opennurbs_object_history.cpp
Go to the documentation of this file.
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 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00018 
00019 class ON_Value
00020 {
00021 public:
00022 
00023   // The VALUE_TYPE enum values must never be changed
00024   // because the values are used to determine the parameter
00025   // type during file reading.  Additions can be made.
00026   enum VALUE_TYPE
00027   {
00028     no_value_type         =  0,
00029 
00030     bool_value            =  1,
00031     int_value             =  2,
00032     double_value          =  3,
00033     color_value           =  4,
00034     point_value           =  5,
00035     vector_value          =  6,
00036     xform_value           =  7,
00037     string_value          =  8,
00038     objref_value          =  9,
00039     geometry_value        = 10,
00040     uuid_value            = 11,
00041     point_on_object_value = 12,
00042     polyedge_value        = 13,
00043 
00044     // each value type must have a case in ON_Value::CreateValue().
00045 
00046     force_32bit_enum = 0xFFFFFFFF
00047   };
00048 
00049   static
00050   ON_Value* CreateValue( int value_type );
00051 
00052   void Report(
00053     ON_TextLog& text_log
00054     ) const;
00055 
00056   // The valid id is a nonzero integer the developer
00057   // assigns to this value.  Developers are responsible
00058   // for ensuring the 
00059   int m_value_id;
00060   
00061   const VALUE_TYPE m_value_type;
00062 
00063   ON_Value( VALUE_TYPE );
00064   virtual ~ON_Value();
00065 
00066   virtual ON_Value* Duplicate() const=0;
00067   virtual int  Count() const=0;
00068   virtual bool ReadHelper(ON_BinaryArchive& )=0;
00069   virtual bool WriteHelper(ON_BinaryArchive& ) const=0;
00070   virtual bool ReportHelper(ON_TextLog& ) const=0;
00071 
00072   virtual int  GetBools( const bool*& ) const;
00073   virtual int  GetInts( const int*& ) const;
00074   virtual int  GetColors( const ON_Color*& ) const;
00075   virtual int  GetDoubles( const double*& ) const;
00076   virtual int  Get3dPoints( const ON_3dPoint*& ) const;
00077   virtual int  Get3dVectors( const ON_3dVector*& ) const;
00078   virtual int  GetXforms( const ON_Xform*& ) const;
00079   virtual int  GetUuids( const ON_UUID*& ) const;
00080   virtual int  GetObjRefs( ON_ClassArray<ON_ObjRef>& ) const;
00081   virtual int  GetGeometryPointers( const ON_Geometry* const*& ) const;
00082   virtual int  GetStrings( ON_ClassArray<ON_wString>& ) const;
00083   virtual int  GetPolyEdgePointers( ON_ClassArray<ON_PolyEdgeHistory>& ) const;
00084 
00085 private:
00086   // no implementation
00087   ON_Value(); 
00088   ON_Value& operator=(const ON_Value&);
00089 };
00090 
00091 ON_Value::ON_Value( ON_Value::VALUE_TYPE value_type )
00092          : m_value_type(value_type)
00093 {
00094   m_value_id = -1;
00095 }
00096 
00097 ON_Value::~ON_Value()
00098 {}
00099 
00100 // base class virtuals do nothing.
00101 int  ON_Value::GetBools( const bool*& ) const {return 0;}
00102 int  ON_Value::GetInts( const int*& ) const {return 0;}
00103 int  ON_Value::GetColors( const ON_Color*& ) const {return 0;}
00104 int  ON_Value::GetDoubles( const double*& ) const {return 0;}
00105 int  ON_Value::Get3dPoints( const ON_3dPoint*& ) const {return 0;}
00106 int  ON_Value::Get3dVectors( const ON_3dVector*& ) const {return 0;}
00107 int  ON_Value::GetXforms( const ON_Xform*& ) const {return 0;}
00108 int  ON_Value::GetUuids( const ON_UUID*& ) const {return 0;}
00109 int  ON_Value::GetObjRefs( ON_ClassArray<ON_ObjRef>& ) const {return 0;}
00110 int  ON_Value::GetGeometryPointers( const ON_Geometry* const*& ) const {return 0;}
00111 int  ON_Value::GetStrings( ON_ClassArray<ON_wString>& ) const {return 0;}
00112 int  ON_Value::GetPolyEdgePointers( ON_ClassArray<ON_PolyEdgeHistory>& ) const {return 0;}
00113 
00114 class ON_DummyValue : public ON_Value
00115 {
00116 public:
00117   ON_DummyValue();
00118   ~ON_DummyValue();
00119   ON_Value* Duplicate() const;
00120   int  Count() const;
00121   bool ReadHelper(ON_BinaryArchive& );
00122   bool WriteHelper(ON_BinaryArchive& ) const;
00123   bool ReportHelper(ON_TextLog& ) const;
00124 };
00125 
00126 ON_DummyValue::ON_DummyValue() : ON_Value(ON_Value::no_value_type)
00127 {
00128 }
00129 
00130 ON_DummyValue::~ON_DummyValue()
00131 {
00132 }
00133 
00134 ON_Value* ON_DummyValue::Duplicate() const {return 0;}
00135 int  ON_DummyValue::Count() const {return 0;}
00136 bool ON_DummyValue::ReadHelper(ON_BinaryArchive& ) {return 0;}
00137 bool ON_DummyValue::WriteHelper(ON_BinaryArchive& ) const {return 0;}
00138 bool ON_DummyValue::ReportHelper(ON_TextLog& ) const {return 0;}
00140 //
00141 // ON_BoolValue saves bool values in the ON_HistoryRecord::m_value[] array
00142 //
00143 
00144 class ON_BoolValue : public ON_Value
00145 {
00146 public:
00147   ON_BoolValue();
00148   ~ON_BoolValue();
00149 
00150   ON_SimpleArray<bool> m_value;
00151 
00152   // virtual 
00153   class ON_Value* Duplicate() const;
00154 
00155   // virtual
00156   int Count() const;
00157 
00158   // virtual 
00159   bool ReadHelper(ON_BinaryArchive& archive );
00160 
00161   // virtual 
00162   bool WriteHelper(ON_BinaryArchive& archive ) const;
00163 
00164   // virtual 
00165   bool ReportHelper(ON_TextLog& text_log ) const;
00166 
00167   // virtual 
00168   int GetBools( const bool*& b ) const;
00169 };
00170 
00171 ON_BoolValue::ON_BoolValue() 
00172              : ON_Value(ON_Value::bool_value) 
00173 {
00174 }
00175 
00176 ON_BoolValue::~ON_BoolValue()
00177 {
00178 }
00179 
00180 // virtual 
00181 class ON_Value* ON_BoolValue::Duplicate() const
00182 {
00183   return new ON_BoolValue(*this);
00184 }
00185 
00186 // virtual
00187 int ON_BoolValue::Count() const 
00188 {
00189   return m_value.Count();
00190 }
00191 
00192 // virtual 
00193 bool ON_BoolValue::ReadHelper(ON_BinaryArchive& archive )
00194 {
00195   return archive.ReadArray(m_value);
00196 }
00197 
00198 // virtual 
00199 bool ON_BoolValue::WriteHelper(ON_BinaryArchive& archive ) const
00200 {
00201   return archive.WriteArray(m_value);
00202 }
00203 
00204 // virtual 
00205 bool ON_BoolValue::ReportHelper(ON_TextLog& text_log ) const
00206 {
00207   int i, count = m_value.Count();
00208   text_log.Print("bool value\n");
00209   text_log.PushIndent();
00210   for ( i = 0; i < count; i++ )
00211   {
00212     text_log.Print(m_value[i]?"true":"false");
00213   }
00214   text_log.PopIndent();
00215   return true;
00216 }
00217 
00218 // virtual 
00219 int ON_BoolValue::GetBools( const bool*& b ) const
00220 {
00221   b = m_value.Array();
00222   return m_value.Count();
00223 }
00224 
00225 
00227 //
00228 // ON_IntValue saves int values in the ON_HistoryRecord::m_value[] array
00229 //
00230 
00231 class ON_IntValue : public ON_Value
00232 {
00233 public:
00234   ON_IntValue();
00235   ~ON_IntValue();
00236 
00237   ON_SimpleArray<int> m_value;
00238 
00239   // virtual 
00240   class ON_Value* Duplicate() const;
00241 
00242   // virtual
00243   int Count() const;
00244 
00245   // virtual 
00246   bool ReadHelper(ON_BinaryArchive& archive );
00247 
00248   // virtual 
00249   bool WriteHelper(ON_BinaryArchive& archive ) const;
00250 
00251   // virtual 
00252   bool ReportHelper(ON_TextLog& text_log ) const;
00253 
00254   // virtual 
00255   int GetInts( const int*& b ) const;
00256 };
00257 
00258 ON_IntValue::ON_IntValue() 
00259              : ON_Value(ON_Value::int_value) 
00260 {
00261 }
00262 
00263 ON_IntValue::~ON_IntValue()
00264 {
00265 }
00266 
00267 // virtual 
00268 class ON_Value* ON_IntValue::Duplicate() const
00269 {
00270   return new ON_IntValue(*this);
00271 }
00272 
00273 // virtual
00274 int ON_IntValue::Count() const 
00275 {
00276   return m_value.Count();
00277 }
00278 
00279 // virtual 
00280 bool ON_IntValue::ReadHelper(ON_BinaryArchive& archive )
00281 {
00282   return archive.ReadArray(m_value);
00283 }
00284 
00285 // virtual 
00286 bool ON_IntValue::WriteHelper(ON_BinaryArchive& archive ) const
00287 {
00288   return archive.WriteArray(m_value);
00289 }
00290 
00291 // virtual 
00292 bool ON_IntValue::ReportHelper(ON_TextLog& text_log ) const
00293 {
00294   int i, count = m_value.Count();
00295   text_log.Print("integer value\n");
00296   text_log.PushIndent();
00297   for ( i = 0; i < count; i++ )
00298   {
00299     text_log.Print("%d",m_value[i]);
00300   }
00301   text_log.PopIndent();
00302   return true;
00303 }
00304 
00305 // virtual 
00306 int ON_IntValue::GetInts( const int*& b ) const
00307 {
00308   b = m_value.Array();
00309   return m_value.Count();
00310 }
00311 
00312 
00314 //
00315 // ON_DoubleValue saves bool values in the ON_HistoryRecord::m_value[] array
00316 //
00317 
00318 class ON_DoubleValue : public ON_Value
00319 {
00320 public:
00321   ON_DoubleValue();
00322   ~ON_DoubleValue();
00323 
00324   ON_SimpleArray<double> m_value;
00325 
00326   // virtual 
00327   class ON_Value* Duplicate() const;
00328 
00329   // virtual
00330   int Count() const;
00331 
00332   // virtual 
00333   bool ReadHelper(ON_BinaryArchive& archive );
00334 
00335   // virtual 
00336   bool WriteHelper(ON_BinaryArchive& archive ) const;
00337 
00338   // virtual 
00339   bool ReportHelper(ON_TextLog& text_log ) const;
00340 
00341   // virtual 
00342   int GetDoubles( const double*& a ) const;
00343 };
00344 
00345 ON_DoubleValue::ON_DoubleValue() 
00346              : ON_Value(ON_Value::double_value) 
00347 {
00348 }
00349 
00350 ON_DoubleValue::~ON_DoubleValue()
00351 {
00352 }
00353 
00354 // virtual 
00355 class ON_Value* ON_DoubleValue::Duplicate() const
00356 {
00357   return new ON_DoubleValue(*this);
00358 }
00359 
00360 // virtual
00361 int ON_DoubleValue::Count() const 
00362 {
00363   return m_value.Count();
00364 }
00365 
00366 // virtual 
00367 bool ON_DoubleValue::ReadHelper(ON_BinaryArchive& archive )
00368 {
00369   return archive.ReadArray(m_value);
00370 }
00371 
00372 // virtual 
00373 bool ON_DoubleValue::WriteHelper(ON_BinaryArchive& archive ) const
00374 {
00375   return archive.WriteArray(m_value);
00376 }
00377 
00378 // virtual 
00379 bool ON_DoubleValue::ReportHelper(ON_TextLog& text_log ) const
00380 {
00381   int i, count = m_value.Count();
00382   text_log.Print("number value\n");
00383   text_log.PushIndent();
00384   for ( i = 0; i < count; i++ )
00385   {
00386     text_log.Print(m_value[i]);
00387   }
00388   text_log.PopIndent();
00389   return true;
00390 }
00391 
00392 // virtual 
00393 int ON_DoubleValue::GetDoubles( const double*& a ) const
00394 {
00395   a = m_value.Array();
00396   return m_value.Count();
00397 }
00398 
00400 //
00401 // ON_PointValue saves bool values in the ON_HistoryRecord::m_value[] array
00402 //
00403 
00404 class ON_PointValue : public ON_Value
00405 {
00406 public:
00407   ON_PointValue();
00408   ~ON_PointValue();
00409 
00410   ON_SimpleArray<ON_3dPoint> m_value;
00411 
00412   // virtual 
00413   class ON_Value* Duplicate() const;
00414 
00415   // virtual
00416   int Count() const;
00417 
00418   // virtual 
00419   bool ReadHelper(ON_BinaryArchive& archive );
00420 
00421   // virtual 
00422   bool WriteHelper(ON_BinaryArchive& archive ) const;
00423 
00424   // virtual 
00425   bool ReportHelper(ON_TextLog& text_log ) const;
00426 
00427   // virtual 
00428   int Get3dPoints( const ON_3dPoint*& a ) const;
00429 };
00430 
00431 ON_PointValue::ON_PointValue() 
00432              : ON_Value(ON_Value::point_value) 
00433 {
00434 }
00435 
00436 ON_PointValue::~ON_PointValue()
00437 {
00438 }
00439 
00440 // virtual 
00441 class ON_Value* ON_PointValue::Duplicate() const
00442 {
00443   return new ON_PointValue(*this);
00444 }
00445 
00446 // virtual
00447 int ON_PointValue::Count() const 
00448 {
00449   return m_value.Count();
00450 }
00451 
00452 // virtual 
00453 bool ON_PointValue::ReadHelper(ON_BinaryArchive& archive )
00454 {
00455   return archive.ReadArray(m_value);
00456 }
00457 
00458 // virtual 
00459 bool ON_PointValue::WriteHelper(ON_BinaryArchive& archive ) const
00460 {
00461   return archive.WriteArray(m_value);
00462 }
00463 
00464 // virtual 
00465 bool ON_PointValue::ReportHelper(ON_TextLog& text_log ) const
00466 {
00467   int i, count = m_value.Count();
00468   text_log.Print("point value\n");
00469   text_log.PushIndent();
00470   for ( i = 0; i < count; i++ )
00471   {
00472     text_log.Print(m_value[i]);
00473   }
00474   text_log.PopIndent();
00475   return true;
00476 }
00477 
00478 // virtual 
00479 int ON_PointValue::Get3dPoints( const ON_3dPoint*& a ) const
00480 {
00481   a = m_value.Array();
00482   return m_value.Count();
00483 }
00484 
00485 
00487 //
00488 // ON_VectorValue saves bool values in the ON_HistoryRecord::m_value[] array
00489 //
00490 
00491 class ON_VectorValue : public ON_Value
00492 {
00493 public:
00494   ON_VectorValue();
00495   ~ON_VectorValue();
00496 
00497   ON_SimpleArray<ON_3dVector> m_value;
00498 
00499   // virtual 
00500   class ON_Value* Duplicate() const;
00501 
00502   // virtual
00503   int Count() const;
00504 
00505   // virtual 
00506   bool ReadHelper(ON_BinaryArchive& archive );
00507 
00508   // virtual 
00509   bool WriteHelper(ON_BinaryArchive& archive ) const;
00510 
00511   // virtual 
00512   bool ReportHelper(ON_TextLog& text_log ) const;
00513 
00514   // virtual 
00515   int Get3dVectors( const ON_3dVector*& a ) const;
00516 };
00517 
00518 ON_VectorValue::ON_VectorValue() 
00519              : ON_Value(ON_Value::vector_value) 
00520 {
00521 }
00522 
00523 ON_VectorValue::~ON_VectorValue()
00524 {
00525 }
00526 
00527 // virtual 
00528 class ON_Value* ON_VectorValue::Duplicate() const
00529 {
00530   return new ON_VectorValue(*this);
00531 }
00532 
00533 // virtual
00534 int ON_VectorValue::Count() const 
00535 {
00536   return m_value.Count();
00537 }
00538 
00539 // virtual 
00540 bool ON_VectorValue::ReadHelper(ON_BinaryArchive& archive )
00541 {
00542   return archive.ReadArray(m_value);
00543 }
00544 
00545 // virtual 
00546 bool ON_VectorValue::WriteHelper(ON_BinaryArchive& archive ) const
00547 {
00548   return archive.WriteArray(m_value);
00549 }
00550 
00551 // virtual 
00552 bool ON_VectorValue::ReportHelper(ON_TextLog& text_log ) const
00553 {
00554   text_log.Print("vector value\n");
00555   text_log.PushIndent();
00556   int i, count = m_value.Count();
00557   for ( i = 0; i < count; i++ )
00558   {
00559     text_log.Print(m_value[i]);
00560   }
00561   text_log.PopIndent();
00562   return true;
00563 }
00564 
00565 // virtual 
00566 int ON_VectorValue::Get3dVectors( const ON_3dVector*& a ) const
00567 {
00568   a = m_value.Array();
00569   return m_value.Count();
00570 }
00571 
00572 
00574 //
00575 // ON_XformValue saves bool values in the ON_HistoryRecord::m_value[] array
00576 //
00577 
00578 class ON_XformValue : public ON_Value
00579 {
00580 public:
00581   ON_XformValue();
00582   ~ON_XformValue();
00583 
00584   ON_SimpleArray<ON_Xform> m_value;
00585 
00586   // virtual 
00587   class ON_Value* Duplicate() const;
00588 
00589   // virtual
00590   int Count() const;
00591 
00592   // virtual 
00593   bool ReadHelper(ON_BinaryArchive& archive );
00594 
00595   // virtual 
00596   bool WriteHelper(ON_BinaryArchive& archive ) const;
00597 
00598   // virtual 
00599   bool ReportHelper(ON_TextLog& text_log ) const;
00600 
00601   // virtual 
00602   int GetXforms( const ON_Xform*& a ) const;
00603 };
00604 
00605 ON_XformValue::ON_XformValue() 
00606              : ON_Value(ON_Value::xform_value) 
00607 {
00608 }
00609 
00610 ON_XformValue::~ON_XformValue()
00611 {
00612 }
00613 
00614 // virtual 
00615 class ON_Value* ON_XformValue::Duplicate() const
00616 {
00617   return new ON_XformValue(*this);
00618 }
00619 
00620 // virtual
00621 int ON_XformValue::Count() const 
00622 {
00623   return m_value.Count();
00624 }
00625 
00626 // virtual 
00627 bool ON_XformValue::ReadHelper(ON_BinaryArchive& archive )
00628 {
00629   return archive.ReadArray(m_value);
00630 }
00631 
00632 // virtual 
00633 bool ON_XformValue::WriteHelper(ON_BinaryArchive& archive ) const
00634 {
00635   return archive.WriteArray(m_value);
00636 }
00637 
00638 // virtual 
00639 bool ON_XformValue::ReportHelper(ON_TextLog& text_log ) const
00640 {
00641   text_log.Print("xform value\n");
00642   text_log.PushIndent();
00643   int i, count = m_value.Count();
00644   for ( i = 0; i < count; i++ )
00645   {
00646     text_log.Print(m_value[i]);
00647   }
00648   text_log.PopIndent();
00649   return true;
00650 }
00651 
00652 // virtual 
00653 int ON_XformValue::GetXforms( const ON_Xform*& a ) const
00654 {
00655   a = m_value.Array();
00656   return m_value.Count();
00657 }
00658 
00659 
00661 //
00662 // ON_ColorValue saves bool values in the ON_HistoryRecord::m_value[] array
00663 //
00664 
00665 class ON_ColorValue : public ON_Value
00666 {
00667 public:
00668   ON_ColorValue();
00669   ~ON_ColorValue();
00670 
00671   ON_SimpleArray<ON_Color> m_value;
00672 
00673   // virtual 
00674   class ON_Value* Duplicate() const;
00675 
00676   // virtual
00677   int Count() const;
00678 
00679   // virtual 
00680   bool ReadHelper(ON_BinaryArchive& archive );
00681 
00682   // virtual 
00683   bool WriteHelper(ON_BinaryArchive& archive ) const;
00684 
00685   // virtual 
00686   bool ReportHelper(ON_TextLog& text_log ) const;
00687 
00688   // virtual 
00689   int GetColors( const ON_Color*& a ) const;
00690 };
00691 
00692 ON_ColorValue::ON_ColorValue() 
00693              : ON_Value(ON_Value::color_value) 
00694 {
00695 }
00696 
00697 ON_ColorValue::~ON_ColorValue()
00698 {
00699 }
00700 
00701 // virtual 
00702 class ON_Value* ON_ColorValue::Duplicate() const
00703 {
00704   return new ON_ColorValue(*this);
00705 }
00706 
00707 // virtual
00708 int ON_ColorValue::Count() const 
00709 {
00710   return m_value.Count();
00711 }
00712 
00713 // virtual 
00714 bool ON_ColorValue::ReadHelper(ON_BinaryArchive& archive )
00715 {
00716   return archive.ReadArray(m_value);
00717 }
00718 
00719 // virtual 
00720 bool ON_ColorValue::WriteHelper(ON_BinaryArchive& archive ) const
00721 {
00722   return archive.WriteArray(m_value);
00723 }
00724 
00725 // virtual 
00726 bool ON_ColorValue::ReportHelper(ON_TextLog& text_log ) const
00727 {
00728   ON_Color c;
00729   text_log.Print("color value\n");
00730   text_log.PushIndent();
00731   int i, count = m_value.Count();
00732   for ( i = 0; i < count; i++ )
00733   {
00734     c = m_value[i];
00735     text_log.Print("rbg(%d,%d,%d)",c.Red(),c.Green(),c.Blue());
00736   }
00737   text_log.PopIndent();
00738   return true;
00739 }
00740 
00741 // virtual 
00742 int ON_ColorValue::GetColors( const ON_Color*& a ) const
00743 {
00744   a = m_value.Array();
00745   return m_value.Count();
00746 }
00747 
00748 
00750 //
00751 // ON_UuidValue saves bool values in the ON_HistoryRecord::m_value[] array
00752 //
00753 
00754 class ON_UuidValue : public ON_Value
00755 {
00756 public:
00757   ON_UuidValue();
00758   ~ON_UuidValue();
00759 
00760   ON_SimpleArray<ON_UUID> m_value;
00761 
00762   // virtual 
00763   class ON_Value* Duplicate() const;
00764 
00765   // virtual
00766   int Count() const;
00767 
00768   // virtual 
00769   bool ReadHelper(ON_BinaryArchive& archive );
00770 
00771   // virtual 
00772   bool WriteHelper(ON_BinaryArchive& archive ) const;
00773 
00774   // virtual 
00775   bool ReportHelper(ON_TextLog& text_log ) const;
00776 
00777   // virtual 
00778   int GetUuids( const ON_UUID*& a ) const;
00779 };
00780 
00781 ON_UuidValue::ON_UuidValue() 
00782              : ON_Value(ON_Value::uuid_value) 
00783 {
00784 }
00785 
00786 ON_UuidValue::~ON_UuidValue()
00787 {
00788 }
00789 
00790 // virtual 
00791 class ON_Value* ON_UuidValue::Duplicate() const
00792 {
00793   return new ON_UuidValue(*this);
00794 }
00795 
00796 // virtual
00797 int ON_UuidValue::Count() const 
00798 {
00799   return m_value.Count();
00800 }
00801 
00802 // virtual 
00803 bool ON_UuidValue::ReadHelper(ON_BinaryArchive& archive )
00804 {
00805   return archive.ReadArray(m_value);
00806 }
00807 
00808 // virtual 
00809 bool ON_UuidValue::WriteHelper(ON_BinaryArchive& archive ) const
00810 {
00811   return archive.WriteArray(m_value);
00812 }
00813 
00814 // virtual 
00815 bool ON_UuidValue::ReportHelper(ON_TextLog& text_log ) const
00816 {
00817   text_log.Print("uuid value\n");
00818   text_log.PushIndent();
00819   int i, count = m_value.Count();
00820   for ( i = 0; i < count; i++ )
00821   {
00822     text_log.Print(m_value[i]);
00823   }
00824   text_log.PopIndent();
00825   return true;
00826 }
00827 
00828 // virtual 
00829 int ON_UuidValue::GetUuids( const ON_UUID*& a ) const
00830 {
00831   a = m_value.Array();
00832   return m_value.Count();
00833 }
00834 
00836 //
00837 // ON_StringValue saves string values in the ON_HistoryRecord::m_value[] array
00838 //
00839 
00840 class ON_StringValue : public ON_Value
00841 {
00842 public:
00843   ON_StringValue();
00844   ~ON_StringValue();
00845 
00846   ON_ClassArray<ON_wString> m_value;
00847 
00848   // virtual 
00849   class ON_Value* Duplicate() const;
00850 
00851   // virtual
00852   int Count() const;
00853 
00854   // virtual 
00855   bool ReadHelper(ON_BinaryArchive& archive );
00856 
00857   // virtual 
00858   bool WriteHelper(ON_BinaryArchive& archive ) const;
00859 
00860   // virtual 
00861   bool ReportHelper(ON_TextLog& text_log ) const;
00862 
00863   // virtual 
00864   int GetStrings( ON_ClassArray<ON_wString>& s ) const;
00865 };
00866 
00867 ON_StringValue::ON_StringValue() 
00868              : ON_Value(ON_Value::string_value) 
00869 {
00870 }
00871 
00872 ON_StringValue::~ON_StringValue()
00873 {
00874 }
00875 
00876 // virtual 
00877 class ON_Value* ON_StringValue::Duplicate() const
00878 {
00879   return new ON_StringValue(*this);
00880 }
00881 
00882 // virtual
00883 int ON_StringValue::Count() const 
00884 {
00885   return m_value.Count();
00886 }
00887 
00888 // virtual 
00889 bool ON_StringValue::ReadHelper(ON_BinaryArchive& archive )
00890 {
00891   return archive.ReadArray(m_value);
00892 }
00893 
00894 // virtual 
00895 bool ON_StringValue::WriteHelper(ON_BinaryArchive& archive ) const
00896 {
00897   return archive.WriteArray(m_value);
00898 }
00899 
00900 // virtual 
00901 bool ON_StringValue::ReportHelper(ON_TextLog& text_log ) const
00902 {
00903   text_log.Print("string value\n");
00904   text_log.PushIndent();
00905   int i, count = m_value.Count();
00906   for ( i = 0; i < count; i++ )
00907   {
00908     text_log.Print(m_value[i]);
00909   }
00910   text_log.PopIndent();
00911   return true;
00912 }
00913 
00914 // virtual 
00915 int ON_StringValue::GetStrings( ON_ClassArray<ON_wString>& s ) const
00916 {
00917   s = m_value;
00918   return m_value.Count();
00919 }
00920 
00921 
00923 //
00924 // ON_ObjRefValue saves objref values in the ON_HistoryRecord::m_value[] array
00925 //
00926 
00927 class ON_ObjRefValue : public ON_Value
00928 {
00929 public:
00930   ON_ObjRefValue();
00931   ~ON_ObjRefValue();
00932 
00933   ON_ClassArray<ON_ObjRef> m_value;
00934 
00935   // virtual 
00936   class ON_Value* Duplicate() const;
00937 
00938   // virtual
00939   int Count() const;
00940 
00941   // virtual 
00942   bool ReadHelper(ON_BinaryArchive& archive );
00943 
00944   // virtual 
00945   bool WriteHelper(ON_BinaryArchive& archive ) const;
00946 
00947   // virtual 
00948   bool ReportHelper(ON_TextLog& text_log ) const;
00949 
00950   // virtual 
00951   int GetObjRefs( ON_ClassArray<ON_ObjRef>& oref ) const;
00952 };
00953 
00954 ON_ObjRefValue::ON_ObjRefValue() 
00955              : ON_Value(ON_Value::objref_value) 
00956 {
00957 }
00958 
00959 ON_ObjRefValue::~ON_ObjRefValue()
00960 {
00961 }
00962 
00963 // virtual 
00964 class ON_Value* ON_ObjRefValue::Duplicate() const
00965 {
00966   return new ON_ObjRefValue(*this);
00967 }
00968 
00969 // virtual
00970 int ON_ObjRefValue::Count() const 
00971 {
00972   return m_value.Count();
00973 }
00974 
00975 // virtual 
00976 bool ON_ObjRefValue::ReadHelper(ON_BinaryArchive& archive )
00977 {
00978   return archive.ReadArray(m_value);
00979 }
00980 
00981 // virtual 
00982 bool ON_ObjRefValue::WriteHelper(ON_BinaryArchive& archive ) const
00983 {
00984   return archive.WriteArray(m_value);
00985 }
00986 
00987 // virtual 
00988 bool ON_ObjRefValue::ReportHelper(ON_TextLog& text_log ) const
00989 {
00990   text_log.Print("objref value\n");
00991   text_log.PushIndent();
00992   int i, count = m_value.Count();
00993   for ( i = 0; i < count; i++ )
00994   {
00995     text_log.Print("object id: ");
00996     text_log.Print(m_value[i].m_uuid);
00997     text_log.Print("\n");
00998   }
00999   text_log.PopIndent();
01000   return true;
01001 }
01002 
01003 // virtual 
01004 int ON_ObjRefValue::GetObjRefs( ON_ClassArray<ON_ObjRef>& s ) const
01005 {
01006   s = m_value;
01007   return m_value.Count();
01008 }
01009 
01010 
01012 //
01013 // ON_GeometryValue saves geometry values in the ON_HistoryRecord::m_value[] array
01014 //
01015 
01016 class ON_GeometryValue : public ON_Value
01017 {
01018 public:
01019   ON_GeometryValue();
01020   ~ON_GeometryValue();
01021   ON_GeometryValue(const ON_GeometryValue& src);
01022   ON_GeometryValue& operator=(const ON_GeometryValue& src);
01023 
01024   ON_SimpleArray<ON_Geometry*> m_value;
01025 
01026   // virtual 
01027   class ON_Value* Duplicate() const;
01028 
01029   // virtual
01030   int Count() const;
01031 
01032   // virtual 
01033   bool ReadHelper(ON_BinaryArchive& archive );
01034 
01035   // virtual 
01036   bool WriteHelper(ON_BinaryArchive& archive ) const;
01037 
01038   // virtual 
01039   bool ReportHelper(ON_TextLog& text_log ) const;
01040 
01041   // virtual 
01042   int GetGeometryPointers( const ON_Geometry* const*& ) const;
01043 };
01044 
01045 ON_GeometryValue::ON_GeometryValue() 
01046              : ON_Value(ON_Value::geometry_value) 
01047 {
01048 }
01049 
01050 ON_GeometryValue::~ON_GeometryValue()
01051 {
01052   int i, count = m_value.Count();
01053   for ( i = 0; i < count; i++ )
01054   {
01055     ON_Geometry* p = m_value[i];
01056     m_value[i] = 0;
01057     if (p)
01058     {
01059       delete p;
01060     }
01061   }
01062 }
01063 
01064 ON_GeometryValue::ON_GeometryValue(const ON_GeometryValue& src) : ON_Value(src)
01065 {
01066   *this = src;
01067 }
01068 
01069 ON_GeometryValue& ON_GeometryValue::operator=(const ON_GeometryValue& src)
01070 {
01071   if ( this != &src )
01072   {
01073     int i, count = m_value.Count();
01074     for ( i = 0; i < count; i++ )
01075     {
01076       ON_Geometry* p = m_value[i];
01077       m_value[i] = 0;
01078       if (p)
01079       {
01080         delete p;
01081       }
01082     }
01083     m_value.Destroy();
01084 
01085     m_value_id = src.m_value_id;
01086 
01087     count = src.m_value.Count();
01088     m_value.Reserve(count);
01089     for ( i = 0; i < count; i++ )
01090     {
01091       const ON_Geometry* src_ptr = src.m_value[i];
01092       if ( !src_ptr )
01093         continue;
01094       ON_Geometry* ptr = src_ptr->Duplicate();
01095       if ( ptr )
01096         m_value.Append(ptr);
01097     }
01098   }
01099   return *this;
01100 }
01101 
01102 // virtual 
01103 class ON_Value* ON_GeometryValue::Duplicate() const
01104 {
01105   return new ON_GeometryValue(*this);
01106 }
01107 
01108 // virtual
01109 int ON_GeometryValue::Count() const 
01110 {
01111   return m_value.Count();
01112 }
01113 
01114 // virtual 
01115 bool ON_GeometryValue::ReadHelper(ON_BinaryArchive& archive )
01116 {
01117   int i, count = m_value.Count();
01118   for ( i = 0; i < count; i++ )
01119   {
01120     delete m_value[i];
01121   }
01122   m_value.SetCount(0);
01123 
01124   int major_version = 0;
01125   int minor_version = 0;
01126   bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
01127   if (!rc)
01128     return false;
01129 
01130   for(;;)
01131   {
01132     rc = archive.ReadInt(&count);
01133     if (!rc) break;
01134     m_value.Reserve(count);
01135     
01136     for( i = 0; i < count && rc; i++ )
01137     {
01138       ON_Object* p=0;
01139       rc = archive.ReadObject(&p) > 0;
01140       if (rc)
01141       {
01142         ON_Geometry* g = ON_Geometry::Cast(p);
01143         if (g)
01144         {
01145           p = 0;
01146           m_value.Append(g);
01147         }
01148       }
01149       if ( p )
01150         delete p;
01151     }
01152     if (!rc) break;
01153 
01154     break;
01155   }
01156 
01157   if ( !archive.EndRead3dmChunk() )
01158     rc = false;
01159   return rc;
01160 }
01161 
01162 // virtual 
01163 bool ON_GeometryValue::WriteHelper(ON_BinaryArchive& archive ) const
01164 {
01165   bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
01166   if (!rc)
01167     return false;
01168 
01169   for(;;)
01170   {
01171     rc = archive.WriteInt(m_value.Count());
01172     if (!rc) break;
01173     
01174     int i, count = m_value.Count();
01175     for( i = 0; i < count && rc; i++ )
01176     {
01177       rc = archive.WriteObject(m_value[i]);
01178     }
01179     if (!rc) break;
01180 
01181     break;
01182   }
01183 
01184   if ( !archive.EndWrite3dmChunk() )
01185     rc = false;
01186   return rc;
01187 }
01188 
01189 // virtual 
01190 bool ON_GeometryValue::ReportHelper(ON_TextLog& text_log ) const
01191 {
01192   text_log.Print("geometry value\n");
01193   text_log.PushIndent();
01194   int i, count = m_value.Count();
01195   for ( i = 0; i < count; i++ )
01196   {
01197     const ON_Geometry* p = m_value[i];
01198     if ( p )
01199       p->Dump(text_log);
01200   }
01201   text_log.PopIndent();
01202   return true;
01203 }
01204 
01205 // virtual 
01206 int ON_GeometryValue::GetGeometryPointers( const ON_Geometry* const*&a ) const
01207 {
01208   a = m_value.Array();
01209   return m_value.Count();
01210 }
01211 
01212 
01214 //
01215 // ON_PolyEdgeHistoryValue saves geometry values in the ON_HistoryRecord::m_value[] array
01216 //
01217 
01218 class ON_PolyEdgeHistoryValue : public ON_Value
01219 {
01220 public:
01221   ON_PolyEdgeHistoryValue();
01222   ~ON_PolyEdgeHistoryValue();
01223 
01224   ON_ClassArray<ON_PolyEdgeHistory> m_value;
01225 
01226   // virtual 
01227   class ON_Value* Duplicate() const;
01228 
01229   // virtual
01230   int Count() const;
01231 
01232   // virtual 
01233   bool ReadHelper(ON_BinaryArchive& archive );
01234 
01235   // virtual 
01236   bool WriteHelper(ON_BinaryArchive& archive ) const;
01237 
01238   // virtual 
01239   bool ReportHelper(ON_TextLog& text_log ) const;
01240 
01241   // virtual 
01242   int  GetPolyEdgePointers( ON_ClassArray<ON_PolyEdgeHistory>& ) const;
01243 };
01244 
01245 ON_PolyEdgeHistoryValue::ON_PolyEdgeHistoryValue() 
01246              : ON_Value(ON_Value::polyedge_value) 
01247 {
01248 }
01249 
01250 ON_PolyEdgeHistoryValue::~ON_PolyEdgeHistoryValue()
01251 {
01252   m_value.Destroy();
01253 }
01254 
01255 //ON_PolyEdgeHistoryValue::ON_PolyEdgeHistoryValue(const ON_PolyEdgeHistoryValue& src) : ON_Value(src)
01256 //{
01257 //  *this = src;
01258 //}
01259 //
01260 //ON_PolyEdgeHistoryValue& ON_PolyEdgeHistoryValue::operator=(const ON_PolyEdgeHistoryValue& src)
01261 //{
01262 //  if ( this != &src )
01263 //  {
01264 //    int i, count = m_value.Count();
01265 //    for ( i = 0; i < count; i++ )
01266 //    {
01267 //      ON_Geometry* p = m_value[i];
01268 //      m_value[i] = 0;
01269 //      if (p)
01270 //      {
01271 //        delete p;
01272 //      }
01273 //    }
01274 //    m_value.Destroy();
01275 //
01276 //    m_value_id = src.m_value_id;
01277 //
01278 //    count = src.m_value.Count();
01279 //    m_value.Reserve(count);
01280 //    for ( i = 0; i < count; i++ )
01281 //    {
01282 //      const ON_Geometry* src_ptr = src.m_value[i];
01283 //      if ( !src_ptr )
01284 //        continue;
01285 //      ON_Geometry* ptr = src_ptr->Duplicate();
01286 //      if ( ptr )
01287 //        m_value.Append(ptr);
01288 //    }
01289 //  }
01290 //  return *this;
01291 //}
01292 
01293 // virtual 
01294 class ON_Value* ON_PolyEdgeHistoryValue::Duplicate() const
01295 {
01296   return new ON_PolyEdgeHistoryValue(*this);
01297 }
01298 
01299 // virtual
01300 int ON_PolyEdgeHistoryValue::Count() const 
01301 {
01302   return m_value.Count();
01303 }
01304 
01305 // virtual 
01306 bool ON_PolyEdgeHistoryValue::ReadHelper(ON_BinaryArchive& archive )
01307 {
01308   m_value.Destroy();
01309 
01310   int major_version = 0;
01311   int minor_version = 0;
01312   bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
01313   if (!rc)
01314     return false;
01315 
01316   for(;;)
01317   {
01318     int count = 0;
01319     rc = archive.ReadInt(&count);
01320     if (!rc) break;
01321     m_value.Reserve(count);
01322     
01323     for( int i = 0; i < count && rc; i++ )
01324     {
01325       if ( !m_value.AppendNew().Read(archive) )
01326       {
01327         m_value.Destroy();
01328         rc = false;
01329         break;
01330       }
01331     }
01332     if (!rc) break;
01333 
01334     break;
01335   }
01336 
01337   if ( !archive.EndRead3dmChunk() )
01338     rc = false;
01339   return rc;
01340 }
01341 
01342 // virtual 
01343 bool ON_PolyEdgeHistoryValue::WriteHelper(ON_BinaryArchive& archive ) const
01344 {
01345   bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
01346   if (!rc)
01347     return false;
01348 
01349   for(;;)
01350   {
01351     rc = archive.WriteInt(m_value.Count());
01352     if (!rc) break;
01353     
01354     int i, count = m_value.Count();
01355     for( i = 0; i < count && rc; i++ )
01356     {
01357       rc = m_value[i].Write(archive);
01358     }
01359     if (!rc) break;
01360 
01361     break;
01362   }
01363 
01364   if ( !archive.EndWrite3dmChunk() )
01365     rc = false;
01366   return rc;
01367 }
01368 
01369 // virtual 
01370 bool ON_PolyEdgeHistoryValue::ReportHelper(ON_TextLog& text_log ) const
01371 {
01372   text_log.Print("polyedge value\n");
01373   text_log.PushIndent();
01374   int i, count = m_value.Count();
01375   for ( i = 0; i < count; i++ )
01376   {
01377     m_value[i].Dump(text_log);
01378   }
01379   text_log.PopIndent();
01380   return true;
01381 }
01382 
01383 // virtual 
01384 int ON_PolyEdgeHistoryValue::GetPolyEdgePointers( ON_ClassArray<ON_PolyEdgeHistory>& a ) const
01385 {
01386   a = m_value;
01387   return m_value.Count();
01388 }
01389 
01391 //
01392 
01393 // static
01394 ON_Value* ON_Value::CreateValue( int value_type )
01395 {
01396   ON_Value* value = 0;
01397   switch((unsigned int)value_type)
01398   {
01399   case no_value_type:
01400     break;
01401   case bool_value:
01402     value = new ON_BoolValue();
01403     break;
01404   case int_value:
01405     value = new ON_IntValue();
01406     break;
01407   case double_value:
01408     value = new ON_DoubleValue();
01409     break;
01410   case color_value:
01411     value = new ON_ColorValue();
01412     break;
01413   case point_value:
01414     value = new ON_PointValue();
01415     break;
01416   case vector_value:
01417     value = new ON_VectorValue();
01418     break;
01419   case xform_value:
01420     value = new ON_XformValue();
01421     break;
01422   case string_value:
01423     value = new ON_StringValue();
01424     break;
01425   case objref_value:
01426     value = new ON_ObjRefValue();
01427     break;
01428   case geometry_value:
01429     value = new ON_PolyEdgeHistoryValue();
01430     break;
01431   case uuid_value:
01432     value = new ON_UuidValue();
01433     break;
01434   case point_on_object_value:
01435     //value = new ON_PointOnObjectValue();
01436     break;
01437   case polyedge_value:
01438     value = new ON_PolyEdgeHistoryValue();
01439     break;
01440   case force_32bit_enum:
01441     break;
01442   default:
01443     break;
01444   }
01445   return value;
01446 }
01447 
01449 //
01450 // ON_HistoryRecord implementation
01451 //
01452 
01453 ON_OBJECT_IMPLEMENT(ON_HistoryRecord,ON_Object,"ECD0FD2F-2088-49dc-9641-9CF7A28FFA6B");
01454 
01455 ON_HistoryRecord::ON_HistoryRecord() 
01456                  : m_antecedents(2),
01457                    m_descendants(1)                   
01458 {
01459   m_command_id    = ON_nil_uuid;
01460   m_version       = 0;
01461   m_record_type   = history_parameters;
01462   m_record_id     = ON_nil_uuid;
01463   m_bValuesSorted = true;
01464 }
01465 
01466 ON_HistoryRecord::~ON_HistoryRecord()
01467 {
01468   int i, count = m_value.Count();
01469   m_value.SetCount(0);
01470   for ( i = 0; i < count; i++ )
01471   {
01472     ON_Value* v = m_value[i];
01473     if ( v )
01474       delete v;
01475   }
01476 }
01477 
01478 void  ON_HistoryRecord::CopyHelper(const ON_HistoryRecord& src)
01479 {
01480   // input value of this->m_value[] is known to be empty
01481   m_command_id   = src.m_command_id;
01482   m_version      = src.m_version;
01483   m_record_type  = src.m_record_type;
01484   m_record_id    = src.m_record_id;
01485   m_descendants  = src.m_descendants;
01486   m_antecedents  = src.m_antecedents;
01487   m_bValuesSorted = true;
01488 
01489   int i, count = src.m_value.Count();
01490   m_value.SetCapacity(count);
01491   const ON_Value* prev_v = 0;
01492   for ( i = 0; i < count; i++ )
01493   {
01494     const ON_Value* src_v = src.m_value[i];
01495     if ( src_v )
01496     {
01497       ON_Value* v = src_v->Duplicate();
01498       if ( v )
01499       {
01500         m_value.Append(v);
01501         if ( m_bValuesSorted && prev_v && prev_v->m_value_id > v->m_value_id )
01502           m_bValuesSorted = false;
01503         prev_v = v;
01504       }
01505     }
01506   }
01507 }
01508 
01509 ON_HistoryRecord::ON_HistoryRecord(const ON_HistoryRecord& src) : ON_Object(src)
01510 {
01511   CopyHelper(src);
01512 }
01513 
01514 ON_HistoryRecord& ON_HistoryRecord::operator=(const ON_HistoryRecord& src)
01515 {
01516   if ( this != &src )
01517   {
01518     Destroy();
01519     ON_Object::operator =(src);
01520     CopyHelper(src);
01521   }
01522   return *this;
01523 }
01524 
01525 ON_BOOL32 ON_HistoryRecord::IsValid( ON_TextLog* text_log ) const
01526 {
01527   return true;
01528 }
01529 
01530 void ON_HistoryRecord::Destroy()
01531 {
01532   int i, count = m_value.Count();
01533   for ( i = 0; i < count; i++ )
01534   {
01535     ON_Value* v = m_value[i];
01536     m_value[i] = 0;
01537     if (v)
01538       delete v;
01539   }
01540   m_value.SetCount(0);
01541   m_record_id = ON_nil_uuid;
01542   m_record_type = ON_HistoryRecord::history_parameters;
01543   m_version = 0;
01544   m_command_id = ON_nil_uuid;
01545   m_antecedents.Empty();
01546   m_descendants.Empty();
01547 }
01548 
01549 ON_HistoryRecord::RECORD_TYPE ON_HistoryRecord::RecordType(int i)
01550 {
01551   RECORD_TYPE rc = ( ON_HistoryRecord::feature_parameters == i )
01552                  ? ON_HistoryRecord::feature_parameters
01553                  : ON_HistoryRecord::history_parameters;
01554   return rc;
01555 }
01556 
01557 bool ON_HistoryRecord::SetBoolValue( int value_id, bool b)
01558 {
01559   return ( 1 == SetBoolValues(value_id, 1, &b) );
01560 }
01561 
01562 bool ON_HistoryRecord::SetIntValue( int value_id, int i)
01563 {
01564   return ( 1 == SetIntValues(value_id, 1, &i) );
01565 }
01566 
01567 bool ON_HistoryRecord::SetDoubleValue( int value_id, double x)
01568 {
01569   return ( 1 == SetDoubleValues(value_id, 1, &x) );
01570 }
01571 
01572 bool ON_HistoryRecord::SetPointValue( int value_id, ON_3dPoint p)
01573 {
01574   return ( 1 == SetPointValues(value_id, 1, &p) );
01575 }
01576 
01577 bool ON_HistoryRecord::SetVectorValue( int value_id, ON_3dVector v)
01578 {
01579   return ( 1 == SetVectorValues(value_id, 1, &v) );
01580 }
01581 
01582 bool ON_HistoryRecord::SetXformValue( int value_id, ON_Xform xform)
01583 {
01584   return ( 1 == SetXformValues(value_id, 1, &xform) );
01585 }
01586 
01587 bool ON_HistoryRecord::SetColorValue( int value_id, ON_Color c)
01588 {
01589   return ( 1 == SetColorValues(value_id, 1, &c) );
01590 }
01591 
01592 bool ON_HistoryRecord::SetObjRefValue( int value_id, const ON_ObjRef& oref)
01593 {
01594   return ( 1 == SetObjRefValues(value_id, 1, &oref) );
01595 }
01596 
01597 bool ON_HistoryRecord::SetPointOnObjectValue( int value_id, const ON_ObjRef& oref, ON_3dPoint point )
01598 {
01599   ON_ObjRef poo = oref;
01600   poo.m_point = point;
01601   return SetObjRefValue(value_id,poo);
01602 }
01603 
01604 bool ON_HistoryRecord::GetPointOnObjectValue( int value_id, ON_ObjRef& oref ) const
01605 {
01606   bool rc = GetObjRefValue(value_id,oref);
01607   return (rc && oref.m_point.IsValid());
01608 }
01609 
01610 bool ON_HistoryRecord::SetGeometryValue( int value_id, ON_Geometry* g)
01611 {
01612   ON_SimpleArray<ON_Geometry*> a(1);
01613   a.Append(g);
01614   return ( 1 == SetGeometryValues(value_id, a) );
01615 }
01616 
01617 bool ON_HistoryRecord::SetPolyEdgeValue( int value_id, const ON_PolyEdgeHistory& polyedge )
01618 {
01619   return ( 1 == SetPolyEdgeValues(value_id, 1, &polyedge) );
01620 }
01621 
01622 bool ON_HistoryRecord::SetUuidValue( int value_id, ON_UUID uuid )
01623 {
01624   return ( 1 == SetUuidValues(value_id, 1, &uuid) );
01625 }
01626 
01627 static
01628 int CompareValueIdHelper(const ON_Value* a, const ON_Value* b )
01629 {
01630   if (!a)
01631   {
01632     return b ? -1 : 0;
01633   }
01634   if (!b)
01635   {
01636     return 1;
01637   }
01638   return (a->m_value_id - b->m_value_id);
01639 }
01640 
01641 static int CompareValueId( ON_Value * const * a, ON_Value * const * b )
01642 {
01643   // handle NULLs in case somebody messes up the m_value[] array.
01644   if ( !a )
01645   {
01646     return b ? -1 : 0;
01647   }
01648   if (!b)
01649     return 1;
01650 
01651   return CompareValueIdHelper(*a,*b);
01652 }
01653 
01654 ON_Value* ON_HistoryRecord::FindValueHelper( int value_id, int value_type, bool bCreateOne ) const
01655 {
01656   ON_HistoryRecord* vp = const_cast<ON_HistoryRecord*>(this);
01657   if ( m_value.Count() > 0 )
01658   {
01659     if ( !m_bValuesSorted )
01660     {
01661       vp->m_value.QuickSort(CompareValueId);
01662       vp->m_bValuesSorted = true;
01663     }
01664 
01665     ON_DummyValue dummy_value;
01666     dummy_value.m_value_id = value_id;
01667     ON_Value* p = &dummy_value;
01668     int i = m_value.BinarySearch(&p,CompareValueId);
01669 
01670     if ( i >= 0 )
01671     {
01672       // m_value[i]->m_value_id == value_id
01673 
01674       if ( value_type == ((int)m_value[i]->m_value_type) )
01675       {
01676         // type matches
01677         return m_value[i];
01678       }
01679 
01680       if ( bCreateOne )
01681       {
01682         // type does not match - replace the existing one
01683         ON_Value* new_value = ON_Value::CreateValue(value_type);
01684         if ( new_value )
01685         {
01686           new_value->m_value_id = value_id;
01687           delete m_value[i];
01688           vp->m_value[i] = new_value;
01689           return new_value;
01690         }
01691       }
01692     }
01693     else if ( bCreateOne )
01694     {
01695       // no value in m_value[] array with a matching value_id
01696       ON_Value* new_value = ON_Value::CreateValue(value_type);
01697       if ( new_value )
01698       {
01699         new_value->m_value_id = value_id;
01700         if ( m_bValuesSorted && (*m_value.Last())->m_value_id > value_id )
01701           vp->m_bValuesSorted = false;
01702         vp->m_value.Append(new_value);
01703         return new_value;
01704       }
01705     }
01706   }
01707   else if ( bCreateOne )
01708   {
01709     ON_Value* new_value = ON_Value::CreateValue(value_type);
01710     if ( new_value )
01711     {
01712       new_value->m_value_id = value_id;
01713       vp->m_bValuesSorted = true;
01714       vp->m_value.Append(new_value);
01715       return new_value;
01716     }
01717   }
01718   return 0;
01719 }
01720 
01721 
01722 bool ON_HistoryRecord::SetBoolValues( int value_id, int count, const bool* b)
01723 {
01724   ON_BoolValue* v = static_cast<ON_BoolValue*>(FindValueHelper(value_id,ON_Value::bool_value,true));
01725   if ( v )
01726   {
01727     v->m_value.SetCount(0);
01728     v->m_value.SetCapacity(count);
01729     v->m_value.Append(count,b);
01730   }
01731   return (0 != v);
01732 }
01733 
01734 bool ON_HistoryRecord::SetIntValues( int value_id, int count, const int* i)
01735 {
01736   ON_IntValue* v = static_cast<ON_IntValue*>(FindValueHelper(value_id,ON_Value::int_value,true));
01737   if ( v )
01738   {
01739     v->m_value.SetCount(0);
01740     v->m_value.SetCapacity(count);
01741     v->m_value.Append(count,i);
01742   }
01743   return (0 != v);
01744 }
01745 
01746 bool ON_HistoryRecord::SetDoubleValues( int value_id, int count, const double* x)
01747 {
01748   ON_DoubleValue* v = static_cast<ON_DoubleValue*>(FindValueHelper(value_id,ON_Value::double_value,true));
01749   if ( v )
01750   {
01751     v->m_value.SetCount(0);
01752     v->m_value.SetCapacity(count);
01753     v->m_value.Append(count,x);
01754   }
01755   return (0 != v);
01756 }
01757 
01758 bool ON_HistoryRecord::SetPointValues( int value_id, int count, const ON_3dPoint* P)
01759 {
01760   ON_PointValue* v = static_cast<ON_PointValue*>(FindValueHelper(value_id,ON_Value::point_value,true));
01761   if ( v )
01762   {
01763     v->m_value.SetCount(0);
01764     v->m_value.SetCapacity(count);
01765     v->m_value.Append(count,P);
01766   }
01767   return (0 != v);
01768 }
01769 
01770 bool ON_HistoryRecord::SetVectorValues( int value_id, int count, const ON_3dVector* V)
01771 {
01772   ON_VectorValue* v = static_cast<ON_VectorValue*>(FindValueHelper(value_id,ON_Value::vector_value,true));
01773   if ( v )
01774   {
01775     v->m_value.SetCount(0);
01776     v->m_value.SetCapacity(count);
01777     v->m_value.Append(count,V);
01778   }
01779   return (0 != v);
01780 }
01781 
01782 bool ON_HistoryRecord::SetXformValues( int value_id, int count, const ON_Xform* xform)
01783 {
01784   ON_XformValue* v = static_cast<ON_XformValue*>(FindValueHelper(value_id,ON_Value::xform_value,true));
01785   if ( v )
01786   {
01787     v->m_value.SetCount(0);
01788     v->m_value.SetCapacity(count);
01789     v->m_value.Append(count,xform);
01790   }
01791   return (0 != v);
01792 }
01793 
01794 bool ON_HistoryRecord::SetColorValues( int value_id, int count, const ON_Color* c)
01795 {
01796   ON_ColorValue* v = static_cast<ON_ColorValue*>(FindValueHelper(value_id,ON_Value::color_value,true));
01797   if ( v )
01798   {
01799     v->m_value.SetCount(0);
01800     v->m_value.SetCapacity(count);
01801     v->m_value.Append(count,c);
01802   }
01803   return (0 != v);
01804 }
01805 
01806 bool ON_HistoryRecord::SetUuidValues( int value_id, int count, const ON_UUID* u )
01807 {
01808   ON_UuidValue* v = static_cast<ON_UuidValue*>(FindValueHelper(value_id,ON_Value::uuid_value,true));
01809   if ( v )
01810   {
01811     v->m_value.SetCount(0);
01812     v->m_value.SetCapacity(count);
01813     v->m_value.Append(count,u);
01814   }
01815   return (0 != v);
01816 }
01817 
01818 bool ON_HistoryRecord::SetStringValues( int value_id, int count, const wchar_t* const* s )
01819 {
01820   ON_StringValue* v = static_cast<ON_StringValue*>(FindValueHelper(value_id,ON_Value::string_value,true));
01821   if ( v )
01822   {
01823     v->m_value.Destroy();
01824     v->m_value.Reserve(count);
01825     int i;
01826     for( i = 0; i < count; i++ )
01827     {
01828       v->m_value.AppendNew() = s[i];
01829     }
01830   }
01831   return (0 != v);
01832 }
01833 
01834 bool ON_HistoryRecord::SetStringValues( int value_id, const ON_ClassArray<ON_wString>& s )
01835 {
01836   ON_StringValue* v = static_cast<ON_StringValue*>(FindValueHelper(value_id,ON_Value::string_value,true));
01837   if ( v )
01838   {
01839     v->m_value = s;
01840   }
01841   return (0 != v);
01842 }
01843 
01844 bool ON_HistoryRecord::SetStringValue( int value_id, const wchar_t* s )
01845 {
01846   ON_StringValue* v = static_cast<ON_StringValue*>(FindValueHelper(value_id,ON_Value::string_value,true));
01847   if ( v )
01848   {
01849     v->m_value.Destroy();
01850     v->m_value.AppendNew() = s;
01851   }
01852   return (0 != v);
01853 }
01854 
01855 
01856 bool ON_HistoryRecord::SetObjRefValues( int value_id, int count, const ON_ObjRef* oref)
01857 {
01858   ON_ObjRefValue* v = static_cast<ON_ObjRefValue*>(FindValueHelper(value_id,ON_Value::objref_value,true));
01859   if ( v )
01860   {
01861     v->m_value.Destroy();
01862     v->m_value.Reserve(count);
01863     int i;
01864     for ( i = 0; i < count; i++ )
01865     {
01866       // The call to DecrementProxyReferenceCount() is critical.
01867       // It makes sure there are no active runtime pointers 
01868       // saved in the history record.  If this call is not here,
01869       // you will eventually crash and history update will never
01870       // work right even when it doesn't crash.
01871       ON_ObjRef& vor = v->m_value.AppendNew();
01872       vor = oref[i];
01873       vor.DecrementProxyReferenceCount();
01874       // Feb 12 2010 - Fixing bug in ExtrudeCrv history
01875       //  and probably lots of other subtle history bugs.
01876       //  History must lookup by UUID and not by runtime serial number.
01877       vor.m_runtime_sn = 0; 
01878       ON_UUID object_id = v->m_value[i].m_uuid;
01879       if ( !ON_UuidIsNil(object_id) )
01880       {
01881         m_antecedents.AddUuid(object_id);
01882       }
01883     }
01884   }
01885   return (0 != v);
01886 }
01887 
01888 
01889 bool ON_HistoryRecord::SetGeometryValues( int value_id, const ON_SimpleArray<ON_Geometry*> a)
01890 {
01891   ON_GeometryValue* v = static_cast<ON_GeometryValue*>(FindValueHelper(value_id,ON_Value::geometry_value,true));
01892   if ( v )
01893   {
01894     v->m_value = a;
01895   }
01896   return (0 != v);
01897 }
01898 
01899 bool ON_HistoryRecord::SetPolyEdgeValues( int value_id,  int count, const ON_PolyEdgeHistory* a )
01900 {
01901   ON_PolyEdgeHistoryValue* v = static_cast<ON_PolyEdgeHistoryValue*>(FindValueHelper(value_id,ON_Value::polyedge_value,true));
01902   if ( v )
01903   {
01904     v->m_value.Destroy();
01905     v->m_value.Append(count,a);
01906 
01907     for ( int i = 0; i < count; i++ )
01908     {
01909       const ON_PolyEdgeHistory& pe_history = a[i];
01910       for ( int j = 0; j < pe_history.m_segment.Count(); j++ )
01911       {
01912         const ON_CurveProxyHistory& segment = pe_history.m_segment[j];
01913         m_antecedents.AddUuid(segment.m_curve_ref.m_uuid);
01914       }
01915     }
01916   }
01917   return (0 != v);
01918 }
01919 
01920 bool ON_HistoryRecord::GetBoolValue( int value_id, bool* b ) const
01921 {
01922   bool rc = false;
01923   const ON_BoolValue* v = static_cast<ON_BoolValue*>(FindValueHelper(value_id,ON_Value::bool_value,0));
01924   if ( v && 1 == v->m_value.Count())
01925   {
01926     *b = v->m_value[0];
01927     rc = true;
01928   }
01929   return rc;
01930 }
01931 
01932 bool ON_HistoryRecord::GetIntValue( int value_id, int* i ) const
01933 {
01934   bool rc = false;
01935   const ON_IntValue* v = static_cast<ON_IntValue*>(FindValueHelper(value_id,ON_Value::int_value,0));
01936   if ( v && 1 == v->m_value.Count())
01937   {
01938     *i = v->m_value[0];
01939     rc = true;
01940   }
01941   return rc;
01942 }
01943 
01944 bool ON_HistoryRecord::GetDoubleValue( int value_id, double* number ) const
01945 {
01946   bool rc = false;
01947   const ON_DoubleValue* v = static_cast<ON_DoubleValue*>(FindValueHelper(value_id,ON_Value::double_value,0));
01948   if ( v && 1 == v->m_value.Count())
01949   {
01950     *number = v->m_value[0];
01951     rc = true;
01952   }
01953   return rc;
01954 }
01955 
01956 bool ON_HistoryRecord::GetPointValue( int value_id, ON_3dPoint& point ) const
01957 {
01958   bool rc = false;
01959   const ON_PointValue* v = static_cast<ON_PointValue*>(FindValueHelper(value_id,ON_Value::point_value,0));
01960   if ( v && 1 == v->m_value.Count())
01961   {
01962     point = v->m_value[0];
01963     rc = true;
01964   }
01965   return rc;
01966 }
01967 
01968 bool ON_HistoryRecord::GetVectorValue( int value_id, ON_3dVector& vector ) const
01969 {
01970   bool rc = false;
01971   const ON_VectorValue* v = static_cast<ON_VectorValue*>(FindValueHelper(value_id,ON_Value::vector_value,0));
01972   if ( v && 1 == v->m_value.Count())
01973   {
01974     vector = v->m_value[0];
01975     rc = true;
01976   }
01977   return rc;
01978 }
01979 
01980 bool ON_HistoryRecord::GetXformValue( int value_id, ON_Xform& xform ) const
01981 {
01982   bool rc = false;
01983   const ON_XformValue* v = static_cast<ON_XformValue*>(FindValueHelper(value_id,ON_Value::xform_value,0));
01984   if ( v && 1 == v->m_value.Count())
01985   {
01986     xform = v->m_value[0];
01987     rc = true;
01988   }
01989   return rc;
01990 }
01991 
01992 bool ON_HistoryRecord::GetColorValue( int value_id, ON_Color* color ) const
01993 {
01994   bool rc = false;
01995   const ON_ColorValue* v = static_cast<ON_ColorValue*>(FindValueHelper(value_id,ON_Value::color_value,0));
01996   if ( v && 1 == v->m_value.Count())
01997   {
01998     *color = v->m_value[0];
01999     rc = true;
02000   }
02001   return rc;
02002 }
02003 
02004 bool ON_HistoryRecord::GetObjRefValue( int value_id, ON_ObjRef& oref ) const
02005 {
02006   bool rc = false;
02007   const ON_ObjRefValue* v = static_cast<ON_ObjRefValue*>(FindValueHelper(value_id,ON_Value::objref_value,0));
02008   if ( v && 1 == v->m_value.Count())
02009   {
02010     oref = v->m_value[0];
02011     rc = true;
02012   }
02013   return rc;
02014 }
02015 
02016 bool ON_HistoryRecord::GetStringValue( int value_id, ON_wString& str ) const
02017 {
02018   bool rc = false;
02019   ON_StringValue* v = static_cast<ON_StringValue*>(FindValueHelper(value_id,ON_Value::string_value,0));
02020   if ( v && 1 == v->m_value.Count())
02021   {
02022     str = v->m_value[0];
02023     rc = true;
02024   }
02025   return rc;
02026 }
02027 
02028 bool ON_HistoryRecord::GetGeometryValue( int value_id, const ON_Geometry*& g ) const
02029 {
02030   bool rc = false;
02031   g = 0;
02032   const ON_GeometryValue* v = static_cast<ON_GeometryValue*>(FindValueHelper(value_id,ON_Value::geometry_value,0));
02033   if ( v && 1 == v->m_value.Count())
02034   {
02035     g = v->m_value[0];
02036     rc = true;
02037   }
02038   return rc;
02039 }
02040 
02041 bool ON_HistoryRecord::GetPolyEdgeValue( int value_id, const ON_PolyEdgeHistory*& polyedge ) const
02042 {
02043   bool rc = false;
02044   polyedge = 0;
02045   const ON_PolyEdgeHistoryValue* v = static_cast<ON_PolyEdgeHistoryValue*>(FindValueHelper(value_id,ON_Value::polyedge_value,0));
02046   if ( v && 1 == v->m_value.Count())
02047   {
02048     polyedge = &v->m_value[0];
02049     rc = true;
02050   }
02051   return rc;
02052 }
02053 
02054 bool ON_HistoryRecord::GetCurveValue( int value_id, const ON_Curve*& c ) const
02055 {
02056   c = 0;
02057   const ON_Geometry* g = 0;
02058   if (GetGeometryValue( value_id, g ))
02059   {
02060     c = ON_Curve::Cast(g);
02061   }
02062   return (0 != c);
02063 }
02064 
02065 bool ON_HistoryRecord::GetSurfaceValue( int value_id, const ON_Surface*& s ) const
02066 {
02067   s = 0;
02068   const ON_Geometry* g = 0;
02069   if (GetGeometryValue( value_id, g ))
02070   {
02071     s = ON_Surface::Cast(g);
02072   }
02073   return (0 != s);
02074 }
02075 
02076 bool ON_HistoryRecord::GetBrepValue( int value_id, const ON_Brep*& b ) const
02077 {
02078   b = 0;
02079   const ON_Geometry* g = 0;
02080   if (GetGeometryValue( value_id, g ))
02081   {
02082     b = ON_Brep::Cast(g);
02083   }
02084   return (0 != b);
02085 }
02086 
02087 bool ON_HistoryRecord::GetMeshValue( int value_id, const ON_Mesh*& m ) const
02088 {
02089   m = 0;
02090   const ON_Geometry* g = 0;
02091   if (GetGeometryValue( value_id, g ))
02092   {
02093     m = ON_Mesh::Cast(g);
02094   }
02095   return (0 != m);
02096 }
02097 
02098 bool ON_HistoryRecord::GetUuidValue( int value_id, ON_UUID* uuid ) const
02099 {
02100   bool rc = false;
02101   const ON_UuidValue* v = static_cast<ON_UuidValue*>(FindValueHelper(value_id,ON_Value::uuid_value,0));
02102   if ( v && 1 == v->m_value.Count())
02103   {
02104     *uuid = v->m_value[0];
02105     rc = true;
02106   }
02107   return rc;
02108 }
02109 
02110 int ON_HistoryRecord::GetBoolValues( int value_id, ON_SimpleArray<bool>& a ) const
02111 {
02112   a.SetCount(0);
02113   const ON_BoolValue* v = static_cast<ON_BoolValue*>(FindValueHelper(value_id,ON_Value::bool_value,0));
02114   if ( v )
02115   {
02116     a = v->m_value;
02117   }
02118   return a.Count();
02119 }
02120 
02121 
02122 int ON_HistoryRecord::GetStringValues( int value_id, ON_ClassArray<ON_wString>& a ) const
02123 {
02124   a.SetCount(0);
02125   const ON_StringValue* v = static_cast<ON_StringValue*>(FindValueHelper(value_id,ON_Value::string_value,0));
02126   if ( v )
02127   {
02128     a = v->m_value;
02129   }
02130   return a.Count();
02131 }
02132 
02133 
02134 int ON_HistoryRecord::GetIntValues( int value_id, ON_SimpleArray<int>& a ) const
02135 {
02136   a.SetCount(0);
02137   const ON_IntValue* v = static_cast<ON_IntValue*>(FindValueHelper(value_id,ON_Value::int_value,0));
02138   if ( v )
02139   {
02140     a = v->m_value;
02141   }
02142   return a.Count();
02143 }
02144 
02145 int ON_HistoryRecord::GetDoubleValues( int value_id, ON_SimpleArray<double>& a) const
02146 {
02147   a.SetCount(0);
02148   const ON_DoubleValue* v = static_cast<ON_DoubleValue*>(FindValueHelper(value_id,ON_Value::double_value,0));
02149   if ( v )
02150   {
02151     a = v->m_value;
02152   }
02153   return a.Count();
02154 }
02155 
02156 int ON_HistoryRecord::GetPointValues( int value_id, ON_SimpleArray<ON_3dPoint>& a ) const
02157 {
02158   a.SetCount(0);
02159   const ON_PointValue* v = static_cast<ON_PointValue*>(FindValueHelper(value_id,ON_Value::point_value,0));
02160   if ( v )
02161   {
02162     a = v->m_value;
02163   }
02164   return a.Count();
02165 }
02166 
02167 int ON_HistoryRecord::GetVectorValues( int value_id, ON_SimpleArray<ON_3dVector>& a ) const
02168 {
02169   a.SetCount(0);
02170   const ON_VectorValue* v = static_cast<ON_VectorValue*>(FindValueHelper(value_id,ON_Value::vector_value,0));
02171   if ( v )
02172   {
02173     a = v->m_value;
02174   }
02175   return a.Count();
02176 }
02177 
02178 int ON_HistoryRecord::GetXformValues( int value_id, ON_SimpleArray<ON_Xform>& a ) const
02179 {
02180   a.SetCount(0);
02181   const ON_XformValue* v = static_cast<ON_XformValue*>(FindValueHelper(value_id,ON_Value::xform_value,0));
02182   if ( v )
02183   {
02184     a = v->m_value;
02185   }
02186   return a.Count();
02187 }
02188 
02189 int ON_HistoryRecord::GetColorValues( int value_id, ON_SimpleArray<ON_Color>& a ) const
02190 {
02191   a.SetCount(0);
02192   const ON_ColorValue* v = static_cast<ON_ColorValue*>(FindValueHelper(value_id,ON_Value::color_value,0));
02193   if ( v )
02194   {
02195     a = v->m_value;
02196   }
02197   return a.Count();
02198 }
02199 
02200 int ON_HistoryRecord::GetObjRefValues( int value_id, ON_ClassArray<ON_ObjRef>& a ) const
02201 {
02202   a.SetCount(0);
02203   const ON_ObjRefValue* v = static_cast<ON_ObjRefValue*>(FindValueHelper(value_id,ON_Value::objref_value,0));
02204   if ( v )
02205   {
02206     a = v->m_value;
02207   }
02208   return a.Count();
02209 }
02210 
02211 int ON_HistoryRecord::GetGeometryValues( int value_id, ON_SimpleArray<const ON_Geometry*>& a) const
02212 {
02213   a.SetCount(0);
02214   const ON_GeometryValue* v = static_cast<ON_GeometryValue*>(FindValueHelper(value_id,ON_Value::geometry_value,0));
02215   if ( v )
02216   {
02217     int i, count = v->m_value.Count();
02218     a.Reserve(count);
02219     for ( i = 0; i < count; i++ )
02220       a.Append(v->m_value[i]);
02221   }
02222   return a.Count();
02223 }
02224 
02225 int ON_HistoryRecord::GetPolyEdgeValues( int value_id, ON_SimpleArray<const ON_PolyEdgeHistory*>& a) const
02226 {
02227   a.SetCount(0);
02228   const ON_PolyEdgeHistoryValue* v = static_cast<ON_PolyEdgeHistoryValue*>(FindValueHelper(value_id,ON_Value::polyedge_value,0));
02229   if ( v )
02230   {
02231     int i, count = v->m_value.Count();
02232     a.Reserve(count);
02233     for ( i = 0; i < count; i++ )
02234       a.Append(&v->m_value[i]);
02235   }
02236   return a.Count();
02237 }
02238 
02239 int ON_HistoryRecord::GetUuidValues( int value_id, ON_SimpleArray<ON_UUID>& a) const
02240 {
02241   a.SetCount(0);
02242   const ON_UuidValue* v = static_cast<ON_UuidValue*>(FindValueHelper(value_id,ON_Value::uuid_value,0));
02243   if ( v )
02244   {
02245     a = v->m_value;
02246   }
02247   return a.Count();
02248 }
02249 
02250 
02251 bool ON_HistoryRecord::IsAntecedent( ON_UUID object_uuid ) const
02252 {
02253   return m_antecedents.FindUuid(object_uuid);
02254 }
02255 
02256 int ON_HistoryRecord::ValueReport( ON_TextLog& text_log ) const
02257 {
02258   int value_count = 0;
02259   int i, vi, count = m_value.Count();
02260 
02261   // list values
02262   ON_SimpleArray<int> vi_list(count);
02263   vi_list.SetCount(count);
02264   vi_list.Zero();
02265 
02266   m_value.Sort( ON::quick_sort, vi_list.Array(), CompareValueId );
02267 
02268   for ( i = 0; i < count; i++ )
02269   {
02270     vi = vi_list[i];
02271     const ON_Value* v = m_value[vi];
02272     if (!v)
02273       continue;
02274     text_log.Print("Value ID %d:\n",v->m_value_id);
02275     text_log.PushIndent();
02276     m_value[i]->ReportHelper(text_log);
02277     text_log.PopIndent();
02278     value_count++;
02279   }
02280   return value_count;
02281 }
02282 
02283 void ON_HistoryRecord::Dump( ON_TextLog& text_log ) const
02284 {
02285   int i, count;
02286   ON_SimpleArray<ON_UUID> uuid_list;
02287 
02288   text_log.Print("Command ID: ");
02289   text_log.Print(m_command_id);
02290   text_log.Print("\n");
02291 
02292   text_log.Print("Version %d\n",m_version);
02293 
02294   text_log.Print("Record ID: ");
02295   text_log.Print(m_record_id);
02296   text_log.Print("\n");
02297 
02298   text_log.Print("Record type: %s\n",
02299                  (m_record_type == ON_HistoryRecord::feature_parameters) 
02300                  ? "feature parameters" : "history parameters");
02301 
02302   // list antededents
02303   uuid_list.SetCount(0);
02304   m_antecedents.GetUuids(uuid_list);
02305   count = uuid_list.Count();
02306   if ( count <= 0 )
02307   {
02308     text_log.Print("No antededents.\n");
02309   }
02310   else
02311   {
02312     text_log.Print("Antededent ID:\n");
02313     text_log.PushIndent();
02314     for ( i = 0; i < count; i++ )
02315     {
02316       text_log.Print(uuid_list[i]);
02317       text_log.Print("\n");
02318     }
02319     text_log.PopIndent();
02320   }
02321 
02322   // list descendants
02323   uuid_list.SetCount(0);
02324   m_descendants.GetUuids(uuid_list);
02325   count = uuid_list.Count();
02326   if ( count <= 0 )
02327   {
02328     text_log.Print("No descendants.\n");
02329   }
02330   else
02331   {
02332     text_log.Print("Descendant ID:\n");
02333     text_log.PushIndent();
02334     for ( i = 0; i < count; i++ )
02335     {
02336       text_log.Print(uuid_list[i]);
02337       text_log.Print("\n");
02338     }
02339     text_log.PopIndent();
02340   }
02341 
02342   text_log.Print("Values:\n");
02343   text_log.PushIndent();
02344   int value_count = ValueReport(text_log);
02345   if ( 0 == value_count )
02346     text_log.Print("none\n");
02347   text_log.PopIndent();
02348 }
02349 
02350 void ON_HistoryRecord::DestroyValue( int value_id )
02351 {
02352   if ( m_value.Count() > 0 )
02353   {
02354     if ( !m_bValuesSorted )
02355     {
02356       m_value.QuickSort(CompareValueId);
02357       m_bValuesSorted = true;
02358     }
02359     ON_DummyValue dummy_value;
02360     dummy_value.m_value_id = value_id;
02361     ON_Value* p = &dummy_value;
02362     int i = m_value.BinarySearch(&p,CompareValueId);
02363     if ( i >= 0 )
02364     {
02365       ON_Value* v = m_value[i];
02366       m_value.Remove();
02367       delete v;
02368     }
02369   }
02370 }
02371 
02372 ON_BOOL32 ON_HistoryRecord::Read( ON_BinaryArchive& archive )
02373 {
02374   Destroy();
02375 
02376   // put entire history record in a chunk
02377   int major_version = 0;
02378   int minor_version = 0;
02379   bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
02380   if (!rc)
02381     return false;
02382 
02383   for(;;)
02384   {
02385     rc = (1 == major_version);
02386     if (!rc) break;
02387 
02388     rc = archive.ReadUuid(m_record_id);
02389     if(!rc) break;
02390 
02391     rc = archive.ReadInt(&m_version);
02392     if(!rc) break;
02393 
02394     rc = archive.ReadUuid(m_command_id);
02395     if(!rc) break;
02396 
02397     rc = m_descendants.Read(archive);
02398     if(!rc) break;
02399 
02400     rc = m_antecedents.Read(archive);
02401     if(!rc) break;
02402 
02403     // all values are in a chunk
02404     int mjvs=0,mnvs=0;
02405     rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&mjvs,&mnvs);
02406     if (rc)
02407     {
02408       rc = ( 1 == mjvs );
02409 
02410       int i, count = 0;
02411       if (rc) 
02412         rc = archive.ReadInt(&count);
02413 
02414       if (rc)
02415         m_value.Reserve(count);
02416 
02417       for ( i = 0; i < count && rc; i++ )
02418       {
02419         int mjv=0,mnv=0;
02420         rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&mjv,&mnv);
02421         if ( !rc)
02422           break;
02423         for(;;)
02424         {
02425           rc = ( 1 == mjv);
02426           if (!rc) break;
02427           int value_type = ON_Value::no_value_type;
02428           rc = archive.ReadInt(&value_type);
02429           if (!rc) 
02430             break;
02431 
02432           int value_id = 0;
02433           rc = archive.ReadInt(&value_id);
02434           if (!rc) 
02435             break;
02436 
02437           ON_Value* value = ON_Value::CreateValue(value_type);
02438           if ( value )
02439           {        
02440             value->m_value_id = value_id;
02441             rc = value->ReadHelper(archive);
02442             if (!rc) 
02443             {
02444               delete value;
02445               break;
02446             }
02447             m_value.Append(value);
02448           }
02449 
02450           break;
02451         }
02452         if (!archive.EndRead3dmChunk())
02453           rc = false;
02454       }
02455 
02456       // end of all values
02457       if (!archive.EndRead3dmChunk())
02458         rc = false;
02459     }
02460 
02461     if ( rc && minor_version >= 1 )
02462     {
02463       // 1.1 fields added to opennurbs version 200603200
02464       int rec_type = ON_HistoryRecord::history_parameters;
02465       if (rc)
02466         rc = archive.ReadInt( &rec_type );
02467       if (rc )
02468         m_record_type = RecordType(rec_type);
02469 
02470     }
02471 
02472     break;
02473   }
02474 
02475   // end of entire history record in a chunk
02476   if (!archive.EndRead3dmChunk())
02477     rc = false;
02478   return rc;
02479 }
02480 
02481 ON_BOOL32 ON_HistoryRecord::Write( ON_BinaryArchive& archive ) const
02482 {
02483   bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
02484   if (!rc)
02485     return false;
02486 
02487   for(;;)
02488   {
02489     rc = archive.WriteUuid(m_record_id);
02490     if(!rc) break;
02491 
02492     rc = archive.WriteInt(m_version);
02493     if(!rc) break;
02494 
02495     rc = archive.WriteUuid(m_command_id);
02496     if(!rc) break;
02497 
02498     rc = m_descendants.Write(archive);
02499     if(!rc) break;
02500 
02501     rc = m_antecedents.Write(archive);
02502     if(!rc) break;
02503 
02504 
02505     // wrap all values in a chunk
02506     rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
02507     if (rc)
02508     {
02509       // value count
02510       int i, count = m_value.Count();
02511       rc = archive.WriteInt(count);
02512 
02513       for ( i = 0; i < count && rc; i++ )
02514       {
02515         // put individual value in its own chunk
02516         rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
02517         if ( !rc)
02518           break;
02519         for(;;)
02520         {
02521           const ON_Value* value = m_value[i];
02522           rc = archive.WriteInt(value ? value->m_value_type : ON_Value::no_value_type );
02523           if (!rc) break;
02524 
02525           rc = archive.WriteInt(value ? value->m_value_id : 0 );
02526           if (!rc) break;
02527           
02528           if ( value && value->m_value_type != ON_Value::no_value_type )
02529             rc = value->WriteHelper(archive);
02530           if (!rc) break;
02531 
02532           break;
02533         }
02534         // end of individual value chunk
02535         if (!archive.EndWrite3dmChunk())
02536           rc = false;
02537       }
02538 
02539       // end of all values chunk
02540       if ( !archive.EndWrite3dmChunk() )
02541         rc = false;
02542 
02543     }
02544 
02545     // 1.1 fields added to opennurbs version 200603200
02546     if (rc)
02547       rc = archive.WriteInt( m_record_type );
02548 
02549     break;
02550   }
02551 
02552   if (!archive.EndWrite3dmChunk())
02553     rc = false;
02554   return rc;
02555 }
02556 
02557 ON_UUID ON_HistoryRecord::ModelObjectId() const
02558 {
02559   return m_record_id;
02560 }
02561 
02562 void ON_HistoryRecord::RemapObjectIds( const ON_SimpleArray<ON_UuidPair>& id_remap )
02563 {
02564   if ( id_remap.Count() > 0 )
02565   {
02566     int i, j;
02567     m_antecedents.RemapUuids(id_remap);
02568     m_descendants.RemapUuids(id_remap);
02569     for ( i = 0; i < m_value.Count(); i++ )
02570     {
02571       ON_Value* v = m_value[i];
02572       if ( v && ON_Value::objref_value == v->m_value_type )
02573       {
02574         ON_ObjRefValue* objrev_v = static_cast<ON_ObjRefValue*>(v);
02575         for ( j = 0; j < objrev_v->m_value.Count(); j++ )
02576         {
02577           objrev_v->m_value[j].RemapObjectId(id_remap);
02578         }
02579       }
02580     }
02581   }
02582 }
02583 
02584 
02586 //
02587 // ON_CurveProxyHistory
02588 //
02589 
02590 ON_CurveProxyHistory::ON_CurveProxyHistory()
02591 {
02592 }
02593 
02594 ON_CurveProxyHistory::~ON_CurveProxyHistory()
02595 {
02596 }
02597 
02598 void ON_CurveProxyHistory::Destroy()
02599 {
02600   m_curve_ref.Destroy();
02601   m_bReversed = false;
02602   m_full_real_curve_domain.Destroy();
02603   m_sub_real_curve_domain.Destroy();
02604   m_proxy_curve_domain.Destroy();
02605 }
02606 
02607 
02608 bool ON_CurveProxyHistory::Write( ON_BinaryArchive& file ) const
02609 {
02610   if ( !file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK,1,0) )
02611     return false;
02612 
02613   bool rc = false;
02614   for(;;)
02615   {
02616     if ( !m_curve_ref.Write(file) )
02617       break;
02618     if ( !file.WriteBool(m_bReversed) )
02619       break;
02620     if ( !file.WriteInterval(m_full_real_curve_domain) )
02621       break;
02622     if ( !file.WriteInterval(m_sub_real_curve_domain) )
02623       break;
02624     if ( !file.WriteInterval(m_proxy_curve_domain) )
02625       break;
02626     rc = true;
02627     break;
02628   }
02629 
02630   if ( !file.EndWrite3dmChunk() )
02631     rc = false;
02632   return rc;
02633 }
02634 
02635 bool ON_CurveProxyHistory::Read( ON_BinaryArchive& file )
02636 {
02637   int version_major = 0;
02638   int version_minor = 0;
02639   Destroy();
02640 
02641   if ( !file.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK,&version_major,&version_minor) )
02642     return false;
02643 
02644   bool rc = false;
02645   for(;;)
02646   {
02647     if ( 1 != version_major )
02648       break;
02649     if ( !m_curve_ref.Read(file) )
02650       break;
02651     if ( !file.ReadBool(&m_bReversed) )
02652       break;
02653     if ( !file.ReadInterval(m_full_real_curve_domain) )
02654       break;
02655     if ( !file.ReadInterval(m_sub_real_curve_domain) )
02656       break;
02657     if ( !file.ReadInterval(m_proxy_curve_domain) )
02658       break;
02659     
02660     rc = true;
02661     break;
02662   }
02663 
02664   if ( !file.EndRead3dmChunk() )
02665     rc = false;
02666 
02667   return rc;
02668 }
02669 
02670 void ON_CurveProxyHistory::Dump( ON_TextLog& ) const
02671 {
02672 }
02673 
02675 //
02676 // ON_PolyEdgeHistory
02677 //
02678 
02679 ON_PolyEdgeHistory::ON_PolyEdgeHistory()
02680 : m_evaluation_mode(0)
02681 {
02682 }
02683 
02684 ON_PolyEdgeHistory::~ON_PolyEdgeHistory()
02685 {
02686 }
02687 
02688 void ON_PolyEdgeHistory::Destroy()
02689 {
02690   m_segment.Destroy();
02691   m_t.Destroy();
02692   m_evaluation_mode = 0;
02693 }
02694 
02695 
02696 bool ON_PolyEdgeHistory::Write( ON_BinaryArchive& file ) const
02697 {
02698   int i;
02699   if ( !file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK,1,0) )
02700     return false;
02701 
02702   bool rc = false;
02703   for(;;)
02704   {
02705     if ( !file.WriteInt(m_segment.Count()) )
02706       break;
02707     for ( i = 0; i < m_segment.Count(); i++ )
02708     {
02709       if ( !m_segment[i].Write(file) )
02710         break;
02711     }
02712     if ( i < m_segment.Count() )
02713       break;
02714     if ( !file.WriteInt(m_t.Count()) )
02715       break;
02716     if ( m_t.Count() > 0 )
02717     {
02718       if ( !file.WriteDouble(m_t.Count(),m_t.Array()) )
02719         break;
02720     }
02721     if ( !file.WriteInt(m_evaluation_mode) )
02722       break;
02723     rc = true;
02724     break;
02725   }
02726 
02727   if ( !file.EndWrite3dmChunk() )
02728     rc = false;
02729   return rc;
02730 }
02731 
02732 bool ON_PolyEdgeHistory::Read( ON_BinaryArchive& file )
02733 {
02734   int count, i;
02735   int version_major = 0;
02736   int version_minor = 0;
02737 
02738   Destroy();
02739 
02740   if ( !file.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK,&version_major,&version_minor) )
02741     return false;
02742 
02743   bool rc = false;
02744   for(;;)
02745   {
02746     if ( 1 != version_major )
02747       break;
02748     count = 0;
02749     if ( !file.ReadInt(&count) )
02750       break;
02751     m_segment.Reserve(count);
02752     for ( i = 0; i < count; i++ )
02753     {
02754       if ( !m_segment.AppendNew().Read(file) )
02755         break;
02756     }
02757     if ( i < count )
02758       break;
02759     count = 0;
02760     if ( !file.ReadInt(&count) )
02761       break;
02762     if ( count > 0 )
02763     {
02764       m_t.Reserve(count);
02765       m_t.SetCount(count);
02766       if ( !file.ReadDouble(count,m_t.Array()) )
02767         break;
02768     }
02769     if ( !file.ReadInt(&m_evaluation_mode) )
02770       break;
02771     rc = true;
02772     break;
02773   }
02774 
02775   if ( !file.EndRead3dmChunk() )
02776     rc = false;
02777   return rc;
02778 }
02779 
02780 void ON_PolyEdgeHistory::Dump( ON_TextLog& ) const
02781 {
02782 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:02