forked from mxe/mxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coin-1-fixes.patch
4040 lines (4021 loc) · 134 KB
/
coin-1-fixes.patch
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
This file is part of MXE. See LICENSE.md for licensing information.
Contains ad hoc patches for cross building.
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tony Theodore <[email protected]>
Date: Sat, 18 Nov 2017 20:43:52 +1100
Subject: [PATCH 1/2] fixes
This patch has been taken from: https://bitbucket.org/msys2/coin/commits/69e9990b05cee506f5fa16c6edad02a7808bc610/raw/
It was modified to work with Coin 3.1.3.
(The order of the template arguments of SbHash was switched.)
diff --git a/include/Inventor/C/glue/spidermonkey.h b/include/Inventor/C/glue/spidermonkey.h
index 1111111..2222222 100644
--- a/include/Inventor/C/glue/spidermonkey.h
+++ b/include/Inventor/C/glue/spidermonkey.h
@@ -47,7 +47,7 @@ extern "C" {
Structs and defines.
*/
typedef int JSBool;
-typedef long jsword;
+typedef intmax_t jsword;
typedef jsword jsval;
typedef jsword jsid;
typedef int intN;
diff --git a/include/Inventor/C/glue/spidermonkey.h.orig b/include/Inventor/C/glue/spidermonkey.h.orig
new file mode 100644
index 1111111..2222222
--- /dev/null
+++ b/include/Inventor/C/glue/spidermonkey.h.orig
@@ -0,0 +1,470 @@
+#ifndef COIN_GLUE_SPIDERMONKEY_H
+#define COIN_GLUE_SPIDERMONKEY_H
+
+/**************************************************************************\
+ *
+ * This file is part of the Coin 3D visualization library.
+ * Copyright (C) by Kongsberg Oil & Gas Technologies.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * ("GPL") version 2 as published by the Free Software Foundation.
+ * See the file LICENSE.GPL at the root directory of this source
+ * distribution for additional information about the GNU GPL.
+ *
+ * For using Coin with software that can not be combined with the GNU
+ * GPL, and for taking advantage of the additional benefits of our
+ * support services, please contact Kongsberg Oil & Gas Technologies
+ * about acquiring a Coin Professional Edition License.
+ *
+ * See http://www.coin3d.org/ for more information.
+ *
+ * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
+ * http://www.sim.no/ [email protected] [email protected]
+ *
+\**************************************************************************/
+
+#include <Inventor/C/basic.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if 0 /* to get proper auto-indentation in emacs */
+}
+#endif /* emacs indentation */
+
+
+/*
+ This is used to detect whether the 'jsapi.h' was included by the
+ user or not. The JSVERSION_IS_ECMA is defined in the 'jspubtd.h'
+ file in the SpiderMonkey header directory.
+*/
+#ifndef JSVERSION_IS_ECMA
+
+
+/*
+ Structs and defines.
+*/
+typedef int JSBool;
+typedef long jsword;
+typedef jsword jsval;
+typedef jsword jsid;
+typedef int intN;
+typedef unsigned int uintN;
+typedef uint16_t jschar;
+
+typedef int32_t jsrefcount;
+typedef uint8_t jsbytecode;
+typedef uint32_t JSHashNumber;
+typedef uint32_t jsatomid;
+
+typedef enum JSType {
+ JSTYPE_VOID,
+ JSTYPE_OBJECT,
+ JSTYPE_FUNCTION,
+ JSTYPE_STRING,
+ JSTYPE_NUMBER,
+ JSTYPE_BOOLEAN,
+ JSTYPE_LIMIT
+} JSType;
+
+typedef enum JSAccessMode {
+ JSACC_PROTO = 0,
+ JSACC_PARENT = 1,
+ JSACC_IMPORT = 2,
+ JSACC_WATCH = 3,
+ JSACC_READ = 4,
+ JSACC_WRITE = 8,
+ JSACC_LIMIT
+} JSAccessMode;
+
+typedef enum JSGCStatus {
+ JSGC_BEGIN,
+ JSGC_END,
+ JSGC_MARK_END,
+ JSGC_FINALIZE_END
+} JSGCStatus;
+
+struct JSIdArray {
+ int32_t length;
+ jsid vector[1];
+};
+
+typedef void JSRuntime;
+typedef void JSContext;
+typedef void JSObject;
+typedef void JSObjectOps;
+typedef void JSXDRState;
+typedef void JSString;
+typedef struct JSClass JSClass;
+typedef struct JSPropertySpec JSPropertySpec;
+typedef int JSVersion;
+typedef void JSFunction;
+typedef struct JSFunctionSpec JSFunctionSpec;
+typedef struct JSErrorReport JSErrorReport;
+typedef void JSScript;
+
+#define JS_DLL_CALLBACK /* FIXME: set up this define properly. 20050601 mortene. */
+
+typedef JSBool (* JS_DLL_CALLBACK JSPropertyOp)(JSContext *, JSObject *, jsval, jsval *);
+typedef JSBool (* JS_DLL_CALLBACK JSEnumerateOp)(JSContext *, JSObject *);
+typedef JSBool (* JS_DLL_CALLBACK JSResolveOp)(JSContext *, JSObject *, jsval);
+typedef JSBool (* JS_DLL_CALLBACK JSConvertOp)(JSContext *, JSObject *, JSType, jsval *);
+typedef void (* JS_DLL_CALLBACK JSFinalizeOp)(JSContext *, JSObject *);
+typedef JSObjectOps * (* JS_DLL_CALLBACK JSGetObjectOps)(JSContext *, JSClass *);
+typedef JSBool (* JS_DLL_CALLBACK JSCheckAccessOp)(JSContext *, JSObject *, jsval, JSAccessMode, jsval *);
+typedef JSBool (* JS_DLL_CALLBACK JSNative)(JSContext *, JSObject *, uintN, jsval *, jsval *);
+typedef JSBool (* JS_DLL_CALLBACK JSXDRObjectOp)(JSXDRState *, JSObject **);
+typedef JSBool (* JS_DLL_CALLBACK JSHasInstanceOp)(JSContext *, JSObject *, jsval, JSBool *);
+typedef uint32_t (* JS_DLL_CALLBACK JSMarkOp)(JSContext *, JSObject *, void *);
+
+struct JSClass {
+ const char * name;
+ uint32_t flags;
+ JSPropertyOp addProperty;
+ JSPropertyOp delProperty;
+ JSPropertyOp getProperty;
+ JSPropertyOp setProperty;
+ JSEnumerateOp enumerate;
+ JSResolveOp resolve;
+ JSConvertOp convert;
+ JSFinalizeOp finalize;
+ JSGetObjectOps getObjectOps;
+ JSCheckAccessOp checkAccess;
+ JSNative call;
+ JSNative construct;
+ JSXDRObjectOp xdrObject;
+ JSHasInstanceOp hasInstance;
+ JSMarkOp mark;
+ jsword spare;
+};
+
+struct JSPropertySpec {
+ const char * name;
+ int8_t tinyid;
+ uint8_t flags;
+ JSPropertyOp getter;
+ JSPropertyOp setter;
+};
+
+struct JSFunctionSpec {
+ const char *name;
+ JSNative call;
+ uint8_t nargs;
+ uint8_t flags;
+ uint16_t extra;
+};
+
+struct JSErrorReport {
+ const char * filename;
+ uintN lineno;
+ const char * linebuf;
+ const char * tokenptr;
+ const jschar * uclinebuf;
+ const jschar * uctokenptr;
+ uintN flags;
+ uintN errorNumber;
+ const jschar * ucmessage;
+ const jschar ** messageArgs;
+};
+
+
+/* Defines and macros. ************************************************** */
+
+#define JSVAL_OBJECT 0x0
+#define JSVAL_INT 0x1
+#define JSVAL_DOUBLE 0x2
+#define JSVAL_STRING 0x4
+#define JSVAL_BOOLEAN 0x6
+
+#define JS_BIT(n) ((uint32_t)1 << (n))
+#define JS_BITMASK(n) (JS_BIT(n) - 1)
+
+#define JSVAL_TAGBITS 3
+#define JSVAL_TAGMASK JS_BITMASK(JSVAL_TAGBITS)
+#define JSVAL_TAG(v) ((v) & JSVAL_TAGMASK)
+#define JSVAL_SETTAG(v,t) ((v) | (t))
+#define JSVAL_CLRTAG(v) ((v) & ~(jsval)JSVAL_TAGMASK)
+
+#define JSVAL_IS_PRIMITIVE(v) (!JSVAL_IS_OBJECT(v) || JSVAL_IS_NULL(v))
+#define JSVAL_IS_OBJECT(v) (JSVAL_TAG(v) == JSVAL_OBJECT)
+#define JSVAL_IS_NUMBER(v) (JSVAL_IS_INT(v) || JSVAL_IS_DOUBLE(v))
+#define JSVAL_IS_INT(v) (((v) & JSVAL_INT) && (v) != JSVAL_VOID)
+#define JSVAL_IS_DOUBLE(v) (JSVAL_TAG(v) == JSVAL_DOUBLE)
+#define JSVAL_IS_STRING(v) (JSVAL_TAG(v) == JSVAL_STRING)
+#define JSVAL_IS_BOOLEAN(v) (JSVAL_TAG(v) == JSVAL_BOOLEAN)
+#define JSVAL_IS_NULL(v) ((v) == JSVAL_NULL)
+#define JSVAL_IS_VOID(v) ((v) == JSVAL_VOID)
+
+#define BOOLEAN_TO_JSVAL(b) JSVAL_SETTAG((jsval)(b) << JSVAL_TAGBITS, JSVAL_BOOLEAN)
+#define JSVAL_TO_BOOLEAN(v) ((JSBool)((v) >> JSVAL_TAGBITS))
+
+#define JSVAL_INT_BITS 31
+#define JSVAL_INT_POW2(n) ((jsval)1 << (n))
+#define JSVAL_INT_MIN ((jsval)1 - JSVAL_INT_POW2(30))
+#define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
+#define INT_FITS_IN_JSVAL(i) ((uint32_t)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
+#define JSVAL_TO_INT(v) ((int32_t)(v) >> 1)
+#define INT_TO_JSVAL(i) (((jsval)(i) << 1) | JSVAL_INT)
+
+#define JSVAL_TO_GCTHING(v) ((void *)JSVAL_CLRTAG(v))
+#define JSVAL_TO_OBJECT(v) ((JSObject *)JSVAL_TO_GCTHING(v))
+#define JSVAL_TO_DOUBLE(v) ((double *)JSVAL_TO_GCTHING(v))
+#define JSVAL_TO_STRING(v) ((JSString *)JSVAL_TO_GCTHING(v))
+#define OBJECT_TO_JSVAL(obj) ((jsval)(obj))
+#define DOUBLE_TO_JSVAL(dp) JSVAL_SETTAG((jsval)(dp), JSVAL_DOUBLE)
+#define STRING_TO_JSVAL(str) JSVAL_SETTAG((jsval)(str), JSVAL_STRING)
+#define JSVAL_TO_PRIVATE(v) ((void *)((v) & ~JSVAL_INT))
+#define PRIVATE_TO_JSVAL(p) ((jsval)(p) | JSVAL_INT)
+
+#define JSPROP_ENUMERATE 0x01
+#define JSPROP_READONLY 0x02
+#define JSPROP_PERMANENT 0x04
+#define JSPROP_EXPORTED 0x08
+#define JSPROP_GETTER 0x10
+#define JSPROP_SETTER 0x20
+#define JSPROP_SHARED 0x40
+#define JSPROP_INDEX 0x80
+
+#define JS_FALSE (int)0
+#define JS_TRUE (int)1
+
+#define JSVAL_VOID INT_TO_JSVAL(0 - JSVAL_INT_POW2(30))
+#define JSVAL_NULL OBJECT_TO_JSVAL(0)
+#define JSVAL_ZERO INT_TO_JSVAL(0)
+#define JSVAL_ONE INT_TO_JSVAL(1)
+#define JSVAL_FALSE BOOLEAN_TO_JSVAL(JS_FALSE)
+#define JSVAL_TRUE BOOLEAN_TO_JSVAL(JS_TRUE)
+
+#define JSCLASS_HAS_PRIVATE (1<<0)
+#define JSCLASS_NEW_ENUMERATE (1<<1)
+#define JSCLASS_NEW_RESOLVE (1<<2)
+#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3)
+#define JSCLASS_SHARE_ALL_PROPERTIES (1<<4)
+#define JSCLASS_NEW_RESOLVE_GETS_START (1<<5)
+
+#define JSFUN_BOUND_METHOD 0x40
+
+#define JSOPTION_STRICT JS_BIT(0)
+#define JSOPTION_WERROR JS_BIT(1)
+#define JSOPTION_VAROBJFIX JS_BIT(2)
+#define JSOPTION_PRIVATE_IS_NSISUPPORTS JS_BIT(3)
+#define JSOPTION_COMPILE_N_GO JS_BIT(4)
+
+
+/* Function typedefs. *************************************************** */
+
+typedef void (* JS_DLL_CALLBACK JSErrorReporter)(JSContext *, const char *, JSErrorReport *);
+typedef JSBool (* JS_DLL_CALLBACK JSGCCallback)(JSContext *, JSGCStatus);
+
+#endif /* !JSVERSION_IS_ECMA */
+
+typedef JSBool (* JS_EvaluateScript_t)(JSContext *, JSObject *, const char *, uintN, const char *, uintN, jsval *);
+typedef JSString * (* JS_ValueToString_t)(JSContext *, jsval);
+typedef char * (* JS_GetStringBytes_t)(JSString *);
+typedef JSBool (* JS_SetProperty_t)(JSContext *, JSObject *, const char *, jsval *);
+typedef JSBool (* JS_GetProperty_t)(JSContext *, JSObject *, const char *, jsval *);
+typedef JSBool (* JS_CallFunctionName_t)(JSContext *, JSObject *, const char *, uintN, jsval *, jsval *);
+typedef JSBool (* JS_CallFunctionValue_t)(JSContext *, JSObject *, jsval, uintN, jsval *, jsval *);
+typedef JSObject * (* JS_ConstructObjectWithArguments_t)(JSContext *, JSClass *, JSObject *, JSObject *, uintN, jsval *);
+typedef JSRuntime * (* JS_NewRuntime_t)(uint32_t);
+typedef void (* JS_DestroyRuntime_t)(JSRuntime *);
+typedef JSContext * (* JS_NewContext_t)(JSRuntime *, size_t);
+typedef void (* JS_DestroyContext_t)(JSContext *);
+typedef void (* JS_ShutDown_t)(void);
+typedef JSObject * (* JS_NewObject_t)(JSContext *, JSClass *, JSObject *, JSObject *);
+typedef JSBool (* JS_InitStandardClasses_t)(JSContext *, JSObject *);
+typedef JSErrorReporter (* JS_SetErrorReporter_t)(JSContext *, JSErrorReporter);
+typedef JSBool (* JS_PropertyStub_t)(JSContext *, JSObject *, jsval, jsval *);
+typedef JSBool (* JS_EnumerateStub_t)(JSContext *, JSObject *);
+typedef JSBool (* JS_ResolveStub_t)(JSContext *, JSObject *, jsval);
+typedef JSBool (* JS_ConvertStub_t)(JSContext *, JSObject *, JSType, jsval *);
+typedef void (* JS_FinalizeStub_t)(JSContext *, JSObject *);
+typedef const char * (* JS_GetImplementationVersion_t)(void);
+typedef void * (* JS_GetPrivate_t)(JSContext *, JSObject *);
+typedef JSBool (* JS_SetPrivate_t)(JSContext *, JSObject *, void *);
+typedef JSFunction * (* JS_NewFunction_t)(JSContext *, JSNative, uintN, uintN flags, JSObject *, const char *);
+typedef JSObject * (* JS_GetFunctionObject_t)(JSFunction *);
+typedef JSObject * (* JS_DefineObject_t)(JSContext *, JSObject *, const char *, JSClass *, JSObject *, uintN);
+typedef JSBool (* JS_DefineProperties_t)(JSContext *, JSObject *, JSPropertySpec *);
+typedef JSObject * (* JS_GetParent_t)(JSContext *, JSObject *);
+typedef JSBool (* JS_SetParent_t)(JSContext *, JSObject *, JSObject *);
+typedef JSBool (* JS_DefineFunctions_t)(JSContext *, JSObject *, JSFunctionSpec *);
+typedef JSString * (* JS_NewStringCopyZ_t)(JSContext *, const char *);
+typedef JSType (* JS_TypeOfValue_t)(JSContext *, jsval);
+typedef const char * (* JS_GetTypeName_t)(JSContext *, JSType);
+typedef JSBool (* JS_InstanceOf_t)(JSContext *, JSObject *, JSClass *, jsval *);
+typedef JSObject * (* JS_InitClass_t)(JSContext *, JSObject *, JSObject *, JSClass *,
+ JSNative, uintN, JSPropertySpec *, JSFunctionSpec *,
+ JSPropertySpec *, JSFunctionSpec *);
+typedef JSBool (* JS_NewDoubleValue_t)(JSContext *, double, jsval *);
+typedef void * (* JS_GetContextPrivate_t)(JSContext *);
+typedef void (* JS_SetContextPrivate_t)(JSContext *, void *);
+typedef JSBool (* JS_ValueToBoolean_t)(JSContext *, jsval, JSBool *);
+typedef JSBool (* JS_ValueToNumber_t)(JSContext *, jsval, double *);
+typedef JSObject * (* JS_NewArrayObject_t)(JSContext *, int32_t, jsval *);
+typedef JSBool (* JS_GetArrayLength_t)(JSContext *, JSObject *, uint32_t *);
+typedef JSBool (* JS_SetArrayLength_t)(JSContext *, JSObject *, uint32_t);
+typedef JSBool (* JS_HasArrayLength_t)(JSContext *, JSObject *, uint32_t *);
+typedef JSBool (* JS_GetElement_t)(JSContext *, JSObject *, int32_t, jsval *);
+typedef JSBool (* JS_SetElement_t)(JSContext *, JSObject *, int32_t, jsval *);
+typedef JSBool (* JS_AddRoot_t)(JSContext *, void *);
+typedef JSBool (* JS_RemoveRoot_t)(JSContext *, void *);
+typedef size_t (* JS_GetStringLength_t)(JSString *);
+typedef JSBool (* JS_LookupProperty_t)(JSContext *, JSObject *, const char *, jsval *);
+typedef JSBool (* JS_DefineProperty_t)(JSContext *, JSObject *, const char *, jsval, JSPropertyOp, JSPropertyOp, uintN);
+typedef JSScript * (* JS_CompileFile_t)(JSContext *, JSObject *, const char *);
+typedef JSBool (* JS_ValueToObject_t)(JSContext *, jsval, JSObject **);
+typedef JSBool (* JS_ExecuteScript_t)(JSContext *, JSObject *, JSScript *, jsval *);
+typedef JSBool (* JS_IsExceptionPending_t)(JSContext *);
+typedef JSBool (* JS_GetPendingException_t)(JSContext *, jsval *);
+typedef void (* JS_SetPendingException_t)(JSContext *, jsval);
+typedef void (* JS_ClearPendingException_t)(JSContext *);
+typedef double * (* JS_NewDouble_t)(JSContext *, double);
+typedef JSBool (* JS_CallFunction_t)(JSContext *, JSObject *, JSFunction *, uintN, jsval *, jsval *);
+typedef JSFunction * (* JS_ValueToFunction_t)(JSContext *, jsval);
+typedef void (* JS_ReportError_t)(JSContext *, const char *, ...);
+typedef JSBool (* JS_IsArrayObject_t)(JSContext *, JSObject *);
+typedef JSBool (* JS_ObjectIsFunction_t)(JSContext *, JSObject *);
+typedef JSBool (* JS_ValueToECMAInt32_t)(JSContext *, jsval, int32_t *);
+typedef JSFunction * (* JS_DefineFunction_t)(JSContext *, JSObject *, const char *, JSNative, uintN, uintN);
+typedef JSObject * (* JS_GetGlobalObject_t)(JSContext *);
+typedef JSGCCallback (* JS_SetGCCallback_t)(JSContext *, JSGCCallback);
+typedef void (* JS_GC_t)(JSContext *);
+typedef void (* JS_MaybeGC_t)(JSContext *);
+typedef JSBool (* JS_IsRunning_t)(JSContext *);
+typedef JSBool (* JS_DeleteProperty_t)(JSContext *, JSObject *, const char *);
+typedef JSScript * (* JS_CompileScript_t)(JSContext *, JSObject *,
+ const char *, size_t,
+ const char *, uintN);
+typedef jsval (* JS_GetNaNValue_t)(JSContext *);
+typedef jsval (* JS_GetNegativeInfinityValue_t)(JSContext *);
+typedef jsval (* JS_GetPositiveInfinityValue_t)(JSContext *);
+typedef jsval (* JS_GetEmptyStringValue_t)(JSContext *);
+typedef JSBool (* JS_SetPropertyAttributes_t)(JSContext *, JSObject *, const char *, uintN, JSBool *);
+typedef JSBool (* JS_GetPropertyAttributes_t)(JSContext *, JSObject *, const char *, uintN *, JSBool *);
+typedef JSClass * (* JS_GetClass_t)(JSObject *);
+typedef JSObject * (* JS_GetPrototype_t)(JSContext *, JSObject *);
+typedef JSObject * (* JS_SetPrototype_t)(JSContext *, JSObject *, JSObject *);
+typedef intN (* JS_CompareStrings_t)(JSString *, JSString *);
+typedef uint32_t (* JS_GetOptions_t)(JSContext *);
+typedef uint32_t (* JS_SetOptions_t)(JSContext *, uint32_t);
+typedef uint32_t (* JS_ToggleOptions_t)(JSContext *, uint32_t);
+typedef struct JSIdArray * (* JS_Enumerate_t)(JSContext *, JSObject *);
+typedef JSBool (* JS_IdToValue_t)(JSContext *, jsid, jsval *);
+typedef const char * (* JS_GetFunctionName_t)(JSFunction *);
+typedef JSObject * (* JS_GetConstructor_t)(JSContext *, JSObject *);
+typedef void (* JS_DestroyIdArray_t)(JSContext *, struct JSIdArray *);
+
+
+/* Access interface. **************************************************** */
+
+typedef struct {
+ int available;
+
+ JS_CallFunctionName_t JS_CallFunctionName;
+ JS_CallFunctionValue_t JS_CallFunctionValue;
+ JS_ConstructObjectWithArguments_t JS_ConstructObjectWithArguments;
+ JS_ConvertStub_t JS_ConvertStub;
+ JS_DestroyContext_t JS_DestroyContext;
+ JS_DestroyRuntime_t JS_DestroyRuntime;
+ JS_EnumerateStub_t JS_EnumerateStub;
+ JS_EvaluateScript_t JS_EvaluateScript;
+ JS_FinalizeStub_t JS_FinalizeStub;
+ JS_GetClass_t JS_GetClass;
+ JS_GetImplementationVersion_t JS_GetImplementationVersion;
+ JS_GetProperty_t JS_GetProperty;
+ JS_GetStringBytes_t JS_GetStringBytes;
+ JS_InitStandardClasses_t JS_InitStandardClasses;
+ JS_NewContext_t JS_NewContext;
+ JS_NewObject_t JS_NewObject;
+ JS_NewRuntime_t JS_NewRuntime;
+ JS_PropertyStub_t JS_PropertyStub;
+ JS_ResolveStub_t JS_ResolveStub;
+ JS_SetErrorReporter_t JS_SetErrorReporter;
+ JS_SetProperty_t JS_SetProperty;
+ JS_ShutDown_t JS_ShutDown;
+ JS_ValueToString_t JS_ValueToString;
+ JS_DefineObject_t JS_DefineObject;
+ JS_DefineProperties_t JS_DefineProperties;
+ JS_GetPrivate_t JS_GetPrivate;
+ JS_SetPrivate_t JS_SetPrivate;
+ JS_NewFunction_t JS_NewFunction;
+ JS_GetFunctionObject_t JS_GetFunctionObject;
+ JS_GetParent_t JS_GetParent;
+ JS_SetParent_t JS_SetParent;
+ JS_DefineFunctions_t JS_DefineFunctions;
+ JS_NewStringCopyZ_t JS_NewStringCopyZ;
+ JS_TypeOfValue_t JS_TypeOfValue;
+ JS_GetTypeName_t JS_GetTypeName;
+ JS_InstanceOf_t JS_InstanceOf;
+ JS_InitClass_t JS_InitClass;
+ JS_NewDoubleValue_t JS_NewDoubleValue;
+ JS_GetContextPrivate_t JS_GetContextPrivate;
+ JS_SetContextPrivate_t JS_SetContextPrivate;
+ JS_ValueToBoolean_t JS_ValueToBoolean;
+ JS_ValueToNumber_t JS_ValueToNumber;
+ JS_NewArrayObject_t JS_NewArrayObject;
+ JS_GetArrayLength_t JS_GetArrayLength;
+ JS_SetArrayLength_t JS_SetArrayLength;
+ JS_HasArrayLength_t JS_HasArrayLength;
+ JS_GetElement_t JS_GetElement;
+ JS_SetElement_t JS_SetElement;
+ JS_AddRoot_t JS_AddRoot;
+ JS_RemoveRoot_t JS_RemoveRoot;
+ JS_GetStringLength_t JS_GetStringLength;
+ JS_LookupProperty_t JS_LookupProperty;
+ JS_DefineProperty_t JS_DefineProperty;
+ JS_CompileFile_t JS_CompileFile;
+ JS_ValueToObject_t JS_ValueToObject;
+ JS_ExecuteScript_t JS_ExecuteScript;
+ JS_IsExceptionPending_t JS_IsExceptionPending;
+ JS_GetPendingException_t JS_GetPendingException;
+ JS_SetPendingException_t JS_SetPendingException;
+ JS_ClearPendingException_t JS_ClearPendingException;
+ JS_NewDouble_t JS_NewDouble;
+ JS_CallFunction_t JS_CallFunction;
+ JS_ValueToFunction_t JS_ValueToFunction;
+ JS_ReportError_t JS_ReportError;
+ JS_IsArrayObject_t JS_IsArrayObject;
+ JS_ObjectIsFunction_t JS_ObjectIsFunction;
+ // Note: We use this function instead of JS_ValueToInt32() since the
+ // latter is buggy in versions of SpiderMonkey older than 2005-09-29,
+ // see Mozilla bug #284032.
+ JS_ValueToECMAInt32_t JS_ValueToECMAInt32;
+ JS_DefineFunction_t JS_DefineFunction;
+ JS_GetGlobalObject_t JS_GetGlobalObject;
+ JS_SetGCCallback_t JS_SetGCCallback;
+ JS_GC_t JS_GC;
+ JS_MaybeGC_t JS_MaybeGC;
+ JS_IsRunning_t JS_IsRunning;
+ JS_DeleteProperty_t JS_DeleteProperty;
+ JS_CompileScript_t JS_CompileScript;
+ JS_GetNaNValue_t JS_GetNaNValue;
+ JS_GetNegativeInfinityValue_t JS_GetNegativeInfinityValue;
+ JS_GetPositiveInfinityValue_t JS_GetPositiveInfinityValue;
+ JS_GetEmptyStringValue_t JS_GetEmptyStringValue;
+ JS_SetPropertyAttributes_t JS_SetPropertyAttributes;
+ JS_GetPropertyAttributes_t JS_GetPropertyAttributes;
+ JS_GetPrototype_t JS_GetPrototype;
+ JS_SetPrototype_t JS_SetPrototype;
+ JS_CompareStrings_t JS_CompareStrings;
+ JS_GetOptions_t JS_GetOptions;
+ JS_SetOptions_t JS_SetOptions;
+ JS_ToggleOptions_t JS_ToggleOptions;
+ JS_Enumerate_t JS_Enumerate;
+ JS_IdToValue_t JS_IdToValue;
+ JS_GetFunctionName_t JS_GetFunctionName;
+ JS_GetConstructor_t JS_GetConstructor;
+ JS_DestroyIdArray_t JS_DestroyIdArray;
+
+} SpiderMonkey_t;
+
+COIN_DLL_API const SpiderMonkey_t * spidermonkey(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* !COIN_GLUE_SPIDERMONKEY_H */
diff --git a/src/foreignfiles/SoSTLFileKit.cpp b/src/foreignfiles/SoSTLFileKit.cpp
index 1111111..2222222 100644
--- a/src/foreignfiles/SoSTLFileKit.cpp
+++ b/src/foreignfiles/SoSTLFileKit.cpp
@@ -594,14 +594,14 @@ SoSTLFileKit::addFacet(const SbVec3f & v1, const SbVec3f & v2, const SbVec3f & v
SO_GET_ANY_PART(this, "facets", SoIndexedFaceSet);
// find existing indexes if any
- long v1idx = PRIVATE(this)->points->findPoint(v1), v1new = (v1idx == -1);
- long v2idx = PRIVATE(this)->points->findPoint(v2), v2new = (v2idx == -1);
- long v3idx = PRIVATE(this)->points->findPoint(v3), v3new = (v3idx == -1);
- if (!v1new) { v1idx = (long) PRIVATE(this)->points->getUserData(v1idx); }
- if (!v2new) { v2idx = (long) PRIVATE(this)->points->getUserData(v2idx); }
- if (!v3new) { v3idx = (long) PRIVATE(this)->points->getUserData(v3idx); }
- long nidx = PRIVATE(this)->normals->findPoint(n);
- if (nidx != -1) { nidx = (long) PRIVATE(this)->normals->getUserData(nidx); }
+ intmax_t v1idx = PRIVATE(this)->points->findPoint(v1), v1new = (v1idx == -1);
+ intmax_t v2idx = PRIVATE(this)->points->findPoint(v2), v2new = (v2idx == -1);
+ intmax_t v3idx = PRIVATE(this)->points->findPoint(v3), v3new = (v3idx == -1);
+ if (!v1new) { v1idx = (intmax_t) PRIVATE(this)->points->getUserData(v1idx); }
+ if (!v2new) { v2idx = (intmax_t) PRIVATE(this)->points->getUserData(v2idx); }
+ if (!v3new) { v3idx = (intmax_t) PRIVATE(this)->points->getUserData(v3idx); }
+ intmax_t nidx = PRIVATE(this)->normals->findPoint(n);
+ if (nidx != -1) { nidx = (intmax_t) PRIVATE(this)->normals->getUserData(nidx); }
// toss out invalid facets - facets where two or more points are in
// the same location. what are these - are they lines and points or
diff --git a/src/foreignfiles/SoSTLFileKit.cpp.orig b/src/foreignfiles/SoSTLFileKit.cpp.orig
new file mode 100644
index 1111111..2222222
--- /dev/null
+++ b/src/foreignfiles/SoSTLFileKit.cpp.orig
@@ -0,0 +1,799 @@
+/**************************************************************************\
+ *
+ * This file is part of the Coin 3D visualization library.
+ * Copyright (C) by Kongsberg Oil & Gas Technologies.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * ("GPL") version 2 as published by the Free Software Foundation.
+ * See the file LICENSE.GPL at the root directory of this source
+ * distribution for additional information about the GNU GPL.
+ *
+ * For using Coin with software that can not be combined with the GNU
+ * GPL, and for taking advantage of the additional benefits of our
+ * support services, please contact Kongsberg Oil & Gas Technologies
+ * about acquiring a Coin Professional Edition License.
+ *
+ * See http://www.coin3d.org/ for more information.
+ *
+ * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
+ * http://www.sim.no/ [email protected] [email protected]
+ *
+\**************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif // HAVE_CONFIG_H
+
+#ifdef HAVE_NODEKITS
+
+#include <ForeignFiles/SoSTLFileKit.h>
+
+#include <Inventor/SbBasic.h>
+#include <Inventor/lists/SbList.h>
+#include <Inventor/errors/SoDebugError.h>
+#include <Inventor/actions/SoCallbackAction.h>
+#include <Inventor/actions/SoReorganizeAction.h>
+#include <Inventor/nodes/SoSeparator.h>
+#include <Inventor/nodes/SoShapeHints.h>
+#include <Inventor/nodes/SoTexture2.h>
+#include <Inventor/nodes/SoNormal.h>
+#include <Inventor/nodes/SoNormalBinding.h>
+#include <Inventor/nodes/SoMaterial.h>
+#include <Inventor/nodes/SoMaterialBinding.h>
+#include <Inventor/nodes/SoCoordinate3.h>
+#include <Inventor/nodes/SoIndexedFaceSet.h>
+#include <Inventor/nodes/SoInfo.h>
+#include <Inventor/SbBSPTree.h>
+#include <Inventor/SoPrimitiveVertex.h>
+
+#include "steel.h"
+#include "nodekits/SoSubKitP.h"
+
+
+#if 0
+ SoCallback "callbackList" SoBaseKit
+ SoSeparator "topSeparator" SoForeignFileKit
+ SoShapeHints "shapehints" SoSTLFileKit
+ SoTexture2 "texture" SoSTLFileKit
+ SoNormalBinding "normalbinding" SoSTLFileKit
+ SoNormal "normals" SoSTLFileKit
+ SoMaterialBinding "materialbinding" SoSTLFileKit
+ SoMaterial "material" SoSTLFileKit
+ SoCoordinate3 "coordinates" SoSTLFileKit
+ SoIndexedFaceSet "facets" SoSTLFileKit
+#endif // 0
+
+class SoSTLFileKitP {
+public:
+ SoSTLFileKitP(SoSTLFileKit * pub)
+ : api(pub) {
+ this->data = new SbList<uint16_t>;
+ this->points = new SbBSPTree;
+ this->normals = new SbBSPTree;
+ }
+ ~SoSTLFileKitP(void) {
+ delete this->data;
+ delete this->points;
+ delete this->normals;
+ }
+
+public:
+ SoSTLFileKit * const api;
+
+ SbList<uint16_t> * data;
+ SbBSPTree * points;
+ SbBSPTree * normals;
+
+ int numfacets;
+ int numvertices;
+ int numnormals;
+ int numsharedvertices;
+ int numsharednormals;
+ int numredundantfacets;
+}; // SoSTLFileKitP
+
+// *************************************************************************
+
+/*!
+ \class SoSTLFileKit SoSTLFileKit.h ForeignFiles/SoSTLFileKit.h
+ \brief SoSTLFileKit is a class for using STL files with Coin.
+
+ Class for using STL files with Coin. You can use it to read and
+ write STL files, and convert back and forth between Open Inventor
+ scene graphs and SoSTLFileKits.
+
+ STL files are 3D models intended for 3D printers, and is a format
+ supported by a wide variety of computer-aided design programs. STL
+ models are, because of their intended purpose, always
+ representations of solid objects. STL is short for
+ Stereolithography, the process used for 3D printing.
+
+ Ordinary STL models do not contain color information. There are,
+ however, two extensions to the binary file format for specifying
+ color. Currently neither extension is supported. This is caused by
+ lack of sample models using the extensions and will be added as soon
+ as such models are found. We have the specs on the extensions, and
+ it should be pretty straight-forwards to implement, but we want to
+ get it right at once since we have write support (we don't want to
+ inadvertently create a third color extension ;).
+
+ When writing STL files, certain STL model criterias are not enforced
+ by SoSTLFileKit. These are:
+
+ - STL models should represent complete solids - it is the user's
+ responsibility to give models of solid data to readScene(), and
+ not readScene()'s responsibility to check the incoming data.
+
+ - STL models should have all triangles in counterclockwise order.
+ This is not enforced either.
+
+ - STL models should reside in the positive octant of the coordinate
+ space. This is also the user's responsibility to ensure, although
+ adding functionality for translating the model should be easy, so
+ it might get implemented.
+
+ Since the color extensions are not supported yet, color information
+ is not collected either when converting Open Inventor scene graphs to
+ SoSTLFileKits.
+
+ \relates foreignfileformats
+ \COIN_CLASS_EXTENSION
+ \since Coin 3.0
+*/
+
+#define PRIVATE(obj) ((obj)->pimpl)
+
+SO_KIT_SOURCE(SoSTLFileKit)
+
+/*!
+ Initializes class and registers file identification functions.
+*/
+
+void
+SoSTLFileKit::initClass(void)
+{
+ SO_KIT_INIT_CLASS(SoSTLFileKit, SoForeignFileKit, SoForeignFileKit);
+
+ SoType type = SoSTLFileKit::getClassTypeId();
+ SoForeignFileKit::registerFileExtension(type, "stl", SoSTLFileKit::identify);
+}
+
+/*!
+ Returns wether or not \a filename is identified as an STL file.
+*/
+
+SbBool
+SoSTLFileKit::identify(const char * filename)
+{
+ assert(filename);
+ stl_reader * reader = stl_reader_create(filename);
+ if ( !reader ) {
+ return FALSE;
+ }
+ stl_reader_destroy(reader);
+ return TRUE;
+}
+
+/*!
+ Constructor.
+*/
+
+SoSTLFileKit::SoSTLFileKit(void)
+{
+ PRIVATE(this) = new SoSTLFileKitP(this);
+
+ SO_KIT_INTERNAL_CONSTRUCTOR(SoSTLFileKit);
+
+ SO_KIT_ADD_FIELD(info, (""));
+ SO_KIT_ADD_FIELD(binary, (FALSE));
+ SO_KIT_ADD_FIELD(colorization, (SoSTLFileKit::GREY));
+
+ SO_KIT_DEFINE_ENUM_VALUE(Colorization, GREY);
+ SO_KIT_DEFINE_ENUM_VALUE(Colorization, MATERIALISE);
+ SO_KIT_DEFINE_ENUM_VALUE(Colorization, TNO_VISICAM);
+
+ SO_KIT_SET_SF_ENUM_TYPE(colorization, Colorization);
+
+ SO_KIT_ADD_CATALOG_ENTRY(facets, SoIndexedFaceSet,
+ FALSE, topSeparator, \x0, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(coordinates, SoCoordinate3,
+ FALSE, topSeparator, facets, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(material, SoMaterial,
+ FALSE, topSeparator, coordinates, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(materialbinding, SoMaterialBinding,
+ FALSE, topSeparator, material, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(normals, SoNormal,
+ FALSE, topSeparator, materialbinding, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(normalbinding, SoNormalBinding,
+ FALSE, topSeparator, normals, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(texture, SoTexture2,
+ FALSE, topSeparator, normalbinding, FALSE);
+ SO_KIT_ADD_CATALOG_ENTRY(shapehints, SoShapeHints,
+ FALSE, topSeparator, texture, FALSE);
+
+ SO_KIT_INIT_INSTANCE();
+}
+
+/*!
+ Destructor.
+*/
+
+SoSTLFileKit::~SoSTLFileKit(void)
+{
+ delete PRIVATE(this);
+ PRIVATE(this) = NULL;
+}
+
+// doc in inherited class
+SbBool
+SoSTLFileKit::canReadFile(const char * filename) const
+{
+ if ( !filename ) return TRUE; // we can read STL files, in general
+ return SoSTLFileKit::identify(filename);
+}
+
+/*!
+ Reads in an STL file. Both ascii and binary files are supported.
+ For binary files, the color extensions are not implemented yet.
+
+ Returns FALSE if \a filename could not be opened or parsed
+ correctly.
+
+ \sa canReadFile, canWriteScene, writeScene
+*/
+
+SbBool
+SoSTLFileKit::readFile(const char * filename)
+{
+ assert(filename);
+
+ this->reset();
+
+ stl_reader * reader = stl_reader_create(filename);
+ if ( !reader ) {
+ SoDebugError::postInfo("SoSTLFileKit::readFile",
+ "unable to create STL reader for '%s'.",
+ filename);
+ return FALSE;
+ }
+
+ SbBool binary = (stl_reader_flags(reader) & STL_BINARY) ? TRUE : FALSE;
+
+ SoShapeHints * hints =
+ SO_GET_ANY_PART(this, "shapehints", SoShapeHints);
+ hints->vertexOrdering.setValue(SoShapeHints::UNKNOWN_ORDERING);
+ // what it should have been
+ // hints->vertexOrdering.setValue(SoShapeHints::COUNTERCLOCKWISE);
+ hints->shapeType.setValue(SoShapeHints::SOLID);
+ hints->faceType.setValue(SoShapeHints::UNKNOWN_FACE_TYPE);
+
+ SoNormalBinding * normalbinding =
+ SO_GET_ANY_PART(this, "normalbinding", SoNormalBinding);
+ normalbinding->value = SoNormalBinding::PER_FACE_INDEXED;
+
+ stl_facet * facet = stl_facet_create();
+ SbBool loop = TRUE, success = TRUE;
+ while ( loop ) {
+ const int peekval = stl_reader_peek(reader);
+ if ( peekval == STL_BEGIN ) {
+ } else if ( peekval == STL_INIT_INFO ) {
+ // FIXME: set info
+ } else if ( peekval == STL_EXIT_INFO ) {
+ } else if ( peekval == STL_END ) {
+ loop = FALSE;
+ } else if ( peekval == STL_FACET ) {
+ stl_real x, y, z;
+ stl_reader_fill_facet(reader, facet);
+ stl_facet_get_normal(facet, &x, &y, &z);
+ SbVec3f normal((float) x, (float) y, (float) z);
+ stl_facet_get_vertex1(facet, &x, &y, &z);
+ SbVec3f vertex1((float) x, (float) y, (float) z);
+ stl_facet_get_vertex2(facet, &x, &y, &z);
+ SbVec3f vertex2((float) x, (float) y, (float) z);
+ stl_facet_get_vertex3(facet, &x, &y, &z);
+ SbVec3f vertex3((float) x, (float) y, (float) z);
+ if ( normal.length() == 0.0f ) { // auto-calculate
+ SbVec3f v1(vertex2-vertex1);
+ SbVec3f v2(vertex3-vertex1);
+ normal = v1.cross(v2);
+ float len = normal.length();
+ if ( len > 0 ) normal /= len;
+ }
+ unsigned int data = stl_facet_get_padding(facet);
+
+ SbBool added = this->addFacet(vertex1, vertex2, vertex3, normal);
+
+#if defined(COIN_EXTRA_DEBUG) || 1
+ if ( added && binary ) {
+ // binary contains padding, which might be colorization
+ // colorization is not implemented yet, so therefore some debug
+ // output comes here so colorized models can be detected.
+ PRIVATE(this)->data->append((uint16_t) data);
+ if ( data != 0 ) {
+ fprintf(stderr, "facet %5d - data: %04x\n", PRIVATE(this)->numfacets - 1, data);
+ }
+ }
+#endif // COIN_EXTRA_DEBUG
+ } else if ( peekval == STL_ERROR ) {
+ SoDebugError::post("SoSTLFileKit::readFile",
+ "error '%s' after %d facets, line %d.",
+ stl_reader_get_error(reader),
+ PRIVATE(this)->numfacets,
+ stl_reader_get_line_number(reader));
+ loop = FALSE;
+ success = FALSE;
+ if (strcmp(stl_reader_get_error(reader), "premature end of file") == 0) {
+ // this one we will accept though - models with missing
+ // end-indicator have been found...
+ success = TRUE;
+ }
+ }
+ }
+
+ // done - no need for the BSP trees to contain data any more
+ PRIVATE(this)->points->clear();
+ PRIVATE(this)->normals->clear();
+
+ stl_facet_destroy(facet);
+ stl_reader_destroy(reader);
+
+ if ( !success ) {
+ this->reset();
+ } else {
+ this->organizeModel();
+ }
+ return success;
+}
+
+// doc in inherited class
+SbBool
+SoSTLFileKit::canReadScene(void) const
+{
+ return TRUE;
+}
+
+/*!
+ Converts a scene graph into an SoSTLFileKit. Useful for creating
+ STL files.
+
+ \sa canReadScene, canWriteFile, writeFile
+*/
+
+SbBool
+SoSTLFileKit::readScene(SoNode * scene)
+{
+ this->reset();
+
+ scene->ref();
+ SoCallbackAction cba;
+ cba.addTriangleCallback(SoType::fromName("SoNode"), add_facet_cb, this);
+ cba.apply(scene);
+ scene->unrefNoDelete();
+
+ // no need for the BSP trees to contain data any more
+ PRIVATE(this)->points->clear();
+ PRIVATE(this)->normals->clear();
+
+ this->organizeModel();
+
+ return TRUE;
+}
+
+// doc in inherited class
+SbBool
+SoSTLFileKit::canWriteScene(const char * format) const
+{
+ if ( !format ) return TRUE;
+ // FIXME: implement format checking (VRML1, VRML97)
+ return TRUE;
+}
+
+/*!
+ Converts the STL model into a native scene graph.
+
+ \sa canWriteScene
+*/
+
+SbBool
+SoSTLFileKit::writeScene(SoNode *& root, const char * format)
+{
+ static const char default_format[] = "#VRML 1.0"; // syntax for this?
+ if ( !format ) format = default_format;
+
+ SbBool success = true;
+
+ // FIXME: implement format check to specify scene graph setup
+ enum Format {
+ UNKNOWN,
+ VRML1,
+ VRML97
+ };
+
+ Format build = VRML1;
+
+ if ( build == VRML1 ) {
+ // create VRML1 scene
+ SoSeparator * sceneroot = new SoSeparator;
+ sceneroot->ref();
+
+ SoInfo * info = new SoInfo;
+ info->string = "STL model data, created by Coin " COIN_VERSION ".";
+ sceneroot->addChild(info);
+
+ SoShapeHints * shapehints_orig =
+ SO_GET_ANY_PART(this, "shapehints", SoShapeHints);
+ SoShapeHints * shapehints_copy = new SoShapeHints;
+ shapehints_copy->copyContents(shapehints_orig, FALSE);
+ sceneroot->addChild(shapehints_copy);
+
+ SoTexture2 * texture_orig = SO_GET_ANY_PART(this, "texture", SoTexture2);
+ SoTexture2 * texture_copy = new SoTexture2;
+ texture_copy->copyContents(texture_orig, FALSE);
+ sceneroot->addChild(texture_copy);
+
+ SoNormalBinding * normalbinding_orig =
+ SO_GET_ANY_PART(this, "normalbinding", SoNormalBinding);
+ SoNormalBinding * normalbinding_copy = new SoNormalBinding;
+ normalbinding_copy->copyContents(normalbinding_orig, FALSE);
+ sceneroot->addChild(normalbinding_copy);
+
+ SoNormal * normals_orig = SO_GET_ANY_PART(this, "normals", SoNormal);
+ SoNormal * normals_copy = new SoNormal;
+ normals_copy->copyContents(normals_orig, FALSE);
+ sceneroot->addChild(normals_copy);
+
+ SoMaterialBinding * materialbinding_orig =
+ SO_GET_ANY_PART(this, "materialbinding", SoMaterialBinding);
+ SoMaterialBinding * materialbinding_copy = new SoMaterialBinding;
+ materialbinding_copy->copyContents(materialbinding_orig, FALSE);
+ sceneroot->addChild(materialbinding_copy);
+
+ SoMaterial * material_orig = SO_GET_ANY_PART(this, "material", SoMaterial);
+ SoMaterial * material_copy = new SoMaterial;
+ material_copy->copyContents(material_orig, FALSE);
+ sceneroot->addChild(material_copy);
+
+ SoCoordinate3 * coordinates_orig =
+ SO_GET_ANY_PART(this, "coordinates", SoCoordinate3);
+ SoCoordinate3 * coordinates_copy = new SoCoordinate3;
+ coordinates_copy->copyContents(coordinates_orig, FALSE);
+ sceneroot->addChild(coordinates_copy);
+
+ SoIndexedFaceSet * facets_orig =
+ SO_GET_ANY_PART(this, "facets", SoIndexedFaceSet);