File: SoInteractionKit.c++

package info (click to toggle)
inventor 2.1.5-10-21
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 36,312 kB
  • sloc: ansic: 33,864; lisp: 7,361; cpp: 3,874; yacc: 369; sh: 359; perl: 234; awk: 141; makefile: 81; csh: 35; sed: 11
file content (1354 lines) | stat: -rw-r--r-- 43,873 bytes parent folder | download | duplicates (2)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
/*
 *
 *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  Further, this software is distributed without any warranty that it is
 *  free of the rightful claim of any third person regarding infringement
 *  or the like.  Any license provided herein, whether implied or
 *  otherwise, applies only to this software file.  Patent licenses, if
 *  any, provided herein do not apply to combinations of this program with
 *  other software, or any other product whatsoever.
 * 
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 *  Mountain View, CA  94043, or:
 * 
 *  http://www.sgi.com 
 * 
 *  For further information regarding this notice, see: 
 * 
 *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
 *
 */

/*
 * Copyright (C) 1990,91   Silicon Graphics, Inc.
 *
 _______________________________________________________________________
 ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
 |
 |   $Revision: 1.1.1.1 $
 |
 |   Classes:
 |	SoInteractionKit
 |
 |   Author(s): Paul Isaacs, David Mott
 |
 ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
 _______________________________________________________________________
 */


#include <stdio.h>
#include <stdlib.h>
#include <Inventor/SbDict.h>
#include <Inventor/SoDB.h>
#include <Inventor/SoInput.h>
#include <Inventor/SoNodeKitPath.h>
#include <Inventor/errors/SoDebugError.h>
#include <Inventor/nodekits/SoInteractionKit.h>
#include <Inventor/nodekits/SoNodeKitListPart.h>
#include <Inventor/nodes/SoGroup.h>
#include <Inventor/nodes/SoNode.h>
#include <Inventor/nodes/SoLabel.h>
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoSwitch.h>
#include <Inventor/actions/SoSearchAction.h>
#include <Inventor/actions/SoHandleEventAction.h>
#include <Inventor/actions/SoGetBoundingBoxAction.h>

SO_KIT_SOURCE(SoInteractionKit);

////////////////////////////////////////////////////////////////////////
//
// Description:
//    Constructor

SoInteractionKit::SoInteractionKit()
//
////////////////////////////////////////////////////////////////////////
{
    SO_KIT_CONSTRUCTOR(SoInteractionKit);

    isBuiltIn = TRUE;

    // Add a separator to the catalog.
    SO_KIT_ADD_CATALOG_ENTRY(topSeparator, SoSeparator, TRUE, this, ,FALSE);
    SO_KIT_ADD_CATALOG_ENTRY(geomSeparator,SoSeparator, 
				TRUE, topSeparator, ,FALSE);

    SO_KIT_ADD_FIELD(renderCaching,            (AUTO));
    SO_KIT_ADD_FIELD(boundingBoxCaching,       (AUTO));
    SO_KIT_ADD_FIELD(renderCulling,            (AUTO));
    SO_KIT_ADD_FIELD(pickCulling,              (AUTO));

    // Set up static info for enum fields
    SO_KIT_DEFINE_ENUM_VALUE(CacheEnabled, OFF);
    SO_KIT_DEFINE_ENUM_VALUE(CacheEnabled, ON);
    SO_KIT_DEFINE_ENUM_VALUE(CacheEnabled, AUTO);

    // Set up info in enumerated type fields
    SO_KIT_SET_SF_ENUM_TYPE(renderCaching,     CacheEnabled);
    SO_KIT_SET_SF_ENUM_TYPE(boundingBoxCaching,CacheEnabled);
    SO_KIT_SET_SF_ENUM_TYPE(renderCulling,     CacheEnabled);
    SO_KIT_SET_SF_ENUM_TYPE(pickCulling,       CacheEnabled);

    SO_KIT_INIT_INSTANCE();

    surrogatePartPathList = new SoPathList;
    surrogatePartNameList = new SbPList;

    // This sensor will watch the topSeparator part.  If the part changes to a 
    // new node,  then the fields of the old part will be disconnected and
    // the fields of the new part will be connected.
    // Connections are made from/to the renderCaching, boundingBoxCaching,
    // renderCulling and pickCulling fields. This way, the SoInteractionKit
    // can be treated from the outside just like a regular SoSeparator node.
    // Setting the fields will affect caching and culling, even though the
    // topSeparator takes care of it.
    // oldTopSep keeps track of the part for comparison.
    fieldSensor = new SoFieldSensor( &SoInteractionKit::fieldSensorCB, this );
    fieldSensor->setPriority(0);
    oldTopSep = NULL;
    setUpConnections( TRUE, TRUE );
}

////////////////////////////////////////////////////////////////////////
//
// Description:
//    Destructor
//

SoInteractionKit::~SoInteractionKit()
//
////////////////////////////////////////////////////////////////////////
{
    // truncate takes care of unref'ing all the entries
    surrogatePartPathList->truncate(0);
    delete surrogatePartPathList;

    surrogatePartNameList->truncate(0);
    delete surrogatePartNameList;

    if (oldTopSep) {
	oldTopSep->unref();
	oldTopSep = NULL;
    }
    if (fieldSensor)
	delete fieldSensor;
}

////////////////////////////////////////////////////////////////////////
//
// Description:
//    Copies the contents of the given instance into this
//    instance. This copies the surrogatePartPathList and the
//    surrogatePartNameList.
//
// Use: protected, virtual

void
SoInteractionKit::copyContents(const SoFieldContainer *fromFC,
			       SbBool copyConnections)
