1+ """
2+ Module for the propeller with shaft bottom-up parametrized construction.
3+ """
4+ import os
5+ import numpy as np
6+ from bladex import Blade , Shaft
7+ import OCC .Core .TopoDS
8+ from OCC .Core .gp import gp_Dir , gp_Pnt , gp_Ax1 , gp_Trsf
9+ from OCC .Core .IGESControl import IGESControl_Reader , IGESControl_Writer
10+ from OCC .Core .BRepBuilderAPI import BRepBuilderAPI_Transform , BRepBuilderAPI_Sewing
11+ from OCC .Core .BRepAlgoAPI import BRepAlgoAPI_Fuse
12+ from OCC .Extend .DataExchange import write_stl_file
13+ from OCC .Display .SimpleGui import init_display
14+
15+ class Propeller (object ):
16+ """
17+ Bottom-up parametrized propeller (including shaft) construction.
18+ The constructor requires PythonOCC to be installed.
19+
20+ :param shaft.Shaft shaft: shaft to be added to the propeller
21+ :param blade.Blade blade: blade of the propeller
22+ :param int n_blades: number of blades composing the propeller
23+ :cvar OCC.Core.TopoDS.TopoDS_Solid shaft_solid: solid shaft
24+ :cvar OCC.Core.TopoDS.TopoDS_Shell sewed_full_body: propeller with shaft shell
25+ """
26+
27+ def __init__ (self , shaft , blade , n_blades ):
28+ self .shaft_solid = shaft .generate_solid ()
29+ blade .apply_transformations (reflect = True )
30+ blade_solid = blade .generate_solid (max_deg = 2 ,
31+ display = False ,
32+ errors = None )
33+ blades = []
34+ blades .append (blade_solid )
35+ for i in range (n_blades - 1 ):
36+ blade .rotate (rad_angle = 1.0 * 2.0 * np .pi / float (n_blades ))
37+ blade_solid = blade .generate_solid (max_deg = 2 , display = False , errors = None )
38+ blades .append (blade_solid )
39+ blades_combined = blades [0 ]
40+ for i in range (len (blades )- 1 ):
41+ boolean_union = BRepAlgoAPI_Fuse (blades_combined , blades [i + 1 ])
42+ boolean_union .Build ()
43+ if not boolean_union .IsDone ():
44+ raise RuntimeError ('Unsuccessful assembling of blade' )
45+ blades_combined = boolean_union .Shape ()
46+ boolean_union = BRepAlgoAPI_Fuse (self .shaft_solid , blades_combined )
47+ boolean_union .Build ()
48+ result_compound = boolean_union .Shape ()
49+ section_edges = boolean_union .SectionEdges ()
50+ sewer = BRepBuilderAPI_Sewing (1e-2 )
51+ sewer .Add (result_compound )
52+ sewer .Perform ()
53+ self .sewed_full_body = sewer .SewedShape ()
54+
55+ def generate_iges (self , filename ):
56+ """
57+ Export the .iges CAD for the propeller with shaft.
58+
59+ :param string filename: path (with the file extension) where to store
60+ the .iges CAD for the propeller and shaft
61+ :raises RuntimeError: if the solid assembling of blades is not
62+ completed successfully
63+ """
64+ iges_writer = IGESControl_Writer ()
65+ iges_writer .AddShape (self .sewed_full_body )
66+ iges_writer .Write (filename )
67+
68+ def generate_stl (self , filename ):
69+ """
70+ Export the .stl CAD for the propeller with shaft.
71+
72+ :param string filename: path (with the file extension) where to store
73+ the .stl CAD for the propeller and shaft
74+ :raises RuntimeError: if the solid assembling of blades is not
75+ completed successfully
76+ """
77+ write_stl_file (self .sewed_full_body , filename )
78+
79+ def display (self ):
80+ """
81+ Display the propeller with shaft.
82+ """
83+ display , start_display , add_menu , add_function_to_menu = init_display ()
84+ display .DisplayShape (self .sewed_full_body , update = True )
85+ start_display ()
0 commit comments