opennurbs_object_history.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(ON_OBJECT_HISTORY_INC_)
18 #define ON_OBJECT_HISTORY_INC_
19 
20 #if defined(ON_DLL_TEMPLATE)
21 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray< class ON_Value* >;
22 #endif
23 
24 class ON_CLASS ON_CurveProxyHistory
25 {
26 public:
27  // Used to save information needed to create an ON_CurveProxy
28  // reference in history records.
31 
32  ON_ObjRef m_curve_ref; // from ON_CurveProxy.m_real_curve
33  bool m_bReversed; // from ON_CurveProxy.m_bReversed
34  ON_Interval m_full_real_curve_domain; // from ON_CurveProxy.m_real_curve.Domain()
35  ON_Interval m_sub_real_curve_domain; // from ON_CurveProxy.m_real_curve_domain
36  ON_Interval m_proxy_curve_domain; // from ON_CurveProxy.m_this_domain
37 
38  void Destroy();
39  bool Write( ON_BinaryArchive& ) const;
40  bool Read( ON_BinaryArchive& );
41  void Dump( ON_TextLog& ) const;
42 
43 private:
44  ON__UINT8 m_reserved[64];
45 };
46 
47 #if defined(ON_DLL_TEMPLATE)
48 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_CurveProxyHistory>;
49 #endif
50 
51 class ON_CLASS ON_PolyEdgeHistory
52 {
53 public:
54  // Used to save information needed to create an CRhinoPolyEdge
55  // reference in history records.
58 
59  void Destroy();
60  bool Write( ON_BinaryArchive& ) const;
61  bool Read( ON_BinaryArchive& );
62  void Dump( ON_TextLog& ) const;
63 
67 private:
68  ON__UINT8 m_reserved[64];
69 };
70 
71 class ON_CLASS ON_HistoryRecord : public ON_ModelComponent
72 {
73  ON_OBJECT_DECLARE(ON_HistoryRecord);
74 public:
75  static const ON_HistoryRecord Empty;
76 
77 public:
78  ON_HistoryRecord() ON_NOEXCEPT;
81  ON_HistoryRecord& operator=(const ON_HistoryRecord& src);
82 
83 private:
84  void Internal_Destroy();
85  void Internal_Copy(
86  const ON_HistoryRecord& src
87  );
88 
89 public:
90  bool IsValid( class ON_TextLog* text_log = nullptr ) const override;
91  void Dump( ON_TextLog& ) const override;
92  bool Write(ON_BinaryArchive& binary_archive) const override;
93  bool Read(ON_BinaryArchive& binary_archive) override;
94 
95 private:
96  bool Internal_WriteV5(ON_BinaryArchive& binary_archive) const;
97 private:
98  bool Internal_ReadV5(ON_BinaryArchive& binary_archive);
99 
100 public:
101  void DestroyValue( int value_id );
102 
103  /*
104  Description:
105  For setting values.
106  Parameters:
107  value_id - [in]
108  If there a value with the same input
109  id exists, the old value is replaced.
110  count - [in]
111  Number of values
112  b - [in]
113  array of count bools
114  i - [in]
115  array of count ints
116  x - [in]
117  array of count doubles
118  p - [in]
119  array of count 3d points
120  v - [in]
121  array of count 3d vectors
122  xform - [in]
123  array of count xforms
124  c - [in]
125  array of count colors
126  or - [in]
127  array of count object references
128  g - [in]
129  array of count geometry pointers
130  u - [in]
131  array of uuids
132  s - [in]
133  string
134  */
135  bool SetBoolValue( int value_id, bool b);
136  bool SetIntValue( int value_id, int i);
137  bool SetDoubleValue( int value_id, double x);
138  bool SetPointValue( int value_id, ON_3dPoint p);
139  bool SetVectorValue( int value_id, ON_3dVector v);
140  bool SetXformValue( int value_id, ON_Xform xform);
141  bool SetColorValue( int value_id, ON_Color c);
142  bool SetObjRefValue( int value_id, const ON_ObjRef& oref);
143  bool SetPointOnObjectValue( int value_id, const ON_ObjRef& oref, ON_3dPoint point );
144  bool SetUuidValue( int value_id, ON_UUID uuid );
145  bool SetStringValue( int value_id, const wchar_t* s );
146  bool SetGeometryValue( int value_id, ON_Geometry* g);
147  bool SetPolyEdgeValue( int value_id, const ON_PolyEdgeHistory& polyedge );
148 
149  /*
150  Description:
151  For setting values.
152  Parameters:
153  value_id - [in]
154  If there a value with the same input
155  id exists, the old value is replaced.
156  count - [in]
157  Number of values
158  b - [in]
159  array of count bools
160  i - [in]
161  array of count ints
162  x - [in]
163  array of count doubles
164  P - [in]
165  array of count 3d points
166  V - [in]
167  array of count 3d vectors
168  xform - [in]
169  array of count xforms
170  c - [in]
171  array of count colors
172  or - [in]
173  array of count object references
174  g - [in]
175  array of count geometry pointers
176  u - [in]
177  array of uuids
178  s - [in]
179  array of strings
180  */
181  bool SetBoolValues( int value_id, int count, const bool* b);
182  bool SetIntValues( int value_id, int count, const int* i);
183  bool SetDoubleValues( int value_id, int count, const double* x);
184  bool SetPointValues( int value_id, int count, const ON_3dPoint* P);
185  bool SetVectorValues( int value_id, int count, const ON_3dVector* V);
186  bool SetXformValues( int value_id, int count, const ON_Xform* xform);
187  bool SetColorValues( int value_id, int count, const ON_Color* c);
188  bool SetObjRefValues( int value_id, int count, const ON_ObjRef* oref);
189  bool SetUuidValues( int value_id, int count, const ON_UUID* u );
190  bool SetStringValues( int value_id, int count, const wchar_t* const* s );
191  bool SetStringValues( int value_id, const ON_ClassArray<ON_wString>& s );
192  bool SetGeometryValues( int value_id, const ON_SimpleArray<ON_Geometry*> a);
193  bool SetPolyEdgeValues( int value_id, int count, const ON_PolyEdgeHistory* a );
194 
195  /*
196  Description:
197  For retrieving values.
198  */
199  bool GetStringValue( int value_id, ON_wString& str ) const;
200  bool GetBoolValue( int value_id, bool* b ) const;
201  bool GetIntValue( int value_id, int* i ) const;
202  bool GetDoubleValue( int value_id, double* number ) const;
203  bool GetPointValue( int value_id, ON_3dPoint& point ) const;
204  bool GetVectorValue( int value_id, ON_3dVector& point ) const;
205  bool GetXformValue( int value_id, ON_Xform& point ) const;
206  bool GetColorValue( int value_id, ON_Color* color ) const;
207  bool GetObjRefValue( int value_id, ON_ObjRef& oref ) const;
208  bool GetPointOnObjectValue( int value_id, ON_ObjRef& oref ) const;
209  bool GetCurveValue( int value_id, const ON_Curve*& ) const;
210  bool GetSurfaceValue( int value_id, const ON_Surface*& ) const;
211  bool GetBrepValue( int value_id, const ON_Brep*& ) const;
212  bool GetMeshValue( int value_id, const ON_Mesh*& ) const;
213  bool GetGeometryValue( int value_id, const ON_Geometry*& ) const;
214  bool GetUuidValue( int value_id, ON_UUID* uuid ) const;
215  bool GetPolyEdgeValue( int value_id, const ON_PolyEdgeHistory*& polyedge ) const;
216 
217  int GetStringValues( int value_id, ON_ClassArray<ON_wString>& string ) const;
218  int GetBoolValues( int value_id, ON_SimpleArray<bool>& ) const;
219  int GetIntValues( int value_id, ON_SimpleArray<int>& ) const;
220  int GetDoubleValues( int value_id, ON_SimpleArray<double>& ) const;
221  int GetPointValues( int value_id, ON_SimpleArray<ON_3dPoint>& ) const;
222  int GetVectorValues( int value_id, ON_SimpleArray<ON_3dVector>& ) const;
223  int GetXformValues( int value_id, ON_SimpleArray<ON_Xform>& ) const;
224  int GetColorValues( int value_id, ON_SimpleArray<ON_Color>& ) const;
225  int GetObjRefValues( int value_id, ON_ClassArray<ON_ObjRef>& objects ) const;
226  int GetGeometryValues( int value_id, ON_SimpleArray<const ON_Geometry*>& ) const;
227  int GetUuidValues( int value_id, ON_SimpleArray<ON_UUID>& ) const;
228  int GetPolyEdgeValues( int value_id, ON_SimpleArray<const ON_PolyEdgeHistory*>& ) const;
229 
230  /*
231  Desccription:
232  Determine if object is an antecedent (input) in this
233  history record.
234  Parameters:
235  object_uuid - [in]
236  Returns:
237  Returns true if object_uuid is the id of an input
238  object.
239  */
240  bool IsAntecedent( ON_UUID object_uuid ) const;
241 
242 
243  /*
244  Description:
245  Print a list of the values in text_log.
246  Parameters:
247  text_log - [in]
248  Returns:
249  Number of values listed.
250  */
251  int ValueReport( ON_TextLog& text_log ) const;
252 
253  // CRhinoCommand::CommandId() value of the command that
254  // created this history record. Each time the command
255  // is run, it can create a history record.
256  ON_UUID m_command_id = ON_nil_uuid;
257 
258  // A YYYYMMDDn version number that gets updated when
259  // a command changes. This version is checked so that
260  // new versions of a command's ReplayHistory don't
261  // attempt to use information saved in old files.
262  int m_version = 0;
263 
264  enum class RECORD_TYPE : unsigned int
265  {
266  history_parameters = 0, // parameters for UpdateHistory
267  feature_parameters = 1 // parameters for a feature
268  };
269 
271 
272  /*
273  Description:
274  Convert integer into an ON_HistoryRecord::RECORD_TYPE.
275  Parameters:
276  i - [in]
277  Returns:
278  ON_HistoryRecord::RECORD_TYPE enum with same value as i.
279  */
280  static
281  ON_HistoryRecord::RECORD_TYPE RecordType(int i);
282 
283  // List of object id values of antecedent objects that
284  // are referenced in the list of input events in m_value[].
285  // These were the command's "input" objects.
286  ON_UuidList m_antecedents;
288  // List of object id values of descendant objects that
289  // were created. These were the command's "output" objects
290  ON_UuidList m_descendants;
291 
292  // Information needed to update the descendant objects
293  // when an antecedent object is modified.
295 
296  /*
297  Description:
298  This tool is used in rare situations when the object ids
299  stored in the uuid list need to be remapped.
300  Parameters:
301  uuid_remap - [in]
302  Is it critical that uuid_remap[] be sorted with respect
303  to ON_UuidPair::CompareFirstUuid.
304  */
305  void RemapObjectIds( const ON_SimpleArray<ON_UuidPair>& uuid_remap );
306 
307  /*
308  12 May, 2015 - Lowell
309  When an object is replaced and the old object has a history record with
310  CopyOnReplaceObject() set to tru, then history record is copied and
311  attached to the new object.
312  That allows a descendant object to continue the history linkage after
313  it is edited.
314  See http://mcneel.myjetbrains.com/youtrack/issue/RH-30399
315  */
316  bool CopyOnReplaceObject() const;
317 
318  void SetCopyOnReplaceObject(
319  bool bCopyOnReplaceObject
320  );
321 
322 private:
323  bool m_bValuesSorted = true;
324  bool m_bCopyOnReplaceObject = false;
325  ON_Value* FindValueHelper( int, int, bool ) const;
326 };
327 
328 #if defined(ON_DLL_TEMPLATE)
329 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_HistoryRecord*>;
330 ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<const ON_HistoryRecord*>;
331 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_HistoryRecord>;
332 #endif
333 
334 #endif
ON_Interval m_full_real_curve_domain
Definition: opennurbs_object_history.h:34
ON_Interval m_proxy_curve_domain
Definition: opennurbs_object_history.h:36
ON_UUID is a 16 byte universally unique identifier.
Definition: opennurbs_uuid.h:32
Definition: opennurbs_object_history.h:71
ON_ObjRef m_curve_ref
Definition: opennurbs_object_history.h:32
The ON_ModelComponent class is a base class for all components in a model and manages the index...
Definition: opennurbs_model_component.h:24
ON_SimpleArray< double > m_t
Definition: opennurbs_object_history.h:65
The ON_UuidList class provides a tool to efficiently maintain a list of uuids and determine if a uuid...
Definition: opennurbs_array.h:803
Definition: opennurbs_array.h:36
ON_Curve is a pure virtual class for curve objects
Definition: opennurbs_curve.h:93
ON_Object array is used to store lists of classes that are derived from ON_Object. It differs from ON_ClassArray in that the virtual ON_Object::MemoryRelocate function is called when growing the dynamic array requires changing the location of the memory buffer used to store the elements in the array.
Definition: opennurbs_array.h:725
Definition: opennurbs_string.h:2020
RECORD_TYPE
Definition: opennurbs_object_history.h:258
Base class for all geometry classes that must provide runtime class id. Provides interface for common...
Definition: opennurbs_geometry.h:37
Definition: opennurbs_object_history.h:24
Definition: opennurbs_color.h:24
Definition: opennurbs_object_history.h:51
int m_evaluation_mode
Definition: opennurbs_object_history.h:66
ON_Interval m_sub_real_curve_domain
Definition: opennurbs_object_history.h:35
bool m_bReversed
Definition: opennurbs_object_history.h:33
Definition: opennurbs_xform.h:28
Definition: opennurbs_mesh.h:2188
ON_ClassArray< ON_CurveProxyHistory > m_segment
Definition: opennurbs_object_history.h:64
Definition: opennurbs_brep.h:1472
Definition: opennurbs_textlog.h:20
Definition: opennurbs_archive.h:1783
Definition: opennurbs_objref.h:163
Definition: opennurbs_point.h:460
Definition: opennurbs_surface.h:57
static const ON_HistoryRecord Empty
Definition: opennurbs_object_history.h:75
Definition: opennurbs_point.h:1152
Definition: opennurbs_point.h:46