Skip to content

Commit 4191986

Browse files
committed
surface nurbs conversion
1 parent 2048836 commit 4191986

File tree

1 file changed

+62
-12
lines changed

1 file changed

+62
-12
lines changed

src/compas_occ/brep/brepface.py

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from OCC.Core.BRepGProp import brepgprop_SurfaceProperties
1616
from OCC.Core.ShapeFix import ShapeFix_Face
1717
from OCC.Core.GProp import GProp_GProps
18+
from OCC.Core.GeomConvert import GeomConvert_ApproxSurface
19+
from OCC.Core.GeomAbs import GeomAbs_Shape
1820

1921
import compas.geometry
2022
from compas.data import Data
@@ -98,31 +100,79 @@ def __init__(self, occ_face: TopoDS_Face = None):
98100
def data(self):
99101
boundary = self.loops[0].data
100102
holes = [loop.data for loop in self.loops[1:]]
101-
if self.is_plane:
102-
plane = compas_plane_from_occ_plane(self.occ_adaptor.Plane())
103-
surfacedata = {"type": "plane", "value": plane.data}
104-
elif self.is_cylinder:
105-
cylinder = compas_cylinder_from_occ_cylinder(self.occ_adaptor.Cylinder())
106-
surfacedata = {"type": "cylinder", "value": cylinder.data}
107-
else:
103+
104+
if self.is_bspline:
108105
surface = self.nurbssurface
109-
surfacedata = {"type": "nurbs", "value": surface.data}
110-
return {"boundary": boundary, "surface": surfacedata, "holes": holes}
106+
surfacedata = {
107+
"type": "nurbs",
108+
"value": surface.data,
109+
}
110+
else:
111+
try:
112+
convert = GeomConvert_ApproxSurface(
113+
self.surface,
114+
1e-3,
115+
GeomAbs_Shape.GeomAbs_C1,
116+
GeomAbs_Shape.GeomAbs_C1,
117+
5,
118+
5,
119+
1,
120+
1,
121+
)
122+
surface = OCCNurbsSurface()
123+
surface.occ_surface = convert.Surface()
124+
surfacedata = {
125+
"type": "nurbs",
126+
"value": surface.data,
127+
}
128+
except Exception:
129+
if self.is_plane:
130+
plane = compas_plane_from_occ_plane(self.occ_adaptor.Plane())
131+
surfacedata = {
132+
"type": "plane",
133+
"value": plane.data,
134+
}
135+
elif self.is_cylinder:
136+
cylinder = compas_cylinder_from_occ_cylinder(
137+
self.occ_adaptor.Cylinder()
138+
)
139+
surfacedata = {
140+
"type": "cylinder",
141+
"value": cylinder.data,
142+
}
143+
elif self.is_cone:
144+
raise NotImplementedError
145+
elif self.is_sphere:
146+
raise NotImplementedError
147+
elif self.is_torus:
148+
raise NotImplementedError
149+
else:
150+
raise
151+
152+
return {
153+
"boundary": boundary,
154+
"surface": surfacedata,
155+
"holes": holes,
156+
}
111157

112158
@data.setter
113159
def data(self, data):
114160
loop = BRepLoop.from_data(data["boundary"])
115161
for hole in data["holes"]:
116162
pass
117-
if data["surface"]["type"] == "plane":
163+
164+
if data["surface"]["type"] == "nurbs":
165+
surface = OCCNurbsSurface.from_data(data["surface"]["value"])
166+
face = BRepFace.from_surface(surface, loop=loop)
167+
elif data["surface"]["type"] == "plane":
118168
plane = Plane.from_data(data["surface"]["value"])
119169
face = BRepFace.from_plane(plane, loop=loop)
120170
elif data["surface"]["type"] == "cylinder":
121171
cylinder = Cylinder.from_data(data["surface"]["value"])
122172
face = BRepFace.from_cylinder(cylinder, loop=loop)
123173
else:
124-
surface = OCCNurbsSurface.from_data(data["surface"]["value"])
125-
face = BRepFace.from_surface(surface, loop=loop)
174+
raise NotImplementedError
175+
126176
self.occ_face = face.occ_face
127177

128178
# ==============================================================================

0 commit comments

Comments
 (0)