Skip to content

Commit 925394e

Browse files
committed
update to latest compas
1 parent debc501 commit 925394e

File tree

10 files changed

+590
-555
lines changed

10 files changed

+590
-555
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
compas >=2.1
1+
compas >=2.3
Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
11
from .curve2d import OCCCurve2d # noqa : F401
2-
from .curve import OCCCurve # noqa: F401
2+
from .curve import OCCCurve
33
from .nurbs import OCCNurbsCurve
44

5-
from compas.geometry import Curve
6-
from compas.geometry import NurbsCurve
7-
85
from compas.plugins import plugin
96

107

118
@plugin(category="factories", requires=["compas_occ"])
12-
def new_curve(cls, *args, **kwargs):
13-
# curve = object.__new__(OCCCurve)
14-
# return curve
15-
return super(Curve, cls).__new__(cls)
9+
def curve_from_native(cls, *args, **kwargs):
10+
return OCCCurve.from_native(*args, **kwargs)
1611

1712

1813
@plugin(category="factories", requires=["compas_occ"])
19-
def new_nurbscurve(cls, *args, **kwargs):
20-
# curve = object.__new__(OCCNurbsCurve)
21-
# return curve
22-
return super(NurbsCurve, cls).__new__(cls)
14+
def nurbscurve_from_native(cls, *args, **kwargs):
15+
return OCCNurbsCurve.from_native(*args, **kwargs)
2316

2417

2518
@plugin(category="factories", requires=["compas_occ"])
26-
def new_nurbscurve_from_native(cls, *args, **kwargs):
27-
return OCCNurbsCurve.from_occ(*args, **kwargs)
19+
def nurbscurve_from_interpolation(cls, *args, **kwargs):
20+
return OCCNurbsCurve.from_interpolation(*args, **kwargs)
2821

2922

3023
@plugin(category="factories", requires=["compas_occ"])
31-
def new_nurbscurve_from_parameters(cls, *args, **kwargs):
24+
def nurbscurve_from_parameters(cls, *args, **kwargs):
3225
return OCCNurbsCurve.from_parameters(*args, **kwargs)
3326

3427

3528
@plugin(category="factories", requires=["compas_occ"])
36-
def new_nurbscurve_from_points(cls, *args, **kwargs):
29+
def nurbscurve_from_points(cls, *args, **kwargs):
3730
return OCCNurbsCurve.from_points(*args, **kwargs)
3831

3932

4033
@plugin(category="factories", requires=["compas_occ"])
41-
def new_nurbscurve_from_interpolation(cls, *args, **kwargs):
42-
return OCCNurbsCurve.from_interpolation(*args, **kwargs)
43-
44-
45-
@plugin(category="factories", requires=["compas_occ"])
46-
def new_nurbscurve_from_step(cls, *args, **kwargs):
34+
def nurbscurve_from_step(cls, *args, **kwargs):
4735
return OCCNurbsCurve.from_step(*args, **kwargs)

