I circumvented the problem by modifying OCCViewer.py. I removed the
OCCViewer.Viewer3d inheritance of OCC.Visualization and directly called the
OCC.Visualization equivalents within OCCViewer.Viewer3d itself, being very
careful to call handles shortly after an object's creation. Unfortunately,
this
fix only works for Viewer3d. Viewer2d and NISVisualization3d will still have
the problem.
Anyway, now you can run wxViewer3d under threads. I can open multiple Viewer
windows under ipython and interact with each separately. If there is great
demand to get similar improvements to Viewer2d, let me know, and I'll work on
them. Make sure the demand is real, though. Despite the brevity of the code,
it took a lot of time to find a solution.
For those interested, the code changes follow. (I can't test the Windows
version, but Linux works for sure.) Interestingly enough, a full change to all
viewers would remove the need for the OCC.Visualization module, I think. I'll
wait a couple days to hear if there's demand for the other Viewers. If not,
and
pending Thomas's approval, I'll submit these fixes to the 0.6 release early
next
week.
- Charles
class Viewer3d(BaseDriver):
def __init__(self, window_handle ):
BaseDriver.__init__(self,window_handle)
self.selected_shape = None
def Create(self, create_default_lights = True):
# Set up the OCC hooks
if sys.platform == 'win32':
gd = OCC.Graphic3d.Graphic3d_WNTGraphicDevice()
window = OCC.WNT.WNT_Window(gd, self._window_handle >> 16,
self._window_handle & 0xffff)
window.SetFlags(OCC.WNT.WDF_NOERASEBKGRND)
else:
if os.environ.has_key('DISPLAY'):
gd =
OCC.Graphic3d.Graphic3d_GraphicDevice(os.environ['DISPLAY'])
window = OCC.Xw.Xw_Window(gd.GetHandle(), self._window_handle
>>
16, self._window_handle & 0xffff, OCC.Xw.Xw_WQ_3DQUALITY)
else:
print "Please set the DISPLAY environment variable"
return
self.Viewer = OCC.V3d.V3d_Viewer(gd.GetHandle(),
OCC.TCollection.TCollection_ExtendedString('Viewer').ToExtString())
self.Viewer_handle = self.Viewer.GetHandle()
self.Viewer.Init()
self.View_handle = self.Viewer.CreateView()
self.View = self.View_handle.GetObject()
self.View.SetWindow(window.GetHandle())
if not window.IsMapped():
window.Map()
self.Context = OCC.AIS.AIS_InteractiveContext(self.Viewer_handle)
self.Context_handle = self.Context.GetHandle()
self.View.MustBeResized()
if create_default_lights:
self.Viewer.SetDefaultLights()
self.Viewer.SetLightOn()
self._inited = True
# nessecary for text rendering
try:
self._struc_mgr =
self.Context.MainPrsMgr().GetObject().StructureManager()
except:
pass
_______________________________________________
Pythonocc-users mailing list
[email protected]
https://mail.gna.org/listinfo/pythonocc-users