Exemplo n.º 1
0
 def area(self):
     """
     :return: The area of all faces of the shape.
     :rtype: float
     """
     props = GProp_GProps()
     BRepGProp.SurfaceProperties_(self.object, props, True)
     return props.Mass()
Exemplo n.º 2
0
 def volume(self):
     """
     :return: The voume of all solids of the shape.
     :rtype: float
     """
     props = GProp_GProps()
     BRepGProp.VolumeProperties_(self.object, props, True)
     return props.Mass()
Exemplo n.º 3
0
 def length(self):
     """
     :return: The length of all edges of the shape.
     :rtype: float
     """
     props = GProp_GProps()
     BRepGProp.LinearProperties_(self.object, props, True)
     return props.Mass()
Exemplo n.º 4
0
 def __init__(self,
              shape,
              tol=1.0e-7,
              only_closed=False,
              skip_shared=False):
     super(VolumeProps, self).__init__()
     BRepGProp.VolumeProperties_(shape.object, self._props, tol,
                                 only_closed, skip_shared)
Exemplo n.º 5
0
def _build_solid(compound, divide_closed):
    """
    Method to try and build a valid solid from an OpenVSP component.
    """
    # Get all the faces in the compound. The surfaces must be split. Discard
    # any with zero area.
    top_exp = TopExp_Explorer(compound, TopAbs_FACE)
    faces = []
    while top_exp.More():
        shape = top_exp.Current()
        face = CheckShape.to_face(shape)
        fprop = GProp_GProps()
        BRepGProp.SurfaceProperties_(face, fprop, 1.0e-7)
        a = fprop.Mass()
        if a <= 1.0e-7:
            top_exp.Next()
            continue
        faces.append(face)
        top_exp.Next()

    # Replace any planar B-Spline surfaces with planes
    non_planar_faces = []
    planar_faces = []
    for f in faces:
        hsrf = BRep_Tool.Surface_(f)
        try:
            is_pln = GeomLib_IsPlanarSurface(hsrf, 1.0e-7)
            if is_pln.IsPlanar():
                w = ShapeAnalysis.OuterWire_(f)
                # Fix the wire because they are usually degenerate edges in
                # the planar end caps.
                builder = BRepBuilderAPI_MakeWire()
                for e in ExploreShape.get_edges(w):
                    if LinearProps(e).length > 1.0e-7:
                        builder.Add(e)
                w = builder.Wire()
                fix = ShapeFix_Wire()
                fix.Load(w)
                geom_pln = Geom_Plane(is_pln.Plan())
                fix.SetSurface(geom_pln)
                fix.FixReorder()
                fix.FixConnected()
                fix.FixEdgeCurves()
                fix.FixDegenerated()
                w = fix.WireAPIMake()
                # Build the planar face
                fnew = BRepBuilderAPI_MakeFace(w, True).Face()
                planar_faces.append(fnew)
            else:
                non_planar_faces.append(f)
        except RuntimeError:
            non_planar_faces.append(f)

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

    # Split closed faces
    if divide_closed:
        divide = ShapeUpgrade_ShapeDivideClosed(shape)
        divide.Perform()
        shape = divide.Result()

    # Sew shape
    sew = BRepBuilderAPI_Sewing(1.0e-7)
    sew.Load(shape)
    sew.Perform()
    sewn_shape = sew.SewedShape()

    if sewn_shape.ShapeType() == TopAbs_FACE:
        face = sewn_shape
        sewn_shape = TopoDS_Shell()
        builder = BRep_Builder()
        builder.MakeShell(sewn_shape)
        builder.Add(sewn_shape, face)

    # Attempt to unify planar domains
    unify_shp = ShapeUpgrade_UnifySameDomain(sewn_shape, False, True, False)
    unify_shp.Build()
    shape = unify_shp.Shape()

    # Make solid
    shell = ExploreShape.get_shells(shape)[0]
    solid = ShapeFix_Solid().SolidFromShell(shell)

    # Limit tolerance
    FixShape.limit_tolerance(solid)

    # Check shape validity
    check_shp = BRepCheck_Analyzer(solid, True)
    if check_shp.IsValid():
        return solid, True, []
    else:
        invalid_shapes = _topods_iterator_check(solid, check_shp)
        return solid, False, invalid_shapes
Exemplo n.º 6
0
 def __init__(self, shape, tol=1.0e-7, skip_shared=False):
     super(SurfaceProps, self).__init__()
     BRepGProp.SurfaceProperties_(shape.object, self._props, tol,
                                  skip_shared)
Exemplo n.º 7
0
 def __init__(self, shape, skip_shared=True):
     super(LinearProps, self).__init__()
     BRepGProp.LinearProperties_(shape.object, self._props, skip_shared)
Exemplo n.º 8
0
 def length(self):
     props = GProp_GProps()
     BRepGProp.LinearProperties_(self.shape, props, True)
     return props.Mass()  # Don't ask