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 00018 // 00019 // virtual base class for all openNURBS objects 00020 // 00022 00023 #if !defined(OPENNURBS_OBJECT_INC_) 00024 #define OPENNURBS_OBJECT_INC_ 00025 00026 00027 class ON_ClassId; // used for runtime class identification 00028 00030 // 00031 // Runtime class id 00032 // 00033 00034 // Description: 00035 // Every class derived from ON_Object has a class id that records 00036 // its class name, baseclass name, and class uuid. The 00037 // ON_OBJECT_DECLARE and ON_OBJECT_IMPLEMENT macros generate 00038 // the code that creates and initializes class ids. 00039 // 00040 // The ON_Object::IsKindOf() and ON_Object::Cast() functions 00041 // use these class ids. 00042 class ON_CLASS ON_ClassId 00043 { 00044 public: 00045 00046 // Description: 00047 // This constructor is called to initialize each class id. 00048 // The call is generated by the ON_OBJECT_IMPLEMENT macro. 00049 // 00050 // Parameters: 00051 // sClassName - [in] name of the class (like ON_Geometry) 00052 // sBaseClassName - [in] name of baseclass (like ON_Object) 00053 // create - [in] function to create a new object(like CreateNewON_Geometry()) 00054 // copy - [in] function to copy 00055 // sUUID - [in] UUID in registry format from Windows guidgen.exe 00056 ON_ClassId( 00057 const char* sClassName, 00058 const char* sBaseClassName, 00059 ON_Object* (*create)(), 00060 const char* sUUID 00061 ); 00062 00063 ON_ClassId( 00064 const char* sClassName, 00065 const char* sBaseClassName, 00066 ON_Object* (*create)(), 00067 bool (*copy)(const ON_Object*,ON_Object* ), 00068 const char* sUUID 00069 ); 00070 00071 ~ON_ClassId(); 00072 00073 // Description: 00074 // Gets a class's ON_ClassId from the class's name. 00075 // Parameters: 00076 // sClassName - [in] name of class 00077 // Returns: 00078 // Pointer to the class's ON_ClassId. 00079 // Example: 00080 // const ON_ClassId* brep_id = ON_CLassId::ClassId("ON_Brep"); 00081 static const ON_ClassId* ClassId( 00082 const char* sClassName 00083 ); 00084 00085 // Description: 00086 // Gets a class's ON_ClassId from the class's uuid. 00087 // Parameters: 00088 // class_uuid - [in] uuid for the class 00089 // Returns: 00090 // Pointer to the class's ON_ClassId. 00091 // Example: 00092 // ON_UUID brep_uuid = ON_UuidFromString("60B5DBC5-E660-11d3-BFE4-0010830122F0"); 00093 // const ON_ClassId* brep_id = ON_CLassId::ClassId(brep_uuid); 00094 static const ON_ClassId* ClassId( 00095 ON_UUID class_uuid 00096 ); 00097 00098 // Description: 00099 // Each class derived from ON_Object has a corresponding ON_ClassId 00100 // stored in a linked list and the class is marked with an integer 00101 // value. ON_ClassId::IncrementMark() increments the value used to 00102 // mark new classes and returns the new marking value. 00103 // Returns: 00104 // Value that will be used to mark all future ON_ClassIds. 00105 static int IncrementMark(); 00106 static int CurrentMark(); 00107 static const ON_ClassId* LastClassId(); 00108 00109 // Description: 00110 // Each class derived from ON_Object has a corresponding 00111 // ON_ClassId stored in a linked list. If a class definition 00112 // is going to disappear (which happens when the derived object 00113 // definition is in a DLL that uses openNURBS as a DLL and the 00114 // DLL containing the derived object's definition is unloaded), 00115 // then the class's ON_ClassId needs to be removed from the class 00116 // list. ON_ClassId::Purge( mark ) removes all ON_ClassIds with a 00117 // a prescribed mark and returns the number of classes that 00118 // were purged. 00119 // Parameters: 00120 // mark - [in] All ON_ClassIds with this mark will be purged. 00121 // Returns: 00122 // Number of classes that were purged. 00123 // Example: 00124 // // Call ON_ClassId::IncrementMark() BEFORE loading MY.DLL. 00125 // int my_dll_classid_mark = ON_ClassId::IncrementMark(); 00126 // load MY.DLL with classes derived from ON_Object 00127 // ... 00128 // // Call ON_ClassId::Purge() BEFORE unloading MY.DLL. 00129 // ON_ClassId::Purge( my_dll_classid_mark ); 00130 // unload MY.DLL 00131 static int Purge(int mark); 00132 static bool PurgeAfter(const ON_ClassId* pClassId); 00133 00134 // Description: 00135 // Dumps the ON_ClassId list 00136 // Parameters: 00137 // dump - [in] destination for the text dump. 00138 static void Dump( 00139 ON_TextLog& dump 00140 ); 00141 00142 // Returns: 00143 // class name 00144 const char* ClassName() const; 00145 00146 // Returns: 00147 // base class name 00148 const char* BaseClassName() const; 00149 00150 // Returns: 00151 // base class id 00152 const ON_ClassId* BaseClass() const; 00153 00154 // Description: 00155 // Determine if the class associated with this ON_ClassId 00156 // is derived from another class. 00157 // Parameters: 00158 // potential_parent - [in] Class to test as parent. 00159 // Returns: 00160 // true if this is derived from potential_parent. 00161 ON_BOOL32 IsDerivedFrom( 00162 const ON_ClassId* potential_parent 00163 ) const; 00164 00165 // Descrption: 00166 // Create an instance of the class associated with 00167 // class id. 00168 // Returns: 00169 // Instance of the class id's class. 00170 ON_Object* Create() const; 00171 00172 // Returns: 00173 // class uuid 00174 ON_UUID Uuid() const; 00175 00176 /* 00177 Description: 00178 Opennurbs classes have a mark value of 0. Core Rhino 00179 classes have a mark value of 1. Rhino plug-in classes 00180 have a mark value of > 1. 00181 Returns: 00182 Class mark value 00183 */ 00184 int Mark() const; 00185 00186 unsigned int ClassIdVersion() const; 00187 00188 private: 00189 static ON_ClassId* m_p0; // first id in the linked list of class ids 00190 static ON_ClassId* m_p1; // last id in the linked list of class ids 00191 static int m_mark0; // current mark value 00192 ON_ClassId* m_pNext; // next in the linked list of class ids 00193 const ON_ClassId* m_pBaseClassId; // base class id 00194 char m_sClassName[80]; 00195 char m_sBaseClassName[80]; 00196 ON_Object* (*m_create)(); 00197 ON_UUID m_uuid; 00198 int m_mark; // bit 0x80000000 is used to indicate new extensions 00199 00200 private: 00201 // no implementaion to prohibit use 00202 ON_ClassId(); 00203 ON_ClassId( const ON_ClassId&); 00204 ON_ClassId& operator=( const ON_ClassId&); 00205 00206 void ConstructorHelper( 00207 const char* sClassName, 00208 const char* sBaseClassName, 00209 const char* sUUID 00210 ); 00211 00212 // This is a temporary way to add simple virtual functions 00213 // to ON_Object without breaking the SDK. At V6 these will 00214 // be redone to be ordinary virtual functions. 00215 friend class ON_Object; 00216 unsigned int m_class_id_version; 00217 bool (*m_copy)(const ON_Object*,ON_Object*); // on version 1 class ids 00218 void* m_f2; 00219 void* m_f3; 00220 void* m_f4; 00221 void* m_f5; 00222 void* m_f6; 00223 void* m_f7; 00224 void* m_f8; 00225 }; 00226 00227 // Description: 00228 // Macro to easily get a pointer to the ON_ClassId for a 00229 // given class; 00230 // 00231 // Example: 00232 // 00233 // const ON_ClassId* brep_class_id = ON_CLASS_ID("ON_Brep"); 00234 // 00235 #define ON_CLASS_ID( cls ) ON_ClassId::ClassId( #cls ) 00236 00237 /* 00238 Description: 00239 Expert user function to get the value of ON_ClassId::m_uuid 00240 of the last instance of ON_ClassId to call ON_ClassId::Create(). 00241 This function was created to support Rhino's .NET SDK. 00242 This function returns the value of a static id in 00243 opennurbs_object.cpp and is NOT thread safe. 00244 Returns: 00245 Value of ON_ClassId::m_uuid of the instance of ON_ClassId that 00246 most recently called ON_ClassId::Create(). 00247 */ 00248 ON_DECL 00249 ON_UUID ON_GetMostRecentClassIdCreateUuid(); 00250 00251 /* 00252 All classes derived from ON_Object must have 00253 00254 ON_OBJECT_DECLARE( <classname> ); 00255 00256 as the first line in their class definition an a corresponding 00257 00258 ON_VIRTUAL_OBJECT_IMPLEMENT( <classname>, <basclassname>, <classuuid> ); 00259 00260 or 00261 00262 ON_OBJECT_IMPLEMENT( <classname>, <basclassname>, <classuuid> ); 00263 00264 in a .CPP file. 00265 */ 00266 #define ON_OBJECT_DECLARE( cls ) \ 00267 protected: \ 00268 static void* m_s_##cls##_ptr; \ 00269 public: \ 00270 static const ON_ClassId m_##cls##_class_id; \ 00271 /*record used for ON_Object runtime type information*/ \ 00272 \ 00273 static cls * Cast( ON_Object* ); \ 00274 /*Description: Similar to C++ dynamic_cast*/ \ 00275 /*Returns: object on success. NULL on failure*/ \ 00276 \ 00277 static const cls * Cast( const ON_Object* ); \ 00278 /*Description: Similar to C++ dynamic_cast*/ \ 00279 /*Returns: object on success. NULL on failure*/ \ 00280 \ 00281 virtual const ON_ClassId* ClassId() const; \ 00282 /*Description:*/ \ 00283 \ 00284 private: \ 00285 virtual ON_Object* DuplicateObject() const; \ 00286 /*used by Duplicate to create copy of an object.*/ \ 00287 \ 00288 static bool Copy##cls( const ON_Object*, ON_Object* ); \ 00289 /* used by ON_Object::CopyFrom copy object into this. */ \ 00290 /* In V6 Copy##cls will vanish and be replaced with */ \ 00291 /* virtual bool CopyFrom( const ON_Object* src ) */ \ 00292 \ 00293 public: \ 00294 cls * Duplicate() const; \ 00295 /*Description: Expert level tool - no support available.*/ \ 00296 /*If this class is derived from CRhinoObject, use CRhinoObject::DuplicateRhinoObject instead*/ 00297 00298 // Objects derived from ON_Object that do not have a valid new, operator=, 00299 // or copy constructor must use ON_VIRTUAL_OBJECT_IMPLEMENT instead of 00300 // ON_OBJECT_IMPLEMENT. Objects defined with ON_VIRTUAL_OBJECT_IMPLEMENT 00301 // cannot be serialized using ON_BinaryArchive::ReadObject()/WriteObject() 00302 // or duplicated using ON_Object::Duplicate(). 00303 // 00304 // The Cast() and ClassId() members work on objects defined with either 00305 // ON_VIRTUAL_OBJECT_IMPLEMENT or ON_OBJECT_IMPLEMENT. 00306 #define ON_VIRTUAL_OBJECT_IMPLEMENT( cls, basecls, uuid ) \ 00307 void* cls::m_s_##cls##_ptr = 0;\ 00308 const ON_ClassId cls::m_##cls##_class_id(#cls,#basecls,0,0,uuid);\ 00309 cls * cls::Cast( ON_Object* p) {return(cls *)Cast((const ON_Object*)p);} \ 00310 const cls * cls::Cast( const ON_Object* p) {return(p&&p->IsKindOf(&cls::m_##cls##_class_id))?(const cls *)p:0;} \ 00311 const ON_ClassId* cls::ClassId() const {return &cls::m_##cls##_class_id;} \ 00312 ON_Object* cls::DuplicateObject() const {return 0;} \ 00313 bool cls::Copy##cls( const ON_Object*, ON_Object* ) {return false;} \ 00314 cls * cls::Duplicate() const {return static_cast<cls *>(DuplicateObject());} 00315 00316 // Objects derived from ON_Object that use ON_OBJECT_IMPLEMENT must 00317 // have a valid operator= and copy constructor. Objects defined with 00318 // ON_OBJECT_IMPLEMENT may be serialized using 00319 // ON_BinaryArchive::ReadObject()/WriteObject() 00320 // and duplicated by calling ON_Object::Duplicate(). 00321 #define ON_OBJECT_IMPLEMENT( cls, basecls, uuid ) \ 00322 void* cls::m_s_##cls##_ptr = 0;\ 00323 static ON_Object* CreateNew##cls() {return new cls();} \ 00324 const ON_ClassId cls::m_##cls##_class_id(#cls,#basecls,CreateNew##cls,cls::Copy##cls,uuid);\ 00325 cls * cls::Cast( ON_Object* p) {return(cls *)Cast((const ON_Object*)p);} \ 00326 const cls * cls::Cast( const ON_Object* p) {return(p&&p->IsKindOf(&cls::m_##cls##_class_id))?(const cls *)p:0;} \ 00327 const ON_ClassId* cls::ClassId() const {return &cls::m_##cls##_class_id;} \ 00328 ON_Object* cls::DuplicateObject() const {cls* p = new cls(); if (p) *p=*this; return p;} \ 00329 bool cls::Copy##cls( const ON_Object* src, ON_Object* dst ){cls* d;const cls* s;if (0!=(s=cls::Cast(src))&&0!=(d=cls::Cast(dst))) {d->cls::operator=(*s);return true;}return false;} \ 00330 cls * cls::Duplicate() const {return static_cast<cls *>(DuplicateObject());} 00331 00332 #define ON__SET__THIS__PTR(ptr) if (ptr) *((void**)this) = ptr 00333 00334 class ON_UserData; 00335 00336 class ON_CLASS ON_UserString 00337 { 00338 public: 00339 ON_UserString(); 00340 ~ON_UserString(); 00341 ON_wString m_key; 00342 ON_wString m_string_value; 00343 00344 void Dump(ON_TextLog& text_log) const; 00345 bool Write(ON_BinaryArchive&) const; 00346 bool Read(ON_BinaryArchive&); 00347 }; 00348 00349 #if defined(ON_DLL_TEMPLATE) 00350 // This stuff is here because of a limitation in the way Microsoft 00351 // handles templates and DLLs. See Microsoft's knowledge base 00352 // article ID Q168958 for details. 00353 #pragma warning( push ) 00354 #pragma warning( disable : 4231 ) 00355 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_UserString>; 00356 #pragma warning( pop ) 00357 #endif 00358 00359 /* 00360 Description: 00361 When ON_Object::IsValid() fails and returns false, ON_IsNotValid() 00362 is called. This way, a developer can put a breakpoint in 00363 ON_IsNotValid() and stop execution at the exact place IsValid() 00364 fails. 00365 Returns: 00366 false; 00367 */ 00368 ON_DECL 00369 bool ON_IsNotValid(); 00370 00372 00373 // Description: 00374 // Pure virtual base class for all classes that must provide 00375 // runtime class id or support object level 3DM serialization 00376 class ON_CLASS ON_Object 00377 { 00379 // 00380 // Any object derived from ON_Object should have a 00381 // ON_OBJECT_DECLARE(ON_...); 00382 // as the last line of its class definition and a 00383 // ON_OBJECT_IMPLEMENT( ON_..., ON_baseclass ); 00384 // in a .cpp file. 00385 // 00386 // These macros declare and implement public members 00387 // 00388 // static ON_ClassId m_ON_Object; 00389 // static cls * Cast( ON_Object* ); 00390 // static const cls * Cast( const ON_Object* ); 00391 // virtual const ON_ClassId* ClassId() const; 00392 ON_OBJECT_DECLARE(ON_Object); 00393 public: 00394 00395 /* 00396 Description: 00397 Copies src into this, if possible. 00398 Parameters: 00399 src - [in] 00400 Returns: 00401 True if this->operator= could be called to copy src. 00402 Remarks: 00403 This should be virtual function declared in the 00404 ON_OBJECT_DECLARE macro along the lines of DuplicateObject() 00405 but is was added after the SDK was frozen (adding virtual 00406 functions breaks the SDK). In V6, the function will work 00407 the same but be implemented like DuplicateObject(); 00408 */ 00409 bool CopyFrom( const ON_Object* src ); 00410 00411 public: 00412 00413 ON_Object(); 00414 ON_Object( const ON_Object& ); 00415 ON_Object& operator=( const ON_Object& ); 00416 virtual ~ON_Object(); 00417 00418 /* 00419 Description: 00420 Sets m_user_data_list = 0. 00421 */ 00422 void EmergencyDestroy(); 00423 00424 /* 00425 Description: 00426 The MemoryRelocate() function is called when an 00427 object's location in memory is changed. For 00428 example, if an object resides in a chunk of 00429 memory that is grown by calling a realloc 00430 that has to allocate a new chunk and 00431 copy the contents of the old chunk to the 00432 new chunk, then the location of the object's 00433 memory changes. In practice this happens when 00434 classes derived from ON_Object are stored 00435 in dynamic arrays, like the default implementation 00436 of ON_ObjectArray<>'s that use realloc to grow 00437 the dynamic array. 00438 */ 00439 virtual 00440 void MemoryRelocate(); 00441 00442 /* 00443 Description: 00444 Low level tool to test if an object is derived 00445 from a specified class. 00446 Parameters: 00447 pClassId - [in] use classname::ClassId() 00448 Returns: 00449 true if the instantiated object is derived from the 00450 class whose id is passed as the argument. 00451 Example: 00452 00453 ON_Object* p = ....; 00454 if ( p->IsKindOf( ON_NurbsCurve::ClassId() ) ) 00455 { 00456 it's a NURBS curve 00457 } 00458 00459 Remarks: 00460 The primary reason for IsKindOf() is to support the 00461 static Cast() members declared in the ON_OBJECT_DECLARE 00462 macro. If we determine that dynamic_cast is properly 00463 supported and implemented by all supported compilers, 00464 then IsKindOf() may dissappear. If an application needs 00465 to determine if a pointer points to a class derived from 00466 ON_SomeClassName, then call 00467 ON_SomeClassName::Cast(mystery pointer) and check for 00468 a non-null return. 00469 */ 00470 ON_BOOL32 IsKindOf( 00471 const ON_ClassId* pClassId 00472 ) const; 00473 00474 /* 00475 Description: 00476 Tests an object to see if its data members are correctly 00477 initialized. 00478 Parameters: 00479 text_log - [in] if the object is not valid and text_log 00480 is not NULL, then a brief englis description of the 00481 reason the object is not valid is appened to the log. 00482 The information appended to text_log is suitable for 00483 low-level debugging purposes by programmers and is 00484 not intended to be useful as a high level user 00485 interface tool. 00486 Returns: 00487 @untitled table 00488 true object is valid 00489 false object is invalid, uninitialized, etc. 00490 */ 00491 virtual 00492 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const = 0; 00493 00494 /* 00495 Description: 00496 Creates a text dump of the object. 00497 Remarks: 00498 Dump() is intended for debugging and is not suitable 00499 for creating high quality text descriptions of an 00500 object. 00501 00502 The default implementations of this virtual function 00503 prints the class's name. 00504 */ 00505 virtual 00506 void Dump( ON_TextLog& ) const; 00507 00508 /* 00509 Returns: 00510 An estimate of the amount of memory the class uses in bytes. 00511 */ 00512 virtual 00513 unsigned int SizeOf() const; 00514 00515 /* 00516 Description: 00517 Returns a CRC calculated from the information that defines 00518 the object. This CRC can be used as a quick way to see 00519 if two objects are not identical. 00520 Parameters: 00521 current_remainder - [in]; 00522 Returns: 00523 CRC of the information the defines the object. 00524 */ 00525 virtual 00526 ON__UINT32 DataCRC(ON__UINT32 current_remainder) const; 00527 00528 /* 00529 Description: 00530 Low level archive writing tool used by ON_BinaryArchive::WriteObject(). 00531 Parameters: 00532 binary_archive - archive to write to 00533 Returns: 00534 Returns true if the write is successful. 00535 Remarks: 00536 Use ON_BinaryArchive::WriteObject() to write objects. 00537 This Write() function should just write the specific definition of 00538 this object. It should not write and any chunk typecode or length 00539 information. 00540 00541 The default implementation of this virtual function returns 00542 false and does nothing. 00543 */ 00544 virtual 00545 ON_BOOL32 Write( 00546 ON_BinaryArchive& binary_archive 00547 ) const; 00548 00549 /* 00550 Description: 00551 Low level archive writing tool used by ON_BinaryArchive::ReadObject(). 00552 Parameters: 00553 binary_archive - archive to read from 00554 Returns: 00555 Returns true if the read is successful. 00556 Remarks: 00557 Use ON_BinaryArchive::ReadObject() to read objects. 00558 This Read() function should read the objects definition back into 00559 its data members. 00560 00561 The default implementation of this virtual function returns 00562 false and does nothing. 00563 */ 00564 virtual 00565 ON_BOOL32 Read( 00566 ON_BinaryArchive& binary_archive 00567 ); 00568 00569 /* 00570 Description: 00571 Useful for switch statements that need to differentiate 00572 between basic object types like points, curves, surfaces, 00573 and so on. 00574 00575 Returns: 00576 ON::object_type enum value. 00577 00578 @untitled table 00579 ON::unknown_object_type unknown object 00580 ON::point_object derived from ON_Point 00581 ON::pointset_object some type of ON_PointCloud, ON_PointGrid, ... 00582 ON::curve_object derived from ON_Curve 00583 ON::surface_object derived from ON_Surface 00584 ON::brep_object derived from ON_Brep 00585 ON::extrusion_object derived from ON_Extrusion 00586 ON::mesh_object derived from ON_Mesh 00587 ON::layer_object derived from ON_Layer 00588 ON::material_object derived from ON_Material 00589 ON::light_object derived from ON_Light 00590 ON::annotation_object derived from ON_Annotation, 00591 ON::userdata_object derived from ON_UserData 00592 ON::text_dot derived from ON_TextDot 00593 00594 Remarks: 00595 The default implementation of this virtual function returns 00596 ON::unknown_object_type 00597 */ 00598 virtual 00599 ON::object_type ObjectType() const; 00600 00601 00602 00603 /* 00604 Description: 00605 All objects in an opennurbs model have an id 00606 ( ON_Layer.m_layer_id, ON_Font.m_font_id, 00607 ON_Material.m_material_id, ON_3dmObjectAttributes.m_uuid 00608 ). 00609 Returns: 00610 The id used to identify the object in the openurbs model. 00611 */ 00612 virtual 00613 ON_UUID ModelObjectId() const; 00614 00616 // 00617 // BEGIN: User string support 00618 // 00619 00620 /* 00621 Description: 00622 Attach a user string to the object. This information will 00623 perisist through copy construction, operator=, and file IO. 00624 Parameters: 00625 key - [in] id used to retrieve this string. 00626 string_value - [in] 00627 If NULL, the string with this id will be removed. 00628 Returns: 00629 True if successful. 00630 */ 00631 bool SetUserString( 00632 const wchar_t* key, 00633 const wchar_t* string_value 00634 ); 00635 00636 /* 00637 Description: 00638 Append entries to the user string list 00639 Parameters: 00640 count - [in] 00641 number of element in us[] array 00642 user_strings - [in] 00643 entries to append. 00644 bReplace - [in] 00645 If bReplace is true, then existing entries with the same key are 00646 updated with the new entry's value. If bReplace is false, then 00647 existing entries are not updated. 00648 Returns: 00649 Number of entries added, deleted, or modified. 00650 */ 00651 int SetUserStrings( int count, const ON_UserString* user_strings, bool bReplace ); 00652 00653 /* 00654 Description: 00655 Get user string from the object. 00656 Parameters: 00657 key - [in] id used to retrieve the string. 00658 string_value - [out] 00659 Returns: 00660 True if a string with id was found. 00661 */ 00662 bool GetUserString( 00663 const wchar_t* key, 00664 ON_wString& string_value 00665 ) const; 00666 00667 /* 00668 Description: 00669 Get a list of all user strings on the object. 00670 Parameters: 00671 user_strings - [out] 00672 user strings are appended to this list. 00673 Returns: 00674 Number of elements appended to the user_strings list. 00675 */ 00676 int GetUserStrings( 00677 ON_ClassArray<ON_UserString>& user_strings 00678 ) const; 00679 00680 /* 00681 Description: 00682 Get a list of all user string keys on the object. 00683 Parameters: 00684 user_string_keys - [out] 00685 user string keys are appended to this list. 00686 Returns: 00687 Number of elements appended to the user_strings list. 00688 */ 00689 int GetUserStringKeys( 00690 ON_ClassArray<ON_wString>& user_string_keys 00691 ) const; 00692 00693 /* 00694 Returns: 00695 Number of user strings on the object. 00696 */ 00697 int UserStringCount() const; 00698 00699 // 00700 // END: User string support 00701 // 00703 00705 // 00706 // User data provides a standard way for extra information to 00707 // be attached to any class derived from ON_Object. The attached 00708 // information can persist and be transformed. If you use user 00709 // data, please carefully read all the comments from here to the 00710 // end of the file. 00711 // 00712 00713 /* 00714 Description: 00715 Attach user data to an object. 00716 Parameters: 00717 pUserData - [in] user data to attach to object. 00718 The ON_UserData pointer passed to AttachUserData() 00719 must be created with new. 00720 Returns: 00721 If true is returned, then ON_Object will delete the user 00722 data when appropriate. If false is returned, then data 00723 could not be attached and caller must delete. 00724 Remarks: 00725 AttachUserData() will fail if the user data's m_userdata_uuid 00726 field is nil or not unique. 00727 */ 00728 ON_BOOL32 AttachUserData( 00729 ON_UserData* pUserData 00730 ); 00731 00732 /* 00733 Description: 00734 Remove user data from an object. 00735 Parameters: 00736 pUserData - [in] user data to attach to object. 00737 The ON_UserData pointer passed to DetachUserData() 00738 must have been previously attached using 00739 AttachUserData(). 00740 Returns: 00741 If true is returned, then the user data was 00742 attached to this object and it was detached. If false 00743 is returned, then the user data was not attached to this 00744 object to begin with. In all cases, you can be assured 00745 that the user data is no longer attached to "this". 00746 Remarks: 00747 Call delete pUserData if you want to destroy the user data. 00748 */ 00749 ON_BOOL32 DetachUserData( 00750 ON_UserData* pUserData 00751 ); 00752 00753 00754 /* 00755 Description: 00756 Get a pointer to user data. 00757 Parameters: 00758 userdata_uuid - [in] value of the user data's 00759 m_userdata_uuid field. 00760 Remarks: 00761 The returned user data is still attached to the object. 00762 Deleting the returned user data will automatically remove 00763 the user data from the object. 00764 */ 00765 ON_UserData* GetUserData( 00766 const ON_UUID& userdata_uuid 00767 ) const; 00768 00769 /* 00770 Description: 00771 PurgeUserData() removes all user data from object. 00772 Remarks: 00773 Use delete GetUserData(...) to destroy a single piece 00774 of user data. 00775 */ 00776 void PurgeUserData(); 00777 00778 /* 00779 Description: 00780 User data is stored as a linked list of ON_UserData 00781 classes. FirstUserData gets the first item in the 00782 linked list. This is the most recent item attached 00783 using AttachUserData(). 00784 Remark: 00785 To iterate through all the user data on an object, 00786 call FirstUserData() and then use ON_UserData::Next() 00787 to traverse the list. 00788 */ 00789 ON_UserData* FirstUserData() const; 00790 00791 /* 00792 Description: 00793 Objects derived from ON_Geometry must call 00794 TransformUserData() in their Transform() member function. 00795 Parameters: 00796 xform - [in] transformation to apply to user data 00797 */ 00798 void TransformUserData( 00799 const ON_Xform& xform 00800 ); 00801 00802 /* 00803 Description: 00804 Expert user tool that copies user data that has a positive 00805 m_userdata_copycount from the source_object to this. 00806 Parameters: 00807 source_object - [in] source of user data to copy 00808 Remarks: 00809 Generally speaking you don't need to use CopyUserData(). 00810 Simply rely on ON_Object::operator=() or the copy constructor 00811 to do the right thing. 00812 */ 00813 void CopyUserData( 00814 const ON_Object& source_object 00815 ); 00816 00817 /* 00818 Description: 00819 Expert user tool Moves user data from source_object 00820 to this, including user data with a nil m_userdata_copycount. 00821 Deletes any source user data with a duplicate m_userdata_uuid 00822 on this. 00823 */ 00824 void MoveUserData( 00825 ON_Object& source_object 00826 ); 00827 00828 00830 // 00831 // Expert interface 00832 // 00833 00834 /* 00835 Description: 00836 Expert user function. If you are using openNURBS in its 00837 default configuration to read and write 3dm archives, 00838 you never need to call this function. 00839 Many objects employ lazy creation of (runtime) caches 00840 that save information to help speed geometric calculations. 00841 This function will destroy all runtime information. 00842 Parameters: 00843 bDelete - [in] if true, any cached information is properly 00844 deleted. If false, any cached information 00845 is simply discarded. This is useful when 00846 the cached information may be in alternate 00847 memory pools that are managed in nonstandard 00848 ways. 00849 */ 00850 virtual 00851 void DestroyRuntimeCache( bool bDelete = true ); 00852 00853 private: 00854 friend int ON_BinaryArchive::ReadObject( ON_Object** ); 00855 friend bool ON_BinaryArchive::WriteObject( const ON_Object& ); 00856 friend bool ON_BinaryArchive::ReadObjectUserData( ON_Object& ); 00857 friend bool ON_BinaryArchive::WriteObjectUserData( const ON_Object& ); 00858 friend class ON_UserData; 00859 ON_UserData* m_userdata_list; 00860 }; 00861 00862 #endif 00863