forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opennurbs_defines.cpp
2586 lines (2332 loc) · 73.7 KB
/
opennurbs_defines.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"
#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
#include "opennurbs_internal_defines.h"
// {EA2EFFD2-C9A9-4cb1-BE15-D2F46290F1A1}
//const ON_UUID ON_MaterialRef::material_from_layer =
//{ 0xea2effd2, 0xc9a9, 0x4cb1, { 0xbe, 0x15, 0xd2, 0xf4, 0x62, 0x90, 0xf1, 0xa1 } };
// {86EDFDE4-8AAF-4bcd-AB7C-F7111978D7FE}
//const ON_UUID ON_MaterialRef::material_from_parent =
//{ 0x86edfde4, 0x8aaf, 0x4bcd, { 0xab, 0x7c, 0xf7, 0x11, 0x19, 0x78, 0xd7, 0xfe } };
// on_stricmp() is a wrapper for case insensitive string compare
// and calls one of _stricmp(), stricmp(), or strcasecmp()
// depending on OS.
int on_stricmp(const char * s1, const char * s2)
{
#if defined(ON_RUNTIME_WIN)
//return stricmp(s1,s2);
return _stricmp(s1,s2);
#else
return strcasecmp(s1,s2);
#endif
}
// on_strupr() calls _strupr() or strupr() depending on OS
char* on_strupr(char* s)
{
#if defined(ON_RUNTIME_WIN)
return _strupr(s); // ANSI name
#else
if (s)
{
while (*s)
{
*s = toupper(*s);
s++;
}
}
return s;
#endif
}
// on_strlwr() calls _strlwr() or strlwr() depending on OS
char* on_strlwr(char* s)
{
#if defined(ON_RUNTIME_WIN)
return _strlwr(s); // ANSI name
#else
if (s) {
while (*s)
{
*s = tolower(*s);
s++;
}
}
return s;
#endif
}
// on_strrev() calls _strrev() or strrev() depending on OS
char* on_strrev(char* s)
{
#if defined(ON_RUNTIME_WIN)
return _strrev(s); // ANSI name
#else
int i, j;
char c;
for ( i = 0, j = ((int)strlen(s))-1; i < j; i++, j-- ) {
c = s[i];
s[i] = s[j];
s[j] = c;
}
return s;
#endif
}
#if defined(ON_COMPILER_MSC)
// Disable the MSC /W4 unreachable code warning for the call to on__hack__wcsicmp()
#pragma ON_PRAGMA_WARNING_PUSH
#pragma ON_PRAGMA_WARNING_DISABLE_MSC( 4702 )
#endif
int on_wcsicmp( const wchar_t* s1, const wchar_t* s2)
{
// handle nullptr strings consistently and without crashing.
return ON_wString::Compare(
s1,
s2,
ON_Locale::InvariantCulture,
true
);
}
#if defined(ON_COMPILER_MSC)
#pragma ON_PRAGMA_WARNING_POP
#endif
wchar_t* on_wcsupr(wchar_t* s)
{
const int length = ON_wString::Length(s);
if ( length < 0 )
return nullptr;
ON_wString::MapStringOrdinal(ON_StringMapOrdinalType::UpperOrdinal,s,length,s,length+1);
return s;
}
// on_wcslwr() calls _wcslwr() or wcslwr() depending on OS
wchar_t* on_wcslwr(wchar_t* s)
{
const int length = ON_wString::Length(s);
if ( length < 0 )
return nullptr;
ON_wString::MapStringOrdinal(ON_StringMapOrdinalType::LowerOrdinal,s,length,s,length+1);
return s;
}
wchar_t* on_wcsrev(wchar_t* s)
{
return ON_wString::Reverse(s,-1);
}
int on_WideCharToMultiByte(
const wchar_t* lpWideCharStr,
int cchWideChar,
char* lpMultiByteStr,
int cchMultiByte
)
{
// 14 March 2011 Dale Lear
// It turns out that Windows WideCharToMultiByte does correctly
// convert UTF-16 to UTF-8 in Windows 7 when the code page
// is CP_ACP and calls with CP_UTF8 sometimes fail to do
// any conversion. So, I wrote ON_ConvertWideCharToUTF8()
// and opennurbs will use ON_ConvertWideCharToUTF8 to get
// consistent results on all platforms.
unsigned int error_status = 0;
unsigned int error_mask = 0xFFFFFFFF;
ON__UINT32 error_code_point = 0xFFFD;
const wchar_t* p1 = 0;
int count = ON_ConvertWideCharToUTF8(false,lpWideCharStr,cchWideChar,lpMultiByteStr,cchMultiByte,
&error_status,error_mask,error_code_point,&p1);
if ( 0 != error_status )
{
ON_ERROR("Error converting UTF-16 encoded wchar_t string to UTF-8 encoded char string.");
}
return count;
}
int on_MultiByteToWideChar(
const char* lpMultiByteStr,
int cchMultiByte,
wchar_t* lpWideCharStr,
int cchWideChar
)
{
// 14 March 2011 Dale Lear
// It turns out that Windows WideCharToMultiByte does not correctly
// convert UTF-8 to UTF-16 in Windows 7 when the code page
// is CP_ACP and calls with CP_UTF8 sometimes fail to do
// any conversion. So, I wrote ON_ConvertUTF8ToWideChar()
// and opennurbs will use ON_ConvertUTF8ToWideChar to get
// consistent results on all platforms.
unsigned int error_status = 0;
unsigned int error_mask = 0xFFFFFFFF;
ON__UINT32 error_code_point = 0xFFFD;
const char* p1 = 0;
int count = ON_ConvertUTF8ToWideChar(false,lpMultiByteStr,cchMultiByte,lpWideCharStr,cchWideChar,
&error_status,error_mask,error_code_point,&p1);
if ( 0 != error_status )
{
ON_ERROR("Error converting UTF-8 encoded char string to UTF-16 encoded wchar_t string.");
}
return count;
}
void on_splitpath(
const char* path,
const char** volume,
const char** dir,
const char** fname,
const char** ext
)
{
// The "const char* path" parameter is a UTF-8 encoded string.
// Since the unicode code point values for the characters we
// are searching for ( '/' '\' '.' ':' A-Z a-z) are all > 0
// and < 128, we can simply check for an array element having
// the character value and not have to worry about dealing
// with UTF-8 continuation values (>= 128).
const char slash1 = '/';
const char slash2 = '\\'; // do this even with the os is unix because
// we might be parsing a file name saved
// in Windows.
const char* f;
const char* e;
const char* s;
const char* s1;
if ( 0 != volume )
*volume = 0;
if ( 0 != dir )
*dir = 0;
if ( 0 != fname )
*fname = 0;
if ( 0 != ext )
*ext = 0;
if ( 0 != path && 0 != *path )
{
// deal with Windows' volume letter (even when the os is unix)
if ( ':' == path[1] )
{
if ( (path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z') )
{
if ( volume )
*volume = path;
path += 2;
if ( 0 == *path )
return;
}
}
else if (
ON_String::Backslash == path[0]
&& ON_String::Backslash == path[1]
&&( (path[2] >= 'A' && path[2] <= 'Z')
|| (path[2] >= 'a' && path[2] <= 'z')
|| (path[2] >= '0' && path[2] <= '9')
)
)
{
// deal with Windows' UNC hostnames like \\hostname (even when the os is unix)
int i = 3;
while (
i < 18
&& ((path[i] >= 'A' && path[i] <= 'Z')
|| (path[i] >= 'a' && path[i] <= 'z')
|| (path[i] >= '0' && path[i] <= '9')
|| '-' == path[i] || '_' == path[i]
))
{
i++;
}
if (i < 18 && (ON_String::Backslash == path[i] || ON_String::Slash == path[i]))
{
if ( volume )
*volume = path;
path += i;
}
}
}
if ( 0 != path && 0 != *path )
{
e = 0;
f = 0;
s1 = path;
while ( 0 != *s1 )
s1++;
s = (s1 > path) ? s1 - 1 : path;
while ( s > path && '.' != *s && slash1 != *s && slash2 != *s )
s--;
if ( '.' == *s && 0 != s[1] )
{
// extensions must have something after the dot.
e = s;
s1 = e;
s--;
}
while ( s > path && slash1 != *s && slash2 != *s )
s--;
if ( s >= path && s < s1 )
{
if (slash1 == *s || slash2 == *s )
{
if ( s+1 < s1 )
f = s+1;
}
else if ( s == path )
{
f = s;
}
}
if ( 0 == f )
{
// must have a non-empty filename in order to have and "extension"
f = e;
e = 0;
}
if ( 0 != dir && (0 == f || path < f) )
*dir = path;
if ( 0 != f && 0 != fname )
*fname = f;
if ( 0 != e && 0 != ext )
*ext = e;
}
}
void on_wsplitpath(
const wchar_t* path,
const wchar_t** volume,
const wchar_t** dir,
const wchar_t** fname,
const wchar_t** ext
)
{
// The "const wchar_t* path" parameter is a UTF-8, UTF-16 or UTF-32
// encoded string. Since the unicode code point values for the
// characters we are searching for ( '/' '\' '.' ':' A-Z a-z) are
// all > 0 and < 128, we can simply check for an array element
// having the character value and not have to worry about dealing
// with UTF-16 surrogate pair values (0xD800-0xDBFF and DC00-DFFF)
// and UTF-8 continuation values (>= 128).
const wchar_t slash1 = '/';
const wchar_t slash2 = '\\'; // do this even with the os is unix because
// we might be parsing a file name saved
// in Windows.
const wchar_t* f;
const wchar_t* e;
const wchar_t* s;
const wchar_t* s1;
if ( 0 != volume )
*volume = 0;
if ( 0 != dir )
*dir = 0;
if ( 0 != fname )
*fname = 0;
if ( 0 != ext )
*ext = 0;
if ( 0 != path && 0 != *path )
{
// deal with Windows' volume letter (even when the os is unix)
if ( ':' == path[1] )
{
if ( (path[0] >= 'A' && path[0] <= 'Z') || (path[0] >= 'a' && path[0] <= 'z') )
{
if ( volume )
*volume = path;
path += 2;
if ( 0 == *path )
return;
}
}
else if (
ON_wString::Backslash == path[0]
&& ON_wString::Backslash == path[1]
&&( (path[2] >= 'A' && path[2] <= 'Z')
|| (path[2] >= 'a' && path[2] <= 'z')
|| (path[2] >= '0' && path[2] <= '9')
)
)
{
// deal with Windows' UNC hostnames like \\hostname (even when the os is unix)
int i = 3;
while (
i < 18
&& ((path[i] >= 'A' && path[i] <= 'Z')
|| (path[i] >= 'a' && path[i] <= 'z')
|| (path[i] >= '0' && path[i] <= '9')
|| '-' == path[i] || '_' == path[i]
))
{
i++;
}
if (i < 18 && (ON_wString::Backslash == path[i] || ON_wString::Slash == path[i]))
{
if ( volume )
*volume = path;
path += i;
}
}
}
if ( 0 != path && 0 != *path )
{
e = 0;
f = 0;
s1 = path;
while ( 0 != *s1 )
s1++;
s = (s1 > path) ? s1 - 1 : path;
while ( s > path && '.' != *s && slash1 != *s && slash2 != *s )
s--;
if ( '.' == *s && 0 != s[1] )
{
// extensions must have something after the dot.
e = s;
s1 = e;
s--;
}
while ( s > path && slash1 != *s && slash2 != *s )
s--;
if ( s >= path && s < s1 )
{
if (slash1 == *s || slash2 == *s )
{
if ( s+1 < s1 )
f = s+1;
}
else if ( s == path )
{
f = s;
}
}
if ( 0 == f )
{
// must have a non-empty filename in order to have and "extension"
f = e;
e = 0;
}
if ( 0 != dir && (0 == f || path < f) )
*dir = path;
if ( 0 != f && 0 != fname )
*fname = f;
if ( 0 != e && 0 != ext )
*ext = e;
}
}
FILE* ON::OpenFile( // like fopen() - needed when OpenNURBS is used as a DLL
const char* filename, // file name
const char* filemode // file mode
)
{
return ON_FileStream::Open(filename,filemode);
}
FILE* ON::OpenFile( // like fopen() - needed when OpenNURBS is used as a DLL
const wchar_t* filename, // file name
const wchar_t* filemode // file mode
)
{
return ON_FileStream::Open(filename,filemode);
}
int ON::CloseFile( // like fclose() - needed when OpenNURBS is used as a DLL
FILE* fp // pointer returned by OpenFile()
)
{
return ON_FileStream::Close(fp);
}
int ON::CloseAllFiles()
{
// returns number of files closed or EOF for error
#if defined(ON_COMPILER_MSC)
return _fcloseall(); // ANSI C name
#elif defined(ON_COMPILER_CLANG)
//#error TODO - call clang fcloseall()
//fcloseall is not supported on OS X
return EOF;
#elif defined(ON_COMPILER_GNU)
fcloseall();
#else
// I can't find an fcloseall() or _fcloseall() in
// gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
return EOF;
#endif
}
ON::active_space ON::ActiveSpace(int i)
{
ON::active_space as;
switch(i)
{
case no_space: as = no_space; break;
case model_space: as = model_space; break;
case page_space: as = page_space; break;
default: as = no_space; break;
}
return as;
}
ON_INTERNAL_OBSOLETE::V5_TextDisplayMode ON_INTERNAL_OBSOLETE::V5TextDisplayModeFromUnsigned(
unsigned int text_display_mode_as_unsigned
)
{
switch (text_display_mode_as_unsigned)
{
ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_TextDisplayMode::kNormal);
ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_TextDisplayMode::kHorizontalToScreen);
ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_TextDisplayMode::kAboveLine);
ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_TextDisplayMode::kInLine);
ON_ENUM_FROM_UNSIGNED_CASE(ON_INTERNAL_OBSOLETE::V5_TextDisplayMode::kHorizontalInCplane);
}
ON_ERROR("Invalid text_display_mode_as_unsigned value");
return (ON_INTERNAL_OBSOLETE::V5_TextDisplayMode::kAboveLine);
}
ON::RuntimeEnvironment ON::RuntimeEnvironmentFromUnsigned(
unsigned int runtime_environment_as_unsigned
)
{
switch (runtime_environment_as_unsigned)
{
ON_ENUM_FROM_UNSIGNED_CASE(ON::RuntimeEnvironment::Unset);
ON_ENUM_FROM_UNSIGNED_CASE(ON::RuntimeEnvironment::None);
ON_ENUM_FROM_UNSIGNED_CASE(ON::RuntimeEnvironment::Windows);
ON_ENUM_FROM_UNSIGNED_CASE(ON::RuntimeEnvironment::Apple);
ON_ENUM_FROM_UNSIGNED_CASE(ON::RuntimeEnvironment::Android);
ON_ENUM_FROM_UNSIGNED_CASE(ON::RuntimeEnvironment::Linux);
}
ON_ERROR("Invalid runtime_environment_as_unsigned parameter value.");
return (ON::RuntimeEnvironment::Unset);
}
ON::RuntimeEnvironment ON::CurrentRuntimeEnvironment()
{
#if defined(ON_RUNTIME_WIN)
return ON::RuntimeEnvironment::Windows;
#elif defined (ON_RUNTIME_APPLE)
return ON::RuntimeEnvironment::Apple;
#elif defined (ON_RUNTIME_ANDROID)
return ON::RuntimeEnvironment::Android;
#elif defined (ON_RUNTIME_LINUX)
return ON::RuntimeEnvironment::Linux;
#else
ON_ERROR("ON_RUNTIME_... not defined.");
return ON::RuntimeEnvironment::Unset;
#endif
}
ON::ReadFileResult ON::ReadFileResultFromUnsigned(
unsigned int read_file_result_as_unsigned
)
{
switch (read_file_result_as_unsigned)
{
ON_ENUM_FROM_UNSIGNED_CASE(ON::ReadFileResult::Unset);
ON_ENUM_FROM_UNSIGNED_CASE(ON::ReadFileResult::Completed);
ON_ENUM_FROM_UNSIGNED_CASE(ON::ReadFileResult::CompletedWithErrors);
ON_ENUM_FROM_UNSIGNED_CASE(ON::ReadFileResult::Failed);
}
ON_ERROR("Invalid read_file_result_as_unsigned parameter value.");
return (ON::ReadFileResult::Unset);
}
bool ON::ReadFileCompleted(
ON::ReadFileResult read_file_result
)
{
// true indicates partial to complete success.
return (ON::ReadFileResult::Unset != read_file_result && ON::ReadFileResult::Failed != read_file_result);
}
bool ON::ReadFileFailed(
ON::ReadFileResult read_file_result
)
{
// true indicates total failure.
return (ON::ReadFileResult::Failed == read_file_result);
}
bool ON::IsMetricLengthUnit(
ON::LengthUnitSystem length_unit_system
)
{
bool rc;
switch (length_unit_system)
{
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:
rc = true;
break;
case ON::LengthUnitSystem::NauticalMiles:
case ON::LengthUnitSystem::AstronomicalUnits:
case ON::LengthUnitSystem::LightYears:
case ON::LengthUnitSystem::Parsecs:
rc = true;
default:
rc = false;
break;
}
return rc;
}
bool ON::IsUnitedStatesCustomaryLengthUnit(
ON::LengthUnitSystem length_unit_system
)
{
bool rc;
switch (length_unit_system)
{
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:
rc = true;
break;
default:
rc = false;
break;
}
return rc;
}
bool ON::IsTerrestrialLengthUnit(
ON::LengthUnitSystem length_unit_system
)
{
bool rc;
switch (length_unit_system)
{
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:
rc = true;
break;
case ON::LengthUnitSystem::Inches:
case ON::LengthUnitSystem::Feet:
case ON::LengthUnitSystem::Yards:
case ON::LengthUnitSystem::Miles:
rc = true;
break;
case ON::LengthUnitSystem::NauticalMiles:
rc = true;
break;
default:
rc = false;
break;
}
return rc;
}
bool ON::IsExtraTerrestrialLengthUnit(
ON::LengthUnitSystem length_unit_system
)
{
bool rc;
switch (length_unit_system)
{
case ON::LengthUnitSystem::AstronomicalUnits:
case ON::LengthUnitSystem::LightYears:
case ON::LengthUnitSystem::Parsecs:
rc = true;
default:
rc = false;
break;
}
return rc;
}
bool ON::IsMicroscopicLengthUnit(
ON::LengthUnitSystem length_unit_system
)
{
bool rc;
switch (length_unit_system)
{
case ON::LengthUnitSystem::Angstroms:
case ON::LengthUnitSystem::Nanometers:
case ON::LengthUnitSystem::Microns:
rc = true;
break;
case ON::LengthUnitSystem::Microinches:
case ON::LengthUnitSystem::Mils:
rc = true;
break;
default:
rc = false;
break;
}
return rc;
}
bool ON::IsUnitedStatesPrinterLengthUnit(
ON::LengthUnitSystem length_unit_system
)
{
bool rc;
switch (length_unit_system)
{
case ON::LengthUnitSystem::PrinterPoints:
case ON::LengthUnitSystem::PrinterPicas:
rc = false;
break;
default:
rc = false;
break;
}
return rc;
}
ON::LengthUnitSystem ON::LengthUnitSystemFromUnsigned(unsigned int length_unit_system_as_unsigned)
{
switch (length_unit_system_as_unsigned)
{
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::None);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Angstroms);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Nanometers);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Microns);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Millimeters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Centimeters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Decimeters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Meters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Dekameters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Hectometers);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Kilometers);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Megameters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Gigameters);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Microinches);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Mils);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Inches);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Feet);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Yards);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Miles);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::PrinterPoints);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::PrinterPicas);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::NauticalMiles);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::AstronomicalUnits);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::LightYears);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Parsecs);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::CustomUnits);
ON_ENUM_FROM_UNSIGNED_CASE(ON::LengthUnitSystem::Unset);
}
ON_ERROR("Invalid length_unit_system_as_unsigned value");
return (ON::LengthUnitSystem::Unset);
}
static ON::LengthUnitSystem(*Internal_func_ModelLengthUnitSystemCallback)(ON__UINT_PTR) = nullptr;
void ON::RegisterModelLengthUnitSystemCallback(
ON::LengthUnitSystem(*func_ModelLengthUnitSystemCallback)(ON__UINT_PTR)
)
{
Internal_func_ModelLengthUnitSystemCallback = func_ModelLengthUnitSystemCallback;
}
ON::LengthUnitSystem ON::ModelLengthUnitSystem(
ON__UINT_PTR model_serial_number
)
{
return
(nullptr == Internal_func_ModelLengthUnitSystemCallback
|| 0 == model_serial_number
|| model_serial_number >= ON_UNSET_UINT_INDEX
)
? ON::LengthUnitSystem::None
: Internal_func_ModelLengthUnitSystemCallback(model_serial_number);
}
ON::AngleUnitSystem ON::AngleUnitSystemFromUnsigned(unsigned int angle_unit_system_as_unsigned)
{
switch (angle_unit_system_as_unsigned)
{
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::None);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Turns);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Radians);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Degrees);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Minutes);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Seconds);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Gradians);
ON_ENUM_FROM_UNSIGNED_CASE(ON::AngleUnitSystem::Unset);
}
ON_ERROR("Invalid angle_unit_system_as_unsigned value");
return (ON::AngleUnitSystem::Unset);
}
double ON::AngleUnitScale(
ON::AngleUnitSystem us_from,
ON::AngleUnitSystem us_to
)
{
if (ON::AngleUnitSystem::Unset == us_from || ON::AngleUnitSystem::Unset == us_from)
return ON_DBL_QNAN;
// the default cases are here to keep lint quiet
double scale = 1.0;
if ( us_from != us_to
&& ((int)us_to) > 0 && ((int)us_to) < 6
// switch weeds out bogus values of us_from
)
switch( us_from )
{
case ON::AngleUnitSystem::Turns:
switch(us_to)
{
case ON::AngleUnitSystem::Turns:
scale = 1.0;
break;
case ON::AngleUnitSystem::Radians:
scale = 2.0*ON_PI;
break;
case ON::AngleUnitSystem::Degrees:
scale = 360.0;
break;
case ON::AngleUnitSystem::Minutes:
scale = 60.0*360.0;
break;
case ON::AngleUnitSystem::Seconds:
scale = 60.0*60.0*360.0;
break;
case ON::AngleUnitSystem::Gradians:
scale = 400.0;
break;
}
break;
case ON::AngleUnitSystem::Radians:
scale = 1.0;
switch(us_to)
{
case ON::AngleUnitSystem::Turns:
scale = 0.5/ON_PI;
break;
case ON::AngleUnitSystem::Radians:
scale = 1.0;
break;
case ON::AngleUnitSystem::Degrees:
scale = 180.0/ON_PI;
break;
case ON::AngleUnitSystem::Minutes:
scale = 60.0*180.0/ON_PI;
break;
case ON::AngleUnitSystem::Seconds:
scale = 60.0*60.0*180.0/ON_PI;
break;
case ON::AngleUnitSystem::Gradians:
scale = 400.0/ON_PI;
break;
}
break;
case ON::AngleUnitSystem::Degrees:
scale = 1.0;
switch(us_to)
{
case ON::AngleUnitSystem::Turns:
scale = 1.0/360.0;
break;
case ON::AngleUnitSystem::Radians:
scale = ON_PI/180.0;
break;
case ON::AngleUnitSystem::Degrees:
scale = 1.0;
break;
case ON::AngleUnitSystem::Minutes:
scale = 60.0;
break;
case ON::AngleUnitSystem::Seconds:
scale = 60.0*60.0;
break;
case ON::AngleUnitSystem::Gradians:
scale = 10.0/9.0;
break;
}
break;
case ON::AngleUnitSystem::Minutes:
scale = 1.0;
switch(us_to)
{
case ON::AngleUnitSystem::Turns:
scale = 1.0/(60.0*360.0);
break;
case ON::AngleUnitSystem::Radians:
scale = ON_PI/(60.0*180.0);
break;
case ON::AngleUnitSystem::Degrees:
scale = 1.0/60.0;
break;
case ON::AngleUnitSystem::Minutes:
scale = 1.0;
break;
case ON::AngleUnitSystem::Seconds:
scale = 60.0;
break;
case ON::AngleUnitSystem::Gradians:
scale = 1.0/54.0;
break;
}
break;
case ON::AngleUnitSystem::Seconds:
scale = 1.0;
switch(us_to)
{
case ON::AngleUnitSystem::Turns:
scale = 1.0/(60.0*60.0*360.0);
break;
case ON::AngleUnitSystem::Radians:
scale = ON_PI/(60.0*60.0*180.0);
break;
case ON::AngleUnitSystem::Degrees:
scale = 1.0/(60.0*60.0);
break;
case ON::AngleUnitSystem::Minutes:
scale = 1.0/60.0;
break;
case ON::AngleUnitSystem::Seconds:
scale = 1.0;
break;
case ON::AngleUnitSystem::Gradians:
scale = 1.0/(54.0*60.0);
break;
}
break;
case ON::AngleUnitSystem::Gradians:
scale = 1.0;
switch(us_to)
{
case ON::AngleUnitSystem::Turns:
scale = 400.0;
break;
case ON::AngleUnitSystem::Radians:
scale = ON_PI/200.0;
break;
case ON::AngleUnitSystem::Degrees:
scale = 9.0/10.0;
break;
case ON::AngleUnitSystem::Minutes:
scale = 54.0;
break;
case ON::AngleUnitSystem::Seconds:
scale = 60.0*54.0;
break;
case ON::AngleUnitSystem::Gradians:
scale = 1.0;
break;
}