src/compas_occ/geometry/curves/curve.py

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,10 @@ class OCCCurve(Curve):
6363
6464
"""
6565

66-
def __init__(self, occ_curve: Geom_Curve, name=None):
66+
def __init__(self, native_curve: Geom_Curve, name=None):
6767
super().__init__(name=name)
6868
self._dimension = 3
69-
self._occ_curve: Geom_Curve = None # type: ignore
70-
self.occ_curve = occ_curve
69+
self._native_curve: Geom_Curve = native_curve
7170

7271
def __eq__(self, other: "OCCCurve") -> bool:
7372
raise NotImplementedError
@@ -81,16 +80,20 @@ def __eq__(self, other: "OCCCurve") -> bool:
8180
# ==============================================================================
8281

8382
@property
84-
def occ_curve(self) -> Geom_Curve:
85-
return self._occ_curve
83+
def native_curve(self) -> Geom_Curve:
84+
return self._native_curve
8685

87-
@occ_curve.setter
88-
def occ_curve(self, curve: Geom_Curve):
89-
self._occ_curve = curve
86+
@native_curve.setter
87+
def native_curve(self, curve: Geom_Curve):
88+
self._native_curve = curve
89+
90+
@property
91+
def occ_curve(self) -> Geom_Curve:
92+
return self._native_curve
9093

9194
@property
9295
def occ_shape(self) -> TopoDS_Shape:
93-
return BRepBuilderAPI_MakeEdge(self.occ_curve).Shape()
96+
return BRepBuilderAPI_MakeEdge(self.native_curve).Shape()
9497

9598
@property
9699
def occ_edge(self) -> TopoDS_Edge:
@@ -106,7 +109,7 @@ def dimension(self) -> int:
106109

107110
@property
108111
def domain(self) -> Tuple[float, float]:
109-
return self.occ_curve.FirstParameter(), self.occ_curve.LastParameter()
112+
return self.native_curve.FirstParameter(), self.native_curve.LastParameter()
110113

111114
@property
112115
def start(self) -> Point:
@@ -118,31 +121,50 @@ def end(self) -> Point:
118121

119122
@property
120123
def is_closed(self) -> bool:
121-
return self.occ_curve.IsClosed()
124+
return self.native_curve.IsClosed()
122125

123126
@property
124127
def is_periodic(self) -> bool:
125-
return self.occ_curve.IsPeriodic()
128+
return self.native_curve.IsPeriodic()
126129

127130
# ==============================================================================
128131
# Constructors
129132
# ==============================================================================
130133

131134
@classmethod
132-
def from_occ(cls, occ_curve: Geom_Curve) -> "OCCCurve":
133-
"""Construct a NURBS curve from an existing OCC BSplineCurve.
135+
def from_native(cls, native_curve: Geom_Curve) -> "OCCCurve":
136+
"""Construct a curve from an existing OCC BSplineCurve.
134137
135138
Parameters
136139
----------
137-
occ_curve : Geom_Curve
140+
native_curve : Geom_Curve
138141
139142
Returns
140143
-------
141144
:class:`OCCCurve`
142145
143146
"""
144-
curve = cls(occ_curve)
145-
return curve
147+
return cls(native_curve)
148+
149+
@classmethod
150+
def from_occ(cls, native_curve: Geom_Curve) -> "OCCCurve":
151+
"""Construct a curve from an existing OCC BSplineCurve.
152+
153+
Parameters
154+
----------
155+
native_curve : Geom_Curve
156+
157+
Returns
158+
-------
159+
:class:`OCCCurve`
160+
161+
Warnings
162+
--------
163+
.. deprecated:: 1.3
164+
Use `from_native` instead.
165+
166+
"""
167+
return cls(native_curve)
146168

147169
# ==============================================================================
148170
# Conversions
@@ -196,8 +218,8 @@ def copy(self) -> "OCCCurve":
196218
197219
"""
198220
cls = type(self)
199-
occ_curve = self.occ_curve.Copy()
200-
return cls(occ_curve) # type: ignore (Copy returns Geom_Geometry)
221+
native_curve = self.native_curve.Copy()
222+
return cls(native_curve) # type: ignore (Copy returns Geom_Geometry)
201223

202224
def transform(self, T: Transformation) -> None:
203225
"""Transform this curve.
@@ -211,7 +233,7 @@ def transform(self, T: Transformation) -> None:
211233
None
212234
213235
"""
214-
self.occ_curve.Transform(compas_transformation_to_trsf(T))
236+
self.native_curve.Transform(compas_transformation_to_trsf(T))
215237

216238
def reverse(self) -> None:
217239
"""Reverse the parametrisation of the curve.
@@ -221,7 +243,7 @@ def reverse(self) -> None:
221243
None
222244
223245
"""
224-
self.occ_curve.Reverse()
246+
self.native_curve.Reverse()
225247

226248
def point_at(self, t: float) -> Point:
227249
"""Compute the point at a curve parameter.
@@ -241,11 +263,11 @@ def point_at(self, t: float) -> Point:
241263
If the parameter is not in the curve domain.
242264
243265
"""
244-
start, end = self.domain # type: ignore (domain could be None if no occ_curve is set)
266+
start, end = self.domain # type: ignore (domain could be None if no native_curve is set)
245267
if t < start or t > end:
246268
raise ValueError("The parameter is not in the domain of the curve. t = {}, domain: {}".format(t, self.domain))
247269

248-
point = self.occ_curve.Value(t)
270+
point = self.native_curve.Value(t)
249271
return point_to_compas(point)
250272

251273
def tangent_at(self, t: float) -> Vector:
@@ -266,13 +288,13 @@ def tangent_at(self, t: float) -> Vector:
266288
If the parameter is not in the curve domain.
267289
268290
"""
269-
start, end = self.domain # type: ignore (domain could be None if no occ_curve is set)
291+
start, end = self.domain # type: ignore (domain could be None if no native_curve is set)
270292
if t < start or t > end:
271293
raise ValueError("The parameter is not in the domain of the curve.")
272294

