Force user to select a special subobject (face, line, vertex)

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Force user to select a special subobject (face, line, vertex)

Post by mariwan »

Have you ever used 3D Wings? There are some icons that let you easily avoid selecting wrong (face, line or vertex) when you click an object.
Please look at the picture. You can choose if you want to select an object, a face, a line or a vertex when you are clicking to the object.
I would like to have that in my workbench .. either if there is existing functionality or I have to think how I can achieve that.
I tried google I couldn't find an answer. I might be wrong but I need your help thanks.
Attachments
Wings_Selecting_mechanism.jpg
Wings_Selecting_mechanism.jpg (29.86 KiB) Viewed 875 times
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: Force user to select a special subobject (face, line, vertex)

Post by davidosterberg »

This is possible. For example, in PartDesign certain commands control what you can select by using a the ReferenceSelection class. Have a look at
src/Mod/PartDesign/Gui/ReferenceSelection.cpp.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Force user to select a special subobject (face, line, vertex)

Post by mariwan »

Could this class help me?

Code: Select all

 addSelectionGate(...)
        addSelectionGate(String|Filter|Gate, resolve=1) -- activate the selection gate.
        The selection gate will prohibit all selections which do not match
        the given selection filter string.
         Examples strings are:
        'SELECT Part::Feature SUBELEMENT Edge',
        'SELECT Robot::RobotObject'
        
        You can also set an instance of SelectionFilter:
        filter = Gui.Selection.Filter('SELECT Part::Feature SUBELEMENT Edge')
        Gui.Selection.addSelectionGate(filter)
        
        And the most flexible approach is to write your own selection gate class
        that implements the method 'allow'
        class Gate:
          def allow(self,doc,obj,sub):
            return (sub[0:4] == 'Face')
        Gui.Selection.addSelectionGate(Gate())
mario52
Veteran
Posts: 4698
Joined: Wed May 16, 2012 2:13 pm

Re: Force user to select a special subobject (face, line, vertex)

Post by mario52 »

hi

see Macro_Select_Hovering this macro select a choice Face, Edge, Vertex hovering by the mouse.

Image

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
freedman
Veteran
Posts: 3472
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Force user to select a special subobject (face, line, vertex)

Post by freedman »

class SelObserver:
def addSelection(self,document, object, element, position):
try:
if element[0] == "E" or element[0] == "F" or element[0] == "V"

[0] is the first letter.Edge, Face, Vertex,
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Force user to select a special subobject (face, line, vertex)

Post by mariwan »

mario52 wrote: Sun Feb 21, 2021 9:22 pm hi
this macro select a choice Face, Edge, Vertex hovering by the mouse.
mario
HI Mario,
I tried your macro but it doesn't seems to work as it should.
I might be wrong but even with selecting one type, I could select the whole object, or something that wasn't chosen in the form.
Have you checked it using .19?
jtm2020hyo
Posts: 594
Joined: Wed Aug 12, 2020 1:24 am

Re: Force user to select a special subobject (face, line, vertex)

Post by jtm2020hyo »

In Blender this is called Selection Filters, this should be implemented in FreeCAD out the box
freedman
Veteran
Posts: 3472
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Force user to select a special subobject (face, line, vertex)

Post by freedman »

In my macros I get the selection/element and then do a "clearSelection, this keeps the main program from doing more highlights like it does with multiple selections of the same face, for instance. Once I'm done with the code I re-select the item. It's kind of a pain but you do get clean selections and single item selections. Also, if someone works on this you can get multiple call-backs to addSelection for one mouse click.
User avatar
mariwan
Posts: 469
Joined: Wed Jan 06, 2021 2:00 pm

Re: Force user to select a special subobject (face, line, vertex)

Post by mariwan »

freedman wrote: Mon Feb 22, 2021 6:30 am In my macros I get the selection/element and then do a "clearSelection, this keeps the main program from doing more highlights like it does with multiple selections of the same face, for instance. Once I'm done with the code I re-select the item. It's kind of a pain but you do get clean selections and single item selections. Also, if someone works on this you can get multiple call-backs to addSelection for one mouse click.
Thanks for your input. This is the first time someone else confirm that remove-callback is not working well. If you try my workbench you will see that placing some of the Primitive objects causes problem for FreeCAD, or the callback is still functioning while I remove them.
mario52
Veteran
Posts: 4698
Joined: Wed May 16, 2012 2:13 pm

Re: Force user to select a special subobject (face, line, vertex)

Post by mario52 »

hi

my macro work without click on mouse only fly over (survoler) the arrow on object for select wire, face or vertex (checkBox checked)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply