1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16
17 #include "opennurbs.h"
18
19 /*
20 Changes and additions 5/01/07 LW
21 Adding several fields to ON_Dimstyle
22 Adding the concept of Parent and Child dimstyles so that individual dimension objects
23 can have their own copy of a dimension style to override some settings
24
25 Adding several fields to ON_Dimstyle - This is done with ON_DimStyleExtra userdata
26 class for now so the SDK doesn't break completely. When the SDK changes, the data in
27 ON_DimstyleExtra should be moved into ON_Dimstyle.
28
29 Adding the concept of Parent and Child dimstyles to support per object overrides of
30 dimstyle based properties. Individual dimensions will be able to have one or more
31 properties that differ from the dimension style for that dimension, but the rest of
32 their properties will be controlled by the parent dimstyle. In this implementation
33 (Rhino 5), dimstyles will only inherit one level deep.
34
35 The first time an individual dimension has a dimstyle value overridden, a new child
36 dimstyle is made that is a copy of the dimension's dimstyle. If there is already a
37 child dimstyle for that dimension, it is used and no new dimstyle is made.
38 The value being overridden is changed in the child dimstyle and a flag is set that
39 the field is being overridden.
40
41 When a value is changed in a parent dimstyle, it should look through the other
42 dimstyles in the dimstyle table (or your application's equivalent) and change any
43 of its children appropriately. Name and Index fields aren't propogated this way.
44 If the parent's field being changed is not set in the child's m_valid_fields array,
45 the child's copy of that field should be changed to match the parent's new value.
46 Changing values in child dimstyles doesn't change values in their parents.
47
48 When a value that has previously been overridden by an individual dimension
49 is set to ByStyle, the corresponding field flag is unset in the valid field array.
50 If all of the flags in a child dimstyle become unset, the dimension is set to
51 reference the parent dimstyle directly.
52
53 */
54
55
56 // Added for v5 - 5/01/07 LW
57 // Userdata class being used to extend ON_DimStyle so the v4 sdk still works
58 // Presumably, this will be moved into ON_DimStyle when the SDK is changed again
59 // Don't put this extension class in a header file or export it.
60 class ON_DimStyleExtra : public ON_UserData
61 {
62 ON_OBJECT_DECLARE(ON_DimStyleExtra);
63 public:
64 //////// 26 Oct 2010 - Changed to always create ON_DimStyleExtra
65 //////static ON_DimStyleExtra* DimStyleExtension( ON_DimStyle* pDimStyle);
66 //////static const ON_DimStyleExtra* DimStyleExtension( const ON_DimStyle* pDimStyle);
67
68 // 2 November 2011 Dale Lear
69 // Undoing above change. Adding this user data is not necessary
70 // and is causing large memory leaks when it is repeatedly
71 // added to the default dimstyle in the Rhino dimstyle table.
72 static ON_DimStyleExtra* DimStyleExtensionGet( ON_DimStyle* pDimStyle, bool bCreateIfNoneExists );
73
74 // 2 November 2011 Dale Lear
75 // Undoing above change. Adding this user data is not necessary
76 // and is causing large memory leaks when it is repeatedly
77 // added to the default dimstyle in the Rhino dimstyle table.
78 // This const version never creates user data.
79 static const ON_DimStyleExtra* DimStyleExtensionGet( const ON_DimStyle* pDimStyle);
80
81 ON_DimStyleExtra();
82 ~ON_DimStyleExtra();
83
84 void SetDefaults();
85
86 /*
87 Returns:
88 True if this ON_DimStyleExtra has default settings.
89 */
90 bool IsDefault() const;
91
92 // override virtual ON_Object::Dump function
93 void Dump( ON_TextLog& text_log ) const;
94
95 // override virtual ON_Object::SizeOf function
96 unsigned int SizeOf() const;
97
98 // override virtual ON_Object::Write function
99 ON_BOOL32 Write(ON_BinaryArchive& binary_archive) const;
100
101 // override virtual ON_Object::Read function
102 ON_BOOL32 Read(ON_BinaryArchive& binary_archive);
103
104 // override virtual ON_UserData::GetDescription function
105 ON_BOOL32 GetDescription( ON_wString& description );
106
107 // override virtual ON_UserData::Archive function
108 ON_BOOL32 Archive() const;
109
110 void SetFieldOverride( int field_id, bool bOverride);
111 bool IsFieldOverride( int field_id) const;
112
113 // Data access
114 // Scale all of the length values
115 void Scale( double scale);
116
117 // Tolerances
118 // Tolerance style
119 // 0: None
120 // 1: Symmetrical
121 // 2: Deviation
122 // 3: Limits
123 // 4: Basic
124 void SetToleranceStyle( int style);
125 int ToleranceStyle() const;
126
127 void SetToleranceResolution( int resolution);
128 int ToleranceResolution() const;
129
130 void SetToleranceUpperValue( double upper_value);
131 double ToleranceUpperValue() const;
132
133 void SetToleranceLowerValue( double lower_value);
134 double ToleranceLowerValue() const;
135
136 void SetToleranceHeightScale( double scale);
137 double ToleranceHeightScale() const;
138
139 void SetBaselineSpacing( double);
140 double BaselineSpacing() const;
141
142 // Determines whether or not to draw a Text Mask
143 bool DrawTextMask() const;
144 void SetDrawTextMask(bool bDraw);
145
146 // Determines where to get the color to draw a Text Mask
147 // 0: Use background color of the viewport. Initially, gradient backgrounds will not be supported
148 // 1: Use the ON_Color returned by MaskColor()
149 int MaskColorSource() const;
150 void SetMaskColorSource(int source);
151
152 ON_Color MaskColor() const; // Only works right if MaskColorSource returns 1.
153 // Does not return viewport background color
154 void SetMaskColor(ON_Color color);
155
156 void SetDimScale(double scale);
157 double DimScale() const;
158 void SetDimScaleSource(int source);
159 int DimScaleSource() const;
160
161 void SetSourceDimstyle(ON_UUID source_uuid);
162 ON_UUID SourceDimstyle() const;
163
164 bool CompareFields(const ON_DimStyleExtra* pOther) const;
165
166 // Data storage
167
168 ON_UUID m_parent_dimstyle; // ON_nil_uuid if there is no parent dimstyle
169 ON_SimpleArray<bool> m_valid_fields;
170 enum { eFieldCount = 66 };
171
172 int m_tolerance_style;
173 int m_tolerance_resolution;
174 double m_tolerance_upper_value; // or both upper and lower in symmetrical style
175 double m_tolerance_lower_value;
176 double m_tolerance_height_scale; // relative to the main dimension text
177
178 double m_baseline_spacing;
179
180 // Text mask - added Dec 12 2009
181 bool m_bDrawMask;
182 int m_mask_color_source;
183 ON_Color m_mask_color;
184
185 // Per dimstyle DimScale added Dec 16, 2009
186 double m_dimscale;
187 int m_dimscale_source;
188
189 // 19 Oct 2010 - Added uuid of source dimstyle to restore defaults
190 ON_UUID m_source_dimstyle;
191 };
192
193
194
195
196
197 // Added for v5 - 5/01/07 LW
198 ON_OBJECT_IMPLEMENT(ON_DimStyleExtra,ON_UserData,"513FDE53-7284-4065-8601-06CEA8B28D6F");
199
200 ////// 26 Oct 2010 - Lowell - Changed to always create ON_DimStyleExtra if there's not one
201 ////ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtension( ON_DimStyle* pDimStyle)
202 ////{
203 //// ON_DimStyleExtra* pExtra = 0;
204 //// if( pDimStyle)
205 //// {
206 //// pExtra = ON_DimStyleExtra::Cast( pDimStyle->GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
207 //// if( pExtra == 0)
208 //// {
209 //// pExtra = new ON_DimStyleExtra;
210 //// if( pExtra)
211 //// {
212 //// if( !pDimStyle->AttachUserData( pExtra))
213 //// {
214 //// delete pExtra;
215 //// pExtra = 0;
216 //// }
217 //// }
218 //// }
219 //// }
220 //// return pExtra;
221 ////}
222
223 // 26 Oct 2010 - Lowell - Changed to always create ON_DimStyleExtra if there's not one
DimStyleExtensionGet(ON_DimStyle * pDimStyle,bool bCreateIfNoneExists)224 ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtensionGet( ON_DimStyle* pDimStyle, bool bCreateIfNoneExists )
225 {
226 ON_DimStyleExtra* pExtra = 0;
227 if( pDimStyle)
228 {
229 pExtra = ON_DimStyleExtra::Cast( pDimStyle->GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
230 // 2 November 2011 Dale Lear
231 // I added the bCreateIfNoneExists parameter and I'm using
232 // is sparingly. It is critical that we do not add
233 // ON_DimStyleExtra unless it is actually being used
234 // to override a default setting. Otherwise, we
235 // end up leaking vast amounts of memory when
236 // the default dimstyle in the Rhino dimstyle
237 // table is used due to the way annotation
238 // is currently drawn.
239 // If you have questions, please ask Dale Lear for details
240 // but please do not revert to constantly adding user
241 // data to dimstyles.
242 if( pExtra == 0 && bCreateIfNoneExists )
243 {
244 pExtra = new ON_DimStyleExtra;
245 if( pExtra)
246 {
247 if( !pDimStyle->AttachUserData( pExtra))
248 {
249 delete pExtra;
250 pExtra = 0;
251 }
252 }
253 }
254 }
255 return pExtra;
256 }
257
258 const
DimStyleExtensionGet(const ON_DimStyle * pDimStyle)259 ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtensionGet( const ON_DimStyle* pDimStyle)
260 {
261 // Please do not changes the "false" to a "true" in the second argument.
262 return ON_DimStyleExtra::DimStyleExtensionGet( (ON_DimStyle*)pDimStyle, false );
263 }
264
ON_DimStyleExtra()265 ON_DimStyleExtra::ON_DimStyleExtra()
266 {
267 m_userdata_uuid = ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid();
268 m_application_uuid = ON_opennurbs5_id; // opennurbs.dll reads/writes this userdata
269 // The id must be the version 5 id because
270 // V6 SaveAs V5 needs to work, but SaveAs
271 // V4 should not write this userdata.
272 m_userdata_copycount = 1;
273 m_valid_fields.Reserve( ON_DimStyleExtra::eFieldCount);
274 m_valid_fields.SetCount( ON_DimStyleExtra::eFieldCount);
275 m_parent_dimstyle = ON_nil_uuid;
276 m_source_dimstyle = ON_nil_uuid;
277 SetDefaults();
278 }
279
~ON_DimStyleExtra()280 ON_DimStyleExtra::~ON_DimStyleExtra()
281 {
282 }
283
SetDefaults()284 void ON_DimStyleExtra::SetDefaults()
285 {
286 m_tolerance_style = ON_DimStyle::DefaultToleranceStyle();
287 m_tolerance_resolution = ON_DimStyle::DefaultToleranceResolution();
288 m_tolerance_upper_value = ON_DimStyle::DefaultToleranceUpperValue();
289 m_tolerance_lower_value = ON_DimStyle::DefaultToleranceLowerValue();
290 m_tolerance_height_scale = ON_DimStyle::DefaultToleranceHeightScale();
291 m_baseline_spacing = ON_DimStyle::DefaultBaselineSpacing();
292 m_bDrawMask = ON_DimStyle::DefaultDrawTextMask(); // false;
293 m_mask_color_source = ON_DimStyle::DefaultMaskColorSource(); // 0;
294 m_mask_color = ON_DimStyle::DefaultMaskColor(); // .SetRGB(255,255,255);
295 m_dimscale = ON_DimStyle::DefaultDimScale(); // 1.0;
296 m_dimscale_source = ON_DimStyle::DefaultDimScaleSource(); // 0;
297
298 for( int i = 0; i < m_valid_fields.Count(); i++)
299 m_valid_fields[i] = false;
300 }
301
IsDefault() const302 bool ON_DimStyleExtra::IsDefault() const
303 {
304 if ( m_tolerance_style != ON_DimStyle::DefaultToleranceStyle() ) return false;
305 if ( m_tolerance_resolution != ON_DimStyle::DefaultToleranceResolution() ) return false;
306 if ( m_tolerance_upper_value != ON_DimStyle::DefaultToleranceUpperValue() ) return false;
307 if ( m_tolerance_lower_value != ON_DimStyle::DefaultToleranceLowerValue() ) return false;
308 if ( m_tolerance_height_scale != ON_DimStyle::DefaultToleranceHeightScale() ) return false;
309 if ( m_baseline_spacing != ON_DimStyle::DefaultBaselineSpacing() ) return false;
310 if ( m_bDrawMask != ON_DimStyle::DefaultDrawTextMask() ) return false;
311 if ( m_mask_color_source != ON_DimStyle::DefaultMaskColorSource() ) return false;
312 if ( m_mask_color != ON_DimStyle::DefaultMaskColor() ) return false;
313 if ( m_dimscale != ON_DimStyle::DefaultDimScale() ) return false;
314 if ( m_dimscale_source != ON_DimStyle::DefaultDimScaleSource() ) return false;
315
316 // The m_valid_fields[] settings only matter when
317 // m_parent_dimstyle is not zero.
318 if ( !(m_parent_dimstyle == ON_nil_uuid) )
319 {
320 for( int i = 0; i < m_valid_fields.Count() && i < ON_DimStyleExtra::eFieldCount; i++)
321 {
322 if ( !m_valid_fields[i] )
323 return false;
324 }
325 }
326
327 return true;
328 }
329
Dump(ON_TextLog & text_log) const330 void ON_DimStyleExtra::Dump( ON_TextLog& text_log ) const
331 {
332 // do nothing
333 }
334
SizeOf() const335 unsigned int ON_DimStyleExtra::SizeOf() const
336 {
337 unsigned int sz = ON_UserData::SizeOf();
338 sz += sizeof(*this) - sizeof(ON_UserData);
339 return sz;
340 }
341
Write(ON_BinaryArchive & archive) const342 ON_BOOL32 ON_DimStyleExtra::Write(ON_BinaryArchive& archive) const
343 {
344 // bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0); Changed to 1,1 for mask settings 12/12/09
345 // bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1); Changed to 1,2 for dimscale 12/17/09
346 // bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,2); Changed to 1,3 for source_dimstyle 10/19/10
347 bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,3);
348
349 if(rc) rc = archive.WriteUuid( m_parent_dimstyle);
350 if(rc) rc = archive.WriteArray( m_valid_fields);
351
352 if(rc) rc = archive.WriteInt(m_tolerance_style);
353 if(rc) rc = archive.WriteInt(m_tolerance_resolution);
354
355 if(rc) rc = archive.WriteDouble(m_tolerance_upper_value);
356 if(rc) rc = archive.WriteDouble(m_tolerance_lower_value);
357 if(rc) rc = archive.WriteDouble(m_tolerance_height_scale);
358
359 // March 22, 2010 - Global DimStyle was obsoleted and moved into DimStyles
360 // So now for writing older version files, its multiplied into all distance values
361 if(archive.Archive3dmVersion() < 5)
362 {
363 if(rc) rc = archive.WriteDouble(m_baseline_spacing * m_dimscale);
364 }
365 else
366 {
367 if(rc) rc = archive.WriteDouble(m_baseline_spacing);
368 }
369
370 if(rc) rc = archive.WriteBool(m_bDrawMask);
371 if(rc) rc = archive.WriteInt(m_mask_color_source);
372 if(rc) rc = archive.WriteColor(m_mask_color);
373
374 if(archive.Archive3dmVersion() < 5)
375 {
376 if(rc) rc = archive.WriteDouble(1.0);
377 }
378 else
379 {
380 if(rc) rc = archive.WriteDouble(m_dimscale);
381 }
382 if(rc) rc = archive.WriteInt(m_dimscale_source); // Obsolete field
383
384 if(rc) rc = archive.WriteUuid(m_source_dimstyle); // Added 19 Oct 2010
385
386 if(!archive.EndWrite3dmChunk())
387 rc = false;
388
389 return rc;
390 }
391
Read(ON_BinaryArchive & archive)392 ON_BOOL32 ON_DimStyleExtra::Read(ON_BinaryArchive& archive)
393 {
394 // Changed to 1,0 for mask settings 12/12/09
395 int major_version = 0;
396 int minor_version = 0;
397 bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
398 if(major_version != 1)
399 rc = false;
400
401 if(rc) rc = archive.ReadUuid(m_parent_dimstyle);
402 if(rc) rc = archive.ReadArray(m_valid_fields);
403
404 if(rc) rc = archive.ReadInt(&m_tolerance_style);
405 if(rc) rc = archive.ReadInt(&m_tolerance_resolution);
406
407 if(rc) rc = archive.ReadDouble(&m_tolerance_upper_value);
408 if(rc) rc = archive.ReadDouble(&m_tolerance_lower_value);
409 if(rc) rc = archive.ReadDouble(&m_tolerance_height_scale);
410
411 if(rc) rc = archive.ReadDouble(&m_baseline_spacing);
412
413 if(minor_version >= 1)
414 {
415 if(rc) rc = archive.ReadBool(&m_bDrawMask);
416 if(rc) rc = archive.ReadInt(&m_mask_color_source);
417 if(rc) rc = archive.ReadColor(m_mask_color);
418 }
419
420 if(minor_version >= 2)
421 {
422 if(rc) rc = archive.ReadDouble(&m_dimscale);
423 if(rc) rc = archive.ReadInt(&m_dimscale_source);
424 }
425
426 if(minor_version >= 3)
427 {
428 if(rc) rc = archive.ReadUuid(m_source_dimstyle);
429 }
430
431 if ( !archive.EndRead3dmChunk() )
432 rc = false;
433
434 return rc;
435 }
436
GetDescription(ON_wString & description)437 ON_BOOL32 ON_DimStyleExtra::GetDescription( ON_wString& description)
438 {
439 description.Format( "Userdata extension of ON_DimStyle");
440 return true;
441 }
442
Archive() const443 ON_BOOL32 ON_DimStyleExtra::Archive() const
444 {
445 // true to write to file
446 return true;
447 }
448
Scale(double scale)449 void ON_DimStyleExtra::Scale( double scale)
450 {
451 if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON)
452 m_baseline_spacing *= scale;
453 }
454
455 // Tolerance style
SetToleranceStyle(int style)456 void ON_DimStyleExtra::SetToleranceStyle( int style)
457 {
458 if( style >= 0 && style <= 4)
459 m_tolerance_style = style;
460 }
461
ToleranceStyle() const462 int ON_DimStyleExtra::ToleranceStyle() const
463 {
464 return m_tolerance_style;
465 }
466
SetToleranceResolution(int resolution)467 void ON_DimStyleExtra::SetToleranceResolution( int resolution)
468 {
469 if( resolution >= 0 && resolution < 16)
470 m_tolerance_resolution = resolution;
471 }
472
ToleranceResolution() const473 int ON_DimStyleExtra::ToleranceResolution() const
474 {
475 return m_tolerance_resolution;
476 }
477
SetToleranceUpperValue(double upper_value)478 void ON_DimStyleExtra::SetToleranceUpperValue( double upper_value)
479 {
480 if( ON_IsValid(upper_value))
481 m_tolerance_upper_value = upper_value;
482 }
483
ToleranceUpperValue() const484 double ON_DimStyleExtra::ToleranceUpperValue() const
485 {
486 return m_tolerance_upper_value;
487 }
488
SetToleranceLowerValue(double lower_value)489 void ON_DimStyleExtra::SetToleranceLowerValue( double lower_value)
490 {
491 if( ON_IsValid(lower_value))
492 m_tolerance_lower_value = lower_value;
493 }
494
ToleranceLowerValue() const495 double ON_DimStyleExtra::ToleranceLowerValue() const
496 {
497 return m_tolerance_lower_value;
498 }
499
SetToleranceHeightScale(double scale)500 void ON_DimStyleExtra::SetToleranceHeightScale( double scale)
501 {
502 if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON)
503 m_tolerance_height_scale = scale;
504 }
505
ToleranceHeightScale() const506 double ON_DimStyleExtra::ToleranceHeightScale() const
507 {
508 return m_tolerance_height_scale;
509 }
510
SetBaselineSpacing(double spacing)511 void ON_DimStyleExtra::SetBaselineSpacing( double spacing)
512 {
513 if( ON_IsValid( spacing) && spacing > ON_SQRT_EPSILON)
514 m_baseline_spacing = spacing;
515 }
516
BaselineSpacing() const517 double ON_DimStyleExtra::BaselineSpacing() const
518 {
519 return m_baseline_spacing;
520 }
521
DrawTextMask() const522 bool ON_DimStyleExtra::DrawTextMask() const
523 {
524 return m_bDrawMask;
525 }
526
SetDrawTextMask(bool bDraw)527 void ON_DimStyleExtra::SetDrawTextMask(bool bDraw)
528 {
529 m_bDrawMask = bDraw ? true : false;
530 }
531
MaskColorSource() const532 int ON_DimStyleExtra::MaskColorSource() const
533 {
534 return m_mask_color_source;
535 }
536
SetMaskColorSource(int source)537 void ON_DimStyleExtra::SetMaskColorSource(int source)
538 {
539 if(source == 1)
540 m_mask_color_source = 1;
541 else
542 m_mask_color_source = 0;
543 }
544
MaskColor() const545 ON_Color ON_DimStyleExtra::MaskColor() const
546 {
547 return m_mask_color;
548 }
549
SetMaskColor(ON_Color color)550 void ON_DimStyleExtra::SetMaskColor(ON_Color color)
551 {
552 m_mask_color = color;
553 }
554
SetDimScale(double scale)555 void ON_DimStyleExtra::SetDimScale(double scale)
556 {
557 m_dimscale = scale;
558 }
559
DimScale() const560 double ON_DimStyleExtra::DimScale() const
561 {
562 return m_dimscale;
563 }
564
SetDimScaleSource(int source)565 void ON_DimStyleExtra::SetDimScaleSource(int source)
566 {
567 m_dimscale_source = source;
568 }
569
DimScaleSource() const570 int ON_DimStyleExtra::DimScaleSource() const
571 {
572 return m_dimscale_source;
573 }
574
SetSourceDimstyle(ON_UUID source_uuid)575 void ON_DimStyleExtra::SetSourceDimstyle(ON_UUID source_uuid)
576 {
577 m_source_dimstyle = source_uuid;
578 }
579
SourceDimstyle() const580 ON_UUID ON_DimStyleExtra::SourceDimstyle() const
581 {
582 return m_source_dimstyle;
583 }
584
585 // returns true if they are the same
CompareFields(const ON_DimStyleExtra * pOther) const586 bool ON_DimStyleExtra::CompareFields(const ON_DimStyleExtra* pOther) const
587 {
588 if(pOther == 0)
589 return false;
590
591 if((m_parent_dimstyle != pOther->m_parent_dimstyle) ||
592 (m_tolerance_style != pOther->m_tolerance_style) ||
593 (m_tolerance_resolution != pOther->m_tolerance_resolution) ||
594 (m_tolerance_upper_value != pOther->m_tolerance_upper_value) ||
595 (m_tolerance_lower_value != pOther->m_tolerance_lower_value) ||
596 (m_tolerance_height_scale != pOther->m_tolerance_height_scale) ||
597 (m_baseline_spacing != pOther->m_baseline_spacing) ||
598 (m_bDrawMask != pOther->m_bDrawMask) ||
599 (m_mask_color_source != pOther->m_mask_color_source) ||
600 (m_mask_color != pOther->m_mask_color) ||
601 (m_dimscale != pOther->m_dimscale) ||
602 (m_dimscale_source != pOther->m_dimscale_source)
603 )
604 return false;
605
606 for(int i = 0; i < m_valid_fields.Count(); i++)
607 {
608 if(m_valid_fields[i] != pOther->m_valid_fields[i])
609 return false;
610 }
611 return true;
612 }
613
614
615 ON_OBJECT_IMPLEMENT( ON_DimStyle, ON_Object, "81BD83D5-7120-41c4-9A57-C449336FF12C" );
616
ON_DimStyle()617 ON_DimStyle::ON_DimStyle()
618 {
619 // 26 Oct 2010
620 // Can't create this here because reading files won't attach what's read from the file if
621 // there's already one there.
622 // ON_DimStyleExtra::DimStyleExtension( this);
623 SetDefaultsNoExtension();
624 }
625
~ON_DimStyle()626 ON_DimStyle::~ON_DimStyle()
627 {
628 }
629
SetDefaults()630 void ON_DimStyle::SetDefaults()
631 {
632 // If there is already a userdata extension, reset it to the defaults,
633 // but don't make one if its not there already
634 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, false );
635 if( pDE)
636 {
637 // 2 November 2011 Dale Lear
638 // The "default" settings are easily handled
639 // by not having the user data present in
640 // the first place. Please discuss changes
641 // with Dale Lear.
642 //
643 delete pDE;
644
645 ////// reset all field override flags
646 ////for( int i = 0; i < pDE->m_valid_fields.Count(); i++)
647 //// pDE->m_valid_fields[i] = false;
648 ////pDE->SetDefaults();
649 }
650 SetDefaultsNoExtension();
651 }
652
653 // Need to be able to set defaults in base without creating extension
654 // because file reading won't attach userdata if there's already one there
SetDefaultsNoExtension()655 void ON_DimStyle::SetDefaultsNoExtension()
656 {
657 m_dimstyle_index = -1;
658 memset(&m_dimstyle_id,0,sizeof(m_dimstyle_id));
659 m_dimstyle_name = L"Default";
660
661 m_extextension = 0.5;
662 m_extoffset = 0.5;
663 m_arrowsize = 1.0;
664 m_centermark = 0.5;
665 m_textgap = 0.25;
666 m_textheight = 1.0;
667 m_textalign = ON::dtAboveLine;
668 m_arrowtype = 0;
669 m_angularunits = 0;
670 m_lengthformat = 0;
671 m_angleformat = 0;
672 m_lengthresolution = 2;
673 m_angleresolution = 2;
674 m_fontindex = -1;
675
676 // Added at 1.3
677 m_lengthfactor = 1.0;
678 m_bAlternate = false;
679 m_alternate_lengthfactor = 25.4;
680 m_alternate_lengthformat = 0;
681 m_alternate_lengthresolution = 2;
682 m_alternate_angleformat = 0;
683 m_alternate_angleresolution = 2;
684
685 m_prefix = L"";
686 m_suffix = L"";
687 m_alternate_prefix = L" [";
688 m_alternate_suffix = L"]";
689 m_valid = 0;
690
691 m_dimextension = 0.0;
692
693 m_leaderarrowsize = 1.0;
694 m_leaderarrowtype = 0;
695 m_bSuppressExtension1 = false;
696 m_bSuppressExtension2 = false;
697 }
698
699
700 // copy from ON_3dmAnnotationSettings and add a couple of fields
operator =(const ON_3dmAnnotationSettings & src)701 ON_DimStyle& ON_DimStyle::operator=( const ON_3dmAnnotationSettings& src)
702 {
703 SetDefaults();
704
705 m_extextension = src.m_dimexe;
706 m_extoffset = src.m_dimexo;
707 m_arrowsize = src.m_arrowlength;
708 m_textalign = src.m_textalign;
709 m_centermark = src.m_centermark;
710 m_textgap = src.m_dimexo / 2.0;
711 m_textheight = src.m_textheight;
712 m_arrowtype = src.m_arrowtype;
713 m_angularunits = src.m_angularunits;
714 m_lengthformat = src.m_lengthformat;
715 m_angleformat = src.m_angleformat;
716 m_lengthresolution = src.m_resolution;
717 m_angleresolution = src.m_resolution;
718
719 return *this;
720 }
721
722 //////////////////////////////////////////////////////////////////////
723 //
724 // ON_Object overrides
725
IsValid(ON_TextLog * text_log) const726 ON_BOOL32 ON_DimStyle::IsValid( ON_TextLog* text_log ) const
727 {
728 return ( m_dimstyle_name.Length() > 0 && m_dimstyle_index >= 0);
729 }
730
Dump(ON_TextLog & dump) const731 void ON_DimStyle::Dump( ON_TextLog& dump ) const
732 {
733 const wchar_t* wsName = m_dimstyle_name;
734 if ( !wsName )
735 wsName = L"";
736 dump.Print("dimstyle index = %d\n",m_dimstyle_index);
737 dump.Print("dimstyle name = \"%ls\"\n",wsName);
738 }
739
Write(ON_BinaryArchive & file) const740 ON_BOOL32 ON_DimStyle::Write(
741 ON_BinaryArchive& file // serialize definition to binary archive
742 ) const
743 {
744 // March 22, 2010 - Global DimStyle was obsoleted and moved into DimStyles
745 // So now for writing older version files, its multiplied into all distance values
746 double ds = 1.0;
747 if(file.Archive3dmVersion() < 5)
748 ds = DimScale();
749
750 // changed to version 1.4 Dec 28, 05
751 // changed to version 1.5 Mar 23, 06
752 ON_BOOL32 rc = file.Write3dmChunkVersion(1,5);
753
754 if (rc) rc = file.WriteInt(m_dimstyle_index);
755 if (rc) rc = file.WriteString(m_dimstyle_name);
756
757 if (rc) rc = file.WriteDouble(m_extextension * ds);
758 if (rc) rc = file.WriteDouble(m_extoffset * ds);
759 if (rc) rc = file.WriteDouble(m_arrowsize * ds);
760 if (rc) rc = file.WriteDouble(m_centermark * ds);
761 if (rc) rc = file.WriteDouble(m_textgap * ds);
762
763 if (rc) rc = file.WriteInt(m_textalign);
764 if (rc) rc = file.WriteInt(m_arrowtype);
765 if (rc) rc = file.WriteInt(m_angularunits);
766 if (rc) rc = file.WriteInt(m_lengthformat);
767 if (rc) rc = file.WriteInt(m_angleformat);
768 if (rc) rc = file.WriteInt(m_lengthresolution);
769 if (rc) rc = file.WriteInt(m_angleresolution);
770 if (rc) rc = file.WriteInt(m_fontindex);
771
772 if (rc) rc = file.WriteDouble(m_textheight * ds);
773
774 // added 1/13/05 ver 1.2
775 if (rc) rc = file.WriteDouble(m_lengthfactor);
776 if (rc) rc = file.WriteString(m_prefix);
777 if (rc) rc = file.WriteString(m_suffix);
778
779 if (rc) rc = file.WriteBool(m_bAlternate);
780 if (rc) rc = file.WriteDouble(m_alternate_lengthfactor);
781 if (rc) rc = file.WriteInt(m_alternate_lengthformat);
782 if (rc) rc = file.WriteInt(m_alternate_lengthresolution);
783 if (rc) rc = file.WriteInt(m_alternate_angleformat);
784 if (rc) rc = file.WriteInt(m_alternate_angleresolution);
785 if (rc) rc = file.WriteString(m_alternate_prefix);
786 if (rc) rc = file.WriteString(m_alternate_suffix);
787 if (rc) rc = file.WriteInt(m_valid);
788
789 // Added 24 October 2005 ver 1.3
790 if (rc) rc = file.WriteUuid(m_dimstyle_id);
791
792 // Added Dec 28, 05 ver 1.4
793 if (rc) rc = file.WriteDouble(m_dimextension * ds);
794
795 // Added Mar 23 06 ver 1.5
796 if (rc) rc = file.WriteDouble(m_leaderarrowsize * ds);
797 if (rc) rc = file.WriteInt(m_leaderarrowtype);
798 if (rc) rc = file.WriteBool(m_bSuppressExtension1);
799 if (rc) rc = file.WriteBool(m_bSuppressExtension2);
800
801 return rc;
802 }
803
Read(ON_BinaryArchive & file)804 ON_BOOL32 ON_DimStyle::Read(
805 ON_BinaryArchive& file // restore definition from binary archive
806 )
807 {
808 SetDefaultsNoExtension();
809
810 int major_version = 0;
811 int minor_version = 0;
812 ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
813
814
815 if ( major_version >= 1 )
816 {
817 if ( rc) rc = file.ReadInt( &m_dimstyle_index);
818 if ( rc) rc = file.ReadString( m_dimstyle_name);
819
820 if ( rc) rc = file.ReadDouble( &m_extextension);
821 if ( rc) rc = file.ReadDouble( &m_extoffset);
822 if ( rc) rc = file.ReadDouble( &m_arrowsize);
823 if ( rc) rc = file.ReadDouble( &m_centermark);
824 if ( rc) rc = file.ReadDouble( &m_textgap);
825
826 if ( rc) rc = file.ReadInt( &m_textalign);
827 if ( rc) rc = file.ReadInt( &m_arrowtype);
828 if ( rc) rc = file.ReadInt( &m_angularunits);
829 if ( rc) rc = file.ReadInt( &m_lengthformat);
830 if ( rc) rc = file.ReadInt( &m_angleformat);
831 if ( rc) rc = file.ReadInt( &m_lengthresolution);
832 if ( rc) rc = file.ReadInt( &m_angleresolution);
833 if ( rc) rc = file.ReadInt( &m_fontindex);
834
835 if( minor_version >= 1)
836 if ( rc) rc = file.ReadDouble( &m_textheight);
837
838 // added 1/13/05
839 if( minor_version >= 2)
840 {
841 if (rc) rc = file.ReadDouble( &m_lengthfactor);
842 if (rc) rc = file.ReadString( m_prefix);
843 if (rc) rc = file.ReadString( m_suffix);
844
845 if (rc) rc = file.ReadBool( &m_bAlternate);
846 if (rc) rc = file.ReadDouble(&m_alternate_lengthfactor);
847 if (rc) rc = file.ReadInt( &m_alternate_lengthformat);
848 if (rc) rc = file.ReadInt( &m_alternate_lengthresolution);
849 if (rc) rc = file.ReadInt( &m_alternate_angleformat);
850 if (rc) rc = file.ReadInt( &m_alternate_angleresolution);
851 if (rc) rc = file.ReadString( m_alternate_prefix);
852 if (rc) rc = file.ReadString( m_alternate_suffix);
853 if (rc) rc = file.ReadInt( &m_valid);
854
855 if ( minor_version >= 3 )
856 {
857 if (rc) rc = file.ReadUuid(m_dimstyle_id);
858 }
859 }
860 // Added Dec 28, 05 ver 1.4
861 if( minor_version >= 4)
862 if( rc) rc = file.ReadDouble( &m_dimextension);
863
864 // Added Mar 23 06 ver 1.5
865 if( minor_version >= 5)
866 {
867 if (rc) rc = file.ReadDouble( &m_leaderarrowsize);
868 if (rc) rc = file.ReadInt( &m_leaderarrowtype);
869 if (rc) rc = file.ReadBool( &m_bSuppressExtension1);
870 if (rc) rc = file.ReadBool( &m_bSuppressExtension2);
871 }
872 }
873 else
874 rc = false;
875
876 return rc;
877 }
878
EmergencyDestroy()879 void ON_DimStyle::EmergencyDestroy()
880 {
881 m_prefix.EmergencyDestroy();
882 m_suffix.EmergencyDestroy();
883 m_alternate_prefix.EmergencyDestroy();
884 m_alternate_suffix.EmergencyDestroy();
885 }
886
887 //////////////////////////////////////////////////////////////////////
888 //
889 // Interface
SetName(const wchar_t * s)890 void ON_DimStyle::SetName( const wchar_t* s )
891 {
892 m_dimstyle_name = s;
893 m_dimstyle_name.TrimLeftAndRight();
894 }
895
SetName(const char * s)896 void ON_DimStyle::SetName( const char* s )
897 {
898 m_dimstyle_name = s;
899 m_dimstyle_name.TrimLeftAndRight();
900 }
901
GetName(ON_wString & s) const902 void ON_DimStyle::GetName( ON_wString& s ) const
903 {
904 s = m_dimstyle_name;
905 }
906
Name() const907 const wchar_t* ON_DimStyle::Name() const
908 {
909 const wchar_t* s = m_dimstyle_name;
910 return s;
911 }
912
SetIndex(int i)913 void ON_DimStyle::SetIndex(int i )
914 {
915 m_dimstyle_index = i;
916 }
917
Index() const918 int ON_DimStyle::Index() const
919 {
920 return m_dimstyle_index;
921 }
922
ExtExtension() const923 double ON_DimStyle::ExtExtension() const
924 {
925 return m_extextension;
926 }
927
SetExtExtension(const double e)928 void ON_DimStyle::SetExtExtension( const double e)
929 {
930 // Allow negative?
931 m_extextension = e;
932 }
933
ExtOffset() const934 double ON_DimStyle::ExtOffset() const
935 {
936 return m_extoffset;
937 }
938
SetExtOffset(const double e)939 void ON_DimStyle::SetExtOffset( const double e)
940 {
941 m_extoffset = e;
942 }
943
ArrowSize() const944 double ON_DimStyle::ArrowSize() const
945 {
946 return m_arrowsize;
947 }
948
SetArrowSize(const double e)949 void ON_DimStyle::SetArrowSize( const double e)
950 {
951 m_arrowsize = e;
952 }
953
LeaderArrowSize() const954 double ON_DimStyle::LeaderArrowSize() const
955 {
956 return m_leaderarrowsize;
957 }
958
SetLeaderArrowSize(const double e)959 void ON_DimStyle::SetLeaderArrowSize( const double e)
960 {
961 m_leaderarrowsize = e;
962 }
963
CenterMark() const964 double ON_DimStyle::CenterMark() const
965 {
966 return m_centermark;
967 }
968
SetCenterMark(const double e)969 void ON_DimStyle::SetCenterMark( const double e)
970 {
971 m_centermark = e;
972 }
973
TextAlignment() const974 int ON_DimStyle::TextAlignment() const
975 {
976 return m_textalign;
977 }
978
SetTextAlignment(ON::eTextDisplayMode a)979 void ON_DimStyle::SetTextAlignment( ON::eTextDisplayMode a)
980 {
981 m_textalign = a;
982 }
983
ArrowType() const984 int ON_DimStyle::ArrowType() const
985 {
986 return m_arrowtype;
987 }
988
SetArrowType(eArrowType a)989 void ON_DimStyle::SetArrowType( eArrowType a)
990 {
991 m_arrowtype = a;
992 }
993
LeaderArrowType() const994 int ON_DimStyle::LeaderArrowType() const
995 {
996 return m_leaderarrowtype;
997 }
998
SetLeaderArrowType(eArrowType a)999 void ON_DimStyle::SetLeaderArrowType( eArrowType a)
1000 {
1001 m_leaderarrowtype = a;
1002 }
1003
AngularUnits() const1004 int ON_DimStyle::AngularUnits() const
1005 {
1006 return m_angularunits;
1007 }
1008
SetAngularUnits(int u)1009 void ON_DimStyle::SetAngularUnits( int u)
1010 {
1011 m_angularunits = u;
1012 }
1013
LengthFormat() const1014 int ON_DimStyle::LengthFormat() const
1015 {
1016 return m_lengthformat;
1017 }
1018
SetLengthFormat(int f)1019 void ON_DimStyle::SetLengthFormat( int f)
1020 {
1021 m_lengthformat = f;
1022 }
1023
AngleFormat() const1024 int ON_DimStyle::AngleFormat() const
1025 {
1026 return m_angleformat;
1027 }
1028
SetAngleFormat(int f)1029 void ON_DimStyle::SetAngleFormat( int f)
1030 {
1031 m_angleformat = f;
1032 }
1033
LengthResolution() const1034 int ON_DimStyle::LengthResolution() const
1035 {
1036 return m_lengthresolution;
1037 }
1038
SetLengthResolution(int r)1039 void ON_DimStyle::SetLengthResolution( int r)
1040 {
1041 if( r >= 0 && r < 16)
1042 {
1043 m_lengthresolution = r;
1044 }
1045 }
1046
AngleResolution() const1047 int ON_DimStyle::AngleResolution() const
1048 {
1049 return m_angleresolution;
1050 }
1051
SetAngleResolution(int r)1052 void ON_DimStyle::SetAngleResolution( int r)
1053 {
1054 if( r >= 0 && r < 16)
1055 {
1056 m_angleresolution = r;
1057 }
1058 }
1059
FontIndex() const1060 int ON_DimStyle::FontIndex() const
1061 {
1062 return m_fontindex;
1063 }
1064
SetFontIndex(int index)1065 void ON_DimStyle::SetFontIndex( int index)
1066 {
1067 m_fontindex = index;
1068 }
1069
TextGap() const1070 double ON_DimStyle::TextGap() const
1071 {
1072 return m_textgap;
1073 }
1074
SetTextGap(double gap)1075 void ON_DimStyle::SetTextGap( double gap)
1076 {
1077 if( gap >= 0.0)
1078 {
1079 m_textgap = gap;
1080 }
1081 }
1082
TextHeight() const1083 double ON_DimStyle::TextHeight() const
1084 {
1085 return m_textheight;
1086 }
1087
SetTextHeight(double height)1088 void ON_DimStyle::SetTextHeight( double height)
1089 {
1090 if( ON_IsValid( height) && height > ON_SQRT_EPSILON)
1091 {
1092 m_textheight = height;
1093 }
1094 }
1095
1096
LengthFactor() const1097 double ON_DimStyle::LengthFactor() const
1098 {
1099 return m_lengthfactor;
1100 }
SetLengthactor(double factor)1101 void ON_DimStyle::SetLengthactor( double factor)
1102 {
1103 SetLengthFactor( factor);
1104 }
SetLengthFactor(double factor)1105 void ON_DimStyle::SetLengthFactor( double factor)
1106 {
1107 m_lengthfactor = factor;
1108 //ValidateField( fn_lengthfactor);
1109 m_valid |= ( 1 << fn_lengthfactor);
1110 }
1111
Alternate() const1112 bool ON_DimStyle::Alternate() const
1113 {
1114 return m_bAlternate;
1115 }
SetAlternate(bool bAlternate)1116 void ON_DimStyle::SetAlternate( bool bAlternate)
1117 {
1118 m_bAlternate = bAlternate;
1119 }
1120
AlternateLengthFactor() const1121 double ON_DimStyle::AlternateLengthFactor() const
1122 {
1123 return m_alternate_lengthfactor;
1124 }
SetAlternateLengthactor(double factor)1125 void ON_DimStyle::SetAlternateLengthactor( double factor)
1126 {
1127 SetAlternateLengthFactor( factor);
1128 }
SetAlternateLengthFactor(double factor)1129 void ON_DimStyle::SetAlternateLengthFactor( double factor)
1130 {
1131 m_alternate_lengthfactor = factor;
1132 //ValidateField( fn_alternate_lengthfactor);
1133 m_valid |= ( 1 << fn_alternate_lengthfactor);
1134 }
1135
AlternateLengthFormat() const1136 int ON_DimStyle::AlternateLengthFormat() const
1137 {
1138 return m_alternate_lengthformat;
1139 }
SetAlternateLengthFormat(int format)1140 void ON_DimStyle::SetAlternateLengthFormat( int format)
1141 {
1142 m_alternate_lengthformat = format;
1143 }
1144
AlternateLengthResolution() const1145 int ON_DimStyle::AlternateLengthResolution() const
1146 {
1147 return m_alternate_lengthresolution;
1148 }
SetAlternateLengthResolution(int resolution)1149 void ON_DimStyle::SetAlternateLengthResolution( int resolution)
1150 {
1151 m_alternate_lengthresolution = resolution;
1152 }
1153
AlternateAngleFormat() const1154 int ON_DimStyle::AlternateAngleFormat() const
1155 {
1156 return m_alternate_angleformat;
1157 }
SetAlternateAngleFormat(int format)1158 void ON_DimStyle::SetAlternateAngleFormat( int format)
1159 {
1160 m_alternate_angleformat = format;
1161 }
1162
AlternateAngleResolution() const1163 int ON_DimStyle::AlternateAngleResolution() const
1164 {
1165 return m_alternate_angleresolution;
1166 }
SetAlternateAngleResolution(int resolution)1167 void ON_DimStyle::SetAlternateAngleResolution( int resolution)
1168 {
1169 m_alternate_angleresolution = resolution;
1170 }
1171
GetPrefix(ON_wString & prefix) const1172 void ON_DimStyle::GetPrefix( ON_wString& prefix) const
1173 {
1174 prefix = m_prefix;
1175 }
Prefix() const1176 const wchar_t* ON_DimStyle::Prefix() const
1177 {
1178 return m_prefix;
1179 }
SetPrefix(wchar_t * prefix)1180 void ON_DimStyle::SetPrefix( wchar_t* prefix)
1181 {
1182 m_prefix = prefix;
1183 }
SetPrefix(const wchar_t * prefix)1184 void ON_DimStyle::SetPrefix( const wchar_t* prefix)
1185 {
1186 m_prefix = prefix;
1187 }
1188
GetSuffix(ON_wString & suffix) const1189 void ON_DimStyle::GetSuffix( ON_wString& suffix) const
1190 {
1191 suffix = m_suffix;
1192 }
Suffix() const1193 const wchar_t* ON_DimStyle::Suffix() const
1194 {
1195 return m_suffix;
1196 }
SetSuffix(wchar_t * suffix)1197 void ON_DimStyle::SetSuffix( wchar_t* suffix)
1198 {
1199 m_suffix = suffix;
1200 }
SetSuffix(const wchar_t * suffix)1201 void ON_DimStyle::SetSuffix( const wchar_t* suffix)
1202 {
1203 m_suffix = suffix;
1204 }
1205
GetAlternatePrefix(ON_wString & prefix) const1206 void ON_DimStyle::GetAlternatePrefix( ON_wString& prefix) const
1207 {
1208 prefix = m_alternate_prefix;
1209 }
AlternatePrefix() const1210 const wchar_t* ON_DimStyle::AlternatePrefix() const
1211 {
1212 return m_alternate_prefix;
1213 }
SetAlternatePrefix(wchar_t * prefix)1214 void ON_DimStyle::SetAlternatePrefix( wchar_t* prefix)
1215 {
1216 m_alternate_prefix = prefix;
1217 }
SetAlternatePrefix(const wchar_t * prefix)1218 void ON_DimStyle::SetAlternatePrefix( const wchar_t* prefix)
1219 {
1220 m_alternate_prefix = prefix;
1221 }
1222
GetAlternateSuffix(ON_wString & suffix) const1223 void ON_DimStyle::GetAlternateSuffix( ON_wString& suffix) const
1224 {
1225 suffix = m_alternate_suffix;
1226 }
AlternateSuffix() const1227 const wchar_t* ON_DimStyle::AlternateSuffix() const
1228 {
1229 return m_alternate_suffix;
1230 }
SetAlternateSuffix(wchar_t * suffix)1231 void ON_DimStyle::SetAlternateSuffix( wchar_t* suffix)
1232 {
1233 m_alternate_suffix = suffix;
1234 }
SetAlternateSuffix(const wchar_t * suffix)1235 void ON_DimStyle::SetAlternateSuffix( const wchar_t* suffix)
1236 {
1237 m_alternate_suffix = suffix;
1238 }
1239
SuppressExtension1() const1240 bool ON_DimStyle::SuppressExtension1() const
1241 {
1242 return m_bSuppressExtension1;
1243 }
SetSuppressExtension1(bool suppress)1244 void ON_DimStyle::SetSuppressExtension1( bool suppress)
1245 {
1246 m_bSuppressExtension1 = suppress;
1247 }
SuppressExtension2() const1248 bool ON_DimStyle::SuppressExtension2() const
1249 {
1250 return m_bSuppressExtension2;
1251 }
SetSuppressExtension2(bool suppress)1252 void ON_DimStyle::SetSuppressExtension2( bool suppress)
1253 {
1254 m_bSuppressExtension2 = suppress;
1255 }
1256
1257 // This function deprecated 5/01/07 LW
Composite(const ON_DimStyle & OverRide)1258 void ON_DimStyle::Composite( const ON_DimStyle& OverRide)
1259 {
1260 /*
1261 InvalidateAllFields();
1262
1263 if( OverRide.IsFieldValid( fn_name)) { ValidateField( fn_name); m_dimstyle_name = OverRide.m_dimstyle_name; }
1264 if( OverRide.IsFieldValid( fn_index)) { ValidateField( fn_index); m_dimstyle_index = OverRide.m_dimstyle_index; }
1265 if( OverRide.IsFieldValid( fn_extextension)) { ValidateField( fn_extextension); m_extextension = OverRide.m_extextension; }
1266 if( OverRide.IsFieldValid( fn_extoffset)) { ValidateField( fn_extoffset); m_extoffset = OverRide.m_extoffset; }
1267 if( OverRide.IsFieldValid( fn_arrowsize)) { ValidateField( fn_arrowsize); m_arrowsize = OverRide.m_arrowsize; }
1268 if( OverRide.IsFieldValid( fn_leaderarrowsize)) { ValidateField( fn_leaderarrowsize); m_leaderarrowsize = OverRide.m_leaderarrowsize; }
1269 if( OverRide.IsFieldValid( fn_centermark)) { ValidateField( fn_centermark); m_centermark = OverRide.m_centermark; }
1270 if( OverRide.IsFieldValid( fn_textgap)) { ValidateField( fn_textgap); m_textgap = OverRide.m_textgap; }
1271 if( OverRide.IsFieldValid( fn_textheight)) { ValidateField( fn_textheight); m_textheight = OverRide.m_textheight; }
1272 if( OverRide.IsFieldValid( fn_textalign)) { ValidateField( fn_textalign); m_textalign = OverRide.m_textalign; }
1273 if( OverRide.IsFieldValid( fn_arrowtype)) { ValidateField( fn_arrowtype); m_arrowtype = OverRide.m_arrowtype; }
1274 if( OverRide.IsFieldValid( fn_leaderarrowtype)) { ValidateField( fn_leaderarrowtype); m_leaderarrowtype = OverRide.m_leaderarrowtype; }
1275 if( OverRide.IsFieldValid( fn_angularunits)) { ValidateField( fn_angularunits); m_angularunits = OverRide.m_angularunits; }
1276 if( OverRide.IsFieldValid( fn_lengthformat)) { ValidateField( fn_lengthformat); m_lengthformat = OverRide.m_lengthformat; }
1277 if( OverRide.IsFieldValid( fn_angleformat)) { ValidateField( fn_angleformat); m_angleformat = OverRide.m_angleformat; }
1278 if( OverRide.IsFieldValid( fn_angleresolution)) { ValidateField( fn_angleresolution); m_angleresolution = OverRide.m_angleresolution; }
1279 if( OverRide.IsFieldValid( fn_lengthresolution)) { ValidateField( fn_lengthresolution); m_lengthresolution = OverRide.m_lengthresolution; }
1280 if( OverRide.IsFieldValid( fn_fontindex)) { ValidateField( fn_fontindex); m_fontindex = OverRide.m_fontindex; }
1281 if( OverRide.IsFieldValid( fn_lengthfactor)) { ValidateField( fn_lengthfactor); m_lengthfactor = OverRide.m_lengthfactor; }
1282 if( OverRide.IsFieldValid( fn_bAlternate)) { ValidateField( fn_bAlternate); m_bAlternate = OverRide.m_bAlternate; }
1283 if( OverRide.IsFieldValid( fn_alternate_lengthfactor)) { ValidateField( fn_alternate_lengthfactor); m_alternate_lengthfactor = OverRide.m_alternate_lengthfactor; }
1284 if( OverRide.IsFieldValid( fn_alternate_lengthformat)) { ValidateField( fn_alternate_lengthformat); m_alternate_lengthformat = OverRide.m_alternate_lengthformat; }
1285 if( OverRide.IsFieldValid( fn_alternate_lengthresolution)) { ValidateField( fn_alternate_lengthresolution); m_alternate_lengthresolution = OverRide.m_alternate_lengthresolution; }
1286 if( OverRide.IsFieldValid( fn_prefix)) { ValidateField( fn_prefix); m_prefix = OverRide.m_prefix; }
1287 if( OverRide.IsFieldValid( fn_suffix)) { ValidateField( fn_suffix); m_suffix = OverRide.m_suffix; }
1288 if( OverRide.IsFieldValid( fn_alternate_prefix)) { ValidateField( fn_alternate_prefix); m_alternate_prefix = OverRide.m_alternate_prefix; }
1289 if( OverRide.IsFieldValid( fn_alternate_suffix)) { ValidateField( fn_alternate_suffix); m_alternate_suffix = OverRide.m_alternate_suffix; }
1290 if( OverRide.IsFieldValid( fn_dimextension)) { ValidateField( fn_dimextension); m_dimextension = OverRide.m_dimextension; }
1291 if( OverRide.IsFieldValid( fn_suppressextension1)) { ValidateField( fn_suppressextension1); m_bSuppressExtension1 = OverRide.m_bSuppressExtension1; }
1292 if( OverRide.IsFieldValid( fn_suppressextension2)) { ValidateField( fn_suppressextension2); m_bSuppressExtension2 = OverRide.m_bSuppressExtension2; }
1293 */
1294 }
1295
1296 // This function deprecated 5/01/07 LW
InvalidateField(eField field)1297 void ON_DimStyle::InvalidateField( eField field)
1298 {
1299 m_valid &= ~( 1 << field);
1300 }
1301 // This function deprecated 5/01/07 LW
InvalidateAllFields()1302 void ON_DimStyle::InvalidateAllFields()
1303 {
1304 m_valid = 0;
1305 }
1306 // This function deprecated 5/01/07 LW
ValidateField(eField field)1307 void ON_DimStyle::ValidateField( eField field)
1308 {
1309 m_valid |= ( 1 << field);
1310 }
1311 // This function deprecated 5/01/07 LW
IsFieldValid(eField field) const1312 bool ON_DimStyle::IsFieldValid( eField field) const
1313 {
1314 return ( m_valid & ( 1 << field)) ? true : false;
1315 }
1316
1317
1318 // ver 1.4, Dec 28, 05
DimExtension() const1319 double ON_DimStyle::DimExtension() const
1320 {
1321 return m_dimextension;
1322 }
1323
SetDimExtension(const double e)1324 void ON_DimStyle::SetDimExtension( const double e)
1325 {
1326 // Allow negative?
1327 m_dimextension = e;
1328 }
1329
1330 //--------------------------------------
1331 // ON_DimStyleExtra access functions
1332 // Added for v5 5/01/07 LW
1333
IsFieldOverride(ON_DimStyle::eField field_id) const1334 bool ON_DimStyle::IsFieldOverride( ON_DimStyle::eField field_id) const
1335 {
1336 const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this);
1337 if(pDE)
1338 return pDE->IsFieldOverride( field_id);
1339
1340 return false;
1341 }
1342
SetFieldOverride(ON_DimStyle::eField field_id,bool bOverride)1343 void ON_DimStyle::SetFieldOverride( ON_DimStyle::eField field_id, bool bOverride)
1344 {
1345 // 2 November 2011 Dale Lear
1346 // If bOverride is true, then create the userdata, otherwise get it
1347 // only if it exists.
1348 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bOverride );
1349 if(pDE)
1350 {
1351 pDE->SetFieldOverride( field_id, bOverride);
1352 }
1353 }
1354
HasOverrides() const1355 bool ON_DimStyle::HasOverrides() const
1356 {
1357 const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this );
1358 if(pDE)
1359 {
1360 for( int i = 0; i < pDE->m_valid_fields.Count(); i++)
1361 {
1362 if( pDE->m_valid_fields[i])
1363 return true;
1364 }
1365 }
1366 return false;
1367 }
1368
OverrideFields(const ON_DimStyle & src,const ON_DimStyle & parent)1369 bool ON_DimStyle::OverrideFields( const ON_DimStyle& src, const ON_DimStyle& parent)
1370 {
1371 // 2 November 2011 Dale Lear
1372 // I made lots of changes to this function to make sure "i" was a valid
1373 // array index before it was passed to operator[].
1374 const ON_DimStyleExtra* pDEsrc = ON_DimStyleExtra::DimStyleExtensionGet( &src);
1375
1376 // Please do not change the 2nd parameter from "false" to a "true" in the
1377 // call to DimStyleExtensionGet(). If "this" does not have ON_DimStyleExtra
1378 // user data at this point, it will be created if it is actually needed.
1379 // If you have questions, please ask Dale Lear.
1380 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, false );
1381
1382 const int src_valid_fields_count = pDEsrc ? pDEsrc->m_valid_fields.Count() : 0;
1383 int this_valid_fields_count = pDE ? pDE->m_valid_fields.Count() : 0;
1384
1385 for( int i = 0; i < ON_DimStyleExtra::eFieldCount; i++)
1386 {
1387 bool bValidSrcField = ( 0 != pDEsrc && i < src_valid_fields_count )
1388 ? pDEsrc->m_valid_fields[i]
1389 : false;
1390
1391 if ( bValidSrcField && 0 == pDE )
1392 {
1393 // Actually need to create ON_DimStyleExtra user data on "this".
1394 pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, true );
1395 if ( pDE )
1396 this_valid_fields_count = pDE->m_valid_fields.Count();
1397 }
1398
1399 if ( 0 != pDE && i < this_valid_fields_count )
1400 {
1401 pDE->m_valid_fields[i] = bValidSrcField;
1402 }
1403
1404 const ON_DimStyle* copyfrom = bValidSrcField ? (&src) : (&parent);
1405
1406 switch( i)
1407 {
1408 case fn_extextension:
1409 SetExtExtension( copyfrom->ExtExtension());
1410 break;
1411 case fn_extoffset:
1412 SetExtOffset( copyfrom->ExtOffset());
1413 break;
1414 case fn_arrowsize:
1415 SetArrowSize( copyfrom->ArrowSize());
1416 break;
1417 case fn_centermark:
1418 SetCenterMark( copyfrom->CenterMark());
1419 break;
1420 case fn_textgap:
1421 SetTextGap( copyfrom->TextGap());
1422 break;
1423 case fn_textheight:
1424 SetTextHeight( copyfrom->TextHeight());
1425 break;
1426 case fn_textalign:
1427 SetTextAlignment( (ON::eTextDisplayMode)copyfrom->TextAlignment());
1428 break;
1429 case fn_arrowtype:
1430 SetArrowType( (eArrowType)copyfrom->ArrowType());
1431 break;
1432 case fn_angularunits:
1433 SetAngularUnits( (eArrowType)copyfrom->AngularUnits());
1434 break;
1435 case fn_lengthformat:
1436 SetLengthFormat( copyfrom->LengthFormat());
1437 break;
1438 case fn_angleformat:
1439 SetAngleFormat( copyfrom->AngleFormat());
1440 break;
1441 case fn_angleresolution:
1442 SetAngleResolution( copyfrom->AngleResolution());
1443 break;
1444 case fn_lengthresolution:
1445 SetLengthResolution( copyfrom->LengthResolution());
1446 break;
1447 case fn_fontindex:
1448 SetFontIndex( copyfrom->FontIndex());
1449 break;
1450 case fn_lengthfactor:
1451 SetLengthFactor( copyfrom->LengthFactor());
1452 break;
1453 case fn_bAlternate:
1454 SetAlternate( copyfrom->Alternate());
1455 break;
1456 case fn_alternate_lengthfactor:
1457 SetAlternateLengthFactor( copyfrom->AlternateLengthFactor());
1458 break;
1459 case fn_alternate_lengthformat:
1460 SetAlternateLengthFormat( copyfrom->AlternateLengthFormat());
1461 break;
1462 case fn_alternate_lengthresolution:
1463 SetAlternateLengthResolution( copyfrom->AlternateLengthResolution());
1464 break;
1465 case fn_alternate_angleformat:
1466 SetAlternateLengthResolution( copyfrom->AlternateLengthResolution());
1467 break;
1468 case fn_alternate_angleresolution:
1469 SetAlternateAngleResolution( copyfrom->AlternateAngleResolution());
1470 break;
1471 case fn_prefix:
1472 SetPrefix( copyfrom->Prefix());
1473 break;
1474 case fn_suffix:
1475 SetSuffix( copyfrom->Suffix());
1476 break;
1477 case fn_alternate_prefix:
1478 SetAlternatePrefix( copyfrom->AlternatePrefix());
1479 break;
1480 case fn_alternate_suffix:
1481 SetAlternateSuffix( copyfrom->AlternateSuffix());
1482 break;
1483 case fn_dimextension:
1484 SetDimExtension( copyfrom->DimExtension());
1485 break;
1486 case fn_leaderarrowsize:
1487 SetLeaderArrowSize( copyfrom->LeaderArrowSize());
1488 break;
1489 case fn_leaderarrowtype:
1490 SetLeaderArrowType( (eArrowType)copyfrom->LeaderArrowType());
1491 break;
1492 case fn_suppressextension1:
1493 SetSuppressExtension1( copyfrom->SuppressExtension1());
1494 break;
1495 case fn_suppressextension2:
1496 SetSuppressExtension2( copyfrom->SuppressExtension2());
1497 break;
1498 case fn_tolerance_style:
1499 SetToleranceStyle( copyfrom->ToleranceStyle());
1500 break;
1501 case fn_tolerance_resolution:
1502 SetToleranceResolution( copyfrom->ToleranceResolution());
1503 break;
1504 case fn_tolerance_upper_value:
1505 SetToleranceUpperValue( copyfrom->ToleranceUpperValue());
1506 break;
1507 case fn_tolerance_lower_value:
1508 SetToleranceLowerValue( copyfrom->ToleranceLowerValue());
1509 break;
1510 case fn_tolerance_height_scale:
1511 SetToleranceHeightScale( copyfrom->ToleranceHeightScale());
1512 break;
1513 case fn_baseline_spacing:
1514 SetBaselineSpacing( copyfrom->BaselineSpacing());
1515 break;
1516 case fn_draw_mask:
1517 SetDrawTextMask( copyfrom->DrawTextMask());
1518 break;
1519 case fn_mask_color_source:
1520 SetMaskColorSource( copyfrom->MaskColorSource());
1521 break;
1522 case fn_mask_color:
1523 SetMaskColor( copyfrom->MaskColor());
1524 break;
1525 case fn_dimscale:
1526 SetDimScale( copyfrom->DimScale());
1527 break;
1528 case fn_dimscale_source:
1529 SetDimScaleSource( copyfrom->DimScaleSource());
1530 break;
1531 }
1532 }
1533 return true;
1534 }
1535
InheritFields(const ON_DimStyle & parent)1536 bool ON_DimStyle::InheritFields( const ON_DimStyle& parent)
1537 {
1538 bool rc = false;
1539
1540 // 2 November 2011 Dale Lear
1541 // Please do not create ON_DimStyleExtra user data if
1542 // it does not exist on this.
1543 const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this);
1544 for( int i = 0; i < ON_DimStyleExtra::eFieldCount; i++ )
1545 {
1546 bool bValidField = ( 0 != pDE && i < pDE->m_valid_fields.Count() )
1547 ? pDE->m_valid_fields[i] :
1548 false;
1549
1550 switch( i)
1551 {
1552 case fn_extextension:
1553 if( !bValidField)
1554 {
1555 SetExtExtension( parent.ExtExtension());
1556 rc = true;
1557 }
1558 break;
1559 case fn_extoffset:
1560 if( !bValidField)
1561 {
1562 SetExtOffset( parent.ExtOffset());
1563 rc = true;
1564 }
1565 break;
1566 case fn_arrowsize:
1567 if( !bValidField)
1568 {
1569 SetArrowSize( parent.ArrowSize());
1570 rc = true;
1571 }
1572 break;
1573 case fn_centermark:
1574 if( !bValidField)
1575 {
1576 SetCenterMark( parent.CenterMark());
1577 rc = true;
1578 }
1579 break;
1580 case fn_textgap:
1581 if( !bValidField)
1582 {
1583 SetTextGap( parent.TextGap());
1584 rc = true;
1585 }
1586 break;
1587 case fn_textheight:
1588 if( !bValidField)
1589 {
1590 SetTextHeight( parent.TextHeight());
1591 rc = true;
1592 }
1593 break;
1594 case fn_textalign:
1595 if( !bValidField)
1596 {
1597 SetTextAlignment( (ON::eTextDisplayMode)parent.TextAlignment());
1598 rc = true;
1599 }
1600 break;
1601 case fn_arrowtype:
1602 if( !bValidField)
1603 {
1604 SetArrowType( (eArrowType)parent.ArrowType());
1605 rc = true;
1606 }
1607 break;
1608 case fn_angularunits:
1609 if( !bValidField)
1610 {
1611 SetAngularUnits( (eArrowType)parent.AngularUnits());
1612 rc = true;
1613 }
1614 break;
1615 case fn_lengthformat:
1616 if( !bValidField)
1617 {
1618 SetLengthFormat( parent.LengthFormat());
1619 rc = true;
1620 }
1621 break;
1622 case fn_angleformat:
1623 if( !bValidField)
1624 {
1625 SetAngleFormat( parent.AngleFormat());
1626 rc = true;
1627 }
1628 break;
1629 case fn_angleresolution:
1630 if( !bValidField)
1631 {
1632 SetAngleResolution( parent.AngleResolution());
1633 rc = true;
1634 }
1635 break;
1636 case fn_lengthresolution:
1637 if( !bValidField)
1638 {
1639 SetLengthResolution( parent.LengthResolution());
1640 rc = true;
1641 }
1642 break;
1643 case fn_fontindex:
1644 if( !bValidField)
1645 {
1646 SetFontIndex( parent.FontIndex());
1647 rc = true;
1648 }
1649 break;
1650 case fn_lengthfactor:
1651 if( !bValidField)
1652 {
1653 SetLengthFactor( parent.LengthFactor());
1654 rc = true;
1655 }
1656 break;
1657 case fn_bAlternate:
1658 if( !bValidField)
1659 {
1660 SetAlternate( parent.Alternate());
1661 rc = true;
1662 }
1663 break;
1664 case fn_alternate_lengthfactor:
1665 if( !bValidField)
1666 {
1667 SetAlternateLengthFactor( parent.LengthFactor());
1668 rc = true;
1669 }
1670 break;
1671 case fn_alternate_lengthformat:
1672 if( !bValidField)
1673 {
1674 SetAlternateLengthFormat( parent.AlternateLengthFormat());
1675 rc = true;
1676 }
1677 break;
1678 case fn_alternate_lengthresolution:
1679 if( !bValidField)
1680 {
1681 SetAlternateLengthResolution( parent.AlternateLengthResolution());
1682 rc = true;
1683 }
1684 break;
1685 case fn_alternate_angleformat:
1686 if( !bValidField)
1687 {
1688 SetAlternateLengthResolution( parent.AlternateLengthResolution());
1689 rc = true;
1690 }
1691 break;
1692 case fn_alternate_angleresolution:
1693 if( !bValidField)
1694 {
1695 SetAlternateAngleResolution( parent.AlternateAngleResolution());
1696 rc = true;
1697 }
1698 break;
1699 case fn_prefix:
1700 if( !bValidField)
1701 {
1702 SetPrefix( parent.Prefix());
1703 rc = true;
1704 }
1705 break;
1706 case fn_suffix:
1707 if( !bValidField)
1708 {
1709 SetSuffix( parent.Suffix());
1710 rc = true;
1711 }
1712 break;
1713 case fn_alternate_prefix:
1714 if( !bValidField)
1715 {
1716 SetAlternatePrefix( parent.AlternatePrefix());
1717 rc = true;
1718 }
1719 break;
1720 case fn_alternate_suffix:
1721 if( !bValidField)
1722 {
1723 SetAlternateSuffix( parent.AlternateSuffix());
1724 rc = true;
1725 }
1726 break;
1727 case fn_dimextension:
1728 if( !bValidField)
1729 {
1730 SetDimExtension( parent.DimExtension());
1731 rc = true;
1732 }
1733 break;
1734 case fn_leaderarrowsize:
1735 if( !bValidField)
1736 {
1737 SetLeaderArrowSize( parent.LeaderArrowSize());
1738 rc = true;
1739 }
1740 break;
1741 case fn_leaderarrowtype:
1742 if( !bValidField)
1743 {
1744 SetLeaderArrowType( (eArrowType)parent.LeaderArrowType());
1745 rc = true;
1746 }
1747 break;
1748 case fn_suppressextension1:
1749 if( !bValidField)
1750 {
1751 SetSuppressExtension1( parent.SuppressExtension1());
1752 rc = true;
1753 }
1754 break;
1755 case fn_suppressextension2:
1756 if( !bValidField)
1757 {
1758 SetSuppressExtension2( parent.SuppressExtension2());
1759 rc = true;
1760 }
1761 break;
1762 case fn_tolerance_style:
1763 if( !bValidField)
1764 {
1765 SetToleranceStyle( parent.ToleranceStyle());
1766 rc = true;
1767 }
1768 break;
1769 case fn_tolerance_resolution:
1770 if( !bValidField)
1771 {
1772 SetToleranceResolution( parent.ToleranceResolution());
1773 rc = true;
1774 }
1775 break;
1776 case fn_tolerance_upper_value:
1777 if( !bValidField)
1778 {
1779 SetToleranceUpperValue( parent.ToleranceUpperValue());
1780 rc = true;
1781 }
1782 break;
1783 case fn_tolerance_lower_value:
1784 if( !bValidField)
1785 {
1786 SetToleranceLowerValue( parent.ToleranceLowerValue());
1787 rc = true;
1788 }
1789 break;
1790 case fn_tolerance_height_scale:
1791 if( !bValidField)
1792 {
1793 SetToleranceHeightScale( parent.ToleranceHeightScale());
1794 rc = true;
1795 }
1796 break;
1797 case fn_baseline_spacing:
1798 if( !bValidField)
1799 {
1800 SetBaselineSpacing( parent.BaselineSpacing());
1801 rc = true;
1802 }
1803 break;
1804 case fn_draw_mask:
1805 if( !bValidField)
1806 {
1807 SetDrawTextMask( parent.DrawTextMask());
1808 rc = true;
1809 }
1810 break;
1811 case fn_mask_color_source:
1812 if( !bValidField)
1813 {
1814 SetMaskColorSource( parent.MaskColorSource());
1815 rc = true;
1816 }
1817 break;
1818 case fn_mask_color:
1819 if( !bValidField)
1820 {
1821 SetMaskColor( parent.MaskColor());
1822 rc = true;
1823 }
1824 break;
1825 case fn_dimscale:
1826 if( !bValidField)
1827 {
1828 SetDimScale( parent.DimScale());
1829 rc = true;
1830 }
1831 break;
1832 case fn_dimscale_source:
1833 if( !bValidField)
1834 {
1835 SetDimScaleSource( parent.DimScaleSource());
1836 rc = true;
1837 }
1838 break;
1839 }
1840 }
1841 return rc;
1842 }
1843
1844
IsChildDimstyle() const1845 bool ON_DimStyle::IsChildDimstyle() const
1846 {
1847 const ON_DimStyleExtra* pDE = DimStyleExtension();
1848 if(pDE && pDE->m_parent_dimstyle != ON_nil_uuid)
1849 return true;
1850 else
1851 return false;
1852 }
1853
IsChildOf(ON_UUID & parent_uuid) const1854 bool ON_DimStyle::IsChildOf( ON_UUID& parent_uuid) const
1855 {
1856 // delete this old function when SDK can be broken.
1857 // parameter needed a const
1858 const ON_DimStyleExtra* pDE = DimStyleExtension();
1859 if(pDE && parent_uuid != ON_nil_uuid && pDE->m_parent_dimstyle == parent_uuid)
1860 return true;
1861 else
1862 return false;
1863 }
1864
IsChildOf(const ON_UUID & parent_uuid) const1865 bool ON_DimStyle::IsChildOf( const ON_UUID& parent_uuid) const
1866 {
1867 const ON_DimStyleExtra* pDE = DimStyleExtension();
1868 if(pDE && parent_uuid != ON_nil_uuid && pDE->m_parent_dimstyle == parent_uuid)
1869 return true;
1870 else
1871 return false;
1872 }
1873
SetParent(ON_UUID & parent_uuid)1874 void ON_DimStyle::SetParent( ON_UUID& parent_uuid)
1875 {
1876 // delete this old function when SDK can be broken.
1877 // parameter needed a const
1878 SetParentId(parent_uuid);
1879 }
1880
SetParentId(ON_UUID parent_id)1881 void ON_DimStyle::SetParentId( ON_UUID parent_id )
1882 {
1883 bool bCreateIfNoneExists = !ON_UuidIsNil(parent_id);
1884 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfNoneExists );
1885 if ( pDE )
1886 pDE->m_parent_dimstyle = parent_id;
1887 }
1888
1889
ParentId() const1890 ON_UUID ON_DimStyle::ParentId() const
1891 {
1892 const ON_DimStyleExtra* pDE = DimStyleExtension(); // get existing
1893 return ( 0 != pDE ? pDE->m_parent_dimstyle : ON_nil_uuid );
1894 }
1895
IsFieldOverride(int field_id) const1896 bool ON_DimStyleExtra::IsFieldOverride( int field_id) const
1897 {
1898 if( field_id >= 0 && field_id < m_valid_fields.Count())
1899 return m_valid_fields[field_id];
1900 else
1901 return false;
1902 }
1903
SetFieldOverride(int field_id,bool bOverride)1904 void ON_DimStyleExtra::SetFieldOverride( int field_id, bool bOverride)
1905 {
1906 if( field_id >= 0 && field_id < m_valid_fields.Count())
1907 m_valid_fields[field_id] = bOverride;
1908 }
1909
1910 // Tolerances
1911 // Tolerance style
1912 // 0: None
1913 // 1: Symmetrical
1914 // 2: Deviation
1915 // 3: Limits
1916 // 4: Basic
ToleranceStyle() const1917 int ON_DimStyle::ToleranceStyle() const
1918 {
1919 // 2 November 2011 Dale Lear
1920 // Changed to NOT create ON_DimStyleExtra user data
1921 // if it did not already exist.
1922 const ON_DimStyleExtra* pDE = DimStyleExtension();
1923 if(pDE)
1924 return pDE->ToleranceStyle();
1925 else
1926 return ON_DimStyle::DefaultToleranceStyle();
1927 }
1928
ToleranceResolution() const1929 int ON_DimStyle::ToleranceResolution() const
1930 {
1931 // 2 November 2011 Dale Lear
1932 // Changed to NOT create ON_DimStyleExtra user data
1933 // if it did not already exist.
1934 const ON_DimStyleExtra* pDE = DimStyleExtension();
1935 if(pDE)
1936 return pDE->ToleranceResolution();
1937 else
1938 return ON_DimStyle::DefaultToleranceResolution();
1939 }
1940
ToleranceUpperValue() const1941 double ON_DimStyle::ToleranceUpperValue() const
1942 {
1943 // 2 November 2011 Dale Lear
1944 // Changed to NOT create ON_DimStyleExtra user data
1945 // if it did not already exist.
1946 const ON_DimStyleExtra* pDE = DimStyleExtension();
1947 if(pDE)
1948 return pDE->ToleranceUpperValue();
1949 else
1950 return ON_DimStyle::DefaultToleranceUpperValue();
1951 }
1952
ToleranceLowerValue() const1953 double ON_DimStyle::ToleranceLowerValue() const
1954 {
1955 // 2 November 2011 Dale Lear
1956 // Changed to NOT create ON_DimStyleExtra user data
1957 // if it did not already exist.
1958 const ON_DimStyleExtra* pDE = DimStyleExtension();
1959 if(pDE)
1960 return pDE->ToleranceLowerValue();
1961 else
1962 return ON_DimStyle::DefaultToleranceLowerValue();
1963 }
1964
ToleranceHeightScale() const1965 double ON_DimStyle::ToleranceHeightScale() const
1966 {
1967 // 2 November 2011 Dale Lear
1968 // Changed to NOT create ON_DimStyleExtra user data
1969 // if it did not already exist.
1970 const ON_DimStyleExtra* pDE = DimStyleExtension();
1971 if(pDE)
1972 return pDE->ToleranceHeightScale();
1973 else
1974 return ON_DimStyle::DefaultToleranceHeightScale();
1975 }
1976
BaselineSpacing() const1977 double ON_DimStyle::BaselineSpacing() const
1978 {
1979 // 2 November 2011 Dale Lear
1980 // Changed to NOT create ON_DimStyleExtra user data
1981 // if it did not already exist.
1982 const ON_DimStyleExtra* pDE = DimStyleExtension();
1983 if(pDE)
1984 return pDE->BaselineSpacing();
1985 else
1986 return ON_DimStyle::DefaultBaselineSpacing();
1987 }
1988
1989 //static
DefaultToleranceStyle()1990 int ON_DimStyle::DefaultToleranceStyle()
1991 {
1992 return 0;
1993 }
1994
1995 //static
DefaultToleranceResolution()1996 int ON_DimStyle::DefaultToleranceResolution()
1997 {
1998 return 4;
1999 }
2000
2001 //static
DefaultToleranceUpperValue()2002 double ON_DimStyle::DefaultToleranceUpperValue()
2003 {
2004 return 0.0;
2005 }
2006
2007 //static
DefaultToleranceLowerValue()2008 double ON_DimStyle::DefaultToleranceLowerValue()
2009 {
2010 return 0.0;
2011 }
2012
2013 //static
DefaultToleranceHeightScale()2014 double ON_DimStyle::DefaultToleranceHeightScale()
2015 {
2016 return 1.0;
2017 }
2018
2019 //static
DefaultBaselineSpacing()2020 double ON_DimStyle::DefaultBaselineSpacing()
2021 {
2022 return 1.0;
2023 }
2024
2025 // static
DefaultDrawTextMask()2026 bool ON_DimStyle::DefaultDrawTextMask()
2027 {
2028 return false;
2029 }
2030
2031 // static
DefaultMaskColorSource()2032 int ON_DimStyle::DefaultMaskColorSource()
2033 {
2034 return 0;
2035 }
2036
2037 // static
DefaultMaskColor()2038 ON_Color ON_DimStyle::DefaultMaskColor()
2039 {
2040 // 2 November 2011 Dale Lear
2041 // TODO - Ask Lowell what this default is supposed to be.
2042 // His ON_DimStyle::MaskColor() function defaulted to black
2043 // and his ON_DimStyleExtra defaulted to white.
2044 //return 0;
2045 return ON_Color(255,255,255);
2046 }
2047
2048 // static
DefaultDimScale()2049 double ON_DimStyle::DefaultDimScale()
2050 {
2051 return 1.0;
2052 }
2053
2054 // static
DefaultDimScaleSource()2055 int ON_DimStyle::DefaultDimScaleSource()
2056 {
2057 return 0;
2058 }
2059
2060
2061 //-------------------
Scale(double scale)2062 void ON_DimStyle::Scale( double scale)
2063 {
2064 if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON && 1.0 != scale )
2065 {
2066 m_extextension *= scale;
2067 m_extoffset *= scale;
2068 m_arrowsize *= scale;
2069 m_centermark *= scale;
2070 m_textgap *= scale;
2071 m_textheight *= scale;
2072 m_dimextension *= scale;
2073 m_leaderarrowsize *= scale;
2074
2075 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, true );
2076 if(pDE)
2077 {
2078 pDE->Scale( scale);
2079 }
2080 }
2081 }
2082
SetToleranceStyle(int style)2083 void ON_DimStyle::SetToleranceStyle( int style)
2084 {
2085 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceStyle() != style );
2086 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2087 if(pDE)
2088 {
2089 pDE->SetToleranceStyle( style);
2090 }
2091 }
2092
SetToleranceResolution(int resolution)2093 void ON_DimStyle::SetToleranceResolution( int resolution)
2094 {
2095 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceResolution() != resolution );
2096 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2097 if(pDE)
2098 {
2099 pDE->SetToleranceResolution( resolution);
2100 }
2101 }
2102
SetToleranceUpperValue(double upper_value)2103 void ON_DimStyle::SetToleranceUpperValue( double upper_value)
2104 {
2105 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceUpperValue() != upper_value );
2106 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2107 if(pDE)
2108 {
2109 pDE->SetToleranceUpperValue( upper_value);
2110 }
2111 }
2112
SetToleranceLowerValue(double lower_value)2113 void ON_DimStyle::SetToleranceLowerValue( double lower_value)
2114 {
2115 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceLowerValue() != lower_value );
2116 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2117 if(pDE)
2118 {
2119 pDE->SetToleranceLowerValue( lower_value);
2120 }
2121 }
2122
SetToleranceHeightScale(double scale)2123 void ON_DimStyle::SetToleranceHeightScale( double scale)
2124 {
2125 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultToleranceHeightScale() != scale );
2126 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2127 if(pDE)
2128 {
2129 pDE->SetToleranceHeightScale( scale);
2130 }
2131 }
2132
SetBaselineSpacing(double spacing)2133 void ON_DimStyle::SetBaselineSpacing( double spacing)
2134 {
2135 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultBaselineSpacing() != spacing );
2136 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2137 if(pDE)
2138 {
2139 pDE->SetBaselineSpacing( spacing);
2140 }
2141 }
2142
DrawTextMask() const2143 bool ON_DimStyle::DrawTextMask() const
2144 {
2145 // 2 November 2011 Dale Lear
2146 // Do not create user data if it does not already exist.
2147 const ON_DimStyleExtra* pDE = DimStyleExtension();
2148 if(pDE)
2149 return pDE->DrawTextMask();
2150 else
2151 return ON_DimStyle::DefaultDrawTextMask();
2152 }
2153
SetDrawTextMask(bool bDraw)2154 void ON_DimStyle::SetDrawTextMask(bool bDraw)
2155 {
2156 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultDrawTextMask() != (bDraw?true:false) );
2157 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2158 if(pDE)
2159 pDE->SetDrawTextMask(bDraw);
2160 }
2161
MaskColorSource() const2162 int ON_DimStyle::MaskColorSource() const
2163 {
2164 // 2 November 2011 Dale Lear
2165 // Do not create user data if it does not already exist.
2166 const ON_DimStyleExtra* pDE = DimStyleExtension();
2167 if(pDE)
2168 return pDE->MaskColorSource();
2169 else
2170 return ON_DimStyle::DefaultMaskColorSource();
2171 }
2172
SetMaskColorSource(int source)2173 void ON_DimStyle::SetMaskColorSource(int source)
2174 {
2175 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultMaskColorSource() != source );
2176 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2177 if(pDE)
2178 pDE->SetMaskColorSource(source);
2179 }
2180
MaskColor() const2181 ON_Color ON_DimStyle::MaskColor() const
2182 {
2183 // 2 November 2011 Dale Lear
2184 // Do not create user data if it does not already exist.
2185 const ON_DimStyleExtra* pDE = DimStyleExtension();
2186 if(pDE)
2187 return pDE->MaskColor();
2188 else
2189 return ON_DimStyle::DefaultMaskColor();
2190 }
2191
SetMaskColor(ON_Color color)2192 void ON_DimStyle::SetMaskColor(ON_Color color)
2193 {
2194 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultMaskColor() != color );
2195 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2196 if(pDE)
2197 pDE->SetMaskColor(color);
2198 }
2199
MaskOffsetFactor() const2200 double ON_DimStyle::MaskOffsetFactor() const
2201 {
2202 if(m_textheight != 0.0)
2203 return 0.5 * m_textgap / m_textheight;
2204 else
2205 return 0.0;
2206 }
2207
SetDimScale(double scale)2208 void ON_DimStyle::SetDimScale(double scale)
2209 {
2210 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultDimScale() != scale );
2211 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2212 if(pDE)
2213 pDE->SetDimScale(scale);
2214 }
2215
DimScale() const2216 double ON_DimStyle::DimScale() const
2217 {
2218 // 2 November 2011 Dale Lear
2219 // Do not create user data if it does not already exist.
2220 const ON_DimStyleExtra* pDE = DimStyleExtension();
2221 if(pDE) // && pDE->DimScaleSource() == 1)
2222 return pDE->DimScale();
2223 else
2224 return ON_DimStyle::DefaultDimScale();
2225 }
2226
SetDimScaleSource(int source)2227 void ON_DimStyle::SetDimScaleSource(int source)
2228 {
2229 bool bCreateIfDoesNotExist = ( ON_DimStyle::DefaultDimScaleSource() != source );
2230 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2231 if(pDE)
2232 pDE->SetDimScaleSource(source);
2233 }
2234
DimScaleSource() const2235 int ON_DimStyle::DimScaleSource() const
2236 {
2237 // 2 November 2011 Dale Lear
2238 // Do not create user data if it does not already exist.
2239 const ON_DimStyleExtra* pDE = DimStyleExtension();
2240 if(pDE)
2241 return pDE->DimScaleSource();
2242 else
2243 return ON_DimStyle::DefaultDimScaleSource();
2244 }
2245
SetSourceDimstyle(ON_UUID source_uuid)2246 void ON_DimStyle::SetSourceDimstyle(ON_UUID source_uuid)
2247 {
2248 bool bCreateIfDoesNotExist = ( !(ON_nil_uuid == source_uuid) );
2249 ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, bCreateIfDoesNotExist );
2250 if(pDE)
2251 pDE->SetSourceDimstyle(source_uuid);
2252 }
2253
SourceDimstyle() const2254 ON_UUID ON_DimStyle::SourceDimstyle() const
2255 {
2256 // 2 November 2011 Dale Lear
2257 // Do not create user data if it does not already exist.
2258 const ON_DimStyleExtra* pDE = DimStyleExtension();
2259 if(pDE)
2260 return pDE->SourceDimstyle();
2261 else
2262 return ON_nil_uuid;
2263 }
2264
2265
2266
2267
2268 // This function is temporary and will be removed next time the SDK can be modified.
DimStyleExtension()2269 class ON_DimStyleExtra* ON_DimStyle::DimStyleExtension()
2270 {
2271 // This function gets an extensions class if one exists.
2272 // It must not create an extensions class if one does not exist.
2273 ON_DimStyleExtra* pExtra = ON_DimStyleExtra::Cast( GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
2274 return pExtra;
2275 }
2276
DimStyleExtension() const2277 const class ON_DimStyleExtra* ON_DimStyle::DimStyleExtension() const
2278 {
2279 // This function gets an extensions class if one exists.
2280 // It must not create an extensions class if one does not exist.
2281 ON_DimStyleExtra* pExtra = ON_DimStyleExtra::Cast( GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
2282 return pExtra;
2283 }
2284
2285 // returns true if they are the same
CompareFields(const ON_DimStyle & other) const2286 bool ON_DimStyle::CompareFields(const ON_DimStyle& other) const
2287 {
2288 if((m_extextension != other.m_extextension) ||
2289 (m_extoffset != other.m_extoffset) ||
2290 (m_arrowsize != other.m_arrowsize) ||
2291 (m_centermark != other.m_centermark) ||
2292 (m_textgap != other.m_textgap) ||
2293 (m_textheight != other.m_textheight) ||
2294 (m_textalign != other.m_textalign) ||
2295 (m_arrowtype != other.m_arrowtype) ||
2296 (m_angularunits != other.m_angularunits) ||
2297 (m_lengthformat != other.m_lengthformat) ||
2298 (m_angleformat != other.m_angleformat) ||
2299 (m_angleresolution != other.m_angleresolution) ||
2300 (m_lengthresolution != other.m_lengthresolution) ||
2301 (m_fontindex != other.m_fontindex) ||
2302 (m_lengthfactor != other.m_lengthfactor) ||
2303 (m_bAlternate != other.m_bAlternate) ||
2304 (m_alternate_lengthfactor != other.m_alternate_lengthfactor) ||
2305 (m_alternate_lengthformat != other.m_alternate_lengthformat) ||
2306 (m_alternate_lengthresolution != other.m_alternate_lengthresolution) ||
2307 (m_alternate_angleformat != other.m_alternate_angleformat) ||
2308 (m_alternate_angleresolution != other.m_alternate_angleresolution) ||
2309 (m_prefix != other.m_prefix) ||
2310 (m_suffix != other.m_suffix) ||
2311 (m_alternate_prefix != other.m_alternate_prefix) ||
2312 (m_alternate_suffix != other.m_alternate_suffix) ||
2313 (m_dimextension != other.m_dimextension) ||
2314 (m_leaderarrowsize != other.m_leaderarrowsize) ||
2315 (m_leaderarrowtype != other.m_leaderarrowtype) ||
2316 (m_bSuppressExtension1 != other.m_bSuppressExtension1) ||
2317 (m_bSuppressExtension2 != other.m_bSuppressExtension2))
2318 return false;
2319
2320 // 2 November 2011 Dale Lear:
2321 // Do not create ON_DimStyleExtra if it does not already exist.
2322 const ON_DimStyleExtra* pDEo = ON_DimStyleExtra::DimStyleExtensionGet(&other);
2323 const ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet(this);
2324
2325 if ( 0 != pDEo && 0 != pDE && !pDE->CompareFields(pDEo) )
2326 return false;
2327
2328 // 2 November 2011 Dale Lear:
2329 // I added ON_DimStyleExtra::IsDefault() and used it here
2330 // so the plethora of ON_DimStyleExtra user data
2331 // that is is all files made before this date and which contains
2332 // all default settings is correctly handled. (For the past year,
2333 // every single dimstyle has had ON_DimStyleExtra added to it
2334 // that starts out containing default settings.
2335 if ( 0 == pDEo && 0 != pDE && !pDE->IsDefault() )
2336 return false;
2337
2338 if ( 0 == pDE && 0 != pDEo && !pDEo->IsDefault() )
2339 return false;
2340
2341 return true;
2342 }
2343