Skip to content

Commit add11db

Browse files
committed
mypy pass: replace deprecated OCC wrapper functions
- migrate deprecated module-level wrappers to their static class methods (breptools_Read -> breptools.Read, gp_XOY -> gp.XOY, brepgprop_*, brepbndlib_Add, XCAFDoc_DocumentTool_*, ...) - pass an Aspect_HatchStyle to SetCappingHatch instead of a bool - add mypy configuration to pyproject.toml
1 parent 88f26ca commit add11db

28 files changed

Lines changed: 392 additions & 395 deletions

‎examples/core_classic_occ_bottle.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@
4040
from OCC.Core.Geom2d import Geom2d_Ellipse, Geom2d_TrimmedCurve
4141
from OCC.Core.GeomAbs import GeomAbs_Plane
4242
from OCC.Core.gp import (
43+
gp,
4344
gp_Ax2,
4445
gp_Ax2d,
4546
gp_Ax3,
4647
gp_Dir2d,
47-
gp_DZ,
48-
gp_OX,
4948
gp_Pln,
5049
gp_Pnt,
5150
gp_Pnt2d,
@@ -99,7 +98,7 @@ def geom_plane_from_face(aFace: TopoDS_Face) -> gp_Pln:
9998
aWire = BRepBuilderAPI_MakeWire(aEdge1.Edge(), aEdge2.Edge(), aEdge3.Edge())
10099

101100
# Quick way to specify the X axis
102-
xAxis = gp_OX()
101+
xAxis = gp.OX()
103102

104103
# Set up the mirror
105104
aTrsf = gp_Trsf()
@@ -139,7 +138,7 @@ def geom_plane_from_face(aFace: TopoDS_Face) -> gp_Pln:
139138

140139
# Create the neck of the bottle
141140
neckLocation = gp_Pnt(0, 0, height)
142-
neckAxis = gp_DZ()
141+
neckAxis = gp.DZ()
143142
neckAx2 = gp_Ax2(neckLocation, neckAxis)
144143

145144
myNeckRadius = thickness / 4.0
@@ -176,7 +175,7 @@ def geom_plane_from_face(aFace: TopoDS_Face) -> gp_Pln:
176175
myBody_step3 = mk_thick_solid.Shape()
177176

178177
# Set up our surfaces for the threading on the neck
179-
neckAx2_Ax3 = gp_Ax3(neckLocation, gp_DZ())
178+
neckAx2_Ax3 = gp_Ax3(neckLocation, gp.DZ())
180179
aCyl1 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 0.99)
181180
aCyl2 = Geom_CylindricalSurface(neckAx2_Ax3, myNeckRadius * 1.05)
182181

‎examples/core_display_callbacks.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
1717

1818
from OCC.Core.Bnd import Bnd_Box
19-
from OCC.Core.BRepBndLib import brepbndlib_Add
19+
from OCC.Core.BRepBndLib import brepbndlib
2020
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeTorus
2121
from OCC.Display.SimpleGui import init_display
2222

@@ -31,7 +31,7 @@ def compute_bbox(shp, *kwargs):
3131
print(f"Compute bbox for {shp} ")
3232
for shape in shp:
3333
bbox = Bnd_Box()
34-
brepbndlib_Add(shape, bbox)
34+
brepbndlib.Add(shape, bbox)
3535
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
3636
dx = xmax - xmin
3737
dy = ymax - ymin

‎examples/core_display_clip_planes.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919

2020
import sys
2121

22+
from OCC.Core.Aspect import Aspect_HS_GRID_DIAGONAL
2223
from OCC.Core.BRep import BRep_Builder
23-
from OCC.Core.BRepTools import breptools_Read
24+
from OCC.Core.BRepTools import breptools
2425
from OCC.Core.gp import gp_Vec
2526
from OCC.Core.Graphic3d import Graphic3d_ClipPlane
2627
from OCC.Core.Quantity import Quantity_Color, Quantity_TOC_RGB
@@ -32,7 +33,7 @@
3233

3334
cylinder_head = TopoDS_Shape()
3435
builder = BRep_Builder()
35-
breptools_Read(cylinder_head, "../assets/models/cylinder_head.brep", builder)
36+
breptools.Read(cylinder_head, "../assets/models/cylinder_head.brep", builder)
3637

3738
ais_shp = display.DisplayShape(cylinder_head)[0]
3839

@@ -41,7 +42,7 @@
4142

4243
# set hatch on
4344
clip_plane_1.SetCapping(True)
44-
clip_plane_1.SetCappingHatch(True)
45+
clip_plane_1.SetCappingHatch(Aspect_HS_GRID_DIAGONAL)
4546

4647
# off by default, user will have to enable it
4748
clip_plane_1.SetOn(False)

‎examples/core_display_signal_slots.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
from OCC.Core.BRepGProp import brepgprop_LinearProperties
3+
from OCC.Core.BRepGProp import brepgprop
44
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere
55
from OCC.Core.gp import gp_Trsf, gp_Vec
66
from OCC.Core.GProp import GProp_GProps
@@ -47,7 +47,7 @@ def on_select(shapes):
4747
g1 = GProp_GProps()
4848

4949
for shape in shapes:
50-
brepgprop_LinearProperties(shape, g1)
50+
brepgprop.LinearProperties(shape, g1)
5151
mass = g1.Mass()
5252
centre_of_mass = g1.CentreOfMass()
5353
com_x = centre_of_mass.X()

‎examples/core_export_gltf_single_shape.py‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,26 @@
1717

1818
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
1919
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere
20-
from OCC.Core.BRepTools import breptools_Clean
20+
from OCC.Core.BRepTools import breptools
2121
from OCC.Core.Message import Message_ProgressRange
2222

2323
# GLTF export
2424
from OCC.Core.RWGltf import RWGltf_CafWriter, RWGltf_WriterTrsfFormat
2525
from OCC.Core.TCollection import TCollection_AsciiString
2626
from OCC.Core.TColStd import TColStd_IndexedDataMapOfStringString
2727
from OCC.Core.TDocStd import TDocStd_Document
28-
from OCC.Core.XCAFDoc import (
29-
XCAFDoc_DocumentTool_LayerTool,
30-
XCAFDoc_DocumentTool_ShapeTool,
31-
)
28+
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool
3229

3330
# create the shapeto export
3431
shp = BRepPrimAPI_MakeSphere(60.0).Shape()
3532

3633
# create a document
3734
doc = TDocStd_Document("pythonocc-doc")
38-
shape_tool = XCAFDoc_DocumentTool_ShapeTool(doc.Main())
39-
layer_tool = XCAFDoc_DocumentTool_LayerTool(doc.Main())
35+
shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main())
36+
layer_tool = XCAFDoc_DocumentTool.LayerTool(doc.Main())
4037

4138
# mesh shape
42-
breptools_Clean(shp)
39+
breptools.Clean(shp)
4340
# Triangulate
4441
msh_algo = BRepMesh_IncrementalMesh(shp, True)
4542
msh_algo.Perform()

‎examples/core_export_step_ap203.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
2222
from OCC.Core.IFSelect import IFSelect_RetDone
23-
from OCC.Core.Interface import Interface_Static_SetCVal
23+
from OCC.Core.Interface import Interface_Static
2424
from OCC.Core.STEPControl import STEPControl_AsIs, STEPControl_Writer
2525

2626
# creates a basic shape
@@ -31,7 +31,7 @@
3131
dd = step_writer.WS().TransferWriter().FinderProcess()
3232
print(dd)
3333

34-
Interface_Static_SetCVal("write.step.schema", "AP203")
34+
Interface_Static.SetCVal("write.step.schema", "AP203")
3535

3636
# transfer shapes and write file
3737
step_writer.Transfer(box_s, STEPControl_AsIs)

‎examples/core_export_step_header_section.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from OCC.Core.APIHeaderSection import APIHeaderSection_MakeHeader
2121
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
2222
from OCC.Core.IFSelect import IFSelect_RetDone
23-
from OCC.Core.Interface import Interface_HArray1OfHAsciiString, Interface_Static_SetCVal
23+
from OCC.Core.Interface import Interface_HArray1OfHAsciiString, Interface_Static
2424
from OCC.Core.STEPControl import STEPControl_AsIs, STEPControl_Writer
2525
from OCC.Core.TCollection import TCollection_HAsciiString
2626

