Problems with SVG imports whith Rectangles

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
tobiasfalk
Posts: 91
Joined: Fri Feb 05, 2021 2:35 pm

Problems with SVG imports whith Rectangles

Post by tobiasfalk »

I do not know if this is a Problem of FreeCAD TD or Qt but when importing SVG's and the rectangle with is set in mm the size in FreeCAF TD is way of.
The top is with the with writen without a unit:
Problem.JPG
Problem.JPG (21.84 KiB) Viewed 1442 times

Code: Select all

<rect x="5mm" y="2.5mm" width="10" height="5"/>
The bottom is with mm as unit:

Code: Select all

<rect x="5mm" y="2.5mm" width="10mm" height="5mm"/>
Last edited by tobiasfalk on Sat Mar 18, 2023 11:13 am, edited 1 time in total.
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: Problems with SVH imports whith Rectangles

Post by chrisb »

tobiasfalk wrote: Sat Mar 18, 2023 9:04 am when importing SVG's and
Please correct the title in case you mean "SVG".
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Problems with SVG imports whith Rectangles

Post by wandererfan »

tobiasfalk wrote: Sat Mar 18, 2023 9:04 am I do not know if this is a Problem of FreeCAD TD or Qt but when importing SVG's and the rectangle with is set in mm the size in FreeCAF TD is way of.
Hard to say without the svg file to look at, but my guess would be that the lines are not using mm as the unit, so they use px.
Attachments
rectInMMLineNoUnit.png
rectInMMLineNoUnit.png (19.3 KiB) Viewed 1317 times
User avatar
tobiasfalk
Posts: 91
Joined: Fri Feb 05, 2021 2:35 pm

Re: Problems with SVG imports whith Rectangles

Post by tobiasfalk »

Here are the two files that I used, the only diference is the line that I showed in the firts kommend, the FreeCAD Projektfile and two pictures to display it a bit better.
In the FreeCAD File and the TD Page I added a 5mm Cube to show that all the other things are scaled correctly, for this the page sclae is 1:1.
1.JPG
1.JPG (89.15 KiB) Viewed 1291 times
2.JPG
2.JPG (37.52 KiB) Viewed 1291 times
Here is the whole SVG Code for those two:
Resistor_mmAsWithAndHight:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<svg width="20mm" height="10mm" version="1.1" viewBox="0 0 20mm 10mm" xmlns="http://www.w3.org/2000/svg">
    <description    name="Resistor"
                    designator="R"
                    description="This is the Simbol the normal resistor"                    
                    name-alias="Widerstand"
                    symbol-alias="Resistor_US.svg"/>
    <g stroke="#000000" fill="none" stroke-width=".35mm" stroke-linecap="round">
        <rect x="5mm" y="2.5mm" width="10mm" height="5mm"/>
        <line x1="0mm" x2="5mm" y1="5mm" y2="5mm" />
        <pin pin="1" x="0mm" y="5mm" type="electric" e-type="passiv"/>
        <line x1="15mm" x2="20mm" y1="5mm" y2="5mm" />
        <pin pin="2" x="20" y="5" type="electric" e-type="passiv"/>
    </g>
</svg>
Resistor_noUnitAsWithAndHight:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<svg width="20mm" height="10mm" version="1.1" viewBox="0 0 20mm 10mm" xmlns="http://www.w3.org/2000/svg">
    <description    name="Resistor"
                    designator="R"
                    description="This is the Simbol the normal resistor"                    
                    name-alias="Widerstand"
                    symbol-alias="Resistor_US.svg"/>
    <g stroke="#000000" fill="none" stroke-width=".35mm" stroke-linecap="round">
        <rect x="5mm" y="2.5mm" width="10" height="5"/>
        <line x1="0mm" x2="5mm" y1="5mm" y2="5mm" />
        <pin pin="1" x="0mm" y="5mm" type="electric" e-type="passiv"/>
        <line x1="15mm" x2="20mm" y1="5mm" y2="5mm" />
        <pin pin="2" x="20" y="5" type="electric" e-type="passiv"/>
    </g>
