Making constraint 'clear' when sketchHandler active

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
paddle
Veteran
Posts: 1364
Joined: Mon Feb 03, 2020 4:47 pm

Making constraint 'clear' when sketchHandler active

Post by paddle »

When a constrain is on top of a geometry, it makes the geometry difficult to select.
select cstr.png
select cstr.png (29.63 KiB) Viewed 2244 times
When you're in general edit mode it's good because you want to be able to select either constrain or geometry. But when you are using a constrain tool, then it can be annoying because you can't select easily the geometry as the constrain get preselected (as it's drawn on top). (while my picture is a simplistic example, when a sketch gets a lot of elements it gets fairly annoying.)

In ViewProviderSketcher::mousemove, I could easily add a 'ignore constrain' bool, as follow :

Code: Select all

if (Mode == STATUS_SKETCH_UseHandler) {
            //don't preselect constraints if a sketcher tool is being used. It seems there isn't any usecase to select constrain while a sketcher tool is active.
            //If there is then we need to add a parameter to not ignore.
            preselectChanged = detectAndShowPreselection(Point.get(), cursorPos, true /*ignore constraints*/);
        }
        else {
            preselectChanged = detectAndShowPreselection(Point.get(), cursorPos);
        }
Which makes the constrain impossible to preselect/highligth. However the underneath line still doesn't get selected. As the constrain still renders on top and apparantly prevent the detection of the line.

I went dipper in

Code: Select all

editCoinManager->detectPreselection
But it doesn't give more hints. Just that constrain is preselected in the first place only if no curves are found.

So it seems this doesn't trigger :

Code: Select all

        // checking for a hit in the curves
        if (tail == editModeScenegraphNodes.CurveSet[l]) {
            const SoDetail *curve_detail = Point->getDetail(editModeScenegraphNodes.CurveSet[l]);
            if (curve_detail && curve_detail->getTypeId() == SoLineDetail::getClassTypeId()) {
                // get the index
                int curveIndex = static_cast<const SoLineDetail *>(curve_detail)->getLineIndex();
                result.GeoIndex = coinMapping.getCurveGeoId(curveIndex, l);

                return result;
            }
        }
So it might need to check in deeper. But before spending so much time on it, does anyone know something on that?

edit: sorry my title is bad. It should be 'Making constrain clear to selection when sketchHandler is active'
User avatar
adrianinsaval
Veteran
Posts: 5534
Joined: Thu Apr 05, 2018 5:15 pm

Re: Making constraint 'clear' when sketchHandler active

Post by adrianinsaval »

is temporarily changing the rendering order an option?
User avatar
paddle
Veteran
Posts: 1364
Joined: Mon Feb 03, 2020 4:47 pm

Re: Making constraint 'clear' when sketchHandler active

Post by paddle »

adrianinsaval wrote: Wed Jan 19, 2022 3:19 pm is temporarily changing the rendering order an option?
Yes I think so, do you know how to do that?
User avatar
adrianinsaval
Veteran
Posts: 5534
Joined: Thu Apr 05, 2018 5:15 pm

Re: Making constraint 'clear' when sketchHandler active

Post by adrianinsaval »

unfortunately I don't
Syres
Veteran
Posts: 2891
Joined: Thu Aug 09, 2018 11:14 am

Re: Making constraint 'clear' when sketchHandler active

Post by Syres »

paddle wrote: Wed Jan 19, 2022 3:40 pm
adrianinsaval wrote: Wed Jan 19, 2022 3:19 pm is temporarily changing the rendering order an option?
Yes I think so, do you know how to do that?
Is the following link a helpful hint or causes more questions https://github.com/FreeCAD/FreeCAD/comm ... bb81043a81
openBrain
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Making constraint 'clear' when sketchHandler active

Post by openBrain »

paddle wrote: Wed Jan 19, 2022 3:40 pm Yes I think so, do you know how to do that?
IMO the best solution is to add a 'SoPickStyle' node in the scenegraph just above 'ConstraintGroup'.
Then when you activate an handler, you set its style value to 'SoPickStyle::UNPICKABLE'.
When deactivating the handler, you set it back to 'SoPickStyle::SHAPE'.

You can test it with following code (run it when a sketch is in edit mode) :

Code: Select all

from pivy import coin
er = Gui.ActiveDocument.ActiveView.getSceneGraph().getByName('EditingRoot').getByName('Sketch_EditRoot')
cg = er.getByName('ConstraintGroup')
ps = coin.SoPickStyle()
ps.style.setValue(ps.UNPICKABLE)
er.insertChild(ps, er.findChild(cg))
At this time constraints are no more selectable. To get this back, just :

Code: Select all

ps.style.setValue(ps.SHAPE)
You'll eventually have to add another SoPickStyle node with SHAPE value just after the 'ConstraintGroup' node so following nodes aren't disturbed by the changes.
openBrain
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Making constraint 'clear' when sketchHandler active

Post by openBrain »

Something like this ? https://github.com/0penBrain/FreeCAD/co ... 1899b7bc7b
consSelect.gif
consSelect.gif (436.57 KiB) Viewed 2093 times
User avatar
paddle
Veteran
Posts: 1364
Joined: Mon Feb 03, 2020 4:47 pm

Re: Making constraint 'clear' when sketchHandler active

Post by paddle »

Whoa this was quick !
Looking great from your gif.

It would be great if it's pushed to upstream :)
openBrain
Veteran
Posts: 9031
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Making constraint 'clear' when sketchHandler active

Post by openBrain »

paddle wrote: Wed Jan 19, 2022 5:45 pm Whoa this was quick !
Looking great from your gif.

It would be great if it's pushed to upstream :)
I added a link to the commit on my fork in my above post so you can eventually test and see if it matches your expectations.
If you think it does, I can push it as a PR to the master. ;)
EDIT : or I can push a draft PR if it's simpler for you to compile and test. ;)
User avatar
paddle
Veteran
Posts: 1364
Joined: Mon Feb 03, 2020 4:47 pm

Re: Making constraint 'clear' when sketchHandler active

Post by paddle »

openBrain wrote: Wed Jan 19, 2022 5:55 pm I added a link to the commit on my fork in my above post so you can eventually test and see if it matches your expectations.
If you think it does, I can push it as a PR to the master. ;)
EDIT : or I can push a draft PR if it's simpler for you to compile and test. ;)
Hmm I have no idea how to get your branch on my local git.
I'll search for it and try it! My new git challenge!
Post Reply