importSVG - Path generation Overhaul (#20749)

* add precision Parameter for importSVG to preferences

* rewrite svgpath import

reorganize the existing svg interpretation code snippets by dividing the responsibilities for data provision and actual shape generation.
That bears the opportunity to optimize the resulting construction data regarding consistency and precision.

* create cuts from inner paths

organize paths in a tree structure where completely contained paths are children of their sorrounding paths

In a second step the even depth paths are cut with their respective (uneven depth) children.

* move svg path import logic into its own module

* Restructure how the import result is controlled by preferences.

* reintroduce alternative transform function

Using transformGeometry() on shapes results in degenerations like lines mutating to bsplines of 1st order. For non-orthogonal Transformations this can't be avoided. But for orthogonal transformations (the majority) we can apply those transformations without degeneration.

The necessary function including fallback to transformGeometry() is already in the code but was disabled due to a regression.

See: https://tracker.freecad.org/view.php?id=2062

Associated commits: f045df1e 2509e59b d4f3cb72

I reactivate the code since the degeneration of paths seems a bigger issue to me than misformed svg files producing incorrect measurements. Degenrated paths are often the culprit for later arising 3D-calculation errors.

* avoid path degeneration by keeping scale transformations uniform

* repair style application on shapes

the style should be based on the configured svgstyle mode in the svgimport preferences.

* improve logging of face generation.

* refactor: rename _precision_step to _tolerance

naming according to example set in draft utils.

* fix: indentation

* spelling
This commit is contained in:
aprospero
2025-04-25 16:44:03 +02:00
committed by GitHub
parent ff92a96170
commit f3fe554af7
5 changed files with 997 additions and 605 deletions

View File

@@ -206,6 +206,29 @@ def precision():
return params.get_param("precision")
def svg_precision():
"""Return the precision value for SVG import from the parameter database.
It is the number of decimal places that a float will have.
Example
::
precision=5, 0.12345
precision=4, 0.1234
precision=3, 0.123
Due to floating point operations there may be rounding errors.
Therefore, this precision number is used to round up values
so that all operations are consistent.
By default the precision is 3 decimal places.
Returns
-------
int
params.get_param("svgPrecision")
"""
return params.get_param("svgPrecision")
def tolerance():
"""Return a tolerance based on the precision() value