Пример #1
0
 def _get_label_name(lab):
     entry = TCollection_AsciiString()
     TDF_Tool.Entry(lab, entry)
     n = TDataStd_Name()
     lab.FindAttribute(TDataStd_Name_GetID(), n)
     if n:
         return n.Get().PrintToString()
     return "No Name"
Пример #2
0
 def name(self):
     """
     :return: The label name.
     :rtype: str or None
     """
     name = TDataStd_Name()
     status, name = self._label.FindAttribute(name.GetID_(), name)
     if status:
         return name.Get().ToExtString()
     return None
Пример #3
0
    def set_name(self, name):
        """
        Set label name.

        :param str name: The name.

        :return: None.
        """
        txt = TCollection_ExtendedString(name)
        TDataStd_Name.Set_(self._label, txt)
Пример #4
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
Пример #5
0
 def setLabelName(self, label, name):
     TDataStd_Name.Set(label, TCollection_ExtendedString(name))
Пример #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