Import SVG Bug?

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Post Reply
jdabbs003
Posts: 26
Joined: Thu Oct 23, 2014 6:23 pm

Import SVG Bug?

Post by jdabbs003 » Sat Oct 03, 2020 3:50 pm

I'm attempting to import the svg code below and extrude it into a solid. However, when I import the file, which is a closed path with 4 arcs and two lines, FreeCAD breaks it up into four open paths. I've tried a few variations, using A and L, a and l, with and without translate, etc. The result is always the same.

<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" width="100mm" height="100mm" viewBox="0 0 100 100">
<defs>
<style>
.cls-1 {
fill: none;
stroke: #231f20;
stroke-miterlimit: 10;
}
</style>
</defs>
<path class="cls-1" d="M 27.5 35 A 9 19 0 0 0 36.5 16 A 9 51 0 0 0 27.5 -35 L -27.5 -35 A 9 51 0 0 0 -36.5 16 A 9 19 0 0 0 -27.5 35 Z"/>
</svg>

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
Syres
Posts: 831
Joined: Thu Aug 09, 2018 11:14 am

Re: Import SVG Bug?

Post by Syres » Sat Oct 03, 2020 4:25 pm

jdabbs003 wrote:
Sat Oct 03, 2020 3:50 pm
I'm attempting to import the svg code below and extrude it into a solid. However, when I import the file, which is a closed path with 4 arcs and two lines, FreeCAD breaks it up into four open paths.
Unfortunately as I found out recently while carrying out a very complex SVG import from Inkscape 1.01 there seems to have been a change in the construction of the SVG files. If I import/load a Inkscape 1.01 file into version 0.92.4 it will open correctly but saving it in 0.92.4 as a Plain SVG results in a file that FreeCAD does not always construct correctly. In the past a file created in 0.92.4 was a reliable workflow, this caused me close on 14 hours work reconstructing the SVG from scratch, the Inkscape devs are not on my Xmas card list to say the least.

Below is the SVG that will import correctly into FreeCAD, you'll notice a significant difference in the xml:

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="73.0mm" height="70.0mm" viewBox="54.540000 -78.680000 73.000000 70.000000" xmlns="http://www.w3.org/2000/svg" version="1.1">
<g id="Sketch001" transform="scale(1,-1)">
<path id="Sketch001_w0000"  d="M 63.540000000000006 78.68 C 61.42853557423195 78.84493894101419 58.93340007004436 73.88857529288455 57.17426318828601 63.74431834110994 C 55.38408817456327 53.775807885158336 54.51006368319523 39.64026489180611 54.540000000000006 27.68 C 54.510063683195256 23.225690114503966 55.38408817456319 17.960624110539545 57.174263188286034 14.246843933037578 C 58.93340007004433 10.46763233119056 61.428535574231965 8.620027233426459 63.540000000000006 8.68 L 118.54 8.68 C 120.65146442576807 8.62002723342645 123.14659992995567 10.467632331190561 124.905736811714 14.246843933037587 C 126.69591182543678 17.960624110539555 127.56993631680479 23.22569011450398 127.54 27.68000000000002 C 127.5699363168047 39.64026489180615 126.69591182543692 53.77580788515833 124.90573681171395 63.74431834110995 C 123.14659992995585 73.88857529288461 120.65146442576794 78.84493894101418 118.54 78.68 L 63.540000000000006 78.68 " stroke="#231f20" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
<title>b'Sketch001'</title>
</g>
</svg>
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.4 (GitTag)
Build type: Release
Branch: releases/FreeCAD-0-18
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)

It's going to take a significant bit of debugging to get the FreeCAD importer to handle both correctly IMHO and yes it's the same for me using:

OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22474 (Git)
Build type: Release
Branch: master
Hash: a44f8ffd427fa9b23b1f00dbf62d66cd152cd774
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
vocx
Posts: 5206
Joined: Thu Oct 18, 2018 9:18 pm

Re: Import SVG Bug?

Post by vocx » Sat Oct 03, 2020 4:47 pm

Syres wrote:
Sat Oct 03, 2020 4:25 pm
...
It's going to take a significant bit of debugging to get the FreeCAD importer to handle both correctly IMHO ...
I concur with this assessment.

The code for importing SVG needs to be revised in the Draft Workbench, the importSVG.py file primarily. I've been doing a few fixes here and there, but it needs to be thoroughly checked to make sure old code still works as intended.

And maybe we need to test with SVG files coming from different sources, as I suspect most testing is done with Inkscape files just because it's what is available to the free software community. Maybe they don't follow the standard, or they do, but our code doesn't handle that part very well.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
jdabbs003
Posts: 26
Joined: Thu Oct 23, 2014 6:23 pm

Re: Import SVG Bug?

Post by jdabbs003 » Sun Oct 04, 2020 2:38 pm

Thanks for the answers.

t seems like the arc directive (A or a) blows it up. Without those, it works. Unfortunately for this situation, I really need to import the arcs.
jdabbs003
Posts: 26
Joined: Thu Oct 23, 2014 6:23 pm

Re: Import SVG Bug?

Post by jdabbs003 » Mon Oct 05, 2020 12:45 pm

So it turns out bezier curves (in my case, c and s) work okay. I was able to move the path from elliptic arcs to bezier curves and get close enough that everybody is okay with the "new design" and we're moving forward. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest