88import numpy as np
99from OCC .BRep import BRep_Tool , BRep_Builder , BRep_Tool_Curve
1010from OCC .BRepAlgo import brepalgo_IsValid
11- from OCC .BRepBuilderAPI import BRepBuilderAPI_MakeEdge
12- from OCC .BRepBuilderAPI import BRepBuilderAPI_MakeFace
13- from OCC .BRepBuilderAPI import BRepBuilderAPI_NurbsConvert
14- from OCC .BRepBuilderAPI import BRepBuilderAPI_MakeWire
15- from OCC .BRepBuilderAPI import BRepBuilderAPI_Sewing
11+ from OCC .BRepBuilderAPI import (BRepBuilderAPI_MakeEdge ,
12+ BRepBuilderAPI_MakeFace , BRepBuilderAPI_NurbsConvert ,
13+ BRepBuilderAPI_MakeWire , BRepBuilderAPI_Sewing )
1614from OCC .BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
1715from OCC .Display .SimpleGui import init_display
18- from OCC .GeomConvert import geomconvert_SurfaceToBSplineSurface
19- from OCC . GeomConvert import geomconvert_CurveToBSplineCurve
16+ from OCC .GeomConvert import ( geomconvert_SurfaceToBSplineSurface ,
17+ geomconvert_CurveToBSplineCurve )
2018from OCC .gp import gp_Pnt , gp_XYZ
2119from OCC .Precision import precision_Confusion
2220from OCC .ShapeAnalysis import ShapeAnalysis_WireOrder
2321from OCC .ShapeFix import ShapeFix_ShapeTolerance , ShapeFix_Shell
2422from OCC .StlAPI import StlAPI_Writer
2523from OCC .TColgp import TColgp_Array1OfPnt , TColgp_Array2OfPnt
26- from OCC .TopAbs import TopAbs_FACE , TopAbs_EDGE , TopAbs_WIRE
27- from OCC . TopAbs import TopAbs_FORWARD , TopAbs_SHELL
24+ from OCC .TopAbs import ( TopAbs_FACE , TopAbs_EDGE , TopAbs_WIRE , TopAbs_FORWARD ,
25+ TopAbs_SHELL )
2826from OCC .TopExp import TopExp_Explorer , topexp
29- from OCC .TopoDS import topods_Face , TopoDS_Compound , topods_Shell
30- from OCC . TopoDS import topods_Edge , topods_Wire , topods , TopoDS_Shape
27+ from OCC .TopoDS import ( topods_Face , TopoDS_Compound , topods_Shell ,
28+ topods_Edge , topods_Wire , topods , TopoDS_Shape )
3129from matplotlib import pyplot
3230from mpl_toolkits import mplot3d
3331from stl import mesh
@@ -38,8 +36,8 @@ class NurbsHandler(fh.FileHandler):
3836 """
3937 Nurbs file handler base class
4038
41- :cvar string infile: name of the input file to be processed.
42- :cvar string outfile: name of the output file where to write in.
39+ :cvar str infile: name of the input file to be processed.
40+ :cvar str outfile: name of the output file where to write in.
4341 :cvar list control_point_position: index of the first NURBS
4442 control point (or pole) of each face of the files.
4543 :cvar TopoDS_Shape shape: shape meant for modification.
@@ -48,11 +46,10 @@ class NurbsHandler(fh.FileHandler):
4846
4947 .. warning::
5048
51- - For non trivial geometries it could be necessary to increase
52- the tolerance. Linking edges into a single wire and then
53- trimming the surface with the wire can be hard for the
54- software, especially when the starting CAD has not been made
55- for analysis but for design purposes.
49+ For non trivial geometries it could be necessary to increase the
50+ tolerance. Linking edges into a single wire and then trimming the
51+ surface with the wire can be hard for the software, especially when the
52+ starting CAD has not been made for analysis but for design purposes.
5653 """
5754
5855 def __init__ (self ):
@@ -66,7 +63,7 @@ def _check_infile_instantiation(self):
6663 """
6764 This private method checks if `self.infile` and `self.shape` are
6865 instantiated. If not it means that nobody called the parse method
69- and at least one of them is None` If the check fails it raises a
66+ and at least one of them is None. If the check fails it raises a
7067 RuntimeError.
7168 """
7269 if not self .shape or not self .infile :
@@ -80,8 +77,8 @@ def load_shape_from_file(self, filename):
8077 Not implemented, it has to be implemented in subclasses.
8178 """
8279 raise NotImplementedError (
83- 'Subclass must implement abstract method ' +
84- self . __class__ . __name__ + ' .load_shape_from_file' )
80+ 'Subclass must implement abstract method'
81+ '{} .load_shape_from_file'. format ( self . __class__ . __name__ ) )
8582
8683 def parse (self , filename ):
8784 """
@@ -135,7 +132,8 @@ def parse(self, filename):
135132 control_point_coordinates .Z ()
136133 ]
137134 i += 1
138- # pushing the control points coordinates to the mesh_points array (used for FFD)
135+ # pushing the control points coordinates to the mesh_points array
136+ # (used for FFD)
139137 mesh_points = np .append (
140138 mesh_points , control_polygon_coordinates , axis = 0 )
141139 control_point_position .append (
@@ -148,13 +146,13 @@ def parse(self, filename):
148146
149147 def write (self , mesh_points , filename , tolerance = None ):
150148 """
151- Writes a output file, called filename, copying all the structures
149+ Writes a output file, called ` filename` , copying all the structures
152150 from self.filename but the coordinates. `mesh_points` is a matrix
153151 that contains the new coordinates to write in the output file.
154152
155- :param numpy.ndarray mesh_points: it is a ` n_points` -by-3 matrix
156- containing the coordinates of the points of the mesh
157- :param string filename: name of the output file.
153+ :param numpy.ndarray mesh_points: it is a * n_points* -by-3 matrix
154+ containing the coordinates of the points of the mesh.
155+ :param str filename: name of the output file.
158156 :param float tolerance: tolerance for the construction of the faces
159157 and wires in the write function. If not given it uses
160158 `self.tolerance`.
@@ -217,7 +215,8 @@ def write(self, mesh_points, filename, tolerance=None):
217215 edge = topods_Edge (edge_explorer .Current ())
218216 # edge in the (u,v) coordinates
219217 edge_uv_coordinates = BRep_Tool .CurveOnSurface (edge , face_aux )
220- # evaluating the new edge: same (u,v) coordinates, but different (x,y,x) ones
218+ # evaluating the new edge: same (u,v) coordinates, but
219+ # different (x,y,x) ones
221220 edge_phis_coordinates_aux = BRepBuilderAPI_MakeEdge (
222221 edge_uv_coordinates [0 ], brep_face )
223222 edge_phis_coordinates = edge_phis_coordinates_aux .Edge ()
@@ -238,10 +237,15 @@ def write(self, mesh_points, filename, tolerance=None):
238237
239238 def check_topology (self ):
240239 """
241- Method to check the topology of imported geometry.
242- :return: 0: 1 solid = 1 shell = n faces
243- 1: 1 solid = 0 shell = n free faces
244- 2: 1 solid = n shell = n faces (1 shell = 1 face)
240+ Method to check the topology of imported geometry; it sets
241+ *self.check_topo* as:
242+
243+ - 0 if 1 solid = 1 shell = n faces
244+ - 1 if 1 solid = 0 shell = n free faces
245+ - 2 if 1 solid = n shell = n faces (1 shell = 1 face)
246+
247+ :return: {0, 1, 2}
248+ :rtype: int
245249 """
246250 # read shells and faces
247251 shells_explorer = TopExp_Explorer (self .shape , TopAbs_SHELL )
@@ -256,10 +260,10 @@ def check_topology(self):
256260 n_faces += 1
257261 faces_explorer .Next ()
258262
259- print ("##############################################\n "
260- "Model statistics -- Nb Shells: {0} Faces: {1} \n "
261- "----------------------------------------------\n " .format (
262- n_shells , n_faces ))
263+ # print("##############################################\n"
264+ # "Model statistics -- Nb Shells: {0} Faces: {1} \n"
265+ # "----------------------------------------------\n".format(
266+ # n_shells, n_faces))
263267
264268 if n_shells == 0 :
265269 self .check_topo = 1
@@ -271,18 +275,14 @@ def check_topology(self):
271275 @staticmethod
272276 def parse_face (topo_face ):
273277 """
274- Method to parse a single Face (a single patch nurbs surface).
278+ Method to parse a single ` Face` (a single patch nurbs surface).
275279 It returns a matrix with all the coordinates of control points of the
276- Face and a second list with all the control points related to the
277- Edges of the Face.
278-
279- :param topo_face: the input Face
280-
281- :return: mesh_points_face: it is a `n_points`-by-3 matrix containing the
282- coordinates of the control points of the Face (a nurbs surface)
280+ `Face` and a second list with all the control points related to the
281+ `Edges` of the `Face.`
283282
284- :return: mesh_points_edge: it is a list of `n_points`-by-3 matrix
283+ :param Face topo_face: the input Face.
285284
285+ :return: control points of the `Face`, control points related to `Edges`.
286286 :rtype: tuple(numpy.ndarray, list)
287287
288288 """
@@ -361,7 +361,7 @@ def parse_shape(self, filename):
361361 of each Face and a second list with all the control points related to
362362 Edges of each Face.
363363
364- :param filename: the input filename.
364+ :param str filename: the input filename.
365365
366366 :return: list of (mesh_points: `n_points`-by-3 matrix containing
367367 the coordinates of the control points of the Face (surface),
@@ -694,8 +694,9 @@ def write_shape(self, l_shells, filename, tol):
694694 # add the new shell to the global compound
695695 global_compound_builder .Add (global_comp , new_shell )
696696
697- print ("Shell {0} of type {1} Processed " .format (0 , itype ))
698- print "=============================================="
697+ # TODO print to logging
698+ # print("Shell {0} of type {1} Processed ".format(0, itype))
699+ # print "=============================================="
699700
700701 self .write_shape_to_file (global_comp , self .outfile )
701702
0 commit comments