opennurbs_3dm_settings.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 // Easy way to toggle the name of the obsolete ON_3dmView::m_target
00020 // variable when you want to change the name and compile to insure
00021 // no rogue code is directly accessing this variable.  See
00022 // ON_3dmView header for more comments.
00023 //
00024 //#define OBSOLETE_3DM_VIEW_TARGET m_target_HIDEME
00025 #define OBSOLETE_3DM_VIEW_TARGET m_target
00026 
00028 //
00029 // ON_3dmUnitsAndTolerances
00030 //
00031 
00032 ON_UnitSystem::ON_UnitSystem()
00033 {
00034   m_unit_system = ON::millimeters;
00035   m_custom_unit_scale = 1.0;
00036 }
00037 
00038 ON_UnitSystem::ON_UnitSystem(ON::unit_system us)
00039 {
00040   m_unit_system = ON::UnitSystem(us);
00041   m_custom_unit_scale = ON::UnitScale(ON::meters,m_unit_system);
00042 }
00043 
00044 ON_UnitSystem& ON_UnitSystem::operator=(ON::unit_system us)
00045 {
00046   m_unit_system = ON::UnitSystem(us);
00047   if ( ON::custom_unit_system != us )
00048   {
00049     m_custom_unit_scale = ON::UnitScale(ON::meters,m_unit_system);
00050     m_custom_unit_name.Destroy();
00051   }
00052   return *this;
00053 }
00054 
00055 bool ON_UnitSystem::operator==(const ON_UnitSystem& other)
00056 {
00057   if ( m_unit_system != other.m_unit_system )
00058     return false;
00059 
00060   if ( ON::custom_unit_system == m_unit_system )
00061   {
00062     if ( m_custom_unit_name.Compare(other.m_custom_unit_name) )
00063       return false;
00064     if ( !(m_custom_unit_scale == other.m_custom_unit_scale) )
00065       return false;
00066   }
00067 
00068   return true;
00069 }
00070 
00071 bool ON_UnitSystem::operator!=(const ON_UnitSystem& other)
00072 {
00073   if ( m_unit_system != other.m_unit_system )
00074     return true;
00075 
00076   if ( ON::custom_unit_system == m_unit_system )
00077   {
00078     if ( m_custom_unit_name.Compare(other.m_custom_unit_name) )
00079       return true;
00080     if ( m_custom_unit_scale != other.m_custom_unit_scale )
00081       return true;
00082   }
00083 
00084   return false;
00085 }
00086 
00087 ON_UnitSystem::~ON_UnitSystem()
00088 {
00089 }
00090 
00091 void ON_UnitSystem::Default()
00092 {
00093   m_unit_system = ON::millimeters;
00094   m_custom_unit_scale = 1.0;
00095   m_custom_unit_name.Destroy();
00096 }
00097 
00098 bool ON_UnitSystem::IsValid() const
00099 {
00100   if ( m_unit_system != ON::UnitSystem(m_unit_system) )
00101   {
00102     // bogus enum value
00103     return false;
00104   }
00105 
00106   if ( ON::custom_unit_system == m_unit_system )
00107   {
00108     if ( !ON_IsValid(m_custom_unit_scale) || m_custom_unit_scale <= 0.0 )
00109     {
00110       // m_custom_unit_scale should be > 0.0 and a valid double
00111       return false;
00112     }
00113   }
00114 
00115   return true;
00116 }
00117 
00118 bool ON_UnitSystem::Read( ON_BinaryArchive& file )
00119 {
00120   Default();
00121 
00122   int major_version = 0;
00123   int minor_version = 0;
00124   
00125   if ( !file.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version) )
00126     return false;
00127 
00128   bool rc = (1 == major_version);
00129   int i = m_unit_system;
00130   if (rc)
00131     rc = file.ReadInt( &i );
00132   if (rc)
00133     m_unit_system = ON::UnitSystem(i);
00134   if (rc)
00135     rc = file.ReadDouble( &m_custom_unit_scale );
00136   if (rc)
00137     rc = file.ReadString( m_custom_unit_name );
00138 
00139   if ( !file.EndRead3dmChunk() )
00140     rc = false;
00141 
00142   return rc;
00143 }
00144 
00145 bool ON_UnitSystem::Write( ON_BinaryArchive& file ) const
00146 {
00147   if ( !file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0) )
00148     return false;
00149 
00150 
00151   // values saved in the file
00152   //no_unit_system =  0, 
00153   //microns        =  1,  // 1.0e-6 meters
00154   //millimeters    =  2,  // 1.0e-3 meters
00155   //centimeters    =  3,  // 1.0e-2 meters
00156   //meters         =  4,
00157   //kilometers     =  5,  // 1.0e+3 meters
00158   //microinches    =  6,  // 1.0e-6 inches
00159   //mils           =  7,  // 1.0e-3 inches
00160   //inches         =  8,  // 0.0254 meters
00161   //feet           =  9,  // 12 inches
00162   //miles          = 10,  // 63360 inches
00163   //custom_unit_system = 11, // x meters with x defined in ON_3dmUnitsAndTolerances.m_custom_unit_scale
00164 
00165   bool rc = file.WriteInt( m_unit_system );
00166   if (rc)
00167     rc = file.WriteDouble( m_custom_unit_scale );
00168   if (rc)
00169     rc = file.WriteString( m_custom_unit_name );
00170 
00171   if ( !file.EndWrite3dmChunk() )
00172     rc = false;
00173 
00174   return rc;
00175 }
00176 
00177 void ON_UnitSystem::Dump( ON_TextLog& dump ) const
00178 {
00179   ON_wString sUnitSystem;
00180   switch( m_unit_system )
00181   {
00182   case ON::no_unit_system:
00183     sUnitSystem = "no units";
00184     break;
00185   case ON::angstroms:
00186     sUnitSystem = "angstroms";
00187     break;
00188   case ON::nanometers:
00189     sUnitSystem = "nanometers";
00190     break;
00191   case ON::microns:
00192     sUnitSystem = "microns";
00193     break;
00194   case ON::millimeters:
00195     sUnitSystem = "millimeters";
00196     break;
00197   case ON::decimeters:
00198     sUnitSystem = "decimeters";
00199     break;
00200   case ON::centimeters:
00201     sUnitSystem = "centimeters";
00202     break;
00203   case ON::meters:
00204     sUnitSystem = "meters";
00205     break;
00206   case ON::dekameters:
00207     sUnitSystem = "dekameters";
00208     break;
00209   case ON::hectometers:
00210     sUnitSystem = "hectometers";
00211     break;
00212   case ON::kilometers:
00213     sUnitSystem = "kilometers";
00214     break;
00215   case ON::megameters:
00216     sUnitSystem = "megameters";
00217     break;
00218   case ON::gigameters:
00219     sUnitSystem = "gigameters";
00220     break;
00221   case ON::microinches:
00222     sUnitSystem = "microinches";
00223     break;
00224   case ON::mils:
00225     sUnitSystem = "mils (= 0.001 inches)";
00226     break;
00227   case ON::inches:
00228     sUnitSystem = "inches";
00229     break;
00230   case ON::feet:
00231     sUnitSystem = "feet";
00232     break;
00233   case ON::yards:
00234     sUnitSystem = "yards";
00235     break;
00236   case ON::miles:
00237     sUnitSystem = "miles";
00238     break;
00239   case ON::printer_point:
00240     sUnitSystem = "points (1/72 inch)";
00241     break;
00242   case ON::printer_pica:
00243     sUnitSystem = "picas (1/6 inch)";
00244     break;
00245   case ON::nautical_mile:
00246     sUnitSystem = "nautical miles";
00247     break;
00248   case ON::astronomical:
00249     sUnitSystem = "astronomical units";
00250     break;
00251   case ON::lightyears:
00252     sUnitSystem = "light years";
00253     break;
00254   case ON::parsecs:
00255     sUnitSystem = "parsecs";
00256     break;
00257 
00258   case ON::custom_unit_system:
00259     if ( m_custom_unit_name.Length() > 0 )
00260     {
00261       const wchar_t* wsCustomUnitName = m_custom_unit_name.Array();
00262       if ( 0 != wsCustomUnitName && 0 != wsCustomUnitName[0] )
00263       {
00264         sUnitSystem.Format("%ls (= %g meters)",
00265                            wsCustomUnitName,
00266                            m_custom_unit_scale);
00267       }
00268     }
00269     else
00270       sUnitSystem.Format("user defined unit (= %g meters)",m_custom_unit_scale);
00271     break;
00272   default:
00273     sUnitSystem = "unknown unit system";
00274     break;
00275   }
00276   const wchar_t* wsUnitSystem = sUnitSystem.Array();
00277   if ( 0 != wsUnitSystem )
00278     dump.Print("Unit system: %ls\n",wsUnitSystem);
00279 }
00280 
00281 void ON_3dmUnitsAndTolerances::Default()
00282 {
00283   m_unit_system.Default();
00284   m_unit_system.m_unit_system = ON::millimeters;
00285   m_unit_system.m_custom_unit_name = L"Units";
00286   m_absolute_tolerance = 0.001;    // = 0.01;       // Dale Lear: Changed March 2006
00287   m_angle_tolerance = ON_PI/180.0; // = ON_PI/60.0; // Dale Lear: Changed 5 April 2006
00288   m_relative_tolerance = 0.01;
00289 
00290   m_distance_display_mode = ON::decimal;
00291   m_distance_display_precision = 3;
00292 }
00293 
00294 ON_3dmUnitsAndTolerances::ON_3dmUnitsAndTolerances()
00295                         : m_absolute_tolerance(0.0),
00296                           m_angle_tolerance(0.0),
00297                           m_relative_tolerance(0.0),
00298                           m_distance_display_mode(ON::decimal),
00299                           m_distance_display_precision(3)
00300 {
00301   Default();
00302 }
00303 
00304 ON_3dmUnitsAndTolerances::~ON_3dmUnitsAndTolerances()
00305 {}
00306 
00307 ON_3dmUnitsAndTolerances::ON_3dmUnitsAndTolerances(const ON_3dmUnitsAndTolerances& src )
00308                         : m_absolute_tolerance(0.0),
00309                           m_angle_tolerance(0.0),
00310                           m_relative_tolerance(0.0),
00311                           m_distance_display_mode(ON::decimal),
00312                           m_distance_display_precision(3)
00313 {
00314   Default();
00315   *this = src;
00316 }
00317 
00318 ON_3dmUnitsAndTolerances& ON_3dmUnitsAndTolerances::operator=(const ON_3dmUnitsAndTolerances& src )
00319 {
00320   if ( this != &src ) 
00321   {
00322     m_unit_system = src.m_unit_system;
00323     m_absolute_tolerance = src.m_absolute_tolerance;
00324     m_angle_tolerance = src.m_angle_tolerance;
00325     m_relative_tolerance = src.m_relative_tolerance;
00326     m_distance_display_mode = src.m_distance_display_mode;
00327     m_distance_display_precision = src.m_distance_display_precision;
00328   }
00329   return *this;
00330 }
00331 
00332 bool ON_3dmUnitsAndTolerances::Write( ON_BinaryArchive& file ) const
00333 {
00334   const int version = 102;
00335   int i;
00336 
00337   // version 100 ON_3dmUnitsAndTolerances settings
00338   bool rc = file.WriteInt( version );
00339   i = m_unit_system.m_unit_system;
00340   if ( rc ) rc = file.WriteInt( i );
00341   if ( rc ) rc = file.WriteDouble( m_absolute_tolerance );
00342   if ( rc ) rc = file.WriteDouble( m_angle_tolerance );
00343   if ( rc ) rc = file.WriteDouble( m_relative_tolerance );
00344 
00345   // added in version 101
00346   i = m_distance_display_mode;
00347   if ( rc ) rc = file.WriteInt( i );
00348   i = m_distance_display_precision;
00349   if ( i < 0 || i > 20 ) {
00350     ON_ERROR("ON_3dmUnitsAndTolerances::Write() - m_distance_display_precision out of range.");
00351     i = 3;
00352   }
00353   if ( rc ) rc = file.WriteInt( i );
00354 
00355   // added in version 102
00356   if ( rc ) rc = file.WriteDouble( m_unit_system.m_custom_unit_scale );
00357   if ( rc ) rc = file.WriteString( m_unit_system.m_custom_unit_name );
00358   return rc;
00359 }
00360 
00361 bool ON_3dmUnitsAndTolerances::Read( ON_BinaryArchive& file )
00362 {
00363   Default();
00364   int version = 0;
00365   bool rc = file.ReadInt( &version );
00366   if ( rc && version >= 100 && version < 200 ) {
00367     int us = ON::no_unit_system;
00368     rc = file.ReadInt( &us );
00369     if ( rc )
00370       m_unit_system.m_unit_system = ON::UnitSystem(us);
00371     if ( rc ) rc = file.ReadDouble( &m_absolute_tolerance );
00372     if ( rc ) rc = file.ReadDouble( &m_angle_tolerance );
00373     if ( rc ) rc = file.ReadDouble( &m_relative_tolerance );
00374     if ( version >= 101 ) {
00375       int dm = ON::decimal;
00376       if ( rc ) rc = file.ReadInt( &dm );
00377       if ( rc ) m_distance_display_mode = ON::DistanceDisplayMode(dm);
00378       if ( rc ) rc = file.ReadInt( &m_distance_display_precision );
00379       if ( m_distance_display_precision < 0 || m_distance_display_precision > 20 )
00380         m_distance_display_precision = 3; // some beta files had bogus values stored in file
00381       if ( version >= 102 ) {
00382         if ( rc ) rc = file.ReadDouble( &m_unit_system.m_custom_unit_scale );
00383         if ( rc ) rc = file.ReadString( m_unit_system.m_custom_unit_name );
00384       }
00385     }
00386   }
00387   return rc;
00388 }
00389 
00390 void ON_3dmUnitsAndTolerances::Dump( ON_TextLog& dump) const
00391 {
00392   m_unit_system.Dump(dump);
00393   dump.Print("Absolute tolerance: %g\n",m_absolute_tolerance);
00394   dump.Print("Angle tolerance: %g\n",m_angle_tolerance);
00395 }
00396 
00397 double ON_3dmUnitsAndTolerances::Scale( ON::unit_system us ) const
00398 {
00399   // Example: If us = meters and m_unit_system = centimeters,
00400   // then Scale() returns 100.
00401   return ON::UnitScale( us, m_unit_system );
00402 }
00403 
00405 //
00406 // ON_3dmRenderSettings
00407 //
00408 void ON_3dmRenderSettings::Dump( ON_TextLog& text_log ) const
00409 {
00410   text_log.Print("m_bCustomImageSize = %s\n",m_bCustomImageSize?"true":"false");
00411   text_log.Print("m_image_width = %d\n",m_image_width);
00412   text_log.Print("m_image_height = %d\n",m_image_height);
00413   text_log.Print("m_image_dpi = %g\n",m_image_dpi);
00414   text_log.Print("m_image_us = %d\n",m_image_us);
00415   text_log.Print("m_ambient_light rgb = ");text_log.PrintRGB(m_ambient_light);text_log.Print("\n");
00416   text_log.Print("m_background_style = %d\n",m_background_style);
00417   text_log.Print("m_background_color rgb = ");text_log.PrintRGB(m_background_color);text_log.Print("\n");
00418   text_log.Print("m_background_bitmap_filename = ");text_log.Print(m_background_bitmap_filename);text_log.Print("\n");
00419   text_log.Print("m_bUseHiddenLights = %s\n",m_bUseHiddenLights?"true":"false");
00420   text_log.Print("m_bDepthCue = %s\n",m_bDepthCue?"true":"false");
00421   text_log.Print("m_bFlatShade = %s\n",m_bFlatShade?"true":"false");
00422   text_log.Print("m_bRenderBackfaces = %s\n",m_bRenderBackfaces?"true":"false");
00423   text_log.Print("m_bRenderPoints = %s\n",m_bRenderPoints?"true":"false");
00424   text_log.Print("m_bRenderCurves = %s\n",m_bRenderCurves?"true":"false");
00425   text_log.Print("m_bRenderIsoparams = %s\n",m_bRenderIsoparams?"true":"false");
00426   text_log.Print("m_bRenderMeshEdges = %s\n",m_bRenderMeshEdges?"true":"false");
00427   text_log.Print("m_bRenderAnnotation = %s\n",m_bRenderAnnotation?"true":"false");
00428 
00429   text_log.Print("m_antialias_style = %d\n",m_antialias_style);
00430   text_log.Print("m_shadowmap_style = %d\n",m_shadowmap_style);
00431   text_log.Print("m_shadowmap_width = %d\n",m_shadowmap_width);
00432   text_log.Print("m_shadowmap_height = %d\n",m_shadowmap_height);
00433   text_log.Print("m_shadowmap_offset = %g\n",m_shadowmap_offset);
00434 
00435   text_log.Print("m_bScaleBackgroundToFit = %s\n",m_bScaleBackgroundToFit?"true":"false");
00436 }
00437 
00438 void ON_3dmRenderSettings::Default()
00439 {
00440   m_bCustomImageSize = false;
00441   m_image_width  = 800;
00442   m_image_height = 600;
00443   m_bScaleBackgroundToFit = false;
00444   memset(m_reserved1,0,sizeof(m_reserved1));
00445   m_image_dpi = 72.0;
00446   m_image_us = ON::inches;
00447 
00448 
00449   m_ambient_light.SetRGB( 0, 0, 0);
00450 
00451   m_background_style = 0;
00452   m_background_color.SetRGB(160,160,160);
00453   m_background_bottom_color.SetRGB(160,160,160);
00454   m_background_bitmap_filename.Destroy();
00455 
00456   m_bUseHiddenLights = false;
00457 
00458   m_bDepthCue = false;
00459   m_bFlatShade = false;
00460 
00461   m_bRenderBackfaces = true;
00462   m_bRenderPoints = false;
00463   m_bRenderCurves = false;
00464   m_bRenderIsoparams = false;
00465   m_bRenderMeshEdges = false;
00466   m_bRenderAnnotation = false;
00467 
00468   m_antialias_style = 1;
00469 
00470   m_shadowmap_style = 1;
00471   m_shadowmap_width = 1000;
00472   m_shadowmap_height = 1000;
00473   m_shadowmap_offset = 0.75;
00474 
00475   m_bUsesAmbientAttr      = true;
00476   m_bUsesBackgroundAttr   = true;
00477   m_bUsesBackfaceAttr     = false;
00478   m_bUsesPointsAttr       = false;
00479   m_bUsesCurvesAttr       = true;
00480   m_bUsesIsoparmsAttr     = true;
00481   m_bUsesMeshEdgesAttr    = false;
00482   m_bUsesAnnotationAttr   = true;
00483   m_bUsesHiddenLightsAttr = true;
00484 
00485   memset(m_reserved2,0,sizeof(m_reserved2));
00486 }
00487 
00488 ON_3dmRenderSettings::ON_3dmRenderSettings()
00489 {
00490   Default();
00491 }
00492 
00493 ON_3dmRenderSettings::~ON_3dmRenderSettings()
00494 {
00495   m_background_bitmap_filename.Destroy();
00496 }
00497 
00498 ON_3dmRenderSettings::ON_3dmRenderSettings(const ON_3dmRenderSettings& src )
00499 {
00500   Default();
00501   *this = src;
00502 }
00503 
00504 ON_3dmRenderSettings& ON_3dmRenderSettings::operator=(const ON_3dmRenderSettings& src )
00505 {
00506   if ( this != &src ) {
00507     m_bCustomImageSize = src.m_bCustomImageSize;
00508     m_image_width = src.m_image_width;
00509     m_image_height = src.m_image_height;
00510     m_bScaleBackgroundToFit = src.m_bScaleBackgroundToFit;
00511     m_image_dpi = src.m_image_dpi;
00512     m_image_us = src.m_image_us;
00513     m_ambient_light = src.m_ambient_light;
00514     m_background_style = src.m_background_style;
00515     m_background_color = src.m_background_color;
00516     m_background_bitmap_filename = src.m_background_bitmap_filename;
00517     m_bUseHiddenLights = src.m_bUseHiddenLights;
00518     m_bDepthCue = src.m_bDepthCue;
00519     m_bFlatShade = src.m_bFlatShade;
00520     m_bRenderBackfaces = src.m_bRenderBackfaces;
00521     m_bRenderPoints = src.m_bRenderPoints;
00522     m_bRenderCurves = src.m_bRenderCurves;
00523     m_bRenderIsoparams = src.m_bRenderIsoparams;
00524     m_bRenderMeshEdges = src.m_bRenderMeshEdges;
00525     m_bRenderAnnotation = src.m_bRenderAnnotation;
00526     m_antialias_style = src.m_antialias_style;
00527     m_shadowmap_style = src.m_shadowmap_style;
00528     m_shadowmap_width = src.m_shadowmap_width;
00529     m_shadowmap_height = src.m_shadowmap_height;
00530     m_shadowmap_offset = src.m_shadowmap_offset;
00531     
00532     m_background_bottom_color = src.m_background_bottom_color;
00533     m_bUsesAmbientAttr      = src.m_bUsesAmbientAttr;
00534     m_bUsesBackgroundAttr   = src.m_bUsesBackgroundAttr;
00535     m_bUsesBackfaceAttr     = src.m_bUsesBackfaceAttr;  
00536     m_bUsesPointsAttr       = src.m_bUsesPointsAttr;        
00537     m_bUsesCurvesAttr       = src.m_bUsesCurvesAttr;       
00538     m_bUsesIsoparmsAttr     = src.m_bUsesIsoparmsAttr;      
00539     m_bUsesMeshEdgesAttr    = src.m_bUsesMeshEdgesAttr;     
00540     m_bUsesAnnotationAttr   = src.m_bUsesAnnotationAttr;    
00541     m_bUsesHiddenLightsAttr = src.m_bUsesHiddenLightsAttr;  
00542   }
00543   return *this;
00544 }
00545 
00546 bool ON_3dmRenderSettings::Write( ON_BinaryArchive& file ) const
00547 {
00548   int i;
00549   // version 103: 11 November 2010
00550   const int version = 103;
00551   bool rc = file.WriteInt( version );
00552   // version >= 100
00553   if (rc) rc = file.WriteInt( m_bCustomImageSize );
00554   if (rc) rc = file.WriteInt( m_image_width );
00555   if (rc) rc = file.WriteInt( m_image_height );
00556   if (rc) rc = file.WriteColor( m_ambient_light );
00557   if (rc) rc = file.WriteInt( m_background_style );
00558   if (rc) rc = file.WriteColor( m_background_color );
00559   if (rc) rc = file.WriteString( m_background_bitmap_filename );
00560   if (rc) rc = file.WriteInt( m_bUseHiddenLights );
00561   if (rc) rc = file.WriteInt( m_bDepthCue );
00562   if (rc) rc = file.WriteInt( m_bFlatShade );
00563 
00564   // 26 August 2003 Dale Lear:
00565   //     When saving V2 files, turn on backfaces. RR 11656
00566   //
00567   i = (file.Archive3dmVersion() >= 3) ? m_bRenderBackfaces : 1;
00568   if (rc) rc = file.WriteInt( i );
00569 
00570   if (rc) rc = file.WriteInt( m_bRenderPoints );
00571   if (rc) rc = file.WriteInt( m_bRenderCurves );
00572   if (rc) rc = file.WriteInt( m_bRenderIsoparams );
00573   if (rc) rc = file.WriteInt( m_bRenderMeshEdges );
00574   if (rc) rc = file.WriteInt( m_bRenderAnnotation );
00575   if (rc) rc = file.WriteInt( m_antialias_style );
00576   if (rc) rc = file.WriteInt( m_shadowmap_style );
00577   if (rc) rc = file.WriteInt( m_shadowmap_width );
00578   if (rc) rc = file.WriteInt( m_shadowmap_height );
00579   if (rc) rc = file.WriteDouble( m_shadowmap_offset );
00580   // version >= 101 begins here
00581   if (rc) rc = file.WriteDouble( m_image_dpi );
00582   i = m_image_us;
00583   if (rc) rc = file.WriteInt( i );
00584   // version >= 102 begins here
00585   if (rc) rc = file.WriteColor( m_background_bottom_color );
00586 
00587   // version >= 103 begins here - added 11 November 2010
00588   if (rc) rc = file.WriteBool( m_bScaleBackgroundToFit );
00589 
00590   return rc;
00591 }
00592 
00593 bool ON_3dmRenderSettings::Read( ON_BinaryArchive& file )
00594 {
00595   Default();
00596   int version = 0;
00597   bool rc = file.ReadInt( &version );
00598   if ( rc && version >= 100 && version < 200 ) 
00599   {
00600     if (rc) 
00601       rc = file.ReadInt( &m_bCustomImageSize );
00602     if (rc) 
00603       rc = file.ReadInt( &m_image_width );
00604     if (rc) 
00605       rc = file.ReadInt( &m_image_height );
00606     if (rc) 
00607       rc = file.ReadColor( m_ambient_light );
00608     if (rc) 
00609       rc = file.ReadInt( &m_background_style );
00610     if (rc) 
00611       rc = file.ReadColor( m_background_color );
00612     if (rc) 
00613       rc = file.ReadString( m_background_bitmap_filename );
00614     if (rc) 
00615       rc = file.ReadInt( &m_bUseHiddenLights );
00616     if (rc) 
00617       rc = file.ReadInt( &m_bDepthCue );
00618     if (rc) 
00619       rc = file.ReadInt( &m_bFlatShade );
00620     if (rc) 
00621       rc = file.ReadInt( &m_bRenderBackfaces );
00622     if (rc) 
00623       rc = file.ReadInt( &m_bRenderPoints );
00624     if (rc) 
00625       rc = file.ReadInt( &m_bRenderCurves );
00626     if (rc) 
00627       rc = file.ReadInt( &m_bRenderIsoparams );
00628     if (rc) 
00629       rc = file.ReadInt( &m_bRenderMeshEdges );
00630     if (rc) 
00631       rc = file.ReadInt( &m_bRenderAnnotation );
00632     if (rc) 
00633       rc = file.ReadInt( &m_antialias_style );
00634     if (rc) 
00635       rc = file.ReadInt( &m_shadowmap_style );
00636     if (rc) 
00637       rc = file.ReadInt( &m_shadowmap_width );
00638     if (rc) 
00639       rc = file.ReadInt( &m_shadowmap_height );
00640     if (rc) 
00641       rc = file.ReadDouble( &m_shadowmap_offset );
00642     if (rc && version >= 101) 
00643     {
00644       if (rc) 
00645         rc = file.ReadDouble( &m_image_dpi );
00646       if (rc) 
00647       {
00648         int i;
00649         rc = file.ReadInt(&i);
00650         if (rc)
00651           m_image_us = ON::UnitSystem(i);
00652       }
00653      
00654       if (rc && version >= 102) 
00655       {
00656         rc = file.ReadColor( m_background_bottom_color );
00657         if (rc && version >= 103)
00658         {
00659           rc = file.ReadBool( &m_bScaleBackgroundToFit );
00660         }
00661       }
00662     }
00663   }
00664   return rc;
00665 }
00666 
00667 bool ON_3dmRenderSettings::ScaleBackgroundToFit() const
00668 {
00669   return m_bScaleBackgroundToFit;
00670 }
00671 
00672 void ON_3dmRenderSettings::SetScaleBackgroundToFit( bool bScaleBackgroundToFit )
00673 {
00674   // The "? true : false" is here to prevent hacks from using a bool
00675   // to store settings besides 1 and 0.
00676   m_bScaleBackgroundToFit = bScaleBackgroundToFit?true:false;
00677 }
00678 
00679 
00681 //
00682 // ON_3dmAnnotationSettings
00683 //
00684 
00685 ON_3dmAnnotationSettings::ON_3dmAnnotationSettings()
00686 {
00687   Default();
00688 }
00689 
00690 ON_3dmAnnotationSettings::~ON_3dmAnnotationSettings()
00691 {
00692 }
00693 
00694 ON_3dmAnnotationSettings::ON_3dmAnnotationSettings(const ON_3dmAnnotationSettings& src)
00695 {
00696   Default();
00697   *this = src;
00698 
00699 }
00700 
00701 ON_3dmAnnotationSettings& ON_3dmAnnotationSettings::operator=(const ON_3dmAnnotationSettings& src)
00702 {
00703   if ( this != &src ) {
00704     m_dimscale = src.m_dimscale;
00705     m_textheight = src.m_textheight;
00706     m_dimexe = src.m_dimexe;
00707     m_dimexo = src.m_dimexo;
00708     m_arrowlength = src.m_arrowlength;
00709     m_arrowwidth = src.m_arrowwidth;
00710     m_centermark = src.m_centermark;
00711     m_dimunits = src.m_dimunits;;
00712     m_arrowtype = src.m_arrowtype;
00713     m_angularunits = src.m_angularunits;
00714     m_lengthformat = src.m_lengthformat;
00715     m_angleformat = src.m_angleformat;
00716     m_textalign = src.m_textalign;
00717     m_resolution = src.m_resolution;
00718     m_facename = src.m_facename;
00719     m_world_view_text_scale = src.m_world_view_text_scale;
00720     m_world_view_hatch_scale = src.m_world_view_hatch_scale;
00721     m_bEnableAnnotationScaling = src.m_bEnableAnnotationScaling;
00722     m_bEnableHatchScaling = src.m_bEnableHatchScaling;
00723   }
00724   return *this;
00725 }
00726 
00727 void ON_3dmAnnotationSettings::Dump( ON_TextLog& text_log ) const
00728 {
00729   // TODO
00730 }
00731 
00732 void ON_3dmAnnotationSettings::Default()
00733 {
00734   memset(this,0,sizeof(*this));
00735 
00736   m_dimscale = 1.0;       // model size / plotted size
00737   m_textheight = 1.0;
00738   m_dimexe = 1.0;
00739   m_dimexo = 1.0;
00740   m_arrowlength = 1.0;
00741   m_arrowwidth = 1.0;
00742   m_centermark = 1.0;
00743 
00744   m_dimunits = ON::no_unit_system;  // units used to measure the dimension
00745   m_arrowtype = 0;     // 0: filled narrow triangular arrow
00746   m_angularunits = 0;  // 0: degrees, 1: radians
00747   m_lengthformat = 0;  // 0: decimal, ...
00748   m_angleformat = 0;   // 0: decimal degrees, ...
00749   m_textalign = 0;     // 0: above line, 1: in line, 2: horizontal
00750   m_resolution = 0;    // depends on m_lengthformat
00751                        // for decimal, digits past the decimal point
00752 
00753   m_facename.Destroy(); // [LF_FACESIZE] // windows font name
00754 
00755   m_world_view_text_scale = 1.0f;
00756   m_world_view_hatch_scale = 1.0f;
00757   m_bEnableAnnotationScaling = 1;
00758   m_bEnableHatchScaling = 1;
00759 }
00760 
00761 double ON_3dmAnnotationSettings::WorldViewTextScale() const
00762 {
00763   return m_world_view_text_scale;
00764 }
00765 
00766 double ON_3dmAnnotationSettings::WorldViewHatchScale() const
00767 {
00768   return m_world_view_hatch_scale;
00769 }
00770 
00771 void ON_3dmAnnotationSettings::SetWorldViewTextScale(double world_view_text_scale )
00772 {
00773   if ( ON_IsValid(world_view_text_scale) && world_view_text_scale > 0.0 )
00774     m_world_view_text_scale = (float)world_view_text_scale;
00775 }
00776 
00777 void ON_3dmAnnotationSettings::SetWorldViewHatchScale(double world_view_hatch_scale )
00778 {
00779   if ( ON_IsValid(world_view_hatch_scale) && world_view_hatch_scale > 0.0 )
00780     m_world_view_hatch_scale = (float)world_view_hatch_scale;
00781 }
00782 
00783 bool ON_3dmAnnotationSettings::IsAnnotationScalingEnabled() const
00784 {
00785   return m_bEnableAnnotationScaling?true:false;
00786 }
00787 
00788 void ON_3dmAnnotationSettings::EnableAnnotationScaling( bool bEnable )
00789 {
00790   m_bEnableAnnotationScaling = bEnable?1:0;
00791 }
00792 
00793 
00794 bool ON_3dmAnnotationSettings::IsHatchScalingEnabled() const
00795 {
00796   return m_bEnableHatchScaling?true:false;
00797 }
00798 
00799 void ON_3dmAnnotationSettings::EnableHatchScaling( bool bEnable )
00800 {
00801   m_bEnableHatchScaling = bEnable?1:0;
00802 }
00803 
00804 
00805 bool ON_3dmAnnotationSettings::Read( ON_BinaryArchive& file )
00806 {
00807   Default();
00808 
00809   int major_version = 0;
00810   int minor_version = 0;
00811   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00812   if ( major_version == 1 ) {
00813     if ( minor_version >= 0 ) {
00814       if (rc) rc = file.ReadDouble(&m_dimscale);
00815       if (rc) rc = file.ReadDouble(&m_textheight);
00816       if (rc) rc = file.ReadDouble(&m_dimexe);
00817       if (rc) rc = file.ReadDouble(&m_dimexo);
00818       if (rc) rc = file.ReadDouble(&m_arrowlength);
00819       if (rc) rc = file.ReadDouble(&m_arrowwidth);
00820       if (rc) rc = file.ReadDouble(&m_centermark);
00821 
00822       {
00823         int i;
00824         if (rc) 
00825         {
00826           rc = file.ReadInt( &i );
00827           if (rc)
00828             m_dimunits = ON::UnitSystem(i);
00829         }
00830       }
00831 
00832       if (rc) rc = file.ReadInt( &m_arrowtype );
00833       if (rc) rc = file.ReadInt( &m_angularunits );
00834       if (rc) rc = file.ReadInt( &m_lengthformat );
00835       if (rc) rc = file.ReadInt( &m_angleformat );
00836       if (rc) rc = file.ReadInt( &m_textalign );
00837       if (rc) rc = file.ReadInt( &m_resolution );
00838 
00839       if (rc) rc = file.ReadString( m_facename );
00840 
00841       // files that do not contain m_bEnableAnnotationScaling,
00842       // set m_bEnableAnnotationScaling = false so the display 
00843       // image does not change.
00844       m_bEnableAnnotationScaling = 0;
00845 
00846       // files that do not contain m_bEnableHatchScaling,
00847       // set m_bEnableHatchScaling = false so the display
00848       // image does not change.
00849       m_bEnableHatchScaling = 0;
00850 
00851       if ( minor_version >= 1 )
00852       {
00853         // Added 25 August 2010 chunk version 1.1
00854         double d = m_world_view_text_scale;
00855         if (rc) rc = file.ReadDouble(&d);
00856         if (rc && ON_IsValid(d) && d >= 0.0 ) m_world_view_text_scale = (float)d;
00857         if (rc) rc = file.ReadChar(&m_bEnableAnnotationScaling);
00858         if ( minor_version >= 2 )
00859         {
00860           d = m_world_view_hatch_scale;
00861           if (rc) rc = file.ReadDouble(&d);
00862           if (rc && ON_IsValid(d) && d >= 0.0) m_world_view_hatch_scale = (float)d;
00863           if (rc) rc = file.ReadChar(&m_bEnableHatchScaling);
00864         }
00865       }
00866     }
00867   }
00868   else {
00869     rc = false;
00870   }
00871   return rc;
00872 }
00873 
00874 bool ON_3dmAnnotationSettings::Write( ON_BinaryArchive& file ) const
00875 {
00876   int i;
00877   bool rc = file.Write3dmChunkVersion(1,2);
00878   // March 22, 2010 - Global DimScale abandoned and moved into DimStyles, so now
00879   // in older files, the dimscale values are multiplied into the DimStyle lengths and
00880   // DimScale is written as 1.0
00881   if (rc) rc = file.WriteDouble(1.0);
00882 
00883   if (rc) rc = file.WriteDouble(m_textheight);
00884   if (rc) rc = file.WriteDouble(m_dimexe);
00885   if (rc) rc = file.WriteDouble(m_dimexo);
00886   if (rc) rc = file.WriteDouble(m_arrowlength);
00887   if (rc) rc = file.WriteDouble(m_arrowwidth);
00888   if (rc) rc = file.WriteDouble(m_centermark);
00889 
00890   i = m_dimunits;
00891   if (rc) rc = file.WriteInt( i );
00892   if (rc) rc = file.WriteInt( m_arrowtype );
00893   if (rc) rc = file.WriteInt( m_angularunits );
00894   if (rc) rc = file.WriteInt( m_lengthformat );
00895   if (rc) rc = file.WriteInt( m_angleformat );
00896   int textalign = (int)m_textalign;
00897 
00898   // 8-20-03 lw 
00899   // How the hell did this get changed?
00900   if( file.Archive3dmVersion() <= 2)
00901   {
00902     switch( m_textalign)
00903     {
00904     case ON::dtHorizontal:
00905       textalign = 2;
00906       break;
00907     case ON::dtInLine:
00908       textalign = 1;
00909       break;
00910     default:
00911       textalign = 0;
00912       break;
00913     }
00914   }
00915   if (rc) rc = file.WriteInt( textalign );
00916   if (rc) rc = file.WriteInt( m_resolution );
00917 
00918   if (rc) rc = file.WriteString( m_facename );
00919 
00920   // Added 25 August 2010 chunk version 1.1
00921   double d = m_world_view_text_scale;
00922   if (rc) rc = file.WriteDouble(d);
00923   if (rc) rc = file.WriteChar(m_bEnableAnnotationScaling);
00924 
00925   // Added 14 January 2011 chunk version 1.2
00926   d = m_world_view_hatch_scale;
00927   if (rc) rc = file.WriteDouble(d);
00928   if (rc) rc = file.WriteChar(m_bEnableHatchScaling);
00929 
00930   return rc;
00931 }
00932 
00934 //
00935 // ON_3dmConstructionPlane
00936 //
00937 ON_3dmConstructionPlane::ON_3dmConstructionPlane()
00938 {
00939   Default();
00940 }
00941 
00942 ON_3dmConstructionPlane::~ON_3dmConstructionPlane()
00943 {
00944 }
00945 
00946 // default copy constructor and operator= work fine
00947 /*
00948 ON_3dmConstructionPlane::ON_3dmConstructionPlane(const ON_3dmConstructionPlane& src)
00949 {
00950   Default();
00951   *this = src;
00952 }
00953 ON_3dmConstructionPlane& ON_3dmConstructionPlane::operator=(const ON_3dmConstructionPlane& src)
00954 {
00955   if ( this != &src ) 
00956   {
00957     m_plane = src.m_plane;
00958     m_grid_spacing = src.m_grid_spacing;
00959     m_snap_spacing = src.m_snap_spacing;
00960     m_grid_line_count = src.m_grid_line_count;
00961     m_grid_thick_frequency = src.m_grid_thick_frequency;
00962     m_name = src.m_name;
00963     m_bDepthBuffer = src.m_bDepthBuffer;
00964   }
00965   return *this;
00966 }
00967 */
00968 
00969 void ON_3dmConstructionPlane::Dump( ON_TextLog& text_log ) const
00970 {
00971   // TODO
00972 }
00973 
00974 void ON_3dmConstructionPlane::Default()
00975 {
00976   m_name.Destroy();
00977   m_plane = ON_xy_plane;
00978 
00979   // construction grid appearance
00980         m_grid_spacing = 1.0;   // distance between grid lines
00981         m_snap_spacing = 1.0;   // distance between grid snap points
00982         m_grid_line_count = 70;     // number of grid lines in each direction
00983   m_grid_thick_frequency = 5; // thick line frequency
00984   m_bDepthBuffer = true;
00985 }
00986 
00987 bool ON_3dmConstructionPlane::Write( ON_BinaryArchive& file ) const
00988 {
00989   bool rc = file.Write3dmChunkVersion(1,1);
00990 
00991   if (rc) rc = file.WritePlane(m_plane);
00992   if (rc) rc = file.WriteDouble(m_grid_spacing);
00993   if (rc) rc = file.WriteDouble(m_snap_spacing);
00994   if (rc) rc = file.WriteInt(m_grid_line_count);
00995   if (rc) rc = file.WriteInt(m_grid_thick_frequency);
00996   if (rc) rc = file.WriteString(m_name);
00997 
00998   // added for version 1.1 chunks
00999   if (rc) rc = file.WriteBool(m_bDepthBuffer);
01000 
01001   return rc;
01002 }
01003 
01004 bool ON_3dmConstructionPlane::Read( ON_BinaryArchive& file )
01005 {
01006   Default();
01007   int major_version = 0;
01008   int minor_version = 0;
01009   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
01010   if (rc && major_version==1) 
01011   {
01012     if (rc) rc = file.ReadPlane(m_plane);
01013     if (rc) rc = file.ReadDouble(&m_grid_spacing);
01014     if (rc) rc = file.ReadDouble(&m_snap_spacing);
01015     if (rc) rc = file.ReadInt(&m_grid_line_count);
01016     if (rc) rc = file.ReadInt(&m_grid_thick_frequency);
01017     if (rc) rc = file.ReadString(m_name);
01018 
01019     if ( minor_version >= 1 )
01020     {
01021       if (rc) rc = file.ReadBool(&m_bDepthBuffer);
01022     }
01023   }
01024   return rc;
01025 }
01026 
01028 //
01029 // ON_3dmConstructionPlaneGridDefaults
01030 //
01031 ON_3dmConstructionPlaneGridDefaults::ON_3dmConstructionPlaneGridDefaults()
01032 {
01033   Default();
01034 }
01035 
01036 ON_3dmConstructionPlaneGridDefaults::~ON_3dmConstructionPlaneGridDefaults()
01037 {
01038 }
01039 
01040 ON_3dmConstructionPlaneGridDefaults::ON_3dmConstructionPlaneGridDefaults(const ON_3dmConstructionPlaneGridDefaults& src)
01041 {
01042   Default();
01043   *this = src;
01044 }
01045 ON_3dmConstructionPlaneGridDefaults& ON_3dmConstructionPlaneGridDefaults::operator=(const ON_3dmConstructionPlaneGridDefaults& src)
01046 {
01047   if ( this != &src ) {
01048     m_grid_spacing = src.m_grid_spacing;
01049     m_snap_spacing = src.m_snap_spacing;
01050     m_grid_line_count = src.m_grid_line_count;
01051     m_grid_thick_frequency = src.m_grid_thick_frequency;
01052     m_bShowGrid = src.m_bShowGrid;
01053     m_bShowGridAxes = src.m_bShowGridAxes;
01054     m_bShowWorldAxes = src.m_bShowWorldAxes;
01055   }
01056   return *this;
01057 }
01058 
01059 void ON_3dmConstructionPlaneGridDefaults::Dump(ON_TextLog& text_log) const
01060 {
01061   // TODO
01062 }
01063 
01064 void ON_3dmConstructionPlaneGridDefaults::Default()
01065 {
01066   // construction grid appearance
01067         m_grid_spacing = 1.0;   // distance between grid lines
01068         m_snap_spacing = 1.0;   // distance between grid snap points
01069         m_grid_line_count = 70;     // number of grid lines in each direction
01070   m_grid_thick_frequency = 5; // thick line frequency
01071   m_bShowGrid = true;
01072   m_bShowGridAxes = true;
01073   m_bShowWorldAxes = true;
01074 }
01075 
01076 bool ON_3dmConstructionPlaneGridDefaults::Write( ON_BinaryArchive& file ) const
01077 {
01078   bool rc = file.Write3dmChunkVersion(1,0);
01079   if (rc) rc = file.WriteDouble(m_grid_spacing);
01080   if (rc) rc = file.WriteDouble(m_snap_spacing);
01081   if (rc) rc = file.WriteInt(m_grid_line_count);
01082   if (rc) rc = file.WriteInt(m_grid_thick_frequency);
01083   if (rc) rc = file.WriteInt(m_bShowGrid);
01084   if (rc) rc = file.WriteInt(m_bShowGridAxes);
01085   if (rc) rc = file.WriteInt(m_bShowWorldAxes);
01086   return rc;
01087 }
01088 
01089 bool ON_3dmConstructionPlaneGridDefaults::Read( ON_BinaryArchive& file )
01090 {
01091   int major_version = 0;
01092   int minor_version = 0;
01093   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
01094   if (rc && major_version==1) {
01095     if (rc) rc = file.ReadDouble(&m_grid_spacing);
01096     if (rc) rc = file.ReadDouble(&m_snap_spacing);
01097     if (rc) rc = file.ReadInt(&m_grid_line_count);
01098     if (rc) rc = file.ReadInt(&m_grid_thick_frequency);
01099     if (rc) rc = file.ReadInt(&m_bShowGrid);
01100     if (rc) rc = file.ReadInt(&m_bShowGridAxes);
01101     if (rc) rc = file.ReadInt(&m_bShowWorldAxes);
01102   }
01103   return rc;
01104 }
01105 
01106 
01107 
01109 //
01110 // ON_3dmViewPosition
01111 //
01112 ON_3dmViewPosition::ON_3dmViewPosition()
01113 {
01114   Default();
01115 }
01116 
01117 ON_3dmViewPosition::~ON_3dmViewPosition()
01118 {
01119 }
01120 
01121 ON_3dmViewPosition::ON_3dmViewPosition(const ON_3dmViewPosition& src)
01122 {
01123   Default();
01124   *this = src;
01125 }
01126 
01127 ON_3dmViewPosition& ON_3dmViewPosition::operator=(const ON_3dmViewPosition& src)
01128 {
01129   if ( this != &src ) {
01130     m_wnd_left   = src.m_wnd_left;
01131     m_wnd_right  = src.m_wnd_right;
01132     m_wnd_top    = src.m_wnd_top;
01133     m_wnd_bottom = src.m_wnd_bottom;
01134     m_bMaximized = src.m_bMaximized;
01135     m_floating_viewport = src.m_floating_viewport;
01136 
01137     // reserved fields are not used
01138     // m_reserved_1 = src.m_reserved_1;
01139     // m_reserved_2 = src.m_reserved_2;
01140     // m_reserved_3 = src.m_reserved_3;
01141   }
01142   return *this;
01143 }
01144 
01145 void ON_3dmViewPosition::Default()
01146 {
01147   m_wnd_left   = 0.0;
01148   m_wnd_right  = 1.0;
01149   m_wnd_top    = 0.0;
01150   m_wnd_bottom = 1.0;
01151   m_bMaximized = false;
01152 
01153   m_floating_viewport = 0;
01154   m_reserved_1 = 0;
01155   m_reserved_2 = 0;
01156   m_reserved_3 = 0;
01157 }
01158 
01159 bool ON_3dmViewPosition::Write( ON_BinaryArchive& file ) const
01160 {
01161   int minor_version =  ( file.Archive3dmVersion() >= 5 ) ? 1 : 0;
01162 
01163   bool rc = file.Write3dmChunkVersion(1,minor_version);
01164   if (rc) 
01165   {
01166     if (rc) rc = file.WriteInt( m_bMaximized );
01167     if (rc) rc = file.WriteDouble( m_wnd_left );
01168     if (rc) rc = file.WriteDouble( m_wnd_right );
01169     if (rc) rc = file.WriteDouble( m_wnd_top );
01170     if (rc) rc = file.WriteDouble( m_wnd_bottom );
01171 
01172     if ( minor_version >= 1 )
01173     {
01174       // 13 March 2009 S. Baer
01175       // version 1.1 added support for m_floating_viewport
01176       // in V5 files.  This info is not in V4 files because
01177       // they might use this to write userdata.
01178       if (rc) rc = file.WriteChar( m_floating_viewport );
01179     }
01180   }
01181   return rc;
01182 }
01183 
01184 bool ON_3dmViewPosition::Read( ON_BinaryArchive& file )
01185 {
01186   int major_version = 0;
01187   int minor_version = 0;
01188   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
01189   double x;
01190   Default();
01191   if (rc && major_version==1) 
01192   {
01193     if (rc) rc = file.ReadInt( &m_bMaximized );
01194     if (rc) rc = file.ReadDouble( &m_wnd_left );
01195     if (rc) rc = file.ReadDouble( &m_wnd_right );
01196     if (rc) rc = file.ReadDouble( &m_wnd_top );
01197     if (rc) rc = file.ReadDouble( &m_wnd_bottom );
01198 
01199     // 13 March 2009 S. Baer
01200     // version 1.1 added support for m_floating_viewport
01201     if( rc && minor_version >= 1 )
01202     {
01203       rc = file.ReadChar( &m_floating_viewport );
01204     }
01205   }
01206 
01207   // if people put bogus values in a file, tune them up to something that will work
01208   if ( m_wnd_left > m_wnd_right ) {
01209     x = m_wnd_left; m_wnd_left = m_wnd_right; m_wnd_right = x;
01210   }
01211   if ( m_wnd_left  < 0.0 ) 
01212     m_wnd_left  = 0.0; 
01213   if ( m_wnd_right >= 1.0 ) 
01214     m_wnd_right = 1.0;
01215   if ( m_wnd_left >= m_wnd_right ) {
01216     m_wnd_left = 0.0;
01217     m_wnd_right = 1.0;
01218   }
01219   
01220   if ( m_wnd_top > m_wnd_bottom ) {
01221     x = m_wnd_top; m_wnd_top = m_wnd_bottom; m_wnd_bottom = x;
01222   }
01223   if ( m_wnd_top  < 0.0 ) 
01224     m_wnd_top  = 0.0; 
01225   if ( m_wnd_bottom >= 1.0 )
01226     m_wnd_bottom = 1.0;
01227   if ( m_wnd_top >= m_wnd_bottom ) {
01228     m_wnd_top = 0.0;
01229     m_wnd_bottom = 1.0;
01230   }
01231 
01232   return rc;
01233 }
01234 
01236 //
01237 // ON_3dmViewTraceImage
01238 //
01239 ON_3dmViewTraceImage::ON_3dmViewTraceImage()
01240 {
01241   Default();
01242 }
01243 
01244 ON_3dmViewTraceImage::~ON_3dmViewTraceImage()
01245 {
01246 }
01247 
01248 void ON_3dmViewTraceImage::Default()
01249 {
01250   m_plane = ON_xy_plane;
01251   m_width = 0.0;
01252   m_height = 0.0;
01253   m_bitmap_filename.Destroy();
01254   m_bGrayScale = true;
01255   m_bHidden = false;
01256   m_bFiltered = false;
01257 }
01258 
01259 bool ON_3dmViewTraceImage::Write( ON_BinaryArchive& file ) const
01260 {
01261   // opennurbs version  < 200307300 - version 1.0 or 1.1 chunk
01262   // opennurbs version >= 200307300 - version 1.2 chunk
01263   bool rc = file.Write3dmChunkVersion(1,3);
01264   if (rc) 
01265   {
01266     if (rc) rc = file.WriteString( m_bitmap_filename );
01267     if (rc) rc = file.WriteDouble( m_width );
01268     if (rc) rc = file.WriteDouble( m_height );
01269     if (rc) rc = file.WritePlane( m_plane );
01270 
01271     // version 1.1
01272     if (rc) rc = file.WriteBool( m_bGrayScale );
01273 
01274     // version 1.2
01275     if (rc) rc = file.WriteBool( m_bHidden );
01276     
01277     // version 1.3
01278     if (rc) rc = file.WriteBool( m_bFiltered );
01279   }
01280   return rc;
01281 }
01282 
01283 
01284 bool ON_3dmViewTraceImage::Read( ON_BinaryArchive& file )
01285 {
01286   // opennurbs version  < 200307300 - version 1.0 or 1.1 chunk
01287   // opennurbs version >= 200307300 - version 1.2 chunk
01288   int major_version = 0;
01289   int minor_version = 0;
01290   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
01291   if (rc && major_version==1)
01292   {
01293     if (rc) rc = file.ReadString( m_bitmap_filename );
01294     if (rc) rc = file.ReadDouble( &m_width );
01295     if (rc) rc = file.ReadDouble( &m_height );
01296     if (rc) rc = file.ReadPlane( m_plane );
01297     if ( minor_version >= 1 )
01298     {
01299       if (rc) rc = file.ReadBool(&m_bGrayScale);
01300       
01301       if ( minor_version >= 2 )
01302       {
01303         if (rc) rc = file.ReadBool(&m_bHidden);
01304         
01305         if ( minor_version >= 3 )
01306         {
01307           if (rc) rc = file.ReadBool( &m_bFiltered );
01308         }
01309       }
01310     }
01311   }
01312   else
01313     rc = false;
01314   return rc;
01315 }
01316 
01317 
01318 bool ON_3dmViewTraceImage::operator==( const ON_3dmViewTraceImage& other ) const
01319 {
01320   if ( m_plane != other.m_plane )
01321     return false;
01322   if ( m_width != other.m_width )
01323     return false;
01324   if ( m_height != other.m_height )
01325     return false;
01326   if( m_bitmap_filename != other.m_bitmap_filename )
01327     return false;
01328   if ( m_bHidden != other.m_bHidden )
01329     return false;
01330   if ( m_bGrayScale != other.m_bGrayScale )
01331     return false;
01332   if ( m_bFiltered != other.m_bFiltered )
01333     return false;
01334     
01335   return true;
01336 }
01337 
01338 bool ON_3dmViewTraceImage::operator!=( const ON_3dmViewTraceImage& other ) const
01339 {
01340   return operator==(other) ? false : true;
01341 }
01342 
01343 
01344 ON_3dmWallpaperImage::ON_3dmWallpaperImage()
01345 {
01346   Default();
01347 }
01348 
01349 ON_3dmWallpaperImage::~ON_3dmWallpaperImage()
01350 {
01351 }
01352 
01353 bool ON_3dmWallpaperImage::operator==( const ON_3dmWallpaperImage& other ) const
01354 {
01355   if ( m_bitmap_filename != other.m_bitmap_filename )
01356     return false;
01357   if ( m_bHidden != other.m_bHidden )
01358     return false;
01359   return ( m_bGrayScale == other.m_bGrayScale );
01360 }
01361 
01362 bool ON_3dmWallpaperImage::operator!=( const ON_3dmWallpaperImage& other ) const
01363 {
01364   return operator==(other) ? false : true;
01365 }
01366 
01367 void ON_3dmWallpaperImage::Default()
01368 {
01369   m_bitmap_filename.Destroy();
01370   m_bGrayScale = true;
01371   m_bHidden = false;
01372 }
01373 
01374 bool ON_3dmWallpaperImage::Write( ON_BinaryArchive& file ) const
01375 {
01376   // version  < 200307300 - version 1.0 chunk
01377   // version >= 200307300 - version 1.1 chunk
01378   bool rc = file.Write3dmChunkVersion(1,1);
01379   if (rc) 
01380   {
01381     if (rc) rc = file.WriteString( m_bitmap_filename );
01382     if (rc) rc = file.WriteBool( m_bGrayScale );
01383 
01384     if (rc) rc = file.WriteBool( m_bHidden ); // added in 1.1 chunk
01385   }
01386   return rc;
01387 }
01388 
01389 bool ON_3dmWallpaperImage::Read( ON_BinaryArchive& file )
01390 {
01391   // version  < 200307300 - version 1.0 chunk
01392   // version >= 200307300 - version 1.1 chunk
01393   Default();
01394   int major_version = 0;
01395   int minor_version = 0;
01396   bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
01397   if (rc && major_version==1)
01398   {
01399     if (rc) rc = file.ReadString( m_bitmap_filename );
01400     if (rc) rc = file.ReadBool( &m_bGrayScale );
01401 
01402     if ( minor_version >= 1 )
01403     {
01404       if (rc) rc = file.ReadBool( &m_bHidden );
01405     }
01406   }
01407   else
01408     rc = false;
01409   return rc;
01410 }
01411 
01412 
01414 //
01415 // ON_3dmView
01416 //
01417 
01418 ON_3dmPageSettings::ON_3dmPageSettings()
01419 {
01420   Default();
01421 }
01422 
01423 ON_3dmPageSettings::~ON_3dmPageSettings()
01424 {
01425 }
01426 
01427 void ON_3dmPageSettings::Default()
01428 {
01429   m_page_number = 0;
01430 
01431   m_width_mm  = 0.0;
01432   m_height_mm = 0.0;
01433 
01434   m_left_margin_mm   = 0.0;
01435   m_right_margin_mm  = 0.0;
01436   m_top_margin_mm    = 0.0;
01437   m_bottom_margin_mm = 0.0;
01438 
01439   m_printer_name.Destroy();
01440 }
01441 
01442 
01443 bool ON_3dmPageSettings::IsValid( ON_TextLog* text_log ) const
01444 {
01445   bool rc = true;
01446 
01447   if ( m_width_mm != 0.0 || m_height_mm != 0.0 )
01448   {
01449     if ( !ON_IsValid(m_width_mm) || m_width_mm <= 0.0 )
01450     {
01451       if ( text_log )
01452       {
01453         text_log->Print("ON_3dmPageSettings has m_width_mm = %g (should be > 0.0).\n",m_width_mm);
01454       }
01455       rc = false;
01456     }
01457     if ( !ON_IsValid(m_height_mm) || m_height_mm <= 0.0 )
01458     {
01459       if ( text_log )
01460       {
01461         text_log->Print("ON_3dmPageSettings has m_height_mm = %g (should be > 0.0).\n",m_height_mm);
01462       }
01463       rc = false;
01464     }
01465     if ( !ON_IsValid(m_top_margin_mm) || m_top_margin_mm < 0.0 )
01466     {
01467       if ( text_log )
01468       {
01469         text_log->Print("ON_3dmPageSettings has m_top_margin_mm = %g (should be >= 0.0).\n",m_top_margin_mm);
01470       }
01471       rc = false;
01472     }
01473     if ( !ON_IsValid(m_bottom_margin_mm) || m_bottom_margin_mm < 0.0 )
01474     {
01475       if ( text_log )
01476       {
01477         text_log->Print("ON_3dmPageSettings has m_bottom_margin_mm = %g (should be >= 0.0).\n",m_bottom_margin_mm);
01478       }
01479       rc = false;
01480     }
01481     if ( !ON_IsValid(m_left_margin_mm) || m_left_margin_mm < 0.0 )
01482     {
01483       if ( text_log )
01484       {
01485         text_log->Print("ON_3dmPageSettings has m_left_margin_mm = %g (should be >= 0.0).\n",m_left_margin_mm);
01486       }
01487       rc = false;
01488     }
01489     if ( !ON_IsValid(m_right_margin_mm) || m_right_margin_mm < 0.0 )
01490     {
01491       if ( text_log )
01492       {
01493         text_log->Print("ON_3dmPageSettings has m_right_margin_mm = %g (should be >= 0.0).\n",m_right_margin_mm);
01494       }
01495       rc = false;
01496     }
01497     if ( m_left_margin_mm + m_right_margin_mm >= m_width_mm )
01498     {
01499       if ( text_log )
01500       {
01501         text_log->Print("ON_3dmPageSettings has m_left_margin_mm+m_right_margin_mm = %g > %g = m_width_mm.\n",m_left_margin_mm + m_right_margin_mm, m_width_mm);
01502       }
01503       rc = false;
01504     }
01505     if ( m_top_margin_mm + m_bottom_margin_mm >= m_height_mm )
01506     {
01507       if ( text_log )
01508       {
01509         text_log->Print("ON_3dmPageSettings has m_top_margin_mm+m_bottom_margin_mm = %g > %g = m_height_mm.\n",m_top_margin_mm + m_bottom_margin_mm, m_height_mm);
01510       }
01511       rc = false;
01512     }
01513   }
01514   else
01515   {
01516     if ( m_top_margin_mm != 0.0 )
01517     {
01518       if ( text_log )
01519       {
01520         text_log->Print("ON_3dmPageSettings has m_top_margin_mm = %g (should be 0.0).\n",m_top_margin_mm);
01521       }
01522       rc = false;
01523     }
01524     if ( m_bottom_margin_mm != 0.0 )
01525     {
01526       if ( text_log )
01527       {
01528         text_log->Print("ON_3dmPageSettings has m_bottom_margin_mm = %g (should be 0.0).\n",m_bottom_margin_mm);
01529       }
01530       rc = false;
01531     }
01532     if ( m_left_margin_mm != 0.0 )
01533     {
01534       if ( text_log )
01535       {
01536         text_log->Print("ON_3dmPageSettings has m_left_margin_mm = %g (should be 0.0).\n",m_left_margin_mm);
01537       }
01538       rc = false;
01539     }
01540     if ( m_right_margin_mm != 0.0 )
01541     {
01542       if ( text_log )
01543       {
01544         text_log->Print("ON_3dmPageSettings has m_right_margin_mm = %g (should be 0.0).\n",m_right_margin_mm);
01545       }
01546       rc = false;
01547     }
01548   }
01549 
01550   return rc;
01551 }
01552 
01553 bool ON_3dmPageSettings::Write(ON_BinaryArchive& archive) const
01554 {
01555   bool rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 0 );
01556   if ( !rc )
01557     return false;
01558 
01559   for(;;)
01560   {
01561     rc = archive.WriteInt( m_page_number );
01562     if (!rc) break;
01563 
01564     rc = archive.WriteDouble(m_width_mm);
01565     if ( !rc) break;
01566 
01567     rc = archive.WriteDouble(m_height_mm);
01568     if ( !rc) break;
01569 
01570     rc = archive.WriteDouble(m_left_margin_mm);
01571     if ( !rc) break;
01572 
01573     rc = archive.WriteDouble(m_right_margin_mm);
01574     if ( !rc) break;
01575 
01576     rc = archive.WriteDouble(m_top_margin_mm);
01577     if ( !rc) break;
01578 
01579     rc = archive.WriteDouble(m_bottom_margin_mm);
01580     if ( !rc) break;
01581 
01582     rc = archive.WriteString(m_printer_name);
01583     if (!rc) break;
01584 
01585     break;
01586   }
01587 
01588   if ( !archive.EndWrite3dmChunk() )
01589     rc = false;
01590 
01591   return rc;
01592 }
01593 
01594 bool ON_3dmPageSettings::Read(ON_BinaryArchive& archive)
01595 {
01596   int major_version = 0;
01597   int minor_version = 0;
01598   bool rc = archive.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &major_version, &minor_version );
01599   if ( !rc )
01600     return false;
01601 
01602   for(;;)
01603   {
01604     rc = (1 == major_version);
01605     if (!rc) break;
01606 
01607     rc = archive.ReadInt(&m_page_number );
01608     if (!rc) break;
01609 
01610     rc = archive.ReadDouble(&m_width_mm);
01611     if ( !rc) break;
01612 
01613     rc = archive.ReadDouble(&m_height_mm);
01614     if ( !rc) break;
01615 
01616     rc = archive.ReadDouble(&m_left_margin_mm);
01617     if ( !rc) break;
01618 
01619     rc = archive.ReadDouble(&m_right_margin_mm);
01620     if ( !rc) break;
01621 
01622     rc = archive.ReadDouble(&m_top_margin_mm);
01623     if ( !rc) break;
01624 
01625     rc = archive.ReadDouble(&m_bottom_margin_mm);
01626     if ( !rc) break;
01627 
01628     rc = archive.ReadString(m_printer_name);
01629     if (!rc) break;
01630 
01631     break;
01632   }
01633 
01634   if ( !archive.EndRead3dmChunk() )
01635     rc = false;
01636 
01637   return rc;
01638 }
01639 
01641 //
01642 // ON_3dmView
01643 //
01644 ON_3dmView::ON_3dmView()
01645 {
01646   Default();
01647 } 
01648 
01649 ON_3dmView::~ON_3dmView()
01650 {
01651 }
01652 
01653 void ON_3dmView::Dump( ON_TextLog& dump ) const
01654 {
01655   const wchar_t* wsViewName = m_name;
01656   if ( !wsViewName )
01657     wsViewName = L"";
01658   ON::view_projection proj = m_vp.Projection();
01659   
01660 
01661   ON_3dPoint camLoc;
01662   ON_3dVector camX, camY, camZ;
01663   ON_BOOL32 bValidCamera = m_vp.GetCameraFrame( camLoc, camX, camY, camZ );
01664   double frus_left,frus_right,frus_bottom,frus_top,frus_near,frus_far;
01665   ON_BOOL32 bValidFrustum = m_vp.GetFrustum(&frus_left,&frus_right,&frus_bottom,&frus_top,&frus_near,&frus_far);
01666   int port_left, port_right, port_bottom, port_top, port_near, port_far;
01667   ON_BOOL32 bValidPort = m_vp.GetScreenPort(&port_left,&port_right,&port_bottom,&port_top,&port_near,&port_far);
01668 
01669   const char* sProjectionName;
01670   switch(proj)
01671   {
01672   case ON::parallel_view: sProjectionName = "parallel"; break;
01673   case ON::perspective_view: sProjectionName = "perspective"; break;
01674   case ON::unknown_view:
01675   default: 
01676     sProjectionName = "unknown";
01677     break;
01678   }
01679   dump.Print("Viewport: name = \"%ls\" projection = %s\n",wsViewName,sProjectionName);
01680 
01681   dump.PushIndent();
01682 
01683   if ( bValidCamera ) 
01684   {
01685     dump.Print("viewport camera frame\n"
01686            "  location = %g, %g, %g\n"
01687            "  X = %g, %g, %g\n"
01688            "  Y = %g, %g, %g\n"
01689            "  Z = %g, %g, %g\n",
01690            camLoc.x,camLoc.y,camLoc.z,
01691            camX.x,camX.y,camX.z,
01692            camY.x,camY.y,camY.z,
01693            camZ.x,camZ.y,camZ.z
01694            );
01695     ON_3dPoint target_point = TargetPoint();
01696     double target_distance = target_point.DistanceTo( camLoc );
01697     dump.Print("camera target\n"
01698                "  distance = %g\n"
01699                "  point = %g,%g,%g\n",
01700                target_distance,
01701                target_point.x,target_point.y,target_point.z
01702                );
01703   }
01704 
01705 
01706   if ( bValidFrustum ) {
01707     dump.Print("view frustum\n"
01708            "  left   = %g, right = %g\n"
01709            "  bottom = %g, top   = %g\n"
01710            "  near   = %g, far   = %g\n",
01711            frus_left,frus_right,
01712            frus_bottom,frus_top,
01713            frus_near,frus_far
01714            );
01715   }
01716 
01717   if ( bValidPort ) {
01718     // location of viewport window on screen
01719     dump.Print("viewport window screen location\n"
01720            "  left   = %4d, right = %4d\n"
01721            "  bottom = %4d, top   = %4d\n"
01722            "  near   = %4d, far   = %4d\n",
01723            port_left,port_right,
01724            port_bottom,port_top,
01725            port_near,port_far
01726            );
01727   }
01728 
01729 
01730   // relative position of viewport window in application main frame
01731   double rel_left,rel_right,rel_bottom,rel_top;
01732   rel_left = m_position.m_wnd_left;
01733   rel_right = m_position.m_wnd_right;
01734   rel_bottom = m_position.m_wnd_bottom;
01735   rel_top = m_position.m_wnd_top;
01736   dump.Print("relative viewport window position in application frame window\n"
01737              "  left   = %6.2f%%, right = %6.2f%%\n"
01738              "  bottom = %6.2f%%, top   = %6.2f%%\n",
01739              100.0*rel_left, 100.0*rel_right,
01740              100.0*rel_bottom, 100.0*rel_top
01741              );
01742 
01743   dump.PopIndent();
01744 
01745 }
01746 
01747 void ON_3dmView::Default()
01748 {
01749   m_name.Destroy();
01750 
01751   m_vp.Initialize();
01752   // ON_3dmView::m_target is obsolete - keep it in sync with m_vp.m_target_point
01753   OBSOLETE_3DM_VIEW_TARGET = m_vp.TargetPoint(); 
01754 
01755   m_cplane.Default();
01756   m_display_mode_id = ON_nil_uuid;
01757   m_display_mode = ON::wireframe_display;
01758   m_view_type = ON::model_view_type;
01759   m_position.Default();
01760   if ( m_vp.Projection() == ON::parallel_view ) {
01761     m_cplane.m_plane.CreateFromFrame( m_cplane.m_plane.origin, m_vp.CameraX(), m_vp.CameraY() );
01762   }
01763   m_bShowConstructionGrid = true;
01764   m_bShowConstructionAxes = true;
01765   m_bShowWorldAxes = true;
01766 
01767   m_trace_image.Default();
01768   m_wallpaper_image.Default();
01769 
01770   m_page_settings.Default();
01771 
01772   m_bLockedProjection = false;
01773 }
01774 
01775 ON_3dPoint ON_3dmView::TargetPoint() const
01776 {
01777   ON_3dPoint target_point = m_vp.TargetPoint();
01778   if ( OBSOLETE_3DM_VIEW_TARGET != target_point )
01779   {
01780     ON_ERROR("Obsolete ON_3dmView::m_target is not set correctly");
01781     const_cast<ON_3dmView*>(this)->OBSOLETE_3DM_VIEW_TARGET = target_point; // fix error condition
01782   }
01783   return target_point;
01784 }
01785 
01786 bool ON_3dmView::SetTargetPoint(ON_3dPoint target_point)
01787 {
01788   bool rc = m_vp.SetTargetPoint(target_point);
01789   OBSOLETE_3DM_VIEW_TARGET = m_vp.TargetPoint(); // keep obsolete m_target in sync with m_vp.m_target_point
01790   return rc;
01791 }
01792 
01793 bool ON_3dmView::IsValid(ON_TextLog* text_log) const
01794 {
01795   bool rc = m_vp.IsValid(text_log)?true:false;
01796   while(rc)
01797   {
01798     switch(m_view_type)
01799     {
01800     case ON::model_view_type:
01801       if ( m_page_settings.m_width_mm != 0.0 || m_page_settings.m_height_mm != 0.0 )
01802       {
01803         if ( text_log )
01804         {
01805           text_log->Print("ON_3dmView has m_view_type = ON::model_view_type but m_page_settings width,height = (%g,%g) (both should be zero).\n",
01806                           m_page_settings.m_width_mm,
01807                           m_page_settings.m_height_mm);
01808         }
01809         rc = false;
01810       }
01811       //if (    m_nested_view_position.m_min.x != 0.0 || m_nested_view_position.m_max.x != 0.0
01812       //     || m_nested_view_position.m_min.y != 0.0 || m_nested_view_position.m_max.y != 0.0
01813       //     || m_nested_view_position.m_min.z != 0.0 || m_nested_view_position.m_max.z != 0.0 )
01814       //{
01815       //  if ( text_log )
01816       //  {
01817       //    text_log->Print("ON_3dmView has m_view_type = ON::model_view_type and m_nested_view_position is not identically zero.\n");
01818       //  }
01819       //  rc = false;
01820       //}
01821       //if ( !ON_UuidIsNil(m_parent_viewport_id) )
01822       //{
01823       //  if ( text_log )
01824       //  {
01825       //    text_log->Print("ON_3dmView has m_view_type = ON::model_view_type and m_parent_viewport_id is not nil\n");
01826       //  }
01827       //  rc = false;
01828       //}
01829       break;
01830     case ON::page_view_type:
01831       //if (    m_nested_view_position.m_min.x != 0.0 || m_nested_view_position.m_max.x != 0.0
01832       //     || m_nested_view_position.m_min.y != 0.0 || m_nested_view_position.m_max.y != 0.0
01833       //     || m_nested_view_position.m_min.z != 0.0 || m_nested_view_position.m_max.z != 0.0 )
01834       //{
01835       //  if ( text_log )
01836       //  {
01837       //    text_log->Print("ON_3dmView has m_view_type = ON::page_view_type and m_nested_view_position is not identically zero.\n");
01838       //  }
01839       //  rc = false;
01840       //}
01841       //if ( !ON_UuidIsNil(m_parent_viewport_id) )
01842       //{
01843       //  if ( text_log )
01844       //  {
01845       //    text_log->Print("ON_3dmView has m_view_type = ON::page_view_type and m_parent_viewport_id is not nil\n");
01846       //  }
01847       //  rc = false;
01848       //}
01849       if ( m_page_settings.m_width_mm <= 0.0 || m_page_settings.m_height_mm <= 0.0 )
01850       {
01851         if ( text_log )
01852         {
01853           text_log->Print("ON_3dmView has m_view_type = ON::page_view_type but page width,height = (%g,%g)\n",
01854                           m_page_settings.m_width_mm,
01855                           m_page_settings.m_height_mm);
01856         }
01857         rc = false;
01858       }
01859       break;
01860 
01861     case ON::nested_view_type:
01862       if ( m_page_settings.m_width_mm != 0.0 || m_page_settings.m_height_mm != 0.0 )
01863       {
01864         if ( text_log )
01865         {
01866           text_log->Print("ON_3dmView has m_view_type = ON::nested_view_type but m_page_settings width,height = (%g,%g) (both should be zero).\n",
01867                           m_page_settings.m_width_mm,
01868                           m_page_settings.m_height_mm);
01869         }
01870         rc = false;
01871       }
01872       //if ( ON_UuidIsNil(m_parent_viewport_id) )
01873       //{
01874       //  if ( text_log )
01875       //  {
01876       //    text_log->Print("ON_3dmView has m_view_type = ON::nested_view_type and m_parent_viewport_id is nil.\n");
01877       //  }
01878       //  rc = false;
01879       //}
01880 
01881       //if ( !m_nested_view_position.IsValid() 
01882       //     || m_nested_view_position.m_min.x >= m_nested_view_position.m_max.x
01883       //     || m_nested_view_position.m_min.y >= m_nested_view_position.m_max.y
01884       //     || m_nested_view_position.m_min.z != m_nested_view_position.m_max.z )
01885       //{
01886       //  if ( text_log )
01887       //  {
01888       //    text_log->Print("ON_3dmView has m_view_type = ON::nested_view_type and m_nested_view_position is bogus.\n");
01889       //  }
01890       //  rc = false;
01891       //}
01892       break;
01893 
01894     default:
01895       if ( text_log )
01896       {
01897         text_log->Print("ON_3dmView m_view_type = %d (illegal enum value)\n",m_view_type);
01898       }
01899       rc = false;
01900       break;
01901     }
01902     if (rc)
01903       break;
01904 
01905 
01906 
01907 
01908     break;
01909   }
01910   return rc;
01911 }
01912 
01913 bool ON_3dmView::Write( ON_BinaryArchive& file ) const
01914 {
01915   // Everything in a view is in a subchunk so new records can 
01916   // be added to a view and old I/O code will still
01917   // work.
01918   bool rc = true;
01919 
01920   // 27 June 2008 Dale Lear
01921   //   I added support for saving userdata attached to
01922   //   the m_vp ON_Viewport.  Ideally, I would just call
01923   //   file.WriteObject(m_vp), but userdata support is being
01924   //   added years after millions of files have been written
01925   //   by calling m_vp.Write().
01926   if(rc) {
01927     rc = file.BeginWrite3dmChunk( TCODE_VIEW_VIEWPORT, 0 );
01928     if(rc) {
01929       rc = m_vp.Write(file)?true:false;
01930       if ( !file.EndWrite3dmChunk() )
01931         rc = false;
01932     }
01933   }
01934   if(rc && 0 != m_vp.FirstUserData() && file.Archive3dmVersion() >= 4) 
01935   {
01936     rc = file.BeginWrite3dmChunk( TCODE_VIEW_VIEWPORT_USERDATA, 0 );
01937     if(rc) 
01938     {
01939       rc = file.WriteObjectUserData(m_vp);
01940       // write a "fake" TCODE_OPENNURBS_CLASS_END end of class 
01941       // mark so I can use
01942       // ON_BinaryArchive::ReadObjectUserData() 
01943       // to read this user data.
01944       if ( file.BeginWrite3dmChunk( TCODE_OPENNURBS_CLASS_END, 0 ) ) 
01945       {
01946         if ( !file.EndWrite3dmChunk() )
01947           rc = false;
01948       }
01949       else
01950       {
01951         rc = false;
01952       }
01953       if ( !file.EndWrite3dmChunk() ) // end of TCODE_VIEW_VIEWPORT_USERDATA
01954         rc = false;
01955     }
01956   }
01957   if(rc) {
01958     rc = file.BeginWrite3dmChunk( TCODE_VIEW_CPLANE, 0 );
01959     if(rc) {
01960       rc = m_cplane.Write(file);
01961       if ( !file.EndWrite3dmChunk() )
01962         rc = false;
01963     }
01964   }
01965   if(rc) {
01966     rc = file.BeginWrite3dmChunk( TCODE_VIEW_TARGET, 0 );
01967     if(rc) {
01968       ON_3dPoint target_point = TargetPoint();
01969       if(rc) rc = file.WritePoint(target_point);
01970       if ( !file.EndWrite3dmChunk() )
01971         rc = false;
01972     }
01973   }
01974   if(rc) {
01975     rc = file.BeginWrite3dmChunk( TCODE_VIEW_DISPLAYMODE, m_display_mode );
01976     if(rc) {
01977       if ( !file.EndWrite3dmChunk() )
01978         rc = false;
01979     }
01980   }
01981   if(rc) {
01982     rc = file.BeginWrite3dmChunk( TCODE_VIEW_POSITION, 0 );
01983     if(rc) {
01984       if(rc) rc = m_position.Write(file);
01985       if ( !file.EndWrite3dmChunk() )
01986         rc = false;
01987     }
01988   }
01989   if(rc) {
01990     rc = file.BeginWrite3dmChunk( TCODE_VIEW_SHOWCONGRID, m_bShowConstructionGrid );
01991     if(rc) {
01992       if ( !file.EndWrite3dmChunk() )
01993         rc = false;
01994     }
01995   }
01996   if(rc) {
01997     rc = file.BeginWrite3dmChunk( TCODE_VIEW_SHOWCONAXES, m_bShowConstructionAxes );
01998     if(rc) {
01999       if ( !file.EndWrite3dmChunk() )
02000         rc = false;
02001     }
02002   }
02003   if(rc) {
02004     rc = file.BeginWrite3dmChunk( TCODE_VIEW_SHOWWORLDAXES, m_bShowWorldAxes );
02005     if(rc) {
02006       if ( !file.EndWrite3dmChunk() )
02007         rc = false;
02008     }
02009   }
02010   if(rc) {
02011     rc = file.BeginWrite3dmChunk( TCODE_VIEW_NAME, 0 );
02012     if(rc) {
02013       if(rc) rc = file.WriteString(m_name);
02014       if ( !file.EndWrite3dmChunk() )
02015         rc = false;
02016     }
02017   }
02018   if(rc) {
02019     rc = file.BeginWrite3dmChunk( TCODE_VIEW_TRACEIMAGE, 0 );
02020     if(rc) 
02021     {
02022       if(rc) 
02023         rc = m_trace_image.Write(file);
02024       if ( !file.EndWrite3dmChunk() )
02025         rc = false;
02026     }
02027   }
02028   if(rc) 
02029   {
02030     rc = file.BeginWrite3dmChunk( TCODE_VIEW_WALLPAPER, 0 );
02031     if(rc) 
02032     {
02033       if(rc) rc = file.WriteString(m_wallpaper_image.m_bitmap_filename);
02034       if ( !file.EndWrite3dmChunk() )
02035         rc = false;
02036     }
02037   }
02038   if(rc && file.Archive3dmVersion() >= 3 ) 
02039   {
02040     // Added 5 June 2003 to support additional wallpaper attributes.
02041     // Older versions of Rhino/opennurbs
02042     // will just skip this chunk and get filename from the
02043     // TCODE_VIEW_WALLPAPER chunk written above.
02044     rc = file.BeginWrite3dmChunk( TCODE_VIEW_WALLPAPER_V3, 0 );
02045     if(rc) 
02046     {
02047       if(rc) 
02048         rc = m_wallpaper_image.Write(file);
02049       if ( !file.EndWrite3dmChunk() )
02050         rc = false;
02051     }
02052   }
02053 
02054   if (rc && file.Archive3dmVersion() >= 4)
02055   {
02056     // 23 March 2005 Dale Lear:
02057     //   The "chunks" above trace their history back to Rhino 1.0;
02058     //   The TCODE_VIEW_ATTRIBUTES chunk uses a chunk version so that
02059     //   new view information can be added without inventing a new 
02060     //   TCODE for each new piece of information.
02061 
02062     rc = file.BeginWrite3dmChunk( TCODE_VIEW_ATTRIBUTES, 0 );
02063     if (rc)
02064     {
02065       rc = file.Write3dmChunkVersion( 1, 4 ); // (there are no 1.0 fields)
02066 
02067       while(rc)
02068       {
02069         // 1.1 fields (there are no 1.0 fields)
02070         rc = file.WriteInt( m_view_type );
02071         if (!rc) break;
02072         
02073         // obsolete values - superceded by m_page_settings
02074         rc = file.WriteDouble( m_page_settings.m_width_mm );
02075         if (!rc) break;
02076 
02077         rc = file.WriteDouble( m_page_settings.m_height_mm );
02078         if (!rc) break;
02079 
02080         ON_UUID obsolete_parent_viewport_id;
02081         memset(&obsolete_parent_viewport_id,0,sizeof(obsolete_parent_viewport_id));
02082         rc = file.WriteUuid( obsolete_parent_viewport_id );
02083         if (!rc) break;
02084 
02085         ON_BoundingBox obsolete_nested_view_position;
02086         rc = file.WriteBoundingBox( obsolete_nested_view_position );
02087         if (!rc) break;
02088 
02089         // 28 feb 2006 version 1.2 fields
02090         rc = file.WriteUuid(m_display_mode_id);
02091         if (!rc) break;
02092 
02093         rc = m_page_settings.Write(file);
02094         if (!rc) break;
02095 
02096         // 7 March 2006 version 1.3 fields
02097         rc = file.WriteBool(m_bLockedProjection);
02098         if (!rc) break;
02099 
02100         // 12 December 2010 version 1.4
02101         rc = file.WriteArray(m_clipping_planes);
02102         if (!rc) break;
02103 
02104         break;
02105       }
02106 
02107       // Since BeginWrite3dmChunk() returned true, EndWrite3dmChunk()
02108       // must be called even when rc is false
02109       if ( !file.EndWrite3dmChunk() )
02110         rc = false;
02111     }
02112   }
02113 
02114   // required TCODE_ENDOFTABLE chunk - marks end of view table
02115   if ( rc ) {
02116     rc = file.BeginWrite3dmChunk( TCODE_ENDOFTABLE, 0 );
02117     if ( rc ) {
02118       if ( !file.EndWrite3dmChunk() )
02119         rc = false;
02120     }
02121   }
02122   return rc;
02123 }
02124 
02125 bool ON_3dmView::Read( ON_BinaryArchive& file )
02126 {
02127   // Everything in a view is in a subchunk so new records can 
02128   // be added to a view and old I/O code will still
02129   // work.
02130   unsigned int tcode = 0;
02131   ON__INT64 big_value = 0;
02132   int i32;
02133   bool rc = true;
02134 
02135   Default();
02136 
02137   bool bHaveTargetPoint = false;
02138   bool bHaveViewport = false;
02139   ON_3dPoint target_point = ON_3dPoint::UnsetPoint;
02140 
02141   while(rc) {
02142     rc = file.BeginRead3dmBigChunk(&tcode,&big_value);
02143     if (!rc)
02144       break;
02145     switch(tcode) 
02146     {
02147     case TCODE_VIEW_CPLANE:
02148       rc = m_cplane.Read(file);
02149       break;
02150     case TCODE_VIEW_VIEWPORT:
02151       rc = m_vp.Read(file)?true:false;
02152       if (rc)
02153         bHaveViewport = true;
02154       break;
02155     case TCODE_VIEW_VIEWPORT_USERDATA:
02156       // 27 June 2008 Dale Lear
02157       //   I added support for saving userdata attached to
02158       //   the m_vp ON_Viewport.  Ideally, the ON_Viewport
02159       //   would be read by calling file.ReadObject(), but
02160       //   userdata support is being added years after 
02161       //   millions of files have been written by calling
02162       //   m_vp.Write()/Read().
02163       rc = file.ReadObjectUserData(m_vp);
02164       break;
02165     case TCODE_VIEW_SHOWCONGRID:
02166       m_bShowConstructionGrid = big_value?true:false;
02167       break;
02168     case TCODE_VIEW_SHOWCONAXES:
02169       m_bShowConstructionAxes = big_value?true:false;
02170       break;
02171     case TCODE_VIEW_SHOWWORLDAXES:
02172       m_bShowWorldAxes = big_value?true:false;
02173       break;
02174     case TCODE_VIEW_TRACEIMAGE:
02175       rc = m_trace_image.Read(file);
02176       break;
02177     case TCODE_VIEW_WALLPAPER:
02178       // used prior to 5 June 2003 and still written
02179       // after 5 June 2003 so older Rhinos/opennurbs
02180       // will not loose the filename information.
02181       rc = file.ReadString(m_wallpaper_image.m_bitmap_filename);
02182       m_wallpaper_image.m_bGrayScale = true;
02183       break;
02184     case TCODE_VIEW_WALLPAPER_V3:
02185       // Added 5 June 2003 to support additional wallpaper attributes.
02186       rc = m_wallpaper_image.Read(file);
02187       break;
02188     case TCODE_VIEW_TARGET:
02189       rc = file.ReadPoint(target_point);
02190       if (rc)
02191         bHaveTargetPoint = true;
02192       break;
02193     case TCODE_VIEW_DISPLAYMODE:
02194       i32 = (int)big_value;
02195       m_display_mode = ON::DisplayMode(i32);
02196       break;
02197     case TCODE_VIEW_NAME:
02198       rc = file.ReadString(m_name);
02199       break;
02200     case TCODE_VIEW_POSITION:
02201       rc = m_position.Read(file);
02202       break;
02203 
02204     case TCODE_VIEW_ATTRIBUTES:
02205       {
02206         int major_version = 0;
02207         int minor_version = 0;
02208         rc = file.Read3dmChunkVersion(&major_version,&minor_version);
02209         // there are no 1.0 fields in this chunk
02210         while ( rc 
02211                 && major_version == 1 && minor_version >= 1 
02212                 && file.Archive3dmVersion() >= 4 
02213                 && file.ArchiveOpenNURBSVersion() >= 200503170 )
02214         {
02215           // Added 23 March 2005 Dale Lear
02216           // 1.1 fields (there are no 1.0 fields)
02217           i32 = 0;
02218           rc = file.ReadInt( &i32 );
02219           if (!rc) break;
02220           m_view_type = ON::ViewType(i32);
02221           
02222           rc = file.ReadDouble( &m_page_settings.m_width_mm );
02223           if (!rc) break;
02224 
02225           rc = file.ReadDouble( &m_page_settings.m_height_mm );
02226           if (!rc) break;
02227 
02228           ON_UUID obsolete_parent_viewport_id;
02229           rc = file.ReadUuid( obsolete_parent_viewport_id );
02230           if (!rc) break;
02231 
02232           ON_BoundingBox obsolete_nested_view_position;
02233           rc = file.ReadBoundingBox( obsolete_nested_view_position );
02234           if (!rc) break;
02235 
02236           if ( minor_version >= 2 )
02237           {
02238             // 28 feb 2006 version 1.2 field
02239             rc = file.ReadUuid(m_display_mode_id);
02240             if (!rc) break;
02241 
02242             rc = m_page_settings.Read(file);
02243             if (!rc) break;
02244 
02245             if ( minor_version >= 3 )
02246             {
02247               rc = file.ReadBool(&m_bLockedProjection);
02248               if (!rc) break;
02249 
02250               if ( minor_version >= 4 )
02251               {
02252                 rc = file.ReadArray(m_clipping_planes);
02253                 if (!rc) break;
02254               }
02255             }
02256           }
02257 
02258           // Add new inforamation here - ask Dale Lear for help.
02259 
02260           break;
02261         }
02262       }
02263       break;
02264     }
02265 
02266     if (!file.EndRead3dmChunk())
02267       rc = false;
02268     if ( tcode == TCODE_ENDOFTABLE )
02269       break;
02270   }
02271 
02272   if (    bHaveViewport 
02273        && bHaveTargetPoint
02274        && target_point.IsValid()
02275        && !OBSOLETE_3DM_VIEW_TARGET.IsValid()
02276      )
02277   {
02278     // m_target is obsolete, but some older files
02279     // have the good value stored in ON_3dmView. In this
02280     // case use the good value as the target point.
02281     SetTargetPoint(target_point); // sets both this->m_target and m_vp.m_target_point
02282   }
02283   else
02284   {
02285     // Assume the value on m_vp.m_target_point is the right one and
02286     // Keep the obsolete m_target in sync with m_vp.m_target_point.
02287     OBSOLETE_3DM_VIEW_TARGET = m_vp.TargetPoint();
02288   }
02289 
02290   return rc;
02291 }
02292 
02293 ON_EarthAnchorPoint::ON_EarthAnchorPoint()
02294 {
02295   Default();
02296 }
02297 
02298 ON_EarthAnchorPoint::~ON_EarthAnchorPoint()
02299 {
02300 }
02301 
02302 void ON_EarthAnchorPoint::Default()
02303 {
02304   m_earth_basepoint_latitude = 0.0;
02305   m_earth_basepoint_longitude = 0.0;
02306   m_earth_basepoint_elevation = 0.0;
02307   m_earth_basepoint_elevation_zero = 0;
02308 
02309   m_model_basepoint.Set(0.0,0.0,0.0);
02310   m_model_north.Set(0.0,1.0,0.0);
02311   m_model_east.Set(1.0,0.0,0.0);
02312 
02313   m_id = ON_nil_uuid;
02314   m_name.Destroy();
02315   m_description.Destroy(); 
02316   m_url.Destroy();
02317   m_url_tag.Destroy();
02318 }
02319 
02320 int ON_EarthAnchorPoint::CompareEarthLocation(const ON_EarthAnchorPoint* a, const ON_EarthAnchorPoint* b)
02321 {
02322   if ( !a )
02323   {
02324     return b ? -1 : 0;
02325   }
02326   if (!b)
02327   {
02328     return 1;
02329   }
02330 
02331   double xa = a->m_earth_basepoint_longitude;
02332   double xb = b->m_earth_basepoint_longitude;
02333   if ( !ON_IsValid(xa) )
02334   {
02335     if ( ON_IsValid(xb) ) return -1;
02336   }
02337   else if ( !ON_IsValid(xb) )
02338   {
02339     return 1;
02340   }
02341   else
02342   {
02343     while(xa <= 0.0)
02344       xa += 360.0;
02345     while(xa > 360.0)
02346       xa -= 360.0;
02347     while(xb <= 0.0)
02348       xb += 360.0;
02349     while(xb > 360.0)
02350       xb -= 360.0;
02351     if ( xa < xb ) return -1;
02352     if ( xa > xb ) return 1;
02353   }
02354 
02355   xa = a->m_earth_basepoint_latitude;
02356   xb = b->m_earth_basepoint_latitude;
02357   if ( !ON_IsValid(xa) )
02358   {
02359     if ( ON_IsValid(xb) ) return -1;
02360   }
02361   else if ( !ON_IsValid(xb) )
02362   {
02363     return 1;
02364   }
02365   else
02366   {
02367     while(xa <= 0.0)
02368       xa += 360.0;
02369     while(xa > 360.0)
02370       xa -= 360.0;
02371     while(xb <= 0.0)
02372       xb += 360.0;
02373     while(xb > 360.0)
02374       xb -= 360.0;
02375     if ( xa < xb ) return -1;
02376     if ( xa > xb ) return 1;
02377   }
02378 
02379   int i = a->m_earth_basepoint_elevation_zero - b->m_earth_basepoint_elevation_zero;
02380   if ( i != 0 )
02381     return i;
02382 
02383   xa = a->m_earth_basepoint_elevation;
02384   xb = b->m_earth_basepoint_elevation;
02385   if ( !ON_IsValid(xa) )
02386   {
02387     if ( ON_IsValid(xb) ) return -1;
02388   }
02389   else if ( !ON_IsValid(xb) )
02390   {
02391     return 1;
02392   }
02393   else
02394   {
02395     if ( xa < xb ) return -1;
02396     if ( xa > xb ) return 1;
02397   }
02398 
02399   return 0;   
02400 }
02401 
02402 int ON_EarthAnchorPoint::CompareModelDirection(const ON_EarthAnchorPoint* a, const ON_EarthAnchorPoint* b)
02403 {
02404   if ( !a )
02405   {
02406     return b ? -1 : 0;
02407   }
02408   if (!b)
02409   {
02410     return 1;
02411   }
02412 
02413   int i = ON_ComparePoint(3,false,&a->m_model_basepoint.x,&b->m_model_basepoint.x);
02414   if ( !i )
02415   {
02416     i = ON_ComparePoint(3,false,&a->m_model_north.x,&b->m_model_north.x);
02417     if ( !i )
02418     {
02419       i = ON_ComparePoint(3,false,&a->m_model_east.x,&b->m_model_east.x);
02420     }
02421   }
02422   return i;  
02423 }
02424 
02425 int ON_EarthAnchorPoint::CompareIdentification(const ON_EarthAnchorPoint* a, const ON_EarthAnchorPoint* b)
02426 {
02427   if ( !a )
02428   {
02429     return b ? -1 : 0;
02430   }
02431   if (!b)
02432   {
02433     return 1;
02434   }
02435 
02436   int i = ON_UuidCompare(a->m_id,b->m_id);
02437   if ( !i)
02438   {
02439     i = a->m_name.Compare(b->m_name);
02440     if (!i)
02441     {
02442       i = a->m_description.Compare(b->m_description);
02443       if (!i)
02444       {
02445         i = a->m_url.CompareNoCase(b->m_url);
02446         if ( !i)
02447         {
02448           i = a->m_url_tag.Compare(b->m_url_tag);
02449         }
02450       }
02451     }
02452   }
02453   return i;  
02454 }
02455 
02456 int ON_EarthAnchorPoint::Compare(const ON_EarthAnchorPoint* a, const ON_EarthAnchorPoint* b)
02457 {
02458   int i = ON_EarthAnchorPoint::CompareEarthLocation(a,b);
02459   if ( !i)
02460   {
02461     i = ON_EarthAnchorPoint::CompareModelDirection(a,b);
02462     if (!i)
02463     {
02464       i = ON_EarthAnchorPoint::CompareIdentification(a,b);
02465     }
02466   }
02467   return i;
02468 }
02469 
02470 bool ON_EarthAnchorPoint::Read( ON_BinaryArchive& file )
02471 {
02472   Default();
02473   int major_version = 0;
02474   int minor_version = 0;
02475   bool rc = file.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
02476   if ( !rc )
02477     return false;
02478 
02479   for(;;)
02480   {
02481     rc = (1 == major_version);
02482     if (!rc) break;
02483 
02484     rc = file.ReadDouble(&m_earth_basepoint_latitude);
02485     if (!rc) break;
02486     rc = file.ReadDouble(&m_earth_basepoint_longitude);
02487     if (!rc) break;
02488     rc = file.ReadDouble(&m_earth_basepoint_elevation);
02489     if (!rc) break;
02490     rc = file.ReadPoint(m_model_basepoint);
02491     if (!rc) break;
02492     rc = file.ReadVector(m_model_north);
02493     if (!rc) break;
02494     rc = file.ReadVector(m_model_east);
02495     if (!rc) break;
02496 
02497     if ( minor_version >= 1 )
02498     {
02499       // 1.1 fields
02500       rc = file.ReadInt(&m_earth_basepoint_elevation_zero);
02501       if (!rc) break;
02502       rc = file.ReadUuid(m_id);
02503       if (!rc) break;
02504       rc = file.ReadString(m_name);
02505       if (!rc) break;
02506       rc = file.ReadString(m_description);
02507       if (!rc) break;
02508       rc = file.ReadString(m_url);
02509       if (!rc) break;
02510       rc = file.ReadString(m_url_tag);
02511       if (!rc) break;
02512     }
02513 
02514     break;
02515   }
02516 
02517   if ( !file.EndRead3dmChunk() )
02518     rc = false;
02519 
02520   return rc;
02521 }
02522 
02523 bool ON_EarthAnchorPoint::Write( ON_BinaryArchive& file ) const
02524 {
02525   bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1);
02526   if ( !rc )
02527     return false;
02528 
02529   for(;;)
02530   {
02531     rc = file.WriteDouble(m_earth_basepoint_latitude);
02532     if (!rc) break;
02533     rc = file.WriteDouble(m_earth_basepoint_longitude);
02534     if (!rc) break;
02535     rc = file.WriteDouble(m_earth_basepoint_elevation);
02536     if (!rc) break;
02537     rc = file.WritePoint(m_model_basepoint);
02538     if (!rc) break;
02539     rc = file.WriteVector(m_model_north);
02540     if (!rc) break;
02541     rc = file.WriteVector(m_model_east);
02542     if (!rc) break;
02543 
02544     // 1.1 fields
02545     rc = file.WriteInt(m_earth_basepoint_elevation_zero);
02546     if (!rc) break;
02547     rc = file.WriteUuid(m_id);
02548     if (!rc) break;
02549     rc = file.WriteString(m_name);
02550     if (!rc) break;
02551     rc = file.WriteString(m_description);
02552     if (!rc) break;
02553     rc = file.WriteString(m_url);
02554     if (!rc) break;
02555     rc = file.WriteString(m_url_tag);
02556     if (!rc) break;
02557 
02558 
02559     break;
02560   }
02561 
02562   if ( !file.EndWrite3dmChunk() )
02563     rc = false;
02564 
02565   return rc;
02566 }
02567 
02568 
02569 bool ON_EarthAnchorPoint::GetModelCompass(ON_Plane& model_compass) const
02570 {
02571   ON_Plane mc;
02572   mc.xaxis = m_model_east;
02573   mc.yaxis = m_model_north;
02574   if ( fabs(mc.xaxis.Length() - 1.0) > ON_SQRT_EPSILON )
02575   {
02576     if ( !mc.xaxis.Unitize() )
02577       return false;
02578   }
02579   if ( fabs(mc.yaxis.Length() - 1.0) > ON_SQRT_EPSILON )
02580   {
02581     if ( !mc.yaxis.Unitize() )
02582       return false;
02583   }
02584   double d = mc.xaxis*mc.yaxis;
02585   if ( fabs(d) > ON_SQRT_EPSILON )
02586   {
02587     // assume north is correct
02588     mc.xaxis.x -= d*mc.yaxis.x;
02589     mc.xaxis.y -= d*mc.yaxis.y;
02590     mc.xaxis.z -= d*mc.yaxis.z;
02591     if( !mc.xaxis.Unitize() )
02592       return false;
02593   }
02594   mc.zaxis = ON_CrossProduct(mc.xaxis,mc.yaxis);
02595   if ( fabs(mc.zaxis.Length() - 1.0) > ON_SQRT_EPSILON )
02596   {
02597     if ( !mc.zaxis.Unitize() )
02598       return false;
02599   }
02600   mc.origin = m_model_basepoint;
02601   mc.UpdateEquation();
02602   model_compass = mc;
02603   return model_compass.IsValid();
02604 }
02605 
02606 bool ON_EarthAnchorPoint::GetModelToEarthXform(
02607           const ON_UnitSystem& model_unit_system,
02608           ON_Xform& model_to_earth
02609           ) const
02610 {
02611   // The orient_model rotates the model so that
02612   //   xaxis runs from west to east
02613   //   yaxis runs from south to north
02614   //   zaxis points "up"
02615   ON_Plane model_compass;
02616   bool rc = GetModelCompass( model_compass );
02617   model_compass.origin = m_model_basepoint;
02618   model_compass.UpdateEquation();
02619   ON_Xform orient_model;
02620   orient_model.Rotation( model_compass, ON_xy_plane  );
02621 
02622   ON_Xform coord_change(1.0);
02623 
02624   const double lat_radians = m_earth_basepoint_latitude/180.0*ON_PI;
02625   const double cos_lat = cos(lat_radians);
02626   const double sin_lat = sin(lat_radians);
02627   
02628   // get radius of earth at this latitude
02629   const double earth_polar_radius      = 6356750.0; // Earth's radius at poles (meters)
02630   const double earth_equatorial_radius = 6378135.0; // Earth's radius at equator (meters)
02631   ON_2dVector r;
02632   r.x = cos_lat;
02633   r.y = sin_lat*(earth_equatorial_radius/earth_polar_radius);
02634   double earth_radius = earth_equatorial_radius/r.Length();
02635   if ( earth_radius > earth_equatorial_radius )
02636     earth_radius = earth_equatorial_radius;
02637   else if ( earth_radius < earth_polar_radius )
02638     earth_radius = earth_polar_radius;
02639 
02640   const double meters_per_degree_latitude = earth_radius*ON_PI/180.0; // meters per degree of latitude
02641 
02642   const double model_to_meters_scale = ON::UnitScale(model_unit_system, ON::meters);
02643   const double north_south_scale  = model_to_meters_scale/meters_per_degree_latitude;
02644   const double east_west_scale = ( 1.0e100*cos_lat < north_south_scale )
02645                                ? north_south_scale
02646                                : north_south_scale/cos_lat;
02647 
02648   coord_change.m_xform[0][0] = east_west_scale;
02649   coord_change.m_xform[0][3] = m_earth_basepoint_longitude;
02650   coord_change.m_xform[1][1] = north_south_scale;
02651   coord_change.m_xform[1][3] = m_earth_basepoint_latitude;
02652   coord_change.m_xform[2][2] = model_to_meters_scale;
02653   coord_change.m_xform[3][2] = m_earth_basepoint_elevation;
02654 
02655   model_to_earth = coord_change*orient_model;
02656 
02657   return rc;
02658 }
02659 
02660 
02662 //
02663 // ON_3dmSettings
02664 //
02665 
02666 void ON_3dmSettings::Default()
02667 {
02668   // default properties
02669   m_model_URL.Destroy();
02670   m_model_basepoint.Set(0.0,0.0,0.0);
02671   m_earth_anchor_point.Default();
02672   m_ModelUnitsAndTolerances.Default();
02673   m_PageUnitsAndTolerances.Default();
02674   m_RenderMeshSettings.Default();
02675   m_CustomRenderMeshSettings.Default();
02676 
02677   m_IO_settings.Default();
02678   
02679   // 28 Febuary 2003 Dale Lear:
02680   //     Add analysis mesh default settings
02681   m_AnalysisMeshSettings.DefaultAnalysisMeshParameters();
02682 
02683   m_AnnotationSettings.Default();
02684   m_named_cplanes.Empty();
02685   m_named_views.Empty();
02686   m_views.Empty();
02687   m_active_view_id = ON_nil_uuid;
02688 
02689   m_current_layer_index = 0;
02690   m_current_font_index = 0;
02691   m_current_dimstyle_index = 0;
02692 
02693   m_current_material_index = -1; // -1 = "default" material
02694   m_current_material_source = ON::material_from_layer;
02695 
02696   m_current_color.SetRGB(0,0,0);
02697   m_current_color_source = ON::color_from_layer;
02698 
02699   m_current_linetype_index = -1;  // -1 = "default" solid line
02700   m_current_linetype_source = ON::linetype_from_layer;
02701 
02702   m_current_plot_color = ON_UNSET_COLOR;
02703   m_current_plot_color_source = ON::plot_color_from_layer;
02704 
02705   m_current_wire_density = 1;
02706   m_RenderSettings.Default();
02707   m_GridDefaults.Default();
02708 
02709   m_linetype_display_scale = 1.0;
02710 
02711   m_plugin_list.Destroy();
02712 }
02713 
02714 ON_3dmSettings::ON_3dmSettings()
02715 {
02716   Default();
02717 };
02718 
02719 ON_3dmSettings::~ON_3dmSettings()
02720 {
02721 }
02722 
02723 ON_3dmIOSettings::ON_3dmIOSettings()
02724 {
02725   Default();
02726 }
02727 
02728 void ON_3dmIOSettings::Default()
02729 {
02730   m_bSaveTextureBitmapsInFile = false;
02731   // 7 February 2011 - default changed to 1.
02732   //m_idef_link_update = 0;
02733   m_idef_link_update = 1;
02734 }
02735 
02736 
02737 bool ON_3dmIOSettings::Read(ON_BinaryArchive& file)
02738 {
02739   Default();
02740 
02741   int major_version = 0;
02742   int minor_version = 0;
02743   bool rc = file.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
02744   if (!rc)
02745     return false;
02746 
02747   for(;;)
02748   {
02749     rc = ( 1 == major_version );
02750     if (!rc) break;
02751 
02752     rc = file.ReadBool(&m_bSaveTextureBitmapsInFile);
02753     if(!rc) break;
02754 
02755     rc = file.ReadInt(&m_idef_link_update);
02756     if(!rc) break;
02757 
02758     if ( 0 == m_idef_link_update && file.Archive3dmVersion() >= 5 )
02759     {
02760       // 7 February 2011 - old 0 value is no longer an option.
02761       m_idef_link_update = 1;
02762     }
02763 
02764     break;
02765   }
02766 
02767   if ( !file.EndRead3dmChunk() )
02768     rc = false;
02769 
02770   return rc;
02771 }
02772 
02773 bool ON_3dmIOSettings::Write(ON_BinaryArchive& file) const
02774 {
02775   bool rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
02776   if (!rc)
02777     return false;
02778   for(;;)
02779   {
02780     rc = file.WriteBool(m_bSaveTextureBitmapsInFile);
02781     if(!rc) break;
02782 
02783     int i = m_idef_link_update;
02784     if ( 0 == i && file.Archive3dmVersion() >= 5 )
02785     {
02786       // 7 February 2011 - old 0 value is no longer an option.
02787       i = 1;
02788     }
02789     rc = file.WriteInt(i);
02790     if(!rc) break;
02791 
02792     break;
02793   }
02794   if ( !file.EndWrite3dmChunk() )
02795     rc = false;
02796 
02797   return rc;
02798 }
02799 
02800 
02801 static bool ON_3dmSettings_Read_v1_TCODE_NAME(ON_BinaryArchive& file, ON_wString& str )
02802 {
02803   // reads legacy 1.0 named view TCODE_NAME chunk
02804   str.Empty();
02805   int len = 0;
02806   bool rc = file.ReadInt( &len );
02807   if (rc && len > 0) {
02808     char* name = (char*)oncalloc( 1, len + 1);
02809     rc = file.ReadString( len, name );
02810     if (rc)
02811       str = name; // ASCII -> UNICODE
02812     if (name)
02813       onfree(name);
02814   }
02815   return rc;
02816 }
02817 
02818 static bool ON_3dmSettings_Read_v1_TCODE_CPLANE(ON_BinaryArchive& file, ON_3dmConstructionPlane& cplane)
02819 {
02820   // reads legacy 1.0 named view TCODE_CPLANE chunk
02821 
02822   // do NOT call cplane.Default() here
02823   bool rc = true;
02824         ON_3dPoint origin;
02825         ON_3dVector xaxis, yaxis;
02826         double gridsize;
02827         int gridsections, gridthicksections;
02828   if (rc) rc = file.ReadPoint( origin );
02829   if (rc) rc = file.ReadVector( xaxis );
02830   if (rc) rc = file.ReadVector( yaxis );
02831   if (rc) 
02832   {
02833     rc = file.ReadDouble(&gridsize);
02834     if (rc) 
02835     {
02836       rc = file.ReadInt(&gridsections);
02837       if (rc) 
02838       {
02839         rc = file.ReadInt(&gridthicksections);
02840         if (rc) 
02841         {
02842           cplane.m_plane.CreateFromFrame(origin,xaxis,yaxis);
02843           cplane.m_grid_line_count = gridsections;
02844           cplane.m_grid_thick_frequency = gridthicksections;
02845           cplane.m_grid_spacing = gridsize;
02846           cplane.m_snap_spacing = gridsize;
02847         }
02848         }
02849     }
02850   }
02851   return rc;
02852 }
02853 
02854 static bool ON_3dmSettings_Read_v1_TCODE_VIEW(ON_BinaryArchive& file, ON_3dmView& view)
02855 {
02856   // reads legacy 1.0 named view TCODE_VIEW chunk
02857   // do NOT call view.Default() here
02858   bool rc = true;
02859 
02860         int projection, valid;
02861         double angle1, angle2, angle3, viewsize, cameradist;
02862   ON_3dPoint target_point;
02863   while(rc)
02864   {
02865     rc = file.ReadInt(&projection);
02866     if (!rc) break;
02867     rc = file.ReadInt(&valid);
02868     if (!rc) break;
02869     rc = file.ReadPoint( target_point );
02870     if (!rc) break;
02871     rc = file.ReadDouble( &angle1 );
02872     if (!rc) break;
02873     rc = file.ReadDouble( &angle2 );
02874     if (!rc) break;
02875     rc = file.ReadDouble( &angle3 );
02876     if (!rc) break;
02877     rc = file.ReadDouble( &viewsize );
02878     if (!rc) break;
02879     rc = file.ReadDouble( &cameradist );
02880     if (!rc) break;
02881 
02882     if( cameradist <= 0.0 || cameradist >= ( DBL_MAX / 2.0 ))
02883       cameradist = 100.0;
02884     if( viewsize <= 0.0 || viewsize >= ( DBL_MAX / 2.0 ))
02885       viewsize = 0.125;
02886     ON_ViewportFromRhinoView(
02887           projection == 2 ? ON::perspective_view : ON::parallel_view,
02888           target_point,
02889           angle1,
02890           angle2,
02891           angle3,
02892           viewsize,
02893           cameradist,
02894           100, // screen_width, 
02895           100, // screen_height,
02896           view.m_vp
02897           );
02898     // keep obsolete view.m_target in sync with view.m_vp.m_target_point
02899     view.OBSOLETE_3DM_VIEW_TARGET = view.m_vp.TargetPoint(); 
02900     break;
02901   }
02902 
02903   return rc;
02904 }
02905 
02906 static bool ON_3dmSettings_Read_v1_TCODE_NAMED_VIEW(ON_BinaryArchive& file, ON_3dmView& view)
02907 {
02908   // reads legacy 1.0 named view TCODE_NAMED_VIEW chunk
02909   view.Default();
02910   bool rc = true;
02911   unsigned int tcode;
02912   ON__INT64 big_value;
02913 
02914   while(rc) 
02915   {
02916     rc = file.BeginRead3dmBigChunk( &tcode, &big_value );
02917     if (!rc )
02918       break;
02919     switch(tcode) {
02920 
02921     case TCODE_NAME:
02922       rc = ON_3dmSettings_Read_v1_TCODE_NAME(file,view.m_name);
02923       break;
02924 
02925     case TCODE_CPLANE:
02926       rc = ON_3dmSettings_Read_v1_TCODE_CPLANE(file,view.m_cplane);
02927       break;
02928 
02929     case TCODE_VIEW:
02930       rc = ON_3dmSettings_Read_v1_TCODE_VIEW( file, view );
02931       break;
02932 
02933     case TCODE_SHOWGRID:
02934       view.m_bShowConstructionGrid = big_value?true:false;
02935       break;
02936                                                 
02937     case TCODE_SHOWGRIDAXES:
02938       view.m_bShowConstructionAxes = big_value?true:false;
02939       break;
02940                                                 
02941     case TCODE_SHOWWORLDAXES:
02942       view.m_bShowWorldAxes = big_value?true:false;
02943       break;                    
02944       
02945     }
02946     if ( !file.EndRead3dmChunk() )
02947       rc = false;
02948     if ( tcode == TCODE_ENDOFTABLE )
02949       break;
02950   }
02951   return rc;
02952 }
02953 
02954 static bool ON_3dmSettings_Read_v1_TCODE_NAMED_CPLANE(ON_BinaryArchive& file, ON_3dmConstructionPlane& cplane)
02955 {
02956   // reads legacy 1.0 named construction plane TCODE_NAMED_CPLANE chunk
02957   cplane.Default();
02958 
02959   bool rc = true;
02960   unsigned int tcode;
02961   ON__INT64 big_value;
02962 
02963   while(rc) 
02964   {
02965     rc = file.BeginRead3dmBigChunk( &tcode, &big_value );
02966     if (!rc )
02967       break;
02968     switch(tcode) {
02969 
02970     case TCODE_NAME:
02971       rc = ON_3dmSettings_Read_v1_TCODE_NAME(file, cplane.m_name );
02972       break;
02973 
02974     case TCODE_CPLANE:
02975       rc = ON_3dmSettings_Read_v1_TCODE_CPLANE(file, cplane );
02976       break;
02977     }
02978     if ( !file.EndRead3dmChunk() )
02979       rc = false;
02980     if ( tcode == TCODE_ENDOFTABLE )
02981       break;
02982   }
02983   return rc;
02984 }
02985 
02986 static bool ON_3dmSettings_Read_v1_TCODE_UNIT_AND_TOLERANCES(ON_BinaryArchive& file, ON_3dmUnitsAndTolerances& UnitsAndTolerances )
02987 {
02988   bool rc = true;
02989   int v = 0;
02990   int us = 0;
02991   UnitsAndTolerances.Default();
02992   if (rc) 
02993     rc = file.ReadInt( &v ); // should get v = 1
02994   if (rc) 
02995     rc = file.ReadInt( &us );
02996   switch (us) 
02997   {
02998   case 0: // NO_UNIT_SYSTEM:
02999     UnitsAndTolerances.m_unit_system.m_unit_system = ON::no_unit_system;
03000     break;
03001   case 1: // MICRONS:
03002     UnitsAndTolerances.m_unit_system.m_unit_system = ON::microns;
03003     break;
03004   case 2: // MILLIMETERS:
03005     UnitsAndTolerances.m_unit_system.m_unit_system = ON::millimeters;
03006     break;
03007   case 3: // CENTIMETERS:
03008     UnitsAndTolerances.m_unit_system.m_unit_system = ON::centimeters;
03009     break;
03010   case 4: // METERS:
03011     UnitsAndTolerances.m_unit_system.m_unit_system = ON::meters;
03012     break;
03013   case 5: // KILOMETERS:
03014     UnitsAndTolerances.m_unit_system.m_unit_system = ON::kilometers;
03015     break;
03016   case 6: // MICROINCHES:
03017     UnitsAndTolerances.m_unit_system.m_unit_system = ON::microinches;
03018     break;
03019   case 7: // MILS:
03020     UnitsAndTolerances.m_unit_system.m_unit_system = ON::mils;
03021     break;
03022   case 8: // INCHES:
03023     UnitsAndTolerances.m_unit_system.m_unit_system = ON::inches;
03024     break;
03025   case 9: // FEET:
03026     UnitsAndTolerances.m_unit_system.m_unit_system = ON::feet;
03027     break;
03028   case 10: // MILES:
03029     UnitsAndTolerances.m_unit_system.m_unit_system = ON::miles;
03030     break;
03031   default: // NO_UNIT_SYSTEM:
03032     UnitsAndTolerances.m_unit_system.m_unit_system = ON::no_unit_system;
03033     break;
03034   }
03035   if (rc) rc = file.ReadDouble( &UnitsAndTolerances.m_absolute_tolerance );
03036   if (rc) rc = file.ReadDouble( &UnitsAndTolerances.m_relative_tolerance );
03037   if (rc) rc = file.ReadDouble( &UnitsAndTolerances.m_angle_tolerance );
03038   return rc;
03039 }
03040 
03041 static bool ON_3dmSettings_Read_v1_TCODE_VIEWPORT(ON_BinaryArchive& file, ON_3dmView& view)
03042 {
03043   // reads legacy 1.0 named construction plane TCODE_VIEWPORT chunk
03044   view.Default();
03045   bool rc = true;
03046   ON__UINT32 tcode;
03047   ON__INT64 big_value;
03048 
03049   double clipdist = 0.0;
03050   double snapsize = 0.0;
03051 
03052   int chunk_count = 0;// debugging counter
03053   for ( chunk_count = 0; rc; chunk_count++ )
03054   {
03055     rc = file.BeginRead3dmBigChunk( &tcode, &big_value );
03056     if (!rc )
03057       break;
03058     switch(tcode) {
03059 
03060     case TCODE_NEAR_CLIP_PLANE:
03061       rc = file.ReadDouble(&clipdist);
03062       break;
03063 
03064     case TCODE_SNAPSIZE:
03065       rc = file.ReadDouble(&snapsize);
03066       break;
03067       
03068     case TCODE_NAME:
03069       rc = ON_3dmSettings_Read_v1_TCODE_NAME(file,view.m_name);
03070       break;
03071 
03072     case TCODE_CPLANE:
03073       rc = ON_3dmSettings_Read_v1_TCODE_CPLANE(file,view.m_cplane);
03074       break;
03075 
03076     case TCODE_VIEW:
03077       rc = ON_3dmSettings_Read_v1_TCODE_VIEW( file, view );
03078       break;
03079 
03080     case TCODE_SHOWGRID:
03081       view.m_bShowConstructionGrid = big_value?true:false;
03082       break;
03083                                                 
03084     case TCODE_SHOWGRIDAXES:
03085       view.m_bShowConstructionAxes = big_value?true:false;
03086       break;
03087                                                 
03088     case TCODE_SHOWWORLDAXES:
03089       view.m_bShowWorldAxes = big_value?true:false;
03090       break;                    
03091       
03092     case TCODE_VIEWPORT_POSITION:
03093       rc = file.ReadDouble(&view.m_position.m_wnd_left);
03094       rc = file.ReadDouble(&view.m_position.m_wnd_top);
03095       rc = file.ReadDouble(&view.m_position.m_wnd_right);
03096       rc = file.ReadDouble(&view.m_position.m_wnd_bottom);
03097       break;
03098                                                 
03099     case TCODE_VIEWPORT_TRACEINFO:
03100       {
03101         ON_3dPoint origin;
03102         ON_3dVector xaxis, yaxis;
03103         if (rc) rc = file.ReadPoint( origin );
03104         if (rc) rc = file.ReadVector( xaxis );
03105         if (rc) rc = file.ReadVector( yaxis );
03106         view.m_trace_image.m_plane.CreateFromFrame(origin,xaxis,yaxis);
03107         if (rc) rc = file.ReadDouble(&view.m_trace_image.m_width);
03108         if (rc) rc = file.ReadDouble(&view.m_trace_image.m_height);
03109         if (rc) rc = ON_3dmSettings_Read_v1_TCODE_NAME(file,view.m_trace_image.m_bitmap_filename);
03110       }
03111       break;
03112       
03113     case TCODE_VIEWPORT_WALLPAPER:
03114       rc = ON_3dmSettings_Read_v1_TCODE_NAME(file,view.m_wallpaper_image.m_bitmap_filename);
03115       break;
03116                                                 
03117     case TCODE_HIDE_TRACE:
03118       // TCODE_HIDE_TRACE was used in early 1.0 betas.  
03119       // It should have add the short bit set and it is no longer used.
03120       // This case is here so that these old files will read correctly.
03121       tcode |= TCODE_SHORT; // so goo skip will work
03122       break;
03123       
03124     case TCODE_MAXIMIZED_VIEWPORT:
03125       if ( big_value )
03126         view.m_position.m_bMaximized = true;
03127       break; 
03128 
03129     case TCODE_VIEWPORT_DISPLAY_MODE: // short TCODE with display mode value
03130       switch ( big_value ) 
03131       {
03132       case 0: // wireframe working mode
03133         view.m_display_mode = ON::wireframe_display;
03134         break;
03135       case 1: // shaded working mode
03136         view.m_display_mode = ON::shaded_display;
03137         break;
03138       }
03139       break;
03140                                                 
03141     }
03142     if ( !file.EndRead3dmChunk() )
03143       rc = false;
03144     if ( tcode == TCODE_ENDOFTABLE )
03145       break;
03146   }
03147   return rc;
03148 }
03149 
03150 bool ON_3dmSettings::Read_v1( ON_BinaryArchive& file )
03151 {
03152   bool bGotSomething = false;
03153   bool rc = false;
03154   // read settings from old version 1 file
03155   size_t pos0 = file.CurrentPosition();
03156 
03157   // need to start at the beginning of the file
03158   ON__UINT32 tcode;
03159   ON__INT64 big_value;
03160   rc = file.SeekFromStart(32)?true:false; // skip 32 byte header
03161   
03162   int chunk_count = 0; // debugging counter
03163   for ( chunk_count = 0; rc; chunk_count++ )
03164   {
03165     rc = file.BeginRead3dmBigChunk( &tcode, &big_value );
03166     if ( !rc ) 
03167       break; // assume we are at the end of the file
03168 
03169     switch(tcode) {
03170     case TCODE_VIEWPORT:
03171       bGotSomething = true;
03172       {
03173         ON_3dmView view;
03174         rc = ON_3dmSettings_Read_v1_TCODE_VIEWPORT(file, view);
03175         if (rc)
03176           m_views.Append(view);
03177       }
03178       break;
03179 
03180     case TCODE_NAMED_CPLANE:
03181       bGotSomething = true;
03182       {
03183         ON_3dmConstructionPlane cplane;
03184         rc = ON_3dmSettings_Read_v1_TCODE_NAMED_CPLANE(file,cplane);
03185         if (rc)
03186           m_named_cplanes.Append(cplane);
03187       }
03188       break;
03189 
03190     case TCODE_NAMED_VIEW:
03191       bGotSomething = true;
03192       {
03193         ON_3dmView view;
03194         rc = ON_3dmSettings_Read_v1_TCODE_NAMED_VIEW(file, view);
03195         if (rc)
03196           m_named_views.Append(view);
03197       }
03198       break;
03199     
03200     case TCODE_UNIT_AND_TOLERANCES:
03201       bGotSomething = true;
03202       rc = ON_3dmSettings_Read_v1_TCODE_UNIT_AND_TOLERANCES(file,m_ModelUnitsAndTolerances);
03203       break;
03204     }
03205 
03206     rc = file.EndRead3dmChunk();
03207   }
03208 
03209   file.SeekFromStart(pos0);
03210   return bGotSomething;
03211 }
03212 
03213 bool ON_3dmSettings::Read_v2(ON_BinaryArchive& file )
03214 {
03215   bool rc = true;
03216   ON__UINT32 tcode;
03217   ON__INT64 big_value;
03218 
03219   while(rc) 
03220   {
03221     tcode = 0;
03222     big_value = 0;
03223     rc = file.BeginRead3dmBigChunk( &tcode, &big_value );
03224     if ( !rc )
03225       break;
03226 
03227     switch(tcode) 
03228     {
03229     case TCODE_SETTINGS_PLUGINLIST: 
03230       {
03231         int major_version = 0, minor_version = 0, count = 0, i;
03232         rc = file.Read3dmChunkVersion(&major_version,&minor_version);
03233         if (rc && 1 == major_version && minor_version >= 0 )
03234         {
03235           rc = file.ReadInt( &count );
03236           if ( count > 0 )
03237           {
03238             for ( i = 0; rc && i < count; i++ )
03239             {
03240               rc = m_plugin_list.AppendNew().Read(file);
03241             }
03242           }
03243         }
03244       }
03245       break;
03246       
03247     case TCODE_SETTINGS_UNITSANDTOLS: // units and tolerances
03248       rc = m_ModelUnitsAndTolerances.Read(file);
03249       // Copy model settings to page settings so reading old files
03250       // will work right.  If the file is new enough to have page
03251       // units and tolerances in it, they get read later.
03252       m_PageUnitsAndTolerances = m_ModelUnitsAndTolerances;
03253       break;
03254       
03255     case TCODE_SETTINGS_RENDERMESH:
03256       rc = m_RenderMeshSettings.Read(file);
03257       break;
03258       
03259     case TCODE_SETTINGS_ANALYSISMESH:
03260       rc = m_AnalysisMeshSettings.Read(file);
03261       break;
03262       
03263     case TCODE_SETTINGS_ANNOTATION:
03264       rc = m_AnnotationSettings.Read(file);
03265       break;
03266       
03267     case TCODE_SETTINGS_NAMED_CPLANE_LIST: // named cplanes
03268       {
03269         m_named_cplanes.Empty();
03270         ON__UINT32 subtcode = 0;
03271         ON__INT64 subvalue = 0;
03272         int count, i;
03273         rc = file.ReadInt(&count);
03274         for ( i = 0; i < count && rc ; i++ ) {
03275           rc = file.BeginRead3dmBigChunk( &subtcode, &subvalue );
03276           if (rc ) {
03277             if ( subtcode != TCODE_VIEW_CPLANE )
03278               rc = false;
03279             else {
03280               ON_3dmConstructionPlane& cplane = m_named_cplanes.AppendNew();
03281               rc = cplane.Read(file);
03282             }
03283             if ( !file.EndRead3dmChunk() ) {
03284               rc = false;
03285             }
03286           }
03287         }
03288       }
03289       break;
03290       
03291     case TCODE_SETTINGS_NAMED_VIEW_LIST: // named views
03292       {
03293         m_named_views.Empty();
03294         ON__UINT32 subtcode = 0;
03295         ON__INT64 subvalue = 0;
03296         int count, i;
03297         rc = file.ReadInt(&count);
03298         for ( i = 0; i < count && rc ; i++ ) 
03299         {
03300           rc = file.BeginRead3dmBigChunk( &subtcode, &subvalue );
03301           if (rc ) 
03302           {
03303             if ( subtcode != TCODE_VIEW_RECORD )
03304               rc = false;
03305             else 
03306             {
03307               ON_3dmView& cplane = m_named_views.AppendNew();
03308               rc = cplane.Read(file);
03309             }
03310             if ( !file.EndRead3dmChunk() )
03311             {
03312               rc = false;
03313             }
03314           }
03315         }
03316       }
03317       break;
03318       
03319     case TCODE_SETTINGS_VIEW_LIST: // active view is first in list
03320       {
03321         m_views.Empty();
03322         ON__UINT32 subtcode = 0;
03323         ON__INT64 subvalue = 0;
03324         int count, i;
03325         rc = file.ReadInt(&count);
03326         m_views.Reserve(count);
03327         for ( i = 0; i < count && rc ; i++ ) 
03328         {
03329           rc = file.BeginRead3dmBigChunk( &subtcode, &subvalue );
03330           if (rc ) 
03331           {
03332             if ( subtcode != TCODE_VIEW_RECORD )
03333               rc = false;
03334             else 
03335             {
03336               ON_3dmView& view = m_views.AppendNew();
03337               rc = view.Read(file);
03338             }
03339             if ( !file.EndRead3dmChunk() )
03340             {
03341               rc = false;
03342             }
03343           }
03344         }
03345       }
03346       break;
03347       
03348     case TCODE_SETTINGS__NEVER__USE__THIS:
03349       {
03350         if ( 28 == big_value )
03351         {
03352           // 23 March 2005 Dale Lear - this was the ON_LineStyle
03353           //                           and a linesytlesource int
03354           //                           that never got used.
03355           unsigned char b[24];
03356           if (rc) rc = file.ReadByte(24,b);
03357           // The other 4 bytes are a 32 bit chunk crc
03358           // that gets read by EndRead3dmChunk()
03359         }
03360       }
03361       break;
03362 
03363     case TCODE_SETTINGS_CURRENT_LAYER_INDEX:
03364       if ( big_value < -1 || big_value > 0x7FFFFFFF )
03365       {
03366         ON_ERROR("ON_3dmSettings::Read_v2() - TCODE_SETTINGS_CURRENT_LAYER_INDEX - invalid layer index value");
03367       }
03368       else
03369       {
03370         m_current_layer_index = (int)big_value;
03371       }
03372       break;
03373       
03374     case TCODE_SETTINGS_CURRENT_FONT_INDEX:
03375       if ( big_value < -1 || big_value > 0x7FFFFFFF )
03376       {
03377         ON_ERROR("ON_3dmSettings::Read_v2() - TCODE_SETTINGS_CURRENT_FONT_INDEX - invalid font index value");
03378       }
03379       else
03380       {
03381         // in archives with opennurbs version >= 200106100
03382         m_current_font_index = (int)big_value;
03383       }
03384       break;
03385       
03386     case TCODE_SETTINGS_CURRENT_DIMSTYLE_INDEX:
03387       if ( big_value < -1 || big_value > 0x7FFFFFFF )
03388       {
03389         ON_ERROR("ON_3dmSettings::Read_v2() - TCODE_SETTINGS_CURRENT_DIMSTYLE_INDEX - invalid dimstyle index value");
03390       }
03391       else
03392       {
03393         // in archives with opennurbs version >= 200106100
03394         m_current_dimstyle_index = (int)big_value;
03395       }
03396       break;
03397       
03398     case TCODE_SETTINGS_CURRENT_MATERIAL_INDEX:
03399       {
03400         int i32 = 0;
03401         if (rc) rc = file.ReadInt( &m_current_material_index );
03402         if (rc) rc = file.ReadInt( &i32 );
03403         if (rc) m_current_material_source = ON::ObjectMaterialSource(i32);
03404       }
03405       break;
03406       
03407     case TCODE_SETTINGS_CURRENT_COLOR:
03408       {
03409         int i32 = 0;
03410         if (rc) rc = file.ReadColor( m_current_color );
03411         if (rc) rc = file.ReadInt( &i32 );
03412         if (rc) m_current_color_source = ON::ObjectColorSource(i32);
03413       }
03414       break;
03415       
03416     case TCODE_SETTINGS_CURRENT_WIRE_DENSITY:
03417       if ( big_value < -2 || big_value > 0x7FFFFFFF )
03418       {
03419         ON_ERROR("ON_3dmSettings::Read_v2() - TCODE_SETTINGS_CURRENT_WIRE_DENSITY - invalid current_wire_density value");
03420       }
03421       else
03422       {
03423         m_current_wire_density = (int)big_value;
03424       }
03425       break;
03426       
03427     case TCODE_SETTINGS_RENDER:
03428       rc = m_RenderSettings.Read(file);
03429       break;
03430 
03431     case TCODE_SETTINGS_GRID_DEFAULTS:
03432       rc = m_GridDefaults.Read(file);
03433       break;
03434 
03435     case TCODE_SETTINGS_MODEL_URL: // added 21 June 2001
03436       rc = file.ReadString(m_model_URL);
03437       break;
03438 
03439     case TCODE_SETTINGS_ATTRIBUTES:
03440       {
03441         int major_version = 0;
03442         int minor_version = 0;
03443         for(;;)
03444         {
03445           rc = file.Read3dmChunkVersion(&major_version,&minor_version);
03446           if (!rc) break;
03447           if ( 1 == major_version )
03448           {
03449             // version 1.0 fields 23 March 2005
03450             rc = file.ReadDouble( &m_linetype_display_scale );
03451             if (!rc) break;
03452 
03453             rc = file.ReadColor(m_current_plot_color);
03454             if (!rc) break;
03455   
03456             int i;
03457             rc = file.ReadInt(&i);
03458             if (!rc) break;
03459             m_current_plot_color_source = ON::PlotColorSource(i);
03460 
03461             rc = file.ReadInt(&m_current_linetype_index);
03462             if (!rc) break;
03463 
03464             rc = file.ReadInt(&i);
03465             if (!rc) break;
03466             m_current_linetype_source = ON::ObjectLinetypeSource(i);
03467 
03468             if ( minor_version >= 1 )
03469             {
03470               // Added 6 Feb 2006
03471               int mjv = 1, mnv = 1;
03472               rc = file.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&mjv,&mnv);
03473               if (rc)
03474               {
03475                 rc = m_PageUnitsAndTolerances.Read(file);
03476                 if ( !file.EndRead3dmChunk() )
03477                   rc = false;
03478               }
03479 
03480 
03481               if ( minor_version >= 2 )
03482               {
03483                 // 1 Mar 2006 1.2 fields
03484                 rc = file.ReadUuid(m_active_view_id);
03485                 if (!rc) break;
03486 
03487                 if ( minor_version >= 3 )
03488                 {
03489                   rc = file.ReadPoint( m_model_basepoint);
03490                   if (!rc) break;
03491                   rc = m_earth_anchor_point.Read(file);
03492                   if (!rc) break;
03493 
03494                   if ( minor_version >= 4 )
03495                   {
03496                     rc = file.ReadBool(&m_IO_settings.m_bSaveTextureBitmapsInFile);
03497                     if (rc && minor_version >= 5)
03498                     {
03499                       rc = m_IO_settings.Read(file);
03500                       if (rc && minor_version >= 6 )
03501                       {
03502                         // 7 June 2006
03503                         m_CustomRenderMeshSettings.Read(file);
03504                       }
03505                     }
03506                   }
03507                 }
03508               }
03509             }
03510 
03511           }
03512 
03513           break;
03514         }
03515       }
03516       break;
03517 
03518     default:
03519       // information added in future will be skipped by file.EndRead3dmChunk()
03520       break;
03521     }
03522 
03523     if ( !file.EndRead3dmChunk() )
03524       rc = false;
03525     if ( TCODE_ENDOFTABLE == tcode )
03526       break;
03527   }
03528 
03529   return rc;
03530 }
03531 
03532 bool ON_3dmSettings::Read(ON_BinaryArchive& file )
03533 {
03534   bool rc = false;
03535 
03536   Default();
03537 
03538   if ( 1 == file.Archive3dmVersion() ) 
03539   {
03540     rc = Read_v1(file); 
03541   }
03542   else
03543   {
03544     rc = Read_v2(file); 
03545   }
03546 
03547   return rc;
03548 }
03549 
03550 
03551 static bool ON_3dmSettings_Write_v1_TCODE_UNIT_AND_TOLERANCES(ON_BinaryArchive& file, const ON_3dmUnitsAndTolerances& UnitsAndTolerances )
03552 {
03553   bool rc = true;
03554   int v = 1, us = 0;
03555   if (rc) rc = file.WriteInt( v ); // v = 1
03556   switch (UnitsAndTolerances.m_unit_system.m_unit_system) 
03557   {
03558   case ON::no_unit_system: 
03559     us=0; // NO_UNIT_SYSTEM
03560     break;
03561   case ON::microns: 
03562     us=1; // MICRONS
03563     break;
03564   case ON::millimeters:
03565     us=2; // MILLIMETERS
03566     break;
03567   case ON::centimeters:
03568     us=3; // CENTIMETERS
03569     break;
03570   case ON::meters:
03571     us=4; // METERS
03572     break;
03573   case ON::kilometers:
03574     us=5; // KILOMETERS
03575     break;
03576   case ON::microinches:
03577     us=6; // MICROINCHES
03578     break;
03579   case ON::mils:
03580     us=7; // MILS
03581     break;
03582   case ON::inches:
03583     us=8; // INCHES
03584     break;
03585   case ON::feet:
03586     us=9; // FEET
03587     break;
03588   case ON::miles:
03589     us=10; // MILES
03590     break;
03591   default:
03592     us=0; // NO_UNIT_SYSTEM
03593     break;
03594   }
03595   if (rc) rc = file.WriteInt( us );
03596   if (rc) rc = file.WriteDouble( UnitsAndTolerances.m_absolute_tolerance );
03597   if (rc) rc = file.WriteDouble( UnitsAndTolerances.m_relative_tolerance );
03598   if (rc) rc = file.WriteDouble( UnitsAndTolerances.m_angle_tolerance );
03599 
03600   return rc;
03601 }
03602 
03603 bool ON_3dmSettings::Write_v1(ON_BinaryArchive& file) const
03604 {
03605   bool rc = true;
03606 
03607   // version 1 units and tolerances chunk
03608   rc = file.BeginWrite3dmChunk(TCODE_UNIT_AND_TOLERANCES,0);
03609   if (rc) {
03610     rc = ON_3dmSettings_Write_v1_TCODE_UNIT_AND_TOLERANCES( file, m_ModelUnitsAndTolerances );
03611     if (!file.EndWrite3dmChunk())
03612       rc = false;
03613   }
03614 
03615   return rc;
03616 }
03617 
03618 bool ON_3dmSettings::Write_v2(ON_BinaryArchive& file) const
03619 {
03620   int i;
03621   bool rc = true;
03622 
03623   // TCODE_SETTINGS_PLUGINLIST - plugins that may have saved userdata in the file
03624   if (rc && file.Archive3dmVersion() >= 4 && m_plugin_list.Count() > 0 )
03625   {
03626     // The plug-in list chunk needs to be first, so the plug-ins that save
03627     // userdata on views can be loaded as needed.
03628     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_PLUGINLIST,0);
03629     if ( rc ) 
03630     {
03631       if (rc) rc = file.Write3dmChunkVersion(1,0);
03632       if (rc) rc = file.WriteInt( m_plugin_list.Count() );
03633       for ( i = 0; rc && i < m_plugin_list.Count(); i++ )
03634       {
03635         rc = m_plugin_list[i].Write(file);
03636       }
03637 
03638       if ( !file.EndWrite3dmChunk() )
03639         rc = false;
03640     }
03641   }
03642 
03643   // TCODE_PROPERTIES_UNITSANDTOLS - units and tolerances
03644   if ( rc  ) {
03645     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_UNITSANDTOLS,0);
03646     if ( rc ) {
03647       rc = m_ModelUnitsAndTolerances.Write(file);
03648       if ( !file.EndWrite3dmChunk() )
03649         rc = false;
03650     }
03651   }
03652 
03653   // TCODE_SETTINGS_RENDERMESH - rendering defaults
03654   if ( rc  ) {
03655     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_RENDERMESH,0);
03656     if ( rc ) {
03657       rc = m_RenderMeshSettings.Write(file);
03658       if ( !file.EndWrite3dmChunk() )
03659         rc = false;
03660     }
03661   }
03662 
03663   // TCODE_SETTINGS_ANALYSISMESH - analysis mesh defaults
03664   if ( rc  ) {
03665     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_ANALYSISMESH,0);
03666     if ( rc ) {
03667       rc = m_AnalysisMeshSettings.Write(file);
03668       if ( !file.EndWrite3dmChunk() )
03669         rc = false;
03670     }
03671   }
03672 
03673   // TCODE_SETTINGS_ANNOTATION - annotation settings
03674   if ( rc  ) {
03675     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_ANNOTATION,0);
03676     if ( rc ) {
03677       rc = m_AnnotationSettings.Write(file);
03678       if ( !file.EndWrite3dmChunk() )
03679         rc = false;
03680     }
03681   }
03682 
03683   // TCODE_SETTINGS_NAMED_CPLANE_LIST
03684   if ( rc  ) {
03685     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_NAMED_CPLANE_LIST,0);
03686     if ( rc ) {
03687       const int count = m_named_cplanes.Count();
03688       rc = file.WriteInt(count);
03689       for ( i = 0; i < count && rc; i++ ) {
03690         rc = file.BeginWrite3dmChunk( TCODE_VIEW_CPLANE, 0 );
03691         if (rc ) {
03692           rc = m_named_cplanes[i].Write(file);
03693           if ( !file.EndWrite3dmChunk() )
03694             rc = false;
03695         }
03696       }
03697       if ( !file.EndWrite3dmChunk() )
03698         rc = false;
03699     }
03700   }
03701 
03702   // TCODE_SETTINGS_NAMED_VIEW_LIST
03703   if ( rc  ) {
03704     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_NAMED_VIEW_LIST,0);
03705     if ( rc ) {
03706       const int count = m_named_views.Count();
03707       rc = file.WriteInt(count);
03708       for ( i = 0; i < count && rc; i++ ) {
03709         rc = file.BeginWrite3dmChunk( TCODE_VIEW_RECORD, 0 );
03710         if (rc ) {
03711           rc = m_named_views[i].Write(file);
03712           if ( !file.EndWrite3dmChunk() )
03713             rc = false;
03714         }
03715       }
03716       if ( !file.EndWrite3dmChunk() )
03717         rc = false;
03718     }
03719   }
03720 
03721   // TCODE_SETTINGS_VIEW_LIST
03722   if ( rc  ) {
03723     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_VIEW_LIST,0);
03724     if ( rc ) {
03725       const int count = m_views.Count();
03726       rc = file.WriteInt(count);
03727       for ( i = 0; i < count && rc; i++ ) {
03728         rc = file.BeginWrite3dmChunk( TCODE_VIEW_RECORD, 0 );
03729         if (rc ) {
03730           rc = m_views[i].Write(file);
03731           if ( !file.EndWrite3dmChunk() )
03732             rc = false;
03733         }
03734       }
03735       if ( !file.EndWrite3dmChunk() )
03736         rc = false;
03737     }
03738   }
03739 
03740   // TCODE_SETTINGS_CURRENT_LAYER_INDEX
03741   if (rc) {
03742     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_CURRENT_LAYER_INDEX, m_current_layer_index );
03743     if ( !file.EndWrite3dmChunk() )
03744       rc = false;
03745   }
03746 
03747   // TCODE_SETTINGS_CURRENT_MATERIAL_INDEX
03748   if (rc) {
03749     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_CURRENT_MATERIAL_INDEX, 0 );
03750     if (rc) {
03751       rc = file.WriteInt( m_current_material_index );
03752       i = m_current_material_source;
03753       if (rc) rc = file.WriteInt( i );
03754       if ( !file.EndWrite3dmChunk() )
03755         rc = false;
03756     }
03757   }
03758 
03759   // TCODE_SETTINGS_CURRENT_COLOR
03760   if (rc) {
03761     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_CURRENT_COLOR, 0 );
03762     if (rc) {
03763       rc = file.WriteColor( m_current_color );
03764       i = m_current_color_source;
03765       if (rc) rc = file.WriteInt( i );
03766       if ( !file.EndWrite3dmChunk() )
03767         rc = false;
03768     }
03769   }
03770 
03771 
03772   // TCODE_SETTINGS_CURRENT_WIRE_DENSITY
03773   if (rc) {
03774     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_CURRENT_WIRE_DENSITY, m_current_wire_density );
03775     if (rc) {
03776       if ( !file.EndWrite3dmChunk() )
03777         rc = false;
03778     }
03779   }
03780 
03781   // TCODE_SETTINGS_RENDER
03782   if (rc) {
03783     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_RENDER, 0 );
03784     if (rc) {
03785       rc = m_RenderSettings.Write(file);
03786       if ( !file.EndWrite3dmChunk() )
03787         rc = false;
03788     }
03789   }
03790 
03791   // TCODE_SETTINGS_GRID_DEFAULTS
03792   if (rc) {
03793     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_GRID_DEFAULTS, 0 );
03794     if (rc) {
03795       rc = m_GridDefaults.Write(file);
03796       if ( !file.EndWrite3dmChunk() )
03797         rc = false;
03798     }
03799   }
03800 
03801   // TCODE_SETTINGS_MODEL_URL - added 21 June 2001
03802   if (rc && m_model_URL.Length() > 0 ) {
03803     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_MODEL_URL, 0 );
03804     if (rc) {
03805       rc = file.WriteString(m_model_URL);
03806       if ( !file.EndWrite3dmChunk() )
03807         rc = false;
03808     }
03809   }
03810 
03811   // TCODE_SETTINGS_CURRENT_FONT_INDEX - added 10 June 2002
03812   if (rc) {
03813     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_CURRENT_FONT_INDEX, m_current_font_index );
03814     if ( !file.EndWrite3dmChunk() )
03815       rc = false;
03816   }
03817     
03818   // TCODE_SETTINGS_CURRENT_DIMSTYLE_INDEX - added 10 June 2002
03819   if (rc) {
03820     rc = file.BeginWrite3dmChunk( TCODE_SETTINGS_CURRENT_DIMSTYLE_INDEX, m_current_dimstyle_index );
03821     if ( !file.EndWrite3dmChunk() )
03822       rc = false;
03823   }
03824 
03825   // TCODE_SETTINGS_ATTRIBUTES
03826   if (rc && file.Archive3dmVersion() >= 4 )
03827   {
03828     // 23 March 2005 Dale Lear
03829     rc = file.BeginWrite3dmChunk(TCODE_SETTINGS_ATTRIBUTES, 0 );
03830     if (rc)
03831     {
03832       for(;;)
03833       {
03834         // 1.0 - 23 March 2005
03835         // 1.1 -  6 Feb   2006
03836         // 1.2 -  1 March 2006
03837         // 1.3 - 29 March 2006
03838         // 1.4 - 18 April 2006
03839         // 1.5 - 21 April 2006
03840         // 1.6 -  7 June  2006
03841         rc = file.Write3dmChunkVersion(1,6);
03842 
03843         // version 1.0 fields 
03844         rc = file.WriteDouble( m_linetype_display_scale );
03845         if (!rc) break;
03846 
03847         rc = file.WriteColor(m_current_plot_color);
03848         if (!rc) break;
03849 
03850         rc = file.WriteInt(m_current_plot_color_source);
03851         if (!rc) break;
03852 
03853         rc = file.WriteInt(m_current_linetype_index);
03854         if (!rc) break;
03855 
03856         rc = file.WriteInt(m_current_linetype_source);
03857         if (!rc) break;
03858 
03859         // 6 Feb 2006, 1.1 fields
03860 
03861         // the units and tols has to be inside a chunk
03862         rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
03863         if (rc)
03864         {
03865           rc = m_PageUnitsAndTolerances.Write(file);
03866           if ( !file.EndWrite3dmChunk() )
03867             rc = false;
03868         }
03869         if (!rc) break;
03870 
03871         // 1 Mar 2006 1.2 fields
03872         rc = file.WriteUuid(m_active_view_id);
03873         if (!rc) break;
03874 
03875         // 29 March 2006 1.3 fields
03876         rc = file.WritePoint( m_model_basepoint);
03877         if (!rc) break;
03878         rc = m_earth_anchor_point.Write(file);
03879         if (!rc) break;
03880 
03881         // 18 April 2006 1.4 fields
03882         rc = file.WriteBool(m_IO_settings.m_bSaveTextureBitmapsInFile);
03883         if (!rc) break;
03884 
03885         // 21 April 2006 1.5 fields
03886         rc = m_IO_settings.Write(file);
03887         if (!rc) break;
03888 
03889         // 7 June 2006 1.6 fields
03890         rc = m_CustomRenderMeshSettings.Write(file);
03891         if (!rc) break;
03892 
03893         break;
03894       }
03895 
03896       if ( !file.EndWrite3dmChunk() )
03897         rc = false;
03898     }
03899   }
03900 
03901   // required TCODE_ENDOFTABLE chunk - marks end of settings table
03902   if ( rc ) {
03903     rc = file.BeginWrite3dmChunk( TCODE_ENDOFTABLE, 0 );
03904     if ( rc ) {
03905       if ( !file.EndWrite3dmChunk() )
03906         rc = false;
03907     }
03908   }
03909 
03910 
03911   return rc;
03912 }
03913 
03914 bool ON_3dmSettings::Write(ON_BinaryArchive& file) const
03915 {
03916   bool rc = false;
03917   if ( 1 == file.Archive3dmVersion() ) 
03918   {
03919     rc = Write_v1(file); 
03920   }
03921   else
03922   {
03923     rc = Write_v2(file); 
03924   }
03925   return rc;
03926 }
03927 
03928 void ON_3dmSettings::Dump( ON_TextLog& dump ) const
03929 {
03930   int i;
03931 
03932   const wchar_t* model_URL = m_model_URL;
03933   if ( model_URL && *model_URL ) 
03934   {
03935     dump.Print("Model URL: %ls\n",model_URL);
03936   }
03937   dump.Print("Model space units and tolerances:\n");
03938   dump.PushIndent();
03939   m_ModelUnitsAndTolerances.Dump(dump);
03940   dump.PopIndent();
03941 
03942   dump.Print("Page space units and tolerances:\n");
03943   dump.PushIndent();
03944   m_PageUnitsAndTolerances.Dump(dump);
03945   dump.PopIndent();
03946 
03947   dump.Print("Render mesh settings:\n");
03948   dump.PushIndent();
03949   m_RenderMeshSettings.Dump(dump);
03950   dump.PopIndent();
03951 
03952   dump.Print("Analysis mesh settings:\n");
03953   dump.PushIndent();
03954   m_AnalysisMeshSettings.Dump(dump);
03955   dump.PopIndent();
03956 
03957   dump.Print("Render settings:\n");
03958   dump.PushIndent();
03959   m_RenderSettings.Dump(dump);
03960   dump.PopIndent();
03961 
03962   dump.Print("Annotation settings:\n");
03963   dump.PushIndent();
03964   m_AnnotationSettings.Dump(dump);
03965   dump.PopIndent();
03966 
03967   dump.Print("Construction plane grid defaults:\n");
03968   dump.PushIndent();
03969   m_GridDefaults.Dump(dump);
03970   dump.PopIndent();
03971 
03972   dump.Print("Named construction planes:\n");
03973   dump.PushIndent();
03974   for ( i = 0; i < m_named_cplanes.Count(); i++ )
03975   {
03976     dump.Print("named construction plane %d:\n");
03977     dump.PushIndent();
03978     m_named_cplanes[i].Dump(dump);
03979     dump.PopIndent();
03980   }
03981   dump.PopIndent();
03982 
03983   dump.Print("Named views:\n");
03984   dump.PushIndent();
03985   for ( i = 0; i < m_named_views.Count(); i++ )
03986   {
03987     dump.Print("named view %d:\n",i);
03988     dump.PushIndent();
03989     m_named_views[i].Dump(dump);
03990     dump.PopIndent();
03991   }
03992   dump.PopIndent();
03993 
03994   dump.Print("Model views:\n");
03995   dump.PushIndent();
03996   for ( i = 0; i < m_views.Count(); i++ )
03997   {
03998     dump.Print("model view %d:\n",i);
03999     dump.PushIndent();
04000     m_views[i].Dump(dump);
04001     dump.PopIndent();
04002   }
04003   dump.PopIndent();
04004 
04005   dump.Print("New object attributes:\n");
04006   dump.PushIndent();
04007   {
04008     dump.Print("Current display color rgb");dump.PrintRGB(m_current_color); dump.Print(":\n");
04009     dump.Print("Current display color source = %d\n",m_current_color_source);
04010     dump.Print("Current plot color rgb");dump.PrintRGB(m_current_plot_color); dump.Print(":\n");
04011     dump.Print("Current plot color source = %d\n",m_current_plot_color_source);
04012     dump.Print("Current material index = %d\n",m_current_material_index);
04013     dump.Print("Current material source = %d\n",m_current_material_source);
04014     dump.Print("Current linetype index = %d\n",m_current_linetype_index);
04015     dump.Print("Current linetype source = %d\n",m_current_linetype_source);
04016     dump.Print("Current layer index = %d\n",m_current_layer_index);
04017     dump.Print("Current font index = %d\n",m_current_font_index);
04018     dump.Print("Current dimstyle index = %d\n",m_current_dimstyle_index);
04019     dump.Print("Current wire density = %d\n",m_current_wire_density);
04020     dump.Print("Linetype diaplay scale = %g\n",m_linetype_display_scale);
04021   }
04022   dump.PopIndent();
04023 
04024   dump.Print("Plug-in list\n");
04025   dump.PushIndent();
04026   for ( i = 0; i < m_plugin_list.Count(); i++ )
04027   {
04028     dump.Print("plug-in %d:\n",i);
04029     dump.PushIndent();
04030     m_plugin_list[i].Dump(dump);
04031     dump.PopIndent();
04032   }
04033   dump.PopIndent();
04034 
04035 }
04036 


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