@@ -31,10 +31,10 @@
3131
step_writer = STEPControl_Writer()
3232
dd = step_writer.WS().TransferWriter().FinderProcess()
3333

34-
Interface_Static_SetCVal("write.step.schema", "AP203")
34+
Interface_Static.SetCVal("write.step.schema", "AP203")
3535

3636
# transfer shapes and write file
37-
Interface_Static_SetCVal("write.step.product.name", "Box")
37+
Interface_Static.SetCVal("write.step.product.name", "Box")
3838
step_writer.Transfer(box_s, STEPControl_AsIs)
3939

4040
#

‎examples/core_geometry_bounding_box.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
1919

2020
from OCC.Core.Bnd import Bnd_Box
21-
from OCC.Core.BRepBndLib import brepbndlib_Add
21+
from OCC.Core.BRepBndLib import brepbndlib
2222
from OCC.Core.BRepMesh import BRepMesh_IncrementalMesh
2323
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeCylinder
2424

@@ -44,7 +44,7 @@ def get_boundingbox(shape, tol=1e-6, use_mesh=True):
4444
mesh.Perform()
4545
if not mesh.IsDone():
4646
raise AssertionError("Mesh not done.")
47-
brepbndlib_Add(shape, bbox, use_mesh)
47+
brepbndlib.Add(shape, bbox, use_mesh)
4848

4949
xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
5050
return xmin, ymin, zmin, xmax, ymax, zmax, xmax - xmin, ymax - ymin, zmax - zmin

‎examples/core_geometry_curves2d_from_curve.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
from OCC.Core.Convert import Convert_TgtThetaOver2
2121
from OCC.Core.GC import GC_MakeEllipse2d
2222
from OCC.Core.Geom2d import Geom2d_TrimmedCurve
23-
from OCC.Core.Geom2dConvert import geom2dconvert_CurveToBSplineCurve
24-
from OCC.Core.gp import gp_OX2d
23+
from OCC.Core.Geom2dConvert import geom2dconvert
24+
from OCC.Core.gp import gp
2525
from OCC.Display.SimpleGui import init_display
2626

2727
display, start_display, add_menu, add_function_to_menu = init_display()
2828

2929

3030
def curves2d_from_curves():
3131
major, minor = 12, 4
32-
axis = gp_OX2d()
32+
axis = gp.OX2d()
3333
ellipse = GC_MakeEllipse2d(axis, major, minor).Value()
3434
trimmed_curve = Geom2d_TrimmedCurve(ellipse, -1, 2, True)
35-
bspline = geom2dconvert_CurveToBSplineCurve(trimmed_curve, Convert_TgtThetaOver2)
35+
bspline = geom2dconvert.CurveToBSplineCurve(trimmed_curve, Convert_TgtThetaOver2)
3636
display.DisplayShape(bspline, update=True)
3737

3838

‎examples/core_geometry_make_pipe_shell.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
1919
from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakePipeShell
2020
from OCC.Core.Geom import Geom_BezierCurve
21-
from OCC.Core.gp import gp_Circ, gp_Pnt, gp_ZOX
21+
from OCC.Core.gp import gp, gp_Circ, gp_Pnt
2222
from OCC.Core.Law import Law_Linear
2323
from OCC.Core.TColgp import TColgp_Array1OfPnt
2424
from OCC.Display.SimpleGui import init_display
@@ -42,7 +42,7 @@ def thicken_spline(event=None):
4242
display.DisplayShape(bz_curv_wire)
4343

4444
# Creation of profile to sweep along the spine
45-
circle = gp_Circ(gp_ZOX(), 1)
45+
circle = gp_Circ(gp.ZOX(), 1)
4646
circle.SetLocation(array[0])
4747
circle_edge = BRepBuilderAPI_MakeEdge(circle).Edge()
4848
circle_wire = BRepBuilderAPI_MakeWire(circle_edge).Wire()

0 commit comments

Comments
 (0)