Exemplo n.º 1
0
 def ShowAssembly(self, top_label):
     self.aisView = TPrsStd.TPrsStd_AISViewer().New(
         top_label, self.context.GetHandle())
     self.aisPres = TPrsStd.TPrsStd_AISPresentation().Set(
         top_label,
         XCAFPrs.XCAFPrs_Driver().GetID())
     self.aisPres.GetObject().Display(True)
def step_caf_import(event=None):
    #
    # First open and parse STEP file
    #
    reader = STEPCAFControl_Reader()
    reader.ReadFile(os.path.join(os.path.split(__file__)[0], 'test.stp'))
    #
    # Create the TDocStd document
    #
    h_doc = Handle_TDocStd_Document()
    #
    # Create the application: really *awfull* way to do that
    #
    #app = Handle_XCAFApp_Application().GetObject()
    app = GetApplication().GetObject()
    app.NewDocument(TCollection_ExtendedString("MDTV-CAF"), h_doc)
    #
    # Transfer
    #
    if not reader.Transfer(h_doc):
        print("Error")
    #
    # Get root assembly
    #
    doc = h_doc.GetObject()
    h_shape_tool = XCAFDoc_DocumentTool().ShapeTool(doc.Main())
    shape_tool = h_shape_tool.GetObject()
    # get the top level shapes
    l_label_shapes = TDF_LabelSequence()
    shape_tool.GetShapes(l_label_shapes)
    top_label = shape_tool.NewShape(
    )  #this is the "root" label for the assembly

    l_Colors = XCAFDoc_DocumentTool().ColorTool(doc.Main())
    #
    shapes = []
    for i in range(1, l_label_shapes.Length()):
        #print l_label_shapes.Value(i)
        shape = shape_tool.GetShape(l_label_shapes.Value(i))
        shapes.append(shape)

    ais_view = TPrsStd.TPrsStd_AISViewer().New(top_label,
                                               display.Context.GetHandle())
    ais_pres = TPrsStd.TPrsStd_AISPresentation().Set(
        top_label,
        XCAFPrs.XCAFPrs_Driver().GetID())
    ais_pres.GetObject().Display(True)

    display.Context.UpdateCurrentViewer()
    display.FitAll()
    print(shapes)
Exemplo n.º 3
0
def viewXDE(doc, aLabel, shape):
    frame = wx.Frame(None, -1, "OCC frame", size=(600, 700))
    canvas = GraphicsCanva3D(frame)
    frame.Show()
    wx.SafeYield()

    canvas.Init3dViewer()
    viewer = canvas._3dDisplay
    context = viewer.Context
    aisView = TPrsStd.TPrsStd_AISViewer().New(aLabel,
                                              viewer.Viewer.GetHandle())
    print aisView
    #    aisView.SetInteractiveContext(context.GetHandle())
    #    #viewer.DisplayShape(shape)
    aisPres = TPrsStd.TPrsStd_AISPresentation().Set(
        aLabel,
        XCAFPrs.XCAFPrs_Driver().GetID())
    aisPres.GetObject().Display(True)
    #context.SetDisplayMode(1)
    #aisView.GetObject().Update(doc.GetData().GetObject().Root())
    context.UpdateCurrentViewer()

    app.MainLoop()
def assembly(event=None):
    # Create the TDocStd document
    h_doc = TDocStd.Handle_TDocStd_Document()
    print("Empty Doc?", h_doc.IsNull())

    # Create the application
    app = XCAFApp.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())
    l_colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main())

    shape_tool = h_shape_tool.GetObject()
    colors = l_colors.GetObject()

    top_label = shape_tool.NewShape(
    )  #this is the "root" label for the assembly

    print("Is Assembly",
          shape_tool.IsAssembly(top_label))  # not yet, 'cos it's empty

    # Add some shapes
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
    box_label = shape_tool.AddShape(box, False)

    cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
    cyl_label = shape_tool.AddShape(cyl, False)

    # Add components as references to our shape
    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(100, 100, 100))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(200, 200, 200))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(150, 200, 100))
    loc = TopLoc.TopLoc_Location(tr)
    cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

    print("Is Assembly", shape_tool.IsAssembly(top_label))  # it is now...

    # Add some colors
    red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
    green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
    colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
    colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)

    # Set up AIS Presentation stuff (I don't understand this, but it kinda works)
    ais_view = TPrsStd.TPrsStd_AISViewer().New(top_label,
                                               display.Context.GetHandle())
    ais_pres = TPrsStd.TPrsStd_AISPresentation().Set(
        top_label,
        XCAFPrs.XCAFPrs_Driver().GetID())
    ais_pres.GetObject().Display(True)
    display.FitAll()
