Issue with SVG export

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!
Shack
Posts: 34
Joined: Thu Jun 22, 2017 6:19 pm

Re: Issue with SVG export

Postby Shack » Tue Jun 11, 2019 11:46 pm

Alright, after some digging I have now found something which appears to be a fix.
https://github.com/FreeCAD/FreeCAD/blob ... /getSVG.py
Line 274:
if round(edge.Curve.Axis.getAngle(drawing_plane_normal),2) == 0:
If I change this as so:
if round(edge.Curve.Axis.getAngle(drawing_plane_normal),2) in [0, 3.14]:
now all my SVG exports are working perfectly.
I tried some of my complex stepfiles which has failed before and did -> 2D projection -> export SVG, and everything seems perfect!

only thing im wondering, is this the actual bug, or shouldn't the 2D projection make the angles in the first place?

I will make a PR tomorrow when I have some more time.
openBrain
Posts: 1959
Joined: Fri Nov 09, 2018 5:38 pm

Re: Issue with SVG export

Postby openBrain » Wed Jun 12, 2019 8:39 am

Shack wrote:
Tue Jun 11, 2019 11:46 pm
Alright, after some digging I have now found something which appears to be a fix.
Woh ! Congrats for your tenacity on this. ;)

However I think your patch isn't totally correct.
Functionally, the goal of line 274 is to determine if the circle is parallel to flattening plane, in order to know if it shall be exported as a circle or an ellipse.
From my short first review, it looks like one property doesn't return the expected value. IMO
  • Either "Axis" returns the direction of AngleXU instead of perpendicular vector
  • Or "getAngle" returns the AngleXU itself instead of a calculated angle between circle normal & projection plane normal
This would need some extra investigations to propose a correct PR. ;)

I can do that later on the day. Or feel free to do it yourself if you have some spare time. :)
Shack
Posts: 34
Joined: Thu Jun 22, 2017 6:19 pm

Re: Issue with SVG export

Postby Shack » Wed Jun 12, 2019 9:10 am

Thanks! :P this has been bugging me for years.

I figured this probably wasn't the correct way to fix it :)

If you have time to help investigate that would be great!
I'm just interested in getting it fixed properly :)

Thanks for your help
openBrain
Posts: 1959
Joined: Fri Nov 09, 2018 5:38 pm

Re: Issue with SVG export

Postby openBrain » Wed Jun 12, 2019 1:39 pm

OK, some steps forward. :)
Here what I get when using your example file and selecting the circle then running :

Code: Select all

>>> Gui.Selection.getSelectionEx()[0].SubObjects[0].Curve.Axis.getAngle(App.Vector(0,0,1))
3.141592653589793
Float number computation at work I guess. :lol:

So I think the line #274 could be easily patched like this :

Code: Select all

if round(edge.Curve.Axis.getAngle(drawing_plane_normal) % math.pi, 2) == 0:
No time ATM to test, but I'll do when possible. Good thing if you can test this patch on your side too. ;)
Shack
Posts: 34
Joined: Thu Jun 22, 2017 6:19 pm

Re: Issue with SVG export

Postby Shack » Wed Jun 12, 2019 2:41 pm

thanks! Ill have a look at it later :)

meanwhile have a look at line 158 in getSVG.py

Code: Select all

if round(c.Axis.getAngle(drawing_plane_normal),2) in [0, 3.14]:
openBrain
Posts: 1959
Joined: Fri Nov 09, 2018 5:38 pm

Re: Issue with SVG export

Postby openBrain » Wed Jun 12, 2019 3:17 pm

Indeed it actually works. This is same behavior, but looks less readable to me. While probably being more efficient at CPU usage.
Both works I guess. Let you choose which one you want to include in the PR. ;)
openBrain
Posts: 1959
Joined: Fri Nov 09, 2018 5:38 pm

Re: Issue with SVG export

Postby openBrain » Wed Jun 12, 2019 6:57 pm

Shack wrote:
Wed Jun 12, 2019 2:41 pm
thanks! Ill have a look at it later :)

meanwhile have a look at line 158 in getSVG.py

Code: Select all

if round(c.Axis.getAngle(drawing_plane_normal),2) in [0, 3.14]:
I tested and both works fine. Probably for consistency, it's better to keep the same (i.e. your first patch proposal).
Would you make the ticket & PR, or should I do it ?
Shack
Posts: 34
Joined: Thu Jun 22, 2017 6:19 pm

Re: Issue with SVG export

Postby Shack » Wed Jun 12, 2019 7:19 pm

I made a PR now
https://github.com/FreeCAD/FreeCAD/pull/2258
should a ticket also be made on the bug tracker?
openBrain
Posts: 1959
Joined: Fri Nov 09, 2018 5:38 pm

Re: Issue with SVG export

Postby openBrain » Wed Jun 12, 2019 7:45 pm

I don't know. Let's ask someone that probably knows. ;)
Kunda1 wrote:
Fri Oct 12, 2018 12:36 pm
Ping
@Kunda1, should a bug ticket also be filled in the case of a PR ?
User avatar
Kunda1
Posts: 5518
Joined: Thu Jan 05, 2017 9:03 pm

Re: Issue with SVG export

Postby Kunda1 » Thu Jun 13, 2019 1:39 am

openBrain wrote:
Wed Jun 12, 2019 7:45 pm
should a bug ticket also be filled in the case of a PR ?
Nope, not necessary. In fact it's not encouraged anymore. Thanks for asking :D
Though it is important to notify the folks maintaining the 0.19 changelog in https://forum.freecadweb.org/viewtopic.php?f=10&t=34586
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features