def buildCrossSection(sliceName, axis, distance, built_parts_dict): """Render the 2D objects required for cross-sections. Parameters ---------- sliceName : axis : distance : built_parts_dict : dict Returns ------- """ polygons = {} for part_name in built_parts_dict: built_part = built_parts_dict[part_name] # loop over FreeCAD shapes corresponding to part # slice the 3D part fcName = f"{part_name}_section_{sliceName}" section = crossSection(built_part, 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 = f"{part_name}_{i}" # this mapping is necessary since numpy floats have a pickle error: polygons[patchName] = [list(map(float, point)) for point in points] return polygons
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