[Bug, SOLVED] Multiple elliptic cuts on different depth levels

Discussions about the development of the TechDraw workbench
aapo
Posts: 103
Joined: Mon Oct 29, 2018 6:41 pm

[Bug, SOLVED] Multiple elliptic cuts on different depth levels

Postby aapo » Mon Oct 29, 2018 7:04 pm

There appears to be a bug in the TechDraw module, when a part contains several elliptic cuts overlapping on different depth levels. Everything works fine, if there's only one elliptic cut in the projected part, but something seems to break if there are several ellipses. I hope the attached files shed some light to my not-so-clear explanation. If the part happens to be more complicated, everything may become really unintelligible in the TechDraw workbench.

Best regards,
Aapo


An example of a simple part triggering the problem, made with the PartDesign workbench:
FreeCAD_elliptic_shape.jpg
FreeCAD_elliptic_shape.jpg (54.08 KiB) Viewed 698 times
A problem occurs in the TechDraw workbench, and one part of the projected ellipses becomes a circle with weird radius and center.
FreeCAD_elliptic_shape_techdraw_bug.png
FreeCAD_elliptic_shape_techdraw_bug.png (53.01 KiB) Viewed 698 times
Attachments
FreeCAD_techdraw_bug.fcstd
(64.15 KiB) Downloaded 19 times
Last edited by aapo on Wed Nov 14, 2018 10:01 am, edited 2 times in total.
ian.rees
Posts: 696
Joined: Sun Jun 15, 2014 3:28 am
Contact:

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby ian.rees » Mon Oct 29, 2018 7:30 pm

Hi aapo, and welcome to FreeCAD! Thanks for your report too!

Please attach the version info from your copy of FreeCAD - there's a nice writeup in the Help forum about how to get the right info in the proper format.
aapo
Posts: 103
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby aapo » Mon Oct 29, 2018 8:56 pm

Thanks! And sorry about forgetting to post the version information. It's below, and I also tested with a recent Windows build from the website, and the same happened with that. Copy-paste from the about dialog:

EDIT: Hmm, I noticed that I've accidentally built against OCE 6.9 on Linux, instead of the OCCT 7.3 I should have. I'll rebuild and retest with the old libraries removed, but as I mentioned, the bug happened on the newest Windows build on the FreeCAD website, too.

OS: Debian GNU/Linux testing (buster)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15099 (Git)
Build type: Release
Branch: master
Hash: 1538a14eca0879be3d223930f7e5f78d4a24691c
Python version: 2.7.15+
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.9.1.oce-0.18
Locale: English/UnitedStates (en_US)
aapo
Posts: 103
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby aapo » Mon Oct 29, 2018 10:55 pm

I tested again on Linux with OCC version 7.3.0, and the same problem occurs.

OS: Debian GNU/Linux testing (buster)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15099 (Git)
Build type: Release
Branch: master
Hash: 1538a14eca0879be3d223930f7e5f78d4a24691c
Python version: 2.7.15+
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
User avatar
wandererfan
Posts: 3856
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby wandererfan » Tue Oct 30, 2018 12:31 am

aapo wrote:
Mon Oct 29, 2018 10:55 pm
I tested again on Linux with OCC version 7.3.0, and the same problem occurs.
Fix is building now. The problem was in the routine that tries to determine if a BSpline should be treated as a Circle.

Thanks for catching this one.

wf
User avatar
wandererfan
Posts: 3856
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby wandererfan » Tue Oct 30, 2018 1:00 pm

git commit 408c31634f merged to master branch.
User avatar
wandererfan
Posts: 3856
Joined: Tue Nov 06, 2012 5:42 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby wandererfan » Tue Oct 30, 2018 1:03 pm

weirdEllipseFixed.png
weirdEllipseFixed.png (16.25 KiB) Viewed 641 times
aapo
Posts: 103
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby aapo » Tue Oct 30, 2018 7:06 pm

Thanks for the fix! I can confirm that the fix in github also works for me, and I get basically the same, expected result after rebuilding.
aapo
Posts: 103
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby aapo » Wed Oct 31, 2018 11:35 pm

