Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: svg export only works in the XY plane #13652

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jnweiger
Copy link

The export() method in Mod/Draft/importSVG.py assumes it is looking down from Z onto the XY plane. This works fine to export shapes parallel to that plan.

For flat or mostly flat objects that are aligned to the XZ or YZ plane, this exports only a thin line, as it looks sideways on the object. A general solution to this problem would e.g. use the draft WorkingPlane (or the current viewing direction).

This PR implements a minimalistic solution that works very well for exporting sketches oriented in one of the main three planes. We simply check which edge of the bounding box is shortest and construct a temporary working plane normal to that direction.

My usecase is 2D Designs for plotting or lasercutting. For this, the simple solution is just perfect, as I do not need to bother about the plan that a certain sketch was started at all.

The export() method in Mod/Draft/importSVG.py assumes it is looking down from Z onto the XY plane.
This works fine to export shapes parallel to that plan.

For flat or mostly flat objects that are aligned to the XZ or YZ plane, this exports only a thin line, as it looks sideways on the object.
A general solution to this problem would e.g. use the draft WorkingPlane (or the current viewing direction).

This PR implements a minimalistic solution that works very well for exporting sketches oriented in one of the main three planes.
We simply check which edge of the bounding box is shortest and construct a temporary working plane normal to that direction.

My usecase is 2D Designs for plotting or lasercutting. For this, the simple solution is just perfect, as I do not need to bother about the plan that a certain sketch was started at all.
@Roy-043
Copy link
Contributor

Roy-043 commented Apr 26, 2024

Your code makes assumptions that need not apply. A sketch can have any rotation, your code only works for sketches aligned with 3 standard planes.

@jnweiger
Copy link
Author

That is true. I was striving for a simple solution that gets there 99%. In the usecase of "someone draws a sketch to export it as SVG" it is almost always in one of the three orientations.

the general usecase of 'any rotation' is more complex.
a) The bounding box needs to be pulled in the rotated coordinate system.
b) assuming "we export one sketch" is also too simple.

  • it could be many sketches with different rotations
  • or not even sketches at all, any kind of flat or non-flat-wires ...
    That leads to headache, as there is apparently no single "always correct" rotatation.

Before I submit a complex PR involving more advanced logic/heuristics, I'd rather try with a simple one to get some feedback, maybe that is acceptable too. :-)

@Roy-043
Copy link
Contributor

Roy-043 commented Apr 27, 2024

I understand what you are saying, but the proposed solution has some obvious limitations. I don't think it is a 99% solution at all. For example a sketch created on the bottom face of a box would result in a mirrored SVG. Which may work if you are cutting (uncoated) sheet metal, but not if you are engraving a name plate. IMO it also makes sense to look at how the C++ DXF exporter handles multiple sketches. I think it just combines them (which does not necessarily make sense BTW).

@WandererFan
Copy link
Contributor

There is code in the c++ dxf exporter to get the normal of the sketch and project along that.

@sliptonic
Copy link
Member

@jnweiger Will you incorporate Wandererfan's suggestion and allow the export to use the sketch normal? Otherwise, this looks good.

@FEA-eng
Copy link
Contributor

FEA-eng commented May 13, 2024

Being able to export the sketches from the 3 base planes instead of 1 is nice but support for an arbitrary sketch location and orientation would be ideal. I assume that's what WandererFan's suggestion would allow?

@Roy-043
Copy link
Contributor

Roy-043 commented May 18, 2024

One very simple way to solve this issue (for sketches only) is to create a realigned new object for each sketch in a temporary document and export that. This would leave the rest of the original code intact. Other objects would still be processed in the 'old' way. Which matched the C++ DXF solution.

It's a bit of a hack perhaps: 😉

    tmp = []
    hidden_doc = FreeCAD.newDocument(name="hidden", hidden=True, temp=True)
    for obj in exportList:
        if obj.isDerivedFrom("Sketcher::SketchObject"):
            new = hidden_doc.addObject("Part::Part2DObjectPython")
            shp = obj.Shape.copy()
            shp.transformShape(obj.Placement.inverse().toMatrix())
            new.Shape = shp
            tmp.append(new)
        else:
            tmp.append(obj)
    exportList = tmp

@Roy-043 Roy-043 removed their request for review May 18, 2024 19:46
@chennes chennes marked this pull request as draft May 20, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WB Draft Related to the Draft Workbench
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants