diff --git a/pygem/cad/cad_deformation.py b/pygem/cad/cad_deformation.py index 6448b96c..b527e95e 100644 --- a/pygem/cad/cad_deformation.py +++ b/pygem/cad/cad_deformation.py @@ -14,19 +14,19 @@ BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge, BRepBuilderAPI_NurbsConvert) -from OCC.Core.BRep import BRep_Tool, BRep_Tool_Curve +from OCC.Core.BRep import BRep_Tool from OCC.Core.Geom import Geom_BSplineCurve, Geom_BSplineSurface from OCC.Core.GeomConvert import (geomconvert_SurfaceToBSplineSurface, - geomconvert_CurveToBSplineCurve, + geomconvert, GeomConvert_CompCurveToBSplineCurve) from OCC.Core.gp import gp_Pnt -from OCC.Core.BRepTools import breptools_OuterWire +from OCC.Core.BRepTools import breptools from OCC.Core.IFSelect import IFSelect_RetDone from OCC.Core.Interface import Interface_Static_SetCVal from OCC.Core.STEPControl import (STEPControl_Writer, STEPControl_Reader, STEPControl_AsIs) from OCC.Core.IGESControl import (IGESControl_Writer, IGESControl_Reader, - IGESControl_Controller_Init) + IGESControl_Controller) class CADDeformation(): @@ -138,7 +138,7 @@ def write_shape(filename, shape): """ def write_iges(filename, shape): """ IGES writer """ - IGESControl_Controller_Init() + IGESControl_Controller.Init() writer = IGESControl_Writer() writer.AddShape(shape) writer.Write(filename) @@ -181,7 +181,7 @@ def _bspline_surface_from_face(self, face): # GeomSurface obtained from Nurbs face surface = BRep_Tool.Surface(nurbs_face) # surface is now further converted to a bspline surface - bspline_surface = geomconvert_SurfaceToBSplineSurface(surface) + bspline_surface = geomconvert.SurfaceToBSplineSurface(surface) return bspline_surface def _bspline_curve_from_wire(self, wire): @@ -216,10 +216,10 @@ def _bspline_curve_from_wire(self, wire): nurbs_edge = nurbs_converter.Shape() # here we extract the underlying curve from the Nurbs edge - nurbs_curve = BRep_Tool_Curve(nurbs_edge)[0] + nurbs_curve = BRep_Tool.Curve(nurbs_edge)[0] # we convert the Nurbs curve to Bspline curve - bspline_curve = geomconvert_CurveToBSplineCurve(nurbs_curve) + bspline_curve = geomconvert.CurveToBSplineCurve(nurbs_curve) # we can now add the Bspline curve to the composite wire curve composite_curve_builder.Add(bspline_curve, self.tolerance) @@ -448,7 +448,7 @@ def __call__(self, obj, dst=None): # using the outer wire, and then we can trim it # with the wires corresponding to all the holes. # the wire order is important, in the trimming process - if wire == breptools_OuterWire(face): + if wire == breptools.OuterWire(face): outer_wires.append(modified_wire) else: inner_wires.append(modified_wire) diff --git a/tests/test_ffdcad.py b/tests/test_ffdcad.py index 998fc188..07b80cf3 100644 --- a/tests/test_ffdcad.py +++ b/tests/test_ffdcad.py @@ -10,9 +10,32 @@ from pygem.cad import CADDeformation - class TestFFDCAD(TestCase): + def extract_floats(self, lines): + """ + Extract all numeric values from IGES file content. + + This helper function parses a list of IGES file lines and returns + a flattened numpy array of all floating-point numbers, ignoring + line breaks, empty lines, and non-numeric text. + + IGES files often wrap data lines differently on different platforms. + By flattening all numeric values into a single array, this function enables reliable numerical comparison of IGES files regardless of + line wrapping or minor formatting differences. + """ + all_values = [] + for line in lines: + if not line.strip(): + continue + parts = line.strip().split(',')[:-1] + for p in parts: + try: + all_values.append(float(p)) + except ValueError: + pass + return np.asarray(all_values) + def test_ffd_iges_pipe_mod_through_files(self): ffd = FFD(None,30,30,30,1e-4) ffd.read_parameters( @@ -20,13 +43,9 @@ def test_ffd_iges_pipe_mod_through_files(self): ffd('tests/test_datasets/test_pipe.iges', 'test_pipe_result.iges') with open('test_pipe_result.iges', "r") as created, \ open('tests/test_datasets/test_pipe_out_true.iges', "r") as reference: - ref = reference.readlines()[5:] - cre = created.readlines()[5:] - self.assertEqual(len(ref),len(cre)) - for i in range(len(cre)): - ref_ = np.asarray(ref[i].split(',')[:-1], dtype=float) - cre_ = np.asarray(cre[i].split(',')[:-1], dtype=float) - np.testing.assert_array_almost_equal(cre_, ref_, decimal=6) + ref_data = self.extract_floats(reference.readlines()[5:]) + cre_data = self.extract_floats(created.readlines()[5:]) + np.testing.assert_array_almost_equal(cre_data, ref_data, decimal=6) self.addCleanup(os.remove, 'test_pipe_result.iges') def test_ffd_iges_pipe_mod_through_topods_shape(self): @@ -39,13 +58,9 @@ def test_ffd_iges_pipe_mod_through_topods_shape(self): CADDeformation.write_shape('test_pipe_hollow_result.iges', mod_shape) with open('test_pipe_hollow_result.iges', "r") as created, \ open('tests/test_datasets/test_pipe_hollow_out_true.iges', "r") as reference: - ref = reference.readlines()[5:] - cre = created.readlines()[5:] - self.assertEqual(len(ref),len(cre)) - for i in range(len(cre)): - ref_ = np.asarray(ref[i].split(',')[:-1], dtype=float) - cre_ = np.asarray(cre[i].split(',')[:-1], dtype=float) - np.testing.assert_array_almost_equal(cre_, ref_, decimal=6) + ref_data = self.extract_floats(reference.readlines()[5:]) + cre_data = self.extract_floats(created.readlines()[5:]) + np.testing.assert_array_almost_equal(cre_data, ref_data, decimal=6) self.addCleanup(os.remove, 'test_pipe_hollow_result.iges') """ @@ -64,5 +79,4 @@ def test_ffd_step_pipe_mod_through_files(self): cre_ = np.asarray(re.findall(r"[+-]? *(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?", cre[i]),dtype=float) np.testing.assert_array_almost_equal(cre_, ref_, decimal=6) self.addCleanup(os.remove, 'test_pipe_result.step') - """ - + """ \ No newline at end of file