I'll revisit this subject slightly, as I believe there's another bug in the TechDraw module. With the same FCSTD example file as above, if one selects "Iso Count = 1" from the UI, the ellipses are again malformed:
FreeCAD_elliptic_shape_techdraw_iscircle2_bug.png
FreeCAD_elliptic_shape_techdraw_iscircle2_bug.png (42.63 KiB) Viewed 573 times

I wrote a small patch, where the crucial matter are the lines containing the checks for GeomAPI_ProjectPointOnCurve.NbPoint():

Code: Select all

@@ -739,9 +736,9 @@ TopoDS_Edge BSpline::isCircle2(bool& arc)
     projm.Init(pm, curve, f, l);
 
     // get projected points
-    gp_Pnt pc1 = proj1.NearestPoint();
-    gp_Pnt pc2 = proj2.NearestPoint();
-    gp_Pnt pcm = projm.NearestPoint();
+    gp_Pnt pc1 = (proj1.NbPoints()>0)?proj1.NearestPoint():p1;
+    gp_Pnt pc2 = (proj2.NbPoints()>0)?proj2.NearestPoint():p2;
+    gp_Pnt pcm = (projm.NbPoints()>0)?projm.NearestPoint():pm;
 
     // make 2 circles and find their radii
     gce_MakeCirc gce_circ1 = gce_MakeCirc(s,pc1,pcm);   //3 point circle
. As per https://www.opencascade.com/doc/occt-7. ... 831c9c114b the NbPoints() in GeomAPI_ProjectPointOnCurve always returns zero in failures (and apparently the class makes an expection with failed call to NearestPoint()?). Anyway, please feel free to use only this part of the patch or some other method to fix the problem, there are unnecessary changes in the patch as I poked at the problem. With the patch, the ellipses are again ok with more ISO points using "Iso Count = 1". I believe this bug affected many more cases, where the splines were small pieces or otherwise difficult for GeomAPI_ProjectPointOnCurve, which caused weird artifacts in some of my more complicated drawings.
FreeCAD_elliptic_shape_techdraw_iscircle2_bugfixed.png
FreeCAD_elliptic_shape_techdraw_iscircle2_bugfixed.png (44.01 KiB) Viewed 573 times
Here is the full patch. On an unrelated note, the git head build of FreeCAD TechDraw cannot make any dimensions for me; it always says "Select an object first" even though I have object and edge selected. Is this perhaps being fixed?
FreeCAD-TechDraw-isCircle2.patch.txt
(4.01 KiB) Downloaded 28 times
EDIT: I guess the proper way to fix this would be to catch the exception with

Code: Select all

try {
   ...
} catch(const StdFail_NotDone &e) {
   ... some cleanup ...
}
but I was a bit lazy.
aapo
Posts: 103
Joined: Mon Oct 29, 2018 6:41 pm

Re: [Bug?] Multiple elliptic cuts on different depth levels

Postby aapo » Sun Nov 04, 2018 8:57 am

It turns out that just catching the exception and returning an empty TopoDS_Edge on failure is enough, just like earlier in the same function if there are not enough poles on the spline. So I wrote a minimal patch to catch the exception, this will also fix the bug with just a few changes:

Code: Select all

diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp
index 0ceb5dac3..000b3fd6e 100644
--- a/src/Mod/TechDraw/App/Geometry.cpp
+++ b/src/Mod/TechDraw/App/Geometry.cpp
@@ -739,9 +739,14 @@ TopoDS_Edge BSpline::isCircle2(bool& arc)
     projm.Init(pm, curve, f, l);
 
     // get projected points
-    gp_Pnt pc1 = proj1.NearestPoint();
-    gp_Pnt pc2 = proj2.NearestPoint();
-    gp_Pnt pcm = projm.NearestPoint();
+    gp_Pnt pc1, pc2, pcm;
+    try {
+       pc1 = proj1.NearestPoint();
+       pc2 = proj2.NearestPoint();
+       pcm = projm.NearestPoint();
+    } catch(const StdFail_NotDone &e) {
+       return result;
+    }
 
     // make 2 circles and find their radii
     gce_MakeCirc gce_circ1 = gce_MakeCirc(s,pc1,pcm);   //3 point circle