//
////////////////////////////////////////////////////////////////////////
{
    // Copy the regular node kit stuff
    SoBaseKit::copyContents(fromFC, copyConnections);

    const SoInteractionKit *fromKit = (const SoInteractionKit *) fromFC;

    // calls to setPartAsDefault() will result in some non-NULL parts
    // receiving calls of setDefault(TRUE).   These nodes should not
    // be copied. Rather, they should be instances of the default nodes
    // use in the original.
	const SoNodekitCatalog *cat = getNodekitCatalog();
	SoType prtFldType = SoSFNode::getClassTypeId();

	for (int i = 1; i < cat->getNumEntries(); i++ ) {

	    // Is this part a leaf node?
	    if ( cat->isLeaf(i) ) {

	        // Is the field for this part set to default and also a
		// node-pointer field?
		const SbName partName = cat->getName(i);
		SoField *fld = getField( partName );
		if ( fld->isDefault() && fld->isOfType( prtFldType )) { 

		    // Is it non-NULL? 
		    SoNode *n = ((SoSFNode *) fld)->getValue();
		    if (n != NULL ) {
			// Set part in this to be an instance of the
			// original part. Use setPartAsDefault(), so
			// it also sets the field to default in this.
			setAnyPartAsDefault(partName, n, TRUE, FALSE);
		    }
		}
	    }
	}

    // Now, copy the two surrogate lists...
	(*surrogatePartPathList).copy( (*fromKit->surrogatePartPathList) );
        (*surrogatePartNameList).copy( (*fromKit->surrogatePartNameList) );
}

////////////////////////////////////////////////////////////////////////
//
// Description:
//    Creates dictionary of part names corresponding to different nodes.
//
//    The 'priority' of entries is as follows:
//
//    Anything in 'filename' will definitely be used.
//    Anything in 'defaultBuffer' will be used, if it's not found in
//    'filename'.
//
// Use: protected
//
void
SoInteractionKit::readDefaultParts(const char   *fileName, 
				const unsigned char   defaultBuffer[],
				int defBufSize )
//
////////////////////////////////////////////////////////////////////////
{
    // Next, read the contents of 'defaultBuffer'. 
    // Add the parts found within this to the dictionary.
    SoGroup *bufStuff = readFromBuffer( defaultBuffer, defBufSize );
    if (bufStuff != NULL)
	bufStuff->ref();

    // Next, read the contents of 'fileName'
    // Add the parts found within this to the dictionary.
    SoGroup *fileStuff = readFromFile( fileName );
    if (fileStuff != NULL)
	fileStuff->ref();
}

////////////////////////////////////////////////////////////////////////
//
// Use: public
//
// Description:
//     Sets the part, then sets the field for that part to default.
//     using partField.setDefault(TRUE).
//     Hence 'newNode' becomes the new default value, and the part 
//     only writes if [a] the part is set to a different node. 
//     [b] values are changes in the fields of newNode.
//     [c] any child below newNode changes.
//
// setPartAsDefault will only set parts if the are public.
// Returns FALSE on failure, TRUE otherwise. 
//
// This version sets the part to the given node.
//
////////////////////////////////////////////////////////////////////////
SbBool
SoInteractionKit::setPartAsDefault(const SbName &partName, SoNode *newNode,
				    SbBool onlyIfAlready )
{
    return( setAnyPartAsDefault( partName, newNode, FALSE, onlyIfAlready ) );
}

////////////////////////////////////////////////////////////////////////
//
// Use: public
//
// Description:
//     This overloaded version of setPartAsDefault takes the name
//     of the node as an argument.  It looks the node up in the global
//      dictionary.
//
////////////////////////////////////////////////////////////////////////
SbBool
SoInteractionKit::setPartAsDefault(const SbName &partName, 
			       const SbName &newNodeName, SbBool onlyIfAlready )
{
    return( setAnyPartAsDefault( partName, newNodeName, FALSE, onlyIfAlready ));
}

