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

A forum dedicated to the Draft, Arch and BIM workbenches development.
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

Postby derek-v-s » Mon May 13, 2019 12:44 am

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

Postby derek-v-s » Mon May 13, 2019 12:55 am

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
Site Admin
Posts: 12046
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

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

Postby yorik » Mon May 13, 2019 10:28 pm

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

Postby derek-v-s » Tue May 14, 2019 11:08 pm

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
Site Admin
Posts: 12046
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

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

Postby yorik » 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
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

Postby derek-v-s » Thu May 16, 2019 5:56 am

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

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

Postby FATHI RAMMAH » Sun May 19, 2019 1:14 pm

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: 270
Joined: Sat Jan 05, 2019 11:46 am
Contact:

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

Postby Moult » Sun May 19, 2019 9:30 pm

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
Site Admin
Posts: 12046
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels, Belgium
Contact:

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

Postby yorik » Mon May 20, 2019 2:42 pm

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