forked from louipc/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_annotation2.cpp
6870 lines (5973 loc) · 176 KB
/
opennurbs_annotation2.cpp
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"
// This define is up here so anybody who want's to defeat the
// bozo vaccine has to be doing it on purpose.
#define BOZO_VACCINE_699FCC4262D4488c9109F1B7A37CE926
// Added for v5 - 12-10-2009 LW
ON_OBJECT_IMPLEMENT(ON_TextExtra,ON_UserData,"D90490A5-DB86-49f8-BDA1-9080B1F4E976");
ON_TextExtra::ON_TextExtra()
{
m_userdata_uuid = ON_TextExtra::m_ON_TextExtra_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;
SetDefaults();
}
ON_TextExtra::~ON_TextExtra()
{
}
ON_TextExtra* ON_TextExtra::TextExtension(ON_TextEntity2* pText, bool bCreate)
{
ON_TextExtra* pExtra = 0;
if(pText)
{
pExtra = ON_TextExtra::Cast(pText->GetUserData(ON_TextExtra::m_ON_TextExtra_class_id.Uuid()));
if(pExtra == 0 && bCreate)
{
pExtra = new ON_TextExtra;
if(pExtra)
{
if(!pText->AttachUserData(pExtra))
{
delete pExtra;
pExtra = 0;
}
}
}
}
return pExtra;
}
const
ON_TextExtra* ON_TextExtra::TextExtension(const ON_TextEntity2* pText, bool bCreate)
{
return TextExtension((ON_TextEntity2*)pText, bCreate);
}
void ON_TextExtra::SetDefaults()
{
m_parent_uuid = ON_nil_uuid;
m_color_source = 0;
m_mask_color = 0;
m_border_offset = 0.1;
}
void ON_TextExtra::Dump( ON_TextLog& text_log ) const
{
// do nothing
}
unsigned int ON_TextExtra::SizeOf() const
{
unsigned int sz = ON_UserData::SizeOf();
sz += sizeof(*this) - sizeof(ON_UserData);
return sz;
}
ON_BOOL32 ON_TextExtra::Write(ON_BinaryArchive& archive) const
{
bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
if(rc) rc = archive.WriteUuid(m_parent_uuid);
if(rc) rc = archive.WriteBool(m_bDrawMask);
if(rc) rc = archive.WriteInt(m_color_source);
if(rc) rc = archive.WriteColor(m_mask_color);
if(rc) rc = archive.WriteDouble(m_border_offset);
if(!archive.EndWrite3dmChunk())
rc = false;
return rc;
}
ON_BOOL32 ON_TextExtra::Read(ON_BinaryArchive& archive)
{
int major_version = 1;
int minor_version = 0;
bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
if(!rc)
return false;
if(major_version != 1)
return false;
if(rc) rc = archive.ReadUuid(m_parent_uuid);
if(rc) rc = archive.ReadBool(&m_bDrawMask);
if(rc) rc = archive.ReadInt(&m_color_source);
if(rc) rc = archive.ReadColor(m_mask_color);
if(rc) rc = archive.ReadDouble(&m_border_offset);
if ( !archive.EndRead3dmChunk() )
rc = false;
return rc;
}
ON_BOOL32 ON_TextExtra::GetDescription( ON_wString& description)
{
description.Format( "Userdata extension of ON_TextEntity");
return true;
}
ON_BOOL32 ON_TextExtra::Archive() const
{
// true to write to file
return true;
}
ON_UUID ON_TextExtra::ParentUUID() const
{
return m_parent_uuid;
}
void ON_TextExtra::SetParentUUID( ON_UUID parent_uuid)
{
m_parent_uuid = parent_uuid;
}
bool ON_TextExtra::DrawTextMask() const
{
return m_bDrawMask;
}
void ON_TextExtra::SetDrawTextMask(bool bDraw)
{
m_bDrawMask = bDraw;
}
int ON_TextExtra::MaskColorSource() const
{
return m_color_source;
}
void ON_TextExtra::SetMaskColorSource(int source)
{
if(source == 1)
m_color_source = 1;
else
m_color_source = 0;
}
ON_Color ON_TextExtra::MaskColor() const
{
return m_mask_color;
}
void ON_TextExtra::SetMaskColor(ON_Color color)
{
m_mask_color = color;
}
double ON_TextExtra::MaskOffsetFactor() const
{
return m_border_offset;
}
void ON_TextExtra::SetMaskOffsetFactor(double offset)
{
m_border_offset = offset;
}
//--------------------
// Added for v5 - 4-20-07 LW
ON_OBJECT_IMPLEMENT(ON_DimensionExtra,ON_UserData,"8AD5B9FC-0D5C-47fb-ADFD-74C28B6F661E");
ON_DimensionExtra::ON_DimensionExtra()
{
m_userdata_uuid = ON_DimensionExtra::m_ON_DimensionExtra_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;
SetDefaults();
}
ON_DimensionExtra::~ON_DimensionExtra()
{
}
static ON_DimensionExtra* AnnotationExtension(ON_Annotation2* pDim, bool bCreate)
{
ON_DimensionExtra* pExtra = 0;
if(pDim)
{
pExtra = ON_DimensionExtra::Cast(pDim->GetUserData(ON_DimensionExtra::m_ON_DimensionExtra_class_id.Uuid()));
if(pExtra == 0 && bCreate)
{
pExtra = new ON_DimensionExtra;
if( pExtra)
{
if(!pDim->AttachUserData(pExtra))
{
delete pExtra;
pExtra = 0;
}
}
}
}
return pExtra;
}
ON_DimensionExtra* ON_DimensionExtra::DimensionExtension(ON_LinearDimension2* pDim, bool bCreate)
{
return AnnotationExtension((ON_Annotation2*)pDim, bCreate);
}
const
ON_DimensionExtra* ON_DimensionExtra::DimensionExtension(const ON_LinearDimension2* pDim, bool bCreate)
{
return DimensionExtension((ON_LinearDimension2*)pDim, bCreate);
}
ON_DimensionExtra* ON_DimensionExtra::DimensionExtension(ON_RadialDimension2* pDim, bool bCreate)
{
return AnnotationExtension((ON_Annotation2*)pDim, bCreate);
}
const
ON_DimensionExtra* ON_DimensionExtra::DimensionExtension(const ON_RadialDimension2* pDim, bool bCreate)
{
return DimensionExtension((ON_RadialDimension2*)pDim, bCreate);
}
ON_DimensionExtra* ON_DimensionExtra::DimensionExtension(ON_OrdinateDimension2* pDim, bool bCreate)
{
return AnnotationExtension((ON_Annotation2*)pDim, bCreate);
}
const
ON_DimensionExtra* ON_DimensionExtra::DimensionExtension(const ON_OrdinateDimension2* pDim, bool bCreate)
{
return DimensionExtension((ON_OrdinateDimension2*)pDim, bCreate);
}
void ON_DimensionExtra::SetDefaults()
{
m_partent_uuid = ON_nil_uuid;
m_arrow_position = 0;
m_text_rects = 0;
m_distance_scale = 1.0;
m_modelspace_basepoint = ON_origin;
}
void ON_DimensionExtra::Dump( ON_TextLog& text_log ) const
{
// do nothing
}
unsigned int ON_DimensionExtra::SizeOf() const
{
unsigned int sz = ON_UserData::SizeOf();
sz += sizeof(*this) - sizeof(ON_UserData);
return sz;
}
ON_BOOL32 ON_DimensionExtra::Write(ON_BinaryArchive& archive) const
{
int major_version = 1;
int minor_version = 1;
bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,major_version,minor_version);
if(rc) rc = archive.WriteUuid( m_partent_uuid);
if(rc) rc = archive.WriteInt( m_arrow_position);
if(rc)
{
if( m_text_rects)
{
rc = archive.WriteInt( 7);
rc = archive.WriteInt( 28, (const int*)m_text_rects);
}
else
rc = archive.WriteInt( 0);
}
// 21 June 2010 Added distance scale, minor version 1
if(rc) rc = archive.WriteDouble(m_distance_scale);
if(!archive.EndWrite3dmChunk())
rc = false;
return rc;
}
ON_BOOL32 ON_DimensionExtra::Read(ON_BinaryArchive& archive)
{
int major_version = 1;
int minor_version = 0;
bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
if(!rc)
return false;
if(major_version != 1)
return false;
if(rc) rc = archive.ReadUuid(m_partent_uuid);
if(rc) rc = archive.ReadInt(&m_arrow_position);
int rect_count = 0;
if(rc) rc = archive.ReadInt( &rect_count);
if( rc && rect_count)
rc = archive.ReadInt( rect_count, (int*)m_text_rects);
// 21 June 2010 Added distance scale, minor version 1
if(minor_version > 0)
{
if(rc) rc = archive.ReadDouble(&m_distance_scale);
}
if ( !archive.EndRead3dmChunk() )
rc = false;
return rc;
}
ON_BOOL32 ON_DimensionExtra::GetDescription( ON_wString& description)
{
description.Format( "Userdata extension of ON_Dimensions");
return true;
}
ON_BOOL32 ON_DimensionExtra::Archive() const
{
// true to write to file
return true;
}
ON_UUID ON_DimensionExtra::ParentUUID() const
{
return m_partent_uuid;
}
void ON_DimensionExtra::SetParentUUID( ON_UUID partent_uuid)
{
m_partent_uuid = partent_uuid;
}
int ON_DimensionExtra::ArrowPosition() const
{
return m_arrow_position;
}
void ON_DimensionExtra::SetArrowPosition( int position)
{
if( position > 0)
m_arrow_position = 1;
else if( position < 0)
m_arrow_position = -1;
else
m_arrow_position = 0;
}
double ON_DimensionExtra::DistanceScale() const
{
return m_distance_scale;
}
void ON_DimensionExtra::SetDistanceScale(double s)
{
m_distance_scale = s;
}
void ON_DimensionExtra::SetModelSpaceBasePoint(ON_3dPoint basepoint)
{
m_modelspace_basepoint = basepoint;
}
ON_3dPoint ON_DimensionExtra::ModelSpaceBasePoint() const
{
return m_modelspace_basepoint;
}
/*
const wchar_t* ON_DimensionExtra::ToleranceUpperString() const
{
return m_upper_string;
}
ON_wString& ON_DimensionExtra::ToleranceUpperString()
{
return m_upper_string;
}
void ON_DimensionExtra::SetToleranceUpperString( const wchar_t* upper_string)
{
m_upper_string = upper_string;
}
void ON_DimensionExtra::SetToleranceUpperString( ON_wString& upper_string)
{
m_upper_string = upper_string;
}
const wchar_t* ON_DimensionExtra::ToleranceLowerString() const
{
return m_lower_string;
}
ON_wString& ON_DimensionExtra::ToleranceLowerString()
{
return m_lower_string;
}
void ON_DimensionExtra::SetToleranceLowerString( const wchar_t* lower_string)
{
m_lower_string = lower_string;
}
void ON_DimensionExtra::SetToleranceLowerString( ON_wString& lower_string)
{
m_lower_string = lower_string;
}
const wchar_t* ON_DimensionExtra::AlternateString() const
{
return m_alt_string;
}
ON_wString& ON_DimensionExtra::AlternateString()
{
return m_alt_string;
}
void ON_DimensionExtra::SetAlternateString( const wchar_t* alt_string)
{
m_alt_string = alt_string;
}
void ON_DimensionExtra::SetAlternateString( ON_wString& alt_string)
{
m_alt_string = alt_string;
}
const wchar_t* ON_DimensionExtra::AlternateToleranceUpperString() const
{
return m_alt_upper_string;
}
ON_wString& ON_DimensionExtra::AlternateToleranceUpperString()
{
return m_alt_upper_string;
}
void ON_DimensionExtra::SetAlternateToleranceUpperString( const wchar_t* upper_string)
{
m_alt_upper_string = upper_string;
}
void ON_DimensionExtra::SetAlternateToleranceUpperString( ON_wString& upper_string)
{
m_alt_upper_string = upper_string;
}
const wchar_t* ON_DimensionExtra::AlternateToleranceLowerString() const
{
return m_alt_lower_string;
}
ON_wString& ON_DimensionExtra::AlternateToleranceLowerString()
{
return m_alt_lower_string;
}
void ON_DimensionExtra::SetAlternateToleranceLowerString( const wchar_t* lower_string)
{
m_alt_lower_string = lower_string;
}
void ON_DimensionExtra::SetAlternateToleranceLowerString( ON_wString& lower_string)
{
m_alt_lower_string = lower_string;
}
*/
//--------------------
ON_VIRTUAL_OBJECT_IMPLEMENT( ON_Annotation2, ON_Geometry, "8D820224-BC6C-46b4-9066-BF39CC13AEFB");
ON_OBJECT_IMPLEMENT( ON_LinearDimension2, ON_Annotation2, "BD57F33B-A1B2-46e9-9C6E-AF09D30FFDDE");
ON_OBJECT_IMPLEMENT( ON_RadialDimension2, ON_Annotation2, "B2B683FC-7964-4e96-B1F9-9B356A76B08B");
ON_OBJECT_IMPLEMENT( ON_AngularDimension2, ON_Annotation2, "841BC40B-A971-4a8e-94E5-BBA26D67348E");
ON_OBJECT_IMPLEMENT( ON_TextEntity2, ON_Annotation2, "46F75541-F46B-48be-AA7E-B353BBE068A7");
ON_OBJECT_IMPLEMENT( ON_Leader2, ON_Annotation2, "14922B7A-5B65-4f11-8345-D415A9637129");
ON_OBJECT_IMPLEMENT( ON_TextDot, ON_Geometry, "74198302-CDF4-4f95-9609-6D684F22AB37");
ON_OBJECT_IMPLEMENT( ON_OrdinateDimension2,ON_Annotation2, "C8288D69-5BD8-4f50-9BAF-525A0086B0C3");
// class ON_Annotation2
//--------------------------------------------------------------------
int ON_Annotation2::Index() const
{
return m_index;
}
void ON_Annotation2::SetIndex( int index)
{
m_index = index;
}
void ON_Annotation2::Create()
{
m_textdisplaymode = ON::dtAboveLine;
m_index = -1;
m_textheight = 1.0;
Destroy();
}
void ON_Annotation2::Destroy()
{
// 10-27-03 LW memory leak prevention
m_points.Empty();
SetTextValue(0);
SetTextFormula(0);
m_type = ON::dtNothing;
m_plane = ON_xy_plane;
m_userpositionedtext = false;
m_justification = 0;
m_annotative_scale = true;
}
void ON_Annotation2::EmergencyDestroy()
{
m_points.EmergencyDestroy();
m_usertext.EmergencyDestroy();
}
ON_Annotation2::ON_Annotation2()
{
Create();
}
ON_Annotation2::~ON_Annotation2()
{
Destroy();
}
bool ON_Annotation2::EvaluatePoint( const ON_ObjRef& objref, ON_3dPoint& P) const
{
bool rc = false;
switch( objref.m_component_index.m_type )
{
case ON_COMPONENT_INDEX::dim_linear_point:
case ON_COMPONENT_INDEX::dim_radial_point:
case ON_COMPONENT_INDEX::dim_angular_point:
case ON_COMPONENT_INDEX::dim_ordinate_point:
case ON_COMPONENT_INDEX::dim_text_point:
{
ON_2dPoint uv = Point(objref.m_component_index.m_index);
if ( uv.IsValid() )
{
P = m_plane.PointAt(uv.x,uv.y);
rc = true;
}
}
break;
default:
// other enum values skipped on purpose
break;
}
if (!rc)
{
P = ON_UNSET_POINT;
}
return rc;
}
// convert from old style annotation
ON_Annotation2& ON_Annotation2::operator=(const ON_Annotation& src)
{
// get a clean and empty "this"
Destroy();
Create();
ON_Geometry::operator=(src);
m_type = src.Type();
m_textdisplaymode = src.TextDisplayMode();
m_plane = src.Plane();
// 13 November 2006 Dale Lear
// Copying 5 points isn't always the right
// thing to do. Sometimes there should be
// no points or fewer points. I'm leaving
// this unchnaged for now and fixing the
// immediate bugs downstream. When we
// have a larger window (> 1 week before
// release) for beta testing, I'll change
// this to copy the number of points
// that actually exist in src
m_points.Reserve(5);
for( int i = 0; i < 5; i++)
SetPoint( 0, src.Point( i));
SetTextValue(src.UserText());
SetTextFormula(0);
m_userpositionedtext = src.UserPositionedText()?true:false;
m_index = 0;
m_textheight = 1.0;
return *this;
}
ON_Annotation2::ON_Annotation2(const ON_Annotation& src)
{
Create();
*this = src;
}
ON_BOOL32 ON_Annotation2::IsValid( ON_TextLog* text_log ) const
{
if ( !m_plane.IsValid() )
{
if ( text_log )
{
text_log->Print("ON_Annotation2 - m_plane is not valid\n");
}
return false;
}
const int points_count = m_points.Count();
int i;
for ( i = 0; i < points_count; i++ )
{
if ( !m_points[i].IsValid() )
{
if ( text_log )
{
text_log->Print("ON_Annotation2 - m_points[%d] is not valid.\n");
}
return false;
}
}
switch ( m_type )
{
case ON::dtDimLinear:
case ON::dtDimAligned:
case ON::dtDimAngular:
case ON::dtDimDiameter:
case ON::dtDimRadius:
case ON::dtLeader:
case ON::dtTextBlock:
case ON::dtDimOrdinate:
break;
default:
if ( text_log )
{
text_log->Print("ON_Annotation2 - m_type = %d is not a valid enum value\n",m_type);
}
return false;
break;
}
return true;
}
/*
bool ON_LinearDimension2::GetAnnotationBoundingBox(
const ON_DimStyle* dimstyle,
ON_2dPoint text0,
ON_2dPoint text1,
ON_BoundingBox& tight_bbox,
int bGrowBox,
const ON_Xform* xform
) const
{
if ( 5 == m_points.Count() )
{
// Get 5 points that are always in the
ON_3dPointArray P(10);
ON_2dPoint uv0, uv1, uv2, uv3;
P.Append( m_plane.origin );
uv0 = m_points[0];
uv1 = uv0;
uv1.y = m_points[1].y;
uv2 = m_points[2];
uv3.x = uv2.x;
uv3.y = uv1.y;
P.Append( m_plane.PointAt(uv0.x,uv0.y) );
P.Append( m_plane.PointAt(uv1.x,uv1.y) );
P.Append( m_plane.PointAt(uv2.x,uv2.y) );
P.Append( m_plane.PointAt(uv3.x,uv3.y) );
if ( dimstyle )
{
// The ends of the displayed extension lines
// have their "y" values adjusted by the dimstyle.
const double el_offset = dimstyle->ExtOffset();
const double el_extension = dimstyle->ExtExtension();
const double v0 = (uv0.y < uv1.y) ? -1.0 : 1.0;
uv0.y += v0*el_offset;
uv1.y += v0*el_extension;
const double v1 = (uv2.y < uv3.y) ? -1.0 : 1.0;
uv2.y += v1*el_offset;
uv3.y += v1*el_extension;
P.Append( m_plane.PointAt(uv0.x,uv0.y) );
P.Append( m_plane.PointAt(uv1.x,uv1.y) );
P.Append( m_plane.PointAt(uv2.x,uv2.y) );
P.Append( m_plane.PointAt(uv3.x,uv3.y) );
}
ON_2dPoint corners[4];
if ( GetAnnotationText2dBoundingBox(dimstyle,text0,text1,corners) )
{
P.Append( m_plane.PointAt(corners[0].x,corners[0].y) );
P.Append( m_plane.PointAt(corners[1].x,corners[1].y) );
P.Append( m_plane.PointAt(corners[2].x,corners[2].y) );
P.Append( m_plane.PointAt(corners[3].x,corners[3].y) );
}
// TODO Add arrowheads
if ( P.GetTightBoundingBox( tight_bbox, bGrowBox, xform ) )
bGrowBox = true;
}
else if ( bGrowBox && !tight_bbox.IsValid() )
{
// invalid linear dimension
tight_bbox.Destroy();
bGrowBox = false;
}
return (0!=bGrowBox);
}
*/
static bool WriteAnnotation2UserText_V4( ON_BinaryArchive& file, const ON_wString& s )
{
bool rc;
ON_wString s4;
int len = s.Length();
for(int i = 0; i < len; i++)
{
if(s[i] == '\r' || s[i] == '\n')
{
s4 += L'\r';
s4 += L'\n';
// May 24, 2012 Tim - Fix for RR 100260. If we use a while here we
// miss adding carriage returns where the user really meant to have a
// blank line. If we only check the next character and then continue on
// we preserve the blank lines.
if(i < len-1 && (s[i+1] == L'\r' || s[i+1] == L'\n'))
i++;
continue;
}
s4 += s[i];
}
rc = file.WriteString(s4);
return rc;
}
static bool WriteAnnotation2UserText_V5( ON_BinaryArchive& file, const ON_wString& s )
{
bool rc;
rc = file.WriteString( s);
return rc;
}
//static int CountTextLines(const ON_wString& text)
//{
// int len = text.Length();
// int lines = len > 0 ? 1 : 0;
// for(int i = 0; i < len; i++)
// {
// if(text[i] == L'\n' || text[i] == L'\r')
// {
// lines++;
// if(i < len-1 && text[i] == L'\r' && text[i+1] == L'\n')
// i++;
// }
// }
// return lines;
//}
ON_BOOL32 ON_Annotation2::Write( ON_BinaryArchive& file ) const
{
int i;
bool rc = false;
bool bInChunk = (file.Archive3dmVersion() >= 5 );
if ( bInChunk )
{
// 18 October 2007 Dale Lear
// I modified this code so that V5 files can add
// information in ON_Annotation2 chunks without
// breaking past and future file IO.
// The opennurbs version number before this change was
// 20071017*. I changed the version to 20071018* when
// I checked in this IO change. The reason I can get
// away with this is that nobody except developers has
// a copy of V5 Rhino.
// 28 Aug, 2010 - Lowell - changed minor version 0->1 to write
// annotative scale flag
// 24 September 2010 Dale Lear
// I incremented chunk version to 1.2 and wrote the TextFormaula() string.
rc = file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,2);
if (!rc)
return false;
}
else
{
// For archives with opennurbs version < 200710180
// The code before version 200710180 does not properly
// handle new additions to the ON_Annotation2 chunk.
rc = file.Write3dmChunkVersion( 1, 0 );
}
while(rc)
{
i = m_type;
rc = file.WriteInt( i);
if ( !rc) break;
i = m_textdisplaymode;
rc = file.WriteInt( i);
if ( !rc) break;
// June 17, 2010 - Lowell - Added adjustment to position text
// a little better in pre-v5 files.
// There's no adjustment for right/left justify becasue we don't
// know the width of the text here
// This doesn't change the size or position of any fields being
// written, but just adjusts the plane to tune up the alignment
// 16 Nov, 2011 - Lowell - Change text to bottom left justified for pre-v5 files rr94270
// This stuff is moved to CRhinoDoc::Write3DMHelper() so it will help with other file
// formats too
//ON_Plane plane = m_plane;
//if(file.Archive3dmVersion() <= 4 && m_type == ON::dtTextBlock)
//{
// double height = m_textheight;
// int lines = CountTextLines(m_usertext);
// double linefeed = ON_Font::m_default_linefeed_ratio;
// if(m_justification & tjBottom)
// {
// if(lines > 1)
// {
// ON_3dPoint p = plane.PointAt(0.0, -height * (lines-1) * linefeed);
// plane.SetOrigin(p);
// }
// }
// else if(m_justification & tjMiddle)
// {
// double h = height * (lines-1) * linefeed + height;
// ON_3dPoint p = plane.PointAt(0.0, h * 0.5);
// plane.SetOrigin(p);
// }
// else if(m_justification & tjTop)
// {
// ON_3dPoint p = plane.PointAt(0.0, -height);
// plane.SetOrigin(p);
// }
//}
rc = file.WritePlane(m_plane);
if ( !rc) break;
ON_2dPointArray points = m_points;
int bUserPositionedText = m_userpositionedtext?1:0;
switch( m_type )
{
case ON::dtDimAligned:
case ON::dtDimLinear:
if ( 4 == points.Count() )
{
// so old versions will read enough points.
points.AppendNew();
points[4].Set(0.5*(points[0].x + points[2].x),points[1].y);
bUserPositionedText = false;
}
break;
case ON::dtDimAngular:
//user positioned text is supported.
break;
case ON::dtDimRadius:
case ON::dtDimDiameter:
// 9 August 2005 Dale Lear - radial dimensions do
// not support user postioned text. The never have
// in Rhino, but the old files had 5 points in them.
if ( 4 == points.Count() )
{
// so old versions will read enough points.
points.AppendNew();
}
if ( points.Count() >= 5 )
{
points[4] = points[2];
}
bUserPositionedText = false;
break;
default:
bUserPositionedText = false;
break;
}
rc = file.WriteArray( points);
if ( !rc) break;
// June 17, 2010 - Lowell - Added support for writing word-wrapped text
// to pre-v5 files with hard returns in place of wrapping markers
rc = ( file.Archive3dmVersion() <= 4 )
? WriteAnnotation2UserText_V4(file,m_usertext)
: WriteAnnotation2UserText_V5(file,m_usertext);
if ( !rc) break;
// 7-9-03 lw removed extra text string getting written
rc = file.WriteInt( bUserPositionedText );
if ( !rc) break;
rc = file.WriteInt( m_index); // font or dimstyle index
if ( !rc) break;
rc = file.WriteDouble( m_textheight);
if ( !rc) break;
if ( !bInChunk )
break;
// NOTE WELL - NEVER change the code in this function
// above this comment. If you do, you will
// break reading and writing V4 files.
// Ask Dale Lear if you have any questions.
// 18 October 2007 - Dale Lear added m_justification IO
rc = file.WriteInt(m_justification);
if ( !rc)
break;
// 28 Aug 2010 - Lowell - Added flag for whether text gets scaled in modelspace
rc = file.WriteBool(m_annotative_scale);
if(!rc)
break;
// 24 September 2010 Dale Lear
// I incremented chunk version to 1.2
ON_wString text_formula = TextFormula();
rc = file.WriteString(text_formula);
if(!rc)
break;
// To write more ON_Annotation2 fields, increment the minor version
// number and write the new information here.
// Finished writing ON_Annotation2 information
break;
}
if ( bInChunk )