Esempio n. 1
0
    def test_inherit_topods_shape(self):
        at = self.assertTrue
        af = self.assertFalse

        class InheritEdge(TopoDS_Edge):
            def __init__(self, edge):
                # following constructor creates an empy TopoDS_Edge
                super(InheritEdge, self).__init__()
                # we need to copy the base shape using the following three
                # lines
                at(self.IsNull())
                self.TShape(edge.TShape())
                self.Location(edge.Location())
                self.Orientation(edge.Orientation())
                af(self.IsNull())
                # then it becomes possible to extend the base class

        # create a line, compute its length
        base_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(100., 0., 0.),
                                            gp_Pnt(150., 0., 0.)).Edge()
        inherited_edge = InheritEdge(base_edge)
        g1 = GProp_GProps()
        brepgprop_LinearProperties(inherited_edge, g1)
        length = g1.Mass()
        self.assertEqual(length, 50.)
Esempio n. 2
0
    def system(self):
        r"""Initialise the GProp_GProps depending on the topological type

        Notes
        -----
        geom_type could be abstracted with TopoDS... instead of using _topo_type

        Returns
        -------
        OCC.GProp.GProp_GProps

        """
        self._system = GProp_GProps()

        if self._topo_type in GlobalProperties.surfacic_types:
            brepgprop_SurfaceProperties(self.shape, self._system)
        elif self._topo_type in GlobalProperties.linear_types:
            brepgprop_LinearProperties(self.shape, self._system)
        elif self._topo_type in GlobalProperties.volumic_types:
            brepgprop_VolumeProperties(self.shape, self._system)
        else:
            msg = "ShapeType is not linear, surfacic or volumic"
            logger.error(msg)
            raise WrongTopologicalType(msg)
        return self._system
Esempio n. 3
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. 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
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. 6
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()))
    def test_inherit_topods_shape(self):
        at = self.assertTrue
        af = self.assertFalse

        class InheritEdge(TopoDS_Edge):
            def __init__(self, edge):
                # following constructor creates an empy TopoDS_Edge
                super(InheritEdge, self).__init__()
                # we need to copy the base shape using the following three
                # lines
                at(self.IsNull())
                self.TShape(edge.TShape())
                self.Location(edge.Location())
                self.Orientation(edge.Orientation())
                af(self.IsNull())
                # then it becomes possible to extend the base class
        # create a line, compute its length
        base_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(100., 0., 0.),
                                            gp_Pnt(150., 0., 0.)).Edge()
        inherited_edge = InheritEdge(base_edge)
        g1 = GProp_GProps()
        brepgprop_LinearProperties(inherited_edge, g1)
        length = g1.Mass()
        self.assertEqual(length, 50.)
Esempio n. 8
0
 def linear(self):
     '''returns the length of a wire or edge
     '''
     prop = GProp_GProps()
     brepgprop_LinearProperties(self.shape, prop)
     return prop
Esempio n. 9
0
    def Center(self):

        Properties = GProp_GProps()
        brepgprop_LinearProperties(self.wrapped, Properties)

        return Vector(Properties.CentreOfMass())
Esempio n. 10
0
    def Length(self):

        Properties = GProp_GProps()
        brepgprop_LinearProperties(self.wrapped, Properties)

        return Properties.Mass()
Esempio n. 11
0
 def linear(self):
     '''returns the length of a wire or edge
     '''
     prop = GProp_GProps()
     brepgprop_LinearProperties(self.shape, prop)
     return prop