def _process_doc(self, doc): main = doc.Main() color_tool = XCAFDoc_DocumentTool.ColorTool_(main) shape_tool = XCAFDoc_DocumentTool.ShapeTool_(main) labels = TDF_LabelSequence() shape_tool.GetFreeShapes(labels) shapes = [] for i in range(1, labels.Length() + 1): shape = shape_tool.GetShape_(labels.Value(i)) shapes.extend(self._process_shape(shape, color_tool)) return shapes
def setUpClass(cls): """ Set up for XCAFDoc_ShapeTool class. """ cls._app = XCAFApp_Application.GetApplication_() XmlXCAFDrivers.DefineFormat_(cls._app) fmt = TCollection_ExtendedString('XmlXCAF') doc = TDocStd_Document(fmt) cls._app.InitDocument(doc) filename = join(dirname(__file__), 'test_io', 'named_box.xml') fn = TCollection_ExtendedString(filename) status, cls._doc = cls._app.Open(fn, doc) cls._tool = XCAFDoc_DocumentTool.ShapeTool_(cls._doc.Main())
def read_step(self, fn): """ Read and translate a STEP file. :param str fn: The filename. :return: The shapes label. :rtype: afem.exchange.xde.Label. :raise RuntimeError: If the file cannot be read. """ reader = STEPCAFControl_Reader() reader.SetNameMode(True) reader.SetColorMode(True) status = reader.Perform(fn, self._doc) if not status: raise RuntimeError("Error reading STEP file.") self._shape = Shape.wrap(reader.Reader().OneShape()) label = XCAFDoc_DocumentTool.ShapesLabel_(self._doc.Main()) return XdeLabel(label)
def shapes_label(self): """ :return: The shapes label of the document. :rtype: afem.exchange.xde.XdeLabel """ return XdeLabel(XCAFDoc_DocumentTool.ShapesLabel_(self._doc.Main()))
def _init_tool(self): self._tool = XCAFDoc_DocumentTool.ShapeTool_(self._doc.Main())