forked from mcneel/opennurbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopennurbs_object.cpp
2339 lines (2066 loc) · 56.4 KB
/
opennurbs_object.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"
#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
#if defined(OPENNURBS_EXPORTS)
//
//
////////////////////////////////////////////////////////////////////////////////
#endif
unsigned int ON_IsRhinoApplicationId(
ON_UUID id
)
{
if (ON_rhino2_id == id)
return 2;
if (ON_rhino3_id == id)
return 3;
if (ON_rhino4_id == id)
return 4;
if (ON_rhino5_id == id)
return 5;
if (ON_rhino6_id == id)
return 6;
if (ON_rhino7_id == id)
return 7;
if (ON_rhino8_id == id)
return 8;
return 0;
}
unsigned int ON_IsOpennurbsApplicationId(
ON_UUID id
)
{
if (ON_opennurbs4_id == id)
return 4;
if (ON_opennurbs5_id == id)
return 5;
if (ON_opennurbs6_id == id)
return 6;
if (ON_opennurbs7_id == id)
return 7;
if (ON_opennurbs8_id == id)
return 8;
return 0;
}
static int ON__isnand(const double* x)
{
const unsigned char* b = (const unsigned char*)x;
static unsigned int b7 = 0;
static unsigned int b6 = 0;
if (0 == b6)
{
// different bytes on
union
{
double x;
unsigned char b[8];
} u; u.x = 2.0; // sign = 0; fraction = 0; exponent = 100 0000 0000 binary
if (0x40 == u.b[7] && 0 == u.b[0]
&& 0 == u.b[1] && 0 == u.b[2] && 0 == u.b[3]
&& 0 == u.b[4] && 0 == u.b[5] && 0 == u.b[6]
)
{
// little endian doubles
b7 = 7;
b6 = 6;
}
else if (0x40 == u.b[0] && 0 == u.b[7]
&& 0 == u.b[1] && 0 == u.b[2] && 0 == u.b[3]
&& 0 == u.b[4] && 0 == u.b[5] && 0 == u.b[6]
)
{
// big endian doubles
b7 = 0;
b6 = 1;
}
else
{
// This situation is not handled by this algorithm
// and that is a bug in the algorithm.
ON_ERROR("Unexpected bit pattern in double 2.0.");
// assume little endian doubles
b7 = 7;
b6 = 6;
}
}
if (0x7F == (0x7F & b[b7]) && (0xF0 == (0xF0 & b[b6])))
{
// All exponent bits are set
if (0x08 & b[b6])
{
// The most significant fraction bit is set.
// This must be a QNaN
return 2;
}
else
{
// The most significant fraction bit is is clear.
// If any other fraction bits are set, it's an SNaN
if (0 != (0x0F & b[b6]))
return 1;
if (6 == b6)
{
// little endian
return
(0 != b[0] || 0 != b[1] || 0 != b[2] || 0 != b[3] || 0 != b[4] || 0 != b[5])
? 1 // some fraction bit is set
: 0; // all fraction bits are clear.
}
else
{
// big endian
return
(0 != b[2] || 0 != b[3] || 0 != b[4] || 0 != b[5] || 0 != b[6] || 0 != b[7])
? 1 // some fraction bit is set
: 0; // all fraction bits are clear.
}
}
}
return 0; // not a NaN
}
static int ON__isnanf(const float* x)
{
const unsigned char* b = (const unsigned char*)x;
static unsigned int b3 = 0;
static unsigned int b2 = 0;
if (0 == b2)
{
union
{
float x;
unsigned char b[4];
} u;
// different bytes on
u.x = 2.0f; // sign = 0; mantissa = 0; exponent = 1000 0000
if (0x40 == u.b[3] && 0 == u.b[0] && 0 == u.b[1] && 0 == u.b[2])
{
// little endian floats
b3 = 3; b2 = 2;
}
else if (0x40 == u.b[0] && 0 == u.b[3] && 0 == u.b[1] && 0 == u.b[2])
{
// big endian floats
b3 = 0; b2 = 1;
}
else
{
// This situation is not handled by this algorithm
// and that is a bug in the algorithm.
ON_ERROR("Unexpected bit pattern in float 2.0f.");
// assume little endian floats
b3 = 3; b2 = 2;
}
}
if (0x7F == (0x7F & b[b3]) && (0x80 == (0x80 & b[b2])))
{
// All exponent bits are set
if (0x7F & b[b2])
{
// The most significant fraction bit is set.
// This must be a QNaN
return 2;
}
else
{
// The most significant fraction bit is is clear.
// If any other fraction bits are set, it's an SNaN
if (0 != (0x0F & b[b2]))
return 1;
if (2 == b2)
{
// little endian
return
(0 != b[0] || 0 != b[1])
? 1 // some fraction bit is set
: 0; // all fraction bits are clear.
}
else
{
// big endian
return
(0 != b[2] || 0 != b[3])
? 1 // some fraction bit is set
: 0; // all fraction bits are clear.
}
}
}
return 0; // not a NaN
}
void ON_DBL_SNAN( double* x)
{
union
{
double x;
unsigned char b[8];
} u;
#if defined(ON_LITTLE_ENDIAN)
#define i7 7
#define i6 6
#elif defined(ON_BIG_ENDIAN)
#define i7 0
#define i6 1
#else
unsigned int i7, i6;
u.x = 2.0; // sign = 0; fraction = 0; exponent = 100 0000 0000 binary
if ( 0x40 == u.b[7] && 0 == u.b[0]
&& 0 == u.b[1] && 0 == u.b[2] && 0 == u.b[3]
&& 0 == u.b[4] && 0 == u.b[5] && 0 == u.b[6]
)
{
// little endian doubles
i7 = 7; i6 = 6;
}
else if ( 0x40 == u.b[0] && 0 == u.b[7]
&& 0 == u.b[1] && 0 == u.b[2] && 0 == u.b[3]
&& 0 == u.b[4] && 0 == u.b[5] && 0 == u.b[6]
)
{
// big endian doubles
i7 = 0; i6 = 1;
}
else
{
// this sitation is not handled by this algorithm
// and that is a bug in the algorithm.
ON_ERROR("CPU has unexpected bit pattern in double 2.0.");
i7 = 0;
i6 = 0;
memset(&x,0xFF,sizeof(*x));
return;
}
#endif
// all exponent bits = 1
// fraction bits = 010...0
u.b[i7] = 0x7F; // 0111 1111
u.b[i6] = 0xF4; // 1111 0100
u.b[5] = 0; // 0...
u.b[4] = 0;
u.b[3] = 0;
u.b[2] = 0;
u.b[7-i6] = 0;
u.b[7-i7] = 0;
#if defined(i7)
#undef i7
#undef i6
#endif
// must use memcpy(). On Intel FPU, assignment using x = u.x
// will set x to qnan and invalid op exception occurs.
memcpy(x,&u.x,sizeof(*x));
}
void ON_FLT_SNAN( float* x)
{
union
{
float x;
unsigned char b[4];
} u;
#if defined(ON_LITTLE_ENDIAN)
#define i3 3
#define i2 2
#elif defined(ON_BIG_ENDIAN)
#define i3 0
#define i2 1
#else
unsigned int i3, i2;
u.x = 2.0f; // sign = 0; mantissa = 0; exponent = 1000 0000
if ( 0x40 == u.b[3] && 0 == u.b[0] && 0 == u.b[1] && 0 == u.b[2] )
{
// little endian doubles
i3 = 3; i2 = 2;
}
else if ( 0x40 == u.b[0] && 0 == u.b[3] && 0 == u.b[1] && 0 == u.b[2] )
{
// big endian doubles
i3 = 0; i2 = 1;
}
else
{
// this sitation is not handled by this algorithm
// and that is a bug in the algorithm.
ON_ERROR("CPU has unexpected bit pattern in float 2.0f.");
memset(&x,0xFF,sizeof(*x));
return;
}
#endif
// all exponent bits = 1
// fraction bits = 011...1
u.b[i3] = 0x7F; // 0111 1111
u.b[i2] = 0xA0; // 1010 0000
u.b[3-i2] = 0; // 0...
u.b[3-i3] = 0;
#if defined(i3)
#undef i3
#undef i2
#endif
// must use memcpy(). On Intel FPU, assignment using x = u.x
// will set x to qnan and invalid op exception occurs.
memcpy(x,&u.x,sizeof(*x));
}
bool ON_IsNaNd(double x)
{
return 0 != ON__isnand(&x);
}
bool ON_IsQNaNd(double x)
{
return 2 == ON__isnand(&x);
}
bool ON_IsSNaNd(double x)
{
return 1 == ON__isnand(&x);
}
bool ON_IsNaNf(float x)
{
return 0 != ON__isnanf(&x);
}
bool ON_IsQNaNf(float x)
{
return 2 == ON__isnanf(&x);
}
bool ON_IsSNaNf(float x)
{
return 1 == ON__isnanf(&x);
}
float ON_FloatFromDouble(
double x
)
{
if (ON_UNSET_VALUE == x)
return ON_UNSET_FLOAT;
if (ON_UNSET_POSITIVE_VALUE == x)
return ON_UNSET_POSITIVE_FLOAT;
return static_cast<float>(x);
}
double ON_DoubleFromFloat(
float x
)
{
if (ON_UNSET_FLOAT == x)
return ON_UNSET_VALUE;
if (ON_UNSET_POSITIVE_FLOAT == x)
return ON_UNSET_POSITIVE_VALUE;
return static_cast<double>(x);
}
bool ON_IsNullPtr(const void* ptr)
{
return (nullptr == ptr);
}
bool ON_IsNullPtr(const ON__UINT_PTR ptr)
{
return (0 == ptr);
}
bool ON_IsNullPtr(const ON__INT_PTR ptr)
{
return (0 == ptr);
}
static void ValidateSizesHelper()
{
static bool bSizedValidated = false;
if ( !bSizedValidated )
{
// Validate int and pointer sizes
bSizedValidated = true;
// These conditional expressions are all constant and should
// all be false. If any are true, then portions of OpenNURBS
// code will fail and probably crash.
#if defined(ON_COMPILER_MSC)
#pragma ON_PRAGMA_WARNING_PUSH
// Disable warning C4127: conditional expression is constant
#pragma ON_PRAGMA_WARNING_DISABLE_MSC( 4127 )
#endif
if ( ON_SIZEOF_POINTER != sizeof(void*) )
{
ON_ERROR("ON_SIZEOF_POINTER is not correctly defined.");
}
if ( ON_SIZEOF_POINTER != sizeof(ON__INT_PTR) )
{
ON_ERROR("ON_INT_PTR is not correctly defined.");
}
if ( 1 != sizeof(char) )
{
ON_ERROR("OpenNURBS assumes sizeof(char) = 1.");
}
if ( 2 != sizeof(ON__INT16) )
{
ON_ERROR("ON__INT16 is not correctly defined.");
}
if ( 4 != sizeof(ON__INT32) )
{
ON_ERROR("ON__INT32 is not correctly defined.");
}
if ( 8 != sizeof(ON__INT64) )
{
ON_ERROR("ON__INT32 is not correctly defined.");
}
if ( sizeof(int) > sizeof(void*) )
{
ON_ERROR("OpenNURBS assumes sizeof(int) <= sizeof(void*).");
}
if ( 4 != sizeof(float) )
{
ON_ERROR("OpenNURBS assumes sizeof(float) = 4.");
}
if ( 8 != sizeof(double) )
{
ON_ERROR("OpenNURBS assumes sizeof(double) = 8.");
}
#if defined(ON_COMPILER_MSC)
#pragma ON_PRAGMA_WARNING_POP
#endif
}
}
unsigned int ON::LibraryStatus()
{
return ON::m_opennurbs_library_status;
}
void ON::SetLibraryStatus(unsigned int status)
{
ON::m_opennurbs_library_status = status;
}
void ON::Begin()
{
if ( 0 != ON::m_opennurbs_library_status )
return;
ON::m_opennurbs_library_status = 1;
ValidateSizesHelper();
#if !defined(OPENNURBS_EXPORTS)
// Some statically linked library optimizations discard
// object code that is not explicitly referenced.
// By explicitly calling all the ON_Object::Cast overrides,
// we can insure that the class definitions get linked in
// by making a single call to ON::Begin(). These definitions
// are needed for the file reading code to work right.
const ON_Object* p=0;
ON_Object::Cast(p);
ON_3dmObjectAttributes::Cast(p);
ON_Bitmap::Cast(p);
ON_EmbeddedBitmap::Cast(p);
ON_WindowsBitmap::Cast(p);
ON_WindowsBitmapEx::Cast(p);
ON_DimStyle::Cast(p);
ON_DocumentUserStringList::Cast(p);
ON_TextStyle::Cast(p);
ON_Geometry::Cast(p);
ON_Annotation::Cast(p);
ON_Text::Cast(p);
ON_Leader::Cast(p);
ON_Dimension::Cast(p);
ON_DimLinear::Cast(p);
ON_DimAngular::Cast(p);
ON_DimRadial::Cast(p);
ON_DimOrdinate::Cast(p);
ON_Centermark::Cast(p);
ON_Brep::Cast(p);
ON_BrepLoop::Cast(p);
ON_Curve::Cast(p);
ON_ArcCurve::Cast(p);
ON_CurveOnSurface::Cast(p);
ON_CurveProxy::Cast(p);
ON_BrepEdge::Cast(p);
ON_BrepTrim::Cast(p);
ON_LineCurve::Cast(p);
ON_NurbsCurve::Cast(p);
ON_PolyCurve::Cast(p);
ON_PolylineCurve::Cast(p);
ON_DetailView::Cast(p);
ON_Hatch::Cast(p);
ON_InstanceDefinition::Cast(p);
ON_InstanceRef::Cast(p);
ON_Light::Cast(p);
ON_Mesh::Cast(p);
ON_MeshComponentRef::Cast(p);
ON_MorphControl::Cast(p);
ON_NurbsCage::Cast(p);
ON_Point::Cast(p);
ON_BrepVertex::Cast(p);
ON_PointCloud::Cast(p);
ON_PointGrid::Cast(p);
ON_Surface::Cast(p);
ON_Extrusion::Cast(p);
ON_NurbsSurface::Cast(p);
ON_PlaneSurface::Cast(p);
ON_ClippingPlaneSurface::Cast(p);
ON_RevSurface::Cast(p);
ON_SumSurface::Cast(p);
ON_SurfaceProxy::Cast(p);
ON_BrepFace::Cast(p);
ON_OffsetSurface::Cast(p);
ON_TextDot::Cast(p);
ON_Viewport::Cast(p);
ON_Group::Cast(p);
ON_HatchPattern::Cast(p);
ON_HistoryRecord::Cast(p);
ON_Layer::Cast(p);
ON_Linetype::Cast(p);
ON_Material::Cast(p);
ON_Texture::Cast(p);
ON_TextureMapping::Cast(p);
ON_UserData::Cast(p);
ON_UnknownUserData::Cast(p);
ON_UserStringList::Cast(p);
#endif
// Lock and mark all constant system components
ON_ModelComponent::Internal_SystemComponentHelper();
ON::m_opennurbs_library_status = 2;
}
void ON::End()
{
}
int ON_ClassId::CurrentMark()
{
return m_mark0;
}
int ON_ClassId::IncrementMark()
{
m_mark0++;
return m_mark0;
}
int ON_ClassId::Purge( int mark_value )
{
// Fundamental openNURBS class ids have a mark value of 0 and cannot be purged.
int purge_count = 0;
if ( mark_value > 0 ) {
ON_ClassId* prev = 0;
ON_ClassId* next = 0;
ON_ClassId* p;
for ( p = m_p0; p; p = next )
{
next = p->m_pNext;
if ( (0x7FFFFFFF & p->m_mark) == mark_value ) {
purge_count++;
if ( prev )
prev->m_pNext = next;
else
m_p0 = next;
p->m_pNext = 0;
}
else
prev = p;
}
}
return purge_count;
}
const ON_ClassId* ON_ClassId::LastClassId()
{
return m_p1;
}
bool ON_ClassId::PurgeAfter(const ON_ClassId* pClassId)
{
// If you crash in on the p=p->m_pNext iterator in
// the for() loop, it is because somebody incorrectly
// unloaded a dll that contains an ON_OBJECT_IMPLEMENT
// macro.
for (ON_ClassId* p = m_p0; p; p = p->m_pNext)
{
if (pClassId == p)
{
// All class ids after pClassId are assumed to
// be bad.
p->m_pNext = 0;
m_p1 = p;
return true;
}
}
ON_ERROR("ON_ClassId::PurgeAfter pClassId is not active");
return false;
}
//////////////////////////////////////////////////////////////////////////////
static bool g_bDisableDemotion = false;
static void IntToString( int i, char s[7] )
{
// avoid format printing during early start up
int j;
int digit;
char sdig[10];
sdig[0] = '0';
sdig[1] = '1';
sdig[2] = '2';
sdig[3] = '3';
sdig[4] = '4';
sdig[5] = '5';
sdig[6] = '6';
sdig[7] = '7';
sdig[8] = '8';
sdig[9] = '9';
for ( digit = 5; digit > 0; digit-- )
{
j = i%10;
if ( j > 9 || j < 0 )
{
s[digit] = '-';
}
else
{
s[digit] = sdig[j];
}
i /= 10;
}
s[0] = '-';
s[6] = 0;
}
ON_ClassId::ON_ClassId( const char* sClassName,
const char* sBaseClassName,
ON_Object* (*create)(),
const char* sUUID // UUID in registry format from guidgen
)
: m_pNext(0),
m_pBaseClassId(0),
m_create(create),
m_mark(m_mark0),
m_class_id_version(0),
m_f1(0),
m_f2(0),
m_f3(0),
m_f4(0),
m_f5(0),
m_f6(0),
m_f7(0),
m_f8(0)
{
// code compiled on or after opennurbs 200703060 calls this constructor
ConstructorHelper(sClassName,sBaseClassName,sUUID);
m_mark |= 0x80000000; // This bit of m_mark is a flag that indicates
// the new constructor was called.
}
void ON_ClassId::ConstructorHelper( const char* sClassName,
const char* sBaseClassName,
const char* sUUID // UUID in registry format from guidgen
)
{
// Do not initialize "m_class_id_version" or any fields
// after it in this helper. See comments in the constructors
// for more information.
memset( m_sClassName, 0, sizeof(m_sClassName) );
memset( m_sBaseClassName, 0, sizeof(m_sBaseClassName) );
m_uuid = ON_UuidFromString(sUUID);
if ( sClassName ) {
strncpy( m_sClassName, sClassName, sizeof(m_sClassName)-1 );
}
if ( sBaseClassName ) {
strncpy( m_sBaseClassName, sBaseClassName, sizeof(m_sBaseClassName)-1 );
}
m_pBaseClassId = ClassId( m_sBaseClassName );
if ( !m_sClassName[0] ) {
ON_ERROR("ON_ClassId::ON_ClassId() - missing class name");
return;
}
const ON_ClassId* duplicate_class = ClassId( m_sClassName );
// The m_mark0 > 2 test prevents opennurbs and Rhino from
// having two ON_Object derived classes that have the same
// name. Plug-ins are free to use any name.
if ( 0 != duplicate_class && m_mark0 > 2 )
{
char s[7];
int ver;
ON_WARNING("ON_ClassId::ON_ClassId() - class name already in use. Will append number to make it unique.");
for ( ver = 1; ver < 10000 && 0 != duplicate_class; ver++ )
{
IntToString(ver,s);
s[6] = 0;
strncpy( m_sClassName, sClassName, sizeof(m_sClassName)-1 );
strncat( m_sClassName, s, sizeof(m_sClassName)-1 );
duplicate_class = ClassId( m_sClassName );
}
}
if ( 0 != duplicate_class )
{
// Do NOT permit core classes to have duplicate names.
ON_ERROR("ON_ClassId::ON_ClassId() - class name already in use.");
return;
}
if ( m_sClassName[0] != 'O'
|| m_sClassName[1] != 'N'
|| m_sClassName[2] != '_'
|| m_sClassName[3] != 'O'
|| m_sClassName[4] != 'b'
|| m_sClassName[5] != 'j'
|| m_sClassName[6] != 'e'
|| m_sClassName[7] != 'c'
|| m_sClassName[8] != 't'
|| m_sClassName[9] != 0 ) {
if ( !m_sBaseClassName[0] )
{
ON_ERROR("ON_ClassId::ON_ClassId() - missing baseclass name.");
return;
}
}
g_bDisableDemotion = true;
if ( ClassId( m_uuid ) )
{
g_bDisableDemotion = false;
ON_ERROR("ON_ClassId::ON_ClassId() - class uuid already in use.");
return;
}
g_bDisableDemotion = false;
if ( ON_UuidIsNil( m_uuid ) ) {
ON_ERROR("ON_ClassId::ON_ClassId() - class uuid is nill.");
return;
}
// see if any derived classes need to be updated because their static
// members got initialized first
if ( m_sClassName[0] )
{
for ( ON_ClassId* p = m_p0; p; p = p->m_pNext )
{
if (
0 == p->m_pBaseClassId
&& 0 != p->m_sBaseClassName[0]
&& 0 == p->m_sBaseClassName[sizeof(p->m_sBaseClassName)/sizeof(p->m_sBaseClassName[0]) - 1]
)
{
if ( 0 == strcmp( m_sClassName, p->m_sBaseClassName ) )
p->m_pBaseClassId = this;
}
}
}
// Append to the list of class ids
if ( m_p0 && m_p1 )
{
m_p1->m_pNext = this;
m_p1 = this;
}
else
{
// first class id
m_p0 = this;
}
m_p1 = this;
m_p1->m_pNext = 0;
}
ON_ClassId::~ON_ClassId()
{}
static ON_UUID s_most_recent_class_id_create_uuid;
ON_UUID ON_GetMostRecentClassIdCreateUuid()
{
return s_most_recent_class_id_create_uuid;
}
ON_Object* ON_ClassId::Create() const
{
// Save the uuid so that Rhino's .NET SDK
// can create appropriate class. The C++
// opennurbs toolkit never uses this value.
s_most_recent_class_id_create_uuid = m_uuid;
return m_create ? m_create() : 0;
}
const ON_ClassId* ON_ClassId::ClassId( const char* sClassName )
{
// static member function
// search list of class ids for one with a matching class name
ON_ClassId* p;
const char* s0;
const char* s1;
if ( !sClassName || !sClassName[0] || sClassName[0] == '0' )
return nullptr;
for(p = m_p0; p; p = p->m_pNext) {
// avoid strcmp() because it crashes on nullptr strings
s0 = sClassName;
s1 = p->m_sClassName;
if ( s0 && s1 && *s0 ) {
while ( *s0 && *s0 == *s1 )
{s0++; s1++;}
if ( !(*s0) && !(*s1) )
break;
}
else {
break;
}
}
return p;
}
const ON_ClassId* ON_ClassId::ClassId( ON_UUID uuid )
{
// static member function
// search list of class ids for one with a matching typecode
const ON_ClassId* p;
for(p = m_p0; p; p = p->m_pNext)
{
if ( !ON_UuidCompare(&p->m_uuid,&uuid) )
break;
}
if ( nullptr == p && false == g_bDisableDemotion)
{
// enable OpenNURBS toolkit to read files that contain old uuids even when
// old class definitions are not loaded.
// 5EAF1119-0B51-11d4-BFFE-0010830122F0 = TL_NurbsCurve
ON_UUID nc0 = {0x5EAF1119,0x0B51,0x11d4,{0xBF,0xFE, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// 76A709D5-1550-11d4-8000-0010830122F0 = old nurbs curve
ON_UUID nc1 = {0x76A709D5,0x1550,0x11d4,{0x80,0x00, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// 4760C817-0BE3-11d4-BFFE-0010830122F0 = TL_NurbsSurface
ON_UUID ns0 = {0x4760C817,0x0BE3,0x11d4,{0xBF,0xFE, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// FA4FD4B5-1613-11d4-8000-0010830122F0 = old nurbs surface
ON_UUID ns1 = {0xFA4FD4B5,0x1613,0x11d4,{0x80,0x00, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// EF638317-154B-11d4-8000-0010830122F0 = old poly curve
ON_UUID pc0 = {0xEF638317,0x154B,0x11d4,{0x80,0x00, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// 0705FDEF-3E2A-11d4-800E-0010830122F0 = old trimmed surface
ON_UUID br0 = {0x0705FDEF,0x3E2A,0x11d4,{0x80,0x0E, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// 2D4CFEDB-3E2A-11d4-800E-0010830122F0 = old b-rep
ON_UUID br1 = {0x2D4CFEDB,0x3E2A,0x11d4,{0x80,0x0E, 0x00,0x10,0x83,0x01,0x22,0xF0}};
// F06FC243-A32A-4608-9DD8-A7D2C4CE2A36 = TL_Brep
ON_UUID br2 = {0xF06FC243,0xA32A,0x4608,{0x9D,0xD8, 0xA7,0xD2,0xC4,0xCE,0x2A,0x36}};
// 0A8401B6-4D34-4b99-8615-1B4E723DC4E5 = TL_RevSurface
ON_UUID revsrf = { 0xa8401b6, 0x4d34, 0x4b99, { 0x86, 0x15, 0x1b, 0x4e, 0x72, 0x3d, 0xc4, 0xe5 } };
// 665F6331-2A66-4cce-81D0-B5EEBD9B5417 = TL_SumSurface
ON_UUID sumsrf = { 0x665f6331, 0x2a66, 0x4cce, { 0x81, 0xd0, 0xb5, 0xee, 0xbd, 0x9b, 0x54, 0x17 } };
if ( !ON_UuidCompare( &uuid, &nc0 ) || !ON_UuidCompare( &uuid, &nc1 ) )
p = &ON_CLASS_RTTI(ON_NurbsCurve);
else if ( !ON_UuidCompare( &uuid, &ns0 ) || !ON_UuidCompare( &uuid, &ns1 ) )
p = &ON_CLASS_RTTI(ON_NurbsSurface);
else if ( !ON_UuidCompare( &uuid, &pc0 ) )
p = &ON_CLASS_RTTI(ON_PolyCurve);
else if ( !ON_UuidCompare( &uuid, &br0 ) || !ON_UuidCompare( &uuid, &br1 ) || !ON_UuidCompare( &uuid, &br2 ) )
p = &ON_CLASS_RTTI(ON_Brep);
else if ( !ON_UuidCompare( &uuid, &revsrf ) )
p = &ON_CLASS_RTTI(ON_RevSurface);
else if ( !ON_UuidCompare( &uuid, &sumsrf ) )
p = &ON_CLASS_RTTI(ON_SumSurface);
else
{
// The p = nullptr line does nothing (p is already nullptr) but, if you're working on
// file reading bugs or other cases that involving rtti bugs, then it's a good
// location for a debugger breakpoint.
p = nullptr;
}
}
return p;
}
class ON__ClassIdDumpNode
{
public:
ON__ClassIdDumpNode();
~ON__ClassIdDumpNode();
const ON_ClassId* m_class_id;
class ON__ClassIdDumpNode* m_parent_node;
int m_depth;
ON_SimpleArray<class ON__ClassIdDumpNode*> m_child_nodes;
int CompareClassUuid( const class ON__ClassIdDumpNode& ) const;
int CompareClassName( const class ON__ClassIdDumpNode& ) const;
bool Dump( int depth, ON_TextLog& text_log );
};
ON__ClassIdDumpNode::ON__ClassIdDumpNode()
{
m_class_id=0;
m_parent_node=0;
m_depth=0;
};
ON__ClassIdDumpNode::~ON__ClassIdDumpNode()
{
}
int ON__ClassIdDumpNode::CompareClassUuid( const class ON__ClassIdDumpNode& other ) const
{
int rc = 0;
const ON_ClassId* a = m_class_id;
const ON_ClassId* b = other.m_class_id;
if ( a != b )
{
if ( 0 == a )
{
rc = -1;
}
else if ( 0 == b )
rc = 1;
else
{
rc = ON_UuidCompare(a->Uuid(),b->Uuid());
if ( 0 == rc )
{
rc = CompareClassName(other);
}
}
}
return rc;
}
int ON__ClassIdDumpNode::CompareClassName( const class ON__ClassIdDumpNode& other ) const
{
int rc = 0;
const ON_ClassId* a = m_class_id;