Detect when external geo is selected in Sketcher

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Detect when external geo is selected in Sketcher

Post by freedman »

Does anyone know how I would go about detecting this, I know when I'm in Sketcher but how would I know if external geo selecting is active? I was hoping to do something to help select external geo.
Thanks
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Detect when external geo is selected in Sketcher

Post by abdullah »

freedman wrote: Sat Jun 19, 2021 8:26 pm Does anyone know how I would go about detecting this, I know when I'm in Sketcher but how would I know if external geo selecting is active? I was hoping to do something to help select external geo.
Thanks
I not a Python guy, but I think power users will need a more complete explanation to know what you are referring to exactly.

Do you want to know if a specific tool (command) is active? This is, if the user has clicked the external link geometry tool in the toolbar?
Do you want to set a filter to only select external geometry?
Do you want to know if geometry selected is external geometry?
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Detect when external geo is selected in Sketcher

Post by freedman »

Do you want to know if a specific tool (command) is active? This is, if the user has clicked the external link geometry tool in the toolbar?
This is it exactly.

I only work with macros so it would be a python thing for me. I don't think this your department :) , this has got to be a Gui, App, Qt thing. I will work this out another way, sorry for the interruption.
Thank you
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Detect when External Geo is selected in Sketcher

Post by freedman »

I still have an issue. Detecting when External geo is selected all worked great by detecting the mouse click on the icon. Now, is there a way to know when the user has cleared external geo? Is there a Python way to get Sig, Flag, bool or something to trigger on.

I believe this would be a (internal to Sketcher) operation, updating the status of flags. I could probably use when the cursor returns to a standard pointer or no tools are currently selected, something like that.
Thanks
abdullah wrote: Sun Jun 20, 2021 4:03 am ping
Last edited by freedman on Mon Jun 21, 2021 5:33 pm, edited 2 times in total.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Detect when external geo is selected in Sketcher

Post by onekk »

Sorry if this could seem a joke, but sometimes, the right question led to the right answer.

Maybe my guess is wrong, but maybe it could address the problem, as reading this thread it seems that the "point" is not so "clear"

Usually you could check the state of a button "pressed" "not pressed".

(don't take the word as commands)

the correct question now behave like:

How to retrieve the status of the "external geo" button?

In this way you have to find the proper widget and check for the correct property, sadly to retrieve a Qt Widget you have to do some assumptions, if you know the name it is as simple to write:

Code: Select all

wid = self.tabw.findChild(QtCore.QObject, 'object_name')
and then check:

Code: Select all

wid.isDown()
According to this page is possible to check the pressed state:

https://doc.qt.io/qtforpython-5/PySide2 ... .isChecked

More generally these are the Widgets:

https://doc.qt.io/qtforpython-5/PySide2 ... .QtWidgets


Note that FreeCAD use a slightly different hierarchy from PySide2 as it translate the QtWidgets to be "compatible" to the old Pyside 1.x scheme to mantain retro compatibility.

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Detect when external geo is selected in Sketcher

Post by freedman »

I have tried every flag that I could, within reason. I have the signal for External Geo selected, I need the de-selection.

isChecked, isDown, isEnabled, isModal, checkStateSet, click..... nothing seems to reflect the change in state.

I was hoping this would work; "disconnectNotify" , but no.

It seems the only way to know what flags are updated is to ask the coder or go search the source file of Sketcher.
Thanks
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Detect when external geo is selected in Sketcher

Post by freedman »

I have considered looking at the cursor pointer, it changes when Exterrnal geo is selected and not. This could be a good choice because many of Sketchers functions change the cursor pointer. That looks hard.

From a logic standpoint Sketcher uses the ESC key/Right mouse click/select some else to exit External Geo, I was hoping not to go down that path, trying to keep it simple.
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Detect when external geo is selected in Sketcher

Post by onekk »

try to put some code, so maybe some kindly guy could try to recreate the condition and test something.

It is difficult to cope with complex things in an abstract way.

This is the main reason why in many coding forum, no answer are given if there is no a MWE (Minimal working Example) that show the problem, so it could be reproduced and some test could be done.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
freedman
Veteran
Posts: 3441
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Detect when external geo is selected in Sketcher

Post by freedman »

It is difficult to cope with complex things in an abstract way.
I get that. :)
Here is a macro that works. Best way to use; open any model, open a sketch and just leave it open. Run the macro and click on any feature in the tree, this will start the connection and a 1 sec timer that prints the status from the timer. You can click on the External geo icon and it will report.

Thank you
Attachments
10020_short.FCMacro
(2.94 KiB) Downloaded 27 times
heda
Veteran
Posts: 1348
Joined: Sat Dec 12, 2015 5:49 pm

Re: Detect when external geo is selected in Sketcher

Post by heda »

freedman wrote: Mon Jun 21, 2021 6:19 pm From a logic standpoint Sketcher uses the ESC key/Right mouse click/select some else to exit External Geo, I was hoping not to go down that path, trying to keep it simple.
probably easier than you think, and why not use pivy for the exit?
- qt for toolbar button
- set your own flag, and hook up a pivy observer (the flag implies that you need to roll your own class for the whole thing)
- once esc-key or right-click is detected, do your thing and then flip the flag & unhook the observer

should be pretty straight forward...
Code_snippets#Observe_mouse_events_in_the_3D_viewer_via_Python
Code_snippets#Display_keys_pressed_and_Events_command
Pivy (example of unhook on the fly...)
Last edited by heda on Tue Jun 22, 2021 9:43 pm, edited 1 time in total.
Post Reply