Skip to content

Commit

Permalink
Merge 9e8ae7c into 827d208
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzncode committed Sep 3, 2023
2 parents 827d208 + 9e8ae7c commit 5c7acc3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cadquery/occ_impl/exporters/dxf.py
Expand Up @@ -8,6 +8,7 @@
from OCP.GeomConvert import GeomConvert
from OCP.gp import gp_Dir
from OCP.GC import GC_MakeArcOfEllipse
from OCP.TopAbs import TopAbs_Orientation
from typing_extensions import Self

from ...cq import Face, Plane, Workplane
Expand Down Expand Up @@ -199,9 +200,17 @@ def _dxf_line(edge: Edge) -> DxfEntityAttributes:
:return: dictionary of DXF entity attributes for creating a line
"""

if edge.wrapped.Orientation() == TopAbs_Orientation.TopAbs_FORWARD:
start = edge.startPoint()
end = edge.endPoint()
else:
start = edge.endPoint()
end = edge.startPoint()

return (
"LINE",
{"start": edge.startPoint().toTuple(), "end": edge.endPoint().toTuple(),},
{"start": start.toTuple(), "end": end.toTuple(),},
)

@staticmethod
Expand Down
18 changes: 18 additions & 0 deletions tests/test_exporters.py
Expand Up @@ -942,3 +942,21 @@ def test_dxf_ellipse_arc(tmpdir):

assert w2.val().isValid()
assert w2.val().Volume() == approx(math.pi * r ** 2 / 4)


def test_dxf_edge_iteration(tmpdir):

w1 = Workplane().box(50, 50, 1).edges("|Z and >XY").fillet(10)

dxf = exporters.dxf.DxfDocument()
dxf.add_layer("layer1", color=1)
dxf.add_shape(w1.section(0), "layer1")

fname = tmpdir.joinpath("edge_iteration1.dxf").resolve()
dxf.document.saveas(fname)

s1 = Sketch().importDXF(fname)
edges = s1.edges().vals()

for e1, e2 in zip(edges, edges[1:]):
assert (e2.startPoint() - e1.endPoint()).Length == approx(0.0)

0 comments on commit 5c7acc3

Please sign in to comment.