예제 #1
0
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
예제 #2
0
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
예제 #3
0
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