Ejemplo n.º 1
0
 def __init__(self, name="name", tol=1.0E-10):
     self.name = name
     self.step = STEPCAFControl_Writer()
     self.step.SetNameMode(True)
     self.h_doc = TDocStd_Document()
     self.x_app = XCAFApp_Application.GetApplication().GetObject()
     self.x_app.NewDocument(TCollection_ExtendedString("MDTV-CAF"),
                            self.h_doc)
     self.doc = self.h_doc.GetObject()
     self.h_shape_tool = XCAFDoc_DocumentTool_ShapeTool(self.doc.Main())
     self.shape_tool = self.h_shape_tool.GetObject()
     Interface_Static_SetCVal("write.step.schema", "AP214")
Ejemplo n.º 2
0
    def testRTStep(self, doc):
        """A 'short-circuit' Round Trip test. Write doc back to step file."""

        fname = "../testRoundTrip.stp"

        # initialize the STEP exporter
        step_writer = STEPCAFControl_Writer()

        # transfer shapes and write file
        step_writer.Transfer(doc)
        status = step_writer.Write(fname)
        assert (status == IFSelect_RetDone)
Ejemplo n.º 3
0
    def saveStep(self):
        """Export self.doc to STEP file."""

        prompt = 'Choose filename for step file.'
        fnametuple = QFileDialog.getSaveFileName(
            None, prompt, './', "STEP files (*.stp *.STP *.step)")
        fname, _ = fnametuple
        if not fname:
            print("Save step cancelled.")
            return
        # Reconstruct XCAFDoc related code from stepXD.StepImporter
        labels = TDF_LabelSequence()
        shape_tool = XCAFDoc_DocumentTool_ShapeTool(self.doc.Main())
        shape_tool.GetShapes(labels)
        logger.info('Number of labels at root : %i', labels.Length())
        try:
            rootlabel = labels.Value(1)  # First label at root
        except RuntimeError:
            return
        name = rootlabel.GetLabelName()
        logger.info('Name of root label: %s', name)
        isAssy = shape_tool.IsAssembly(rootlabel)
        logger.info("First label at root holds an assembly? %s", isAssy)

        # Modify self.doc by adding active part to rootlabel.
        #Standard_Boolean expand = Standard_False; //default
        #TDF_Label aLabel = myAssembly->AddComponent (aShape [,expand]);
        newLabel = shape_tool.AddComponent(rootlabel, self.activePart, True)
        #set a name to newlabel (as a reminder using OCAF), use:
        #TCollection_ExtendedString aName ...;
        #// contains the desired name for this Label (ASCII)
        #TDataStd_Name::Set (aLabel, aName);
        newName = TCollection_ExtendedString(
            self._nameDict[self.activePartUID])
        TDataStd_Name.Set(newLabel, newName)
        logger.info('Name of new part: %s', newName)
        #myAssembly->UpdateAssemblies();
        shape_tool.UpdateAssemblies()

        # initialize the STEP exporter
        step_writer = STEPCAFControl_Writer()

        # transfer shapes and write file
        step_writer.Transfer(self.doc)
        status = step_writer.Write(fname)
        assert status == IFSelect_RetDone
Ejemplo n.º 4
0
    def saveStepDoc(self):
        """Export self.doc to STEP file."""

        prompt = 'Choose filename for step file.'
        fnametuple = QFileDialog.getSaveFileName(
            None, prompt, './', "STEP files (*.stp *.STP *.step)")
        fname, _ = fnametuple
        if not fname:
            print("Save step cancelled.")
            return

        # initialize STEP exporter
        WS = XSControl_WorkSession()
        step_writer = STEPCAFControl_Writer(WS, False)

        # transfer shapes and write file
        step_writer.Transfer(self.doc, STEPControl_AsIs)
        status = step_writer.Write(fname)
        assert status == IFSelect_RetDone
