-
Notifications
You must be signed in to change notification settings - Fork 140
/
opennurbs_3dm_settings.cpp
7132 lines (6181 loc) · 193 KB
/
opennurbs_3dm_settings.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
//
// Copyright (c) 1993-2022 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"
#include "opennurbs_internal_defines.h"
#if !defined(ON_COMPILING_OPENNURBS)
// This check is included in all opennurbs source .c and .cpp files to insure
// ON_COMPILING_OPENNURBS is defined when opennurbs source is compiled.
// When opennurbs source is being compiled, ON_COMPILING_OPENNURBS is defined
// and the opennurbs .h files alter what is declared and how it is declared.
#error ON_COMPILING_OPENNURBS must be defined when compiling opennurbs
#endif
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmUnitsAndTolerances
//
static double ON_Internal_UnitSystemCtorMetersPerUnit(
ON::LengthUnitSystem length_unit_system
)
{
double meters_per_unit;
switch (length_unit_system)
{
case ON::LengthUnitSystem::None:
meters_per_unit = 1.0;
break;
case ON::LengthUnitSystem::Angstroms:
case ON::LengthUnitSystem::Nanometers:
case ON::LengthUnitSystem::Microns:
case ON::LengthUnitSystem::Millimeters:
case ON::LengthUnitSystem::Centimeters:
case ON::LengthUnitSystem::Decimeters:
case ON::LengthUnitSystem::Meters:
case ON::LengthUnitSystem::Dekameters:
case ON::LengthUnitSystem::Hectometers:
case ON::LengthUnitSystem::Kilometers:
case ON::LengthUnitSystem::Megameters:
case ON::LengthUnitSystem::Gigameters:
case ON::LengthUnitSystem::Microinches:
case ON::LengthUnitSystem::Mils:
case ON::LengthUnitSystem::Inches:
case ON::LengthUnitSystem::Feet:
case ON::LengthUnitSystem::Yards:
case ON::LengthUnitSystem::Miles:
case ON::LengthUnitSystem::PrinterPoints:
case ON::LengthUnitSystem::PrinterPicas:
case ON::LengthUnitSystem::NauticalMiles:
case ON::LengthUnitSystem::AstronomicalUnits:
case ON::LengthUnitSystem::LightYears:
case ON::LengthUnitSystem::Parsecs:
meters_per_unit = ON::UnitScale(length_unit_system, ON::LengthUnitSystem::Meters);
break;
case ON::LengthUnitSystem::CustomUnits:
meters_per_unit = 1.0;
break;
case ON::LengthUnitSystem::Unset:
meters_per_unit = ON_DBL_QNAN;
break;
default:
meters_per_unit = ON_DBL_QNAN;
break;
}
return meters_per_unit;
}
ON_UnitSystem::ON_UnitSystem(ON::LengthUnitSystem length_unit_system)
: m_unit_system(ON::LengthUnitSystemFromUnsigned(static_cast<unsigned int>(length_unit_system)))
, m_meters_per_custom_unit(ON_Internal_UnitSystemCtorMetersPerUnit(m_unit_system))
{}
ON_UnitSystem& ON_UnitSystem::operator=(
ON::LengthUnitSystem length_unit_system
)
{
*this = ON_UnitSystem(length_unit_system);
return *this;
}
bool ON_UnitSystem::operator==(const ON_UnitSystem& other) const
{
if ( m_unit_system != other.m_unit_system )
return false;
if ( ON::LengthUnitSystem::CustomUnits == m_unit_system )
{
if ( !(m_meters_per_custom_unit == other.m_meters_per_custom_unit) )
return false;
if ( false == m_custom_unit_name.EqualOrdinal(other.m_custom_unit_name,false) )
return false;
}
return true;
}
bool ON_UnitSystem::operator!=(const ON_UnitSystem& other) const
{
if ( m_unit_system != other.m_unit_system )
return true;
if ( ON::LengthUnitSystem::CustomUnits == m_unit_system )
{
if (m_meters_per_custom_unit != other.m_meters_per_custom_unit)
return true;
if ( false == m_custom_unit_name.EqualOrdinal(other.m_custom_unit_name,false) )
return true;
}
return false;
}
bool ON_UnitSystem::IsValid() const
{
if ( m_unit_system != ON::LengthUnitSystemFromUnsigned(static_cast<unsigned int>(m_unit_system)) )
{
// invalid enum value
return false;
}
if (ON::LengthUnitSystem::Unset == m_unit_system)
return false;
if (ON::LengthUnitSystem::CustomUnits == m_unit_system)
{
if (false == ON_IsValidPositiveNumber(m_meters_per_custom_unit))
return false;
}
return true;
}
bool ON_UnitSystem::IsSet() const
{
return (ON::LengthUnitSystem::Unset != m_unit_system && ON::LengthUnitSystem::None != m_unit_system && IsValid() );
}
bool ON_UnitSystem::IsCustomUnitSystem() const
{
return (ON::LengthUnitSystem::CustomUnits == m_unit_system && IsSet());
}
void ON_UnitSystem::SetUnitSystem(
ON::LengthUnitSystem us
)
{
*this = ON_UnitSystem(us);
}
ON_UnitSystem ON_UnitSystem::CreateCustomUnitSystem(
const wchar_t* custom_unit_name,
double meters_per_custom_unit
)
{
ON_UnitSystem custom_unit_system = ON_UnitSystem::Unset;
custom_unit_system.SetCustomUnitSystem(custom_unit_name, meters_per_custom_unit);
return custom_unit_system;
}
void ON_UnitSystem::SetCustomUnitSystem(
const wchar_t* custom_unit_name,
double meters_per_custom_unit
)
{
ON_wString local_str(custom_unit_name);
local_str.TrimLeftAndRight();
m_unit_system = ON::LengthUnitSystem::CustomUnits;
m_custom_unit_name = local_str;
if ( ON_IsValidPositiveNumber(meters_per_custom_unit) )
{
m_meters_per_custom_unit = meters_per_custom_unit;
}
else
{
ON_ERROR("Invalid meters_per_custom_unit parameter");
m_meters_per_custom_unit = 1.0; // must be > 0.0 and < ON_UNSET_POSITIVE_VALUE
}
}
void ON_UnitSystem::SetCustomUnitSystemName(
const wchar_t* custom_unit_name
)
{
const bool bIsCustomUnitSystem = (ON::LengthUnitSystem::CustomUnits == m_unit_system);
ON_wString local_name(custom_unit_name);
local_name.TrimLeftAndRight();
if (local_name.IsNotEmpty() || bIsCustomUnitSystem)
{
const double meters_per_custom_unit
= bIsCustomUnitSystem
? m_meters_per_custom_unit
: 1.0;
SetCustomUnitSystem(local_name, meters_per_custom_unit);
}
}
void ON_UnitSystem::SetCustomUnitSystemScale(
double meters_per_custom_unit
)
{
if (ON_IsValidPositiveNumber(meters_per_custom_unit))
{
const bool bIsCustomUnitSystem = (ON::LengthUnitSystem::CustomUnits == m_unit_system);
if (false == (meters_per_custom_unit == m_meters_per_custom_unit) || bIsCustomUnitSystem)
{
const ON_wString unit_system_name
= (ON::LengthUnitSystem::CustomUnits == m_unit_system)
? m_custom_unit_name
: ON_wString::EmptyString;
SetCustomUnitSystem(unit_system_name, meters_per_custom_unit);
}
}
}
double ON_UnitSystem::MetersPerUnit(
double unset_return_value
) const
{
switch (m_unit_system)
{
case ON::LengthUnitSystem::None:
return 1.0;
break;
case ON::LengthUnitSystem::CustomUnits:
return m_meters_per_custom_unit;
break;
case ON::LengthUnitSystem::Unset:
return unset_return_value;
break;
default:
break;
}
return ON::UnitScale(m_unit_system, ON::LengthUnitSystem::Meters);
}
double ON_UnitSystem::MillimetersPerUnit(
double unset_return_value
) const
{
switch (m_unit_system)
{
case ON::LengthUnitSystem::None:
return 1.0;
break;
case ON::LengthUnitSystem::CustomUnits:
return 1000.0*m_meters_per_custom_unit;
break;
case ON::LengthUnitSystem::Unset:
return unset_return_value;
break;
default:
break;
}
return ON::UnitScale(m_unit_system, ON::LengthUnitSystem::Millimeters);
}
double ON_UnitSystem::MetersPerUnit() const
{
// NOTE WELL:
// https://mcneel.myjetbrains.com/youtrack/issue/RH-60700
// For standard units, this function returns the WRONG value (inverse of the correct value).
// The reason is the Rhino 6 VRay plug-in assumes the incorrect value is returned
// and V6 VRay does not work correctly in Rhino 7 if the correct value is returned.
// After some discussion (see the bug above), we will leave the inverse bug in
// ON_UnitSystem::MetersPerUnit(), deprecate ON_UnitSystem::MetersPerUnit(),
// and add a new function that returns the correct answer.
if (ON::LengthUnitSystem::CustomUnits == m_unit_system)
{
// correct answer for custom units - V6 behavior.
return m_meters_per_custom_unit; //
}
// For standard units, the inverse of the correct answer is returned
// to preserve V6 bug so VRay works in Rhino 7.
return 1.0/ON_UnitSystem::MetersPerUnit(ON_DBL_QNAN);
}
ON::LengthUnitSystem ON_UnitSystem::UnitSystem() const
{
return m_unit_system;
}
static void ON_Internal_InitUnitSystemName(
const wchar_t* name,
ON_wString& local_storage
)
{
if (local_storage.IsEmpty())
local_storage = name;
}
const ON_wString& ON_UnitSystem::UnitSystemName() const
{
switch (m_unit_system)
{
case ON::LengthUnitSystem::None:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"no units",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Angstroms:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"angstroms",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Nanometers:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"nanometers",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Microns:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"microns",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Millimeters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"millimeters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Decimeters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"decimeters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Centimeters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"centimeters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Meters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"meters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Dekameters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"dekameters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Hectometers:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"hectometers",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Kilometers:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"kilometers",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Megameters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"megameters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Gigameters:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"gigameters",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Microinches:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"microinches",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Mils:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"mils",s_name);// (= 0.001 inches)";
return s_name;
}
break;
case ON::LengthUnitSystem::Inches:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"inches",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Feet:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"feet",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Yards:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"yards",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Miles:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"miles",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::PrinterPoints:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"points",s_name); // (1/72 inch)";
return s_name;
}
break;
case ON::LengthUnitSystem::PrinterPicas:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"picas",s_name); // (1/6 inch)";
return s_name;
}
break;
case ON::LengthUnitSystem::NauticalMiles:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"nautical miles",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::AstronomicalUnits:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"astronomical units",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::LightYears:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"light years",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::Parsecs:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"parsecs",s_name);
return s_name;
}
break;
case ON::LengthUnitSystem::CustomUnits:
if (m_custom_unit_name.IsEmpty())
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"custom units", s_name);
return s_name;
}
return m_custom_unit_name;
break;
case ON::LengthUnitSystem::Unset:
{
static ON_wString s_name;
ON_Internal_InitUnitSystemName(L"unset", s_name);
return s_name;
}
break;
}
return ON_wString::EmptyString;
}
bool ON_UnitSystem::Read( ON_BinaryArchive& file )
{
*this = ON_UnitSystem::None;
int major_version = 0;
int minor_version = 0;
if ( !file.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version) )
return false;
ON::LengthUnitSystem us = ON::LengthUnitSystem::None;
double meters_per_unit = 0.0;
ON_wString custom_unit_name;
bool rc = false;
for (;;)
{
if (1 != major_version)
break;
unsigned int i = ON_UNSET_UINT_INDEX;
if (false == file.ReadInt(&i))
break;
us = ON::LengthUnitSystemFromUnsigned(i);
if (false == file.ReadDouble(&meters_per_unit))
break;
if (false == file.ReadString(custom_unit_name))
break;
rc = true;
break;
}
if (!file.EndRead3dmChunk())
{
rc = false;
}
else
{
if (ON::LengthUnitSystem::CustomUnits == us)
{
m_unit_system = us;
m_custom_unit_name = custom_unit_name;
m_meters_per_custom_unit = meters_per_unit;
}
else
{
*this = ON_UnitSystem(us);
}
}
return rc;
}
bool ON_UnitSystem::Write( ON_BinaryArchive& file ) const
{
if ( !file.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0) )
return false;
// values saved in the file
//no_unit_system = 0,
//microns = 1, // 1.0e-6 meters
//millimeters = 2, // 1.0e-3 meters
//centimeters = 3, // 1.0e-2 meters
//meters = 4,
//kilometers = 5, // 1.0e+3 meters
//microinches = 6, // 1.0e-6 inches
//mils = 7, // 1.0e-3 inches
//inches = 8, // 0.0254 meters
//feet = 9, // 12 inches
//miles = 10, // 63360 inches
//custom_unit_system = 11, // x meters with x defined in ON_3dmUnitsAndTolerances.m_custom_unit_scale
bool rc = false;
for (;;)
{
if (!file.WriteInt(static_cast<unsigned int>(m_unit_system)))
break;
if (!file.WriteDouble(ON::LengthUnitSystem::CustomUnits == m_unit_system ? m_meters_per_custom_unit : ON::UnitScale(m_unit_system, ON::LengthUnitSystem::Meters)))
break;
if (!file.WriteString(ON::LengthUnitSystem::CustomUnits == m_unit_system ? m_custom_unit_name : ON_wString::EmptyString))
break;
rc = true;
break;
}
if ( !file.EndWrite3dmChunk() )
rc = false;
return rc;
}
const ON_wString ON_UnitSystem::ToString() const
{
ON_wString str(UnitSystemName());
if (ON::LengthUnitSystem::CustomUnits == m_unit_system)
{
ON_wString meters_per_unit;
meters_per_unit.Format(L" (= %g meters )", m_meters_per_custom_unit);
str += meters_per_unit;
}
return str;
}
void ON_UnitSystem::Dump( ON_TextLog& dump ) const
{
const ON_wString sUnitSystem(ToString());
dump.Print("Unit system: %ls\n",static_cast<const wchar_t*>(sUnitSystem));
}
bool ON_3dmUnitsAndTolerances::operator==(const ON_3dmUnitsAndTolerances& other) const
{
bool equal = m_unit_system == other.m_unit_system
&& m_absolute_tolerance == other.m_absolute_tolerance
&& m_angle_tolerance == other.m_angle_tolerance
&& m_relative_tolerance == other.m_relative_tolerance
&& m_distance_display_mode == other.m_distance_display_mode
&& m_distance_display_precision == other.m_distance_display_precision;
return equal;
}
bool ON_3dmUnitsAndTolerances::operator!=(const ON_3dmUnitsAndTolerances& other) const
{
return !(*this == other);
}
bool ON_3dmUnitsAndTolerances::Write( ON_BinaryArchive& file ) const
{
const int version = 102;
unsigned int i;
// version 100 ON_3dmUnitsAndTolerances settings
bool rc = file.WriteInt( version );
i = static_cast<unsigned int>(m_unit_system.UnitSystem());
if ( rc ) rc = file.WriteInt( i );
if ( rc ) rc = file.WriteDouble( m_absolute_tolerance );
if ( rc ) rc = file.WriteDouble( m_angle_tolerance );
if ( rc ) rc = file.WriteDouble( m_relative_tolerance );
// added in version 101
i = static_cast<unsigned int>(m_distance_display_mode);
if ( rc ) rc = file.WriteInt( i );
i = m_distance_display_precision;
if ( i > 20 )
{
ON_ERROR("ON_3dmUnitsAndTolerances::Write() - m_distance_display_precision out of range.");
i = 3;
}
if ( rc ) rc = file.WriteInt( i );
// added in version 102
if ( rc ) rc = file.WriteDouble( m_unit_system.MetersPerUnit(ON_DBL_QNAN));
if ( rc ) rc = file.WriteString( (ON::LengthUnitSystem::CustomUnits == m_unit_system.UnitSystem() ? m_unit_system.UnitSystemName() : ON_wString::EmptyString) );
return rc;
}
bool ON_3dmUnitsAndTolerances::Read( ON_BinaryArchive& file )
{
*this = ON_3dmUnitsAndTolerances::Millimeters;
int version = 0;
bool rc = file.ReadInt( &version );
if ( rc && version >= 100 && version < 200 )
{
ON::LengthUnitSystem us = ON::LengthUnitSystem::None;
double meters_per_unit = 1.0;
ON_wString custom_unit_name;
int i = ON_UNSET_UINT_INDEX;
rc = file.ReadInt( &i );
if ( rc )
us = ON::LengthUnitSystemFromUnsigned(i);
if ( rc ) rc = file.ReadDouble( &m_absolute_tolerance );
if ( rc ) rc = file.ReadDouble( &m_angle_tolerance );
if ( rc ) rc = file.ReadDouble( &m_relative_tolerance );
if ( version >= 101 )
{
unsigned int dm = static_cast<unsigned int>(ON::OBSOLETE_DistanceDisplayMode::Decimal);
if ( rc ) rc = file.ReadInt( &dm );
if ( rc ) m_distance_display_mode = ON::DistanceDisplayModeFromUnsigned(dm);
if ( rc ) rc = file.ReadInt( &m_distance_display_precision );
if ( m_distance_display_precision < 0 || m_distance_display_precision > 20 )
m_distance_display_precision = 3; // some beta files had bogus values stored in file
if ( version >= 102 )
{
if ( rc ) rc = file.ReadDouble( &meters_per_unit );
if ( rc ) rc = file.ReadString( custom_unit_name );
}
}
if ( ON::LengthUnitSystem::CustomUnits == us )
m_unit_system.SetCustomUnitSystem(custom_unit_name,meters_per_unit);
else
m_unit_system.SetUnitSystem(us);
}
return rc;
}
void ON_3dmUnitsAndTolerances::Dump( ON_TextLog& dump) const
{
m_unit_system.Dump(dump);
dump.Print("Absolute tolerance: %g\n",m_absolute_tolerance);
dump.Print("Angle tolerance: %g\n",m_angle_tolerance);
}
double ON_3dmUnitsAndTolerances::Scale( ON::LengthUnitSystem us ) const
{
// Example: If us = meters and m_unit_system = centimeters,
// then Scale() returns 100.
return ON::UnitScale( us, m_unit_system );
}
bool ON_3dmUnitsAndTolerances::IsValid() const
{
for (;;)
{
// April 17, 2023 - Tim
// Changed upper limit to 8 so we can use the display precision
// stuff found in the annotation code for V8
// Fixes https://mcneel.myjetbrains.com/youtrack/issue/RH-74242
if (!(m_distance_display_precision >= 0 && m_distance_display_precision <= 8))
break;
if (!((int)m_distance_display_mode >= 0 && (int)m_distance_display_mode <= 3))
break;
if (!TolerancesAreValid())
break;
return true;
}
return false;
}
double ON_3dmUnitsAndTolerances::AbsoluteTolerance() const
{
return m_absolute_tolerance;
}
void ON_3dmUnitsAndTolerances::SetAbsoluteTolerance(double absolute_tolerance)
{
if (absolute_tolerance > 0.0)
m_absolute_tolerance = absolute_tolerance;
}
double ON_3dmUnitsAndTolerances::AngleTolerance() const
{
return m_angle_tolerance;
}
void ON_3dmUnitsAndTolerances::SetAngleTolerance(double angle_tolerance)
{
if (angle_tolerance > 0.0 && angle_tolerance <= ON_PI)
m_angle_tolerance = angle_tolerance;
}
double ON_3dmUnitsAndTolerances::RelativeTolerance() const
{
return m_relative_tolerance;
}
void ON_3dmUnitsAndTolerances::SetRelativeTolerance(double relative_tolerance)
{
if (relative_tolerance > 0.0 && relative_tolerance < 1.0)
m_relative_tolerance = relative_tolerance;
}
ON::OBSOLETE_DistanceDisplayMode ON_3dmUnitsAndTolerances::DistanceDisplayMode() const
{
return m_distance_display_mode;
}
void ON_3dmUnitsAndTolerances::SetDistanceDisplayMode(ON::OBSOLETE_DistanceDisplayMode distance_display_mode)
{
m_distance_display_mode = distance_display_mode;
}
int ON_3dmUnitsAndTolerances::DistanceDisplayPrecision() const
{
return m_distance_display_precision;
}
void ON_3dmUnitsAndTolerances::SetDistanceDisplayPrecision(int distance_display_precision)
{
// April 17, 2023 - Tim
// Changed upper limit to 8 so we can use the display precision
// stuff found in the annotation code for V8
// Fixes https://mcneel.myjetbrains.com/youtrack/issue/RH-74242
if (distance_display_precision >= 0 && distance_display_precision <= 8)
m_distance_display_precision = distance_display_precision;
}
bool ON_3dmUnitsAndTolerances::TolerancesAreValid() const
{
for (;;)
{
if (!(m_absolute_tolerance > 0.0))
break;
if (!(m_angle_tolerance > 0.0 && m_angle_tolerance <= ON_PI))
break;
if (!(m_relative_tolerance > 0.0 && m_relative_tolerance < 1.0))
break;
return true;
}
return false;
}
unsigned int ON_3dmUnitsAndTolerances::SetInvalidTolerancesToDefaultValues()
{
unsigned int rc = 0;
if ( !(m_absolute_tolerance > 0.0) )
{
rc |= 1;
// Do NOT apply scaling from mm to current units.
m_absolute_tolerance = ON_3dmUnitsAndTolerances::Millimeters.m_absolute_tolerance;
}
if ( !(m_angle_tolerance > 0.0 && m_angle_tolerance <= ON_PI) )
{
rc |= 2;
m_angle_tolerance = ON_3dmUnitsAndTolerances::Millimeters.m_angle_tolerance;
}
if ( !( m_relative_tolerance > 0.0 && m_relative_tolerance < 1.0) )
{
rc |= 4;
m_relative_tolerance = ON_3dmUnitsAndTolerances::Millimeters.m_relative_tolerance;
}
return rc;
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmRenderSettings
//
static const wchar_t* XMLPathBack360(void) // Not used for 'override'.
{
return ON_RDK_DOCUMENT ON_XML_SLASH ON_RDK_CURRENT_CONTENT;
}
static const wchar_t* XMLPathReflRefr(void)
{
return ON_RDK_DOCUMENT ON_XML_SLASH ON_RDK_SETTINGS ON_XML_SLASH ON_RDK_RENDERING;
}
static const wchar_t* XMLPathSkylight(void)
{
return ON_RDK_DOCUMENT ON_XML_SLASH ON_RDK_SETTINGS ON_XML_SLASH ON_RDK_SUN;
}
ON_EnvironmentsImpl::ON_EnvironmentsImpl(const ON_EnvironmentsImpl& ei)
{
operator = (ei);
}
ON_EnvironmentsImpl& ON_EnvironmentsImpl::operator = (const ON_EnvironmentsImpl& ep)
{
if (this != &ep)
{
SetBackgroundRenderEnvironmentId (ep.BackgroundRenderEnvironmentId());
SetSkylightingRenderEnvironmentOverride(ep.SkylightingRenderEnvironmentOverride());
SetSkylightingRenderEnvironmentId (ep.SkylightingRenderEnvironmentId());
SetReflectionRenderEnvironmentOverride (ep.ReflectionRenderEnvironmentOverride());
SetReflectionRenderEnvironmentId (ep.ReflectionRenderEnvironmentId());
}
return *this;
}
bool ON_EnvironmentsImpl::operator == (const ON_EnvironmentsImpl& ep)
{
if (BackgroundRenderEnvironmentId() != ep.BackgroundRenderEnvironmentId()) return false;
if (SkylightingRenderEnvironmentOverride() != ep.SkylightingRenderEnvironmentOverride()) return false;
if (SkylightingRenderEnvironmentId() != ep.SkylightingRenderEnvironmentId()) return false;
if (ReflectionRenderEnvironmentOverride() != ep.ReflectionRenderEnvironmentOverride()) return false;
if (ReflectionRenderEnvironmentId() != ep.ReflectionRenderEnvironmentId()) return false;
return true;
}
ON_UUID ON_EnvironmentsImpl::BackgroundRenderEnvironmentId(void) const
{
return GetParameter_NoType(XMLPathBack360(), ON_RDK_BACKGROUND_ENVIRONMENT, L"uuid", ON_nil_uuid).AsUuid();
}
void ON_EnvironmentsImpl::SetBackgroundRenderEnvironmentId(const ON_UUID& id)
{
SetParameter_NoType(XMLPathBack360(), ON_RDK_BACKGROUND_ENVIRONMENT, id);
}
bool ON_EnvironmentsImpl::SkylightingRenderEnvironmentOverride(void) const
{
return GetParameter(XMLPathSkylight(), ON_RDK_SUN_SKYLIGHT_ENVIRONMENT_OVERRIDE, false);
}
void ON_EnvironmentsImpl::SetSkylightingRenderEnvironmentOverride(bool on)
{
SetParameter(XMLPathSkylight(), ON_RDK_SUN_SKYLIGHT_ENVIRONMENT_OVERRIDE, on);
}
ON_UUID ON_EnvironmentsImpl::SkylightingRenderEnvironmentId(void) const
{
return GetParameter_NoType(XMLPathSkylight(), ON_RDK_SUN_SKYLIGHT_ENVIRONMENT_ID, L"uuid", ON_nil_uuid).AsUuid();
}
void ON_EnvironmentsImpl::SetSkylightingRenderEnvironmentId(const ON_UUID& id)
{
SetParameter_NoType(XMLPathSkylight(), ON_RDK_SUN_SKYLIGHT_ENVIRONMENT_ID, id);
}
bool ON_EnvironmentsImpl::ReflectionRenderEnvironmentOverride(void) const
{
return GetParameter(XMLPathReflRefr(), ON_RDK_CUSTOM_REFLECTIVE_ENVIRONMENT_ON, false);
}
void ON_EnvironmentsImpl::SetReflectionRenderEnvironmentOverride(bool on)
{
SetParameter(XMLPathReflRefr(), ON_RDK_CUSTOM_REFLECTIVE_ENVIRONMENT_ON, on);
}
ON_UUID ON_EnvironmentsImpl::ReflectionRenderEnvironmentId(void) const
{
return GetParameter_NoType(XMLPathReflRefr(), ON_RDK_CUSTOM_REFLECTIVE_ENVIRONMENT, L"uuid", ON_nil_uuid).AsUuid();
}
void ON_EnvironmentsImpl::SetReflectionRenderEnvironmentId(const ON_UUID& id)
{
SetParameter_NoType(XMLPathReflRefr(), ON_RDK_CUSTOM_REFLECTIVE_ENVIRONMENT, id);
}
ON_OBJECT_IMPLEMENT(ON_3dmRenderSettings, ON_Object, "58A5953A-57C5-4FD3-84F5-7D4240478D15");
ON_DECL ON_XMLNode& ON_GetRdkDocNode(const ON_3dmRenderSettings& rs)
{
return ON_3dmRenderSettingsPrivate::Get(rs)._rdk_document_data;
}
ON_DECL ON__UINT_PTR ON_GetDocumentObjectSpecializer(const ON_3dmRenderSettings& rs)
{
return ON__UINT_PTR(&ON_3dmRenderSettingsPrivate::Get(rs));
}
ON_DECL void ON_SpecializeDocumentObjects(ON__UINT_PTR specializer,
ON_GroundPlane& gp, ON_LinearWorkflow& lw, ON_Sun& sun)
{
auto* priv = reinterpret_cast<ON_3dmRenderSettingsPrivate*>(specializer);
ON_ASSERT(nullptr != priv);
if (nullptr != priv)
{
priv->SpecializeGroundPlane(gp);
priv->SpecializeLinearWorkflow(lw);
priv->SpecializeSun(sun);
}
}
ON_3dmRenderSettingsPrivate::ON_3dmRenderSettingsPrivate()
{
CreateDocumentObjects();
// 26th January 2023 John Croudy, https://mcneel.myjetbrains.com/youtrack/issue/RH-71396
// Populate the RDK document data with defaults. The previous fix for this did it in RdkDocNode()
// which was the wrong place. We have to do it even if the RDK isn't being used.
ON_RdkDocumentDefaults dd(ON::VersionMajor(), ON_RdkDocumentDefaults::ValueSets::All);
dd.CopyDefaultsTo(_rdk_document_data);
}
ON_3dmRenderSettingsPrivate::ON_3dmRenderSettingsPrivate(const ON_3dmRenderSettingsPrivate& p)
{
CreateDocumentObjects();
operator = (p);
}
ON_3dmRenderSettingsPrivate::~ON_3dmRenderSettingsPrivate()
{
delete _ground_plane;
delete _dithering;
delete _safe_frame;
delete _skylight;
delete _linear_workflow;
delete _render_channels;
delete _sun;
delete _environments;
delete _post_effects;
}
const ON_3dmRenderSettingsPrivate& ON_3dmRenderSettingsPrivate::operator = (const ON_3dmRenderSettingsPrivate& p)
{
if (this != &p)