@@ -160,6 +160,7 @@ def __init__(self, sections, radii, chord_lengths, pitch, rake,
160160 self .skew_angles = skew_angles
161161 self ._check_params ()
162162
163+ self .conversion_factor = 1000 # to convert units if necessary
163164 self .reset ()
164165
165166 def reset (self ):
@@ -184,15 +185,19 @@ def build(self, reflect=True):
184185
185186 """
186187 self .apply_transformations (reflect = reflect )
187- self .upper_face = InterpolatedFace (self .blade_coordinates_up ).face
188- self .lower_face = InterpolatedFace (self .blade_coordinates_down ).face
188+
189+ blade_coordinates_up = self .blade_coordinates_up * self .conversion_factor
190+ blade_coordinates_down = self .blade_coordinates_down * self .conversion_factor
191+
192+ self .upper_face = InterpolatedFace (blade_coordinates_up ).face
193+ self .lower_face = InterpolatedFace (blade_coordinates_down ).face
189194 self .tip_face = InterpolatedFace (np .stack ([
190- self . blade_coordinates_up [- 1 ],
191- self . blade_coordinates_down [- 1 ]
195+ blade_coordinates_up [- 1 ],
196+ blade_coordinates_down [- 1 ]
192197 ])).face
193198 self .root_face = InterpolatedFace (np .stack ([
194- self . blade_coordinates_up [0 ],
195- self . blade_coordinates_down [0 ]
199+ blade_coordinates_up [0 ],
200+ blade_coordinates_down [0 ]
196201 ])).face
197202
198203 def _check_params (self ):
@@ -419,19 +424,25 @@ def rotate(self, deg_angle=None, rad_angle=None, axis='x'):
419424 else :
420425 raise ValueError ('Axis must be either x, y, or z.' )
421426
422- self .blade_coordinates_up = np .einsum ('ij, kjl->kil' ,
423- rot_matrix , self .blade_coordinates_up )
424- self .blade_coordinates_down = np .einsum ('ij, kjl->kil' ,
425- rot_matrix , self .blade_coordinates_down )
427+ # self.blade_coordinates_up = np.einsum('ij, kjl->kil',
428+ # rot_matrix, self.blade_coordinates_up)
429+ # self.blade_coordinates_down = np.einsum('ij, kjl->kil',
430+ # rot_matrix, self.blade_coordinates_down)
426431
427432 def scale (self , factor ):
428433 """
429434 Scale the blade coordinates by a specified factor.
430435
431436 :param float factor: scaling factor
432437 """
438+ from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform
433439 self .blade_coordinates_up *= factor
434440 self .blade_coordinates_down *= factor
441+ # for face in [self.upper_face, self.lower_face, self.tip_face, self.root_face]:
442+ # brepgp_Trsf = BRepBuilderAPI_Transform()
443+ # brepgp_Trsf.SetScale(gp_Pnt(0, 0, 0), factor)
444+ # brepgp_Trsf.Perform(face, True)
445+ # face = brepgp_Trsf.Shape()
435446
436447 def plot (self , elev = None , azim = None , ax = None , outfile = None ):
437448 """
@@ -500,8 +511,8 @@ def plot(self, elev=None, azim=None, ax=None, outfile=None):
500511 >>> blade.apply_transformations()
501512 >>> blade.plot()
502513 """
503- if not self .blade_coordinates_up :
504- raise ValueError ('You must apply transformations before plotting.' )
514+ if len ( self .blade_coordinates_up ) == 0 :
515+ raise ValueError ('You must build the blade before plotting.' )
505516 if ax :
506517 ax = ax
507518 else :
@@ -628,32 +639,21 @@ def _write_blade_errors(self, upper_face, lower_face, errors):
628639 output_string += '\n '
629640 f .write (output_string )
630641
631- def generate_solid (self ,
632- max_deg = 1 ,
633- display = False ,
634- errors = None ):
642+ def generate_solid (self ):
635643 """
636644 Generate a solid blade assembling the upper face, lower face, tip and
637645 root using the BRepBuilderAPI_MakeSolid algorithm.
638- This method requires PythonOCC (7.4.0) to be installed.
639646
640647 :param int max_deg: Define the maximal U degree of generated surface.
641648 Default value is 1
642- :param bool display: if True, then display the generated CAD. Default
643- value is False
644- :param string errors: if string is passed then the method writes out
645- the distances between each discrete point used to construct the
646- blade and the nearest point on the CAD that is perpendicular to
647- that point. Default value is None
648649 :raises RuntimeError: if the assembling of the solid blade is not
649650 completed successfully
650651 """
651652 from OCC .Display .SimpleGui import init_display
652653 from OCC .Core .TopoDS import TopoDS_Shell
653654 import OCC .Core .TopoDS
654-
655- if max_deg <= 0 :
656- raise ValueError ('max_deg argument must be a positive integer.' )
655+ from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Sewing , \
656+ BRepBuilderAPI_MakeSolid
657657
658658 faces = [
659659 self .upper_face , self .lower_face , self .tip_face , self .root_face
@@ -674,28 +674,30 @@ def generate_solid(self,
674674
675675 return result_solid
676676
677- def generate_stl_blade (self , filename ):
677+ def export_stl (self , filename , linear_deflection = 0.1 ):
678678 """
679679 Generate and export the .STL file for the entire blade.
680680 This method requires PythonOCC (7.4.0) to be installed.
681681 """
682682 from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Sewing
683+ from OCC .Core .BRepMesh import BRepMesh_IncrementalMesh
683684 from OCC .Extend .DataExchange import write_stl_file
684-
685- self ._generate_upper_face (max_deg = 1 )
686- self ._generate_lower_face (max_deg = 1 )
687- self ._generate_root (max_deg = 1 )
688- self ._generate_tip (max_deg = 1 )
685+ from OCC .Core .StlAPI import StlAPI_Writer
689686
690687 sewer = BRepBuilderAPI_Sewing (1e-2 )
691- sewer .Add (self .generated_upper_face )
692- sewer .Add (self .generated_lower_face )
693- sewer .Add (self .generated_root )
694- sewer .Add (self .generated_tip )
688+ sewer .Add (self .upper_face )
689+ sewer .Add (self .lower_face )
690+ sewer .Add (self .root_face )
691+ sewer .Add (self .tip_face )
695692 sewer .Perform ()
696- self . sewed_full = sewer .SewedShape ()
693+ sewed_shape = sewer .SewedShape ()
697694
698- write_stl_file (self .sewed_full , filename )
695+ triangulation = BRepMesh_IncrementalMesh (sewed_shape , linear_deflection , True )
696+ triangulation .Perform ()
697+
698+ writer = StlAPI_Writer ()
699+ writer .SetASCIIMode (False )
700+ writer .Write (sewed_shape , filename )
699701
700702 def _generate_leading_edge_curves (self ):
701703 """
@@ -749,26 +751,21 @@ def _generate_leading_edge_curves(self):
749751 self .upper_le_edge = BRepBuilderAPI_MakeEdge (upper_curve .Curve ()).Edge ()
750752 self .lower_le_edge = BRepBuilderAPI_MakeEdge (lower_curve .Curve ()).Edge ()
751753
752- def generate_iges_blade (self , filename , include_le_curves = False ):
754+ def export_iges (self , filename , include_le_curves = False ):
753755 """
754756 Generate and export the .IGES file for the entire blade.
755757 This method requires PythonOCC (7.4.0) to be installed.
756758 """
757759 from OCC .Core .IGESControl import IGESControl_Writer
758760
759- self ._generate_upper_face (max_deg = 1 )
760- self ._generate_lower_face (max_deg = 1 )
761- self ._generate_root (max_deg = 1 )
762- self ._generate_tip (max_deg = 1 )
763-
764761 if include_le_curves :
765762 self ._generate_leading_edge_curves ()
766763
767764 iges_writer = IGESControl_Writer ()
768- iges_writer .AddShape (self .generated_upper_face )
769- iges_writer .AddShape (self .generated_lower_face )
770- iges_writer .AddShape (self .generated_root )
771- iges_writer .AddShape (self .generated_tip )
765+ iges_writer .AddShape (self .upper_face )
766+ iges_writer .AddShape (self .lower_face )
767+ iges_writer .AddShape (self .root_face )
768+ iges_writer .AddShape (self .tip_face )
772769
773770 if include_le_curves :
774771 iges_writer .AddShape (self .upper_le_edge )
0 commit comments