sketch Validation tool bug

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

sketch Validation tool bug

Post by easyw-fc »

Hi @abdullah
abdullah wrote: ping
I found an issue on Validation of Sketches...
Here a test file
sk2.FCStd
(46.73 KiB) Downloaded 31 times
The sketch has 1 (hidden) line geometry with length equal to zero because of some previous constrains applied...
The resulting sketch is no more editable and if I try to fix it with the Validation tool, the sketch will be wiped out...
here a screencast of the issue
phpBB [video]

It seems that the solver cannot handle coincident points of lines (lines with zero length) and the Validating tool will simply remove all the geometries to try to fix it...

my FC details:
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15190 (Git)
Build type: Release
Branch: master
Hash: c18785fdb31e378500440de23dcf648a2c79dc5f
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: sketch Validation tool bug

Post by abdullah »

easyw-fc wrote: Tue Nov 13, 2018 11:43 am Hi @abdullah

I found an issue on Validation of Sketches...
I am not sure what has happened, but in the file you have uploaded, the sketch has no geometry:
>>> App.ActiveDocument.Sketch.GeometryCount
0L
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: sketch Validation tool bug

Post by abdullah »

easyw-fc wrote: Tue Nov 13, 2018 11:43 am It seems that the solver cannot handle coincident points of lines (lines with zero length) and the Validating tool will simply remove all the geometries to try to fix it...
If you happen to have such a file, I will be willing to give it a try.

If that is the case, we could try to prevent the situation and in addition, we could add a "test" to the validator for zero size lines... maybe with arcs is the same problem... maybe geometries having start and ending points at the same position...
chrisb
Veteran
Posts: 54166
Joined: Tue Mar 17, 2015 9:14 am

Re: sketch Validation tool bug

Post by chrisb »

abdullah wrote: Tue Nov 13, 2018 6:12 pm If that is the case, we could try to prevent the situation and in addition, we could add a "test" to the validator for zero size lines... maybe with arcs is the same problem... maybe geometries having start and ending points at the same position...
I haven't seen any questions concerning zero length lines but we used to have them every now and then. They had never been on purpose so I think it might be sensible to check this already in Sketcher. Perhaps just asking for confirmation, because I don't like the idea of having too much automatism that cannot be overruled.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: sketch Validation tool bug

Post by easyw-fc »

abdullah wrote: Tue Nov 13, 2018 6:12 pm If you happen to have such a file, I will be willing to give it a try.

If that is the case, we could try to prevent the situation and in addition, we could add a "test" to the validator for zero size lines... maybe with arcs is the same problem... maybe geometries having start and ending points at the same position...
1) open the sk3-1.FCStd file
2) convert the 'Shape' to Sketch using the Draft makeSketch button (this is creating an editable Sketch)
(note I have 'Auto constraints' and 'Avoid reduntant auto constraints' checked)
3) Save the file to i.e. sk3-2.FCStd file
4) close it
5) open it back in FC and you will have an empty geometry Sketch (but with a visible/clickable edges)
(Note I get 'Both points are equal' as an error message at the report view)
sk3-1.FCStd
(43.8 KiB) Downloaded 25 times
sk3-2.FCStd
(46.76 KiB) Downloaded 27 times
chrisb wrote: Tue Nov 13, 2018 6:47 pm Perhaps just asking for confirmation, because I don't like the idea of having too much automatism that cannot be overruled.
This could be done in the Validating tool or even in Constrainator tool or in both
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: sketch Validation tool bug

Post by abdullah »

easyw-fc wrote: Tue Nov 13, 2018 8:27 pm
abdullah wrote: Tue Nov 13, 2018 6:12 pm If you happen to have such a file, I will be willing to give it a try.

If that is the case, we could try to prevent the situation and in addition, we could add a "test" to the validator for zero size lines... maybe with arcs is the same problem... maybe geometries having start and ending points at the same position...
1) open the sk3-1.FCStd file
2) convert the 'Shape' to Sketch using the Draft makeSketch button (this is creating an editable Sketch)
(note I have 'Auto constraints' and 'Avoid reduntant auto constraints' checked)
3) Save the file to i.e. sk3-2.FCStd file
4) close it
5) open it back in FC and you will have an empty geometry Sketch (but with a visible/clickable edges)
(Note I get 'Both points are equal' as an error message at the report view)

