> 
> If you're on Windows, download the latest binary from 
> http://www.pythonocc.org/Releases/daily. If you're on Linux/MacOsX, the 
> XCAFPrs module was added yesterday (rev. 234). Be sure you're up-to-date 
> with latest subversion repositoy revision.

OK. Got it. (I was at rev. 233). 

I've got it working! (more by trial and error than anything else). See
attached demo.

Bryan


import wx
import os

#edit this as necessary
os.environ['CSF_GraphicShr'] = "/usr/local/lib/libTKOpenGl.so"

from wxDisplay import GraphicsCanva3D

from OCC import XCAFApp, TDocStd, TCollection,\
        XCAFDoc, BRepPrimAPI, Quantity, TopLoc, gp,\
        TPrsStd, XCAFPrs
        
#
# 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)

app = wx.App()
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

#
# 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()

app.MainLoop()
_______________________________________________
Pythonocc-users mailing list
Pythonocc-users@gna.org
https://mail.gna.org/listinfo/pythonocc-users

Reply via email to