grid snap doesn't work when the grid point is covered

A forum dedicated to the Draft, Arch and BIM workbenches development.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
derek-v-s
Posts: 26
Joined: Mon May 06, 2019 9:47 pm
Contact:

grid snap doesn't work when the grid point is covered

Post by derek-v-s »

If a line or arc passes through a grid point, then a draft tool will not snap to that grid point.

This is apparently caused by the following condition in the Snapper.snap method:

Code: Select all

if self.snapInfo and "Component" in self.snapInfo:
    return self.snapToObject(lastpoint, active, constrain, eline, point, oldActive)
https://github.com/FreeCAD/FreeCAD/blob ... ap.py#L244

The condition is satisfied whenever there is an object under the cursor; consequently, the method returns before the grid snap code is run.

My first thought was to move the related grid snap code above all the other snap code. The problem is that snapToGrid doesn't clearly indicate when it fails to return a grid point: It just returns the point it received, instead of a grid point.

The solution seemed simple, just return None to indicate failure. However, that results in a crash. My temporary work-around is having it return Vector(0,0,1), which is an invalid 2D point.

Is there some connection with C++ code that requires the snapToGrid method to only return Vector objects?
User avatar
derek-v-s
Posts: 26
Joined: Mon May 06, 2019 9:47 pm
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by derek-v-s »

I went to verify that the crash message was unhelpful, and suddenly snapToGrid can return None without the program crashing. I'm not really sure what changed.

Anyhow... does that seem like the optimal solution?
Any other thoughts?
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by yorik »

I have no problem snapping to a grid point where a line passes, you must just place your cursor a little bit outside the line but close to the grid point... You might need to change a bit the snap radius with [ and ] keys... If your cursor is right on the line, then the line takes precedence. This seems to work well to me.

If you want to change this, I suggest then making it optional so users (me :D ) can keep the current behaviour

About the crash, indeed the rest of the code below expects snapToGrid to return a point. If you want to make it return None, then line 254 should probably be changed to something like this:

Code: Select all

point = self.snapToGrid(point)
if not point:
    return None
User avatar
derek-v-s
Posts: 26
Joined: Mon May 06, 2019 9:47 pm
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by derek-v-s »

Thanks!

What do you think about increasing the default snap radius a bit? With the current default it takes the finesse of a surgeon. ;-]

Two other potential projects:

- add snap radius to preferences -> draft -> grid and snapping
- prevent hotkey characters (i.e. [ and ]) from being added to the circle radius entry widget
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by yorik »

It is true that a new user might never find out about snapping radius... Indeed adding it to the working plane panel is a good idea. Done in git commit 76cf1ceb3
User avatar
derek-v-s
Posts: 26
Joined: Mon May 06, 2019 9:47 pm
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by derek-v-s »

:sunglasses:
FATHI RAMMAH
Posts: 71
Joined: Sun Jul 09, 2017 7:38 pm
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by FATHI RAMMAH »

yorik wrote: Wed May 15, 2019 10:49 pm It is true that a new user might never find out about snapping radius... Indeed adding it to the working plane panel is a good idea. Done in git commit 76cf1ceb3
hellow yorik
too many changes there to be modified ,can you put the tow files here ,thank you
User avatar
Moult
Posts: 321
Joined: Sat Jan 05, 2019 11:46 am
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by Moult »

By the way, have you tried "snap cycling"? Pressing the ` key will cycle between potential snap targets. This works for objects, so it may not work for grids, but it might help in other related scenarios.
I also blog about 3D rendering, architecture, software and other on thinkMoult.com. RSS / Atom feed available for your convenience.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: grid snap doesn't work when the grid point is covered

Post by yorik »

@FATHI RAMMAH you can take the complete files from github too, just navigate back to the main page
Post Reply