Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:userdata [2015/09/14]
127.0.0.1 external edit
developer:userdata [2015/11/18] (current)
sandy
Line 1: Line 1:
-====== Info: Rhino plug-in user data ======+====== Info: Rhino Plug-in User Data ======
 > **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​ > **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 > **Summary:​** //Discusses document and object user data.// > **Summary:​** //Discusses document and object user data.//
- 
-=====Overview===== 
  
  
 There are two basic ways plug-ins can store information in Rhino .3dm files, **document user data** and **object user data**. There are two basic ways plug-ins can store information in Rhino .3dm files, **document user data** and **object user data**.
  
-For example, a rendering plug-in might save a scene descriptions ​as **document user data** and use **object user data** to attach rendering material information to individual surfaces.+For example, a rendering plug-in might save a scene description ​as **document user data** and use **object user data** to attach rendering material information to individual surfaces.
  
-=====Document ​User Data=====+=====Document ​user data=====
  
  
Line 21: Line 19:
 </​code> ​   </​code> ​  
  
-When Rhino writes a .3dm file, it goes through all the plug-ins that are currently loaded. ​ First Rhino calls CallWriteDocument() to see if the plug-in wants to save document user data.  If CallWriteDocument() returns true, Rhino saves information that identifies the plug-in and then calls WriteDocument() when it is time for the plug-in to save its "document" ​user data.+When Rhino writes a .3dm file, it goes through all the plug-ins that are currently loaded. ​ First Rhino calls CallWriteDocument() to see if the plug-in wants to save document user data.  If CallWriteDocument() returns true, Rhino saves information that identifies the plug-in and then calls WriteDocument() when it is time for the plug-in to save its document user data.
  
-When Rhino reads a .3dm file and it encounters document user data, it uses the plug-in identification information to load the plug-in and then calls the plug-in'​s ReadDocument() to read the plug-in'​s ​"document" ​user data.+When Rhino reads a .3dm file and it encounters document user data, it uses the plug-in identification information to load the plug-in and then calls the plug-in'​s ReadDocument() to read the plug-in'​s document user data.
  
-Sample ​of this is provided at **[[developer:​sdksamples:​documentdata|SdkDocumentData]]**.+sample ​of this is provided at **[[developer:​sdksamples:​documentdata|SdkDocumentData]]**.
  
  
-=====Object ​User Data=====+=====Object ​user data=====
  
-Object user data can be attached to things like layers, materials, geometry objects, and object attributes. ​ In fact object user data can be attached to any class derived from ON_Object. ​ This user data is stored in a linked list on ON_Object and can be copied, transformed and saved along with the parent object. ​ For example, you could attach object user data to a mesh.  When the mesh is copied the object user data would be copied and attached to the copy.  When the mesh is transformed,​ the transformation ​would be recored ​by the object user data.  When the mesh is saved in a .3dm file, the object user data will be saved too.+Object user data can be attached to things like layers, materials, geometry objects, and object attributes. ​ In fact object user data can be attached to any class derived from ON_Object. ​ This user data is stored in a linked list on ON_Object and can be copied, transformedand saved along with the parent object. ​ For example, you could attach object user data to a mesh.  When the mesh is copied the object user data is copied and attached to the copy.  When the mesh is transformed,​ the transformation ​is recorded ​by the object user data.  When the mesh is saved in a .3dm file, the object user data is saved too.
  
-All object user data is saved in a class you write that is derived from the class ON_UserData. ​ The first example, CMyUserData1,​ shows how to make a simple piece of user data that is not save in .3dm files. ​ The second example, CMyUserData2,​ shows how to make a piece of user data that is saved in .3dm files.+All object user data is saved in a class you write that is derived from the class ON_UserData. ​ The first example, CMyUserData1,​ shows how to make a simple piece of user data that is not saved in .3dm files. ​ The second example, CMyUserData2,​ shows how to make a piece of user data that is saved in .3dm files.
  
 =====Examples===== =====Examples=====
  
-**[[http://​wiki.mcneel.com/​_media/​legacy/​en/​MyUserDataExample.zip|The source code for the next two the examples ​can be downloaded here.]]**+You can download the [[http://​wiki.mcneel.com/​_media/​legacy/​en/​MyUserDataExample.zip|source code for the next two examples]] ​here.
  
 ===Example: CMyUserData1=== ===Example: CMyUserData1===
Line 62: Line 60:
 </​code>​ </​code>​
  
-The CMyUserData1 class must always be on the heap ( constructed by calling the C++ new operator ).  The class'​s constuctor must initialize two ON_UserData fields, m_userdata_uuid,​ m_application_uuid. ​ In addition, if you want the object user data to be copied whenever its parent object is copied, you have to set m_userdata_copycount to one.+The CMyUserData1 class must always be on the heap (constructed by calling the C++ new operator). ​ The class'​s constuctor must initialize two ON_UserData fields, m_userdata_uuid,​ m_application_uuid. ​ In addition, if you want the object user data copied whenever its parent object is copied, you have to set m_userdata_copycount to one.
  
 <code c++> <code c++>
Line 126: Line 124:
 Make sure you completely understand the CMyUserData1 example before studying this example. Make sure you completely understand the CMyUserData1 example before studying this example.
  
-In order to have your user data saved in files, you have to add several IO related functions and add full [[developer:​opennurbs:​home|opennurbs]] object support to your class.+To have your user data saved in files, you have to add several IO related functions and add full [[developer:​opennurbs:​home|opennurbs]] object support to your class.
  
 <code c++> <code c++>
Line 158: Line 156:
 </​code>​ </​code>​
  
-Again, the CMyUserData2 class must always be on the heap ( constructed by calling the C++ new operator ).  In order to support file IO, the definition of CMyUserData2 must contain the ON_OBJECT_DECLARE macro.+Again, the CMyUserData2 class must always be on the heap (constructed by calling the C++ new operator). ​To support file IO, the definition of CMyUserData2 must contain the ON_OBJECT_DECLARE macro.
  
 The cpp file where the class is implemented must contain the ON_OBJECT_IMPLEMENT macro shown below. The cpp file where the class is implemented must contain the ON_OBJECT_IMPLEMENT macro shown below.
Line 166: Line 164:
 </​code>​ </​code>​
  
-The construction code for CMyUserData2 looks like.+The construction code for CMyUserData2 looks like:
  
 <code c++> <code c++>
Line 266: Line 264:
 </​code>​ </​code>​
  
-=====Attaching ​Object User Data to CRhinoObjects=====+=====Attaching ​object user data to CRhinoObjects=====
  
 The Rhino geometry table is where the bulk of the Rhino model is stored. ​ This is where the points, curves, meshes, surface, polysurfaces,​ annotation, render lights, and so on are stored. ​ Each member of the geometry table is derived from the CRhinoObject class. ​ There are three places you can attach object user data to a CRhinoObject:​ the CRhinoObject geometry class, the CRhinoObject attributes class, and the CRhinoObject itself. ​ Object user data attached to the geometry and attributes class persists through copys, transformations,​ and file IO.  Object user data attached directly on the CRhinoObject class is never saved in .3dm file. The Rhino geometry table is where the bulk of the Rhino model is stored. ​ This is where the points, curves, meshes, surface, polysurfaces,​ annotation, render lights, and so on are stored. ​ Each member of the geometry table is derived from the CRhinoObject class. ​ There are three places you can attach object user data to a CRhinoObject:​ the CRhinoObject geometry class, the CRhinoObject attributes class, and the CRhinoObject itself. ​ Object user data attached to the geometry and attributes class persists through copys, transformations,​ and file IO.  Object user data attached directly on the CRhinoObject class is never saved in .3dm file.
developer/userdata.txt ยท Last modified: 2015/11/18 by sandy