Ejemplo n.º 1
0
    def centre_mass_vizuall(self):
        flag = 0
        shape = 0
        for name in self.modules:
            if flag == 0:
                cp = BRepBuilderAPI_Copy(self.modules[name])
                cp.Perform(self.modules[name])
                shape = cp.Shape()
                flag = 1
            shape = BRepAlgoAPI_Fuse(shape, self.modules[name]).Shape()

        props = GProp_GProps()
        brepgprop_VolumeProperties(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))
        mat = props.MatrixOfInertia()
        #######################################################################################
        list_1 = [mat.Value(1, 1), mat.Value(1, 2), mat.Value(1, 3)]
        list_2 = [mat.Value(2, 1), mat.Value(2, 2), mat.Value(2, 3)]
        list_3 = [mat.Value(3, 1), mat.Value(3, 2), mat.Value(3, 3)]

        print('\t'.join(str(i) for i in list_1))
        print('\t'.join(str(i) for i in list_2))
        print('\t'.join(str(i) for i in list_3))

        var1 = (cog_x**2 + cog_y**2 + cog_z**2)**0.5
        print(var1)
Ejemplo n.º 2
0
    def copy(self):
        """

        :return:
        """
        cp = BRepBuilderAPI_Copy(self)
        cp.Perform(self)
        # get the class, construct a new instance
        # cast the cp.Shape() to its specific TopoDS topology
        _copy = self.__class__(shape_lut(cp.Shape()))
        return _copy
Ejemplo n.º 3
0
    def filling(self, name_body, coord_centres, coord_centres_2):
        '''

        :param name_body:
        :param coord_centres: 0 - угол поворота x (градусы)
        1 - угол поворота y (градусы)
        2 - угол поворота z (градусы)
        3 - смещенмие по x
        4 - смещенмие по y
        5 - смещенмие по z
        :return:
        '''
        # print(name_body, coord_centres)
        # shape = self.modules[name_body]
        # print(body)

        cp = BRepBuilderAPI_Copy(self.reserv_models[name_body])
        cp.Perform(self.reserv_models[name_body])
        shape = cp.Shape()
        # print(shape)

        r = R.from_euler(
            'xyz', [coord_centres[0], coord_centres[1], coord_centres[2]],
            degrees=True)
        Rot = r.as_dcm()

        trsf = gp_Trsf()
        Mat = gp_Mat(Rot[0][0], Rot[0][1], Rot[0][2], Rot[1][0], Rot[1][1],
                     Rot[1][2], Rot[2][0], Rot[2][1], Rot[2][2])

        trsf.SetRotation(gp_Quaternion(Mat))
        shape.Move(TopLoc_Location(trsf))

        r = R.from_euler(
            'xyz',
            [coord_centres_2[0], coord_centres_2[1], coord_centres_2[2]],
            degrees=True)
        Rot = r.as_dcm()

        trsf = gp_Trsf()
        Mat = gp_Mat(Rot[0][0], Rot[0][1], Rot[0][2], Rot[1][0], Rot[1][1],
                     Rot[1][2], Rot[2][0], Rot[2][1], Rot[2][2])

        trsf.SetRotation(gp_Quaternion(Mat))
        shape.Move(TopLoc_Location(trsf))

        trsf = gp_Trsf()

        trsf.SetTranslation(
            gp_Vec(coord_centres[3], coord_centres[4], coord_centres[5]))
        shape.Move(TopLoc_Location(trsf))
        self.modules[name_body] = shape
Ejemplo n.º 4
0
    def centre_mass_assamble(self):

        flag = 0
        shape = 0
        for name in self.modules:
            if flag == 0:
                cp = BRepBuilderAPI_Copy(self.modules[name])
                cp.Perform(self.modules[name])
                shape = cp.Shape()
                flag = 1
            shape = BRepAlgoAPI_Fuse(shape, self.modules[name]).Shape()

        variation, var_inert = self.centre_mass(shape)
        # self.save_assembly(shape)
        return variation, var_inert
