pythonocc-contrib
pythonocc-contrib copied to clipboard
IFC simple viewer improvements
@jf--- and @aothms I submitted a PR to pythonocc-core (see https://github.com/tpaviot/pythonocc-core/pull/211) that implements a callback mechanism at the OCC level (and not at the gui level). This way, it's much simple to add basic features to the IFC viewer without any gui programming (for instance display the properties list of the selected shape, compute its volume, its surface etc.)
Honestly, not too crazy about this one... Using slots / signals is a lot more efficient...
For instance, I'd advocate an approach where the signal would push the selected entity to the slot. When you use threading, now you need to apply a lock such that your selection wont chance until processed... Also, you need to grab the selection, while that is known ( repeat of effort )
For simpler use cases this is fine, but for larger apps signals / slots are the way to go. being able to connect / disconnect from signals, or sending signals to multiple slots is key, what was the method sending the signals etc... all of this is key when building on top of OCCViewer
Callbacks are a garantueed pain when you start to use threading / or when lots of parallel events are happening... signals / slots work across threads...
Hmmm... this is advocating a bad pattern... To build GUI functionality, data driven event handling is a painful way to go about it... I'm sitting on the blisters of this anti-pattern, since that's exactly what I did for our robotics app ( through traitsui... trying to sidestep learning Qt was a bad idea... ) have been learning about this the hard way ;)
So this is a mixed bag... For developing what we have been discussing this morning, callbacks are pure evil IMO... For simple functionality... you dont have to deal with Qt, but it for certain doesnt scale when you do something non-trivial.
( wrt signals / slots I really dont care about WX, true :fearful: )
<<< here's an example handling selection with signal / slots >>>
Hit "g" to compute linear properties for Solid, Face, Edge, Vertex...
wow, very long comment, no time today to discuss al that.
Please @jf--- take care of the qt4 or 5 stuff, with QML and so on, do whatever you want with events/slots or anything qt related.
on my side, I've been trying to go further, step by step, with the SimpleGui so far.
@jf--- ok with your signal/slot example, please submit a PR to pythonocc-core. I agree it's more robust than what I did. It's at the GUI level whereas my callbadck mechanism is at the occ level and GUI independant. I think both approaches are complementary.
I pushed a modification, and renamed the script name as ifc_viewer_simplegui.py. There also should be another ifc_viewer_qt.py with a more advanced GUI. Feel free to, for instance, copy/paste/modify the over_painter_example so that properties are displayed over the shape rather than in the console.
hi Thomas,
yeah, sorry for the long winding comment... yes, they serve different purposes, signals / slots are important for larger apps, for straightfwd scripts there's nothing against a simple callback. this example served to underpin our discussion on application architecture for more sophisticated GUI stuff.
I like the overpainting idea, that's great... I might need to jump through a few loops, since I prefer to make a small demo that does this, but with QML / pyqt5.