55from compas .geometry import Point
66from compas .geometry import Polyline
77from 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
1616from compas_occ .conversions import point2d_to_compas
1717from 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