273295
point = gp_Pnt()
274296
uvec = gp_Vec()
275-
self.occ_curve.D1(t, point, uvec)
297+
self.native_curve.D1(t, point, uvec)
276298

277299
return vector_to_compas(uvec)
278300

@@ -294,14 +316,14 @@ def curvature_at(self, t: float) -> Vector:
294316
If the parameter is not in the curve domain.
295317
296318
"""
297-
start, end = self.domain # type: ignore (domain could be None if no occ_curve is set)
319+
start, end = self.domain # type: ignore (domain could be None if no native_curve is set)
298320
if t < start or t > end:
299321
raise ValueError("The parameter is not in the domain of the curve.")
300322

301323
point = gp_Pnt()
302324
uvec = gp_Vec()
303325
vvec = gp_Vec()
304-
self.occ_curve.D2(t, point, uvec, vvec)
326+
self.native_curve.D2(t, point, uvec, vvec)
305327

306328
return vector_to_compas(vvec)
307329

@@ -323,14 +345,14 @@ def frame_at(self, t: float) -> Frame:
323345
If the parameter is not in the curve domain.
324346
325347
"""
326-
start, end = self.domain # type: ignore (domain could be None if no occ_curve is set)
348+
start, end = self.domain # type: ignore (domain could be None if no native_curve is set)
327349
if t < start or t > end:
328350
raise ValueError("The parameter is not in the domain of the curve.")
329351

330352
point = gp_Pnt()
331353
uvec = gp_Vec()
332354
vvec = gp_Vec()
333-
self.occ_curve.D2(t, point, uvec, vvec)
355+
self.native_curve.D2(t, point, uvec, vvec)
334356