Ejemplo n.º 5
0
    def centre_mass_assamble(self):
        from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge, \
            BRepBuilderAPI_Copy
        from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse, BRepAlgoAPI_Common, BRepAlgoAPI_Section, BRepAlgoAPI_Cut

        flag = 0
        shape = 0
        for name in self.modules:
            if flag == 0:
                cp = BRepBuilderAPI_Copy(self.modules[name])
                cp.Perform(self.modules[name])
                shape = cp.Shape()
                flag = 1
            shape = BRepAlgoAPI_Fuse(shape, self.modules[name]).Shape()

        variation, var_inert = self.centre_mass(shape)
        # self.save_assembly(shape)
        return variation, var_inert
Ejemplo n.º 6
0
    def copy(self, geom=True):
        """
        Copy this shape.

        :param bool geom: Option to copy geometry.

        :return: The copied shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(BRepBuilderAPI_Copy(self.object, geom).Shape())
Ejemplo n.º 7
0
    def inter_with_frame(self):
        # print('Start_inter_analyse')
        #print(self.names_models)
        all_result = 0
        props = GProp_GProps()
        # self.display.DisplayShape(body_inter, color='YELLOW')
        brepgprop_VolumeProperties(self.frame, props)
        mass_frame = props.Mass()

        cp = BRepBuilderAPI_Copy(self.frame)
        cp.Perform(self.frame)
        shape = cp.Shape()

        builder = BOPAlgo_Builder()

        for name in self.modules:
            builder.AddArgument(self.modules[name])

        builder.SetRunParallel(True)
        builder.Perform()
        models = builder.Shape()

        props = GProp_GProps()
        # self.display.DisplayShape(body_inter, color='YELLOW')

        brepgprop_VolumeProperties(models, props)
        mass_models = props.Mass()

        mass_1 = mass_frame + mass_models
        '''builder = BOPAlgo_Builder()

        builder.AddArgument(shape)
        builder.AddArgument(models)

        builder.SetRunParallel(True)
        builder.Perform()
        m_w_frame = builder.Shape()'''

        self.m_w_frame = BRepAlgoAPI_Fuse(shape, models).Shape()
        # self.display.DisplayShape(m_w_frame, color='YELLOW', transparency=0.9)

        props = GProp_GProps()

        brepgprop_VolumeProperties(self.m_w_frame, props)
        mass_2 = props.Mass()

        mass = mass_1 - mass_2

        # print(self.modules)
        '''for model in self.modules:
            # print('#')
            props = GProp_GProps()
            new_shape = BRepAlgoAPI_Cut(shape, self.modules[model]).Shape()
            # self.display.DisplayShape(body_inter, color='YELLOW')
            brepgprop_VolumeProperties(new_shape, props)
            mass_frame_2 = props.Mass()
            self.display.DisplayShape(new_shape, color='YELLOW', transparency=0.9)

            mass = mass_frame - mass_frame_2

            props = GProp_GProps()
            inter = TopOpeBRep_ShapeIntersector()
            inter.InitIntersection(self.modules[model], self.frame)
            flag = inter.MoreIntersection()
            body_inter = inter.CurrentGeomShape(1)
            brepgprop_VolumeProperties(body_inter, props)
            mass = props.Mass()

            props = GProp_GProps()
            body_inter = inter.CurrentGeomShape(2)
            brepgprop_VolumeProperties(body_inter, props)
            mass = abs(mass) + abs(props.Mass())

            dss = BRepExtrema_DistShapeShape()
            dss.LoadS1(self.modules[model])
            dss.LoadS2(self.frame)
            dss.Perform()

            flag = dss.IsDone()
            mass = dss.Value()
            print(mass)
            print(flag)'''
        print(mass)

        if mass > 1e-6:
            # print(mass)
            all_result += 1

        return all_result
Ejemplo n.º 8
0
    def Locate_centre_face(self, number, name_body, angle, x_drive, y_drive):
        cp = BRepBuilderAPI_Copy(self.reserv_models[name_body])
        cp.Perform(self.reserv_models[name_body])
        shape = cp.Shape()

        # move to zero
        bbox = Bnd_Box()
        brepbndlib_Add(shape, bbox)
        xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()

        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(-xmin - (xmax - xmin) / 2, -ymin - (ymax - ymin) / 2,
                   -zmin))
        shape.Move(TopLoc_Location(trsf))

        # Process vector of rotation to face
        x = -self.walls[number][1][1]
        y = self.walls[number][1][0]
        z = 0
        P0 = gp_Pnt(0, 0, 0)
        P1 = gp_Pnt(0, 0, 1)
        P2 = gp_Pnt(self.walls[number][1][0], self.walls[number][1][1],
                    self.walls[number][1][2])

        # rotation to Ax z
        v_x = gp_Vec(P0, gp_Pnt(0, 1, 0))
        v_r = gp_Vec(P0, gp_Pnt(x, y, z))
        if v_x.X != v_r.X and v_x.Y != v_r.Y and v_x.Z != v_r.Z:
            trsf = gp_Trsf()
            #print(v_r.Angle(v_x))
            trsf.SetRotation(gp_Ax1(P0, gp_Dir(0, 0, 1)), v_r.Angle(v_x))
            shape.Move(TopLoc_Location(trsf))

        # rotation in parallel to face
        v0 = gp_Vec(P0, P1)
        v1 = gp_Vec(P0, P2)
        # print(v1.Angle(v0))
        if v1.X != v0.X and v1.Y != v0.Y and v1.Z != v0.Z:
            trsf = gp_Trsf()
            trsf.SetRotation(gp_Ax1(P0, gp_Dir(x, y, z)), v1.Angle(v0))
            # move to face
            shape.Move(TopLoc_Location(trsf))
        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(self.walls[number][0][0], self.walls[number][0][1],
                   self.walls[number][0][2]))
        shape.Move(TopLoc_Location(trsf))

        # Rotation by given angle
        trsf = gp_Trsf()
        trsf.SetRotation(
            gp_Ax1(
                P0,
                gp_Dir(self.walls[number][1][0], self.walls[number][1][1],
                       self.walls[number][1][2])), angle)
        shape.Move(TopLoc_Location(trsf))

        # initional x, y
        offset_y, offset_x = self.rot_point(xmax - xmin, ymax - ymin, angle)

        limit_x = self.walls[number][3][0] / 2 - offset_x
        limit_y = self.walls[number][3][1] / 2 - offset_y

        move_x = limit_x * x_drive
        move_y = limit_y * y_drive

        # Move to x and y
        x_axy = self.walls[number][1][1] * self.walls[number][2][
            2] - self.walls[number][1][2] * self.walls[number][2][1]
        y_axy = -(self.walls[number][1][0] * self.walls[number][2][2] -
                  self.walls[number][1][2] * self.walls[number][2][0])
        z_axy = self.walls[number][1][0] * self.walls[number][2][
            1] - self.walls[number][1][1] * self.walls[number][2][0]

        x_axy *= move_y
        y_axy *= move_y
        z_axy *= move_y

        trsf = gp_Trsf()
        trsf.SetTranslation(gp_Vec(x_axy, y_axy, z_axy))
        shape.Move(TopLoc_Location(trsf))

        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(self.walls[number][2][0] * move_x,
                   self.walls[number][2][1] * move_x,
                   self.walls[number][2][2] * move_x))
        shape.Move(TopLoc_Location(trsf))
        #print(name_body, shape)

        self.modules[name_body] = shape
Ejemplo n.º 9
0
    def Locate_centre_face2(self, number, name_body, angle, x_drive, y_drive):
        from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge, \
            BRepBuilderAPI_Copy
        from OCC.Core.Bnd import Bnd_Box
        from OCC.Core.BRepBndLib import brepbndlib_Add
        from OCC.Core.gp import gp_Pnt, gp_Trsf, gp_Vec, gp_Pln, gp_Dir, gp_Ax3, gp_Ax1
        from OCC.Core.TopLoc import TopLoc_Location

        cp = BRepBuilderAPI_Copy(self.reserv_models[name_body])
        cp.Perform(self.reserv_models[name_body])
        shape = cp.Shape()

        # move to zero
        bbox = Bnd_Box()
        brepbndlib_Add(shape, bbox)
        xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()

        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(-xmin - (xmax - xmin) / 2, -ymin - (ymax - ymin) / 2,
                   -zmin))
        shape.Move(TopLoc_Location(trsf))

        # Process vector of rotation to face
        x, y = 1, 1

        x = -self.walls[number][1][1]
        y = self.walls[number][1][0]

        z = 0
        P0 = gp_Pnt(0, 0, 0)
        P1 = gp_Pnt(0, 0, 1)
        P2 = gp_Pnt(self.walls[number][1][0], self.walls[number][1][1],
                    self.walls[number][1][2])

        # rotation to Ax z
        v_x = gp_Vec(P0, gp_Pnt(0, 1, 0))
        v_r = gp_Vec(P0, gp_Pnt(x, y, z))
        trsf = gp_Trsf()
        #print(v_r.Angle(v_x))
        trsf.SetRotation(gp_Ax1(P0, gp_Dir(0, 0, 1)), v_r.Angle(v_x))
        shape.Move(TopLoc_Location(trsf))

        # rotation in parallel to face
        v0 = gp_Vec(P0, P1)
        v1 = gp_Vec(P0, P2)
        # print(v1.Angle(v0))
        trsf = gp_Trsf()
        trsf.SetRotation(gp_Ax1(P0, gp_Dir(x, y, z)), v1.Angle(v0))
        # move to face
        shape.Move(TopLoc_Location(trsf))
        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(self.walls[number][0][0], self.walls[number][0][1],
                   self.walls[number][0][2]))
        shape.Move(TopLoc_Location(trsf))

        # Rotation by given angle
        trsf = gp_Trsf()
        trsf.SetRotation(
            gp_Ax1(
                P0,
                gp_Dir(self.walls[number][1][0], self.walls[number][1][1],
                       self.walls[number][1][2])), angle)
        shape.Move(TopLoc_Location(trsf))

        # initional x, y
        offset_y, offset_x = self.rot_point(xmax - xmin, ymax - ymin, angle)

        limit_x = self.walls[number][3][0] / 2 - offset_x
        limit_y = self.walls[number][3][1] / 2 - offset_y

        move_x = int(limit_x * x_drive)
        move_y = int(limit_y * y_drive)

        # Move to x and y
        x_axy = self.walls[number][1][1] * self.walls[number][2][
            2] - self.walls[number][1][2] * self.walls[number][2][1]
        y_axy = -(self.walls[number][1][0] * self.walls[number][2][2] -
                  self.walls[number][1][2] * self.walls[number][2][0])
        z_axy = self.walls[number][1][0] * self.walls[number][2][
            1] - self.walls[number][1][1] * self.walls[number][2][0]

        x_axy *= move_y
        y_axy *= move_y
        z_axy *= move_y

        trsf = gp_Trsf()
        trsf.SetTranslation(gp_Vec(x_axy, y_axy, z_axy))
        shape.Move(TopLoc_Location(trsf))

        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(self.walls[number][2][0] * move_x,
                   self.walls[number][2][1] * move_x,
                   self.walls[number][2][2] * move_x))
        shape.Move(TopLoc_Location(trsf))
        # print(name_body, shape)

        self.modules[name_body] = shape