class Stack(list): classification = EuroCircuits6C() dielectricThicknesses = [0.180+0.180, 0.710, 0.180+0.180 ] @property def numberOfFaces(self): return len(self) def __init__(self,numberOfFaces,title='Untitled',author='Author',notes=''): self.title = title self.author = author self.creationMoment = datetime.datetime.now() self.skipLayerMarkerOutlineNumbers = [] self.notes = notes list.__init__(self,[None]*numberOfFaces) ## file initialisation self._platedFile = Excellon('Drill Plated',plated=True) self._nonPlatedFile = Excellon('Drill Unplated',plated=False) self._drillFile = HoleFile(self._platedFile,self._nonPlatedFile) self.addHole = self._drillFile.addHole self.top = GerberFile('Signal 1 Top',physicalLayer=1) self.topSolderMask = GerberFile('Soldermask Top') self.topSilkScreen = GerberFile('Silkscreen Top') self.topSilkScreenLine = self.topSilkScreen.addCircularAperture(0.23) self[0] = Face(self,self.top,self.topSolderMask,self.topSilkScreen,thickness=0.025) self.innerOneFile = GerberFile('Signal 2 Inner',physicalLayer=2) self[1] = Face(self,self.innerOneFile,thickness=0.035) self.innerTwoFile = GerberFile('Signal 3 Inner',physicalLayer=3) self[2] = Face(self,self.innerTwoFile,thickness=0.035) self.bottom = GerberFile('Signal 4 Bottom',physicalLayer=4) self.bottomSolderMask = GerberFile('Soldermask Bottom') self.bottomSilkScreen = GerberFile('Silkscreen Bottom') self[3] = Face(self,self.bottom,self.bottomSolderMask,self.bottomSilkScreen,thickness=0.025) self[-1].opposite = self[ 0] self[ 0].opposite = self[-1] self.mechanical = GerberFile('Mechanical Outline') self.mechanicalApertureDiameter = 0.2 self.boardOutline = Square(center=Location(0,0),width=100).outline() assert self.numberOfFaces == numberOfFaces @property def thickness(self): return self[0].thickness + self[-1].depth @property def rectangularHull(self): return self.boardOutline.rectangularHull() @property def width(self): return self.rectangularHull.width @property def height(self): return self.rectangularHull.height @property def timeStamp(self): return self.creationMoment.strftime('%Y-%m-%d %H:%M') def writeOut(self,toZip=False): if toZip: zipFile = zipfile.ZipFile('../'+self.title+'.zip','w',zipfile.ZIP_DEFLATED) outputFile = zipFile.filename else: outputFile = '../output/' zipFile = None layerMarkers = [] for (shapeNumber,shape) in enumerate(self.boardOutline): if shapeNumber not in self.skipLayerMarkerOutlineNumbers: layerMarkers += [LayerMarker(Arrow(shape.bottomLeft,E), 4)] if len(self.boardOutline) > 1: self.boardOutline += [self.rectangularHull.outset(self.classification.panelBorder)] def addApertureAndShapesTo(gerberFile): apertureNumber = gerberFile.addCircularAperture(self.mechanicalApertureDiameter) for shape in self.boardOutline: shape.outline().draw(gerberFile[30],apertureNumber) addApertureAndShapesTo(self.mechanical) # StrokeText(textString='{title} {timeStamp}\n{notes}'.format(title=self.title,timeStamp=self.timeStamp,notes=self.notes), # startArrow=Arrow(self.rectangularHull.bottomLeft,E).outsetArrow(2.5), # gerberLayer=self.mechanical[0]).draw() self.mechanical.writeOut(zipFile=zipFile) for face in self: addApertureAndShapesTo(face.copper) for layerMarker in layerMarkers: layerMarker.draw(face.copper) face.writeOut(zipFile=zipFile) self._drillFile.writeOut(zipFile=zipFile) if zipFile: zipFile.close() print 'Written out {width:.2f} x {height:.2f} mm to {outputFile}'.format(width=self.width,height=self.height,outputFile = os.path.abspath(outputFile))