Ejemplo n.º 1
0
    def __init__(self, file_path):
        self.h_doc = TDocStd.Handle_TDocStd_Document()
        self.app = XCAFApp.GetApplication().GetObject()
        self.app.NewDocument(TCollection_ExtendedString("MDTV-XCAF"),
                             self.h_doc)

        self.STEPReader = STEPCAFControl_Reader()
        if not self.STEPReader.ReadFile(file_path.encode("utf-8")):
            raise Exception("OpenCascade could not read STEP file")
        self.STEPReader.Transfer(self.h_doc)
        self.doc = self.h_doc.GetObject()
        self.h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool_ShapeTool(
            self.doc.Main())
        self.h_colors_tool = XCAFDoc.XCAFDoc_DocumentTool_ColorTool(
            self.doc.Main())
        self.shape_tool = self.h_shape_tool.GetObject()
        self.color_tool = self.h_colors_tool.GetObject()
        self.shapes = TDF_LabelSequence()
        self.shape_tool.GetShapes(self.shapes)
        roots = TDF_LabelSequence()
        self.shape_tool.GetFreeShapes(roots)
        ws = self.STEPReader.Reader().WS().GetObject()
        model = ws.Model().GetObject()
        model.Clear()
        for i in range(1, 8):
            ws.ClearData(i)
        ws.ClearFile()
Ejemplo n.º 2
0
    def FillTestDoc(doc):
        h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool_ShapeTool(doc.Main())
        h_Colors = XCAFDoc.XCAFDoc_DocumentTool_ColorTool(doc.Main())

        shape_tool = h_shape_tool.GetObject()
        colors = h_Colors.GetObject()

        top_label = shape_tool.NewShape(
        )  # this is the "root" label for the assembly

        print("top entry", Label(TDF_Label=top_label).entry)

        box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
        box_label = shape_tool.AddShape(box, False)

        cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
        cyl_label = shape_tool.AddShape(cyl, False)
        #
        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(100, 100, 100))
        loc = TopLoc.TopLoc_Location(tr)
        box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(200, 200, 200))
        loc = TopLoc.TopLoc_Location(tr)
        box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(150, 200, 100))
        loc = TopLoc.TopLoc_Location(tr)
        cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

        red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
        green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
        colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
        colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)
Ejemplo n.º 3
0
    def __init__(self, file_path, id=None):

        self.file = file_path.encode("utf-8")
        self.id = id
        self.shapes_simples = []
        self.main_product = None
        basename = os.path.basename(self.file)
        self.fileName = os.path.splitext(basename)[0]

        self.STEPReader = STEPCAFControl_Reader()

        if self.STEPReader.ReadFile(self.file) != 1:
            raise OCCReadingStepError

        self.h_doc = TDocStd.Handle_TDocStd_Document()
        self.app = XCAFApp.GetApplication().GetObject()
        self.app.NewDocument(TCollection_ExtendedString("MDTV-XCAF"),
                             self.h_doc)

        self.STEPReader.Transfer(self.h_doc)

        self.doc = self.h_doc.GetObject()
        self.h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool_ShapeTool(
            self.doc.Main())
        self.h_colors_tool = XCAFDoc.XCAFDoc_DocumentTool_ColorTool(
            self.doc.Main())
        self.shape_tool = self.h_shape_tool.GetObject()
        self.color_tool = self.h_colors_tool.GetObject()

        self.shapes = TDF_LabelSequence()
        self.shape_tool.GetShapes(self.shapes)
        for i in range(self.shapes.Length()):
            shape = self.shapes.Value(i + 1)
            if self.shape_tool.IsSimpleShape(shape):
                compShape = self.shape_tool.GetShape(shape)
                t = Topo(compShape)
                if t.number_of_vertices() > 0:
                    label = get_label_name(shape)
                    color = find_color(shape, self.color_tool, self.shape_tool)
                    self.shapes_simples.append(
                        SimpleShape(label, compShape, color))

        roots = TDF_LabelSequence()
        self.shape_tool.GetFreeShapes(roots)
        self.thumbnail_valid = False
        if roots.Length() == 1:
            shape = self.shape_tool.GetShape(roots.Value(1))
            t = Topo(shape)
            if t.number_of_vertices() > 0:
                bbox = Bnd_Box()
                gap = 0
                bbox.SetGap(gap)

                BRepMesh_Mesh(shape, get_mesh_precision(shape, 1))
                faces_iterator = Topo(shape).faces()
                for F in faces_iterator:
                    face_location = TopLoc_Location()
                    BRep_Tool_Triangulation(F, face_location)
                BRepBndLib_Add(shape, bbox)
                x_min, y_min, z_min, x_max, y_max, z_max = bbox.Get()
                diagonal = max(x_max - x_min, y_max - y_min, z_max - z_min)
                if diagonal > 0:
                    self.scale = 200. / diagonal
                    self.trans = ((x_max - x_min) / 2. - x_max,
                                  (y_max - y_min) / 2. - y_max,
                                  (z_max - z_min) / 2. - z_max)
                    self.thumbnail_valid = True

        ws = self.STEPReader.Reader().WS().GetObject()
        model = ws.Model().GetObject()
        model.Clear()