Ejemplo n.º 5
0
    def write_file(self):
        r"""Write file"""
        work_session = XSControl_WorkSession()
        writer = STEPCAFControl_Writer(work_session.GetHandle(), False)

        transfer_status = writer.Transfer(self.h_doc, STEPControl_AsIs)
        if transfer_status != IFSelect_RetDone:
            msg = "An error occurred while transferring a shape " \
                  "to the STEP writer"
            logger.error(msg)
            raise StepShapeTransferException(msg)
        logger.info('Writing STEP file')

        write_status = writer.Write(self.filename)
        if write_status == IFSelect_RetDone:
            logger.info("STEP file write successful.")
        else:
            msg = "An error occurred while writing the STEP file"
            logger.error(msg)
            raise StepFileWriteException(msg)
Ejemplo n.º 6
0
 def externalGeometryAssembly(self):
     # Create a TDoc holding the assembly of structure parts with external geometry. When assembled, write the STEP file
     # Initialize the  writer
     shapes = []
     step_writer = STEPCAFControl_Writer()
     step_writer.SetNameMode(True)
     step_writer.SetPropsMode(True)
     # create the handle to a document
     doc = TDocStd_Document(TCollection_ExtendedString("ocx-doc"))
     # Get root assembly
     shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
     shape_tool.SetAutoNaming(False)
     l_colors = XCAFDoc_DocumentTool_ColorTool(doc.Main())
     l_layers = XCAFDoc_DocumentTool_LayerTool(doc.Main())
     l_materials = XCAFDoc_DocumentTool_MaterialTool(doc.Main())
     aBuilder = BRep_Builder()
     # Loop over all Panels
     panelchildren = []
     for panel in self.model.panels:
         OCXCommon.LogMessage(panel, self.logging)
         guid = self.model.getGUID(panel)
         children = self.model.getPanelChildren(guid)
         panelchildren = panelchildren + children
         # Build the Panel compound
         compound = TopoDS_Compound()
         aBuilder.MakeCompound(compound)
         label = shape_tool.AddShape(compound)
         pname = panel.get('name')
         tname = TDataStd_Name()
         tname.Set(TCollection_ExtendedString(pname))
         label.AddAttribute(tname)
         for child in children:
             object = self.model.getObject(child)
             name = object.get('name')
             extg = ExternalGeometry(self.model, object, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     # Root brackets
     compound = TopoDS_Compound()
     aBuilder.MakeCompound(compound)
     label = shape_tool.AddShape(compound)
     tname = TDataStd_Name()
     tname.Set(TCollection_ExtendedString('Brackets'))
     label.AddAttribute(tname)
     for br in self.model.brackets:
         guid = self.model.getGUID(br)
         name = br.get('name')
         if guid not in panelchildren:
             extg = ExternalGeometry(self.model, br, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     # Root plates
     compound = TopoDS_Compound()
     aBuilder.MakeCompound(compound)
     label = shape_tool.AddShape(compound)
     tname = TDataStd_Name()
     tname.Set(TCollection_ExtendedString('Plates'))
     label.AddAttribute(tname)
     for pl in self.model.plates:
         guid = self.model.getGUID(pl)
         name = pl.get('name')
         if guid not in panelchildren:
             extg = ExternalGeometry(self.model, pl, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     # Root pillars
     compound = TopoDS_Compound()
     aBuilder.MakeCompound(compound)
     label = shape_tool.AddShape(compound)
     tname = TDataStd_Name()
     tname.Set(TCollection_ExtendedString('Pillars'))
     label.AddAttribute(tname)
     for pil in self.model.pillars:
         guid = self.model.getGUID(pil)
         name = pil.get('name')
         if guid not in panelchildren:
             extg = ExternalGeometry(self.model, pil, self.dict,
                                     self.logging)  # Init the creator
             extg.readExtGeometry()  # Read the Brep
             if extg.IsDone():
                 aBuilder.Add(compound, extg.Shape())
                 tname = TDataStd_Name()
                 label = shape_tool.AddShape(extg.Shape())
                 tname.Set(TCollection_ExtendedString(name))
                 label.AddAttribute(tname)
     step_writer.Perform(
         doc, TCollection_AsciiString(self.model.ocxfile.stem + '.stp'))
     return