예제 #1
0
파일: xde.py 프로젝트: trelau/AFEM
    def __init__(self, binary=True):
        if binary:
            self._fmt = 'BinXCAF'
            self._ext = '.xbf'
        else:
            self._fmt = 'XmlXCAF'
            self._ext = '.xml'

        # Get application
        self._app = XCAFApp_Application.GetApplication_()
        if binary:
            BinXCAFDrivers.DefineFormat_(self._app)
        else:
            XmlXCAFDrivers.DefineFormat_(self._app)

        # Initialize document
        fmt = TCollection_ExtendedString(self._fmt)
        self._doc = TDocStd_Document(fmt)
        self._app.InitDocument(self._doc)

        # Exchange data
        self._shape = None
        self._step_writer = None
        self._step_fp = None

        self._init_tool()
예제 #2
0
    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())
예제 #3
0
파일: xde.py 프로젝트: trelau/AFEM
    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 test_Open(self):
        """
        Test TDocStd_Application::Open.
        """
        fmt = TCollection_ExtendedString('XmlXCAF')
        doc = TDocStd_Document(fmt)

        self._app.InitDocument(doc)

        filename = join(dirname(__file__), 'test_io', 'named_box.xml')

        fn = TCollection_ExtendedString(filename)
        status, doc = self._app.Open(fn, doc)

        self.assertEqual(PCDM_ReaderStatus.PCDM_RS_OK, status)
        self.assertFalse(doc.IsEmpty())
        self.assertEqual(doc.FileExtension().ToExtString(), 'xml')

        self._app.Close(doc)
예제 #5
0
    def create_item(self):
        d = self.declaration
        text = TCollection_ExtendedString(d.text)
        ais_item = AIS_TextLabel()
        ais_item.SetText(text)
        ais_item.SetPosition(d.position.proxy)
        ais_item.SetHeight(d.size)
        if d.font:
            ais_item.SetFont(d.font)

        color, alpha = color_to_quantity_color(d.color)
        ais_item.SetColor(color)
        self.item = ais_item
예제 #6
0
파일: xde.py 프로젝트: trelau/AFEM
    def save_as(self, fn):
        """
        Save the document.

        :param str fn: The filename.

        :return: *True* if sucessfully saved, *False* if not.
        :rtype: bool
        """
        if not fn.endswith(self._ext):
            fn += self._ext

        txt = TCollection_ExtendedString(fn)
        status = self._app.SaveAs(self._doc, txt)
        return status == PCDM_StoreStatus.PCDM_SS_OK
예제 #7
0
    def load_iges(self, path):
        """ Load an iges model """
        reader = IGESCAFControl_Reader()
        reader.SetColorMode(True)
        status = reader.ReadFile(path)
        if status != IFSelect_RetDone:
            raise ValueError("Failed to read: {}".format(path))

        if not reader.NbRootsForTransfer():
            raise ValueError("File has no shapes: {}".format(path))

        name = TCollection_ExtendedString("IGES-{}".format(id(self)))
        doc = TDocStd_Document(name)
        if not reader.Transfer(doc):
            raise ValueError("Failed to transfer: {}".format(path))

        return self._process_doc(doc)
예제 #8
0
파일: xde.py 프로젝트: trelau/AFEM
    def open(self, fn):
        """
        Open a document.

        :param str fn: The filename.

        :return: *True* if opened, *False* if not.
        :rtype: bool
        """
        if not fn.endswith(self._ext):
            fn += self._ext

        txt = TCollection_ExtendedString(fn)
        status, self._doc = self._app.Open(txt, self._doc)
        if status != PCDM_ReaderStatus.PCDM_RS_OK:
            return False
        self._init_tool()
        return True
예제 #9
0
def to_string(_string):
    from OCCT.TCollection import TCollection_ExtendedString
    return TCollection_ExtendedString(_string)
예제 #10
0
from OCCT.TDocStd import TDocStd_Document
from OCCT.XCAFDoc import (XCAFDoc_DocumentTool_ShapeTool,
                          XCAFDoc_DocumentTool_ColorTool,
                          XCAFDoc_DocumentTool_LayerTool,
                          XCAFDoc_DocumentTool_MaterialTool)
from OCCT.STEPCAFControl import STEPCAFControl_Reader
from OCCT.IFSelect import IFSelect_RetDone
from OCCT.TDF import TDF_LabelSequence

from OCC.Display.SimpleGui import init_display

filename = '../assets/models/as1_pe_203.stp'
_shapes = []

# create an handle to a document
doc = TDocStd_Document(TCollection_ExtendedString("pythonocc-doc"))

# Get root assembly
shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
l_colors = XCAFDoc_DocumentTool_ColorTool(doc.Main())
l_layers = XCAFDoc_DocumentTool_LayerTool(doc.Main())
l_materials = XCAFDoc_DocumentTool_MaterialTool(doc.Main())

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

status = step_reader.ReadFile(filename)
if status == IFSelect_RetDone: