Skip to content

Commit 79ae003

Browse files
authored
Update version, modernization, cylinder shaft
* cylinder shaft, minimal test * pythonocc update * add pyproject and remove old style setup.py * update Python versions in CI workflow * update Python compatibility requirement in README
1 parent 0a4379e commit 79ae003

File tree

9 files changed

+125
-69
lines changed

9 files changed

+125
-69
lines changed

.github/workflows/testing_pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [windows-latest, macos-latest, ubuntu-latest]
16-
python-version: [3.8, 3.9]
16+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1717

1818
steps:
1919
- uses: actions/checkout@v4

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ See the [**Examples**](#examples) section below and the [**Tutorials**](tutorial
4646

4747
## Dependencies and installation
4848
**BladeX** requires `numpy`, `scipy`, `matplotlib`, `sphinx` (for the documentation), and `pytest` (for the local test). They can be easily installed using `pip`.
49-
**BladeX** is compatible with Python 3.6. Moreover, some of the modules require `OCC` to be installed for the `.iges` or `.stl` CAD generation. This requirement cannot be satisfied through `pip`, but the precompiled binaries are available on `conda` using the command:
49+
**BladeX** is compatible with Python>=3.9. Moreover, some of the modules require `OCC` to be installed for the `.iges` or `.stl` CAD generation. This requirement cannot be satisfied through `pip`, but the precompiled binaries are available on `conda` using the command:
5050

5151
```bash
52-
> conda install -c conda-forge pythonocc-core=7.4.0
52+
> conda install -c conda-forge pythonocc-core
5353
```
5454

5555
You can also refer to `pythonocc.org` or `github.com/tpaviot/pythonocc-core` for further instructions.

bladex/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""
22
BladeX init
33
"""
4-
__all__ = ['ProfileInterface', 'NacaProfile', 'CustomProfile',
5-
'ReversePropeller', 'Blade', 'Shaft', 'Propeller', 'Deformation',
6-
'ParamFile', 'RBF', 'reconstruct_f', 'scipy_bspline']
4+
__all__ = [
5+
'ProfileInterface', 'NacaProfile', 'CustomProfile',
6+
'ReversePropeller', 'Blade', 'Shaft', 'CylinderShaft',
7+
'Propeller', 'Deformation', 'ParamFile', 'RBF',
8+
'reconstruct_f', 'scipy_bspline'
9+
]
710

811
from .meta import *
912
from .profile import ProfileInterface
@@ -16,3 +19,4 @@
1619
from .params import ParamFile
1720
from .ndinterpolator import RBF, reconstruct_f, scipy_bspline
1821
from .reversepropeller import ReversePropeller
22+
from .cylinder_shaft import CylinderShaft

bladex/blade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ def generate_solid(self,
960960
sewer.Perform()
961961
result_shell = sewer.SewedShape()
962962
solid_maker = BRepBuilderAPI_MakeSolid()
963-
solid_maker.Add(OCC.Core.TopoDS.topods_Shell(result_shell))
963+
solid_maker.Add(OCC.Core.TopoDS.topods.Shell(result_shell))
964964
if not solid_maker.IsDone():
965965
raise RuntimeError('Unsuccessful assembling of solid blade')
966966
result_solid = solid_maker.Solid()

bladex/cylinder_shaft.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
""" Cylinder Shaft """
2+
from OCC.Display.SimpleGui import init_display
3+
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder
4+
from OCC.Core.gp import gp_Pnt, gp_Dir, gp_Ax2
5+
6+
7+
class CylinderShaft:
8+
"""
9+
Cylinder shaft construction.
10+
11+
:param float radius: radius of the cylinder shaft. Defaults to 1.0.
12+
:param float height: height of the cylinder shaft. Defaults to 1.0.
13+
:param list orientation: orientation vector of the cylinder shaft. Defaults
14+
to [1.0, 0.0, 0.0], so along X axis.
15+
:param list origin: origin point of the cylinder shaft. Defaults to
16+
[0.0, 0.0, 0.0].
17+
"""
18+
19+
def __init__(self, radius=1.0, height=1.0, orientation=None, origin=None):
20+
self.radius = radius
21+
self.height = height
22+
23+
if orientation is None:
24+
self.orientation = [1.0, 0.0, 0.0] # default orientation along X
25+
26+
if origin is None:
27+
self.origin = [0.0, 0.0, 0.0] # default origin at (0,0,0)
28+
29+
def generate_solid(self):
30+
"""
31+
Generate a cylindrical shaft using the BRepBuilderAPI_MakeCylinder
32+
algorithm. This method requires PythonOCC to be installed.
33+
34+
:return: solid shaft
35+
:rtype: OCC.Core.TopoDS.TopoDS_Solid
36+
"""
37+
38+
origin = gp_Pnt(*self.origin)
39+
orientation = gp_Dir(*self.orientation)
40+
ax2 = gp_Ax2(origin, orientation)
41+
42+
shape = BRepPrimAPI_MakeCylinder(ax2, self.radius, self.height).Shape()
43+
44+
return shape
45+
46+
def display(self):
47+
"""
48+
Display the shaft.
49+
"""
50+
shaft_solid = self.generate_solid()
51+
display, start_display = init_display()[:2]
52+
display.DisplayShape(shaft_solid, update=True)
53+
start_display()

bladex/shaft.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def generate_solid(self):
4444
sewer.Perform()
4545
result_sewed_shaft = sewer.SewedShape()
4646
shaft_solid_maker = BRepBuilderAPI_MakeSolid()
47-
shaft_solid_maker.Add(OCC.Core.TopoDS.topods_Shell(result_sewed_shaft))
47+
shaft_solid_maker.Add(OCC.Core.TopoDS.topods.Shell(result_sewed_shaft))
4848
if not shaft_solid_maker.IsDone():
4949
raise RuntimeError('Unsuccessful assembling of solid shaft')
5050
shaft_solid = shaft_solid_maker.Solid()

pyproject.toml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[build-system]
2+
requires = ["setuptools>=61", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "BladeX"
7+
version = "0.1.0"
8+
description = "Python Blade Morphing"
9+
readme = { file = "README.md", content-type = "text/markdown" }
10+
requires-python = ">=3.9"
11+
license = { text = "MIT" }
12+
authors = [
13+
{ name = "Marco Tezzele", email = "[email protected]" },
14+
{ name = "Mahmoud Gadalla", email = "[email protected]" }
15+
]
16+
keywords = ["blade-generation", "propeller", "iges", "procal"]
17+
classifiers = [
18+
"Development Status :: 5 - Production/Stable",
19+
"License :: OSI Approved :: MIT License",
20+
"Programming Language :: Python :: 3.9",
21+
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
23+
"Programming Language :: Python :: 3.12",
24+
"Intended Audience :: Science/Research",
25+
"Topic :: Scientific/Engineering :: Mathematics"
26+
]
27+
dependencies = [
28+
"numpy",
29+
"scipy",
30+
"matplotlib",
31+
]
32+
33+
[project.optional-dependencies]
34+
docs = [
35+
"Sphinx",
36+
"sphinx_rtd_theme"
37+
]
38+
test = [
39+
"pytest",
40+
"pytest-cov"
41+
]
42+
43+
[project.urls]
44+
Homepage = "https://github.com/mathLab/BladeX"
45+
46+
[tool.setuptools]
47+
include-package-data = true
48+
49+
[tool.setuptools.packages.find]
50+
include = ["bladex*"]
51+

setup.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

tests/test_cylinder_shaft.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from unittest import TestCase
2+
from bladex import CylinderShaft
3+
from OCC.Core.TopoDS import TopoDS_Solid
4+
5+
6+
def test_generate_solid_01():
7+
sh = CylinderShaft()
8+
shaft_solid = sh.generate_solid()
9+
assert isinstance(shaft_solid, TopoDS_Solid)

0 commit comments

Comments
 (0)