////////////////////////////////////////////////////////////////////////
//
// Use: protected
//
// Description:
//     Protected versions of these methods that allow you to set non-leaf
//     and/or private parts.
////////////////////////////////////////////////////////////////////////
SbBool 
SoInteractionKit::setAnyPartAsDefault(const SbName &partName, 
			const SbName &newPartName, SbBool anyPart,
			SbBool onlyIfAlready )
{
    // Try to find the given node in the global dictionary.
    SoNode *newNode = SoNode::getByName(newPartName);
    return( setAnyPartAsDefault( partName, newNode, anyPart, onlyIfAlready ));
}
SbBool 
SoInteractionKit::setAnyPartAsDefault(const SbName &partName, 
			SoNode *newNode, SbBool anyPart, SbBool onlyIfAlready )
{
    // Ref ourself while in this routine.
    ref();

    // Find the 'owner' kit. This is the kit (which could be a child of this 
    // one) which is the closest parent above the part.
    SoField   *f;
    SoBaseKit *owner = NULL;
    SbBool happyDone = FALSE;
    SbBool reply = TRUE;

    // If the partName is in our catalog, we are the owner.
    if (getNodekitCatalog()->getPartNumber(partName) 
	    != SO_CATALOG_NAME_NOT_FOUND)
	owner = this;

    if ( onlyIfAlready ) {
	// We have to determine if the part already isDefault()

	// If we're the owner, it's pretty easy to check...
	if ( owner == this ) {
	    f = getField( partName );
	    if ( ! f ||  ! f->isDefault() )
		reply = FALSE;
	}
	else {
	    // Create a path to the part, but use makeIfNeeded of FALSE.
	    // Don't check leaf or public. We just want information.
	    SoNodeKitPath *testP 
		= createPathToAnyPart(partName, FALSE,FALSE,FALSE);
	    if (testP != NULL) {
		testP->ref();

		// Cast to a full path:
		    SoFullPath *fp = (SoFullPath *) testP;
		// The part is the tail of the full path:
		    SoNode *part = fp->getTail();
		    SoNode *tester;
		// Owner is first nodekit above the tail:
		    for (int ind = 1; ind < fp->getLength(); ind ++ ) {
			tester = fp->getNodeFromTail(ind);
			if ( tester->isOfType(SoBaseKit::getClassTypeId()) ) {
			    owner = (SoBaseKit *) tester;
			    break;
			}
		    }

		if (owner == NULL)     // This should never happen...
		    reply = FALSE;
		else {

		    // Determine name of part in the owner's catalog.
		    // If contains '.' character (e.g., "duck.foot.toe")
		    // take LAST word.
		    const char *partStringInOwner;
		    const char *lastDot = strrchr(partName.getString(), '.' );
		    if (lastDot)
			partStringInOwner = lastDot+1;
		    else
			partStringInOwner = partName.getString();

		    // Find out if the part isDefault()
		    f = owner->getField(partStringInOwner);
		    if (! f || ! f->isDefault() )
			reply = FALSE;
		    else if ( ((SoSFNode *)f)->getValue() == newNode ) {
			// We can return successfully!  The part is default,
			// and already equals newNode.
			happyDone = TRUE;
		    }
		}

		testP->unref();
	    }
	    // If path was NULL, the part has not been created, so 
	    // we will allow ourselves to set the part as default. We may
	    // continue...
	}
    }

    // Did we pass the onlyIfAlready test (if we were required to)??
    if ( reply == FALSE ) {
	unrefNoDelete();
	return FALSE;
    }

    // Was the part already there and already default?
    if ( happyDone == TRUE ) {
	unrefNoDelete();
	return FALSE;
    }

    // If we can't set the part, then bag it and return.
    if ( !setAnyPart(partName,   newNode, anyPart )) {
	unrefNoDelete();
	return FALSE;
    }

    // If we still don't know the owner, we've got to find out now...
    if (owner == NULL) {

	// use makeIfNeed of TRUE. We'll set the part back to NULL if 
	// newNode is NULL.
	SoNodeKitPath *nkp = createPathToAnyPart( partName, TRUE,
						 !anyPart, !anyPart );
	if (nkp == NULL)
	    reply = FALSE;
	else {
	    nkp->ref();

	    SoBaseKit *tail = (SoBaseKit *) nkp->getTail();

	    if (tail != newNode)
		owner = (SoBaseKit *) tail;
	    else
		owner = (SoBaseKit *) nkp->getNodeFromTail( 1 );

	    nkp->unref();
	}
    }
    if (owner == NULL)
	reply = FALSE;

    // We got the owner.
    if ( reply ) {
        owner->ref();

	// Determine name of part in the owner's catalog.
	// If contains '.' character (e.g., "duck.foot.toe")
	// take LAST word.
	const char *partStringInOwner;
	const char *lastDot = strrchr(partName.getString(), '.' );
	if (lastDot)
	    partStringInOwner = lastDot+1;
	else
	    partStringInOwner = partName.getString();

	// If newNode is NULL, set it back to NULL now.
	// (remember, we forced part creation when we
	// made the path to find the owner).
	if (newNode == NULL)
	    setAnyPart( partName,NULL,anyPart);

	// call setDefault(TRUE) on the part.
	f = owner->getField(partStringInOwner);
	if (f != NULL)
	    f->setDefault(TRUE);
	else
	    reply = FALSE;

	owner->unref();
    }

    unrefNoDelete();
    return reply;
}

////////////////////////////////////////////////////////////////////////
//
// Description:
//    Creates shared dragger geometry 
//
// Use: protected
//
SoGroup *
SoInteractionKit::readFromFile(const char *fileName)
//
////////////////////////////////////////////////////////////////////////
{
    SoInput	in;

    // Only look for the file if the environment variable is set.
    if ( getenv("SO_DRAGGER_DIR") == NULL )
	return NULL;

    SoGroup *answer = NULL;

#ifdef DRAGGER_DIR_TEST
    fprintf(stderr, "STARTING DIRECTORY LIST\n");
    const SbStringList &startList = SoInput::getDirectories();
    for (int sli = 0; sli < startList.getLength(); sli++ ) {
	fprintf(stderr,"  %s\n", startList[sli]->getString() );
    }
#endif

    // There is a static directory list on the class SoInput.
    // We ONLY want to look in the ones in our SO_DRAGGER_DIR, so
    // we save the list, do our stuff, then restore the list.
	SbStringList dirStrings = SoInput::getDirectories();
	SbStringList savedDirStrings;
	int i;
	for (i = 0; i < dirStrings.getLength(); i++ ) {
	    SbString *newOne = new SbString( dirStrings[i]->getString() );
	    savedDirStrings.append( newOne );
	}

    // Set up the directory list based on the enviroment variable only
	SoInput::clearDirectories();
	in.addEnvDirectoriesLast( "SO_DRAGGER_DIR");

    if ( in.openFile( fileName, TRUE )) {

	// read it on in...
	answer = SoDB::readAll( &in );

	in.closeFile();
    }

    // Restore the old directory list
	SoInput::clearDirectories();
	for ( i = 0; i < savedDirStrings.getLength(); i++ )
	    SoInput::addDirectoryLast( savedDirStrings[i]->getString() );

    // Delete the strings we allocated and truncate the saved list
	for ( i = 0; i < savedDirStrings.getLength(); i++ )
	    delete savedDirStrings[i];
	savedDirStrings.truncate(0);

#ifdef DRAGGER_DIR_TEST
    fprintf(stderr, "ENDING DIRECTORY LIST\n");
    const SbStringList &endList = SoInput::getDirectories();
    for (int eli = 0; eli < endList.getLength(); eli++ ) {
	fprintf(stderr,"  %s\n", endList[eli]->getString() );
    }
#endif

    return answer;
}

