@@ -662,19 +662,18 @@ def _write_blade_errors(self, upper_face, lower_face, errors):
662662 vertex = BRepBuilderAPI_MakeVertex (
663663 gp_Pnt (
664664 1000 * self .blade_coordinates_up [i ][0 ][j ],
665- 1000 * self .blade_coordinates_up [i ][1 ][j ],
666- 1000 * self .blade_coordinates_up [i ][2 ][
667- j ])).Vertex ()
665+ 1000 * self .blade_coordinates_up [i ][1 ][j ], 1000
666+ * self .blade_coordinates_up [i ][2 ][j ])).Vertex ()
668667 projection = BRepExtrema_DistShapeShape (
669668 self .generated_upper_face , vertex )
670669 projection .Perform ()
671670 output_string += str (
672671 i ) + '\t \t \t ' + str (j ) + '\t \t \t ' + str (
673- 1000 * self . blade_coordinates_up [ i ][ 0 ]
674- [j ]) + '\t \t \t '
672+ 1000 *
673+ self . blade_coordinates_up [ i ][ 0 ] [j ]) + '\t \t \t '
675674 output_string += str (
676- 1000 * self .blade_coordinates_up [i ]
677- [1 ][ j ]) + '\t \t \t ' + str (
675+ 1000 * self .blade_coordinates_up [i ][ 1 ]
676+ [j ]) + '\t \t \t ' + str (
678677 1000 * self .blade_coordinates_up [i ][2 ]
679678 [j ]) + '\t \t \t ' + str (projection .Value ())
680679 output_string += '\n '
@@ -691,24 +690,23 @@ def _write_blade_errors(self, upper_face, lower_face, errors):
691690 gp_Pnt (
692691 1000 * self .blade_coordinates_down [i ][0 ][j ],
693692 1000 * self .blade_coordinates_down [i ][1 ][j ],
694- 1000 * self . blade_coordinates_down [ i ][ 2 ][
695- j ])).Vertex ()
693+ 1000 *
694+ self . blade_coordinates_down [ i ][ 2 ][ j ])).Vertex ()
696695 projection = BRepExtrema_DistShapeShape (
697696 self .generated_lower_face , vertex )
698697 projection .Perform ()
699698 output_string += str (
700699 i ) + '\t \t \t ' + str (j ) + '\t \t \t ' + str (
701- 1000 * self . blade_coordinates_down [ i ][ 0 ]
702- [j ]) + '\t \t \t '
700+ 1000 *
701+ self . blade_coordinates_down [ i ][ 0 ] [j ]) + '\t \t \t '
703702 output_string += str (
704- 1000 * self .blade_coordinates_down [i ]
705- [1 ][ j ]) + '\t \t \t ' + str (
703+ 1000 * self .blade_coordinates_down [i ][ 1 ]
704+ [j ]) + '\t \t \t ' + str (
706705 1000 * self .blade_coordinates_down [i ][2 ]
707706 [j ]) + '\t \t \t ' + str (projection .Value ())
708707 output_string += '\n '
709708 f .write (output_string )
710709
711-
712710 def generate_iges (self ,
713711 upper_face = None ,
714712 lower_face = None ,
@@ -781,7 +779,8 @@ def generate_iges(self,
781779 self ._check_string (filename = errors )
782780 self ._check_errors (upper_face = upper_face , lower_face = lower_face )
783781
784- self . _write_blade_errors (upper_face = upper_face , lower_face = lower_face , errors = errors )
782+ self ._write_blade_errors (
783+ upper_face = upper_face , lower_face = lower_face , errors = errors )
785784
786785 if display :
787786 display , start_display , add_menu , add_function_to_menu = init_display (
@@ -805,7 +804,7 @@ def generate_stl(self, min_length=None, max_length=None, outfile_stl=None):
805804 and http://docs.salome-platform.org/7/gui/SMESH/index.html for
806805 further details.
807806
808- This method requires PythonOCC and SMESH to be installed.
807+ This method requires PythonOCC and SMESH to be installed.
809808
810809 :param double min_length: smallest distance between two nodes. Default
811810 value is None
@@ -825,24 +824,32 @@ def generate_stl(self, min_length=None, max_length=None, outfile_stl=None):
825824 manual mesh healing is recommended by the user (e.g. see
826825 "Repair > Sewing" in SALOME GUI) for a proper mesh closure.
827826 """
828- from OCC .SMESH import SMESH_Gen , SMESH_MeshVSLink
829- from OCC .StdMeshers import (StdMeshers_Arithmetic1D , StdMeshers_TrianglePreference ,
830- StdMeshers_Regular_1D , StdMeshers_Quadrangle_2D ,
831- StdMeshers_MEFISTO_2D )
827+ from OCC .SMESH import SMESH_Gen
828+ from OCC .StdMeshers import (
829+ StdMeshers_Arithmetic1D , StdMeshers_TrianglePreference ,
830+ StdMeshers_Regular_1D , StdMeshers_MEFISTO_2D )
832831 from OCC .BRep import BRep_Builder
833832 from OCC .TopoDS import TopoDS_Shape , TopoDS_Compound
834833
834+ if min_length <= 0 or max_length <= 0 :
835+ raise ValueError ('min_length and max_length must be positive.' )
836+ if min_length >= max_length :
837+ raise ValueError ('min_length can not be greater than max_length' )
838+
835839 # First we check that blade shapes are generated, otherwise we generate
836840 # them. After that we combine the generated_upper_face,
837841 # generated_lower_face, and generated_tip into a topological compound
838842 # that we use to compute the surface mesh
839- if (self .generated_upper_face is None ) or not isinstance (self .generated_upper_face , TopoDS_Shape ):
843+ if (self .generated_upper_face is None ) or not isinstance (
844+ self .generated_upper_face , TopoDS_Shape ):
840845 # Upper face is generated with a maximal U degree = 1
841846 self ._generate_upper_face (maxDeg = 1 )
842- if (self .generated_lower_face is None ) or not isinstance (self .generated_lower_face , TopoDS_Shape ):
847+ if (self .generated_lower_face is None ) or not isinstance (
848+ self .generated_lower_face , TopoDS_Shape ):
843849 # Upper face is generated with a maximal U degree = 1
844850 self ._generate_lower_face (maxDeg = 1 )
845- if (self .generated_tip is None ) or not isinstance (self .generated_tip , TopoDS_Shape ):
851+ if (self .generated_tip is None ) or not isinstance (
852+ self .generated_tip , TopoDS_Shape ):
846853 # Upper face is generated with a maximal U degree = 1
847854 self ._generate_tip (maxDeg = 1 )
848855
@@ -851,9 +858,9 @@ def generate_stl(self, min_length=None, max_length=None, outfile_stl=None):
851858 aBuilder = BRep_Builder ()
852859 aBuilder .MakeCompound (aCompound )
853860 # Add shapes
854- aBuilder .Add (aCompound ,self .generated_upper_face )
855- aBuilder .Add (aCompound ,self .generated_lower_face )
856- aBuilder .Add (aCompound ,self .generated_tip )
861+ aBuilder .Add (aCompound , self .generated_upper_face )
862+ aBuilder .Add (aCompound , self .generated_lower_face )
863+ aBuilder .Add (aCompound , self .generated_tip )
857864
858865 # In the following we build the surface mesh according to the given
859866 # hypotheses
@@ -887,12 +894,14 @@ def generate_stl(self, min_length=None, max_length=None, outfile_stl=None):
887894 aMesh .AddHypothesis (aCompound , 2 )
888895 aMesh .AddHypothesis (aCompound , 3 )
889896
890- #Compute the data
891- aMeshGen .Compute (aMesh , aMesh .GetShapeToMesh ())
892-
893897 if outfile_stl is not None :
894- assert isinstance (outfile_stl , str ), "outfile_stl must be a valid string."
895- aMesh .ExportSTL (outfile_stl + '.stl' , False )
898+ if not isinstance (outfile_stl , str ):
899+ raise ValueError ('outfile_stl must be a valid string.' )
900+
901+ #Compute the data
902+ aMeshGen .Compute (aMesh , aMesh .GetShapeToMesh ())
903+ # Export STL
904+ aMesh .ExportSTL (outfile_stl + '.stl' , False )
896905
897906 @staticmethod
898907 def _check_string (filename ):
0 commit comments