335357
return Frame(
336358
point_to_compas(point),
@@ -363,7 +385,7 @@ def parameter_at_distance(
363385
The new parameter.
364386
365387
"""
366-
a = GCPnts_AbscissaPoint(GeomAdaptor_Curve(self.occ_curve), distance, t, precision)
388+
a = GCPnts_AbscissaPoint(GeomAdaptor_Curve(self.native_curve), distance, t, precision)
367389
return a.Parameter()
368390

369391
def aabb(self, precision: float = 0.0) -> Box:
@@ -379,7 +401,7 @@ def aabb(self, precision: float = 0.0) -> Box:
379401
380402
"""
381403
box = Bnd_Box()
382-
BndLib_Add3dCurve.Add(GeomAdaptor_Curve(self.occ_curve), precision, box)
404+
BndLib_Add3dCurve.Add(GeomAdaptor_Curve(self.native_curve), precision, box)
383405
return Box.from_diagonal(
384406
(
385407
point_to_compas(box.CornerMin()),
@@ -399,7 +421,7 @@ def length(self, precision: float = 1e-3) -> float:
399421
float
400422
401423
"""
402-
return GCPnts_AbscissaPoint.Length(GeomAdaptor_Curve(self.occ_curve), precision)
424+
return GCPnts_AbscissaPoint.Length(GeomAdaptor_Curve(self.native_curve), precision)
403425

404426
def closest_point(
405427
self,
@@ -424,7 +446,7 @@ def closest_point(
424446
If `return_parameter` is True, the nearest point on the curve and the corresponding parameter.
425447
426448
"""
427-
projector = GeomAPI_ProjectPointOnCurve(point_to_occ(point), self.occ_curve)
449+
projector = GeomAPI_ProjectPointOnCurve(point_to_occ(point), self.native_curve)
428450

429451
try:
430452
point = point_to_compas(projector.NearestPoint())
@@ -448,11 +470,11 @@ def closest_point(
448470
if d_start <= d_end:
449471
if not return_parameter:
450472
return start
451-
return start, self.occ_curve.FirstParameter()
473+
return start, self.native_curve.FirstParameter()
452474

453475
if not return_parameter:
454476
return end
455-
return end, self.occ_curve.LastParameter()
477+
return end, self.native_curve.LastParameter()
456478

457479
def closest_parameters_curve(
458480
self,
@@ -475,7 +497,7 @@ def closest_parameters_curve(
475497
If `return_distance` is True, the distance between the two curves in addition to the curve parameters.
476498
477499
"""
478-
extrema = GeomAPI_ExtremaCurveCurve(self.occ_curve, curve.occ_curve)
500+
extrema = GeomAPI_ExtremaCurveCurve(self.native_curve, curve.native_curve)
479501
if not return_distance:
480502
return extrema.LowerDistanceParameters()
481503
return extrema.LowerDistanceParameters(), extrema.LowerDistance()
@@ -502,7 +524,7 @@ def closest_points_curve(
502524
503525
"""
504526
a, b = gp_Pnt(), gp_Pnt()
505-
extrema = GeomAPI_ExtremaCurveCurve(self.occ_curve, curve.occ_curve)
527+
extrema = GeomAPI_ExtremaCurveCurve(self.native_curve, curve.native_curve)
506528
extrema.NearestPoints(a, b)
507529
points = point_to_compas(a), point_to_compas(b)
508530
if not return_distance:
@@ -540,7 +562,7 @@ def divide_by_count(
540562
a, b = self.domain
541563
t = a
542564
params = [t]
543-
adaptor = GeomAdaptor_Curve(self.occ_curve)
565+
adaptor = GeomAdaptor_Curve(self.native_curve)
544566
for _ in range(count - 1):
545567
a = GCPnts_AbscissaPoint(adaptor, length, t, precision)
546568
t = a.Parameter()
@@ -587,7 +609,7 @@ def divide_by_length(
587609
a, b = self.domain
588610
t = a
589611
params = [t]
590-
adaptor = GeomAdaptor_Curve(self.occ_curve)
612+
adaptor = GeomAdaptor_Curve(self.native_curve)
591613
for _ in range(count - 1):
592614
a = GCPnts_AbscissaPoint(adaptor, length, t, precision)
593615
t = a.Parameter()
@@ -611,7 +633,7 @@ def projected(self, surface) -> "OCCCurve":
611633
:class:`OCCCurve`
612634
613635
"""
614-
result = geomprojlib.Project(self.occ_curve, surface.occ_surface)
636+
result = geomprojlib.Project(self.native_curve, surface.occ_surface)
615637
curve = OCCCurve.from_occ(result)
616638
return curve
617639

@@ -628,7 +650,7 @@ def embedded(self, surface) -> OCCCurve2d:
628650
:class:`OCCCurve2d`
629651
630652
"""
631-
result = geomprojlib.Curve2d(self.occ_curve, surface.occ_surface)
653+
result = geomprojlib.Curve2d(self.native_curve, surface.occ_surface)
632654
curve = OCCCurve2d.from_occ(result)
633655
return curve
634656

@@ -651,9 +673,9 @@ def offset(self, distance: float, direction: Vector) -> "OCCCurve":
651673
:class:`OCCCurve`
652674
653675
"""
654-
occ_curve = Geom_OffsetCurve(
655-
self.occ_curve,
676+
native_curve = Geom_OffsetCurve(
677+
self.native_curve,
656678
distance,
657679
direction_to_occ(direction),
658680
)
659-
return OCCCurve.from_occ(occ_curve)
681+
return OCCCurve.from_occ(native_curve)

0 commit comments

Comments
 (0)