Skip to content

Commit 4eea193

Browse files
authored
Merge pull request #273 from mkofler96/main
added export check to splinepy/io/iges.py
2 parents b86fa64 + 264cdcc commit 4eea193

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

splinepy/io/iges.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
iges io.
33
"""
44
from splinepy import splinepy_core
5+
from splinepy.utils import log
56

67

78
def load(fname):
@@ -34,4 +35,29 @@ def export(fname, splines):
3435
--------
3536
None
3637
"""
37-
return splinepy_core.export_iges(fname, splines)
38+
try:
39+
return splinepy_core.export_iges(fname, splines)
40+
41+
except RuntimeError:
42+
# create empty valid spline array
43+
valid_splines = []
44+
# check if any spline contains volume elements
45+
for ispl, spline in enumerate(splines):
46+
if spline.para_dim > 2:
47+
log.warning(
48+
f"Skipping volumetric {type(spline)} at splines[{ispl}]"
49+
"which cannot be handled by the .iges file format \n"
50+
"To include this spline, use a boundary representation "
51+
"instead, by calling e.g. spline.extract.boundaries()"
52+
)
53+
elif spline.dim > 3:
54+
log.warning(
55+
f"Skipping high dim {type(spline)} at splines[{ispl}]"
56+
"which cannot be handled by the .iges file format."
57+
"iges supports up to dim=3."
58+
)
59+
else:
60+
valid_splines.append(spline)
61+
62+
if len(valid_splines) == 0:
63+
raise ValueError("No valid splines found in the given input")

tests/test_iges.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import tempfile
2+
3+
try:
4+
from . import common as c
5+
except BaseException:
6+
import common as c
7+
8+
9+
class IGESExportTest(c.unittest.TestCase):
10+
def test_iges_round_trip_bsplines(self):
11+
"""
12+
Test npz export-import routine
13+
"""
14+
bsp_el2 = c.splinepy.BSpline(
15+
degrees=[1, 1],
16+
control_points=[[0, 1], [1, 1], [0, 2], [1, 2]],
17+
knot_vectors=[[0, 0, 1, 1], [0, 0, 1, 1]],
18+
)
19+
nur_el3 = c.splinepy.NURBS(
20+
degrees=[1, 1],
21+
control_points=[[1, 1], [2, 1], [1, 2], [2, 2]],
22+
weights=[1, 1, 1, 1],
23+
knot_vectors=[[0, 0, 1, 1], [0, 0, 1, 1]],
24+
)
25+
26+
# Make it more tricky
27+
bsp_el2.elevate_degrees(0)
28+
bsp_el2.elevate_degrees(1)
29+
nur_el3.elevate_degrees(0)
30+
nur_el3.elevate_degrees(1)
31+
bsp_el2.insert_knots(1, [0.5])
32+
nur_el3.insert_knots(1, [0.5])
33+
34+
# Test output against input
35+
list_of_splines = [bsp_el2, nur_el3]
36+
with tempfile.TemporaryDirectory() as tmpd:
37+
tmpf = c.to_tmpf(tmpd)
38+
c.splinepy.io.iges.export(tmpf, list_of_splines)
39+
list_of_splines_loaded = c.splinepy.io.iges.load(tmpf)
40+
41+
# to compare we need 3d "bumped" splines of originals
42+
splines_in_3d = []
43+
for s in list_of_splines:
44+
tmp_s = s.copy()
45+
tmp_s.cps = c.np.hstack(
46+
[tmp_s.cps, c.np.zeros((len(tmp_s.cps), 1))]
47+
)
48+
splines_in_3d.append(tmp_s)
49+
50+
assert all(
51+
c.are_splines_equal(a, b)
52+
for a, b in zip(splines_in_3d, list_of_splines_loaded)
53+
)
54+
55+
56+
if __name__ == "__main__":
57+
c.unittest.main()

0 commit comments

Comments
 (0)