////////////////////////////////////////////////////////////////////////
//
// Description:
//    Reads geometry from a set of buffers.
//    Assumes that the last buffer is empty.
//    If the buffer contains numerous scene graphs, puts them all under
//    a common separator.
//
// Use: protected
//
SoGroup *
SoInteractionKit::readFromBuffer(const unsigned char defaultBuffer[], int defBufSize )
//
////////////////////////////////////////////////////////////////////////
{
    SoInput	in;

    if ( defaultBuffer == NULL )
	return NULL;

    in.setBuffer((void *) defaultBuffer, (size_t) defBufSize );

    // read it on in...
    SoSeparator  *root = SoDB::readAll( &in );

    return root;
}

////////////////////////////////////////////////////////////////////////
//
// Use: public
//
SbBool
SoInteractionKit::setPartAsPath( const SbName &partName, SoPath *surrogatePath )
//
////////////////////////////////////////////////////////////////////////
{
    // The last 2 arguments indicate that we can only do this for 
    // leafparts that are also public.
    return( setAnyPartAsPath( partName, surrogatePath, TRUE, TRUE ) );
}

////////////////////////////////////////////////////////////////////////
//
// Use: public
//
SbBool
SoInteractionKit::setAnyPartAsPath( const SbName &partName, 
				    SoPath *surrogatePath,
				    SbBool leafCheck, SbBool publicCheck )
//
////////////////////////////////////////////////////////////////////////
{
    // Try to set the surrogate path to 'surrogatePath'
    // You might not be able to, for example if the part does not exist
    // or if it is not public or not a leaf.
    if ( !setAnySurrogatePath(partName, surrogatePath, leafCheck, publicCheck)){
#ifdef DEBUG
	SoDebugError::post("SoInteractionKit::setPartAsPath",
		"can not set surrogate path for part %s", partName.getString());
#endif
	return FALSE;
    }

    // If you were successful, then 
    // see if you can empty out the part.
    // You might not be able to, for example if the part does not exist
    // or if it is not public or not a leaf.

    // Strategy:
    //1-Get pathToPart, with makeIfNeeded FALSE.
    //2-If (pathToPart == NULL) the part is already NULL, so just return.
    //3-Get the 'partParent' and 'partNode' from pathToPart, then discard path.
    //4-Determine if we can set any part by examining leafCheck & publicCheck
    //5-If 'partParent' is NOT an SoSwitch:
    //  Set the part to NULL and return.
    //6-If 'partParent' IS an SoSwitch:
    //  Setting the part to NULL could screw up the whichChild
    //  numbering. So we won't set part to NULL if we can avoid it.
	//A-If the 'partNode' is exactly of type SoGroup or 
	//  SoSeparator, setPart(partName, freshlyCreatedEmptyOne ); and return.
	//B-If the 'partNode' is a different type, we have to set 
	//  the part to NULL, but to be safe we will change the setting 
	//  of whichChild.
	    //1-If (whichChild > partIndex) decrement by one.
	    //2-Else if (whichChild == partIndex) set to NONE.
	    //3-Else (whichChild < partIndex) so leave alone.
	    //4-Set the part to NULL and return.

    //1-Get pathToPart, with makeIfNeeded FALSE.
	SoNodeKitPath *pathToPart 
	    = SoBaseKit::createPathToAnyPart( partName, FALSE, 
					      leafCheck, publicCheck );

    //2-If (pathToPart == NULL) the part is already NULL, so just return.
	if (pathToPart == NULL)
	    return TRUE;

    //3-Get the 'partParent' and 'partNode' from pathToPart, then discard path.
	pathToPart->ref();
	SoNode *partParent = ((SoFullPath *)pathToPart)->getNodeFromTail(1);
	SoNode *partNode   = ((SoFullPath *)pathToPart)->getTail();
	pathToPart->unref();

    //4-Determine if we can set any part by examining leafCheck & publicCheck
	SbBool anyPart = ( !leafCheck && !publicCheck );

    //5-If 'partParent' is NOT an SoSwitch:
    //  Set the part to NULL and return.
        if ( ! partParent->isOfType(SoSwitch::getClassTypeId() ) )
	    return ( SoBaseKit::setAnyPart( partName, NULL, anyPart ) );

    //6-If 'partParent' IS an SoSwitch:
    //  Setting the part to NULL could screw up the whichChild
    //  numbering. So we won't set part to NULL if we can avoid it.

	//A-If the 'partNode' is exactly of type SoGroup or 
	//  SoSeparator, setPart(partName, freshlyCreatedEmptyOne ); and return.
	    if (partNode->getTypeId() == SoGroup::getClassTypeId())
	        return(SoBaseKit::setAnyPart(partName, new SoGroup, anyPart));
	    if (partNode->getTypeId() == SoSeparator::getClassTypeId())
	        return(SoBaseKit::setAnyPart(partName,new SoSeparator,anyPart));

	//B-If the 'partNode' is a different type, we have to set 
	//  the part to NULL, but to be safe we will change the setting 
	//  of whichChild.

	    SoSwitch *parentSwitch = (SoSwitch *) partParent;
	    int whichChild = parentSwitch->whichChild.getValue();
	    int partIndex = parentSwitch->findChild( partNode );

	    //1-If (whichChild > partIndex) decrement by one.
		if (whichChild > partIndex)
		    parentSwitch->whichChild.setValue( whichChild - 1 );
	    //2-Else if (whichChild == partIndex) set to NONE.
		else if (whichChild == partIndex)
		    parentSwitch->whichChild.setValue( SO_SWITCH_NONE );
	    //3-Else (whichChild < partIndex) so leave alone.
		else {
		}

	    //4-Set the part to NULL and return.
    		return SoBaseKit::setAnyPart( partName, NULL, anyPart );
}

////////////////////////////////////////////////////////////////////////
//
// Use: protected
//
SoNode *
SoInteractionKit::getAnyPart( const SbName &partName, SbBool makeIfNeeded,
			      SbBool leafCheck, SbBool publicCheck )
