Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
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()
Esempio n. 4
0
 def system(self):
     self._system = GProp_GProps()
     # todo, type should be abstracted with TopoDS...
     _topo_type = self.instance.topo_type
     if _topo_type == 'face' or _topo_type == 'shell':
         brepgprop_SurfaceProperties(self.instance, self._system)
     elif _topo_type == 'edge':
         brepgprop_LinearProperties(self.instance, self._system)
     elif _topo_type == 'solid':
         brepgprop_VolumeProperties(self.instance, self._system)
     return self._system
Esempio n. 5
0
def shape_faces_surface():
    """ Compute the surface of each face of a shape
    """
    # first create the shape
    the_shape = BRepPrimAPI_MakeBox(50., 30., 10.).Shape()
    # then loop over faces
    t = TopologyExplorer(the_shape)
    props = GProp_GProps()
    shp_idx = 1
    for face in t.faces():
        brepgprop_SurfaceProperties(face, props)
        face_surf = props.Mass()
        print("Surface for face nbr %i : %f" % (shp_idx, face_surf))
        shp_idx += 1
Esempio n. 6
0
def cube_inertia_properties():
    """ Compute the inertia properties of a shape
    """
    # Create and display cube
    print("Creating a cubic box shape (50*50*50)")
    cube_shape = BRepPrimAPI_MakeBox(50., 50., 50.).Shape()
    # Compute inertia properties
    props = GProp_GProps()
    brepgprop_VolumeProperties(cube_shape, props)
    # Get inertia properties
    mass = props.Mass()
    cog = props.CentreOfMass()
    matrix_of_inertia = props.MatrixOfInertia()
    # Display inertia properties
    print("Cube mass = %s" % mass)
    cog_x, cog_y, cog_z = cog.Coord()
    print("Center of mass: x = %f;y = %f;z = %f;" % (cog_x, cog_y, cog_z))
    print("Matrix of inertia", matrix_of_inertia)
Esempio n. 7
0
def on_select(shapes):
    """

    Parameters
    ----------
    shape : TopoDS_Shape

    """
    g1 = GProp_GProps()

    for shape in shapes:
        brepgprop_LinearProperties(shape, g1)
        mass = g1.Mass()
        centre_of_mass = g1.CentreOfMass()
        com_x = centre_of_mass.X()
        com_y = centre_of_mass.Y()
        com_z = centre_of_mass.Z()
        static_moments = g1.StaticMoments()
        print("shape {shape}: \n mass: {mass}"
              "\n center of mass: {com_x}, {com_y}, {com_z}"
              "\n static moments: {static_moments}".format(**vars()))
Esempio n. 8
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
Esempio n. 9
0
 def __init__(self):
     self._props = GProp_GProps()
 def linear(self):
     '''returns the length of a wire or edge
     '''
     prop = GProp_GProps()
     brepgprop_LinearProperties(self.shape, prop)
     return prop
 def surface(self):
     '''returns the area of a surface
     '''
     prop = GProp_GProps()
     brepgprop_SurfaceProperties(self.shape, prop, self.tolerance)
     return prop
 def volume(self):
     '''returns the volume of a solid
     '''
     prop = GProp_GProps()
     brepgprop_VolumeProperties(self.shape, prop, self.tolerance)
     return prop
Esempio n. 13
0
 def length(self):
     props = GProp_GProps()
     BRepGProp.LinearProperties_(self.shape, props, True)
     return props.Mass()  # Don't ask