Пример #1
0
 def _build_extrude(self, partName):
     """Build an extrude part."""
     partDict = self.model.modelDict['3DParts'][partName]
     assert partDict['directive'] == 'extrude'
     z0 = self._fetch_geo_param(partDict['z0'])
     deltaz = self._fetch_geo_param(partDict['thickness'])
     sketch = self.doc.getObject(partDict['fcName'])
     splitSketches = splitSketch(sketch)
     extParts = []
     for mySplitSketch in splitSketches:
         extPart = extrudeBetween(mySplitSketch, z0, z0 + deltaz)
         extPart.Label = partName
         extParts.append(extPart)
         delete(mySplitSketch)
     return extParts
Пример #2
0
def buildAlShell(sketch,
                 zBottom,
                 width,
                 verts,
                 thickness,
                 depoZone=None,
                 etchZone=None,
                 offset=0.0):
    """Builds a shell on a nanowire parameterized by sketch, zBottom, and width.

    Here, verts describes the vertices that are covered, and thickness describes
    the thickness of the shell. depoZone, if given, is extruded and intersected
    with the shell (for an etch). Note that offset here *is not* a real offset -
    for simplicity we keep this a thin shell that lies cleanly on top of the
    bigger wire offset. There's no need to include the bottom portion since that's
    already taken up by the wire.
    """
    lineSegments = findSegments(sketch)[0]
    x0, y0, z0 = lineSegments[0]
    x1, y1, z1 = lineSegments[1]
    dx = x1 - x0
    dy = y1 - y0
    rAxis = np.array([-dy, dx, 0])
    # axis perpendicular to the wire in the xy plane
    rAxis /= np.sqrt(np.sum(rAxis**2))
    zAxis = np.array([0, 0, 1.])
    doc = FreeCAD.ActiveDocument
    shellList = []
    for vert in verts:
        # Make the original wire (including an offset if applicable)
        originalWire = buildWire(sketch, zBottom, width, offset=offset)
        # Now make the shifted wire:
        angle = vert * np.pi / 3.
        dirVec = rAxis * np.cos(angle) + zAxis * np.sin(angle)
        shiftVec = (thickness) * dirVec
        transVec = FreeCAD.Vector(tuple(shiftVec))
        face = makeHexFace(sketch, zBottom - offset,
                           width + 2 * offset)  # make the bigger face
        shiftedFace = Draft.move(face, transVec, copy=False)
        extendedSketch = extendSketch(sketch, offset)
        # The shell offset is handled manually since we are using faceOverride to
        # input a shifted starting face:
        shiftedWire = buildWire(extendedSketch,
                                zBottom,
                                width,
                                faceOverride=shiftedFace)
        delete(extendedSketch)
        shellCut = doc.addObject("Part::Cut",
                                 sketch.Name + "_cut_" + str(vert))
        shellCut.Base = shiftedWire
        shellCut.Tool = originalWire
        doc.recompute()
        shell = Draft.move(shellCut, FreeCAD.Vector(0., 0., 0.), copy=True)
        doc.recompute()
        delete(shellCut)
        delete(originalWire)
        delete(shiftedWire)
        shellList.append(shell)
    if len(shellList) > 1:
        coatingUnion = doc.addObject("Part::MultiFuse",
                                     sketch.Name + "_coating")
        coatingUnion.Shapes = shellList
        doc.recompute()
        coatingUnionClone = copy(coatingUnion)
        doc.removeObject(coatingUnion.Name)
        for shell in shellList:
            doc.removeObject(shell.Name)
    elif len(shellList) == 1:
        coatingUnionClone = shellList[0]
    else:
        raise NameError(
            'Trying to build an empty Al shell. If no shell is desired, omit the AlVerts key from the json.'
        )
    if (depoZone is None) and (etchZone is None):
        return coatingUnionClone

    elif depoZone is not None:
        coatingBB = getBB(coatingUnionClone)
        zMin = coatingBB[4]
        zMax = coatingBB[5]
        depoVol = extrudeBetween(depoZone, zMin, zMax)
        etchedCoatingUnionClone = intersect([depoVol, coatingUnionClone],
                                            consumeInputs=True)
        return etchedCoatingUnionClone
    else:  # etchZone instead
        coatingBB = getBB(coatingUnionClone)
        zMin = coatingBB[4]
        zMax = coatingBB[5]
        etchVol = extrudeBetween(etchZone, zMin, zMax)
        etchedCoatingUnionClone = subtract(coatingUnionClone,
                                           etchVol,
                                           consumeInputs=True)
        return etchedCoatingUnionClone