//
////////////////////////////////////////////////////////////////////////
{
    // Try to get the part:
    SoNode *n;
    n = SoBaseKit::getAnyPart(partName, makeIfNeeded, leafCheck, publicCheck);

    // You might not be able to, for example:
    //    [a] makeIfNeeded == FALSE
    //    [b] part does not exist
    //    [c] we ask it to leafCheck or publicCheck and it fails.
    if ( n == NULL )
	return NULL;

    // If you were successful, then try to set the surrogate path to NULL
    n->ref();
    if ( !setAnySurrogatePath( partName, NULL, leafCheck, publicCheck )) {
#ifdef DEBUG
	SoDebugError::post("SoInteractionKit::getAnyPart",
		"can not set surrogate path to NULL for part %s",
		partName.getString() );
#endif
    }
    n->unref();

    return n;
}

////////////////////////////////////////////////////////////////////////
//
// Use: protected
//
SoNodeKitPath *
SoInteractionKit::createPathToAnyPart( const SbName &partName, 
			SbBool makeIfNeeded, SbBool leafCheck, 
			SbBool publicCheck, const SoPath *pathToExtend )
//
////////////////////////////////////////////////////////////////////////
{
    // Try to create a path to the part:
    SoNodeKitPath  *answerPath = SoBaseKit::createPathToAnyPart(
		    		    partName, makeIfNeeded, leafCheck, 
				    publicCheck, pathToExtend );

    // You might not be able to, for example:
    //    [a] makeIfNeeded == FALSE
    //    [b] part does not exist
    //    [c] we ask it to leafCheck or publicCheck and it fails.
    if ( answerPath == NULL )
	return NULL;

    // If you were successful, then try to set the surrogate path to NULL
    answerPath->ref();
    if ( !setAnySurrogatePath( partName, NULL, leafCheck, publicCheck )) {
#ifdef DEBUG
	SoDebugError::post("SoInteractionKit::createPathToAnyPart",
		"can not set surrogate path to NULL for part %s",
		partName.getString() );
#endif
    }
    answerPath->unrefNoDelete();

    return answerPath;
}

////////////////////////////////////////////////////////////////////////
//
// Use: protected
//
SbBool
SoInteractionKit::setAnyPart( const SbName &partName, SoNode *from,
			      SbBool anyPart )
//
////////////////////////////////////////////////////////////////////////
{
    // Try to create set the part:
    // You might not be able to, for example:
    //    [a] part does not exist
    //    [b] anyPart is FALSE and the part is a leaf or non-public.
    if ( !SoBaseKit::setAnyPart( partName, from, anyPart ))
	return FALSE;

    // Temporary ref
    if (from)
	from->ref();

    // If you were successful, then try to set the surrogate path to NULL
    SbBool success = TRUE;
    if ( !setAnySurrogatePath( partName, NULL, !anyPart, !anyPart )) {
#ifdef DEBUG
	SoDebugError::post("SoInteractionKit::setAnyPart",
		"can not set surrogate path to NULL for part %s",
		partName.getString() );
#endif
	success = FALSE;
    }

    // Undo temporary ref
    if (from)
	from->unref();
    return success;
}

////////////////////////////////////////////////////////////////////////
//
// Use: protected
//
SbBool
SoInteractionKit::setAnySurrogatePath( const SbName &partName, 
			SoPath *from, SbBool leafCheck, SbBool publicCheck )
