Example #1
0
    def __init__(self, filename, layer_name='layer-00'):
        logger.info("StepOcafExporter instantiated with filename : %s" %
                    filename)

        check_exporter_filename(filename, step_extensions)
        check_overwrite(filename)

        self.filename = filename
        self.h_doc = h_doc = TDocStd.Handle_TDocStd_Document()
        logger.info("Empty Doc?", h_doc.IsNull())

        # Create the application
        app = XCAFApp._XCAFApp.XCAFApp_Application_GetApplication().GetObject()
        app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"),
                        h_doc)

        # Get root assembly
        doc = h_doc.GetObject()
        self.shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(
            doc.Main()).GetObject()
        self.colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(
            doc.Main()).GetObject()
        self.layers = XCAFDoc.XCAFDoc_DocumentTool().LayerTool(
            doc.Main()).GetObject()
        labels = TDF.TDF_LabelSequence()
        color_labels = TDF.TDF_LabelSequence()
        # TopoDS_Shape aShape;

        self.top_label = self.shape_tool.NewShape()
        self.current_color = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
        self.current_layer = self.layers.AddLayer(
            TCollection.TCollection_ExtendedString(layer_name))
        self.layer_names = {}
Example #2
0
#app = Handle_XCAFApp_Application().GetObject()
app = XCAFApp.GetApplication().GetObject()
app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"),h_doc)
print "3"
#
# Transfer
#
print h_doc.IsNull()
if not reader.Transfer(h_doc):
    print "Error"
print "4 bis"
#
# Get root assembly
#
doc = h_doc.GetObject()
print "4"
h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main())
shape_tool = h_shape_tool.GetObject()
# get the top level shapes

l_LabelShapes = TDF.TDF_LabelSequence()
shape_tool.GetShapes(l_LabelShapes)

count = l_LabelShapes.Length()

root_label = l_LabelShapes.Value(1)

shape = shape_tool.GetShape(root_label)
viewXDE(doc, root_label, shape)

Example #3
0
    def read_file(self):
        r"""Read file"""
        logger.info("Reading STEP file")
        h_doc = TDocStd.Handle_TDocStd_Document()

        # Create the application
        app = XCAFApp._XCAFApp.XCAFApp_Application_GetApplication().GetObject()
        app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"),
                        h_doc)

        # Get root assembly
        doc = h_doc.GetObject()
        h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(
            doc.Main()).GetObject()
        color_tool = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(
            doc.Main()).GetObject()
        layer_tool = XCAFDoc.XCAFDoc_DocumentTool().LayerTool(
            doc.Main()).GetObject()
        l_materials = XCAFDoc.XCAFDoc_DocumentTool().MaterialTool(
            doc.Main()).GetObject()

        step_reader = STEPCAFControl.STEPCAFControl_Reader()
        step_reader.SetColorMode(True)
        step_reader.SetLayerMode(True)
        step_reader.SetNameMode(True)
        step_reader.SetMatMode(True)

        status = step_reader.ReadFile(self.filename)

        if status == IFSelect.IFSelect_RetDone:
            logger.info("Transfer doc to STEPCAFControl_Reader")
            step_reader.Transfer(doc.GetHandle())
        else:
            raise ValueError("could not read {}".format(self.filename))

        labels = TDF.TDF_LabelSequence()
        color_labels = TDF.TDF_LabelSequence()
        # TopoDS_Shape a_shape;
        h_shape_tool.GetFreeShapes(labels)
        h_shape_tool.GetShapes(labels)

        logger.info('Number of shapes at root :%i' % labels.Length())

        # for i in range(labels.Length()):
        #     a_shape = h_shape_tool.GetObject().GetShape(labels.Value(i+1))
        #     logger.debug("%i - type : %s" % (i, a_shape.ShapeType()))
        #     sub_shapes_labels = TDF.TDF_LabelSequence()
        #     print("Is Assembly?", shape_tool.IsAssembly(labels.Value(i + 1)))
        #     # sub_shapes = shape_tool.getsubshapes(labels.Value(i+1), sub_shapes_labels)
        #
        #     sub_shapes = shape_tool.FindSubShape(labels.Value(i + 1), a_shape, labels.Value(i + 1))
        #     print('Number of subshapes in the assembly : %i' % sub_shapes_labels.Length())
        #
        # color_tool.GetObject().GetColors(color_labels)
        # logger.info('Number of colors : %i' % color_labels.Length())

        for i in range(labels.Length()):
            # print i
            label = labels.Value(i + 1)
            logger.debug("Label : %s" % label)
            a_shape = h_shape_tool.GetShape(labels.Value(i + 1))

            # string_seq = TColStd.TColStd_HSequenceOfExtendedString()
            # string_seq is an TColStd.TColStd_HSequenceOfExtendedString
            string_seq = layer_tool.GetLayers(a_shape)
            color = Quantity.Quantity_Color()
            c = color_tool.GetColor(a_shape, XCAFDoc.XCAFDoc_ColorSurf, color)

            logger.info("The shape type is : %i" % a_shape.ShapeType())
            if a_shape.ShapeType() == TopAbs.TopAbs_COMPOUND:
                logger.info("The shape type is TopAbs.TopAbs_COMPOUND")
                topo = Topo(a_shape)
                logger.info("Nb of compounds : %i" % topo.number_of_compounds)
                logger.info("Nb of solids : %i" % topo.number_of_solids)
                logger.info("Nb of shells : %i" % topo.number_of_shells)
                for solid in topo.solids:
                    logger.info("Adding solid to the shapes list")
                    self._shapes.append(solid)
            elif a_shape.ShapeType() == TopAbs.TopAbs_SOLID:
                logger.info("The shape type is TopAbs.TopAbs_SOLID")
                self._shapes.append(a_shape)
                self._colors.append(color)
                self._layers.append(string_seq)

        return True