def buildCrossSection(sliceInfo, passModel=None): """Render the 2D objects required for cross-sections.""" if passModel is None: passModel = getModel() doc = FreeCAD.ActiveDocument sliceName = sliceInfo['sliceName'] axis, distance = sliceInfo['axis'], sliceInfo['distance'] sliceParts = {} for name, part in iteritems(passModel.modelDict['3DParts']): # loop over FreeCAD shapes corresponding to part polygons = {} for shapeName in part['fileNames'].keys(): # slice the 3D part fcName = shapeName + '_section_' + sliceName partObj = doc.getObject(shapeName) section = crossSection(partObj, axis=axis, d=distance, name=fcName) # separate disjoint pieces segments, cycles = findEdgeCycles(section) for i, cycle in enumerate(cycles): points = [tuple(segments[idx, 0]) for idx in cycle] patchName = fcName patchName = '{}_{}'.format(shapeName, i) polygons[patchName] = points # store sliced part if polygons: slicePart = part.copy() slicePart['type'] = "domain" slicePart['3DPart'] = name slicePart['geometry'] = polygons sliceParts[name] = slicePart return sliceParts
def build2DGeo(passModel=None): """Construct the 2D geometry entities defined in the json file.""" # TODO: THIS FUNCTION NEEDS TO BE UPDATED AFTER modelRevision # RESTRUCTURING! myModel = getModel() if passModel is None else passModel twoDObjs = {} doc = FreeCAD.ActiveDocument for fcName in myModel.modelDict['freeCADInfo']: keys = myModel.modelDict['freeCADInfo'][fcName].keys() if '2DObject' in keys: objType = '2DObject' objControlDict = myModel.modelDict['freeCADInfo'][fcName][objType] returnDict = {} returnDict.update(objControlDict['physicsProps']) returnDict['type'] = objControlDict['type'] if objControlDict['type'] == 'boundary': points = [ tuple(v.Point) for v in doc.getObject(fcName).Shape.Vertexes ] twoDObjs[fcName] = (points, returnDict) else: lineSegments, cycles = findEdgeCycles(doc.getObject(fcName)) for i, cycle in enumerate(cycles): points = [tuple(lineSegments[idx, 0]) for idx in cycle] name = fcName if len(cycles) > 1: name = '{}_{}'.format(name, i) twoDObjs[name] = (points, returnDict) return twoDObjs
def __init__(self, passModel=None, debugMode=False): """Builds a model defined by the JSON input file.""" if passModel is None: self.model = getModel() else: self.model = passModel self.debugMode = debugMode self.doc = FreeCAD.ActiveDocument self._buildPartsDict = {} self.lithoSetup = False # Has the litho setup routine been run? self.trash = [] # trash for garbage collection at the end # Update the FreeCAD model to reflect the current value of any model # parameters: updateParams(passModel=self.model)