-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathopennurbs_dimstyle.cpp
More file actions
2342 lines (2056 loc) · 67.8 KB
/
opennurbs_dimstyle.cpp
File metadata and controls
2342 lines (2056 loc) · 67.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
/*
Changes and additions 5/01/07 LW
Adding several fields to ON_Dimstyle
Adding the concept of Parent and Child dimstyles so that individual dimension objects
can have their own copy of a dimension style to override some settings
Adding several fields to ON_Dimstyle - This is done with ON_DimStyleExtra userdata
class for now so the SDK doesn't break completely. When the SDK changes, the data in
ON_DimstyleExtra should be moved into ON_Dimstyle.
Adding the concept of Parent and Child dimstyles to support per object overrides of
dimstyle based properties. Individual dimensions will be able to have one or more
properties that differ from the dimension style for that dimension, but the rest of
their properties will be controlled by the parent dimstyle. In this implementation
(Rhino 5), dimstyles will only inherit one level deep.
The first time an individual dimension has a dimstyle value overridden, a new child
dimstyle is made that is a copy of the dimension's dimstyle. If there is already a
child dimstyle for that dimension, it is used and no new dimstyle is made.
The value being overridden is changed in the child dimstyle and a flag is set that
the field is being overridden.
When a value is changed in a parent dimstyle, it should look through the other
dimstyles in the dimstyle table (or your application's equivalent) and change any
of its children appropriately. Name and Index fields aren't propogated this way.
If the parent's field being changed is not set in the child's m_valid_fields array,
the child's copy of that field should be changed to match the parent's new value.
Changing values in child dimstyles doesn't change values in their parents.
When a value that has previously been overridden by an individual dimension
is set to ByStyle, the corresponding field flag is unset in the valid field array.
If all of the flags in a child dimstyle become unset, the dimension is set to
reference the parent dimstyle directly.
*/
// Added for v5 - 5/01/07 LW
// Userdata class being used to extend ON_DimStyle so the v4 sdk still works
// Presumably, this will be moved into ON_DimStyle when the SDK is changed again
// Don't put this extension class in a header file or export it.
class ON_DimStyleExtra : public ON_UserData
{
ON_OBJECT_DECLARE(ON_DimStyleExtra);
public:
//////// 26 Oct 2010 - Changed to always create ON_DimStyleExtra
//////static ON_DimStyleExtra* DimStyleExtension( ON_DimStyle* pDimStyle);
//////static const ON_DimStyleExtra* DimStyleExtension( const ON_DimStyle* pDimStyle);
// 2 November 2011 Dale Lear
// Undoing above change. Adding this user data is not necessary
// and is causing large memory leaks when it is repeatedly
// added to the default dimstyle in the Rhino dimstyle table.
static ON_DimStyleExtra* DimStyleExtensionGet( ON_DimStyle* pDimStyle, bool bCreateIfNoneExists );
// 2 November 2011 Dale Lear
// Undoing above change. Adding this user data is not necessary
// and is causing large memory leaks when it is repeatedly
// added to the default dimstyle in the Rhino dimstyle table.
// This const version never creates user data.
static const ON_DimStyleExtra* DimStyleExtensionGet( const ON_DimStyle* pDimStyle);
ON_DimStyleExtra();
~ON_DimStyleExtra();
void SetDefaults();
/*
Returns:
True if this ON_DimStyleExtra has default settings.
*/
bool IsDefault() const;
// override virtual ON_Object::Dump function
void Dump( ON_TextLog& text_log ) const;
// override virtual ON_Object::SizeOf function
unsigned int SizeOf() const;
// override virtual ON_Object::Write function
ON_BOOL32 Write(ON_BinaryArchive& binary_archive) const;
// override virtual ON_Object::Read function
ON_BOOL32 Read(ON_BinaryArchive& binary_archive);
// override virtual ON_UserData::GetDescription function
ON_BOOL32 GetDescription( ON_wString& description );
// override virtual ON_UserData::Archive function
ON_BOOL32 Archive() const;
void SetFieldOverride( int field_id, bool bOverride);
bool IsFieldOverride( int field_id) const;
// Data access
// Scale all of the length values
void Scale( double scale);
// Tolerances
// Tolerance style
// 0: None
// 1: Symmetrical
// 2: Deviation
// 3: Limits
// 4: Basic
void SetToleranceStyle( int style);
int ToleranceStyle() const;
void SetToleranceResolution( int resolution);
int ToleranceResolution() const;
void SetToleranceUpperValue( double upper_value);
double ToleranceUpperValue() const;
void SetToleranceLowerValue( double lower_value);
double ToleranceLowerValue() const;
void SetToleranceHeightScale( double scale);
double ToleranceHeightScale() const;
void SetBaselineSpacing( double);
double BaselineSpacing() const;
// Determines whether or not to draw a Text Mask
bool DrawTextMask() const;
void SetDrawTextMask(bool bDraw);
// Determines where to get the color to draw a Text Mask
// 0: Use background color of the viewport. Initially, gradient backgrounds will not be supported
// 1: Use the ON_Color returned by MaskColor()
int MaskColorSource() const;
void SetMaskColorSource(int source);
ON_Color MaskColor() const; // Only works right if MaskColorSource returns 1.
// Does not return viewport background color
void SetMaskColor(ON_Color color);
void SetDimScale(double scale);
double DimScale() const;
void SetDimScaleSource(int source);
int DimScaleSource() const;
void SetSourceDimstyle(ON_UUID source_uuid);
ON_UUID SourceDimstyle() const;
bool CompareFields(const ON_DimStyleExtra* pOther) const;
// Data storage
ON_UUID m_parent_dimstyle; // ON_nil_uuid if there is no parent dimstyle
ON_SimpleArray<bool> m_valid_fields;
enum { eFieldCount = 66 };
int m_tolerance_style;
int m_tolerance_resolution;
double m_tolerance_upper_value; // or both upper and lower in symmetrical style
double m_tolerance_lower_value;
double m_tolerance_height_scale; // relative to the main dimension text
double m_baseline_spacing;
// Text mask - added Dec 12 2009
bool m_bDrawMask;
int m_mask_color_source;
ON_Color m_mask_color;
// Per dimstyle DimScale added Dec 16, 2009
double m_dimscale;
int m_dimscale_source;
// 19 Oct 2010 - Added uuid of source dimstyle to restore defaults
ON_UUID m_source_dimstyle;
};
// Added for v5 - 5/01/07 LW
ON_OBJECT_IMPLEMENT(ON_DimStyleExtra,ON_UserData,"513FDE53-7284-4065-8601-06CEA8B28D6F");
////// 26 Oct 2010 - Lowell - Changed to always create ON_DimStyleExtra if there's not one
////ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtension( ON_DimStyle* pDimStyle)
////{
//// ON_DimStyleExtra* pExtra = 0;
//// if( pDimStyle)
//// {
//// pExtra = ON_DimStyleExtra::Cast( pDimStyle->GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
//// if( pExtra == 0)
//// {
//// pExtra = new ON_DimStyleExtra;
//// if( pExtra)
//// {
//// if( !pDimStyle->AttachUserData( pExtra))
//// {
//// delete pExtra;
//// pExtra = 0;
//// }
//// }
//// }
//// }
//// return pExtra;
////}
// 26 Oct 2010 - Lowell - Changed to always create ON_DimStyleExtra if there's not one
ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtensionGet( ON_DimStyle* pDimStyle, bool bCreateIfNoneExists )
{
ON_DimStyleExtra* pExtra = 0;
if( pDimStyle)
{
pExtra = ON_DimStyleExtra::Cast( pDimStyle->GetUserData( ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid()));
// 2 November 2011 Dale Lear
// I added the bCreateIfNoneExists parameter and I'm using
// is sparingly. It is critical that we do not add
// ON_DimStyleExtra unless it is actually being used
// to override a default setting. Otherwise, we
// end up leaking vast amounts of memory when
// the default dimstyle in the Rhino dimstyle
// table is used due to the way annotation
// is currently drawn.
// If you have questions, please ask Dale Lear for details
// but please do not revert to constantly adding user
// data to dimstyles.
if( pExtra == 0 && bCreateIfNoneExists )
{
pExtra = new ON_DimStyleExtra;
if( pExtra)
{
if( !pDimStyle->AttachUserData( pExtra))
{
delete pExtra;
pExtra = 0;
}
}
}
}
return pExtra;
}
const
ON_DimStyleExtra* ON_DimStyleExtra::DimStyleExtensionGet( const ON_DimStyle* pDimStyle)
{
// Please do not changes the "false" to a "true" in the second argument.
return ON_DimStyleExtra::DimStyleExtensionGet( (ON_DimStyle*)pDimStyle, false );
}
ON_DimStyleExtra::ON_DimStyleExtra()
{
m_userdata_uuid = ON_DimStyleExtra::m_ON_DimStyleExtra_class_id.Uuid();
m_application_uuid = ON_opennurbs5_id; // opennurbs.dll reads/writes this userdata
// The id must be the version 5 id because
// V6 SaveAs V5 needs to work, but SaveAs
// V4 should not write this userdata.
m_userdata_copycount = 1;
m_valid_fields.Reserve( ON_DimStyleExtra::eFieldCount);
m_valid_fields.SetCount( ON_DimStyleExtra::eFieldCount);
m_parent_dimstyle = ON_nil_uuid;
m_source_dimstyle = ON_nil_uuid;
SetDefaults();
}
ON_DimStyleExtra::~ON_DimStyleExtra()
{
}
void ON_DimStyleExtra::SetDefaults()
{
m_tolerance_style = ON_DimStyle::DefaultToleranceStyle();
m_tolerance_resolution = ON_DimStyle::DefaultToleranceResolution();
m_tolerance_upper_value = ON_DimStyle::DefaultToleranceUpperValue();
m_tolerance_lower_value = ON_DimStyle::DefaultToleranceLowerValue();
m_tolerance_height_scale = ON_DimStyle::DefaultToleranceHeightScale();
m_baseline_spacing = ON_DimStyle::DefaultBaselineSpacing();
m_bDrawMask = ON_DimStyle::DefaultDrawTextMask(); // false;
m_mask_color_source = ON_DimStyle::DefaultMaskColorSource(); // 0;
m_mask_color = ON_DimStyle::DefaultMaskColor(); // .SetRGB(255,255,255);
m_dimscale = ON_DimStyle::DefaultDimScale(); // 1.0;
m_dimscale_source = ON_DimStyle::DefaultDimScaleSource(); // 0;
for( int i = 0; i < m_valid_fields.Count(); i++)
m_valid_fields[i] = false;
}
bool ON_DimStyleExtra::IsDefault() const
{
if ( m_tolerance_style != ON_DimStyle::DefaultToleranceStyle() ) return false;
if ( m_tolerance_resolution != ON_DimStyle::DefaultToleranceResolution() ) return false;
if ( m_tolerance_upper_value != ON_DimStyle::DefaultToleranceUpperValue() ) return false;
if ( m_tolerance_lower_value != ON_DimStyle::DefaultToleranceLowerValue() ) return false;
if ( m_tolerance_height_scale != ON_DimStyle::DefaultToleranceHeightScale() ) return false;
if ( m_baseline_spacing != ON_DimStyle::DefaultBaselineSpacing() ) return false;
if ( m_bDrawMask != ON_DimStyle::DefaultDrawTextMask() ) return false;
if ( m_mask_color_source != ON_DimStyle::DefaultMaskColorSource() ) return false;
if ( m_mask_color != ON_DimStyle::DefaultMaskColor() ) return false;
if ( m_dimscale != ON_DimStyle::DefaultDimScale() ) return false;
if ( m_dimscale_source != ON_DimStyle::DefaultDimScaleSource() ) return false;
// The m_valid_fields[] settings only matter when
// m_parent_dimstyle is not zero.
if ( !(m_parent_dimstyle == ON_nil_uuid) )
{
for( int i = 0; i < m_valid_fields.Count() && i < ON_DimStyleExtra::eFieldCount; i++)
{
if ( !m_valid_fields[i] )
return false;
}
}
return true;
}
void ON_DimStyleExtra::Dump( ON_TextLog& text_log ) const
{
// do nothing
}
unsigned int ON_DimStyleExtra::SizeOf() const
{
unsigned int sz = ON_UserData::SizeOf();
sz += sizeof(*this) - sizeof(ON_UserData);
return sz;
}
ON_BOOL32 ON_DimStyleExtra::Write(ON_BinaryArchive& archive) const
{
// bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0); Changed to 1,1 for mask settings 12/12/09
// bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,1); Changed to 1,2 for dimscale 12/17/09
// bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,2); Changed to 1,3 for source_dimstyle 10/19/10
bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,3);
if(rc) rc = archive.WriteUuid( m_parent_dimstyle);
if(rc) rc = archive.WriteArray( m_valid_fields);
if(rc) rc = archive.WriteInt(m_tolerance_style);
if(rc) rc = archive.WriteInt(m_tolerance_resolution);
if(rc) rc = archive.WriteDouble(m_tolerance_upper_value);
if(rc) rc = archive.WriteDouble(m_tolerance_lower_value);
if(rc) rc = archive.WriteDouble(m_tolerance_height_scale);
// March 22, 2010 - Global DimStyle was obsoleted and moved into DimStyles
// So now for writing older version files, its multiplied into all distance values
if(archive.Archive3dmVersion() < 5)
{
if(rc) rc = archive.WriteDouble(m_baseline_spacing * m_dimscale);
}
else
{
if(rc) rc = archive.WriteDouble(m_baseline_spacing);
}
if(rc) rc = archive.WriteBool(m_bDrawMask);
if(rc) rc = archive.WriteInt(m_mask_color_source);
if(rc) rc = archive.WriteColor(m_mask_color);
if(archive.Archive3dmVersion() < 5)
{
if(rc) rc = archive.WriteDouble(1.0);
}
else
{
if(rc) rc = archive.WriteDouble(m_dimscale);
}
if(rc) rc = archive.WriteInt(m_dimscale_source); // Obsolete field
if(rc) rc = archive.WriteUuid(m_source_dimstyle); // Added 19 Oct 2010
if(!archive.EndWrite3dmChunk())
rc = false;
return rc;
}
ON_BOOL32 ON_DimStyleExtra::Read(ON_BinaryArchive& archive)
{
// Changed to 1,0 for mask settings 12/12/09
int major_version = 0;
int minor_version = 0;
bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
if(major_version != 1)
rc = false;
if(rc) rc = archive.ReadUuid(m_parent_dimstyle);
if(rc) rc = archive.ReadArray(m_valid_fields);
if(rc) rc = archive.ReadInt(&m_tolerance_style);
if(rc) rc = archive.ReadInt(&m_tolerance_resolution);
if(rc) rc = archive.ReadDouble(&m_tolerance_upper_value);
if(rc) rc = archive.ReadDouble(&m_tolerance_lower_value);
if(rc) rc = archive.ReadDouble(&m_tolerance_height_scale);
if(rc) rc = archive.ReadDouble(&m_baseline_spacing);
if(minor_version >= 1)
{
if(rc) rc = archive.ReadBool(&m_bDrawMask);
if(rc) rc = archive.ReadInt(&m_mask_color_source);
if(rc) rc = archive.ReadColor(m_mask_color);
}
if(minor_version >= 2)
{
if(rc) rc = archive.ReadDouble(&m_dimscale);
if(rc) rc = archive.ReadInt(&m_dimscale_source);
}
if(minor_version >= 3)
{
if(rc) rc = archive.ReadUuid(m_source_dimstyle);
}
if ( !archive.EndRead3dmChunk() )
rc = false;
return rc;
}
ON_BOOL32 ON_DimStyleExtra::GetDescription( ON_wString& description)
{
description.Format( "Userdata extension of ON_DimStyle");
return true;
}
ON_BOOL32 ON_DimStyleExtra::Archive() const
{
// true to write to file
return true;
}
void ON_DimStyleExtra::Scale( double scale)
{
if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON)
m_baseline_spacing *= scale;
}
// Tolerance style
void ON_DimStyleExtra::SetToleranceStyle( int style)
{
if( style >= 0 && style <= 4)
m_tolerance_style = style;
}
int ON_DimStyleExtra::ToleranceStyle() const
{
return m_tolerance_style;
}
void ON_DimStyleExtra::SetToleranceResolution( int resolution)
{
if( resolution >= 0 && resolution < 16)
m_tolerance_resolution = resolution;
}
int ON_DimStyleExtra::ToleranceResolution() const
{
return m_tolerance_resolution;
}
void ON_DimStyleExtra::SetToleranceUpperValue( double upper_value)
{
if( ON_IsValid(upper_value))
m_tolerance_upper_value = upper_value;
}
double ON_DimStyleExtra::ToleranceUpperValue() const
{
return m_tolerance_upper_value;
}
void ON_DimStyleExtra::SetToleranceLowerValue( double lower_value)
{
if( ON_IsValid(lower_value))
m_tolerance_lower_value = lower_value;
}
double ON_DimStyleExtra::ToleranceLowerValue() const
{
return m_tolerance_lower_value;
}
void ON_DimStyleExtra::SetToleranceHeightScale( double scale)
{
if( ON_IsValid( scale) && scale > ON_SQRT_EPSILON)
m_tolerance_height_scale = scale;
}
double ON_DimStyleExtra::ToleranceHeightScale() const
{
return m_tolerance_height_scale;
}
void ON_DimStyleExtra::SetBaselineSpacing( double spacing)
{
if( ON_IsValid( spacing) && spacing > ON_SQRT_EPSILON)
m_baseline_spacing = spacing;
}
double ON_DimStyleExtra::BaselineSpacing() const
{
return m_baseline_spacing;
}
bool ON_DimStyleExtra::DrawTextMask() const
{
return m_bDrawMask;
}
void ON_DimStyleExtra::SetDrawTextMask(bool bDraw)
{
m_bDrawMask = bDraw ? true : false;
}
int ON_DimStyleExtra::MaskColorSource() const
{
return m_mask_color_source;
}
void ON_DimStyleExtra::SetMaskColorSource(int source)
{
if(source == 1)
m_mask_color_source = 1;
else
m_mask_color_source = 0;
}
ON_Color ON_DimStyleExtra::MaskColor() const
{
return m_mask_color;
}
void ON_DimStyleExtra::SetMaskColor(ON_Color color)
{
m_mask_color = color;
}
void ON_DimStyleExtra::SetDimScale(double scale)
{
m_dimscale = scale;
}
double ON_DimStyleExtra::DimScale() const
{
return m_dimscale;
}
void ON_DimStyleExtra::SetDimScaleSource(int source)
{
m_dimscale_source = source;
}
int ON_DimStyleExtra::DimScaleSource() const
{
return m_dimscale_source;
}
void ON_DimStyleExtra::SetSourceDimstyle(ON_UUID source_uuid)
{
m_source_dimstyle = source_uuid;
}
ON_UUID ON_DimStyleExtra::SourceDimstyle() const
{
return m_source_dimstyle;
}
// returns true if they are the same
bool ON_DimStyleExtra::CompareFields(const ON_DimStyleExtra* pOther) const
{
if(pOther == 0)
return false;
if((m_parent_dimstyle != pOther->m_parent_dimstyle) ||
(m_tolerance_style != pOther->m_tolerance_style) ||
(m_tolerance_resolution != pOther->m_tolerance_resolution) ||
(m_tolerance_upper_value != pOther->m_tolerance_upper_value) ||
(m_tolerance_lower_value != pOther->m_tolerance_lower_value) ||
(m_tolerance_height_scale != pOther->m_tolerance_height_scale) ||
(m_baseline_spacing != pOther->m_baseline_spacing) ||
(m_bDrawMask != pOther->m_bDrawMask) ||
(m_mask_color_source != pOther->m_mask_color_source) ||
(m_mask_color != pOther->m_mask_color) ||
(m_dimscale != pOther->m_dimscale) ||
(m_dimscale_source != pOther->m_dimscale_source)
)
return false;
for(int i = 0; i < m_valid_fields.Count(); i++)
{
if(m_valid_fields[i] != pOther->m_valid_fields[i])
return false;
}
return true;
}
ON_OBJECT_IMPLEMENT( ON_DimStyle, ON_Object, "81BD83D5-7120-41c4-9A57-C449336FF12C" );
ON_DimStyle::ON_DimStyle()
{
// 26 Oct 2010
// Can't create this here because reading files won't attach what's read from the file if
// there's already one there.
// ON_DimStyleExtra::DimStyleExtension( this);
SetDefaultsNoExtension();
}
ON_DimStyle::~ON_DimStyle()
{
}
void ON_DimStyle::SetDefaults()
{
// If there is already a userdata extension, reset it to the defaults,
// but don't make one if its not there already
ON_DimStyleExtra* pDE = ON_DimStyleExtra::DimStyleExtensionGet( this, false );
if( pDE)
{
// 2 November 2011 Dale Lear
// The "default" settings are easily handled
// by not having the user data present in
// the first place. Please discuss changes
// with Dale Lear.
//
delete pDE;
////// reset all field override flags
////for( int i = 0; i < pDE->m_valid_fields.Count(); i++)
//// pDE->m_valid_fields[i] = false;
////pDE->SetDefaults();
}
SetDefaultsNoExtension();
}
// Need to be able to set defaults in base without creating extension
// because file reading won't attach userdata if there's already one there
void ON_DimStyle::SetDefaultsNoExtension()
{
m_dimstyle_index = -1;
memset(&m_dimstyle_id,0,sizeof(m_dimstyle_id));
m_dimstyle_name = L"Default";
m_extextension = 0.5;
m_extoffset = 0.5;
m_arrowsize = 1.0;
m_centermark = 0.5;
m_textgap = 0.25;
m_textheight = 1.0;
m_textalign = ON::dtAboveLine;
m_arrowtype = 0;
m_angularunits = 0;
m_lengthformat = 0;
m_angleformat = 0;
m_lengthresolution = 2;
m_angleresolution = 2;
m_fontindex = -1;
// Added at 1.3
m_lengthfactor = 1.0;
m_bAlternate = false;
m_alternate_lengthfactor = 25.4;
m_alternate_lengthformat = 0;
m_alternate_lengthresolution = 2;
m_alternate_angleformat = 0;
m_alternate_angleresolution = 2;
m_prefix = L"";
m_suffix = L"";
m_alternate_prefix = L" [";
m_alternate_suffix = L"]";
m_valid = 0;
m_dimextension = 0.0;
m_leaderarrowsize = 1.0;
m_leaderarrowtype = 0;
m_bSuppressExtension1 = false;
m_bSuppressExtension2 = false;
}
// copy from ON_3dmAnnotationSettings and add a couple of fields
ON_DimStyle& ON_DimStyle::operator=( const ON_3dmAnnotationSettings& src)
{
SetDefaults();
m_extextension = src.m_dimexe;
m_extoffset = src.m_dimexo;
m_arrowsize = src.m_arrowlength;
m_textalign = src.m_textalign;
m_centermark = src.m_centermark;
m_textgap = src.m_dimexo / 2.0;
m_textheight = src.m_textheight;
m_arrowtype = src.m_arrowtype;
m_angularunits = src.m_angularunits;
m_lengthformat = src.m_lengthformat;
m_angleformat = src.m_angleformat;
m_lengthresolution = src.m_resolution;
m_angleresolution = src.m_resolution;
return *this;
}
//////////////////////////////////////////////////////////////////////
//
// ON_Object overrides
ON_BOOL32 ON_DimStyle::IsValid( ON_TextLog* text_log ) const
{
return ( m_dimstyle_name.Length() > 0 && m_dimstyle_index >= 0);
}
void ON_DimStyle::Dump( ON_TextLog& dump ) const
{
const wchar_t* wsName = m_dimstyle_name;
if ( !wsName )
wsName = L"";
dump.Print("dimstyle index = %d\n",m_dimstyle_index);
dump.Print("dimstyle name = \"%ls\"\n",wsName);
}
ON_BOOL32 ON_DimStyle::Write(
ON_BinaryArchive& file // serialize definition to binary archive
) const
{
// March 22, 2010 - Global DimStyle was obsoleted and moved into DimStyles
// So now for writing older version files, its multiplied into all distance values
double ds = 1.0;
if(file.Archive3dmVersion() < 5)
ds = DimScale();
// changed to version 1.4 Dec 28, 05
// changed to version 1.5 Mar 23, 06
ON_BOOL32 rc = file.Write3dmChunkVersion(1,5);
if (rc) rc = file.WriteInt(m_dimstyle_index);
if (rc) rc = file.WriteString(m_dimstyle_name);
if (rc) rc = file.WriteDouble(m_extextension * ds);
if (rc) rc = file.WriteDouble(m_extoffset * ds);
if (rc) rc = file.WriteDouble(m_arrowsize * ds);
if (rc) rc = file.WriteDouble(m_centermark * ds);
if (rc) rc = file.WriteDouble(m_textgap * ds);
if (rc) rc = file.WriteInt(m_textalign);
if (rc) rc = file.WriteInt(m_arrowtype);
if (rc) rc = file.WriteInt(m_angularunits);
if (rc) rc = file.WriteInt(m_lengthformat);
if (rc) rc = file.WriteInt(m_angleformat);
if (rc) rc = file.WriteInt(m_lengthresolution);
if (rc) rc = file.WriteInt(m_angleresolution);
if (rc) rc = file.WriteInt(m_fontindex);
if (rc) rc = file.WriteDouble(m_textheight * ds);
// added 1/13/05 ver 1.2
if (rc) rc = file.WriteDouble(m_lengthfactor);
if (rc) rc = file.WriteString(m_prefix);
if (rc) rc = file.WriteString(m_suffix);
if (rc) rc = file.WriteBool(m_bAlternate);
if (rc) rc = file.WriteDouble(m_alternate_lengthfactor);
if (rc) rc = file.WriteInt(m_alternate_lengthformat);
if (rc) rc = file.WriteInt(m_alternate_lengthresolution);
if (rc) rc = file.WriteInt(m_alternate_angleformat);
if (rc) rc = file.WriteInt(m_alternate_angleresolution);
if (rc) rc = file.WriteString(m_alternate_prefix);
if (rc) rc = file.WriteString(m_alternate_suffix);
if (rc) rc = file.WriteInt(m_valid);
// Added 24 October 2005 ver 1.3
if (rc) rc = file.WriteUuid(m_dimstyle_id);
// Added Dec 28, 05 ver 1.4
if (rc) rc = file.WriteDouble(m_dimextension * ds);
// Added Mar 23 06 ver 1.5
if (rc) rc = file.WriteDouble(m_leaderarrowsize * ds);
if (rc) rc = file.WriteInt(m_leaderarrowtype);
if (rc) rc = file.WriteBool(m_bSuppressExtension1);
if (rc) rc = file.WriteBool(m_bSuppressExtension2);
return rc;
}
ON_BOOL32 ON_DimStyle::Read(
ON_BinaryArchive& file // restore definition from binary archive
)
{
SetDefaultsNoExtension();
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
if ( major_version >= 1 )
{
if ( rc) rc = file.ReadInt( &m_dimstyle_index);
if ( rc) rc = file.ReadString( m_dimstyle_name);
if ( rc) rc = file.ReadDouble( &m_extextension);
if ( rc) rc = file.ReadDouble( &m_extoffset);
if ( rc) rc = file.ReadDouble( &m_arrowsize);
if ( rc) rc = file.ReadDouble( &m_centermark);
if ( rc) rc = file.ReadDouble( &m_textgap);
if ( rc) rc = file.ReadInt( &m_textalign);
if ( rc) rc = file.ReadInt( &m_arrowtype);
if ( rc) rc = file.ReadInt( &m_angularunits);
if ( rc) rc = file.ReadInt( &m_lengthformat);
if ( rc) rc = file.ReadInt( &m_angleformat);
if ( rc) rc = file.ReadInt( &m_lengthresolution);
if ( rc) rc = file.ReadInt( &m_angleresolution);
if ( rc) rc = file.ReadInt( &m_fontindex);
if( minor_version >= 1)
if ( rc) rc = file.ReadDouble( &m_textheight);
// added 1/13/05
if( minor_version >= 2)
{
if (rc) rc = file.ReadDouble( &m_lengthfactor);
if (rc) rc = file.ReadString( m_prefix);
if (rc) rc = file.ReadString( m_suffix);
if (rc) rc = file.ReadBool( &m_bAlternate);
if (rc) rc = file.ReadDouble(&m_alternate_lengthfactor);
if (rc) rc = file.ReadInt( &m_alternate_lengthformat);
if (rc) rc = file.ReadInt( &m_alternate_lengthresolution);
if (rc) rc = file.ReadInt( &m_alternate_angleformat);
if (rc) rc = file.ReadInt( &m_alternate_angleresolution);
if (rc) rc = file.ReadString( m_alternate_prefix);
if (rc) rc = file.ReadString( m_alternate_suffix);
if (rc) rc = file.ReadInt( &m_valid);
if ( minor_version >= 3 )
{
if (rc) rc = file.ReadUuid(m_dimstyle_id);
}
}
// Added Dec 28, 05 ver 1.4
if( minor_version >= 4)
if( rc) rc = file.ReadDouble( &m_dimextension);
// Added Mar 23 06 ver 1.5
if( minor_version >= 5)
{
if (rc) rc = file.ReadDouble( &m_leaderarrowsize);
if (rc) rc = file.ReadInt( &m_leaderarrowtype);
if (rc) rc = file.ReadBool( &m_bSuppressExtension1);
if (rc) rc = file.ReadBool( &m_bSuppressExtension2);
}
}
else
rc = false;
return rc;
}
void ON_DimStyle::EmergencyDestroy()
{
m_prefix.EmergencyDestroy();
m_suffix.EmergencyDestroy();
m_alternate_prefix.EmergencyDestroy();
m_alternate_suffix.EmergencyDestroy();
}
//////////////////////////////////////////////////////////////////////
//
// Interface
void ON_DimStyle::SetName( const wchar_t* s )
{
m_dimstyle_name = s;
m_dimstyle_name.TrimLeftAndRight();
}
void ON_DimStyle::SetName( const char* s )
{
m_dimstyle_name = s;
m_dimstyle_name.TrimLeftAndRight();
}
void ON_DimStyle::GetName( ON_wString& s ) const
{
s = m_dimstyle_name;
}
const wchar_t* ON_DimStyle::Name() const
{
const wchar_t* s = m_dimstyle_name;
return s;
}
void ON_DimStyle::SetIndex(int i )
{
m_dimstyle_index = i;
}
int ON_DimStyle::Index() const
{
return m_dimstyle_index;
}
double ON_DimStyle::ExtExtension() const
{
return m_extextension;
}
void ON_DimStyle::SetExtExtension( const double e)
{
// Allow negative?
m_extextension = e;
}
double ON_DimStyle::ExtOffset() const
{
return m_extoffset;
}
void ON_DimStyle::SetExtOffset( const double e)
{
m_extoffset = e;
}
double ON_DimStyle::ArrowSize() const
{
return m_arrowsize;
}
void ON_DimStyle::SetArrowSize( const double e)
{
m_arrowsize = e;
}
double ON_DimStyle::LeaderArrowSize() const
{
return m_leaderarrowsize;
}
void ON_DimStyle::SetLeaderArrowSize( const double e)
{
m_leaderarrowsize = e;
}
double ON_DimStyle::CenterMark() const
{
return m_centermark;
}
void ON_DimStyle::SetCenterMark( const double e)
{
m_centermark = e;
}
int ON_DimStyle::TextAlignment() const
{
return m_textalign;
}
void ON_DimStyle::SetTextAlignment( ON::eTextDisplayMode a)
{
m_textalign = a;
}
int ON_DimStyle::ArrowType() const
{
return m_arrowtype;
}
void ON_DimStyle::SetArrowType( eArrowType a)
{
m_arrowtype = a;
}
int ON_DimStyle::LeaderArrowType() const
{
return m_leaderarrowtype;
}
void ON_DimStyle::SetLeaderArrowType( eArrowType a)
{