QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_objref.h
Go to the documentation of this file.
1/* $NoKeywords: $ */
2/*
3//
4// Copyright (c) 1993-2007 Robert McNeel & Associates. All rights reserved.
5// Rhinoceros is a registered trademark of Robert McNeel & Assoicates.
6//
7// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
8// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
9// MERCHANTABILITY ARE HEREBY DISCLAIMED.
10//
11// For complete openNURBS copyright information see <http://www.opennurbs.org>.
12//
14*/
15
16#if !defined(ON_OBJREF_INC_)
17#define ON_OBJREF_INC_
18
20{
21public:
24
25 void Default();
26
27 bool Write( ON_BinaryArchive& ) const;
28 bool Read( ON_BinaryArchive& );
29
30
31 // If m_point != ON_UNSET_POINT and m_t_type != 0, then
32 // m_t_type, m_t, and m_t_ci record the m_geometry evaluation
33 // parameters of the m_point.
34 //
35 // m_t_type values
36 //
37 // 0: no parameter values; m_t_ci and m_t[] have no meaning.
38 //
39 // 1: m_geometry points to a curve, m_t[0] is a curve
40 // parameter for m_point, and m_t_ci has no meaning.
41 //
42 // 2: m_geometry points to surface or single faced brep,
43 // (m_t[0],m_t[1]) is a surface parameter for m_point,
44 // and m_t_ci has no meaning.
45 // In this case, m_component_index may not be set or,
46 // if m_geometry points to a brep face, m_component_index
47 // may identify the face in the parent brep.
48 //
49 // 3: m_geometry points to a brep edge with an associated
50 // trim and m_t[0] is the edge parameter for m_point.
51 // m_t_ci is the ON_BrepTrim component index and m_t[1]
52 // is the ON_BrepTrim parameter that corresponds to the
53 // edge point. m_s[0] and m_s[1] are normalized parameters.
54 // In this case m_component_index identifies the
55 // the edge in the brep and m_t_ci identifies a trim.
56 //
57 // 4: m_geometry points to a mesh or mesh face and
58 // m_t_ci identifies the mesh face.
59 // If the face is a triangle, the barycentric coordinates
60 // of m_point are(m_t[0], m_t[1], m_t[2]) and m_t[3] is zero.
61 // If the mesh face is a quadrangle, the barycentric coordinates
62 // of m_point are (m_t[0], m_t[1], m_t[2], m_t[3]) and at least
63 // one of the coordinates is zero. In both cases, the point
64 // can be evaluated using the formula
65 // m_t[0]*mesh.m_V[f.vi[0]] + ... + m_t[3]*mesh.m_V[f.vi[3]],
66 // where f = mesh.m_F[m_component_index.m_index].
67 // In this case, if m_geometry points to a mesh, then
68 // m_component_index != m_t_ci.
69 //
70 // 5: m_geometry points to a mesh or mesh edge and m_t_ci
71 // identifies the mesh edge. The normalized coordinate of
72 // the point on the mesh edge is m_t[0]. The point can be evaluated
73 // using the formula
74 // m_t[0]*mesh.m_V[v0] + (1.0-m_t[0])*mesh.m_V[v1],
75 // where v0 and v1 are the indices of the mesh vertices at
76 // the edge's ends.
77 // In this case, if m_geometry points to a mesh, then
78 // m_component_index != m_t_ci.
79 //
80 // 6: m_geometry points to a NURBS cage and (m_t[0],m_t[1],m_t[2])
81 // are cage evaluation parameters.
82 //
83 // 7: m_geometry points to an annotation object and m_t_ci identifies
84 // a point on the annotation object.
85 //
86 // 8: m_geometry points to a mesh or mesh vertex object and m_t_ci
87 // identifies a vertex on the mesh object.
88 //
90private:
91 int m_reserved; // for future use to record snap info.
92public:
93 double m_t[4];
94 ON_Interval m_s[3]; // curve/surface/cage domains
95 ON_COMPONENT_INDEX m_t_ci; // Not necesarily the same as m_component_index
96 // See comment above for details.
97};
98
100{
101public:
104
105 bool Write(ON_BinaryArchive&) const;
106 bool Read(ON_BinaryArchive&);
107
108 void Default();
109
110 // m_iref_uuid is the CRhinoInstanceObject's uuid stored
111 // in its ON_3dmObjectAttributes.m_uuid.
113
114 // m_iref_xform is the value stored in ON_InstanceRef.m_xform.
116
117 // m_idef_uuid is the instance definition id stored in
118 // ON_InstanceRef.m_instance_definition_uuid and
119 // ON_InstanceDefinition.m_uuid.
121
122 // m_geometry_index is the index of the uuid of the pertinant
123 // piece of geometry in the ON_InstanceRef.m_object_uuid[]
124 // array. This index is identical to the index of the
125 // geometry's CRhinoObject in the
126 // CRhinoInstanceDefinition.m_objects[] array.
128
129 // m_geometry_xform is the transformation to map the
130 // base geometry to world coordinates. If the
131 // instance reference is not nested, then
132 // m_geometry_xform = m_iref_xform. If the instance
133 // reference is nested, then
134 // m_geometry_xform = m_iref_xform * .... * T1
135 // where the Ts are the transformations from the children.
137
138 // If this ON_ObjRef_IRefID is the first entry in the
139 // ON_ObjRef.m__iref[] array, then it references a "real"
140 // piece of geometry (not a nested instance reference).
141 // If the reference is to a subobject of the real piece
142 // of geometry, then m_component_index records
143 // the subobject index.
144 // In all other cases, m_component_index is not set.
145 ON_COMPONENT_INDEX m_component_index;
146
147 // If this ON_ObjRef_IRefID is the first entry in the
148 // ON_ObjRef.m__iref[] array, then it references a "real"
149 // piece of geometry (not a nested instance reference).
150 // If there is an evaluation parameter for the geometry,
151 // it is saved in m_evp.
152 // In all other cases, m_evp is not set.
154};
155
156#if defined(ON_DLL_TEMPLATE)
157// This stuff is here because of a limitation in the way Microsoft
158// handles templates and DLLs. See Microsoft's knowledge base
159// article ID Q168958 for details.
160#pragma warning( push )
161#pragma warning( disable : 4231 )
162ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_ObjRef_IRefID>;
163#pragma warning( pop )
164#endif
165
167{
168public:
169 ON_ObjRef();
170 ON_ObjRef(const ON_ObjRef& src);
171 ON_ObjRef& operator=(const ON_ObjRef& src);
172 ~ON_ObjRef();
173
174 bool Write( ON_BinaryArchive& ) const;
175 bool Read( ON_BinaryArchive& );
176
177 // In Rhino, this uuid is the persistent id of the CRhinoObject
178 // that owns the referenced geometry. The value of the
179 // CRhinoObject id is stored on ON_3dmObjectAttributes.m_uuid.
181
182 // The m_geometry and m_parent_geometry pointers are runtime values
183 // that point to the object being referenced. The destructor
184 // ~ON_ObjRef does not delete the objects these pointers reference.
185 //
186 // m_geometry_type records the type of geometry m_geometry points to.
187 //
188 // When the referenced object is a subobject, like a part of a brep
189 // or mesh, m_geometry points to the subobject and m_parent_geometry
190 // points to the parent object, like the brep or mesh. In this case
191 // m_component_index records the location of the subobject.
192 //
193 // Parts of instance reference objects:
194 // When the geometry belongs to an instance reference
195 // m_uuid is the id of the CRhinoInstanceObject,
196 // m_parent_geometry points to the instance definition
197 // geometry or a transformed proxy, and m_geometry points
198 // to the piece of m_geometry. The m__iref[] array records
199 // the connection between the instance reference and the
200 // geometry the ON_ObjRef refers to.
201 //
202 // For example if the ON_ObjRef is to an edge of a brep in
203 // and instance reference, m_uuid would be the Rhino id of
204 // the CRhinoInstanceObject, m_parent_geometry would point
205 // to a, possibly proxy, ON_Brep object, m_geometry would point
206 // to the ON_BrepEdge in the ON_Brep, m_component_index would
207 // record the edge's index in the ON_Brep.m_E[] array and
208 // m_geometry_type would be ON::curve_object or ON::brep_edge.
209 // m__iref->Last() would contain the information about the
210 // top level instance reference. If the brep was at the bottom
211 // of a chain of instance references, m__iref[0] would be the
212 // reference that immediately used the brep.
215 ON_COMPONENT_INDEX m_component_index;
217
218 // If m_runtime_sn > 0, then it is the value of a Rhino object's
219 // CRhinoObject::m_runtime_object_serial_number field.
220 // The serial number is used instead of the pointer to
221 // prevent crashes in cases when the CRhinoObject is deleted
222 // but an ON_ObjRef continues to reference the Rhino object.
223 // The value of m_runtime_sn is not saved in archives because
224 // it generally changes if you save and reload an archive.
225 unsigned int m_runtime_sn;
226
227 // If m_point != ON_UNSET_POINT, then the ObjRef resolves to
228 // a point location. The point location is saved here so the
229 // information can persist if the object itself vanishes.
231
232 // If the point was the result of some type of object snap, then
233 // the object snap is recorded here.
234 ON::osnap_mode m_osnap_mode;
235
236 // If m_point != ON_UNSET_POINT and m_evp.m_t_type != 0, then
237 // m_evp records the records the m_geometry evaluation
238 // parameters for the m_point.
240
241 // If m__iref[] is not empty, then m_uuid identifies
242 // and instance reference (ON_InstanceRef/CRhinoInstanceObject)
243 // and m__iref[] records the chain of instance references from
244 // the base piece of geometry to the instance reference.
245 // The top level instance reference is last in the list.
247
248 /*
249 Description:
250 Expert user tool to decrement reference counts. Most
251 users will never need to call this tool. It is called
252 by ~ON_ObjRef and used in rare cases when a
253 ON_ObjRef needs to reference an object only by uuid
254 and component index.
255 */
256 void DecrementProxyReferenceCount();
257
258 /*
259 Description:
260 Expert user tool to initialize the ON_ObjRef
261 m__proxy1, m__proxy2, and m__proxy_ref_count fields.
262 */
263 void SetProxy(
264 ON_Object* proxy1,
265 ON_Object* proxy2,
266 bool bCountReferences
267 );
268
269 bool SetParentIRef( const ON_InstanceRef& iref,
270 ON_UUID iref_id,
271 int idef_geometry_index
272 );
273
274 /*
275 Returns:
276 0: This ON_ObjRef is not counting references.
277 >0: Number of references.
278 */
279 int ProxyReferenceCount() const;
280
281 /*
282 Parameters:
283 proxy_object_index - [in] 1 or 2.
284 Returns:
285 A pointer to the requested proxy object.
286 */
287 const ON_Object* ProxyObject(int proxy_object_index) const;
288
289 /*
290 Description:
291 This tool is used in rare situations when the object ids
292 stored in the uuid list need to be remapped.
293 Parameters:
294 uuid_remap - [in]
295 Is it critical that uuid_remap[] be sorted with respect
296 to ON_UuidPair::CompareFirstUuid.
297 */
298 void RemapObjectId( const ON_SimpleArray<ON_UuidPair>& uuid_remap );
299
300private:
301 // In simple (and the most common) cases where m_geometry
302 // is managed by something outside of the ON_ObjRef class,
303 // m__proxy_ref_count is NULL. In this case, the m__proxy1
304 // and m__proxy2 pointers may still be used to store
305 // references to a parent object.
306 //
307 // In cases when the referenced geometry pointed at by
308 // m_geometry is not being managed by another class,
309 // m_proxy1 and m_proxy2 are not NULL and *m_proxy_ref_count
310 // counts the number of ON_ObjRef classes that refer to m__proxy1/2.
311 // When the last ON_ObjRef is destroyed, m__proxy1/2 is deleted.
312 // When the ON_ObjRef is using reference counting and managing
313 // m__proxy1/2, m_geometry points to some part of m__proxy1/2 and
314 // m_geometry is destroyed when m__proxy1/2 is destroyed.
315 //
316 // The convention is to use m__proxy1 to store
317 // ON_MeshVertex/Edge/FaceRefs and CRhinoPolyEdges
318 // and m__proxy2 to store transformed copies if instance
319 // definition geometry.
323};
324
325#if defined(ON_DLL_TEMPLATE)
326// This stuff is here because of a limitation in the way Microsoft
327// handles templates and DLLs. See Microsoft's knowledge base
328// article ID Q168958 for details.
329#pragma warning( push )
330#pragma warning( disable : 4231 )
331ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_ObjRef>;
332#pragma warning( pop )
333#endif
334
335#endif
Definition opennurbs_point.h:403
Definition opennurbs_archive.h:152
Definition opennurbs_array.h:760
Definition opennurbs_geometry.h:36
Definition opennurbs_instance.h:219
Definition opennurbs_point.h:46
Definition opennurbs_objref.h:100
ON_COMPONENT_INDEX m_component_index
Definition opennurbs_objref.h:145
int m_idef_geometry_index
Definition opennurbs_objref.h:127
ON_UUID m_idef_uuid
Definition opennurbs_objref.h:120
ON_Xform m_geometry_xform
Definition opennurbs_objref.h:136
ON_ObjRefEvaluationParameter m_evp
Definition opennurbs_objref.h:153
ON_Xform m_iref_xform
Definition opennurbs_objref.h:115
ON_UUID m_iref_uuid
Definition opennurbs_objref.h:112
Definition opennurbs_objref.h:20
ON_COMPONENT_INDEX m_t_ci
Definition opennurbs_objref.h:95
int m_reserved
Definition opennurbs_objref.h:91
int m_t_type
Definition opennurbs_objref.h:89
Definition opennurbs_objref.h:167
ON_Object * m__proxy1
Definition opennurbs_objref.h:320
int * m__proxy_ref_count
Definition opennurbs_objref.h:322
ON_3dPoint m_point
Definition opennurbs_objref.h:230
ON_SimpleArray< ON_ObjRef_IRefID > m__iref
Definition opennurbs_objref.h:246
ON_COMPONENT_INDEX m_component_index
Definition opennurbs_objref.h:215
ON_Object * m__proxy2
Definition opennurbs_objref.h:321
ON::osnap_mode m_osnap_mode
Definition opennurbs_objref.h:234
int m_geometry_type
Definition opennurbs_objref.h:216
ON_UUID m_uuid
Definition opennurbs_objref.h:180
const ON_Geometry * m_geometry
Definition opennurbs_objref.h:213
unsigned int m_runtime_sn
Definition opennurbs_objref.h:225
const ON_Geometry * m_parent_geometry
Definition opennurbs_objref.h:214
ON_ObjRefEvaluationParameter m_evp
Definition opennurbs_objref.h:239
Definition opennurbs_object.h:393
Definition opennurbs_array.h:46
Definition opennurbs_uuid.h:31
Definition opennurbs_xform.h:28
#define ON_CLASS
Definition opennurbs_defines.h:91