Пример #3
0
 def _initialize_lithography(self, fillShells=True):
     self.fillShells = fillShells
     # The lithography step requires some infrastructure to track things
     # throughout.
     self.lithoDict = {
     }  # dictionary containing objects for the lithography step
     self.lithoDict['layers'] = {}
     # Dictionary for containing the substrate. () indicates un-offset objects,
     # and subsequent tuples are offset by t_i for each index in the tuple.
     self.lithoDict['substrate'] = {(): []}
     # To start, we need to collect up all the lithography directives, and
     # organize them by layerNum and objectIDs within layers.
     baseSubstratePartNames = []
     for partName in self.model.modelDict['3DParts'].keys():
         partDict = self.model.modelDict['3DParts'][partName]
         # If this part is a litho step
         if 'lithography' == partDict['directive']:
             layerNum = partDict['layerNum']  # layerNum of this part
             # Add the layerNum to the layer dictionary:
             if layerNum not in self.lithoDict['layers']:
                 self.lithoDict['layers'][layerNum] = {'objIDs': {}}
             layerDict = self.lithoDict['layers'][layerNum]
             # Gennerate the base and thickness of the layer:
             layerBase = self._fetch_geo_param(partDict['z0'])
             layerThickness = self._fetch_geo_param(partDict['thickness'])
             # All parts within a given layer number are required to have
             # identical thickness and base, so check that:
             if 'base' in layerDict:
                 assert layerBase == layerDict['base']
             else:
                 layerDict['base'] = layerBase
             if 'thickness' in layerDict:
                 assert layerThickness == layerDict['thickness']
             else:
                 layerDict['thickness'] = layerThickness
             # A given part references a base sketch. However, we need to split
             # the sketch here into possibly disjoint sub-sketches to work
             # with them:
             sketch = self.doc.getObject(partDict['fcName'])
             splitSketches = splitSketch(sketch)
             for mySplitSketch in splitSketches:
                 objID = len(layerDict['objIDs'])
                 objDict = {}
                 objDict['partName'] = partName
                 objDict['sketch'] = mySplitSketch
                 self.trash.append(mySplitSketch)
                 self.lithoDict['layers'][layerNum]['objIDs'][
                     objID] = objDict
             # Add the base substrate to the appropriate dictionary
             baseSubstratePartNames += partDict['lithoBase']
     # Get rid of any duplicates:
     baseSubstratePartNames = list(set(baseSubstratePartNames))
     # Now convert the part names for the substrate into 3D freeCAD objects, which
     # should have already been rendered.
     for baseSubstratePartName in baseSubstratePartNames:
         for baseSubstrateObjName in self.model.modelDict['3DParts'][
                 baseSubstratePartName]['fileNames'].keys():
             self.lithoDict['substrate'][()] += [
                 self.doc.getObject(baseSubstrateObjName)
             ]
     # Now that we have ordered the primitives, we need to compute a few
     # aux quantities that we will need. First, we compute the total bounding
     # box of the lithography procedure:
     thicknesses = []
     bases = []
     for layerNum in self.lithoDict['layers'].keys():
         thicknesses.append(self.lithoDict['layers'][layerNum]['thickness'])
         bases.append(self.lithoDict['layers'][layerNum]['base'])
     bottom = min(bases)
     totalThickness = sum(thicknesses)
     assert len(self.lithoDict['substrate'][
         ()]) > 0  # Otherwise, we don't have a reference for the lateral BB
     substrateUnion = genUnion(self.lithoDict['substrate'][()],
                               consumeInputs=False)  # total substrate
     BB = list(getBB(substrateUnion))  # bounding box
     BB[4] = min([bottom, BB[4]])
     BB[5] = max([BB[5] + totalThickness, bottom + totalThickness])
     BB = tuple(BB)
     constructionZone = makeBB(BB)  # box that encompases the whole domain.
     self.lithoDict['boundingBox'] = [BB, constructionZone]
     delete(substrateUnion)  # not needed for next steps
     delete(constructionZone)  # not needed for next steps
     # Next, we add two prisms for each sketch. The first, which we denote "B",
     # is bounded by the base from the bottom and the layer thickness on the top.
     # These serve as "stencils" that would be the deposited shape if no other.
     # objects got in the way. The second set of prisms, denoted "C", covers the
     # base of the layer to the top of the entire domain box. This is used for
     # forming the volumes occupied when substrate objects are offset and
     # checking for overlaps.
     for layerNum in self.lithoDict['layers'].keys():
         base = self.lithoDict['layers'][layerNum]['base']
         thickness = self.lithoDict['layers'][layerNum]['thickness']
         for objID in self.lithoDict['layers'][layerNum]['objIDs']:
             sketch = self.lithoDict['layers'][layerNum]['objIDs'][objID][
                 'sketch']
             B = extrudeBetween(sketch, base, base + thickness)
             C = extrudeBetween(sketch, base, BB[5])
             self.lithoDict['layers'][layerNum]['objIDs'][objID]['B'] = B
             self.lithoDict['layers'][layerNum]['objIDs'][objID]['C'] = C
             self.trash.append(B)
             self.trash.append(C)
             # In addition, add a hook for the HDict, which will contain the "H"
             # constructions for this object, but offset to thicknesses of various
             # layers, according to the keys.
             self.lithoDict['layers'][layerNum]['objIDs'][objID][
                 'HDict'] = {}