//
////////////////////////////////////////////////////////////////////////
{
    // Strategy:
    //   [-2] If 'partName' is in this catalog, just call 
    //        setMySurrogatePath and return.
    //   [-1] If 'from' is NULL, and partName is not directly in this catalog,
    //        determine which of our leaf nodes is on the way to the part.
    //        This will be either a nodekit or a list part.
    //        If this 'intermediary' has not been created yet, then we
    //        can just return.  This is because if the intermediary is NULL,
    //        then the part below it can have no value as of yet. So we don't
    //        need to bother removing it's surrogate path (which is what 
    //        we do when 'from' is NULL.
    //   [0] Temporarily ref 'from' and 'this'
    //       We need to ref 'this' because creating a path refs this,
    //       and this can get called from within constructors since
    //       it's called from within setPart(), getPart(), etc.
    //   [1] get partPath, which leads down to the part.
    //       First time, use 'makeIfNeeded' of FALSE.
    //       That's how we'll find out if there was something there to start.
    //
    //   [2] If (partPath == NULL), call it again with 'makeIfNeeded' of TRUE,
    //       but remember that we must NULL out the part when we are finished.
    //
    //   [3] Now we've got a path from 'this' down to the part.
    //       Find 'owner', the first InteractionKit above the part in the 
    //       partPath. 
    //       Note:   'owner' might not == this.
    //   [4] Find the 'nameInOwner' the name of the part within 'owner'
    //   [5] Tell 'owner' to use the given path 'from' as its surrogate 
    //       path for 'nameInOwner'
    //   [6] If you need to, remember to set the node-part back to NULL
    //   [8] Undo temporary ref of 'from' and 'this'

    //   [-2] If 'partName' is in this catalog, just call 
    //        setMySurrogatePath and return.
	const SoNodekitCatalog *cat = getNodekitCatalog();
	int partNum = cat->getPartNumber( partName );
	if ( partNum != SO_CATALOG_NAME_NOT_FOUND ) {
	    if ( leafCheck && (cat->isLeaf(partNum) == FALSE) )
		return FALSE;
	    if ( publicCheck && (cat->isPublic(partNum) == FALSE) )
		return FALSE;
	    setMySurrogatePath(partName, from);
	    return TRUE;
	}

    //   [-1] If 'from' is NULL, and partName is not directly in this catalog,
    //        determine which of our leaf nodes is on the way to the part.
    //        This will be either a nodekit or a list part.
    //        If this 'intermediary' has not been created yet, then we
    //        can just return.  This is because if the intermediary is NULL,
    //        then the part below it can have no value as of yet. So we don't
    //        need to bother removing its surrogate path (which is what 
    //        we do when 'from' is NULL.
	if (from == NULL) {

	    // See if there's a '.' and/or a '[' in the partName.
	    // (as in "childList[0].appearance")
	    // If so, get the string up to whichever came first.
	    // This will be the 'intermediary' we look for.
	    const char *dotPtr   = strchr( partName.getString(), '.' );
	    const char *brackPtr = strchr( partName.getString(), '[' );

	    if ( dotPtr != NULL || brackPtr != NULL ) {
		char *nameCopy = strdup( partName.getString() );
		char *firstName;
		if (dotPtr == NULL)
		    firstName = strtok( nameCopy, "[");
		else if (brackPtr == NULL || dotPtr < brackPtr)
		    firstName = strtok( nameCopy, ".");
		else 
		    firstName = strtok( nameCopy, "[");

		// Okay, look for the part, then free the string copy.
		int firstPartNum = cat->getPartNumber( firstName );

		SoNode *firstPartNode = NULL; 
		if ( firstPartNum != SO_CATALOG_NAME_NOT_FOUND ) {
		    // Check if the part is there.
		    // 2nd arg is FALSE, 'cause we don't want to create part.
		    // 3rd arg is TRUE 'cause this better be a leaf.
		    firstPartNode = SoBaseKit::getAnyPart( firstName, 
						FALSE, TRUE, publicCheck );
		}
		free (nameCopy);

		// If the intermediary doesn't exist, return TRUE
		if (firstPartNode == NULL)
		    return TRUE;
	    }
	}


    //   [0] Temporarily ref 'from' and 'this'
	if (from) from->ref();
	ref();

    //   [1] get partPath, which leads down to the part.
    //       First time, use 'makeIfNeeded' of FALSE.
    //       That's how we'll find out if there was something there to start.
	SbBool        makeIfNeeded = FALSE;
	SoNodeKitPath *partPath    = NULL;

	partPath = SoBaseKit::createPathToAnyPart( partName, makeIfNeeded, 
					           leafCheck, publicCheck );

    //   [2] If (partPath == NULL), call it again with 'makeIfNeeded' of TRUE,
    //       but remember that we must NULL out the part when we are finished.
	if (partPath == NULL) {
	    // Try again, this time with 'makeIfNeeded' TRUE
	    makeIfNeeded = TRUE;
	    partPath = SoBaseKit::createPathToAnyPart( partName, makeIfNeeded, 
					           leafCheck, publicCheck );
	}
	if (partPath == NULL) {
	    // This would happen if leafCheck or publicCheck were TRUE
	    // and the check failed.
#ifdef DEBUG
	    SoDebugError::post("SoInteractionKit::setAnySurrogatePath",
		"can not get a part path for part %s", partName.getString());
#endif
	    // Undo temporary ref of 'from' and 'this'
	    if (from) from->unref();
	    unrefNoDelete();
	    return FALSE;
	}
	else
	    partPath->ref();

    //   [3] Now we've got a path from 'this' down to the part.
    //       Find 'owner', the first InteractionKit above the part in the 
    //       partPath. 
    //       Note:   'owner' might not == this.
	SoInteractionKit *owner = NULL;
	for (int i = partPath->getLength() - 1;  i >= 0; i-- ) {
	    SoNode *n = partPath->getNode(i);
	    if ( n != ((SoFullPath *)partPath)->getTail() &&
		 n->isOfType( SoInteractionKit::getClassTypeId() ) ) {
		    owner = (SoInteractionKit *) n;
		    owner->ref();
		    break;
	    }
	}
	if ( owner == NULL ) {
	    partPath->unref();
	    // Undo temporary ref of 'from' and this.
	    if (from) from->unref();
	    unrefNoDelete();
	    return FALSE;
	}

    //   [4] Find the 'nameInOwner' the name of the part within 'owner'
	SbName nameInOwner = owner->getPartString( partPath );
	
    //   [5] Tell 'owner' to use the given path 'from' as its surrogate 
    //       path for 'nameInOwner'
    //       Use setMySurrogatePath for this...
	owner->setMySurrogatePath(nameInOwner,from);

    //   [6] If you need to, remember to set the node-part back to NULL
	SbBool success = TRUE;
	if (makeIfNeeded == TRUE) {
	    SbBool anyPart = ( !leafCheck && !publicCheck );
	    if ( !SoBaseKit::setAnyPart( partName, NULL, anyPart ) )
		success = FALSE;
	}

	owner->unref();
	partPath->unref();

    //   [8] Undo temporary ref of 'from' and 'this'
	if (from) from->unref();
	unrefNoDelete();

	return success;
}

////////////////////////////////////////////////////////////////////////
//
// Assumes that this node is the 'owner' of the surrogate part.
// That is, it is the first InteractionKit above the part.
//
// This means that 'name' is registered in this node's catalog,
// or if the name is 'listName[#]', then listName is in the catalog.
//
// Passing a value of NULL for newPath has the effect of removing 
// this part from the surrogate path lists.
//
// Use: private
//
void
SoInteractionKit::setMySurrogatePath( const SbName &name, SoPath *newPath )
//
////////////////////////////////////////////////////////////////////////
{
    int index = surrogatePartNameList->find( (void *) name.getString() );
    if ( index != -1 ) {
	// an entry already exists for this part name. So we need to remove
	// the old entry before adding the new one.
	surrogatePartNameList->remove( index );
	surrogatePartPathList->remove( index );
    }

    // Now append the new entry.
    if ( newPath != NULL ) {
	surrogatePartNameList->append( (void *) name.getString() );
	surrogatePartPathList->append( newPath );
    }
}

