opennurbs_dimstyle.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 /*
00020 Changes and additions 5/01/07 LW
00021 Adding several fields to ON_Dimstyle
00022 Adding the concept of Parent and Child dimstyles so that individual dimension objects
00023 can have their own copy of a dimension style to override some settings
00024 
00025   Adding several fields to ON_Dimstyle - This is done with ON_DimStyleExtra userdata
00026   class for now so the SDK doesn't break completely. When the SDK changes, the data in 
00027   ON_DimstyleExtra should be moved into ON_Dimstyle.
00028 
00029   Adding the concept of Parent and Child dimstyles to support per object overrides of
00030   dimstyle based properties.  Individual dimensions will be able to have one or more
00031   properties that differ from the dimension style for that dimension, but the rest of 
00032   their properties will be controlled by the parent dimstyle. In this implementation 
00033   (Rhino 5), dimstyles will only inherit one level deep.
00034 
00035   The first time an individual dimension has a dimstyle value overridden, a new child 
00036   dimstyle is made that is a copy of the dimension's dimstyle. If there is already a 
00037   child dimstyle for that dimension, it is used and no new dimstyle is made.
00038   The value being overridden is changed in the child dimstyle and a flag is set that 
00039   the field is being overridden.
00040 
00041   When a value is changed in a parent dimstyle, it should look through the other 
00042   dimstyles in the dimstyle table (or your application's equivalent) and change any 
00043   of its children appropriately.  Name and Index fields aren't propogated this way.
00044   If the parent's field being changed is not set in the child's m_valid_fields array,
00045   the child's copy of that field should be changed to match the parent's new value.
00046   Changing values in child dimstyles doesn't change values in their parents.
00047 
00048   When a value that has previously been overridden by an individual dimension
00049   is set to ByStyle, the corresponding field flag is unset in the valid field array. 
00050   If all of the flags in a child dimstyle become unset, the dimension is set to 
00051   reference the parent dimstyle directly.
00052   
00053 */
00054 
00055 
00056 // Added for v5 - 5/01/07 LW
00057 // Userdata class being used to extend ON_DimStyle so the v4 sdk still works
00058 // Presumably, this will be moved into ON_DimStyle when the SDK is changed again
00059 // Don't put this extension class in a header file or export it.
00060 class ON_DimStyleExtra : public ON_UserData
00061 {
00062   ON_OBJECT_DECLARE(ON_DimStyleExtra);
00063 public:
00067 
00068   // 2 November 2011 Dale Lear
00069   //   Undoing above change.  Adding this user data is not necessary
00070   //   and is causing large memory leaks when it is repeatedly
00071   //   added to the default dimstyle in the Rhino dimstyle table.
00072   static ON_DimStyleExtra* DimStyleExtensionGet( ON_DimStyle* pDimStyle, bool bCreateIfNoneExists );
00073 
00074   // 2 November 2011 Dale Lear
00075   //   Undoing above change.  Adding this user data is not necessary
00076   //   and is causing large memory leaks when it is repeatedly
00077   //   added to the default dimstyle in the Rhino dimstyle table.
00078   //   This const version never creates user data.
00079   static const ON_DimStyleExtra* DimStyleExtensionGet( const ON_DimStyle* pDimStyle);
00080 
00081   ON_DimStyleExtra();
00082   ~ON_DimStyleExtra();
00083 
00084   void SetDefaults();
00085 
00086   /*
00087   Returns:
00088     True if this ON_DimStyleExtra has default settings.
00089   */
00090   bool IsDefault() const;
00091 
00092   // override virtual ON_Object::Dump function
00093   void Dump( ON_TextLog& text_log ) const;
00094 
00095   // override virtual ON_Object::SizeOf function
00096   unsigned int SizeOf() const;
00097 
00098   // override virtual ON_Object::Write function
00099   ON_BOOL32 Write(ON_BinaryArchive& binary_archive) const;
00100 
00101   // override virtual ON_Object::Read function
00102   ON_BOOL32 Read(ON_BinaryArchive& binary_archive);
00103 
00104   // override virtual ON_UserData::GetDescription function
00105   ON_BOOL32 GetDescription( ON_wString& description );
00106 
00107   // override virtual ON_UserData::Archive function
00108   ON_BOOL32 Archive() const; 
00109 
00110   void SetFieldOverride( int field_id, bool bOverride);
00111   bool IsFieldOverride( int field_id) const;
00112 
00113   // Data access
00114   // Scale all of the length values
00115   void Scale( double scale);
00116 
00117   // Tolerances
00118   // Tolerance style
00119   //  0: None
00120   //  1: Symmetrical
00121   //  2: Deviation
00122   //  3: Limits
00123   //  4: Basic
00124   void SetToleranceStyle( int style);
00125   int  ToleranceStyle() const;
00126   
00127   void SetToleranceResolution( int resolution);
00128   int  ToleranceResolution() const;
00129 
00130   void SetToleranceUpperValue( double upper_value);
00131   double ToleranceUpperValue() const;
00132 
00133   void SetToleranceLowerValue( double lower_value);
00134   double ToleranceLowerValue() const;
00135 
00136   void SetToleranceHeightScale( double scale);
00137   double ToleranceHeightScale() const;
00138 
00139   void SetBaselineSpacing( double);
00140   double BaselineSpacing() const;
00141 
00142   // Determines whether or not to draw a Text Mask
00143   bool DrawTextMask() const;
00144   void SetDrawTextMask(bool bDraw);
00145 
00146   // Determines where to get the color to draw a Text Mask
00147   // 0: Use background color of the viewport.  Initially, gradient backgrounds will not be supported
00148   // 1: Use the ON_Color returned by MaskColor()
00149   int MaskColorSource() const;
00150   void SetMaskColorSource(int source);
00151 
00152   ON_Color MaskColor() const;  // Only works right if MaskColorSource returns 1.
00153                                // Does not return viewport background color
00154   void SetMaskColor(ON_Color color);
00155 
00156   void SetDimScale(double scale);
00157   double DimScale() const;
00158   void SetDimScaleSource(int source);
00159   int DimScaleSource() const;
00160 
00161   void SetSourceDimstyle(ON_UUID source_uuid);
00162   ON_UUID SourceDimstyle() const;
00163 
00164   bool CompareFields(const ON_DimStyleExtra* pOther) const;
00165 
00166   // Data storage
00167 
00168   ON_UUID m_parent_dimstyle;  // ON_nil_uuid if there is no parent dimstyle
00169   ON_SimpleArray<bool> m_valid_fields;
00170   enum { eFieldCount = 66 };
00171 
00172   int    m_tolerance_style;
00173   int    m_tolerance_resolution;
00174   double m_tolerance_upper_value;   // or both upper and lower in symmetrical style
00175   double m_tolerance_lower_value;
00176   double m_tolerance_height_scale;  // relative to the main dimension text
00177 
00178   double m_baseline_spacing;
00179 
00180   // Text mask - added Dec 12 2009
00181   bool     m_bDrawMask;
00182   int      m_mask_color_source;
00183   ON_Color m_mask_color;
00184 
00185   // Per dimstyle DimScale added Dec 16, 2009
00186   double   m_dimscale;
00187   int      m_dimscale_source;
00188 
00189   // 19 Oct 2010 - Added uuid of source dimstyle to restore defaults
00190   ON_UUID  m_source_dimstyle;
00191 };
00192 
00193 
00194 
00195 
00196 
00197 // Added for v5 - 5/01/07 LW
00198 ON_OBJECT_IMPLEMENT(ON_DimStyleExtra,ON_UserData,"513FDE53-7284-4065-8601-06CEA8B28D6F");
00199 
00222 
00223 // 26 Oct 2010 - Lowell - Changed to always create ON_DimStyleExtra if there's not one
00224 ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtensionGet( ON_DimStyle* pDimStyle, bool bCreateIfNoneExists )
00225 {
00226   ON_DimStyleExtra* pExtra = 0;
00227   if( pDimStyle)
00228   {
00229     pExtra = ON_DimStyleExtra::Cast( pDimStyle->GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
00230     // 2 November 2011 Dale Lear
00231     //   I added the bCreateIfNoneExists parameter and I'm using
00232     //   is sparingly.  It is critical that we do not add
00233     //   ON_DimStyleExtra unless it is actually being used
00234     //   to override a default setting.  Otherwise, we 
00235     //   end up leaking vast amounts of memory when
00236     //   the default dimstyle in the Rhino dimstyle
00237     //   table is used due to the way annotation
00238     //   is currently drawn.
00239     //   If you have questions, please ask Dale Lear for details
00240     //   but please do not revert to constantly adding user
00241     //   data to dimstyles.
00242     if( pExtra == 0 && bCreateIfNoneExists )
00243     {
00244       pExtra = new ON_DimStyleExtra;
00245       if( pExtra)
00246       {
00247         if( !pDimStyle->AttachUserData( pExtra))
00248         {
00249           delete pExtra;
00250           pExtra = 0;
00251         }
00252       }
00253     }
00254   }
00255   return pExtra;
00256 }
00257 
00258 const 
00259 ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtensionGet( const ON_DimStyle* pDimStyle)
00260 {
00261   // Please do not changes the "false" to a "true" in the second argument.
00262   return ON_DimStyleExtra::DimStyleExtensionGet( (ON_DimStyle*)pDimStyle, false );
00263 }
00264 
00265 ON_DimStyleExtra::ON_DimStyleExtra()
00266 {
00267   m_userdata_uuid = ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid();
00268   m_application_uuid = ON_opennurbs5_id; // opennurbs.dll reads/writes this userdata
00269                                          // The id must be the version 5 id because
00270                                          // V6 SaveAs V5 needs to work, but SaveAs
00271                                          // V4 should not write this userdata.
00272   m_userdata_copycount = 1;
00273   m_valid_fields.Reserve( ON_DimStyleExtra::eFieldCount);
00274   m_valid_fields.SetCount( ON_DimStyleExtra::eFieldCount);
00275   m_parent_dimstyle = ON_nil_uuid;
00276   m_source_dimstyle = ON_nil_uuid;
00277   SetDefaults();
00278 }
00279 
00280 ON_DimStyleExtra::~ON_DimStyleExtra()
00281 {
00282 }
00283 
00284 void ON_DimStyleExtra::SetDefaults()
00285 {
00286   m_tolerance_style = ON_DimStyle::DefaultToleranceStyle();
00287   m_tolerance_resolution = ON_DimStyle::DefaultToleranceResolution();
00288   m_tolerance_upper_value = ON_DimStyle::DefaultToleranceUpperValue();
00289   m_tolerance_lower_value = ON_DimStyle::DefaultToleranceLowerValue();
00290   m_tolerance_height_scale = ON_DimStyle::DefaultToleranceHeightScale();
00291   m_baseline_spacing = ON_DimStyle::DefaultBaselineSpacing();
00292   m_bDrawMask = ON_DimStyle::DefaultDrawTextMask(); // false;
00293   m_mask_color_source = ON_DimStyle::DefaultMaskColorSource(); // 0;
00294   m_mask_color = ON_DimStyle::DefaultMaskColor(); // .SetRGB(255,255,255);
00295   m_dimscale = ON_DimStyle::DefaultDimScale(); // 1.0;
00296   m_dimscale_source = ON_DimStyle::DefaultDimScaleSource(); // 0;
00297 
00298   for( int i = 0; i < m_valid_fields.Count(); i++)
00299     m_valid_fields[i] = false;
00300 }
00301 
00302 bool ON_DimStyleExtra::IsDefault() const
00303 {
00304   if ( m_tolerance_style != ON_DimStyle::DefaultToleranceStyle() ) return false;
00305   if ( m_tolerance_resolution != ON_DimStyle::DefaultToleranceResolution() ) return false;
00306   if ( m_tolerance_upper_value != ON_DimStyle::DefaultToleranceUpperValue() ) return false;
00307   if ( m_tolerance_lower_value != ON_DimStyle::DefaultToleranceLowerValue() ) return false;
00308   if ( m_tolerance_height_scale != ON_DimStyle::DefaultToleranceHeightScale() ) return false;
00309   if ( m_baseline_spacing != ON_DimStyle::DefaultBaselineSpacing() ) return false;
00310   if ( m_bDrawMask != ON_DimStyle::DefaultDrawTextMask() ) return false;
00311   if ( m_mask_color_source != ON_DimStyle::DefaultMaskColorSource() ) return false;
00312   if ( m_mask_color != ON_DimStyle::DefaultMaskColor() ) return false;
00313   if ( m_dimscale != ON_DimStyle::DefaultDimScale() ) return false;
00314   if ( m_dimscale_source != ON_DimStyle::DefaultDimScaleSource() ) return false;
00315 
00316   // The m_valid_fields[] settings only matter when
00317   // m_parent_dimstyle is not zero.
00318   if ( !(m_parent_dimstyle == ON_nil_uuid) )
00319   {
00320     for( int i = 0; i < m_valid_fields.Count() && i < ON_DimStyleExtra::eFieldCount; i++)
00321     {
00322       if ( !m_valid_fields[i] )
00323         return false;
00324     }
00325   }
00326 
00327   return true;
00328 }
00329 
00330 void ON_DimStyleExtra::Dump( ON_TextLog& text_log ) const
00331 {
00332   // do nothing
00333 }
00334 
00335 unsigned int ON_DimStyleExtra::SizeOf() const
00336 {
00337   unsigned int sz = ON_UserData::SizeOf();
00338   sz += sizeof(*this) - sizeof(ON_UserData);
00339   return sz;
00340 }
00341 
00342 ON_BOOL32 ON_DimStyleExtra::Write(ON_BinaryArchive& archive) const
00343 {
00344 //  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0); Changed to 1,1 for mask settings 12/12/09
00345 //  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1); Changed to 1,2 for dimscale 12/17/09
00346 //  bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,2); Changed to 1,3 for source_dimstyle 10/19/10
00347   bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,3);
00348 
00349   if(rc) rc = archive.WriteUuid( m_parent_dimstyle);
00350   if(rc) rc = archive.WriteArray( m_valid_fields);
00351 
00352   if(rc) rc = archive.WriteInt(m_tolerance_style);
00353   if(rc) rc = archive.WriteInt(m_tolerance_resolution);
00354 
00355   if(rc) rc = archive.WriteDouble(m_tolerance_upper_value);
00356   if(rc) rc = archive.WriteDouble(m_tolerance_lower_value);
00357   if(rc) rc = archive.WriteDouble(m_tolerance_height_scale);
00358 
00359   // March 22, 2010 - Global DimStyle was obsoleted and moved into DimStyles
00360   // So now for writing older version files, its multiplied into all distance values
00361   if(archive.Archive3dmVersion() < 5)
00362   {
00363     if(rc) rc = archive.WriteDouble(m_baseline_spacing * m_dimscale);
00364   }
00365   else
00366   {
00367     if(rc) rc = archive.WriteDouble(m_baseline_spacing);
00368   }
00369 
00370   if(rc) rc = archive.WriteBool(m_bDrawMask);
00371   if(rc) rc = archive.WriteInt(m_mask_color_source);
00372   if(rc) rc = archive.WriteColor(m_mask_color);
00373 
00374   if(archive.Archive3dmVersion() < 5)
00375   {
00376     if(rc) rc = archive.WriteDouble(1.0);
00377   }
00378   else
00379   {
00380     if(rc) rc = archive.WriteDouble(m_dimscale);
00381   }
00382   if(rc) rc = archive.WriteInt(m_dimscale_source); // Obsolete field
00383 
00384   if(rc) rc = archive.WriteUuid(m_source_dimstyle);  // Added 19 Oct 2010
00385 
00386   if(!archive.EndWrite3dmChunk())
00387     rc = false;
00388 
00389   return rc;
00390 }
00391 
00392 ON_BOOL32 ON_DimStyleExtra::Read(ON_BinaryArchive& archive)
00393 {
00394   // Changed to 1,0 for mask settings 12/12/09
00395   int major_version = 0;
00396   int minor_version = 0;
00397   bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
00398   if(major_version != 1)
00399     rc = false;
00400 
00401   if(rc) rc = archive.ReadUuid(m_parent_dimstyle);
00402   if(rc) rc = archive.ReadArray(m_valid_fields);
00403 
00404   if(rc) rc = archive.ReadInt(&m_tolerance_style);
00405   if(rc) rc = archive.ReadInt(&m_tolerance_resolution);
00406 
00407   if(rc) rc = archive.ReadDouble(&m_tolerance_upper_value);
00408   if(rc) rc = archive.ReadDouble(&m_tolerance_lower_value);
00409   if(rc) rc = archive.ReadDouble(&m_tolerance_height_scale);
00410 
00411   if(rc) rc = archive.ReadDouble(&m_baseline_spacing);
00412 
00413   if(minor_version >= 1)
00414   {
00415     if(rc) rc = archive.ReadBool(&m_bDrawMask);
00416     if(rc) rc = archive.ReadInt(&m_mask_color_source);
00417     if(rc) rc = archive.ReadColor(m_mask_color);
00418   }
00419 
00420   if(minor_version >= 2)
00421   {
00422     if(rc) rc = archive.ReadDouble(&m_dimscale);
00423     if(rc) rc = archive.ReadInt(&m_dimscale_source);
00424   }
00425 
00426   if(minor_version >= 3)
00427   {
00428     if(rc) rc = archive.ReadUuid(m_source_dimstyle);
00429   }
00430 
00431   if ( !archive.EndRead3dmChunk() )
00432     rc = false;
00433 
00434   return rc;
00435 }
00436 
00437 ON_BOOL32 ON_DimStyleExtra::GetDescription( ON_wString& description)
00438 {
00439   description.Format( "Userdata extension of ON_DimStyle");
00440   return true;
00441 }
00442 
00443 ON_BOOL32 ON_DimStyleExtra::Archive() const
00444 {
00445   // true to write to file
00446   return true;
00447 }
00448 
00449 void ON_DimStyleExtra::Scale( double scale)
00450 {
00451   if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON)
00452     m_baseline_spacing *= scale;
00453 }
00454 
00455 // Tolerance style
00456 void ON_DimStyleExtra::SetToleranceStyle( int style)
00457 {
00458   if( style >= 0 && style <= 4)
00459     m_tolerance_style = style;
00460 }
00461 
00462 int ON_DimStyleExtra::ToleranceStyle() const
00463 {
00464   return m_tolerance_style;
00465 }
00466 
00467 void ON_DimStyleExtra::SetToleranceResolution( int resolution)
00468 {
00469   if( resolution >= 0 && resolution < 16)
00470     m_tolerance_resolution = resolution;
00471 }
00472 
00473 int ON_DimStyleExtra::ToleranceResolution() const
00474 {
00475   return m_tolerance_resolution;
00476 }
00477 
00478 void ON_DimStyleExtra::SetToleranceUpperValue( double upper_value)
00479 {
00480   if( ON_IsValid(upper_value))
00481     m_tolerance_upper_value = upper_value;
00482 }
00483 
00484 double ON_DimStyleExtra::ToleranceUpperValue() const
00485 {
00486   return m_tolerance_upper_value;
00487 }
00488 
00489 void ON_DimStyleExtra::SetToleranceLowerValue( double lower_value)
00490 {
00491   if( ON_IsValid(lower_value))
00492     m_tolerance_lower_value = lower_value;
00493 }
00494 
00495 double ON_DimStyleExtra::ToleranceLowerValue() const
00496 {
00497   return m_tolerance_lower_value;
00498 }
00499 
00500 void ON_DimStyleExtra::SetToleranceHeightScale( double scale)
00501 {
00502   if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON)
00503     m_tolerance_height_scale = scale;
00504 }
00505 
00506 double ON_DimStyleExtra::ToleranceHeightScale() const
00507 {
00508   return m_tolerance_height_scale;
00509 }
00510 
00511 void ON_DimStyleExtra::SetBaselineSpacing( double spacing)
00512 {
00513   if( ON_IsValid( spacing) && spacing > ON_SQRT_EPSILON)
00514     m_baseline_spacing = spacing;
00515 }
00516 
00517 double ON_DimStyleExtra::BaselineSpacing() const
00518 {
00519   return m_baseline_spacing;
00520 }
00521 
00522 bool ON_DimStyleExtra::DrawTextMask() const
00523 {
00524   return m_bDrawMask;
00525 }
00526 
00527 void ON_DimStyleExtra::SetDrawTextMask(bool bDraw)
00528 {
00529   m_bDrawMask = bDraw ? true : false;
00530 }
00531 
00532 int ON_DimStyleExtra::MaskColorSource() const
00533 {
00534   return m_mask_color_source;
00535 }
00536 
00537 void ON_DimStyleExtra::SetMaskColorSource(int source)
00538 {
00539   if(source == 1)
00540     m_mask_color_source = 1;
00541   else
00542     m_mask_color_source = 0;
00543 }
00544 
00545 ON_Color ON_DimStyleExtra::MaskColor() const
00546 {
00547   return m_mask_color;
00548 }
00549 
00550 void ON_DimStyleExtra::SetMaskColor(ON_Color color)
00551 {
00552   m_mask_color = color;
00553 }
00554 
00555 void ON_DimStyleExtra::SetDimScale(double scale)
00556 {
00557   m_dimscale = scale;
00558 }
00559 
00560 double ON_DimStyleExtra::DimScale() const
00561 {
00562   return m_dimscale;
00563 }
00564 
00565 void ON_DimStyleExtra::SetDimScaleSource(int source)
00566 {
00567   m_dimscale_source = source;
00568 }
00569 
00570 int ON_DimStyleExtra::DimScaleSource() const
00571 {
00572   return m_dimscale_source;
00573 }
00574 
00575 void ON_DimStyleExtra::SetSourceDimstyle(ON_UUID source_uuid)
00576 {
00577   m_source_dimstyle = source_uuid;
00578 }
00579 
00580 ON_UUID ON_DimStyleExtra::SourceDimstyle() const
00581 {
00582   return m_source_dimstyle;
00583 }
00584 
00585 // returns true if they are the same
00586 bool ON_DimStyleExtra::CompareFields(const ON_DimStyleExtra* pOther) const
00587 {
00588   if(pOther == 0)
00589     return false;
00590 
00591   if((m_parent_dimstyle        != pOther->m_parent_dimstyle) ||
00592      (m_tolerance_style        != pOther->m_tolerance_style) ||
00593      (m_tolerance_resolution   != pOther->m_tolerance_resolution) ||
00594      (m_tolerance_upper_value  != pOther->m_tolerance_upper_value) ||
00595      (m_tolerance_lower_value  != pOther->m_tolerance_lower_value) ||
00596      (m_tolerance_height_scale != pOther->m_tolerance_height_scale) ||
00597      (m_baseline_spacing       != pOther->m_baseline_spacing) ||
00598      (m_bDrawMask              != pOther->m_bDrawMask) ||
00599      (m_mask_color_source      != pOther->m_mask_color_source) ||
00600      (m_mask_color             != pOther->m_mask_color) ||
00601      (m_dimscale               != pOther->m_dimscale) ||
00602      (m_dimscale_source        != pOther->m_dimscale_source)
00603      )
00604     return false;
00605 
00606   for(int i = 0; i < m_valid_fields.Count(); i++)
00607   {
00608     if(m_valid_fields[i] != pOther->m_valid_fields[i])
00609       return false;
00610   }
00611   return true;
00612 }
00613 
00614 
00615 ON_OBJECT_IMPLEMENT( ON_DimStyle, ON_Object, "81BD83D5-7120-41c4-9A57-C449336FF12C" );
00616 
00617 ON_DimStyle::ON_DimStyle()
00618 {
00619   // 26 Oct 2010
00620   // Can't create this here because reading files won't attach what's read from the file if 
00621   // there's already one there.
00622 //  ON_DimStyleExtra::DimStyleExtension( this);
00623   SetDefaultsNoExtension();
00624 }
00625 
00626 ON_DimStyle::~ON_DimStyle()
00627 {
00628 }
00629 
00630 void ON_DimStyle::SetDefaults()
00631 {
00632   // If there is already a userdata extension, reset it to the defaults,
00633   // but don't make one if its not there already
00634   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, false );
00635   if( pDE)
00636   {
00637     // 2 November 2011 Dale Lear
00638     //    The "default" settings are easily handled
00639     //    by not having the user data present in 
00640     //    the first place.  Please discuss changes
00641     //    with Dale Lear.
00642     //
00643     delete pDE;
00644 
00649   }
00650   SetDefaultsNoExtension();
00651 }
00652 
00653 // Need to be able to set defaults in base without creating extension
00654 // because file reading won't attach userdata if there's already one there
00655 void ON_DimStyle::SetDefaultsNoExtension()
00656 {
00657   m_dimstyle_index = -1;
00658   memset(&m_dimstyle_id,0,sizeof(m_dimstyle_id));
00659   m_dimstyle_name = L"Default";
00660 
00661   m_extextension = 0.5;
00662   m_extoffset = 0.5;
00663   m_arrowsize = 1.0;
00664   m_centermark = 0.5;
00665   m_textgap = 0.25;
00666   m_textheight = 1.0;
00667   m_textalign = ON::dtAboveLine;
00668   m_arrowtype = 0;
00669   m_angularunits = 0;
00670   m_lengthformat = 0;
00671   m_angleformat = 0;
00672   m_lengthresolution = 2;
00673   m_angleresolution = 2;
00674   m_fontindex = -1;
00675 
00676   // Added at 1.3
00677   m_lengthfactor = 1.0;  
00678   m_bAlternate = false;
00679   m_alternate_lengthfactor = 25.4;
00680   m_alternate_lengthformat = 0;
00681   m_alternate_lengthresolution = 2;
00682   m_alternate_angleformat = 0;
00683   m_alternate_angleresolution = 2;
00684 
00685   m_prefix = L"";
00686   m_suffix = L"";
00687   m_alternate_prefix = L" [";
00688   m_alternate_suffix = L"]";
00689   m_valid = 0;
00690 
00691   m_dimextension = 0.0;
00692 
00693   m_leaderarrowsize = 1.0;
00694   m_leaderarrowtype = 0;
00695   m_bSuppressExtension1 = false;
00696   m_bSuppressExtension2 = false;
00697 }
00698 
00699 
00700 // copy from ON_3dmAnnotationSettings and add a couple of fields
00701 ON_DimStyle& ON_DimStyle::operator=( const ON_3dmAnnotationSettings& src)
00702 {
00703   SetDefaults();
00704 
00705   m_extextension = src.m_dimexe;
00706   m_extoffset = src.m_dimexo;
00707   m_arrowsize = src.m_arrowlength;
00708   m_textalign = src.m_textalign;
00709   m_centermark = src.m_centermark;
00710   m_textgap = src.m_dimexo / 2.0;
00711   m_textheight = src.m_textheight;
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_lengthresolution = src.m_resolution;
00717   m_angleresolution = src.m_resolution;
00718 
00719   return *this;
00720 }
00721 
00723 //
00724 // ON_Object overrides
00725 
00726 ON_BOOL32 ON_DimStyle::IsValid( ON_TextLog* text_log ) const
00727 {
00728   return ( m_dimstyle_name.Length() > 0 && m_dimstyle_index >= 0);
00729 }
00730 
00731 void ON_DimStyle::Dump( ON_TextLog& dump ) const
00732 {
00733   const wchar_t* wsName = m_dimstyle_name;
00734   if ( !wsName )
00735     wsName = L"";
00736   dump.Print("dimstyle index = %d\n",m_dimstyle_index);
00737   dump.Print("dimstyle name = \"%ls\"\n",wsName);
00738 }
00739 
00740 ON_BOOL32 ON_DimStyle::Write(
00741        ON_BinaryArchive& file // serialize definition to binary archive
00742      ) const
00743 {
00744   // March 22, 2010 - Global DimStyle was obsoleted and moved into DimStyles
00745   // So now for writing older version files, its multiplied into all distance values
00746   double ds = 1.0;
00747   if(file.Archive3dmVersion() < 5)
00748     ds = DimScale();
00749 
00750   // changed to version 1.4 Dec 28, 05
00751   // changed to version 1.5 Mar 23, 06
00752   ON_BOOL32 rc = file.Write3dmChunkVersion(1,5);
00753 
00754   if (rc) rc = file.WriteInt(m_dimstyle_index);
00755   if (rc) rc = file.WriteString(m_dimstyle_name);
00756 
00757   if (rc) rc = file.WriteDouble(m_extextension * ds);
00758   if (rc) rc = file.WriteDouble(m_extoffset * ds);
00759   if (rc) rc = file.WriteDouble(m_arrowsize * ds);
00760   if (rc) rc = file.WriteDouble(m_centermark * ds);
00761   if (rc) rc = file.WriteDouble(m_textgap * ds);
00762   
00763   if (rc) rc = file.WriteInt(m_textalign);
00764   if (rc) rc = file.WriteInt(m_arrowtype);
00765   if (rc) rc = file.WriteInt(m_angularunits);
00766   if (rc) rc = file.WriteInt(m_lengthformat);
00767   if (rc) rc = file.WriteInt(m_angleformat);
00768   if (rc) rc = file.WriteInt(m_lengthresolution);
00769   if (rc) rc = file.WriteInt(m_angleresolution);
00770   if (rc) rc = file.WriteInt(m_fontindex);
00771 
00772   if (rc) rc = file.WriteDouble(m_textheight * ds);
00773 
00774   // added 1/13/05 ver 1.2
00775   if (rc) rc = file.WriteDouble(m_lengthfactor);
00776   if (rc) rc = file.WriteString(m_prefix);
00777   if (rc) rc = file.WriteString(m_suffix);
00778 
00779   if (rc) rc = file.WriteBool(m_bAlternate);
00780   if (rc) rc = file.WriteDouble(m_alternate_lengthfactor);
00781   if (rc) rc = file.WriteInt(m_alternate_lengthformat);
00782   if (rc) rc = file.WriteInt(m_alternate_lengthresolution);
00783   if (rc) rc = file.WriteInt(m_alternate_angleformat);
00784   if (rc) rc = file.WriteInt(m_alternate_angleresolution);
00785   if (rc) rc = file.WriteString(m_alternate_prefix);
00786   if (rc) rc = file.WriteString(m_alternate_suffix);
00787   if (rc) rc = file.WriteInt(m_valid);
00788 
00789   // Added 24 October 2005 ver 1.3
00790   if (rc) rc = file.WriteUuid(m_dimstyle_id);
00791 
00792   // Added Dec 28, 05 ver 1.4
00793   if (rc) rc = file.WriteDouble(m_dimextension * ds);
00794 
00795   // Added Mar 23 06 ver 1.5
00796   if (rc) rc = file.WriteDouble(m_leaderarrowsize * ds);
00797   if (rc) rc = file.WriteInt(m_leaderarrowtype);
00798   if (rc) rc = file.WriteBool(m_bSuppressExtension1);
00799   if (rc) rc = file.WriteBool(m_bSuppressExtension2);
00800 
00801   return rc;
00802 }
00803 
00804 ON_BOOL32 ON_DimStyle::Read(
00805        ON_BinaryArchive& file // restore definition from binary archive
00806      )
00807 {
00808   SetDefaultsNoExtension();
00809 
00810   int major_version = 0;
00811   int minor_version = 0;
00812   ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00813 
00814 
00815   if ( major_version >= 1 ) 
00816   {
00817     if ( rc) rc = file.ReadInt( &m_dimstyle_index);
00818     if ( rc) rc = file.ReadString( m_dimstyle_name);
00819     
00820     if ( rc) rc = file.ReadDouble( &m_extextension);
00821     if ( rc) rc = file.ReadDouble( &m_extoffset);
00822     if ( rc) rc = file.ReadDouble( &m_arrowsize);
00823     if ( rc) rc = file.ReadDouble( &m_centermark);
00824     if ( rc) rc = file.ReadDouble( &m_textgap);
00825     
00826     if ( rc) rc = file.ReadInt( &m_textalign);
00827     if ( rc) rc = file.ReadInt( &m_arrowtype);
00828     if ( rc) rc = file.ReadInt( &m_angularunits);
00829     if ( rc) rc = file.ReadInt( &m_lengthformat);
00830     if ( rc) rc = file.ReadInt( &m_angleformat);
00831     if ( rc) rc = file.ReadInt( &m_lengthresolution);
00832     if ( rc) rc = file.ReadInt( &m_angleresolution);
00833     if ( rc) rc = file.ReadInt( &m_fontindex);
00834 
00835     if( minor_version >= 1)
00836       if ( rc) rc = file.ReadDouble( &m_textheight);
00837 
00838     // added 1/13/05
00839     if( minor_version >= 2)
00840     {
00841       if (rc) rc = file.ReadDouble( &m_lengthfactor);
00842       if (rc) rc = file.ReadString( m_prefix);
00843       if (rc) rc = file.ReadString( m_suffix);
00844 
00845       if (rc) rc = file.ReadBool( &m_bAlternate);
00846       if (rc) rc = file.ReadDouble(&m_alternate_lengthfactor);
00847       if (rc) rc = file.ReadInt( &m_alternate_lengthformat);
00848       if (rc) rc = file.ReadInt( &m_alternate_lengthresolution);
00849       if (rc) rc = file.ReadInt( &m_alternate_angleformat);
00850       if (rc) rc = file.ReadInt( &m_alternate_angleresolution);
00851       if (rc) rc = file.ReadString( m_alternate_prefix);
00852       if (rc) rc = file.ReadString( m_alternate_suffix);
00853       if (rc) rc = file.ReadInt( &m_valid);
00854 
00855       if ( minor_version >= 3 )
00856       {
00857         if (rc) rc = file.ReadUuid(m_dimstyle_id);
00858       }
00859     }
00860     // Added Dec 28, 05 ver 1.4
00861     if( minor_version >= 4)
00862       if( rc) rc = file.ReadDouble( &m_dimextension);
00863 
00864     // Added Mar 23 06 ver 1.5
00865     if( minor_version >= 5)
00866     {
00867       if (rc) rc = file.ReadDouble( &m_leaderarrowsize);
00868       if (rc) rc = file.ReadInt( &m_leaderarrowtype);
00869       if (rc) rc = file.ReadBool( &m_bSuppressExtension1);
00870       if (rc) rc = file.ReadBool( &m_bSuppressExtension2);
00871     }
00872   }
00873   else
00874     rc = false;
00875 
00876   return rc;
00877 }
00878 
00879 void ON_DimStyle::EmergencyDestroy()
00880 {
00881   m_prefix.EmergencyDestroy();
00882   m_suffix.EmergencyDestroy();
00883   m_alternate_prefix.EmergencyDestroy();
00884   m_alternate_suffix.EmergencyDestroy();
00885 }
00886 
00888 //
00889 // Interface
00890 void ON_DimStyle::SetName( const wchar_t* s )
00891 {
00892   m_dimstyle_name = s;
00893   m_dimstyle_name.TrimLeftAndRight();
00894 }
00895 
00896 void ON_DimStyle::SetName( const char* s )
00897 {
00898   m_dimstyle_name = s;
00899   m_dimstyle_name.TrimLeftAndRight();
00900 }
00901 
00902 void ON_DimStyle::GetName( ON_wString& s ) const
00903 {
00904   s = m_dimstyle_name;
00905 }
00906 
00907 const wchar_t* ON_DimStyle::Name() const
00908 {
00909   const wchar_t* s = m_dimstyle_name;
00910   return s;
00911 }
00912 
00913 void ON_DimStyle::SetIndex(int i )
00914 {
00915   m_dimstyle_index = i;
00916 }
00917 
00918 int ON_DimStyle::Index() const
00919 {
00920   return m_dimstyle_index;
00921 }
00922 
00923 double ON_DimStyle::ExtExtension() const
00924 {
00925   return m_extextension;
00926 }
00927 
00928 void ON_DimStyle::SetExtExtension( const double e)
00929 {
00930   // Allow negative?
00931   m_extextension = e;
00932 }
00933 
00934 double ON_DimStyle::ExtOffset() const
00935 {
00936   return m_extoffset;
00937 }
00938 
00939 void ON_DimStyle::SetExtOffset( const double e)
00940 {
00941   m_extoffset = e;
00942 }
00943 
00944 double ON_DimStyle::ArrowSize() const
00945 {
00946   return m_arrowsize;
00947 }
00948 
00949 void ON_DimStyle::SetArrowSize( const double e)
00950 {
00951   m_arrowsize = e;
00952 }
00953 
00954 double ON_DimStyle::LeaderArrowSize() const
00955 {
00956   return m_leaderarrowsize;
00957 }
00958 
00959 void ON_DimStyle::SetLeaderArrowSize( const double e)
00960 {
00961   m_leaderarrowsize = e;
00962 }
00963 
00964 double ON_DimStyle::CenterMark() const
00965 {
00966   return m_centermark;
00967 }
00968 
00969 void ON_DimStyle::SetCenterMark( const double e)
00970 {
00971   m_centermark = e;
00972 }
00973 
00974 int ON_DimStyle::TextAlignment() const
00975 {
00976   return m_textalign;
00977 }
00978 
00979 void ON_DimStyle::SetTextAlignment( ON::eTextDisplayMode a)
00980 {
00981   m_textalign = a;
00982 }
00983 
00984 int ON_DimStyle::ArrowType() const
00985 {
00986   return m_arrowtype;
00987 }
00988 
00989 void ON_DimStyle::SetArrowType( eArrowType a)
00990 {
00991   m_arrowtype = a;
00992 }
00993 
00994 int ON_DimStyle::LeaderArrowType() const
00995 {
00996   return m_leaderarrowtype;
00997 }
00998 
00999 void ON_DimStyle::SetLeaderArrowType( eArrowType a)
01000 {
01001   m_leaderarrowtype = a;
01002 }
01003 
01004 int ON_DimStyle::AngularUnits() const
01005 {
01006   return m_angularunits;
01007 }
01008 
01009 void ON_DimStyle::SetAngularUnits( int u)
01010 {
01011   m_angularunits = u;
01012 }
01013 
01014 int ON_DimStyle::LengthFormat() const
01015 {
01016   return m_lengthformat;
01017 }
01018 
01019 void ON_DimStyle::SetLengthFormat( int f)
01020 {
01021   m_lengthformat = f;
01022 }
01023 
01024 int ON_DimStyle::AngleFormat() const
01025 {
01026   return m_angleformat;
01027 }
01028 
01029 void ON_DimStyle::SetAngleFormat( int f)
01030 {
01031   m_angleformat = f;
01032 }
01033 
01034 int ON_DimStyle::LengthResolution() const
01035 {
01036   return m_lengthresolution;
01037 }
01038 
01039 void ON_DimStyle::SetLengthResolution( int r)
01040 {
01041   if( r >= 0 && r < 16)
01042   {
01043     m_lengthresolution = r;
01044   }
01045 }
01046 
01047 int ON_DimStyle::AngleResolution() const
01048 {
01049   return m_angleresolution;
01050 }
01051 
01052 void ON_DimStyle::SetAngleResolution( int r)
01053 {
01054   if( r >= 0 && r < 16)
01055   {
01056     m_angleresolution = r;
01057   }
01058 }
01059 
01060 int ON_DimStyle::FontIndex() const
01061 {
01062   return m_fontindex;
01063 }
01064 
01065 void ON_DimStyle::SetFontIndex( int index)
01066 {
01067   m_fontindex = index;
01068 }
01069 
01070 double ON_DimStyle::TextGap() const
01071 {
01072   return m_textgap;
01073 }
01074 
01075 void ON_DimStyle::SetTextGap( double gap)
01076 {
01077   if( gap >= 0.0)
01078   {
01079     m_textgap = gap;
01080   }
01081 }
01082 
01083 double ON_DimStyle::TextHeight() const
01084 {
01085   return m_textheight;
01086 }
01087 
01088 void ON_DimStyle::SetTextHeight( double height)
01089 {
01090   if( ON_IsValid( height) && height > ON_SQRT_EPSILON)
01091   {
01092     m_textheight = height;
01093   }
01094 }
01095 
01096 
01097 double ON_DimStyle::LengthFactor() const
01098 {
01099   return m_lengthfactor;
01100 }
01101 void ON_DimStyle::SetLengthactor( double factor)
01102 {
01103   SetLengthFactor( factor);
01104 }
01105 void ON_DimStyle::SetLengthFactor( double factor)
01106 {
01107   m_lengthfactor = factor;
01108   //ValidateField( fn_lengthfactor);
01109   m_valid |= ( 1 << fn_lengthfactor);
01110 }
01111 
01112 bool ON_DimStyle::Alternate() const
01113 {
01114   return m_bAlternate;
01115 }
01116 void ON_DimStyle::SetAlternate( bool bAlternate)
01117 {
01118   m_bAlternate = bAlternate;
01119 }
01120 
01121 double ON_DimStyle::AlternateLengthFactor() const
01122 {
01123   return m_alternate_lengthfactor;
01124 }
01125 void ON_DimStyle::SetAlternateLengthactor( double factor)
01126 {
01127   SetAlternateLengthFactor( factor);
01128 }
01129 void ON_DimStyle::SetAlternateLengthFactor( double factor)
01130 {
01131   m_alternate_lengthfactor = factor;
01132   //ValidateField( fn_alternate_lengthfactor);
01133   m_valid |= ( 1 << fn_alternate_lengthfactor);
01134 }
01135 
01136 int ON_DimStyle::AlternateLengthFormat() const
01137 {
01138   return m_alternate_lengthformat;
01139 }
01140 void ON_DimStyle::SetAlternateLengthFormat( int format)
01141 {
01142   m_alternate_lengthformat = format;
01143 }
01144 
01145 int ON_DimStyle::AlternateLengthResolution() const
01146 {
01147   return m_alternate_lengthresolution;
01148 }
01149 void ON_DimStyle::SetAlternateLengthResolution( int resolution)
01150 {
01151   m_alternate_lengthresolution = resolution;
01152 }
01153 
01154 int ON_DimStyle::AlternateAngleFormat() const
01155 {
01156   return m_alternate_angleformat;
01157 }
01158 void ON_DimStyle::SetAlternateAngleFormat( int format)
01159 {
01160   m_alternate_angleformat = format;
01161 }
01162 
01163 int ON_DimStyle::AlternateAngleResolution() const
01164 {
01165   return m_alternate_angleresolution;
01166 }
01167 void ON_DimStyle::SetAlternateAngleResolution( int resolution)
01168 {
01169   m_alternate_angleresolution = resolution;
01170 }
01171 
01172 void ON_DimStyle::GetPrefix( ON_wString& prefix) const
01173 {
01174   prefix = m_prefix;
01175 }
01176 const wchar_t* ON_DimStyle::Prefix() const
01177 {
01178   return m_prefix;
01179 }
01180 void ON_DimStyle::SetPrefix( wchar_t* prefix)
01181 {
01182   m_prefix = prefix;
01183 }
01184 void ON_DimStyle::SetPrefix( const wchar_t* prefix)
01185 {
01186   m_prefix = prefix;
01187 }
01188 
01189 void ON_DimStyle::GetSuffix( ON_wString& suffix) const
01190 {
01191   suffix = m_suffix;
01192 }
01193 const wchar_t* ON_DimStyle::Suffix() const
01194 {
01195   return m_suffix;
01196 }
01197 void ON_DimStyle::SetSuffix( wchar_t* suffix)
01198 {
01199   m_suffix = suffix;
01200 }
01201 void ON_DimStyle::SetSuffix( const wchar_t* suffix)
01202 {
01203   m_suffix = suffix;
01204 }
01205 
01206 void ON_DimStyle::GetAlternatePrefix( ON_wString& prefix) const
01207 {
01208   prefix = m_alternate_prefix;
01209 }
01210 const wchar_t* ON_DimStyle::AlternatePrefix() const
01211 {
01212   return m_alternate_prefix;
01213 }
01214 void ON_DimStyle::SetAlternatePrefix( wchar_t* prefix)
01215 {
01216   m_alternate_prefix = prefix;
01217 }
01218 void ON_DimStyle::SetAlternatePrefix( const wchar_t* prefix)
01219 {
01220   m_alternate_prefix = prefix;
01221 }
01222 
01223 void ON_DimStyle::GetAlternateSuffix( ON_wString& suffix) const
01224 {
01225   suffix = m_alternate_suffix;
01226 }
01227 const wchar_t* ON_DimStyle::AlternateSuffix() const
01228 {
01229   return m_alternate_suffix;
01230 }
01231 void ON_DimStyle::SetAlternateSuffix( wchar_t* suffix)
01232 {
01233   m_alternate_suffix = suffix;
01234 }
01235 void ON_DimStyle::SetAlternateSuffix( const wchar_t* suffix)
01236 {
01237   m_alternate_suffix = suffix;
01238 }
01239 
01240 bool ON_DimStyle::SuppressExtension1() const
01241 {
01242   return m_bSuppressExtension1;
01243 }
01244 void ON_DimStyle::SetSuppressExtension1( bool suppress)
01245 {
01246   m_bSuppressExtension1 = suppress;
01247 }
01248 bool ON_DimStyle::SuppressExtension2() const
01249 {
01250   return m_bSuppressExtension2;
01251 }
01252 void ON_DimStyle::SetSuppressExtension2( bool suppress)
01253 {
01254   m_bSuppressExtension2 = suppress;
01255 }
01256 
01257 // This function deprecated 5/01/07 LW
01258 void ON_DimStyle::Composite( const ON_DimStyle& OverRide)
01259 {
01260 /*
01261   InvalidateAllFields();
01262 
01263   if( OverRide.IsFieldValid( fn_name))                          { ValidateField( fn_name); m_dimstyle_name = OverRide.m_dimstyle_name; }
01264   if( OverRide.IsFieldValid( fn_index))                         { ValidateField( fn_index); m_dimstyle_index = OverRide.m_dimstyle_index; }
01265   if( OverRide.IsFieldValid( fn_extextension))                  { ValidateField( fn_extextension); m_extextension = OverRide.m_extextension; }
01266   if( OverRide.IsFieldValid( fn_extoffset))                     { ValidateField( fn_extoffset); m_extoffset = OverRide.m_extoffset; }
01267   if( OverRide.IsFieldValid( fn_arrowsize))                     { ValidateField( fn_arrowsize); m_arrowsize = OverRide.m_arrowsize; }
01268   if( OverRide.IsFieldValid( fn_leaderarrowsize))               { ValidateField( fn_leaderarrowsize); m_leaderarrowsize = OverRide.m_leaderarrowsize; }
01269   if( OverRide.IsFieldValid( fn_centermark))                    { ValidateField( fn_centermark); m_centermark = OverRide.m_centermark; }
01270   if( OverRide.IsFieldValid( fn_textgap))                       { ValidateField( fn_textgap); m_textgap = OverRide.m_textgap; }
01271   if( OverRide.IsFieldValid( fn_textheight))                    { ValidateField( fn_textheight); m_textheight = OverRide.m_textheight; }
01272   if( OverRide.IsFieldValid( fn_textalign))                     { ValidateField( fn_textalign); m_textalign = OverRide.m_textalign; }
01273   if( OverRide.IsFieldValid( fn_arrowtype))                     { ValidateField( fn_arrowtype); m_arrowtype = OverRide.m_arrowtype; }
01274   if( OverRide.IsFieldValid( fn_leaderarrowtype))               { ValidateField( fn_leaderarrowtype); m_leaderarrowtype = OverRide.m_leaderarrowtype; }
01275   if( OverRide.IsFieldValid( fn_angularunits))                  { ValidateField( fn_angularunits); m_angularunits = OverRide.m_angularunits; }
01276   if( OverRide.IsFieldValid( fn_lengthformat))                  { ValidateField( fn_lengthformat); m_lengthformat = OverRide.m_lengthformat; }
01277   if( OverRide.IsFieldValid( fn_angleformat))                   { ValidateField( fn_angleformat); m_angleformat = OverRide.m_angleformat; }
01278   if( OverRide.IsFieldValid( fn_angleresolution))               { ValidateField( fn_angleresolution); m_angleresolution = OverRide.m_angleresolution; }
01279   if( OverRide.IsFieldValid( fn_lengthresolution))              { ValidateField( fn_lengthresolution); m_lengthresolution = OverRide.m_lengthresolution; }
01280   if( OverRide.IsFieldValid( fn_fontindex))                     { ValidateField( fn_fontindex); m_fontindex = OverRide.m_fontindex; }
01281   if( OverRide.IsFieldValid( fn_lengthfactor))                  { ValidateField( fn_lengthfactor); m_lengthfactor = OverRide.m_lengthfactor; }
01282   if( OverRide.IsFieldValid( fn_bAlternate))                    { ValidateField( fn_bAlternate); m_bAlternate = OverRide.m_bAlternate; }
01283   if( OverRide.IsFieldValid( fn_alternate_lengthfactor))        { ValidateField( fn_alternate_lengthfactor); m_alternate_lengthfactor = OverRide.m_alternate_lengthfactor; }
01284   if( OverRide.IsFieldValid( fn_alternate_lengthformat))        { ValidateField( fn_alternate_lengthformat); m_alternate_lengthformat = OverRide.m_alternate_lengthformat; }
01285   if( OverRide.IsFieldValid( fn_alternate_lengthresolution))    { ValidateField( fn_alternate_lengthresolution); m_alternate_lengthresolution = OverRide.m_alternate_lengthresolution; }
01286   if( OverRide.IsFieldValid( fn_prefix))                        { ValidateField( fn_prefix); m_prefix = OverRide.m_prefix; }
01287   if( OverRide.IsFieldValid( fn_suffix))                        { ValidateField( fn_suffix); m_suffix = OverRide.m_suffix; }
01288   if( OverRide.IsFieldValid( fn_alternate_prefix))              { ValidateField( fn_alternate_prefix); m_alternate_prefix = OverRide.m_alternate_prefix; }
01289   if( OverRide.IsFieldValid( fn_alternate_suffix))              { ValidateField( fn_alternate_suffix); m_alternate_suffix = OverRide.m_alternate_suffix; }
01290   if( OverRide.IsFieldValid( fn_dimextension))                  { ValidateField( fn_dimextension); m_dimextension = OverRide.m_dimextension; }
01291   if( OverRide.IsFieldValid( fn_suppressextension1))            { ValidateField( fn_suppressextension1); m_bSuppressExtension1 = OverRide.m_bSuppressExtension1; }
01292   if( OverRide.IsFieldValid( fn_suppressextension2))            { ValidateField( fn_suppressextension2); m_bSuppressExtension2 = OverRide.m_bSuppressExtension2; }
01293 */
01294 }
01295 
01296 // This function deprecated 5/01/07 LW
01297 void ON_DimStyle::InvalidateField( eField field)
01298 {
01299   m_valid &= ~( 1 << field);
01300 }
01301 // This function deprecated 5/01/07 LW
01302 void ON_DimStyle::InvalidateAllFields()
01303 {
01304   m_valid = 0;
01305 }
01306 // This function deprecated 5/01/07 LW
01307 void ON_DimStyle::ValidateField( eField field)
01308 {
01309   m_valid |= ( 1 << field);
01310 }
01311 // This function deprecated 5/01/07 LW
01312 bool ON_DimStyle::IsFieldValid( eField field) const
01313 {
01314   return ( m_valid & ( 1 << field)) ? true : false;
01315 }
01316 
01317 
01318 // ver 1.4, Dec 28, 05
01319 double ON_DimStyle::DimExtension() const
01320 {
01321   return m_dimextension;
01322 }
01323 
01324 void ON_DimStyle::SetDimExtension( const double e)
01325 {
01326   // Allow negative?
01327   m_dimextension = e;
01328 }
01329 
01330 //--------------------------------------
01331 // ON_DimStyleExtra access functions
01332 // Added for v5 5/01/07 LW
01333 
01334 bool ON_DimStyle::IsFieldOverride( ON_DimStyle::eField field_id) const
01335 {
01336   const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this);
01337   if(pDE)
01338     return pDE->IsFieldOverride( field_id);
01339 
01340   return false;
01341 }
01342 
01343 void ON_DimStyle::SetFieldOverride(  ON_DimStyle::eField field_id, bool bOverride)
01344 {
01345   // 2 November 2011 Dale Lear
01346   //   If bOverride is true, then create the userdata, otherwise get it 
01347   //   only if it exists.
01348   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bOverride );
01349   if(pDE)
01350   {
01351     pDE->SetFieldOverride( field_id, bOverride);
01352   }
01353 }
01354   
01355 bool ON_DimStyle::HasOverrides() const 
01356 {
01357   const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this );
01358   if(pDE)
01359   {
01360     for( int i = 0; i < pDE->m_valid_fields.Count(); i++)
01361     {
01362       if( pDE->m_valid_fields[i])
01363         return true;
01364     }
01365   }
01366   return false;
01367 }
01368 
01369 bool ON_DimStyle::OverrideFields( const ON_DimStyle& src, const ON_DimStyle& parent)
01370 {
01371   // 2 November 2011 Dale Lear
01372   //   I made lots of changes to this function to make sure "i" was a valid
01373   //   array index before it was passed to operator[].
01374   const ON_DimStyleExtra* pDEsrc = ON_DimStyleExtra::DimStyleExtensionGet( &src);
01375 
01376   // Please do not change the 2nd parameter from "false" to a "true" in the
01377   // call to DimStyleExtensionGet().  If "this" does not have ON_DimStyleExtra
01378   // user data at this point, it will be created if it is actually needed.
01379   // If you have questions, please ask Dale Lear.
01380   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, false );
01381 
01382   const int src_valid_fields_count = pDEsrc ? pDEsrc->m_valid_fields.Count() : 0;
01383   int this_valid_fields_count = pDE ? pDE->m_valid_fields.Count() : 0;
01384 
01385   for( int i = 0; i < ON_DimStyleExtra::eFieldCount; i++)
01386   {
01387     bool bValidSrcField = ( 0 != pDEsrc && i < src_valid_fields_count )
01388                         ? pDEsrc->m_valid_fields[i]
01389                         : false;
01390 
01391     if ( bValidSrcField && 0 == pDE )
01392     {
01393       // Actually need to create ON_DimStyleExtra user data on "this".
01394       pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, true );
01395       if ( pDE )
01396         this_valid_fields_count = pDE->m_valid_fields.Count();
01397     }
01398 
01399     if ( 0 != pDE && i < this_valid_fields_count )
01400     {
01401       pDE->m_valid_fields[i] = bValidSrcField;
01402     }
01403 
01404     const ON_DimStyle* copyfrom = bValidSrcField ? (&src) : (&parent);
01405 
01406     switch( i)
01407     {
01408     case fn_extextension:
01409       SetExtExtension( copyfrom->ExtExtension());
01410       break;
01411     case fn_extoffset:
01412       SetExtOffset( copyfrom->ExtOffset());
01413       break;
01414     case fn_arrowsize:
01415       SetArrowSize( copyfrom->ArrowSize());
01416       break;
01417     case fn_centermark:
01418       SetCenterMark( copyfrom->CenterMark());
01419       break;
01420     case fn_textgap:
01421       SetTextGap( copyfrom->TextGap());
01422       break;
01423     case fn_textheight:
01424       SetTextHeight( copyfrom->TextHeight());
01425       break;
01426     case fn_textalign:
01427       SetTextAlignment( (ON::eTextDisplayMode)copyfrom->TextAlignment());
01428       break;
01429     case fn_arrowtype:
01430       SetArrowType( (eArrowType)copyfrom->ArrowType());
01431       break;
01432     case fn_angularunits:
01433       SetAngularUnits( (eArrowType)copyfrom->AngularUnits());
01434       break;
01435     case fn_lengthformat:
01436       SetLengthFormat( copyfrom->LengthFormat());
01437       break;
01438     case fn_angleformat:
01439       SetAngleFormat( copyfrom->AngleFormat());
01440       break;
01441     case fn_angleresolution:
01442       SetAngleResolution( copyfrom->AngleResolution());
01443       break;
01444     case fn_lengthresolution:
01445       SetLengthResolution( copyfrom->LengthResolution());
01446       break;
01447     case fn_fontindex:
01448       SetFontIndex( copyfrom->FontIndex());
01449       break;
01450     case fn_lengthfactor:
01451       SetLengthFactor( copyfrom->LengthFactor());
01452       break;
01453     case fn_bAlternate:
01454       SetAlternate( copyfrom->Alternate());
01455       break;
01456     case fn_alternate_lengthfactor:
01457       SetAlternateLengthFactor( copyfrom->AlternateLengthFactor());
01458       break;
01459     case fn_alternate_lengthformat:
01460       SetAlternateLengthFormat( copyfrom->AlternateLengthFormat());
01461       break;
01462     case fn_alternate_lengthresolution:
01463       SetAlternateLengthResolution( copyfrom->AlternateLengthResolution());
01464       break;
01465     case fn_alternate_angleformat:
01466       SetAlternateLengthResolution( copyfrom->AlternateLengthResolution());
01467       break;
01468     case fn_alternate_angleresolution:
01469       SetAlternateAngleResolution( copyfrom->AlternateAngleResolution());
01470       break;
01471     case fn_prefix:
01472       SetPrefix( copyfrom->Prefix());
01473       break;
01474     case fn_suffix:
01475       SetSuffix( copyfrom->Suffix());
01476       break;
01477     case fn_alternate_prefix:
01478       SetAlternatePrefix( copyfrom->AlternatePrefix());
01479       break;
01480     case fn_alternate_suffix:
01481       SetAlternateSuffix( copyfrom->AlternateSuffix());
01482       break;
01483     case fn_dimextension:
01484       SetDimExtension( copyfrom->DimExtension());
01485       break;
01486     case fn_leaderarrowsize:
01487       SetLeaderArrowSize( copyfrom->LeaderArrowSize());
01488       break;
01489     case fn_leaderarrowtype:
01490       SetLeaderArrowType( (eArrowType)copyfrom->LeaderArrowType());
01491       break;
01492     case fn_suppressextension1:
01493       SetSuppressExtension1( copyfrom->SuppressExtension1());
01494       break;
01495     case fn_suppressextension2:
01496       SetSuppressExtension2( copyfrom->SuppressExtension2());
01497       break;
01498     case fn_tolerance_style:
01499       SetToleranceStyle( copyfrom->ToleranceStyle());
01500       break;
01501     case fn_tolerance_resolution:
01502       SetToleranceResolution( copyfrom->ToleranceResolution());
01503       break;
01504     case fn_tolerance_upper_value:
01505       SetToleranceUpperValue( copyfrom->ToleranceUpperValue());
01506       break;
01507     case fn_tolerance_lower_value:
01508       SetToleranceLowerValue( copyfrom->ToleranceLowerValue());
01509       break;
01510     case fn_tolerance_height_scale:
01511       SetToleranceHeightScale( copyfrom->ToleranceHeightScale());
01512       break;
01513     case fn_baseline_spacing:
01514       SetBaselineSpacing( copyfrom->BaselineSpacing());
01515       break;
01516     case fn_draw_mask:
01517       SetDrawTextMask( copyfrom->DrawTextMask());
01518       break;
01519     case fn_mask_color_source:
01520       SetMaskColorSource( copyfrom->MaskColorSource());
01521       break;
01522     case fn_mask_color:
01523       SetMaskColor( copyfrom->MaskColor());
01524       break;
01525     case fn_dimscale:
01526       SetDimScale( copyfrom->DimScale());
01527       break;
01528     case fn_dimscale_source:
01529       SetDimScaleSource( copyfrom->DimScaleSource());
01530       break;
01531     }
01532   }
01533   return true;
01534 }
01535 
01536 bool ON_DimStyle::InheritFields( const ON_DimStyle& parent)
01537 {
01538   bool rc = false;
01539 
01540   // 2 November 2011 Dale Lear
01541   //   Please do not create ON_DimStyleExtra user data if
01542   //   it does not exist on this.
01543   const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this);
01544   for( int i = 0; i < ON_DimStyleExtra::eFieldCount; i++ )
01545   {
01546     bool bValidField = ( 0 != pDE && i < pDE->m_valid_fields.Count() )
01547                      ? pDE->m_valid_fields[i] : 
01548                      false;
01549                      
01550     switch( i)
01551     {
01552     case fn_extextension:
01553       if( !bValidField)
01554       {
01555         SetExtExtension( parent.ExtExtension());
01556         rc = true;
01557       }
01558       break;
01559     case fn_extoffset:
01560       if( !bValidField)
01561       {
01562         SetExtOffset( parent.ExtOffset());
01563         rc = true;
01564       }
01565       break;
01566     case fn_arrowsize:
01567       if( !bValidField)
01568       {
01569         SetArrowSize( parent.ArrowSize());
01570         rc = true;
01571       }
01572       break;
01573     case fn_centermark:
01574       if( !bValidField)
01575       {
01576         SetCenterMark( parent.CenterMark());
01577         rc = true;
01578       }
01579       break;
01580     case fn_textgap:
01581       if( !bValidField)
01582       {
01583         SetTextGap( parent.TextGap());
01584         rc = true;
01585       }
01586       break;
01587     case fn_textheight:
01588       if( !bValidField)
01589       {
01590         SetTextHeight( parent.TextHeight());
01591         rc = true;
01592       }
01593       break;
01594     case fn_textalign:
01595       if( !bValidField)
01596       {
01597         SetTextAlignment( (ON::eTextDisplayMode)parent.TextAlignment());
01598         rc = true;
01599       }
01600       break;
01601     case fn_arrowtype:
01602       if( !bValidField)
01603       {
01604         SetArrowType( (eArrowType)parent.ArrowType());
01605         rc = true;
01606       }
01607       break;
01608     case fn_angularunits:
01609       if( !bValidField)
01610       {
01611         SetAngularUnits( (eArrowType)parent.AngularUnits());
01612         rc = true;
01613       }
01614       break;
01615     case fn_lengthformat:
01616       if( !bValidField)
01617       {
01618         SetLengthFormat( parent.LengthFormat());
01619         rc = true;
01620       }
01621       break;
01622     case fn_angleformat:
01623       if( !bValidField)
01624       {
01625         SetAngleFormat( parent.AngleFormat());
01626         rc = true;
01627       }
01628       break;
01629     case fn_angleresolution:
01630       if( !bValidField)
01631       {
01632         SetAngleResolution( parent.AngleResolution());
01633         rc = true;
01634       }
01635       break;
01636     case fn_lengthresolution:
01637       if( !bValidField)
01638       {
01639         SetLengthResolution( parent.LengthResolution());
01640         rc = true;
01641       }
01642       break;
01643     case fn_fontindex:
01644       if( !bValidField)
01645       {
01646         SetFontIndex( parent.FontIndex());
01647         rc = true;
01648       }
01649       break;
01650     case fn_lengthfactor:
01651       if( !bValidField)
01652       {
01653         SetLengthFactor( parent.LengthFactor());
01654         rc = true;
01655       }
01656       break;
01657     case fn_bAlternate:
01658       if( !bValidField)
01659       {
01660         SetAlternate( parent.Alternate());
01661         rc = true;
01662       }
01663       break;
01664     case fn_alternate_lengthfactor:
01665       if( !bValidField)
01666       {
01667         SetAlternateLengthFactor( parent.LengthFactor());
01668         rc = true;
01669       }
01670       break;
01671     case fn_alternate_lengthformat:
01672       if( !bValidField)
01673       {
01674         SetAlternateLengthFormat( parent.AlternateLengthFormat());
01675         rc = true;
01676       }
01677       break;
01678     case fn_alternate_lengthresolution:
01679       if( !bValidField)
01680       {
01681         SetAlternateLengthResolution( parent.AlternateLengthResolution());
01682         rc = true;
01683       }
01684       break;
01685     case fn_alternate_angleformat:
01686       if( !bValidField)
01687       {
01688         SetAlternateLengthResolution( parent.AlternateLengthResolution());
01689         rc = true;
01690       }
01691       break;
01692     case fn_alternate_angleresolution:
01693       if( !bValidField)
01694       {
01695         SetAlternateAngleResolution( parent.AlternateAngleResolution());
01696         rc = true;
01697       }
01698       break;
01699     case fn_prefix:
01700       if( !bValidField)
01701       {
01702         SetPrefix( parent.Prefix());
01703         rc = true;
01704       }
01705       break;
01706     case fn_suffix:
01707       if( !bValidField)
01708       {
01709         SetSuffix( parent.Suffix());
01710         rc = true;
01711       }
01712       break;
01713     case fn_alternate_prefix:
01714       if( !bValidField)
01715       {
01716         SetAlternatePrefix( parent.AlternatePrefix());
01717         rc = true;
01718       }
01719       break;
01720     case fn_alternate_suffix:
01721       if( !bValidField)
01722       {
01723         SetAlternateSuffix( parent.AlternateSuffix());
01724         rc = true;
01725       }
01726       break;
01727     case fn_dimextension:
01728       if( !bValidField)
01729       {
01730         SetDimExtension( parent.DimExtension());
01731         rc = true;
01732       }
01733       break;
01734     case fn_leaderarrowsize:
01735       if( !bValidField)
01736       {
01737         SetLeaderArrowSize( parent.LeaderArrowSize());
01738         rc = true;
01739       }
01740       break;
01741     case fn_leaderarrowtype:
01742       if( !bValidField)
01743       {
01744         SetLeaderArrowType( (eArrowType)parent.LeaderArrowType());
01745         rc = true;
01746       }
01747       break;
01748     case fn_suppressextension1:
01749       if( !bValidField)
01750       {
01751         SetSuppressExtension1( parent.SuppressExtension1());
01752         rc = true;
01753       }
01754       break;
01755     case fn_suppressextension2:
01756       if( !bValidField)
01757       {
01758         SetSuppressExtension2( parent.SuppressExtension2());
01759         rc = true;
01760       }
01761       break;
01762     case fn_tolerance_style:
01763       if( !bValidField)
01764       {
01765         SetToleranceStyle( parent.ToleranceStyle());
01766         rc = true;
01767       }
01768       break;
01769     case fn_tolerance_resolution:
01770       if( !bValidField)
01771       {
01772         SetToleranceResolution( parent.ToleranceResolution());
01773         rc = true;
01774       }
01775       break;
01776     case fn_tolerance_upper_value:
01777       if( !bValidField)
01778       {
01779         SetToleranceUpperValue( parent.ToleranceUpperValue());
01780         rc = true;
01781       }
01782       break;
01783     case fn_tolerance_lower_value:
01784       if( !bValidField)
01785       {
01786         SetToleranceLowerValue( parent.ToleranceLowerValue());
01787         rc = true;
01788       }
01789       break;
01790     case fn_tolerance_height_scale:
01791       if( !bValidField)
01792       {
01793         SetToleranceHeightScale( parent.ToleranceHeightScale());
01794         rc = true;
01795       }
01796       break;
01797     case fn_baseline_spacing:
01798       if( !bValidField)
01799       {
01800         SetBaselineSpacing( parent.BaselineSpacing());
01801           rc = true;
01802       }
01803       break;
01804     case fn_draw_mask:
01805       if( !bValidField)
01806       {
01807         SetDrawTextMask( parent.DrawTextMask());
01808           rc = true;
01809       }
01810       break;
01811     case fn_mask_color_source:
01812       if( !bValidField)
01813       {
01814         SetMaskColorSource( parent.MaskColorSource());
01815           rc = true;
01816       }
01817       break;
01818     case fn_mask_color:
01819       if( !bValidField)
01820       {
01821         SetMaskColor( parent.MaskColor());
01822           rc = true;
01823       }
01824       break;
01825     case fn_dimscale:
01826       if( !bValidField)
01827       {
01828         SetDimScale( parent.DimScale());
01829           rc = true;
01830       }
01831       break;
01832     case fn_dimscale_source:
01833       if( !bValidField)
01834       {
01835         SetDimScaleSource( parent.DimScaleSource());
01836           rc = true;
01837       }
01838       break;
01839     }
01840   }
01841   return rc;
01842 }
01843 
01844 
01845 bool ON_DimStyle::IsChildDimstyle() const
01846 {
01847   const ON_DimStyleExtra* pDE = DimStyleExtension();
01848   if(pDE && pDE->m_parent_dimstyle != ON_nil_uuid)
01849     return true;
01850   else
01851     return false;
01852 }
01853 
01854 bool ON_DimStyle::IsChildOf( ON_UUID& parent_uuid) const
01855 {
01856   // delete this old function when SDK can be broken.
01857   // parameter needed a const
01858   const ON_DimStyleExtra* pDE = DimStyleExtension();
01859   if(pDE && parent_uuid != ON_nil_uuid && pDE->m_parent_dimstyle == parent_uuid)
01860     return true;
01861   else
01862     return false;
01863 }
01864 
01865 bool ON_DimStyle::IsChildOf( const ON_UUID& parent_uuid) const
01866 {
01867   const ON_DimStyleExtra* pDE = DimStyleExtension();
01868   if(pDE && parent_uuid != ON_nil_uuid && pDE->m_parent_dimstyle == parent_uuid)
01869     return true;
01870   else
01871     return false;
01872 }
01873 
01874 void ON_DimStyle::SetParent( ON_UUID& parent_uuid)
01875 {
01876   // delete this old function when SDK can be broken.
01877   // parameter needed a const
01878   SetParentId(parent_uuid);
01879 }
01880 
01881 void ON_DimStyle::SetParentId( ON_UUID parent_id )
01882 {
01883   bool bCreateIfNoneExists = !ON_UuidIsNil(parent_id);
01884   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfNoneExists );
01885   if ( pDE )
01886     pDE->m_parent_dimstyle = parent_id;
01887 }
01888 
01889 
01890 ON_UUID ON_DimStyle::ParentId() const
01891 {
01892   const ON_DimStyleExtra* pDE = DimStyleExtension(); // get existing
01893   return ( 0 != pDE ? pDE->m_parent_dimstyle : ON_nil_uuid );
01894 }
01895 
01896 bool ON_DimStyleExtra::IsFieldOverride( int field_id) const
01897 {
01898   if( field_id >= 0 && field_id < m_valid_fields.Count())
01899     return m_valid_fields[field_id];
01900   else
01901     return false;
01902 }
01903 
01904 void ON_DimStyleExtra::SetFieldOverride( int field_id, bool bOverride)
01905 {
01906   if( field_id >= 0 && field_id < m_valid_fields.Count())
01907     m_valid_fields[field_id] = bOverride;
01908 }
01909 
01910 // Tolerances
01911 // Tolerance style
01912 //  0: None
01913 //  1: Symmetrical
01914 //  2: Deviation
01915 //  3: Limits
01916 //  4: Basic
01917 int ON_DimStyle::ToleranceStyle() const
01918 {
01919   // 2 November 2011 Dale Lear
01920   //   Changed to NOT create ON_DimStyleExtra user data
01921   //   if it did not already exist.
01922   const ON_DimStyleExtra* pDE = DimStyleExtension();
01923   if(pDE)
01924     return pDE->ToleranceStyle();
01925   else
01926     return ON_DimStyle::DefaultToleranceStyle();
01927 }
01928 
01929 int ON_DimStyle::ToleranceResolution() const
01930 {
01931   // 2 November 2011 Dale Lear
01932   //   Changed to NOT create ON_DimStyleExtra user data
01933   //   if it did not already exist.
01934   const ON_DimStyleExtra* pDE = DimStyleExtension();
01935   if(pDE)
01936     return pDE->ToleranceResolution();
01937   else
01938     return ON_DimStyle::DefaultToleranceResolution();
01939 }
01940 
01941 double ON_DimStyle::ToleranceUpperValue() const
01942 {
01943   // 2 November 2011 Dale Lear
01944   //   Changed to NOT create ON_DimStyleExtra user data
01945   //   if it did not already exist.
01946   const ON_DimStyleExtra* pDE = DimStyleExtension();
01947   if(pDE)
01948     return pDE->ToleranceUpperValue();
01949   else
01950     return ON_DimStyle::DefaultToleranceUpperValue();
01951 }
01952 
01953 double ON_DimStyle::ToleranceLowerValue() const
01954 {
01955   // 2 November 2011 Dale Lear
01956   //   Changed to NOT create ON_DimStyleExtra user data
01957   //   if it did not already exist.
01958   const ON_DimStyleExtra* pDE = DimStyleExtension();
01959   if(pDE)
01960     return pDE->ToleranceLowerValue();
01961   else
01962     return ON_DimStyle::DefaultToleranceLowerValue();
01963 }
01964 
01965 double ON_DimStyle::ToleranceHeightScale() const
01966 {
01967   // 2 November 2011 Dale Lear
01968   //   Changed to NOT create ON_DimStyleExtra user data
01969   //   if it did not already exist.
01970   const ON_DimStyleExtra* pDE = DimStyleExtension();
01971   if(pDE)
01972     return pDE->ToleranceHeightScale();
01973   else
01974     return ON_DimStyle::DefaultToleranceHeightScale();
01975 }
01976 
01977 double ON_DimStyle::BaselineSpacing() const
01978 {
01979   // 2 November 2011 Dale Lear
01980   //   Changed to NOT create ON_DimStyleExtra user data
01981   //   if it did not already exist.
01982   const ON_DimStyleExtra* pDE = DimStyleExtension();
01983   if(pDE)
01984     return pDE->BaselineSpacing();
01985   else
01986     return ON_DimStyle::DefaultBaselineSpacing();
01987 }
01988 
01989 //static 
01990 int ON_DimStyle::DefaultToleranceStyle()
01991 {
01992   return 0;
01993 }
01994 
01995 //static 
01996 int ON_DimStyle::DefaultToleranceResolution()
01997 {
01998   return 4;
01999 }
02000 
02001 //static 
02002 double ON_DimStyle::DefaultToleranceUpperValue()
02003 {
02004   return 0.0;
02005 }
02006 
02007 //static 
02008 double ON_DimStyle::DefaultToleranceLowerValue()
02009 {
02010   return 0.0;
02011 }
02012 
02013 //static 
02014 double ON_DimStyle::DefaultToleranceHeightScale()
02015 {
02016   return 1.0;
02017 }
02018 
02019 //static 
02020 double ON_DimStyle::DefaultBaselineSpacing()
02021 {
02022   return 1.0;
02023 }
02024 
02025 // static
02026 bool ON_DimStyle::DefaultDrawTextMask()
02027 {
02028   return false;
02029 }
02030 
02031 // static
02032 int ON_DimStyle::DefaultMaskColorSource()
02033 {
02034   return 0;
02035 }
02036 
02037 // static
02038 ON_Color ON_DimStyle::DefaultMaskColor()
02039 {
02040   // 2 November 2011 Dale Lear
02041   //   TODO - Ask Lowell what this default is supposed to be.
02042   //          His ON_DimStyle::MaskColor() function defaulted to black
02043   //          and his ON_DimStyleExtra defaulted to white.
02044   //return 0;
02045   return ON_Color(255,255,255);
02046 }
02047 
02048 // static
02049 double ON_DimStyle::DefaultDimScale()
02050 {
02051   return 1.0;
02052 }
02053 
02054 // static
02055 int ON_DimStyle::DefaultDimScaleSource()
02056 {
02057   return 0;
02058 }
02059 
02060 
02061 //-------------------
02062 void ON_DimStyle::Scale( double scale)
02063 {
02064   if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON && 1.0 != scale )
02065   {
02066     m_extextension    *= scale;
02067     m_extoffset       *= scale;
02068     m_arrowsize       *= scale;
02069     m_centermark      *= scale;
02070     m_textgap         *= scale;
02071     m_textheight      *= scale;
02072     m_dimextension    *= scale;
02073     m_leaderarrowsize *= scale;
02074 
02075     ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, true );
02076     if(pDE)
02077     {
02078       pDE->Scale( scale);
02079     }
02080   }
02081 }
02082 
02083 void ON_DimStyle::SetToleranceStyle( int style)
02084 {
02085   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceStyle() != style );
02086   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02087   if(pDE)
02088   {
02089     pDE->SetToleranceStyle( style);
02090   }
02091 }
02092 
02093 void ON_DimStyle::SetToleranceResolution( int resolution)
02094 {
02095   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceResolution() != resolution );
02096   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02097   if(pDE)
02098   {
02099     pDE->SetToleranceResolution( resolution);
02100   }
02101 }
02102 
02103 void ON_DimStyle::SetToleranceUpperValue( double upper_value)
02104 {
02105   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceUpperValue() != upper_value );
02106   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02107   if(pDE)
02108   {
02109     pDE->SetToleranceUpperValue( upper_value);
02110   }
02111 }
02112 
02113 void ON_DimStyle::SetToleranceLowerValue( double lower_value)
02114 {
02115   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceLowerValue() != lower_value );
02116   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02117   if(pDE)
02118   {
02119     pDE->SetToleranceLowerValue( lower_value);
02120   }
02121 }
02122 
02123 void ON_DimStyle::SetToleranceHeightScale( double scale)
02124 {
02125   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceHeightScale() != scale );
02126   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02127   if(pDE)
02128   {
02129     pDE->SetToleranceHeightScale( scale);
02130   }
02131 }
02132 
02133 void ON_DimStyle::SetBaselineSpacing( double spacing)
02134 {
02135   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultBaselineSpacing() != spacing );
02136   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02137   if(pDE)
02138   {
02139     pDE->SetBaselineSpacing( spacing);
02140   }
02141 }
02142 
02143 bool ON_DimStyle::DrawTextMask() const
02144 {
02145   // 2 November 2011 Dale Lear 
02146   //   Do not create user data if it does not already exist.
02147   const ON_DimStyleExtra* pDE = DimStyleExtension();
02148   if(pDE)
02149     return pDE->DrawTextMask();
02150   else
02151     return ON_DimStyle::DefaultDrawTextMask();
02152 }
02153 
02154 void ON_DimStyle::SetDrawTextMask(bool bDraw)
02155 {
02156   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultDrawTextMask() != (bDraw?true:false) );
02157   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02158   if(pDE)
02159     pDE->SetDrawTextMask(bDraw);
02160 }
02161 
02162 int ON_DimStyle::MaskColorSource() const
02163 {
02164   // 2 November 2011 Dale Lear 
02165   //   Do not create user data if it does not already exist.
02166   const ON_DimStyleExtra* pDE = DimStyleExtension();
02167   if(pDE)
02168     return pDE->MaskColorSource();
02169   else
02170     return ON_DimStyle::DefaultMaskColorSource();
02171 }
02172 
02173 void ON_DimStyle::SetMaskColorSource(int source)
02174 {
02175   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultMaskColorSource() != source );
02176   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02177   if(pDE)
02178     pDE->SetMaskColorSource(source);
02179 }
02180 
02181 ON_Color ON_DimStyle::MaskColor() const
02182 {
02183   // 2 November 2011 Dale Lear 
02184   //   Do not create user data if it does not already exist.
02185   const ON_DimStyleExtra* pDE = DimStyleExtension();
02186   if(pDE)
02187     return pDE->MaskColor();
02188   else
02189     return ON_DimStyle::DefaultMaskColor();
02190 }
02191 
02192 void ON_DimStyle::SetMaskColor(ON_Color color)
02193 {
02194   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultMaskColor() != color );
02195   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02196   if(pDE)
02197     pDE->SetMaskColor(color);
02198 }
02199 
02200 double ON_DimStyle::MaskOffsetFactor() const
02201 {
02202   if(m_textheight != 0.0)
02203     return 0.5 * m_textgap / m_textheight;
02204   else
02205     return 0.0;
02206 }
02207 
02208 void ON_DimStyle::SetDimScale(double scale)
02209 {
02210   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultDimScale() != scale );
02211   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02212   if(pDE)
02213     pDE->SetDimScale(scale);
02214 }
02215 
02216 double ON_DimStyle::DimScale() const
02217 {
02218   // 2 November 2011 Dale Lear 
02219   //   Do not create user data if it does not already exist.
02220   const ON_DimStyleExtra* pDE = DimStyleExtension();
02221   if(pDE) // && pDE->DimScaleSource() == 1)
02222       return pDE->DimScale();
02223   else
02224     return ON_DimStyle::DefaultDimScale();
02225 }
02226 
02227 void ON_DimStyle::SetDimScaleSource(int source)
02228 {
02229   bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultDimScaleSource() != source );
02230   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02231   if(pDE)
02232     pDE->SetDimScaleSource(source);
02233 }
02234 
02235 int ON_DimStyle::DimScaleSource() const
02236 {
02237   // 2 November 2011 Dale Lear 
02238   //   Do not create user data if it does not already exist.
02239   const ON_DimStyleExtra* pDE = DimStyleExtension();
02240   if(pDE)
02241     return pDE->DimScaleSource();
02242   else
02243     return ON_DimStyle::DefaultDimScaleSource();
02244 }
02245 
02246 void ON_DimStyle::SetSourceDimstyle(ON_UUID source_uuid)
02247 {
02248   bool bCreateIfDoesNotExist = ( !(ON_nil_uuid == source_uuid) );
02249   ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
02250   if(pDE)
02251     pDE->SetSourceDimstyle(source_uuid);
02252 }
02253 
02254 ON_UUID ON_DimStyle::SourceDimstyle() const
02255 {
02256   // 2 November 2011 Dale Lear 
02257   //   Do not create user data if it does not already exist.
02258   const ON_DimStyleExtra* pDE = DimStyleExtension();
02259   if(pDE)
02260     return pDE->SourceDimstyle();
02261   else
02262     return ON_nil_uuid;
02263 }
02264 
02265 
02266 
02267 
02268 // This function is temporary and will be removed next time the SDK can be modified.
02269 class ON_DimStyleExtra* ON_DimStyle::DimStyleExtension()
02270 {
02271   // This function gets an extensions class if one exists.
02272   // It must not create an extensions class if one does not exist.
02273   ON_DimStyleExtra* pExtra = ON_DimStyleExtra::Cast( GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
02274   return pExtra;
02275 }
02276 
02277 const class ON_DimStyleExtra* ON_DimStyle::DimStyleExtension() const
02278 {
02279   // This function gets an extensions class if one exists.
02280   // It must not create an extensions class if one does not exist.
02281   ON_DimStyleExtra* pExtra = ON_DimStyleExtra::Cast( GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
02282   return pExtra;
02283 }
02284 
02285 // returns true if they are the same
02286 bool ON_DimStyle::CompareFields(const ON_DimStyle& other) const
02287 {
02288   if((m_extextension               != other.m_extextension) ||
02289      (m_extoffset                  != other.m_extoffset) ||
02290      (m_arrowsize                  != other.m_arrowsize) ||
02291      (m_centermark                 != other.m_centermark) ||
02292      (m_textgap                    != other.m_textgap) ||
02293      (m_textheight                 != other.m_textheight) ||
02294      (m_textalign                  != other.m_textalign) ||
02295      (m_arrowtype                  != other.m_arrowtype) ||
02296      (m_angularunits               != other.m_angularunits) ||
02297      (m_lengthformat               != other.m_lengthformat) ||
02298      (m_angleformat                != other.m_angleformat) ||
02299      (m_angleresolution            != other.m_angleresolution) ||
02300      (m_lengthresolution           != other.m_lengthresolution) ||
02301      (m_fontindex                  != other.m_fontindex) ||
02302      (m_lengthfactor               != other.m_lengthfactor) ||
02303      (m_bAlternate                 != other.m_bAlternate) ||
02304      (m_alternate_lengthfactor     != other.m_alternate_lengthfactor) ||
02305      (m_alternate_lengthformat     != other.m_alternate_lengthformat) ||
02306      (m_alternate_lengthresolution != other.m_alternate_lengthresolution) ||
02307      (m_alternate_angleformat      != other.m_alternate_angleformat) ||
02308      (m_alternate_angleresolution  != other.m_alternate_angleresolution) ||
02309      (m_prefix                     != other.m_prefix) ||
02310      (m_suffix                     != other.m_suffix) ||
02311      (m_alternate_prefix           != other.m_alternate_prefix) ||
02312      (m_alternate_suffix           != other.m_alternate_suffix) ||
02313      (m_dimextension               != other.m_dimextension) ||
02314      (m_leaderarrowsize            != other.m_leaderarrowsize) ||
02315      (m_leaderarrowtype            != other.m_leaderarrowtype) ||
02316      (m_bSuppressExtension1        != other.m_bSuppressExtension1) ||
02317      (m_bSuppressExtension2        != other.m_bSuppressExtension2))
02318     return false;
02319 
02320   // 2 November 2011 Dale Lear:
02321   //   Do not create ON_DimStyleExtra if it does not already exist.
02322   const ON_DimStyleExtra* pDEo = ON_DimStyleExtra::DimStyleExtensionGet(&other);
02323   const ON_DimStyleExtra* pDE  = ON_DimStyleExtra::DimStyleExtensionGet(this);
02324 
02325   if ( 0 != pDEo && 0 != pDE && !pDE->CompareFields(pDEo) )
02326     return false;
02327 
02328   // 2 November 2011 Dale Lear:
02329   //   I added ON_DimStyleExtra::IsDefault() and used it here
02330   //   so the plethora of ON_DimStyleExtra user data
02331   //   that is is all files made before this date and which contains
02332   //   all default settings is correctly handled.  (For the past year,
02333   //   every single dimstyle has had ON_DimStyleExtra added to it
02334   //   that starts out containing default settings.
02335   if ( 0 == pDEo && 0 != pDE && !pDE->IsDefault() )
02336     return false;
02337 
02338   if ( 0 == pDE && 0 != pDEo && !pDEo->IsDefault() )
02339     return false;
02340 
02341   return true;
02342 }


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