</svg>
The FreeCAD version I used:

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.2.29177 +426 (Git)
Build type: Release
Branch: (HEAD detached from 0.20.2)
Hash: 930dd9a76203a3260b1e6256c70c1c3cad8c5cb8
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: German/Germany (de_DE)
Installed mods: 
  * 3DfindIT 1.2.0
  * A2plus 0.4.56a
  * AirPlaneDesign 0.4.0
  * Assembly3 0.11.4
  * Assembly4 0.11.10
  * CADExchanger
  * cadquery_module
  * CurvedShapes 1.0.4
  * dxf-library
  * DynamicData 2.46.0
  * ExplodedAssembly
  * fasteners 0.3.40
  * fcgear 1.0.0
  * FeedsAndSpeeds 0.5.0
  * FEM_FrontISTR 0.1.0
  * FreeCAD_Electric
  * FreeCAD_Schematics
  * GDML 2.0.0
  * kicadStepUpMod 10.11.7
  * Plot 2022.4.17
  * pyrate
  * Render 2022.2.0
  * sheetmetal 0.2.56
  * Ship 2022.4.11
  * SteelColumn
  * ThreadProfile 1.82.0
  * timber
  * trails 2022.1.0
Attachments
Resistor_mmAsWithAndHight.svg
(823 Bytes) Downloaded 27 times
Resistor_noUnitAsWithAndHight.svg
(819 Bytes) Downloaded 26 times
problem.FCStd
(21.13 KiB) Downloaded 25 times
User avatar
tobiasfalk
Posts: 91
Joined: Fri Feb 05, 2021 2:35 pm

Re: Problems with SVG imports whith Rectangles

Post by tobiasfalk »

As problem check I also opened both of them in Firefox and Edge:
Left: Resistor_mmAsWithAndHight; Right: Resistor_noUnitAsWithAndHight
3.JPG
3.JPG (63.22 KiB) Viewed 1284 times
4.JPG
4.JPG (40.6 KiB) Viewed 1284 times
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Problems with SVG imports whith Rectangles

Post by wandererfan »

tobiasfalk wrote: Sun Mar 19, 2023 5:38 pm
It is getting late here - are we investigating the size of the resistor body or the leads not being attached to the body? :?
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Problems with SVG imports whith Rectangles

Post by wandererfan »

tobiasfalk wrote: Sun Mar 19, 2023 5:38 pm
I don't know enough about Svg to explain it, but I managed to make a symbol that comes very close to being 10 x 5.
10mmResistor.png
10mmResistor.png (5.35 KiB) Viewed 1141 times
Attachments
Resistor_10x5mm.svg
(846 Bytes) Downloaded 27 times
User avatar
tobiasfalk
Posts: 91
Joined: Fri Feb 05, 2021 2:35 pm

Re: Problems with SVG imports whith Rectangles

Post by tobiasfalk »

The Problem is with the interpretation of the with and height. If a mm is in the with or hight it should be interprated as mm and if not as px. The problem is that if no unit is set than it is interprated as mm and if mm is added the size is multiplyed by 3.7795, witch is the ratio betwen px and mm. This is why I added the Pictures of how Edge and Firefox interprates them.
User avatar
tobiasfalk
Posts: 91
Joined: Fri Feb 05, 2021 2:35 pm

Re: Problems with SVG imports whith Rectangles

Post by tobiasfalk »

This dous not occur for example with cirles and there radius(r):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<svg width="20mm" height="10mm" version="1.1" viewBox="0 0 20mm 10mm" xmlns="http://www.w3.org/2000/svg">
    <description    name="Voltmeter"
                    designator="V"
                    description="This is the Simbol for a voltmeter"/>
    <g stroke="#000000" fill="none" stroke-width=".35mm" stroke-linecap="round">
        <circle cx="10mm" cy="5mm" r="5mm" stroke="black" />
        <text x="10mm" y="7.6mm" font-family="osifont" font-size="7mm" fill="black" stroke="black" text-anchor="middle" always-horizontal="true">V</text>
        <line x1="0mm" x2="5mm" y1="5mm" y2="5mm" />
        <pin pin="1" x="0mm" y="5mm" type="electric" e-type="passiv"/>
        <line x1="15mm" x2="20mm" y1="5mm" y2="5mm" />
        <pin pin="2" x="20" y="5" type="electric" e-type="passiv"/>
    </g>
</svg>
The line of the cirle:

Code: Select all

<circle cx="10mm" cy="5mm" r="5mm" stroke="black" />
5.JPG
5.JPG (34.12 KiB) Viewed 1094 times
User avatar
wandererfan
Veteran
Posts: 6238
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Problems with SVG imports whith Rectangles

Post by wandererfan »

If I remove the scaling code, and just set the scale to 1.0, I get this:
Resistor_noScaling.png
Resistor_noScaling.png (16.27 KiB) Viewed 966 times
which looks like 12 x 6 instead of 10 x 5.
Post Reply