|
2 | 2 | from compas.geometry import Line |
3 | 3 | from compas.geometry import Circle |
4 | 4 | from compas.geometry import Ellipse |
| 5 | +from compas.geometry import Frame |
| 6 | +from compas.geometry import Arc |
5 | 7 | from compas_rhino.geometry import RhinoNurbsCurve |
6 | 8 | from compas_rhino.conversions import curve_to_compas_line |
| 9 | +from compas_rhino.conversions import plane_to_compas_frame |
| 10 | +from compas_rhino.conversions import circle_to_compas |
| 11 | +from compas_rhino.conversions import ellipse_to_compas |
| 12 | +from compas_rhino.conversions import ellipse_to_rhino |
| 13 | +from compas_rhino.conversions import circle_to_rhino |
| 14 | +from compas_rhino.conversions import frame_to_rhino_plane |
| 15 | +from compas_rhino.conversions import line_to_rhino |
| 16 | +from compas_rhino.conversions import arc_to_compas |
| 17 | +from compas_rhino.conversions import arc_to_rhino |
| 18 | + |
| 19 | +from Rhino.Geometry import ArcCurve |
| 20 | +from Rhino.Geometry import NurbsCurve |
| 21 | +from Rhino.Geometry import LineCurve |
| 22 | +from Rhino.Geometry import NurbsCurve |
| 23 | +from Rhino.Geometry import Interval |
7 | 24 |
|
8 | 25 | # from compas_rhino.conversions import curve_to_compas_circle |
9 | 26 | # from compas_rhino.conversions import curve_to_compas_ellipse |
10 | 27 | from compas_rhino.conversions import line_to_rhino_curve |
11 | 28 | from compas_rhino.conversions import circle_to_rhino_curve |
12 | 29 | from compas_rhino.conversions import ellipse_to_rhino_curve |
13 | 30 |
|
14 | | - |
15 | 31 | from .vertex import RhinoBrepVertex |
16 | 32 |
|
17 | 33 |
|
@@ -62,17 +78,19 @@ def _set_edge(self, rhino_edge): |
62 | 78 |
|
63 | 79 | @property |
64 | 80 | def data(self): |
65 | | - curve_type, curve = self._get_curve_geometry() |
| 81 | + curve_type, curve, plane, domain = self._get_curve_geometry() |
66 | 82 | return { |
67 | 83 | "curve_type": curve_type, |
68 | 84 | "curve": curve.data, |
| 85 | + "frame": plane_to_compas_frame(plane).data, |
69 | 86 | "start_vertex": self._edge.StartVertex.VertexIndex, |
70 | 87 | "end_vertex": self._edge.EndVertex.VertexIndex, |
| 88 | + "domain": domain, |
71 | 89 | } |
72 | 90 |
|
73 | 91 | @data.setter |
74 | 92 | def data(self, value): |
75 | | - edge_curve = self._create_curve_from_data(value["curve_type"], value["curve"]) |
| 93 | + edge_curve = self._create_curve_from_data(value["curve_type"], value["curve"], value["frame"], value["domain"]) |
76 | 94 | edge = self._builder.add_edge(edge_curve, value["start_vertex"], value["end_vertex"]) |
77 | 95 | self._set_edge(edge) |
78 | 96 |
|
@@ -131,28 +149,45 @@ def is_ellipse(self): |
131 | 149 |
|
132 | 150 | def _get_curve_geometry(self): |
133 | 151 | curve = self._edge.EdgeCurve |
134 | | - if self.is_line: |
135 | | - type_ = "line" |
136 | | - curve = curve_to_compas_line(curve) |
137 | | - # TODO: there is an edge/trim direction issue when creating and edge from circle |
138 | | - # elif self.is_circle: |
139 | | - # type_ = "circle" |
140 | | - # curve = curve_to_compas_circle(curve) |
141 | | - # elif self.is_ellipse: |
142 | | - # type_ = "ellipse" |
143 | | - # curve = curve_to_compas_ellipse(curve) |
144 | | - else: |
145 | | - type_ = "nurbs" |
146 | | - curve = self._curve |
147 | | - return type_, curve |
| 152 | + domain = [self._edge.Domain[0], self._edge.Domain[1]] |
| 153 | + _, frame = curve.FrameAt(0) |
| 154 | + if isinstance(curve, LineCurve): |
| 155 | + return "line", curve_to_compas_line(curve), frame, domain |
| 156 | + if isinstance(curve, NurbsCurve): |
| 157 | + return "nurbs", RhinoNurbsCurve.from_rhino(curve), frame, domain |
| 158 | + if isinstance(curve, ArcCurve): |
| 159 | + if not curve.IsClosed: |
| 160 | + return "arc", arc_to_compas(curve.Arc), curve.Arc.Plane, domain |
| 161 | + is_circle, circle = curve.TryGetCircle() |
| 162 | + if is_circle: |
| 163 | + return "circle", circle_to_compas(circle), circle.Plane, domain |
| 164 | + is_ellipse, ellipse = curve.TryGetEllipse() |
| 165 | + if is_ellipse: |
| 166 | + return "ellipse", ellipse_to_compas(ellipse), ellipse.Plane, domain |
| 167 | + return "nurbs", curve.ToNurbsCurve(), frame, domain |
| 168 | + raise ValueError("Unknown curve type: {}".format(curve.__class__.__name__)) |
148 | 169 |
|
149 | 170 | @staticmethod |
150 | | - def _create_curve_from_data(curve_type, curve_data): |
| 171 | + def _create_curve_from_data(curve_type, curve_data, frame_data, domain): |
| 172 | + frame = Frame.from_data(frame_data) |
151 | 173 | if curve_type == "line": |
152 | | - return line_to_rhino_curve(Line.from_data(curve_data)) |
| 174 | + line = Line.from_data(curve_data) |
| 175 | + curve = LineCurve(line_to_rhino(line)) |
153 | 176 | elif curve_type == "circle": |
154 | | - return circle_to_rhino_curve(Circle.from_data(curve_data)) |
| 177 | + circle = circle_to_rhino(Circle.from_data(curve_data)) |
| 178 | + circle.Plane = frame_to_rhino_plane(frame) |
| 179 | + curve = ArcCurve(circle) |
155 | 180 | elif curve_type == "ellipse": |
156 | | - return ellipse_to_rhino_curve(Ellipse.from_data(curve_data)) |
| 181 | + ellipse = ellipse_to_rhino(Ellipse.from_data(curve_data)) |
| 182 | + ellipse.Plane = frame_to_rhino_plane(frame) |
| 183 | + curve = NurbsCurve.CreateFromEllipse(ellipse) |
| 184 | + elif curve_type == "arc": |
| 185 | + arc = arc_to_rhino(Arc.from_data(curve_data)) |
| 186 | + curve = ArcCurve(arc) |
| 187 | + elif curve_type == "nurbs": |
| 188 | + curve = RhinoNurbsCurve.from_data(curve_data).rhino_curve |
157 | 189 | else: |
158 | | - return RhinoNurbsCurve.from_data(curve_data).rhino_curve |
| 190 | + raise ValueError("Unknown curve type: {}".format(curve_type)) |
| 191 | + curve.Domain = (Interval(*domain)) |
| 192 | + return curve |
| 193 | + |
0 commit comments