////////////////////////////////////////////////////////////////////////
//
// Use: EXTENDER public
//
SbBool
SoInteractionKit::isPathSurrogateInMySubgraph( const SoPath *pathToCheck )
//
////////////////////////////////////////////////////////////////////////
{
    SoPath *pathToOwner, *pathInOwner;
    SbName  nameInOwner;

    return( isPathSurrogateInMySubgraph( pathToCheck, pathToOwner,
				       nameInOwner, pathInOwner, FALSE ));
}

////////////////////////////////////////////////////////////////////////
//
// Use: EXTENDER public
//
SbBool
SoInteractionKit::isPathSurrogateInMySubgraph( const SoPath *pathToCheck,
		       SoPath *&pathToOwner, SbName  &surrogateNameInOwner,
		       SoPath *&surrogatePathInOwner, SbBool fillArgs )
//
////////////////////////////////////////////////////////////////////////
{
    // Search inside this kit and each InteractionKit below.
    // See if they have a surrogate path that is wholely contained within
    // pathToCheck.
    // The first time you find one, fill in the info and return.

    // Get the paths to the InteractionKits
	static SoSearchAction *searchAction = NULL;
	if (searchAction == NULL)
	    searchAction = new SoSearchAction;
	else
	    searchAction->reset();
	searchAction->setType( SoInteractionKit::getClassTypeId() );
	searchAction->setInterest( SoSearchAction::ALL );
	SbBool oldNkVal = SoBaseKit::isSearchingChildren();
	SoBaseKit::setSearchingChildren( TRUE );
	searchAction->apply(this);
	SoBaseKit::setSearchingChildren( oldNkVal );

	SoPathList ownerPaths = searchAction->getPaths();

    // Start at the end and work backwards.
    // More likely to find a closer match this way...
    // For each path:
	for (int i = ownerPaths.getLength() - 1; i >= 0; i-- ) {

	    // Get the potential owner:
		SoPath *ownerPath = ownerPaths[i];
		SoInteractionKit *owner 
		    = (SoInteractionKit *) ((SoFullPath *)ownerPath)->getTail();

	    // See if the potential owner is in fact the owner...
		int surrogateNum = owner->indexOfSurrogateInMyList(pathToCheck);

	    // If it's the owner, we've succeeded and should return.
		if ( surrogateNum != -1 ) {
		    if (fillArgs == TRUE) {
			pathToOwner = ownerPath->copy();
			surrogateNameInOwner = (char *) 
			      (*(owner->surrogatePartNameList))[surrogateNum];
			surrogatePathInOwner =
			      (*(owner->surrogatePartPathList))[surrogateNum];
		    }
		    return TRUE;
		}
	}

    // Return FALSE if you could not find an owner.
	return FALSE;
}

////////////////////////////////////////////////////////////////////////
//
// Use: private
//
int
SoInteractionKit::indexOfSurrogateInMyList( const SoPath *pathToCheck )
//
////////////////////////////////////////////////////////////////////////
{
    if (pathToCheck == NULL)
	return -1;

    // Check each of the surrogate paths...
    for ( int i = 0; i < surrogatePartPathList->getLength(); i++ ) {

	// If the pathToCheck contains the surrogate path, we're okay!
	if ( pathToCheck->containsPath( (*surrogatePartPathList)[i] ) )
	    return i;
    }
    return -1; // no match found
}

////////////////////////////////////////////////////////////////////////
//
// Use: EXTENDER public, static
//
void
SoInteractionKit::setSwitchValue( SoNode *n, int newVal )
//
////////////////////////////////////////////////////////////////////////
{
    if ( n != NULL ) {
	if  (n->getTypeId() == SoSwitch::getClassTypeId()) {
	    SoSwitch *sw = (SoSwitch *) n;
	    if (sw->whichChild.getValue() != newVal && 
		sw->getNumChildren() > newVal )
		sw->whichChild.setValue( newVal );
	}
    }
}

////////////////////////////////////////////////////////////////////////
//
// Description:
//    overrides method in SoNode to return FALSE.
//    Since there is a separator as the top child of the dragger.
//
// Use: public
//
SbBool
SoInteractionKit::affectsState() const
{
    return FALSE;
}

//    detach/attach any sensors, callbacks, and/or field connections.
//    Called by:            start/end of SoBaseKit::readInstance
//    and on new copy by:   start/end of SoBaseKit::copy.
//    Classes that redefine must call setUpConnections(TRUE,TRUE) 
//    at end of constructor.
//    Returns the state of the node when this was called.
SbBool
SoInteractionKit::setUpConnections( SbBool onOff, SbBool doItAlways )
{
    if ( !doItAlways && connectionsSetUp == onOff)
	return onOff;

    if ( onOff ) {

	// We connect AFTER base class.
	SoBaseKit::setUpConnections( onOff, FALSE );

	// Hookup the field-to-field connections on topSeparator.
	connectSeparatorFields( oldTopSep, TRUE );

	// Call sensor CBs to make sure oldTopSep is up-to-date
	fieldSensorCB( this, NULL );

	// Connect the field sensors
	if (fieldSensor->getAttachedField() != &topSeparator)
	    fieldSensor->attach( &topSeparator );
    }
    else {

	// We disconnect BEFORE base class.

	// Disconnect the field sensors.
	if (fieldSensor->getAttachedField())
	    fieldSensor->detach();

	// Undo the field-to-field connections on topSeparator.
        connectSeparatorFields( oldTopSep, FALSE );

	SoBaseKit::setUpConnections( onOff, FALSE );
    }

    return !(connectionsSetUp = onOff);
}

