Skip to content

Commit

Permalink
Minor revision of the Shaft class (#66)
Browse files Browse the repository at this point in the history
* Minor revision of the Shaft class

* shaft.py: raise Exception on the shaft file format included
  • Loading branch information
ggurioli committed May 18, 2021
1 parent 7c91106 commit f752c5a
Show file tree
Hide file tree
Showing 3 changed files with 8,195 additions and 8 deletions.
19 changes: 13 additions & 6 deletions bladex/shaft.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from OCC.Core.IGESControl import IGESControl_Reader
from OCC.Extend.DataExchange import read_stl_file
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeSolid, BRepBuilderAPI_Sewing
import OCC.Core.TopoDS
from OCC.Display.SimpleGui import init_display
Expand All @@ -8,9 +9,9 @@ class Shaft(object):
"""
Bottom-up parametrized shaft construction.
:param string filename: path (with the file extension) of a .iges file with
:param string filename: path (with the file extension) of a .stl or .iges file with
stored shaft information.
:cvar string filename: path (with the file extension) of a .iges file with
:cvar string filename: path (with the file extension) of a .stl or .iges file with
stored shaft information.
"""

Expand All @@ -27,10 +28,16 @@ def generate_solid(self):
:return: solid shaft
:rtype: OCC.Core.TopoDS.TopoDS_Solid
"""
iges_reader = IGESControl_Reader()
iges_reader.ReadFile(self.filename)
iges_reader.TransferRoots()
shaft_compound = iges_reader.Shape()
ext = os.path.splitext(self.filename)[1][1:]
if ext == 'stl':
shaft_compound = read_stl_file(self.filename)
elif ext == 'iges':
iges_reader = IGESControl_Reader()
iges_reader.ReadFile(self.filename)
iges_reader.TransferRoots()
shaft_compound = iges_reader.Shape()
else:
raise Exception('The shaft file is not in iges/stl formats')
sewer = BRepBuilderAPI_Sewing(1e-2)
sewer.Add(shaft_compound)
sewer.Perform()
Expand Down

0 comments on commit f752c5a

Please sign in to comment.