Skip to content

Commit 2840d1a

Browse files
committed
update to new OCC
1 parent 7d72349 commit 2840d1a

File tree

2 files changed

+44
-55
lines changed

2 files changed

+44
-55
lines changed

src/compas_occ/geometry/curves/curve.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@
1010
from compas.geometry import Transformation
1111
from compas.geometry import Vector
1212
from compas.geometry import distance_point_point
13+
from OCC.Core import IFSelect
14+
from OCC.Core import Interface
15+
from OCC.Core import STEPControl
1316
from OCC.Core.Bnd import Bnd_Box
14-
from OCC.Core.BndLib import BndLib_Add3dCurve_Add
17+
from OCC.Core.BndLib import BndLib_Add3dCurve
1518
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
1619
from OCC.Core.GCPnts import GCPnts_AbscissaPoint
17-
from OCC.Core.GCPnts import GCPnts_AbscissaPoint_Length
1820
from OCC.Core.Geom import Geom_Curve
1921
from OCC.Core.Geom import Geom_OffsetCurve
2022
from OCC.Core.GeomAdaptor import GeomAdaptor_Curve
2123
from OCC.Core.GeomAPI import GeomAPI_ExtremaCurveCurve
2224
from OCC.Core.GeomAPI import GeomAPI_ProjectPointOnCurve
23-
from OCC.Core.GeomProjLib import geomprojlib_Curve2d
24-
from OCC.Core.GeomProjLib import geomprojlib_Project
25+
from OCC.Core.GeomProjLib import geomprojlib
2526
from OCC.Core.gp import gp_Pnt
2627
from OCC.Core.gp import gp_Vec
2728
from OCC.Core.TopoDS import TopoDS_Edge
2829
from OCC.Core.TopoDS import TopoDS_Shape
29-
from OCC.Core.TopoDS import topods_Edge
30+
from OCC.Core.TopoDS import topods
3031

3132
from compas_occ.conversions import compas_transformation_to_trsf
3233
from compas_occ.conversions import direction_to_occ
@@ -62,11 +63,10 @@ class OCCCurve(Curve):
6263
6364
"""
6465

65-
_occ_curve: Geom_Curve
66-
6766
def __init__(self, occ_curve: Geom_Curve, name=None):
6867
super().__init__(name=name)
6968
self._dimension = 3
69+
self._occ_curve: Geom_Curve = None # type: ignore
7070
self.occ_curve = occ_curve
7171

7272
def __eq__(self, other: "OCCCurve") -> bool:
@@ -94,7 +94,7 @@ def occ_shape(self) -> TopoDS_Shape:
9494

9595
@property
9696
def occ_edge(self) -> TopoDS_Edge:
97-
return topods_Edge(self.occ_shape)
97+
return topods.Edge(self.occ_shape)
9898

9999
# ==============================================================================
100100
# Properties
@@ -161,16 +161,11 @@ def to_step(self, filepath: str, schema: str = "AP203") -> None:
161161
None
162162
163163
"""
164-
from OCC.Core.IFSelect import IFSelect_RetDone
165-
from OCC.Core.Interface import Interface_Static_SetCVal
166-
from OCC.Core.STEPControl import STEPControl_AsIs
167-
from OCC.Core.STEPControl import STEPControl_Writer
168-
169-
step_writer = STEPControl_Writer()
170-
Interface_Static_SetCVal("write.step.schema", schema)
171-
step_writer.Transfer(self.occ_edge, STEPControl_AsIs)
164+
step_writer = STEPControl.STEPControl_Writer()
165+
Interface.Interface_Static.SetCVal("write.step.schema", schema)
166+
step_writer.Transfer(self.occ_edge, STEPControl.STEPControl_AsIs)
172167
status = step_writer.Write(filepath)
173-
if status != IFSelect_RetDone:
168+
if status != IFSelect.IFSelect_RetDone:
174169
raise AssertionError("Operation failed.")
175170

176171
def to_polyline(self, n: int = 100) -> Polyline:
@@ -384,7 +379,7 @@ def aabb(self, precision: float = 0.0) -> Box:
384379
385380
"""
386381
box = Bnd_Box()
387-
BndLib_Add3dCurve_Add(GeomAdaptor_Curve(self.occ_curve), precision, box)
382+
BndLib_Add3dCurve.Add(GeomAdaptor_Curve(self.occ_curve), precision, box)
388383
return Box.from_diagonal(
389384
(
390385
point_to_compas(box.CornerMin()),
@@ -404,7 +399,7 @@ def length(self, precision: float = 1e-3) -> float:
404399
float
405400
406401
"""
407-
return GCPnts_AbscissaPoint_Length(GeomAdaptor_Curve(self.occ_curve), precision)
402+
return GCPnts_AbscissaPoint.Length(GeomAdaptor_Curve(self.occ_curve), precision)
408403

409404
def closest_point(
410405
self,
@@ -616,7 +611,7 @@ def projected(self, surface) -> "OCCCurve":
616611
:class:`OCCCurve`
617612
618613
"""
619-
result = geomprojlib_Project(self.occ_curve, surface.occ_surface)
614+
result = geomprojlib.Project(self.occ_curve, surface.occ_surface)
620615
curve = OCCCurve.from_occ(result)
621616
return curve
622617

@@ -633,7 +628,7 @@ def embedded(self, surface) -> OCCCurve2d:
633628
:class:`OCCCurve2d`
634629
635630
"""
636-
result = geomprojlib_Curve2d(self.occ_curve, surface.occ_surface)
631+
result = geomprojlib.Curve2d(self.occ_curve, surface.occ_surface)
637632
curve = OCCCurve2d.from_occ(result)
638633
return curve
639634

src/compas_occ/geometry/curves/curve2d.py

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
from compas.geometry import Point
66
from compas.geometry import Polyline
77
from compas.geometry import Vector
8-
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge2d
9-
from OCC.Core.Geom2d import Geom2d_Curve
10-
from OCC.Core.gp import gp_Pnt2d
11-
from OCC.Core.gp import gp_Vec2d
12-
from OCC.Core.TopoDS import TopoDS_Edge
13-
from OCC.Core.TopoDS import TopoDS_Shape
14-
from OCC.Core.TopoDS import topods_Edge
8+
from OCC.Core import BRepBuilderAPI
9+
from OCC.Core import Geom2d
10+
from OCC.Core import IFSelect
11+
from OCC.Core import Interface
12+
from OCC.Core import STEPControl
13+
from OCC.Core import TopoDS
14+
from OCC.Core import gp
1515

1616
from compas_occ.conversions import point2d_to_compas
1717
from compas_occ.conversions import vector2d_to_compas
@@ -42,11 +42,10 @@ class OCCCurve2d(Curve):
4242
4343
"""
4444

45-
_occ_curve: Geom2d_Curve
46-
47-
def __init__(self, occ_curve: Geom2d_Curve, name=None):
45+
def __init__(self, occ_curve: Geom2d.Geom2d_Curve, name=None):
4846
super().__init__(name=name)
4947
self._dimension = 2
48+
self._occ_curve: Geom2d.Geom2d_Curve = None # type: ignore
5049
self.occ_curve = occ_curve
5150

5251
def __eq__(self, other: "OCCCurve2d") -> bool:
@@ -61,20 +60,20 @@ def __eq__(self, other: "OCCCurve2d") -> bool:
6160
# ==============================================================================
6261

6362
@property
64-
def occ_curve(self) -> Geom2d_Curve:
63+
def occ_curve(self) -> Geom2d.Geom2d_Curve:
6564
return self._occ_curve
6665

6766
@occ_curve.setter
68-
def occ_curve(self, curve: Geom2d_Curve):
67+
def occ_curve(self, curve: Geom2d.Geom2d_Curve):
6968
self._occ_curve = curve
7069

7170
@property
72-
def occ_shape(self) -> TopoDS_Shape:
73-
return BRepBuilderAPI_MakeEdge2d(self.occ_curve).Shape()
71+
def occ_shape(self) -> TopoDS.TopoDS_Shape:
72+
return BRepBuilderAPI.BRepBuilderAPI_MakeEdge2d(self.occ_curve).Shape()
7473

7574
@property
76-
def occ_edge(self) -> TopoDS_Edge:
77-
return topods_Edge(self.occ_shape)
75+
def occ_edge(self) -> TopoDS.TopoDS_Edge:
76+
return TopoDS.topods.Edge(self.occ_shape)
7877

7978
# ==============================================================================
8079
# Properties
@@ -109,7 +108,7 @@ def is_periodic(self) -> bool:
109108
# ==============================================================================
110109

111110
@classmethod
112-
def from_occ(cls, occ_curve: Geom2d_Curve) -> "OCCCurve2d":
111+
def from_occ(cls, occ_curve: Geom2d.Geom2d_Curve) -> "OCCCurve2d":
113112
"""Construct a NURBS curve from an existing OCC BSplineCurve.
114113
115114
Parameters
@@ -140,16 +139,11 @@ def to_step(self, filepath: str, schema: str = "AP203") -> None:
140139
None
141140
142141
"""
143-
from OCC.Core.IFSelect import IFSelect_RetDone
144-
from OCC.Core.Interface import Interface_Static_SetCVal
145-
from OCC.Core.STEPControl import STEPControl_AsIs
146-
from OCC.Core.STEPControl import STEPControl_Writer
147-
148-
step_writer = STEPControl_Writer()
149-
Interface_Static_SetCVal("write.step.schema", schema)
150-
step_writer.Transfer(self.occ_edge, STEPControl_AsIs)
142+
step_writer = STEPControl.STEPControl_Writer()
143+
Interface.Interface_Static.SetCVal("write.step.schema", schema)
144+
step_writer.Transfer(self.occ_edge, STEPControl.STEPControl_AsIs)
151145
status = step_writer.Write(filepath)
152-
if status != IFSelect_RetDone:
146+
if status != IFSelect.IFSelect_RetDone:
153147
raise AssertionError("Operation failed.")
154148

155149
def to_polyline(self, n: int = 100) -> Polyline:
@@ -230,8 +224,8 @@ def tangent_at(self, t: float) -> Vector:
230224
if t < start or t > end:
231225
raise ValueError("The parameter is not in the domain of the curve.")
232226

233-
point = gp_Pnt2d()
234-
uvec = gp_Vec2d()
227+
point = gp.gp_Pnt2d()
228+
uvec = gp.gp_Vec2d()
235229
self.occ_curve.D1(t, point, uvec)
236230
return vector2d_to_compas(uvec)
237231

@@ -257,9 +251,9 @@ def curvature_at(self, t: float) -> Vector:
257251
if t < start or t > end:
258252
raise ValueError("The parameter is not in the domain of the curve.")
259253

260-
point = gp_Pnt2d()
261-
uvec = gp_Vec2d()
262-
vvec = gp_Vec2d()
254+
point = gp.gp_Pnt2d()
255+
uvec = gp.gp_Vec2d()
256+
vvec = gp.gp_Vec2d()
263257
self.occ_curve.D2(t, point, uvec, vvec)
264258
return vector2d_to_compas(vvec)
265259

@@ -285,9 +279,9 @@ def frame_at(self, t: float) -> Frame:
285279
if t < start or t > end:
286280
raise ValueError("The parameter is not in the domain of the curve.")
287281

288-
point = gp_Pnt2d()
289-
uvec = gp_Vec2d()
290-
vvec = gp_Vec2d()
282+
point = gp.gp_Pnt2d()
283+
uvec = gp.gp_Vec2d()
284+
vvec = gp.gp_Vec2d()
291285
self.occ_curve.D2(t, point, uvec, vvec)
292286

293287
return Frame(

0 commit comments

Comments
 (0)