2020
2121
2222class RhinoBrep (Brep ):
23- """
24- Rhino Brep backend class.
25- Wraps around and allows serialization and de-serialization of a `Rhino.Geometry.Brep`
23+ """Rhino Brep backend class.
24+
25+ Wraps around and allows serialization and de-serialization of a :class:`Rhino.Geometry.Brep`.
26+
27+ Attributes
28+ ----------
29+ native_brep : :class:`Rhino.Geometry.Brep`
30+ The underlying Rhino Brep instance,
31+ vertices : list[:class:`~compas_rhino.geometry.RhinoBrepVertex`], read-only
32+ The list of vertices which comprise this Brep,
33+ points : list[:class:`~compas.geometry.Point`], read-only
34+ The list of vertex geometries as points in 3D space,
35+ edges : list[:class:`~compas_rhino.geometry.RhinoBrepEdge`], read-only
36+ The list of edges which comprise this brep,
37+ loops : list[:class:`~compas_rhino.geometry.RhinoBrepLoop`], read-only
38+ The list of loops which comprise this brep,
39+ faces : list[:class:`~compas_rhino.geometry.RhinoBrepFace`], read-only
40+ The list of faces which comprise this brep,
41+ frame : :class:`~compas.geometry.Frame`, read-only
42+ The brep's origin (Frame.worldXY()),
43+ area : float, read-only
44+ The calculated area of this brep.
45+ volume : float, read-only
46+ The calculated volume of this brep.
47+
2648 """
2749
2850 # this makes de-serialization backend-agnostic.
@@ -40,20 +62,6 @@ def __init__(self, brep=None):
4062 super (RhinoBrep , self ).__init__ ()
4163 self ._brep = brep or Rhino .Geometry .Brep ()
4264
43- # ==============================================================================
44- # Constructors
45- # ==============================================================================
46-
47- @classmethod
48- def from_brep (cls , rhino_brep ):
49- brep = cls (rhino_brep )
50- return brep
51-
52- @classmethod
53- def from_box (cls , box ):
54- rhino_box = box_to_rhino (box )
55- return cls .from_brep (rhino_box .ToBrep ())
56-
5765 # ==============================================================================
5866 # Data
5967 # ==============================================================================
@@ -67,15 +75,6 @@ def data(self):
6775
6876 @data .setter
6977 def data (self , data ):
70- """
71- Parameters
72- ----------
73- data
74-
75- Returns
76- -------
77-
78- """
7978 faces = []
8079 for facedata in data ["faces" ]:
8180 face = RhinoBrepFace .from_data (facedata )
@@ -88,13 +87,6 @@ def data(self, data):
8887
8988 @property
9089 def native_brep (self ):
91- """
92- Returns the native representation of this Brep.
93-
94- Returns
95- -------
96- :class: `Rhino.Geometry.Brep`
97- """
9890 return self ._brep
9991
10092 @property
@@ -135,18 +127,101 @@ def volume(self):
135127 if self ._brep :
136128 return self ._brep .GetVolume ()
137129
138- def _create_native_brep (self , faces ):
130+ # ==============================================================================
131+ # Constructors
132+ # ==============================================================================
133+
134+ @classmethod
135+ def from_brep (cls , rhino_brep ):
136+ """Constructs a RhinoBrep from an instance of a Rhino brep
137+
138+ Parameters
139+ ----------
140+ rhino_brep : :class:`Rhino.Geometry.Brep`
141+ The instance of Rhino brep to wrap.
142+
143+ Returns
144+ -------
145+ :class:`compas_rhino.geometry.RhinoBrep`
146+
147+ """
148+ brep = cls (rhino_brep )
149+ return brep
150+
151+ @classmethod
152+ def from_box (cls , box ):
153+ """Create a RhinoBrep from a box.
154+
155+ Parameters
156+ ----------
157+ box : :class:`~compas.geometry.Box`
158+ The box geometry of the brep.
159+
160+ Returns
161+ -------
162+ :class:`~compas_rhino.geometry.RhinoBrep`
163+
164+ """
165+ rhino_box = box_to_rhino (box )
166+ return cls .from_brep (rhino_box .ToBrep ())
167+
168+ # ==============================================================================
169+ # Methods
170+ # ==============================================================================
171+
172+ def transform (self , matrix ):
173+ """Transform this Brep by given transformation matrix
174+
175+ Parameters
176+ ----------
177+ matrix: :class:`~compas.geometry.Transformation`
178+ The transformation matrix by which to transform this Brep.
179+
180+ Returns
181+ -------
182+ None
183+
139184 """
140- Source: https://github.com/mcneel/rhino-developer-samples/blob/3179a8386a64602ee670cc832c77c561d1b0944b/rhinocommon/cs/SampleCsCommands/SampleCsTrimmedPlane.cs
141- Things need to be defined in a valid brep:
142- 1- Vertices
143- 2- 3D Curves (geometry)
144- 3- Edges (topology - reference curve geometry)
145- 4- Surfaces (geometry)
146- 5- Faces (topology - reference surface geometry)
147- 6- Loops (2D parameter space of faces)
148- 4- Trims and 2D curves (2D parameter space of edges)
185+ self ._brep .Transform (xform_to_rhino (matrix ))
186+
187+ def trim (self , trimming_plane , tolerance = TOLERANCE ):
188+ """Trim this brep by the given trimming plane
189+
190+ Parameters
191+ ----------
192+ trimming_plane : :class:`~compas.geometry.Frame` or :class:`~compas.geometry.Plane`
193+ The frame or plane to use when trimming.
194+
195+ tolerance : float
196+ The precision to use for the trimming operation.
197+
198+ Returns
199+ -------
200+ None
201+
149202 """
203+ rhino_frame = frame_to_rhino (trimming_plane )
204+ rhino_frame .Flip ()
205+ results = self ._brep .Trim (rhino_frame , tolerance )
206+ if not results :
207+ raise BrepTrimmingError ("Trim operation ended with no result" )
208+
209+ self ._brep = results [0 ]
210+
211+ # ==============================================================================
212+ # Other Methods
213+ # ==============================================================================
214+
215+ def _create_native_brep (self , faces ):
216+ # Source: https://github.com/mcneel/rhino-developer-samples/blob/3179a8386a64602ee670cc832c77c561d1b0944b/rhinocommon/cs/SampleCsCommands/SampleCsTrimmedPlane.cs
217+ # Things need to be defined in a valid brep:
218+ # 1- Vertices
219+ # 2- 3D Curves (geometry)
220+ # 3- Edges (topology - reference curve geometry)
221+ # 4- Surfaces (geometry)
222+ # 5- Faces (topology - reference surface geometry)
223+ # 6- Loops (2D parameter space of faces)
224+ # 4- Trims and 2D curves (2D parameter space of edges)
150225 self ._brep = Rhino .Geometry .Brep ()
151226 for face in faces :
152227 rhino_face , rhino_surface = self ._create_brep_face (face )
@@ -213,36 +288,3 @@ def _create_trim_curve(rhino_edge, rhino_surface):
213288 curve_2d = rhino_surface .Pullback (rhino_edge .EdgeCurve , TOLERANCE )
214289 curve_2d .Reverse ()
215290 return curve_2d
216-
217- # ==============================================================================
218- # Methods
219- # ==============================================================================
220-
221- def transform (self , matrix ):
222- """
223- Transform this Brep by given transformation matrix
224- Parameters
225- ----------
226- matrix: :class:`~compas.geometry.Transformation`
227- The transformation matrix by which to transform this Brep.
228- """
229- self ._brep .Transform (xform_to_rhino (matrix ))
230-
231- def trim (self , trimming_plane , tolerance = TOLERANCE ):
232- """Trim this brep by the given trimming plane
233-
234- Parameters
235- ----------
236- trimming_plane
237- :class:`~compas.geometry.Frame`
238-
239- tolerance: the tolerance to use when trimming
240- float
241- """
242- rhino_frame = frame_to_rhino (trimming_plane )
243- rhino_frame .Flip ()
244- results = self ._brep .Trim (rhino_frame , tolerance )
245- if not results :
246- raise BrepTrimmingError ("Trim operation ended with no result" )
247-
248- self ._brep = results [0 ]
0 commit comments