Exemplo n.º 1
0
    def inter_objects(self):

        # print('Start_inter_analyse')
        self.inter_mass = 0
        props = GProp_GProps()
        # print(self.names_models)

        for i in range(len(self.names_models) - 1):
            for j in range(i + 1, len(self.names_models)):
                # self.display.DisplayShape(self.modules[self.names_models[i]], color='RED', transparency=0.9)
                # self.display.DisplayShape(self.modules[self.names_models[j]], color='RED', transparency=0.9)
                print(self.names_models[i], self.names_models[j])
                if self.names_models[i] == self.names_models[j]: continue
                body_inter = BRepAlgoAPI_Section(
                    self.modules[self.names_models[i]],
                    self.modules[self.names_models[j]]).Shape()
                # self.display.DisplayShape(body_inter, color='WHITE')
                brepgprop_LinearProperties(body_inter, props)
                mass = props.Mass()
                print(mass)
                if mass > 0:
                    self.inter_mass += mass
                    self.valume_inter_obj[self.names_models[i]][
                        self.names_models[j]] = mass

        #self.start_display()
        return self.inter_mass
Exemplo n.º 2
0
    def inter_objects(self):
        from OCC.Core.GProp import GProp_GProps
        from OCC.Core.BRepGProp import brepgprop_VolumeProperties, brepgprop_SurfaceProperties, \
            brepgprop_LinearProperties
        from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse, BRepAlgoAPI_Common, BRepAlgoAPI_Section, BRepAlgoAPI_Cut

        # print('Start_inter_analyse')
        inter_mass = 0
        props = GProp_GProps()
        # print(self.names_models)
        names = []
        for name in self.modules:
            names.append(name)

        if len(names) > 1:
            for i in range(len(names) - 1):
                for j in range(i + 1, len(names)):
                    # print(self.names_models[i], self.names_models[j])
                    if self.names_models[i] == self.names_models[j]: continue
                    body_inter = BRepAlgoAPI_Section(
                        self.modules[self.names_models[i]],
                        self.modules[self.names_models[j]]).Shape()
                    brepgprop_LinearProperties(body_inter, props)
                    mass = props.Mass()
                    # print(mass)
                    if mass > 0:
                        inter_mass += mass

        # self.start_display()
        return inter_mass
    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.)
Exemplo n.º 4
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.º 5
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
Exemplo n.º 6
0
def measure_shape_mass_center_of_gravity(shape):
    """Returns the shape center of gravity
    Returns a gp_Pnt if requested (set as_Pnt to True)
    or a list of 3 coordinates, by default."""
    inertia_props = GProp_GProps()
    if is_edge(shape):
        brepgprop_LinearProperties(shape, inertia_props)
        mass_property = "Length"
    elif is_face(shape):
        brepgprop_SurfaceProperties(shape, inertia_props)
        mass_property = "Area"
    else:
        brepgprop_VolumeProperties(shape, inertia_props)
        mass_property = "Volume"
    cog = inertia_props.CentreOfMass()
    mass = inertia_props.Mass()
    return cog, mass, mass_property
Exemplo n.º 7
0
def line_clicked(shp, *kwargs):
    """ This function is called whenever a line is selected
        """
    try:
        pass
        for shape in shp:  # this should be a TopoDS_Edge
            print("Edge selected: ", shape)
            e = topods_Edge(shape)

            props = GProp_GProps()
            brepgprop_LinearProperties(e, props)

            length = props.Mass()
            print("此边的长度为: %f" % length)
            centerMass = props.CentreOfMass()
            print("此边的中心点为", centerMass.X(), centerMass.Y(), centerMass.Z())
    except:
        pass
Exemplo n.º 8
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()))
Exemplo n.º 9
0
def line_clicked(shp, *kwargs):
    """ This function is called whenever a line is selected
    """
    for shape in shp:  # this should be a TopoDS_Edge
        print("Edge selected: ", shape)
        e = topods_Edge(shape)

        props = GProp_GProps()
        brepgprop_LinearProperties(e, props)

        length = props.Mass()
        print("此边的长度为: %f" % length)
        centerMass = props.CentreOfMass()
        print("此边的中心点为", centerMass.X(), centerMass.Y(), centerMass.Z())
        list_edge.append(e)
        if len(list_edge) == 2:
            pass
            am = AIS_AngleDimension(list_edge[0], list_edge[1])
            print(123)
            display.Context.Display(am, True)
            list_edge.clear()
Exemplo n.º 10
0
    def inter_objects(self):

        # print('Start_inter_analyse')
        inter_mass = 0
        props = GProp_GProps()
        # print(self.names_models)

        for i in range(len(self.names_models) - 1):
            for j in range(i + 1, len(self.names_models)):
                # print(self.names_models[i], self.names_models[j])
                if self.names_models[i] == self.names_models[j]: continue
                body_inter = BRepAlgoAPI_Section(
                    self.modules[self.names_models[i]],
                    self.modules[self.names_models[j]]).Shape()
                brepgprop_LinearProperties(body_inter, props)
                mass = props.Mass()
                # print(mass)
                if mass > 0:
                    inter_mass += mass

        # self.start_display()
        return inter_mass
 def test_inherit_topods_shape(self):
     t = self
     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
             t.assertTrue(self.IsNull())
             self.TShape(edge.TShape())
             self.Location(edge.Location())
             self.Orientation(edge.Orientation())
             t.assertFalse(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.)
Exemplo n.º 12
0
 def linear(self):
     '''returns the length of a wire or edge
     '''
     prop = GProp_GProps()
     brepgprop_LinearProperties(self.shape, prop)
     return prop
Exemplo n.º 13
0
 def __init__(self, shape, skip_shared=True):
     super(LinearProps, self).__init__()
     brepgprop_LinearProperties(shape.object, self._props, skip_shared)
Exemplo n.º 14
0
 def cal_len(self, shp=TopoDS_Shape()):
     brepgprop_LinearProperties(shp, self.prop)
     return self.prop.Mass()
Exemplo n.º 15
0
    stpname = "{}/shp_{:04d}.stp".format("./shp/", num)
    write_step_file(box, stpname)

    splitter = BOPAlgo_Splitter()
    splitter.AddArgument(box)

    for i in range(7):
        pnt = gp_Pnt(*np.random.rand(3) * 100)
        vec = gp_Vec(*np.random.randn(3))
        pln = gp_Pln(pnt, vec_to_dir(vec))
        fce = make_face(pln, -1000, 1000, -1000, 1000)
        splitter.AddTool(fce)

    splitter.Perform()
    #shp_list = splitter.Generated()

    exp = TopExp_Explorer(splitter.Shape(), TopAbs_SOLID)
    shp = []
    while exp.More():
        num += 1

        props = GProp_GProps()
        brepgprop_LinearProperties(exp.Current(), props)
        vol = props.Mass()
        print(vol)

        stpname = "./shp/shp_{:04d}_{:05.0f}.stp".format(num, vol)
        write_step_file(exp.Current(), stpname)
        shp.append(exp.Current())
        exp.Next()