00001 /* $NoKeywords: $ */ 00002 /* 00003 // 00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved. 00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert 00006 // McNeel & Associates. 00007 // 00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF 00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED. 00011 // 00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>. 00013 // 00015 */ 00016 00017 #if !defined(OPENNURBS_USERDATA_INC_) 00018 #define OPENNURBS_USERDATA_INC_ 00019 00020 class ON_CLASS ON_UserData : public ON_Object 00021 { 00022 ON_OBJECT_DECLARE(ON_UserData); 00023 public: 00024 ON_UserData(); 00025 ON_UserData(const ON_UserData&); 00026 ON_UserData& operator=(const ON_UserData&); 00027 00029 // The destructor automatically removes the user data 00030 // from ON_Object::m_userdata_list. 00031 ~ON_UserData(); 00032 00033 /* 00034 Description: 00035 Tests an object to see if its data members are correctly 00036 initialized. 00037 Parameters: 00038 text_log - [in] if the object is not valid and text_log 00039 is not NULL, then a brief englis description of the 00040 reason the object is not valid is appened to the log. 00041 The information appended to text_log is suitable for 00042 low-level debugging purposes by programmers and is 00043 not intended to be useful as a high level user 00044 interface tool. 00045 Returns: 00046 @untitled table 00047 true object is valid 00048 false object is invalid, uninitialized, etc. 00049 Remarks: 00050 Overrides virtual ON_Object::IsValid 00051 */ 00052 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00053 00054 /* 00055 Description: 00056 Overrides virtual ON_Object::Dump(). 00057 Prints class name, description, and uuid. 00058 Parameters: 00059 text_log - [in] Information is sent to this text log. 00060 Remarks: 00061 */ 00062 void Dump( ON_TextLog& text_log ) const; 00063 00064 /* 00065 Description: 00066 Overrides virtual ON_Object::SizeOf(). 00067 Returns: 00068 Approximate number of bytes this class uses. 00069 */ 00070 unsigned int SizeOf() const; 00071 00073 // Returns object that owns the user data 00074 ON_Object* Owner() const; 00075 00077 // Used for traversing list of user data attached 00078 // to an object. 00079 ON_UserData* Next() const; 00080 00082 // Returns the class id which is not necessarily the 00083 // same as m_userdata_uuid. 00084 ON_UUID UserDataClassUuid() const; 00085 00087 // Returns true if the user data is anonymous. This happens 00088 // when the user data class is not defined at the time the 00089 // user data is read from an archive. For example, if a class 00090 // derived from ON_UserData is defined in application A 00091 // but is not defined in application B, then the class can be 00092 // defined when an archive is written by A but not exist when 00093 // an archive is read by B. In this case, the 00094 // user data is not lost, it is just read as ON_UnknownUserData 00095 // by application B. If application B saves the parent 00096 // object in an archive, the unknown user data is resaved in 00097 // a form that can be read by application A. 00098 ON_BOOL32 IsUnknownUserData() const; 00099 00100 /* 00101 Parameters: 00102 description - [out] description of user data shown in 00103 object properties dump. 00104 Returns: 00105 True if user data class is ready. 00106 */ 00107 virtual 00108 ON_BOOL32 GetDescription( ON_wString& description ); 00109 00110 /* 00111 Description: 00112 User will persist in binary archives if Archive() returns 00113 true, m_application_uuid is not nil, and the virtual Read() 00114 and Write() are functions are overridden. 00115 00116 Returns: 00117 true if user data should persist in binary archives. 00118 false if the user data should not be save in binary archives. 00119 00120 Remarks: 00121 The default implementation returns false. If you override 00122 ON_UserData::Archive so that it returns true, then your 00123 constructor must set m_application_uuid, you must override 00124 the virtual ON_Object::Read and ON_Object::Write functions and 00125 you must CAREFULLY TEST your code. 00126 00127 ON_UserData requires expert programming and testing skills. 00128 00129 YOU SHOULD READ AND UNDERSTAND EVERY COMMENT IN THIS 00130 HEADER FILE IN BEFORE ATTEMPTING TO USE ON_UserData. 00131 */ 00132 virtual 00133 ON_BOOL32 Archive() const; 00134 00135 /* 00136 Description: 00137 If Transform() return false, then the userdata is destroyed when 00138 its parent object is transformed. The default Transform() 00139 updates m_userdata_xform and returns true. 00140 Carefully read the comments above m_userdata_xform 00141 */ 00142 virtual 00143 ON_BOOL32 Transform( const ON_Xform& ); 00144 00145 /* 00146 Description: 00147 This uuid is the value that must be passed to 00148 ON_Object::GetUserData() to retrieve 00149 this piece of user data. 00150 */ 00151 ON_UUID m_userdata_uuid; 00152 00153 /* 00154 Description: 00155 This uuid is used to identify the application that 00156 created this piece of user data. In the case of 00157 Rhino, this is the id of the plug-in that created 00158 the user data. User data with a nil application id 00159 will not be saved in 3dm archives. 00160 */ 00161 ON_UUID m_application_uuid; 00162 00164 // If m_userdata_copycount is 0, user data is not copied when 00165 // object is copied. If > 0, user data is copied and m_copycount 00166 // is incremented when parent object is copied. The user data's 00167 // operator=() is used to copy. 00168 // The default ON_UserData::ON_UserData() constructor sets 00169 // m_userdata_copycount to zero. 00170 unsigned int m_userdata_copycount; 00171 00173 // Updated if user data is attached to a piece of geometry that is 00174 // transformed and the virtual ON_UserData::Transform() is not 00175 // overridden. If you override ON_UserData::Transform() and want 00176 // m_userdata_xform to be updated, then call the 00177 // ON_UserData::Transform() in your override. 00178 // The default constructor sets m_userdata_xform to the identity. 00179 ON_Xform m_userdata_xform; 00180 00181 private: // don't look and don't touch - these may change 00182 friend int ON_BinaryArchive::ReadObject( ON_Object** ); 00183 friend bool ON_BinaryArchive::WriteObject( const ON_Object& ); 00184 friend bool ON_BinaryArchive::ReadObjectUserData( ON_Object& ); 00185 friend bool ON_BinaryArchive::WriteObjectUserData( const ON_Object& ); 00186 friend class ON_Object; 00187 ON_Object* m_userdata_owner; 00188 ON_UserData* m_userdata_next; 00189 }; 00190 00191 class ON_CLASS ON_UnknownUserData : public ON_UserData 00192 { 00193 ON_OBJECT_DECLARE(ON_UnknownUserData); 00194 // used to hold user data will application class is not loaded 00195 // at time data is read 00196 public: 00197 ON_UnknownUserData(); 00198 ON_UnknownUserData(const ON_UnknownUserData&); 00199 ~ON_UnknownUserData(); 00200 ON_UnknownUserData& operator=(const ON_UnknownUserData&); 00201 00202 // ON_Object overrides 00203 00204 /* 00205 Description: 00206 Tests an object to see if its data members are correctly 00207 initialized. 00208 Parameters: 00209 text_log - [in] if the object is not valid and text_log 00210 is not NULL, then a brief englis description of the 00211 reason the object is not valid is appened to the log. 00212 The information appended to text_log is suitable for 00213 low-level debugging purposes by programmers and is 00214 not intended to be useful as a high level user 00215 interface tool. 00216 Returns: 00217 @untitled table 00218 true object is valid 00219 false object is invalid, uninitialized, etc. 00220 Remarks: 00221 Overrides virtual ON_Object::IsValid 00222 */ 00223 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00224 00225 void Dump( ON_TextLog& ) const; 00226 ON_BOOL32 Write( ON_BinaryArchive& ) const; 00227 ON_BOOL32 Read( ON_BinaryArchive& ); 00228 00229 unsigned int SizeOf() const; // return amount of memory used by user data 00230 ON_BOOL32 GetDescription( ON_wString& ); // description of user data 00231 ON_BOOL32 Archive() const; 00232 00233 // Convert unknown user data to actual user data. Useful if 00234 // definition of actual user data is dynamically linked after 00235 // archive containing user data is read. 00236 ON_UserData* Convert() const; 00237 00238 /* 00239 Description: 00240 This is the uuid of the missing class. This uuid 00241 is the 3rd parameter to the ON_OBJECT_IMPLEMENT() 00242 macro of the missing class. 00243 */ 00244 ON_UUID m_unknownclass_uuid; 00245 int m_sizeof_buffer; 00246 void* m_buffer; 00247 00248 // These version numbers are set when unknown user data is read 00249 // from a file record the version of the 3dm archive and the 00250 // version of opennurbs that were used when the plug-in wrote 00251 // the user data. 00252 // This information was added in to V5 opennurbs 200910190. 00253 // For files written with earlier versions of opennurbs, these 00254 // values are set from the archive containing the user data. 00255 // The purpose of this version information is to have it accompany 00256 // unknown user data so that if is is eventually read by the plug-in 00257 // an ON_BinaryArchive with correct version information can be 00258 // passed to the plug-in's reading code. In archives, these values 00259 // are stored in the TCODE_USER_TABLE_RECORD_HEADER chunk. 00260 int m_3dm_version; // 3dm archive version (0,1,2,3,4,5,50,...) 00261 int m_3dm_opennurbs_version; // 0 or YYYYMMDDN 00262 }; 00263 00264 class ON_CLASS ON_UserStringList : public ON_UserData 00265 { 00266 ON_OBJECT_DECLARE(ON_UserStringList); 00267 public: 00268 00269 ON_UserStringList(); 00270 ~ON_UserStringList(); 00271 00272 // override virtual ON_Object::Dump function 00273 void Dump( ON_TextLog& text_log ) const; 00274 00275 // override virtual ON_Object::SizeOf function 00276 unsigned int SizeOf() const; 00277 00278 // override virtual ON_Object::DataCRC function 00279 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 00280 00281 // override virtual ON_Object::Write function 00282 ON_BOOL32 Write(ON_BinaryArchive& binary_archive) const; 00283 00284 // override virtual ON_Object::Read function 00285 ON_BOOL32 Read(ON_BinaryArchive& binary_archive); 00286 00287 // override virtual ON_UserData::GetDescription function 00288 ON_BOOL32 GetDescription( ON_wString& description ); 00289 00290 // override virtual ON_UserData::Archive function 00291 ON_BOOL32 Archive() const; 00292 00293 /* 00294 Description: 00295 Add, replace or remove a user string. 00296 Parameters: 00297 key - [in] 00298 must be a non-empty string. If an entry with the same key 00299 (case insensitive compares are used) exists, the existing 00300 entry is updated. 00301 string_value - [in] 00302 If string_value is empty and an entry with a matching key 00303 exists, the entry is deleted. 00304 Returns: 00305 True if the key is valid. 00306 */ 00307 bool SetUserString( const wchar_t* key, const wchar_t* string_value ); 00308 00309 bool GetUserString( const wchar_t* key, ON_wString& string_value ) const; 00310 00311 /* 00312 Description: 00313 Append entries to the user string list 00314 Parameters: 00315 count - [in] 00316 number of element in us[] array 00317 us - [in] 00318 entries to append. 00319 bReplace - [in] 00320 If bReplace is true, then existing entries with the same key are 00321 updated with the new entry's value. If bReplace is false, then 00322 existing entries are not updated. 00323 Returns: 00324 Number of entries added, deleted, or modified. 00325 */ 00326 int SetUserStrings( int count, const ON_UserString* us, bool bReplace ); 00327 00328 ON_ClassArray<ON_UserString> m_e; 00329 }; 00330 00331 class ON_CLASS ON_UserDataHolder : public ON_Object 00332 { 00333 public: 00334 /* 00335 Description: 00336 Transfers the user data from source_object to "this". 00337 When MoveUserDataFrom() returns source_object will not 00338 have any user data. If "this" had user data when 00339 MoveUserDataFrom() was called, then that user data is 00340 destroyed. 00341 Parameters: 00342 source_object - [in] The "const" is a lie. It is 00343 there because, in practice the source object is frequently 00344 const and const_cast ends up being excessively used. 00345 Returns: 00346 True if source_object had user data that was transfered 00347 to "this". False if source_object had no user data. 00348 In any case, any user data that was on the input "this" 00349 is destroyed. 00350 */ 00351 bool MoveUserDataFrom( const ON_Object& source_object ); 00352 00353 /* 00354 Description: 00355 Transfers the user data on "this" to source_object. 00356 When MoveUserDataTo() returns "this" will not have any 00357 user data. 00358 Parameters: 00359 source_object - [in] The "const" is a lie. It is 00360 there because, in practice the source object is generally 00361 const and const_cast ends up being constantly used. 00362 bAppend - [in] if true, existing user data on source_object 00363 is left unchanged. If false, existing user data on source_object 00364 is destroyed, even when there is no user data on "this". 00365 Returns: 00366 True if "this" had user data that was transfered to source_object. 00367 In any case, any user data that was on the input "this" 00368 is destroyed. 00369 */ 00370 bool MoveUserDataTo( const ON_Object& source_object, bool bAppend ); 00371 00372 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00373 }; 00374 00375 /* 00376 Description: 00377 An ON_DocumentUserStringList object is saved in the list of user 00378 tables. The Rhino SetDocumentText and GetDocumentText 00379 commands use the ON_Object SetUserString, GetUserString, 00380 GetUserStrings, GetUserStringKeys functions on an 00381 ON_DocumentUserStringList class to manage the tag-value pairs of 00382 strings. 00383 */ 00384 class ON_CLASS ON_DocumentUserStringList : public ON_Object 00385 { 00386 ON_OBJECT_DECLARE(ON_DocumentUserStringList); 00387 public: 00388 ON_DocumentUserStringList(); 00389 ~ON_DocumentUserStringList(); 00390 00391 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const; 00392 void Dump( ON_TextLog& ) const; 00393 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 00394 ON_BOOL32 Write(ON_BinaryArchive& binary_archive) const; 00395 ON_BOOL32 Read(ON_BinaryArchive& binary_archive); 00396 00397 // Use the 00398 // ON_Object::SetUserString() 00399 // ON_Object::GetUserString() 00400 // ON_Object::GetUserStrings() 00401 // ON_Object::GetUserStringKeys() 00402 // ON_Object::UserStringCount() 00403 // functions to access and modify user string information. 00404 }; 00405 00406 #endif