|
15 | 15 | from OCC.Core.BRepGProp import brepgprop_SurfaceProperties |
16 | 16 | from OCC.Core.ShapeFix import ShapeFix_Face |
17 | 17 | from OCC.Core.GProp import GProp_GProps |
| 18 | +from OCC.Core.GeomConvert import GeomConvert_ApproxSurface |
| 19 | +from OCC.Core.GeomAbs import GeomAbs_Shape |
18 | 20 |
|
19 | 21 | import compas.geometry |
20 | 22 | from compas.data import Data |
@@ -98,31 +100,79 @@ def __init__(self, occ_face: TopoDS_Face = None): |
98 | 100 | def data(self): |
99 | 101 | boundary = self.loops[0].data |
100 | 102 | 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: |
108 | 105 | 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 | + } |
111 | 157 |
|
112 | 158 | @data.setter |
113 | 159 | def data(self, data): |
114 | 160 | loop = BRepLoop.from_data(data["boundary"]) |
115 | 161 | for hole in data["holes"]: |
116 | 162 | 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": |
118 | 168 | plane = Plane.from_data(data["surface"]["value"]) |
119 | 169 | face = BRepFace.from_plane(plane, loop=loop) |
120 | 170 | elif data["surface"]["type"] == "cylinder": |
121 | 171 | cylinder = Cylinder.from_data(data["surface"]["value"]) |
122 | 172 | face = BRepFace.from_cylinder(cylinder, loop=loop) |
123 | 173 | else: |
124 | | - surface = OCCNurbsSurface.from_data(data["surface"]["value"]) |
125 | | - face = BRepFace.from_surface(surface, loop=loop) |
| 174 | + raise NotImplementedError |
| 175 | + |
126 | 176 | self.occ_face = face.occ_face |
127 | 177 |
|
128 | 178 | # ============================================================================== |
|
0 commit comments