SbBool
SoInteractionKit::readInstance( SoInput *in, unsigned short flags )
{
    // Start with base kit functionality...
	SbBool answer = SoBaseKit::readInstance(in, flags);

    // Any part that is set to a non-NULL value should not have a corresponding
    // entry in the surrogate part list.
    // The exception would be a part that is an empty group or an empty
    // separator node.  These can stay.

    // Run through every name in the surrogatePartNameList.
	char   *theName;
	SoNode *thePart;
	for ( int i = 0; i < surrogatePartNameList->getLength(); i++ ) {

	    theName = (char *) (*surrogatePartNameList)[i];

	    // Check if a part exists for it. 
		thePart = SO_CHECK_ANY_PART( this, theName, SoNode );

	    // If the part is NULL or an empty group or an empty separator, 
	    // the surrogate path can stay. Otherwise, remove it.
		SbBool removeSurrogate = TRUE;
		if (thePart == NULL)
		    removeSurrogate = FALSE;
		else if ( thePart->getTypeId() == SoGroup::getClassTypeId() ) {
		    if ( ((SoGroup *)thePart)->getNumChildren() == 0 )
			removeSurrogate = FALSE;
		}
		else if(thePart->getTypeId() == SoSeparator::getClassTypeId() ){
		    if ( ((SoSeparator *)thePart)->getNumChildren() == 0 )
			removeSurrogate = FALSE;
		}

	    // Remove the name and path if necessary.
		if (removeSurrogate == TRUE) {
		    surrogatePartNameList->remove( i );
		    surrogatePartPathList->remove( i );
		}
	}

    return answer;
}

void
SoInteractionKit::connectSeparatorFields( SoSeparator *dest, SbBool onOff )
{
    if (dest == NULL)
	return;
    if (onOff) {
	SoField *f;
	if ( ! dest->renderCaching.getConnectedField(f) ||
	       f != &renderCaching )
	    dest->renderCaching.connectFrom( &renderCaching );
	if ( ! dest->boundingBoxCaching.getConnectedField(f) ||
	       f != &boundingBoxCaching )
	    dest->boundingBoxCaching.connectFrom( &boundingBoxCaching );
	if ( ! dest->renderCulling.getConnectedField(f) ||
	       f != &renderCulling )
	    dest->renderCulling.connectFrom( &renderCulling );
	if ( ! dest->pickCulling.getConnectedField(f) ||
	       f != &pickCulling )
	    dest->pickCulling.connectFrom( &pickCulling );
    }
    else {
	dest->renderCaching.disconnect();
	dest->boundingBoxCaching.disconnect();
	dest->renderCulling.disconnect();
	dest->pickCulling.disconnect();
    }
}

void
SoInteractionKit::fieldSensorCB( void *inKit, SoSensor *)
{
    SoInteractionKit *k  = (SoInteractionKit *) inKit;
    if ( k->oldTopSep == k->topSeparator.getValue())
	return;

    k->connectSeparatorFields( k->oldTopSep, FALSE );

    SoNode *newTopSep = k->topSeparator.getValue();
    if (newTopSep)
	newTopSep->ref();

    if (k->oldTopSep)
	k->oldTopSep->unref();

    k->oldTopSep = (SoSeparator *) newTopSep;
    k->connectSeparatorFields( k->oldTopSep, TRUE );
}

/////////////////////////////////////////////////////////////////////////
//
// Called by the SoBaseKit::write() method. 
//
// InteractionKits don't want to write fields if they have default vals.
//
// Calls setDefault(TRUE) on caching fields if default and not 
// connected.
//
// Calls setDefault(TRUE) on the topSeparator. 
// Calls setDefault(TRUE) on the geomSeparator. 
// 
// Calls setDefault(TRUE) on any non-leaf part of type exactly == SoSwitch.
// Subclasses can override this if they like, since the function is virtual.
// But interactionKits use non-leaf switches to turn parts on and off, and 
// this does not need to be written to file.
//
// Lastly, calls same method on SoBaseKit.
//
// NOTE: Parts which are set to default may still wind up writing to file 
//       if, for example, they lie on a path.
/////////////////////////////////////////////////////////////////////////
void
SoInteractionKit::setDefaultOnNonWritingFields()
{

// Here's a little macro to test the field value against another node and
// also make sure there's no active connection.
#define __SO_FCHECK( f, v )                                 \
	  ( ! (f.isConnected() && f.isConnectionEnabled())  \
	    && f.getValue() == v )

    // Calls setDefault(TRUE) on caching fields if default and not 
    // connected.
	if ( __SO_FCHECK( renderCaching, SoInteractionKit::AUTO ) )
			  renderCaching.setDefault(TRUE);
	if ( __SO_FCHECK( boundingBoxCaching, SoInteractionKit::AUTO ) )
			  boundingBoxCaching.setDefault(TRUE);
	if ( __SO_FCHECK( renderCulling, SoInteractionKit::AUTO ) )
			  renderCulling.setDefault(TRUE);
	if ( __SO_FCHECK( pickCulling, SoInteractionKit::AUTO ) )
			  pickCulling.setDefault(TRUE);

#undef __SO_FCHECK

    // Calls setDefault(TRUE) on the topSeparator. 
	topSeparator.setDefault(TRUE);
	geomSeparator.setDefault(TRUE);


    // Calls setDefault(TRUE) on any non-leaf part of type exactly == SoSwitch.
	const SoNodekitCatalog *cat = getNodekitCatalog();
	int   numParts = cat->getNumEntries();

	for (int i = 1; i < numParts; i++ ) {

	    // The part should not be a leaf.
		if ( cat->isLeaf(i) )
		    continue;

		SoSFNode *fld = (SoSFNode *) getField( cat->getName(i) );
		SoNode   *n   = fld->getValue();

	    // set to default if node is NULL
		if (n == NULL ) {
		    fld->setDefault(TRUE);
		    continue;
		}

	    // set to default if node is exactly an SoSwitch.
		if ( n->getTypeId() == SoSwitch::getClassTypeId()) {
		    fld->setDefault(TRUE);
		    continue;
		}
	}

    // Call the base class...
        SoBaseKit::setDefaultOnNonWritingFields();
}