3838from OCC .Core .TopLoc import TopLoc_Location
3939from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform
4040
41- from OCC .Extend .TopologyUtils import (TopologyExplorer , discretize_edge ,
42- get_sorted_hlr_edges , list_of_shapes_to_compound )
41+ from OCC .Extend .TopologyUtils import (discretize_edge , get_sorted_hlr_edges ,
42+ list_of_shapes_to_compound )
4343
4444try :
4545 import svgwrite
@@ -74,9 +74,9 @@ def read_step_file(filename, as_compound=True, verbosity=True):
7474 _nbs = step_reader .NbShapes ()
7575 if _nbs == 0 :
7676 raise AssertionError ("No shape to transfer." )
77- if _nbs == 1 : # most cases
77+ elif _nbs == 1 : # most cases
7878 return step_reader .Shape (1 )
79- elif _nbs > 1 :
79+ elif _nbs > 1 :
8080 print ("Number of shapes:" , _nbs )
8181 shps = []
8282 # loop over root shapes
@@ -94,6 +94,7 @@ def read_step_file(filename, as_compound=True, verbosity=True):
9494 return shps
9595 else :
9696 raise AssertionError ("Error: can't read file." )
97+ return None
9798
9899
99100def write_step_file (a_shape , filename , application_protocol = "AP203" ):
@@ -256,7 +257,7 @@ def _get_sub_shapes(lab, loc):
256257 if (color_tool .GetColor (lab , 0 , c ) or
257258 color_tool .GetColor (lab , 1 , c ) or
258259 color_tool .GetColor (lab , 2 , c )):
259-
260+
260261 color_tool .SetInstanceColor (shape , 0 , c )
261262 color_tool .SetInstanceColor (shape , 1 , c )
262263 color_tool .SetInstanceColor (shape , 2 , c )
@@ -392,7 +393,7 @@ def read_iges_file(filename, return_as_shapes=False, verbosity=False, visible_on
392393 iges_reader .PrintCheckTransfer (failsonly , IFSelect_ItemsByEntity )
393394 iges_reader .TransferRoots ()
394395 nbr = iges_reader .NbRootsForTransfer ()
395- for n in range (1 , nbr + 1 ):
396+ for _ in range (1 , nbr + 1 ):
396397 nbs = iges_reader .NbShapes ()
397398 if nbs == 0 :
398399 print ("At least one shape in IGES cannot be transfered" )
@@ -450,9 +451,9 @@ def edge_to_svg_polyline(topods_edge, tol=0.1, unit="mm"):
450451 """
451452 unit_factor = 1 # by default
452453
453- if unit == "mm" :
454+ if unit == "mm" :
454455 unit_factor = 1
455- elif unit == "m" :
456+ elif unit == "m" :
456457 unit_factor = 1e3
457458
458459 points_3d = discretize_edge (topods_edge , tol )
@@ -465,7 +466,7 @@ def edge_to_svg_polyline(topods_edge, tol=0.1, unit="mm"):
465466 y_p = point [1 ] * unit_factor
466467 box2d .Add (gp_Pnt2d (x_p , y_p ))
467468 points_2d .append ((x_p , y_p ))
468-
469+
469470 return svgwrite .shapes .Polyline (points_2d , fill = "none" ), box2d
470471
471472def export_shape_to_svg (shape , filename = None ,
@@ -543,34 +544,3 @@ def export_shape_to_svg(shape, filename=None,
543544 print ("Shape successfully exported to %s" % filename )
544545 return True
545546 return dwg .tostring ()
546-
547-
548- if __name__ == "__main__" :
549- from OCC .Core .BRepPrimAPI import BRepPrimAPI_MakeSphere , BRepPrimAPI_MakeBox
550- sphere_shape = BRepPrimAPI_MakeSphere (30. ).Shape ()
551- write_step_file (sphere_shape , "s_203.stp" , application_protocol = "AP203" )
552- write_step_file (sphere_shape , "s_214.stp" , application_protocol = "AP214IS" )
553- read_step_file ("s_203.stp" )
554- read_step_file ("s_214.stp" )
555- read_step_file ("s_214.stp" , return_as_shapes = True )
556- write_stl_file (sphere_shape , "s_stl_ascii.stl" )
557- write_stl_file (sphere_shape , "s_stl_binary.stl" , mode = "binary" )
558- read_stl_file ("s_stl_ascii.stl" )
559- read_stl_file ("s_stl_binary.stl" )
560- # improve the precision by a factor 2
561- write_stl_file (sphere_shape , "s_stl_precise_ascii.stl" , linear_deflection = 0.1 , angular_deflection = 0.2 )
562- read_stl_file ("s_stl_precise_ascii.stl" )
563- # iges test
564- write_iges_file (sphere_shape , "s_iges.igs" )
565- # write IGES with special character
566- write_iges_file (sphere_shape , "sphère.igs" )
567- read_iges_file ("sphère.igs" )
568- read_iges_file ("s_iges.igs" )
569- read_iges_file ("s_iges.igs" , return_as_shapes = True )
570- # test step with colors
571- read_step_file_with_names_colors ("s_214.stp" )
572- # create a box
573- box_shp = BRepPrimAPI_MakeBox (10 , 50 , 300 ).Shape ()
574- get_sorted_hlr_edges (box_shp )
575- export_shape_to_svg (box_shp , filename = "box.svg" , width = "297mm" , height = "210mm" ,
576- export_hidden_edges = False )
0 commit comments