QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_userdata.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(OPENNURBS_USERDATA_INC_)
17#define OPENNURBS_USERDATA_INC_
18
20{
22public:
26
28 // The destructor automatically removes the user data
29 // from ON_Object::m_userdata_list.
31
32 /*
33 Description:
34 Tests an object to see if its data members are correctly
35 initialized.
36 Parameters:
37 text_log - [in] if the object is not valid and text_log
38 is not NULL, then a brief englis description of the
39 reason the object is not valid is appened to the log.
40 The information appended to text_log is suitable for
41 low-level debugging purposes by programmers and is
42 not intended to be useful as a high level user
43 interface tool.
44 Returns:
45 @untitled table
46 true object is valid
47 false object is invalid, uninitialized, etc.
48 Remarks:
49 Overrides virtual ON_Object::IsValid
50 */
51 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
52
53 /*
54 Description:
55 Overrides virtual ON_Object::Dump().
56 Prints class name, description, and uuid.
57 Parameters:
58 text_log - [in] Information is sent to this text log.
59 Remarks:
60 */
61 void Dump( ON_TextLog& text_log ) const;
62
63 /*
64 Description:
65 Overrides virtual ON_Object::SizeOf().
66 Returns:
67 Approximate number of bytes this class uses.
68 */
69 unsigned int SizeOf() const;
70
72 // Returns object that owns the user data
73 ON_Object* Owner() const;
74
76 // Used for traversing list of user data attached
77 // to an object.
78 ON_UserData* Next() const;
79
81 // Returns the class id which is not necessarily the
82 // same as m_userdata_uuid.
83 ON_UUID UserDataClassUuid() const;
84
86 // Returns true if the user data is anonymous. This happens
87 // when the user data class is not defined at the time the
88 // user data is read from an archive. For example, if a class
89 // derived from ON_UserData is defined in application A
90 // but is not defined in application B, then the class can be
91 // defined when an archive is written by A but not exist when
92 // an archive is read by B. In this case, the
93 // user data is not lost, it is just read as ON_UnknownUserData
94 // by application B. If application B saves the parent
95 // object in an archive, the unknown user data is resaved in
96 // a form that can be read by application A.
97 ON_BOOL32 IsUnknownUserData() const;
98
99 /*
100 Parameters:
101 description - [out] description of user data shown in
102 object properties dump.
103 Returns:
104 True if user data class is ready.
105 */
106 virtual
107 ON_BOOL32 GetDescription( ON_wString& description );
108
109 /*
110 Description:
111 User will persist in binary archives if Archive() returns
112 true, m_application_uuid is not nil, and the virtual Read()
113 and Write() are functions are overridden.
114
115 Returns:
116 true if user data should persist in binary archives.
117 false if the user data should not be save in binary archives.
118
119 Remarks:
120 The default implementation returns false. If you override
121 ON_UserData::Archive so that it returns true, then your
122 constructor must set m_application_uuid, you must override
123 the virtual ON_Object::Read and ON_Object::Write functions and
124 you must CAREFULLY TEST your code.
125
126 ON_UserData requires expert programming and testing skills.
127
128 YOU SHOULD READ AND UNDERSTAND EVERY COMMENT IN THIS
129 HEADER FILE IN BEFORE ATTEMPTING TO USE ON_UserData.
130 */
131 virtual
132 ON_BOOL32 Archive() const;
133
134 /*
135 Description:
136 If Transform() return false, then the userdata is destroyed when
137 its parent object is transformed. The default Transform()
138 updates m_userdata_xform and returns true.
139 Carefully read the comments above m_userdata_xform
140 */
141 virtual
142 ON_BOOL32 Transform( const ON_Xform& );
143
144 /*
145 Description:
146 This uuid is the value that must be passed to
147 ON_Object::GetUserData() to retrieve
148 this piece of user data.
149 */
151
152 /*
153 Description:
154 This uuid is used to identify the application that
155 created this piece of user data. In the case of
156 Rhino, this is the id of the plug-in that created
157 the user data. User data with a nil application id
158 will not be saved in 3dm archives.
159 */
161
163 // If m_userdata_copycount is 0, user data is not copied when
164 // object is copied. If > 0, user data is copied and m_copycount
165 // is incremented when parent object is copied. The user data's
166 // operator=() is used to copy.
167 // The default ON_UserData::ON_UserData() constructor sets
168 // m_userdata_copycount to zero.
169 unsigned int m_userdata_copycount;
170
172 // Updated if user data is attached to a piece of geometry that is
173 // transformed and the virtual ON_UserData::Transform() is not
174 // overridden. If you override ON_UserData::Transform() and want
175 // m_userdata_xform to be updated, then call the
176 // ON_UserData::Transform() in your override.
177 // The default constructor sets m_userdata_xform to the identity.
179
180private: // don't look and don't touch - these may change
185 friend class ON_Object;
188};
189
191{
193 // used to hold user data will application class is not loaded
194 // at time data is read
195public:
200
201 // ON_Object overrides
202
203 /*
204 Description:
205 Tests an object to see if its data members are correctly
206 initialized.
207 Parameters:
208 text_log - [in] if the object is not valid and text_log
209 is not NULL, then a brief englis description of the
210 reason the object is not valid is appened to the log.
211 The information appended to text_log is suitable for
212 low-level debugging purposes by programmers and is
213 not intended to be useful as a high level user
214 interface tool.
215 Returns:
216 @untitled table
217 true object is valid
218 false object is invalid, uninitialized, etc.
219 Remarks:
220 Overrides virtual ON_Object::IsValid
221 */
222 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
223
224 void Dump( ON_TextLog& ) const;
227
228 unsigned int SizeOf() const; // return amount of memory used by user data
229 ON_BOOL32 GetDescription( ON_wString& ); // description of user data
230 ON_BOOL32 Archive() const;
231
232 // Convert unknown user data to actual user data. Useful if
233 // definition of actual user data is dynamically linked after
234 // archive containing user data is read.
235 ON_UserData* Convert() const;
236
237 /*
238 Description:
239 This is the uuid of the missing class. This uuid
240 is the 3rd parameter to the ON_OBJECT_IMPLEMENT()
241 macro of the missing class.
242 */
245 void* m_buffer;
246
247 // These version numbers are set when unknown user data is read
248 // from a file record the version of the 3dm archive and the
249 // version of opennurbs that were used when the plug-in wrote
250 // the user data.
251 // This information was added in to V5 opennurbs 200910190.
252 // For files written with earlier versions of opennurbs, these
253 // values are set from the archive containing the user data.
254 // The purpose of this version information is to have it accompany
255 // unknown user data so that if is is eventually read by the plug-in
256 // an ON_BinaryArchive with correct version information can be
257 // passed to the plug-in's reading code. In archives, these values
258 // are stored in the TCODE_USER_TABLE_RECORD_HEADER chunk.
259 int m_3dm_version; // 3dm archive version (0,1,2,3,4,5,50,...)
260 int m_3dm_opennurbs_version; // 0 or YYYYMMDDN
261};
262
264{
266public:
267
270
271 // override virtual ON_Object::Dump function
272 void Dump( ON_TextLog& text_log ) const;
273
274 // override virtual ON_Object::Dump function
275 unsigned int SizeOf() const;
276
277 // override virtual ON_Object::Write function
278 ON_BOOL32 Write(ON_BinaryArchive& binary_archive) const;
279
280 // override virtual ON_Object::Read function
281 ON_BOOL32 Read(ON_BinaryArchive& binary_archive);
282
283 // override virtual ON_UserData::GetDescription function
284 ON_BOOL32 GetDescription( ON_wString& description );
285
286 // override virtual ON_UserData::Archive function
287 ON_BOOL32 Archive() const;
288
289 bool SetUserString( const wchar_t* key, const wchar_t* string_value );
290
291 bool GetUserString( const wchar_t* key, ON_wString& string_value ) const;
292
294};
295
297{
298public:
299 /*
300 Description:
301 Transfers the user data from source_object to "this".
302 When MoveUserDataFrom() returns source_object will not
303 have any user data. If "this" had user data when
304 MoveUserDataFrom() was called, then that user data is
305 destroyed.
306 Parameters:
307 source_object - [in] The "const" is a lie. It is
308 there because, in practice the source object is frequently
309 const and const_cast ends up being excessively used.
310 Returns:
311 True if source_object had user data that was transfered
312 to "this". False if source_object had no user data.
313 In any case, any user data that was on the input "this"
314 is destroyed.
315 */
316 bool MoveUserDataFrom( const ON_Object& source_object );
317
318 /*
319 Description:
320 Transfers the user data on "this" to source_object.
321 When MoveUserDataTo() returns "this" will not have any
322 user data.
323 Parameters:
324 source_object - [in] The "const" is a lie. It is
325 there because, in practice the source object is generally
326 const and const_cast ends up being constantly used.
327 bAppend - [in] if true, existing user data on source_object
328 is left unchanged. If false, existing user data on source_object
329 is destroyed, even when there is no user data on "this".
330 Returns:
331 True if "this" had user data that was transfered to source_object.
332 In any case, any user data that was on the input "this"
333 is destroyed.
334 */
335 bool MoveUserDataTo( const ON_Object& source_object, bool bAppend );
336
337 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
338};
339
340#endif
@ Transform
Definition RSMetaType.h:67
Definition opennurbs_archive.h:152
int ReadObject(ON_Object **ppObject)
Definition opennurbs_archive.cpp:3117
bool WriteObject(const ON_Object *)
Definition opennurbs_archive.cpp:2778
bool ReadObjectUserData(ON_Object &object)
Definition opennurbs_archive.cpp:3558
bool WriteObjectUserData(const ON_Object &object)
Definition opennurbs_archive.cpp:2938
Definition opennurbs_array.h:760
Definition opennurbs_object.h:393
virtual void Dump(ON_TextLog &) const
Definition opennurbs_object.cpp:1695
bool SetUserString(const wchar_t *key, const wchar_t *string_value)
Definition opennurbs_userdata.cpp:781
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
Definition opennurbs_object.cpp:1734
virtual unsigned int SizeOf() const
Definition opennurbs_object.cpp:1677
ON_Object & operator=(const ON_Object &)
Definition opennurbs_object.cpp:1362
friend class ON_UserData
Definition opennurbs_object.h:852
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
Definition opennurbs_object.cpp:1714
bool GetUserString(const wchar_t *key, ON_wString &string_value) const
Definition opennurbs_userdata.cpp:824
Definition opennurbs_textlog.h:20
Definition opennurbs_uuid.h:31
Definition opennurbs_userdata.h:191
ON_OBJECT_DECLARE(ON_UnknownUserData)
int m_sizeof_buffer
Definition opennurbs_userdata.h:244
int m_3dm_version
Definition opennurbs_userdata.h:259
int m_3dm_opennurbs_version
Definition opennurbs_userdata.h:260
ON_UUID m_unknownclass_uuid
Definition opennurbs_userdata.h:243
void * m_buffer
Definition opennurbs_userdata.h:245
Definition opennurbs_userdata.h:297
Definition opennurbs_userdata.h:20
ON_Object * m_userdata_owner
Definition opennurbs_userdata.h:186
ON_UUID m_application_uuid
Definition opennurbs_userdata.h:160
ON_Xform m_userdata_xform
Definition opennurbs_userdata.h:178
ON_OBJECT_DECLARE(ON_UserData)
ON_UserData * m_userdata_next
Definition opennurbs_userdata.h:187
ON_UUID m_userdata_uuid
Definition opennurbs_userdata.h:150
unsigned int m_userdata_copycount
Definition opennurbs_userdata.h:169
Definition opennurbs_userdata.h:264
ON_ClassArray< ON_UserString > m_e
Definition opennurbs_userdata.h:293
ON_OBJECT_DECLARE(ON_UserStringList)
Definition opennurbs_xform.h:28
Definition opennurbs_string.h:392
#define ON_CLASS
Definition opennurbs_defines.h:91
#define NULL
Definition opennurbs_system.h:256
int ON_BOOL32
Definition opennurbs_system.h:362