Exemplo n.º 5
0
tr.SetTranslation(gp.gp_Vec(150,200,100))
loc = TopLoc.TopLoc_Location(tr)
cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

print "Is Assembly", shape_tool.IsAssembly(top_label) #it is now...

#
#Add some colors
#
red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)

context = display.Context

#
# Set up AIS Presentation stuff (I don't understand this, but it kinda works)
#
aisView = TPrsStd.TPrsStd_AISViewer().New(top_label, context.GetHandle())

aisPres = TPrsStd.TPrsStd_AISPresentation().Set(top_label, XCAFPrs.XCAFPrs_Driver().GetID())
aisPres.GetObject().Display(True)

#context.UpdateCurrentViewer()
#canvas.ZoomAll(None)
display.FitAll()

loop()

Exemplo n.º 6
0
def step_export_layers_and_colors(event=None):
    r"""
    demo showing how to export step files with layers & colors.
    adapted from Bryan's names_shape_demo
    """

    # Create the TDocStd document
    h_doc = TDocStd.Handle_TDocStd_Document()
    print("Empty Doc?", h_doc.IsNull())

    # Create the application
    app = XCAFApp.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())
    l_colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main())
    l_layers = XCAFDoc.XCAFDoc_DocumentTool().LayerTool(doc.Main())

    shape_tool = h_shape_tool.GetObject()
    colors = l_colors.GetObject()
    layers = l_layers.GetObject()

    top_label = shape_tool.NewShape(
    )  # this is the "root" label for the assembly

    print("Is Assembly",
          shape_tool.IsAssembly(top_label))  # not yet, 'cos it's empty)

    # Add some shapes
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
    box_label = shape_tool.AddShape(box, False)

    cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
    cyl_label = shape_tool.AddShape(cyl, False)

    # Add components as references to our shape
    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(100, 100, 100))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(200, 200, 200))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(150, 200, 100))
    loc = TopLoc.TopLoc_Location(tr)
    cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

    print("Is Assembly", shape_tool.IsAssembly(top_label))  # it is now...

    # Add some colors
    red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
    green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
    colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
    colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)

    # Set the box on the 'box' layer, the cylinder on the 'cylinder' layer
    layers.SetLayer(box_comp1, TCollection_ExtendedString('BOX'))
    layers.SetLayer(cyl_comp, TCollection_ExtendedString('CYLINDER'))

    # Set up AIS Presentation stuff (I don't understand this, but it kinda works)
    aisView = TPrsStd.TPrsStd_AISViewer().New(top_label,
                                              display.Context.GetHandle())
    aisPres = TPrsStd.TPrsStd_AISPresentation().Set(
        top_label,
        XCAFPrs.XCAFPrs_Driver().GetID())
    aisPres.GetObject().Display(True)
    display.FitAll()

    # write the stuff to STEP, with layers & colors
    work_session = XSControl_WorkSession()
    writer = STEPCAFControl_Writer(work_session.GetHandle(), False)
    writer.Transfer(h_doc, STEPControl_AsIs)
    pth = '.'
    print('writing STEP file')
    status = writer.Write(os.path.join(pth, 'step_layers_colors.step'))
    print('status:', status)
#
doc = h_doc.GetObject()
h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main())

shape_tool = h_shape_tool.GetObject()

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

count = l_LabelShapes.Length()
print "shape count", count
top_label = l_LabelShapes.Value(1)

context = display.Context

#
# Set up AIS Presentation stuff (I don't understand this, but it kinda works)
#
aisView = TPrsStd.TPrsStd_AISViewer().New(top_label, context.GetHandle())

aisPres = TPrsStd.TPrsStd_AISPresentation().Set(
    top_label,
    XCAFPrs.XCAFPrs_Driver().GetID())
aisPres.GetObject().Display(True)

#context.UpdateCurrentViewer()
#canvas.ZoomAll(None)
display.FitAll()

loop()