示例#1
0
    def __init__(self, shape, pnt):
        pnt = CheckGeom.to_point(pnt)

        if shape.shape_type not in [Shape.FACE, Shape.SHELL]:
            raise RuntimeError('Invalid shape for creating half-space.')
        self._solid = Solid(
            BRepPrimAPI_MakeHalfSpace(shape.object, pnt).Solid())
示例#2
0
 def __init__(self, pln, width, height, depth):
     w = width / 2.
     h = height / 2.
     gp_pln = pln.gp_pln
     topods_face = BRepBuilderAPI_MakeFace(gp_pln, -w, w, -h, h).Face()
     vn = pln.norm(0., 0.)
     vn.Normalize()
     vn.Scale(depth)
     self._solid = Solid(BRepPrimAPI_MakePrism(topods_face, vn).Shape())
示例#3
0
文件: vsp.py 项目: sanderboer/AFEM
def _build_solid(compound, divide_closed):
    """
    Try to build a solid from the OpenVSP compound of faces.

    :param afem.topology.entities.Compound compound: The compound.
    :param bool divide_closed: Option to divide closed faces.

    :return: The solid.
    :rtype: afem.topology.entities.Solid
    """
    # Get all the faces in the compound. The surfaces must be split. Discard
    # any with zero area.
    faces = []
    for face in compound.faces:
        area = SurfaceProps(face).area
        if area > 1.0e-7:
            faces.append(face)

    # Replace any planar B-Spline surfaces with planes.
    non_planar_faces = []
    planar_faces = []
    for f in faces:
        srf = f.surface
        try:
            pln = srf.as_plane()
            if pln:
                w = f.outer_wire
                # Fix the wire because they are usually degenerate edges in
                # the planar end caps.
                builder = BRepBuilderAPI_MakeWire()
                for e in w.edges:
                    if LinearProps(e).length > 1.0e-7:
                        builder.Add(e.object)
                w = builder.Wire()
                fix = ShapeFix_Wire()
                fix.Load(w)
                fix.SetSurface(pln.object)
                fix.FixReorder()
                fix.FixConnected()
                fix.FixEdgeCurves()
                fix.FixDegenerated()
                w = Wire(fix.WireAPIMake())
                fnew = Face.by_wire(w)
                planar_faces.append(fnew)
            else:
                non_planar_faces.append(f)
        except RuntimeError:
            logger.info('Failed to check for planar face...')
            non_planar_faces.append(f)

    # Make a compound of the faces
    shape = Compound.by_shapes(non_planar_faces + planar_faces)

    # Split closed faces
    if divide_closed:
        shape = DivideClosedShape(shape).shape

    # Sew shape
    sewn_shape = SewShape(shape).sewed_shape
    if isinstance(sewn_shape, Face):
        sewn_shape = sewn_shape.to_shell()

    # Attempt to unify planar domains
    shell = UnifyShape(sewn_shape).shape

    # Make solid
    if not isinstance(shell, Shell):
        logger.info('\tA valid shell was not able to be generated.')
        check = CheckShape(shell)
        if not check.is_valid:
            logger.info('\tShape errors:')
            check.log_errors()
        return shell, check.invalid_shapes

    solid = Solid.by_shell(shell)

    # Limit tolerance
    FixShape.limit_tolerance(solid)

    # Check the solid and attempt to fix
    invalid = []
    check = CheckShape(solid)
    if not check.is_valid:
        logger.info('\tFixing the solid...')
        solid = FixShape(solid).shape
        check = CheckShape(solid)
        if not check.is_valid:
            logger.info('\t...solid could not be fixed.')
            logger.info('\tShape errors:')
            check.log_errors()
            failed = check.invalid_shapes
            invalid += failed
    else:
        tol = solid.tol_avg
        logger.info(
            '\tSuccessfully generated solid with tolerance={}'.format(tol))

    return solid, invalid
示例#4
0
 def box(self):
     """
     :return: The bounding box of all provided shapes.
     :rtype: afem.topology.entities.Solid
     """
     return Solid(self._bop.Box())
示例#5
0
 def __init__(self, face, v):
     v = CheckGeom.to_vector(v)
     builder = BRepPrimAPI_MakePrism(face.object, v)
     self._solid = Solid(builder.Shape())
     self._f1 = Face(builder.FirstShape())
     self._f2 = Face(builder.LastShape())
示例#6
0
 def __init__(self, shell):
     self._solid = Solid.by_shell(shell)
示例#7
0
 def solid(self):
     """
     :return: The sphere as a solid.
     :rtype: afem.topology.entities.Face
     """
     return Solid(self._builder.Solid())
示例#8
0
 def solid(self):
     """
     :return: The cylinder as a solid.
     :rtype: afem.topology.entities.Solid
     """
     return Solid(self._builder.Solid())