@@ -31,11 +31,21 @@ class IgesHandler(fh.FileHandler):
3131 It is equal to ['.iges', '.igs'].
3232 :cvar list control_point_position: index of the first NURBS control point (or pole)
3333 of each face of the iges file.
34+ :cvar float tolerance: tolerance for the construction of the faces and wires
35+ in the write function. Default value is 1e-6.
36+
37+ .. warning::
38+
39+ - For non trivial geometries it could be necessary to increase the tolerance.
40+ Linking edges into a single wire and then trimming the surface with the wire
41+ can be hard for the software, especially when the starting CAD has not been
42+ made for analysis but for design purposes.
3443 """
3544 def __init__ (self ):
3645 super (IgesHandler , self ).__init__ ()
3746 self .extension = ['.iges' , '.igs' ]
3847 self ._control_point_position = None
48+ self .tolerance = 1e-6
3949
4050
4151 def parse (self , filename ):
@@ -46,9 +56,6 @@ def parse(self, filename):
4656 the points of the mesh
4757 :rtype: numpy.ndarray
4858
49- .. todo::
50-
51- - specify when it works
5259 """
5360 self ._check_filename_type (filename )
5461 self ._check_extension (filename )
@@ -106,7 +113,7 @@ def parse(self, filename):
106113 return mesh_points
107114
108115
109- def write (self , mesh_points , filename ):
116+ def write (self , mesh_points , filename , tolerance = None ):
110117 """
111118 Writes a iges file, called filename, copying all the structures from self.filename but
112119 the coordinates. mesh_points is a matrix that contains the new coordinates to
@@ -121,6 +128,9 @@ def write(self, mesh_points, filename):
121128 self ._check_infile_instantiation (self .infile )
122129
123130 self .outfile = filename
131+
132+ if tolerance is not None :
133+ self .tolerance = tolerance
124134
125135 # init the ouput file writer
126136 writer = IGESControl_Writer ()
@@ -168,7 +178,7 @@ def write(self, mesh_points, filename):
168178 # construct the deformed wire for the trimmed surfaces
169179 wire_maker = BRepBuilderAPI_MakeWire ()
170180 tol = ShapeFix_ShapeTolerance ()
171- brep = BRepBuilderAPI_MakeFace (occ_face .GetHandle (), 1e-4 ).Face ()
181+ brep = BRepBuilderAPI_MakeFace (occ_face .GetHandle (), self . tolerance ).Face ()
172182 brep_face = BRep_Tool .Surface (brep )
173183
174184 # cycle on the edges
@@ -180,7 +190,7 @@ def write(self, mesh_points, filename):
180190 # evaluating the new edge: same (u,v) coordinates, but different (x,y,x) ones
181191 edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge (edge_uv_coordinates [0 ], brep_face )
182192 edge_phis_coordinates = edge_phis_coordinates_aux .Edge ()
183- tol .SetTolerance (edge_phis_coordinates , 1e-4 )
193+ tol .SetTolerance (edge_phis_coordinates , self . tolerance )
184194 wire_maker .Add (edge_phis_coordinates )
185195 edge_explorer .Next ()
186196
0 commit comments