heda, I was hoping to find a standard method to use for Sketcher and Sketcher in general. I don't like using a work-around for something knowing that the next person that wants to do this will need to hack up something. What about all the other Sketcher icons.......
My long term goals are to get the FreeCAD GUI as good as it can be and as modifiably as I can get it, at some point I might need to build a branch but if I can get enough control then I can do it all in a macro. I really don't want to branch the source code.
I will read-up on pivy, maybe it's an option.
Thanks
Detect when external geo is selected in Sketcher
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Detect when external geo is selected in Sketcher
honourable goal, and all the best for the adventures ahead of you then.
Re: Detect when external geo is selected in Sketcher
Using left mouse button or ESC is a complexity of other issues. Esc is an option so I will need to monitor in Preferences, and then another way to exit External geo is to select any other icon in Sketcher, to do that I would need to monitor all the other icons. Simple is my best option or I will just bag the whole idea.
Re: Detect when external geo is selected in Sketcher
I do not know if it is possible to see from Python whether a command is active or not.
All functions have a command. Many commands have a drawsketchhandler. The latter is only in c++ inside ViewProviderSketch. I do not see how to get it from Python. This is why I am suggesting maybe the command is the way to go...
All functions have a command. Many commands have a drawsketchhandler. The latter is only in c++ inside ViewProviderSketch. I do not see how to get it from Python. This is why I am suggesting maybe the command is the way to go...
Re: Detect when external geo is selected in Sketcher
seems not to be prohibitive hard though, once the entry point to a cursor that actually changes is traced down...
this catches all that is going on in the 3d regarding mouse, and whole app for keystrokes as it looks,
and that should be more than halfway there
just did simplest detection of cursor that had a chance to work, and it seems like it does, could do cross diagonals or something (like whole pixmap) if not.
to make it work with different colour schemes, suppose one would have to create the recognition sum at start-up, and adjust for actual pixmap size for full robustness.
this does not take the initial entry to the mode when done through toolbar, but that you had sorted out already...
the code seems to behave as expected when using keystrokes,
but much less so when using toolbar,
so that needs attention to make it overall well behaved.
like hammering out needed flags, up/down events, etc.
although it is not as expected (for whatever reason, either qt or sketcher c) it seems to be consistent, and then it should be possible to figure it out.
Code: Select all
view = Gui.activeDocument().activeView()
viewqt = view.graphicsView()
#cursor = viewqt.cursor()
class ViewObserver3D:
"""3d view events with purpose to detect mouse cursor images"""
count = 0
externalgeo = sum((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4292214784, 3551592448, 0, 4292214784, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0)) # diagonal pixels of pixmap
def useraction(self, info):
up = info['State'] == 'UP'
if up:
self.count += 1
cursor = viewqt.cursor() # needs to be picked up every time
# eventtype = info['Type']
# print(eventtype)
if 'Key' in info:
print(info['Key'], cursor.pixmap())
else:
print(info['Button'], cursor.pixmap())
# unfortunately the pixmap id seems to be same
# so resorting to an arbitrary characteristic of pixmap
# might need tweaks to be a robust detection
pixm = cursor.pixmap()
if not pixm.isNull():
im = pixm.toImage()
pixsum = sum((im.pixel(i, i) for i in range(32)))
print(pixsum, pixsum == self.externalgeo)
## to see what is picked up
#im.save('/location/curico{}'.format(count))
observer = ViewObserver3D()
cb = view.addEventCallback('SoButtonEvent', observer.useraction)
#view.removeEventCallback('SoButtonEvent', cb)
Re: Detect when external geo is selected in Sketcher
I will look closer at that, maybe there is something unique. Thanks for the base-line code.