Skip to content

Commit b482f27

Browse files
Fix: IGES test and resolve pythonocc deprecation warnings (#286)
* fix: issue 285 and some deprecation from pythonocc * fix: ignore trailing whitespace in IGES tests for macOS compatibility * fix: relax IGES test length check for cross-platform compatibility
1 parent 95c7bdf commit b482f27

File tree

2 files changed

+40
-26
lines changed

2 files changed

+40
-26
lines changed

pygem/cad/cad_deformation.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
1414
BRepBuilderAPI_MakeWire,
1515
BRepBuilderAPI_MakeEdge,
1616
BRepBuilderAPI_NurbsConvert)
17-
from OCC.Core.BRep import BRep_Tool, BRep_Tool_Curve
17+
from OCC.Core.BRep import BRep_Tool
1818
from OCC.Core.Geom import Geom_BSplineCurve, Geom_BSplineSurface
1919
from OCC.Core.GeomConvert import (geomconvert_SurfaceToBSplineSurface,
20-
geomconvert_CurveToBSplineCurve,
20+
geomconvert,
2121
GeomConvert_CompCurveToBSplineCurve)
2222
from OCC.Core.gp import gp_Pnt
23-
from OCC.Core.BRepTools import breptools_OuterWire
23+
from OCC.Core.BRepTools import breptools
2424
from OCC.Core.IFSelect import IFSelect_RetDone
2525
from OCC.Core.Interface import Interface_Static_SetCVal
2626
from OCC.Core.STEPControl import (STEPControl_Writer, STEPControl_Reader,
2727
STEPControl_AsIs)
2828
from OCC.Core.IGESControl import (IGESControl_Writer, IGESControl_Reader,
29-
IGESControl_Controller_Init)
29+
IGESControl_Controller)
3030

3131

3232
class CADDeformation():
@@ -138,7 +138,7 @@ def write_shape(filename, shape):
138138
"""
139139
def write_iges(filename, shape):
140140
""" IGES writer """
141-
IGESControl_Controller_Init()
141+
IGESControl_Controller.Init()
142142
writer = IGESControl_Writer()
143143
writer.AddShape(shape)
144144
writer.Write(filename)
@@ -181,7 +181,7 @@ def _bspline_surface_from_face(self, face):
181181
# GeomSurface obtained from Nurbs face
182182
surface = BRep_Tool.Surface(nurbs_face)
183183
# surface is now further converted to a bspline surface
184-
bspline_surface = geomconvert_SurfaceToBSplineSurface(surface)
184+
bspline_surface = geomconvert.SurfaceToBSplineSurface(surface)
185185
return bspline_surface
186186

187187
def _bspline_curve_from_wire(self, wire):
@@ -216,10 +216,10 @@ def _bspline_curve_from_wire(self, wire):
216216
nurbs_edge = nurbs_converter.Shape()
217217

218218
# here we extract the underlying curve from the Nurbs edge
219-
nurbs_curve = BRep_Tool_Curve(nurbs_edge)[0]
219+
nurbs_curve = BRep_Tool.Curve(nurbs_edge)[0]
220220

221221
# we convert the Nurbs curve to Bspline curve
222-
bspline_curve = geomconvert_CurveToBSplineCurve(nurbs_curve)
222+
bspline_curve = geomconvert.CurveToBSplineCurve(nurbs_curve)
223223

224224
# we can now add the Bspline curve to the composite wire curve
225225
composite_curve_builder.Add(bspline_curve, self.tolerance)
@@ -448,7 +448,7 @@ def __call__(self, obj, dst=None):
448448
# using the outer wire, and then we can trim it
449449
# with the wires corresponding to all the holes.
450450
# the wire order is important, in the trimming process
451-
if wire == breptools_OuterWire(face):
451+
if wire == breptools.OuterWire(face):
452452
outer_wires.append(modified_wire)
453453
else:
454454
inner_wires.append(modified_wire)

tests/test_ffdcad.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,42 @@
1010
from pygem.cad import CADDeformation
1111

1212

13-
1413
class TestFFDCAD(TestCase):
1514

15+
def extract_floats(self, lines):
16+
"""
17+
Extract all numeric values from IGES file content.
18+
19+
This helper function parses a list of IGES file lines and returns
20+
a flattened numpy array of all floating-point numbers, ignoring
21+
line breaks, empty lines, and non-numeric text.
22+
23+
IGES files often wrap data lines differently on different platforms.
24+
By flattening all numeric values into a single array, this function enables reliable numerical comparison of IGES files regardless of
25+
line wrapping or minor formatting differences.
26+
"""
27+
all_values = []
28+
for line in lines:
29+
if not line.strip():
30+
continue
31+
parts = line.strip().split(',')[:-1]
32+
for p in parts:
33+
try:
34+
all_values.append(float(p))
35+
except ValueError:
36+
pass
37+
return np.asarray(all_values)
38+
1639
def test_ffd_iges_pipe_mod_through_files(self):
1740
ffd = FFD(None,30,30,30,1e-4)
1841
ffd.read_parameters(
1942
filename='tests/test_datasets/parameters_test_ffd_iges.prm')
2043
ffd('tests/test_datasets/test_pipe.iges', 'test_pipe_result.iges')
2144
with open('test_pipe_result.iges', "r") as created, \
2245
open('tests/test_datasets/test_pipe_out_true.iges', "r") as reference:
23-
ref = reference.readlines()[5:]
24-
cre = created.readlines()[5:]
25-
self.assertEqual(len(ref),len(cre))
26-
for i in range(len(cre)):
27-
ref_ = np.asarray(ref[i].split(',')[:-1], dtype=float)
28-
cre_ = np.asarray(cre[i].split(',')[:-1], dtype=float)
29-
np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
46+
ref_data = self.extract_floats(reference.readlines()[5:])
47+
cre_data = self.extract_floats(created.readlines()[5:])
48+
np.testing.assert_array_almost_equal(cre_data, ref_data, decimal=6)
3049
self.addCleanup(os.remove, 'test_pipe_result.iges')
3150

3251
def test_ffd_iges_pipe_mod_through_topods_shape(self):
@@ -39,13 +58,9 @@ def test_ffd_iges_pipe_mod_through_topods_shape(self):
3958
CADDeformation.write_shape('test_pipe_hollow_result.iges', mod_shape)
4059
with open('test_pipe_hollow_result.iges', "r") as created, \
4160
open('tests/test_datasets/test_pipe_hollow_out_true.iges', "r") as reference:
42-
ref = reference.readlines()[5:]
43-
cre = created.readlines()[5:]
44-
self.assertEqual(len(ref),len(cre))
45-
for i in range(len(cre)):
46-
ref_ = np.asarray(ref[i].split(',')[:-1], dtype=float)
47-
cre_ = np.asarray(cre[i].split(',')[:-1], dtype=float)
48-
np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
61+
ref_data = self.extract_floats(reference.readlines()[5:])
62+
cre_data = self.extract_floats(created.readlines()[5:])
63+
np.testing.assert_array_almost_equal(cre_data, ref_data, decimal=6)
4964
self.addCleanup(os.remove, 'test_pipe_hollow_result.iges')
5065

5166
"""
@@ -64,5 +79,4 @@ def test_ffd_step_pipe_mod_through_files(self):
6479
cre_ = np.asarray(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", cre[i]),dtype=float)
6580
np.testing.assert_array_almost_equal(cre_, ref_, decimal=6)
6681
self.addCleanup(os.remove, 'test_pipe_result.step')
67-
"""
68-
82+
"""

0 commit comments

Comments
 (0)