sk3-1.FCStd
sk3-2.FCStd
Yup. I can reproduce, this one is a nice one...
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: sketch Validation tool bug

Post by abdullah »

abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: sketch Validation tool bug

Post by abdullah »

wmayer wrote: ...ping...
A line with two identical endpoints (zero length line) is saved onto a file (they are not fully identical, but yes within the tolerance we save). When restoring, this line which is part of a sketch, throws an exception and the whole sketch is lost.

xml:

Code: Select all

<Geometry type="Part::GeomLineSegment"><Construction value="0"/><LineSegment StartX="-105.000000000000" StartY="6.000000000000" StartZ="0.000000000000" EndX="-105.000000000000" EndY="6.000000000000" EndZ="0.000000000000"/></Geometry>
Screenshot_20181115_161721.png
Screenshot_20181115_161721.png (33.04 KiB) Viewed 1704 times
Trace:
#0 Part::GeomLineSegment::setPoints() at /home/abdullah/github/free-cad-code/src/Mod/Part/App/Geometry.cpp:3663
#1 Part::GeomLineSegment::Restore() at /home/abdullah/github/free-cad-code/src/Mod/Part/App/Geometry.cpp:3726
#2 Part::PropertyGeometryList::Restore() at /home/abdullah/github/free-cad-code/src/Mod/Part/App/PropertyGeometryList.cpp:182
#3 App::PropertyContainer::Restore() at /home/abdullah/github/free-cad-code/src/App/PropertyContainer.cpp:278
#4 App::ExtensionContainer::Restore() at /home/abdullah/github/free-cad-code/src/App/ExtensionContainer.cpp:307
#5 Part::Part2DObject::Restore() at /home/abdullah/github/free-cad-code/src/Mod/Part/App/Part2DObject.cpp:243
#6 Sketcher::SketchObject::Restore() at /home/abdullah/github/free-cad-code/src/Mod/Sketcher/App/SketchObject.cpp:6547
Things that I can think of:
1. PREVENT: Check at saving that two points are at least within the tolerance gp::Resolution(), if not
1.1. Move the endpoint so that the distance is gp:Resolution() AND
1.2. Warn the user somehow?

2. RESILIENT: When arriving to such situation on loading:
2.1. Move the endpoint to that the distance is gp:Resolution AND
2.2. Warn the user somehow?

Any nicer idea?
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: sketch Validation tool bug

Post by easyw-fc »

What I do in kicad to FreeCAD importing, is to remove zero length geometries.
Creating a minimum resolution length entity may add issues on the Sketcher to be i.e. fully constrained and then i.e extruded or used for part design generation.
May be we could add a warning message and eventually move the modified Geo to construction geometries or just drop it.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: sketch Validation tool bug

Post by abdullah »

easyw-fc wrote: Thu Nov 15, 2018 3:51 pm What I do in kicad to FreeCAD importing, is to remove zero length geometries.
Creating a minimum resolution length entity may add issues on the Sketcher to be i.e. fully constrained and then i.e extruded or used for part design generation.
May be we could add a warning message and eventually move the modified Geo to construction geometries or just drop it.
It is not really zero length, one can not create such line segment.

The problem is that the length is greater than gp::Resolution(), but higher than the resolution we use to save files.

The logical solution is either not to allow to create such segment (so one gets an error on creation), or to actually increase the resolution in the xml file. The former is "easy" to handle as it is only changing the existing test to the save resolution, but we will never have a line segment under the save resolution. The latter I do not know if it makes sense.

If we cannot change the python resolution and we still do not want to apply the former, then maybe one of the other solutions above is "sufficiently good".

...or maybe Werner comes with a better solution... ;)

EDIT: For some reason I said python resolution instead of save resolution.

EDIT: gp::Resolution() is 2.22e-308, I am positive we cannot increase the resolution of saving to that value. Currently the resolution for saving is 1e-12 (ZipStream.precision(12)).
Post Reply