Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Maybe this image helps:
Two lines created from the center of a circle with their end snapped to the edge of the circle with Near snap:
Red circle: R = 1 mm
White line: L = 0.999990 mm
Black line: L = 0.996803 mm
Two lines created from the center of a circle with their end snapped to the edge of the circle with Near snap:
Red circle: R = 1 mm
White line: L = 0.999990 mm
Black line: L = 0.996803 mm
- Attachments
-
- circle-near-snap.png (4.84 KiB) Viewed 1212 times
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Hmm I see... The problem is indeed here:
https://github.com/FreeCAD/FreeCAD/blob ... r.py#L1051
The near point is actually the point returned by the 3D view...indeed we should project it onto the edge.
Basically I think get the snapped subelement like here:
https://github.com/FreeCAD/FreeCAD/blob ... er.py#L355
then project onto it.
I'll try to do that tomorrow, but if anyone feels like trying before that, go for it
https://github.com/FreeCAD/FreeCAD/blob ... r.py#L1051
The near point is actually the point returned by the 3D view...indeed we should project it onto the edge.
Basically I think get the snapped subelement like here:
https://github.com/FreeCAD/FreeCAD/blob ... er.py#L355
then project onto it.
I'll try to do that tomorrow, but if anyone feels like trying before that, go for it
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Hmm the case is more complex than I thought... Projecting onto the shape still gives a small offset
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
If accurate snap near can't be realized directly for curves, maybe this tool could automatically extend the line being snapped to a curve and trim it. Of course, this would have to be done internally, showing just the final result. I don't know if it makes sense in terms of coding, it's just a loose idea.
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Here is my solution. It still needs some work, but AFAICT the results are accurate (of course the usual floating point tolerances apply). Near snap should work for edges and faces, so please test with both.
Some other things that I have changed:
Instructions:
Some other things that I have changed:
- To snap to a Draft_Point, Draft_Snap_Endpoint has to be used instead of Draft_Snap_Near. This was done to make things compatible with snapping to points in a point cloud.
- The snapToPerpendicular function was simplified and should now work for all edges, but is still limited to finding only one point per edge.
- There was a strange behavior if the "Always snap (disable snap mod)" preference was set to off. Near snap would work without the need to press the Ctrl key. I have removed that (to simplify the code). I do not know if many users use Ctrl+Snap, and if some of them rely on this functionality in their workflow, but my guess is that there are very few.
Instructions:
- Look for /Mod/Draft/draftguitools/gui_snapper.py in your FreeCAD installation folder.
- Rename that file.
- Place the attached file in the same folder.
- Restart FreeCAD.
- Attachments
-
- gui_snapper.py
- (72.42 KiB) Downloaded 19 times
Last edited by Roy_043 on Sat Jun 25, 2022 9:48 am, edited 2 times in total.
- thomas-neemann
- Veteran
- Posts: 11958
- Joined: Wed Jan 22, 2020 6:03 pm
- Location: Osnabrück DE 🇩🇪
- Contact:
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
... Here are the questions I have:
1.
The Snapper has an active property. But AFAICT it is always set to True. What is its purpose?
https://github.com/FreeCAD/FreeCAD/blob ... er.py#L112
2.
What is the purpose of oldActive? When does the code linked to below run?
https://github.com/FreeCAD/FreeCAD/blob ... #L277-L283
https://github.com/FreeCAD/FreeCAD/blob ... #L505-L509
3.
Which objects are targeted here? It must be objects without faces, edges and vertexes that can be selected in the 3D view.
https://github.com/FreeCAD/FreeCAD/blob ... #L441-L446
1.
The Snapper has an active property. But AFAICT it is always set to True. What is its purpose?
https://github.com/FreeCAD/FreeCAD/blob ... er.py#L112
2.
What is the purpose of oldActive? When does the code linked to below run?
https://github.com/FreeCAD/FreeCAD/blob ... #L277-L283
https://github.com/FreeCAD/FreeCAD/blob ... #L505-L509
3.
Which objects are targeted here? It must be objects without faces, edges and vertexes that can be selected in the 3D view.
https://github.com/FreeCAD/FreeCAD/blob ... #L441-L446
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
This "active/inactive" mode was when Draft was always snapping,OR you had to press Ctrl to enable snapping. I don't think this is used a lot, though...
IIRC there were some modes that were able to override the active state. Therefore it had to be restored afterwards
IIRC again, there were objects with their coin nodes not properly implemented, for which the component string was blank
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Thanks for your answers. It seems better to leave those confusing bits in then.
https://github.com/FreeCAD/FreeCAD/pull/7132
https://github.com/FreeCAD/FreeCAD/pull/7132
Re: Issue #6613 - [Bug] Draft Snap Near is inaccurate when snapping to curves
Upon retesting I see that this code must be removed. In some cases it substitutes the projected, accurate, near point. We obviously need to avoid that. I'll update my PR.Roy_043 wrote: ↑Thu Jun 30, 2022 11:16 am 2.
What is the purpose of oldActive? When does the code linked to below run?
https://github.com/FreeCAD/FreeCAD/blob ... #L277-L283
https://github.com/FreeCAD/FreeCAD/blob ... #L505-L509