Debian Codegraph @

lib/interaction/src/SoSelection.c++

raw
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990-93 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.2 $
44 |
45 | Classes:
46 | SoSelection
47 |
48 | Authors: David Mott, Paul Isaacs, Thaddeus Beier
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54
55 #include <X11/Xlib.h>
56
57 #include <Inventor/SoDB.h>
58 #include <Inventor/SoInput.h>
59 #include <Inventor/SoInteraction.h>
60 #include <Inventor/SoLists.h>
61 #include <Inventor/SoOutput.h>
62 #include <Inventor/SoPickedPoint.h>
63 #include <Inventor/actions/SoGLRenderAction.h>
64 #include <Inventor/actions/SoHandleEventAction.h>
65 #include <Inventor/actions/SoSearchAction.h>
66 #include <Inventor/actions/SoWriteAction.h>
67 #include <Inventor/errors/SoDebugError.h>
68 #include <Inventor/events/SoEvent.h>
69 #include <Inventor/events/SoMouseButtonEvent.h>
70 #include <Inventor/fields/SoFieldData.h>
71 #include <Inventor/misc/SoCallbackList.h>
72 #include <Inventor/nodes/SoSelection.h>
73 #include <Inventor/nodes/SoSubNode.h>
74
75
76 SO_NODE_SOURCE(SoSelection);
77
78 SoSearchAction *SoSelection::searchAction = NULL;
79
80
81 ////////////////////////////////////////////////////////////////////////
82 //
83 // Description:
84 // Constructor initialization
85 //
86 // Use: private
87 //
88 void
89 SoSelection::constructorCommon()
90 //
91 ////////////////////////////////////////////////////////////////////////
92 {
93 SO_NODE_CONSTRUCTOR(SoSelection);
94 SO_NODE_ADD_FIELD(policy, (SoSelection::SHIFT));
95
96 // Set up static info for enumerated type field
97 SO_NODE_DEFINE_ENUM_VALUE(Policy, SINGLE);
98 SO_NODE_DEFINE_ENUM_VALUE(Policy, TOGGLE);
99 SO_NODE_DEFINE_ENUM_VALUE(Policy, SHIFT);
100
101 // Set up info in enumerated type field
102 SO_NODE_SET_SF_ENUM_TYPE(policy, Policy);
103
104 isBuiltIn = TRUE;
105
106 // selection callback functions and user data
107 selCBList = NULL;
108 deselCBList = NULL;
109 startCBList = NULL;
110 finishCBList = NULL;
111 changeCBList = NULL;
112
113 pickCBFunc = NULL;
114 pickCBData = NULL;
115
116 mouseDownPickPath = NULL;
117 pickMatching = TRUE;
118 }
119
120 ////////////////////////////////////////////////////////////////////////
121 //
122 // Description:
123 // Constructors
124 //
125 // Use: public
126 //
127 SoSelection::SoSelection()
128 {
129 constructorCommon();
130 }
131
132 SoSelection::SoSelection(int numChildren)
133 : SoSeparator(numChildren)
134 {
135 constructorCommon();
136 }
137
138 ////////////////////////////////////////////////////////////////////////
139 //
140 // Description:
141 // Destructor.
142 //
143 // Use: protected
144
145 SoSelection::~SoSelection()
146 //
147 ////////////////////////////////////////////////////////////////////////
148 {
149 delete selCBList;
150 delete deselCBList;
151 delete startCBList;
152 delete finishCBList;
153 delete changeCBList;
154
155 if (mouseDownPickPath != NULL)
156 mouseDownPickPath->unref();
157 }
158
159 ////////////////////////////////////////////////////////////////////////
160 //
161 // Description:
162 // Traversal for event handling. The parent class SoSeparator is called
163 // to traverse the children. If the event is not handled by any children,
164 // then handle it here by invoking the current selection policy.
165 // Calls action->setHandled() if the event was handled.
166 //
167 // Use: protected
168
169 void
170 SoSelection::handleEvent(SoHandleEventAction *action)
171 //
172 ////////////////////////////////////////////////////////////////////////
173 {
174 // let SoSeparator traverse the children
175 SoSeparator::handleEvent(action);
176
177 // On Button1 press, see who got picked.
178 // On Button1 release, see who got picked.
179 // If pick-matching is on, and they match,
180 // then select the object that got picked.
181 //??? this event should be programmer configurable! translation tables?
182 const SoEvent *event = action->getEvent();
183 if (! event->isOfType(SoMouseButtonEvent::getClassTypeId()))
184 return;
185
186 const SoMouseButtonEvent *be = (const SoMouseButtonEvent *) event;
187 if (be->getButton() != SoMouseButtonEvent::BUTTON1)
188 return;
189
190 if ((pickMatching && (be->getState() == SoButtonEvent::DOWN)) ||
191 (be->getState() == SoButtonEvent::UP)) {
192 //??? change the action so we only pick the FIRST thing, not a list?
193 const SoPickedPoint *pickedPoint = action->getPickedPoint();
194 SoPath *pickPath = NULL;
195
196 // Get the pick path
197 if (pickedPoint != NULL) {
198 // If the pick callback exists, let it tell us what path to pick
199 if (pickCBFunc != NULL) {
200 if (callPickCBOnlyIfSelectable) {
201 // Make sure pick passes through this
202 if (pickedPoint->getPath()->containsNode(this))
203 pickPath = (*pickCBFunc)(pickCBData, pickedPoint);
204 }
205 else pickPath = (*pickCBFunc)(pickCBData, pickedPoint);
206 }
207 // Else no pick CB - use the picked path as is.
208 else pickPath = pickedPoint->getPath();
209 }
210
211 // For button press, save the pick path whether a child
212 // handled the event or not - we may get a crack at the
213 // button release event later.
214 if (be->getState() == SoButtonEvent::DOWN) {
215 if (mouseDownPickPath != NULL)
216 mouseDownPickPath->unref(); // out with the old...
217
218 mouseDownPickPath = copyFromThis(pickPath);
219
220 if (mouseDownPickPath != NULL) {
221 mouseDownPickPath->ref(); // ...in with the new
222 action->setHandled();
223 }
224 }
225 // Else button release.
226 // If no children handled the event during SoSeparator::handleEvent()
227 // traversal, handle it here.
228 else if (! action->isHandled()) {
229 // For button release, get the pick path and see if it matches
230 // the button press pick path.
231 //
232 // If they match, invoke the selection policy.
233 // If they do NOT match, do nothing.
234
235 if (pickPath == NULL) {
236 // If nothing was picked, pass NULL to invokeSelectionPolicy.
237 if ((! pickMatching) || (mouseDownPickPath == NULL)) {
238 invokeSelectionPolicy(NULL, be->wasShiftDown());
239 action->setHandled();
240 }
241 // else paths do not match - ignore event
242 }
243 else {
244 pickPath->ref();
245
246 if ((! pickMatching) || (mouseDownPickPath != NULL)) {
247 // Mouse down pick hit something.
248 // Was it same as mouse up pick?
249 // See if the pick path passes through this node
250 SoPath *mouseUpPickPath = copyFromThis(pickPath);
251 if (mouseUpPickPath != NULL) {
252 mouseUpPickPath->ref();
253
254 // If paths match, invoke the selection policy.
255 if ((! pickMatching) ||
256 (*mouseDownPickPath == *mouseUpPickPath)) {
257 if (mouseUpPickPath->getLength() == 1) {
258 // Path is to ONLY the selection node.
259 // Act as if nothing were picked, but
260 // allow traversal to continue.
261 invokeSelectionPolicy(NULL, be->wasShiftDown());
262 }
263 else {
264 // Alter selection and halt traversal.
265 invokeSelectionPolicy(mouseUpPickPath,
266 be->wasShiftDown());
267 action->setHandled();
268 }
269 }
270 // else paths do not match - ignore event
271
272 mouseUpPickPath->unref();
273 }
274 // else path does not pass through this node - ignore event
275 }
276 // else paths do not match - ignore event
277
278 pickPath->unref();
279 }
280
281 // All done with mouse down pick path
282 if (mouseDownPickPath != NULL) {
283 mouseDownPickPath->unref();
284 mouseDownPickPath = NULL;
285 }
286 }
287 }
288 }
289
290 ////////////////////////////////////////////////////////////////////////
291 //
292 // Description:
293 // invoke the appropriate routine which implements the current
294 // selection policy.
295 //
296 // Use: protected
297 //
298 void
299 SoSelection::invokeSelectionPolicy(SoPath *path, SbBool shiftDown)
300 //
301 ////////////////////////////////////////////////////////////////////////
302 {
303 // employ the current selection policy
304 switch (policy.getValue()) {
305 case SINGLE:
306 performSingleSelection(path);
307 break;
308 case TOGGLE:
309 performToggleSelection(path);
310 break;
311 case SHIFT:
312 if (shiftDown)
313 performToggleSelection(path); // SHIFT DOWN
314 else performSingleSelection(path); // NO SHIFT
315 break;
316 default:
317 #ifdef DEBUG
318 SoDebugError::post("SoSelection::invokeSelectionPolicy",
319 "Unknown selection policy %d", policy.getValue());
320 #endif
321 break;
322 }
323 }
324
325 ////////////////////////////////////////////////////////////////////////
326 //
327 // Description:
328 // clear the selection, then select the picked object.
329 // if no object is picked, then nothing is selected.
330 // only one object may be selected at a time. The passed path should have
331 // already been copied (i.e. we just store it!)
332 //
333 // Use: protected
334 //
335 void
336 SoSelection::performSingleSelection(SoPath *path)
337 //
338 ////////////////////////////////////////////////////////////////////////
339 {
340 SbBool needFinishCB = FALSE;
341
342 // let app know (if and only if) user is changing the selection
343 if ((getNumSelected() > 0) || (path != NULL)) {
344 if (startCBList != NULL)
345 startCBList->invokeCallbacks(this);
346 needFinishCB = TRUE;
347 }
348
349 if (path == NULL) {
350 deselectAll();
351 }
352 else {
353 if (isSelected(path)) {
354 // Deselect everything except the given path.
355 // This avoids deselecting and then selecting the same thing.
356 int which = selectionList.findPath(*path);
357 if (which != -1) {
358 for (int i = selectionList.getLength() - 1; i >= 0; i--) {
359 if (i != which)
360 removePath(i);
361 }
362 }
363 }
364 else {
365 deselectAll();
366 addPath(path);
367 }
368 }
369
370 // let app know user is done changing the selection
371 if (needFinishCB) {
372 if (finishCBList != NULL)
373 finishCBList->invokeCallbacks(this);
374 }
375 }
376
377 ////////////////////////////////////////////////////////////////////////
378 //
379 // Description:
380 // picking on an object toggles that objects selection status.
381 // multiple objects may be selected. The passed path should have
382 // already been copied (i.e. we just store it!)
383 //
384 // Use: protected
385 //
386 void
387 SoSelection::performToggleSelection(SoPath *path)
388 //
389 ////////////////////////////////////////////////////////////////////////
390 {
391 if (path != NULL) {
392 // let app know user is changing the selection
393 if (startCBList != NULL)
394 startCBList->invokeCallbacks(this);
395
396 // toggle the picked object
397 int which = findPath(path);
398 if (which == -1)
399 addPath(path); // path not in list, add it
400 else removePath(which); // path in list, remove it
401
402 // let app know user is done changing the selection
403 if (finishCBList != NULL)
404 finishCBList->invokeCallbacks(this);
405 }
406 }
407
408 ////////////////////////////////////////////////////////////////////////
409 //
410 // Description:
411 // Find 'this' in the path, then copy the path from 'this' down to
412 // the path tail. If 'this' is not in the path, return NULL.
413 //
414 // Use: private
415 //
416 SoPath *
417 SoSelection::copyFromThis(const SoPath *path) const
418 {
419 if (path == NULL)
420 return NULL;
421
422 SoNode *node;
423 int i, indexToThis = -1;
424 SoPath *p = NULL;
425
426 SoFullPath *fullInPath = (SoFullPath *) path;
427
428 for (i = 0; i < fullInPath->getLength(); i++) {
429 node = fullInPath->getNode(i);
430 if (node == (SoNode *) this) {
431 indexToThis = i;
432 break;
433 }
434 }
435
436 if (indexToThis != -1) {
437 p = fullInPath->copy(indexToThis);
438 }
439
440 return p;
441 }
442
443 ////////////////////////////////////////////////////////////////////////
444 //
445 // Description:
446 // Add path to the selection list. It is assumed that path->head
447 // is this - DO NOT CALL THIS FUNCTION unless this is true. Also, the
448 // path must include more than just the selection node by itself.
449 //
450 // Use: private
451 //
452 void
453 SoSelection::addPath(SoPath *path)
454 //
455 ////////////////////////////////////////////////////////////////////////
456 {
457 // Add the path to the selection list,
458 // and notify the app that this path has been selected
459 if (selectionList.findPath(*path) == -1) {
460 path->ref();
461 selectionList.append(path);
462 if (selCBList != NULL)
463 selCBList->invokeCallbacks(path);
464 path->unref();
465
466 if (changeCBList != NULL)
467 changeCBList->invokeCallbacks(this);
468 }
469 }
470
471 //////////////////////////////////////////////////////////////////////////////
472 //
473 // This method takes the path indexed by `which' out of the selection list.
474 // The path will be unreferenced by the SoPathList (SoBaseList) class.
475 //
476 // Use: protected
477 //
478 //
479 void
480 SoSelection::removePath(int which)
481 //
482 //////////////////////////////////////////////////////////////////////////////
483 {
484 // Remove the path from the selection list,
485 // and notify the app that this path has been deselected.
486 if (which >= 0) {
487 SoPath *p = (SoPath *) selectionList[which];
488 p->ref();
489 selectionList.remove(which);
490 if (deselCBList != NULL)
491 deselCBList->invokeCallbacks(p);
492 p->unref();
493
494 if (changeCBList != NULL)
495 changeCBList->invokeCallbacks(this);
496 }
497 }
498
499 ////////////////////////////////////////////////////////////////////////
500 //
501 // Description:
502 // Add this path to the selection list. Path should include this
503 // node. The path will be referenced by the SoPathList (SoBaseList) class.
504 //
505 // Use: public
506 //
507 void
508 SoSelection::select(const SoPath *path)
509 //
510 ////////////////////////////////////////////////////////////////////////
511 {
512 // get a path whose head is this selection node
513 SoPath *selPath = copyFromThis(path);
514 if ((selPath != NULL) && (selPath->getLength() > 1)) {
515 selPath->ref();
516 addPath(selPath);
517 selPath->unref();
518 }
519 #ifdef DEBUG
520 else {
521 SoDebugError::post("SoSelection::select",
522 "Path does not pass through this selection node.");
523 return;
524 }
525 #endif
526 }
527
528 ////////////////////////////////////////////////////////////////////////
529 //
530 // Description:
531 // Search for the passed node under this, then select that path.
532 //
533 // Use: public
534 //
535 void
536 SoSelection::select(SoNode *node)
537 //
538 ////////////////////////////////////////////////////////////////////////
539 {
540 if (node != NULL) {
541 node->ref();
542
543 if (searchAction == NULL)
544 searchAction = new SoSearchAction;
545 else
546 searchAction->reset();
547 searchAction->setInterest(SoSearchAction::FIRST);
548 searchAction->setFind(SoSearchAction::NODE);
549 searchAction->setNode(node);
550 searchAction->apply(this);
551
552 SoPath *p = searchAction->getPath();
553 if ((p != NULL) && (p->getLength() > 1))
554 addPath(p);
555 #ifdef DEBUG
556 else {
557 SoDebugError::post("SoSelection::select",
558 "Node does not pass through this selection node.");
559 return;
560 }
561 #endif
562
563 node->unref();
564 }
565 }
566
567 //////////////////////////////////////////////////////////////////////////////
568 //
569 // This method takes the path indexed by `which' out of the selection list.
570 // The path will be unreferenced by the SoPathList (SoBaseList) class.
571 //
572 // Use: public
573 //
574 //
575 void
576 SoSelection::deselect(int which)
577 //
578 //////////////////////////////////////////////////////////////////////////////
579 {
580 removePath(which);
581 }
582
583 //////////////////////////////////////////////////////////////////////////////
584 //
585 // remove a path, finds path and removes it by index
586 //
587 // Use: public
588 //
589 void
590 SoSelection::deselect(const SoPath *path)
591 //
592 //////////////////////////////////////////////////////////////////////////////
593 {
594 //??? should we copyFromThis() as a convenience to the caller?
595 if (path != NULL) {
596 int which;
597 if ((which = findPath(path)) != -1)
598 removePath(which);
599
600 #ifdef DEBUG
601 else
602 SoDebugError::post("SoSelection::deselect", "Path not already selected");
603 #endif
604
605 }
606
607 #ifdef DEBUG
608 else {
609 SoDebugError::post("SoSelection::deselect", "Passed path is NULL");
610 }
611 #endif
612 }
613
614 ////////////////////////////////////////////////////////////////////////
615 //
616 // Description:
617 // Search for the passed node under this, then deselect that path.
618 //
619 // Use: public
620 //
621 void
622 SoSelection::deselect(SoNode *node)
623 //
624 ////////////////////////////////////////////////////////////////////////
625 {
626 if (node != NULL) {
627 node->ref();
628
629 if (searchAction == NULL)
630 searchAction = new SoSearchAction;
631 else
632 searchAction->reset();
633 searchAction->setInterest(SoSearchAction::FIRST);
634 searchAction->setFind(SoSearchAction::NODE);
635 searchAction->setNode(node);
636 searchAction->apply(this);
637 if (searchAction->getPath() != NULL)
638 deselect(searchAction->getPath());
639
640 node->unref();
641 }
642 }
643
644
645 //////////////////////////////////////////////////////////////////////////////
646 //
647 // returns the index of the path in the selection list
648 //
649 // Use: protected
650 //
651 int
652 SoSelection::findPath(const SoPath *path) const
653 //
654 //////////////////////////////////////////////////////////////////////////////
655 {
656 int index = -1;
657 if (path != NULL) {
658 SoPath *selPath = NULL;
659 if (path->getHead() != (SoNode *) this)
660 selPath = copyFromThis(path);
661 else selPath = (SoPath *) path; // const cast away
662
663 // selPath still not NULL? (copyFromThis() might have returned NULL)
664 if (selPath != NULL) {
665 selPath->ref();
666 index = ((SoPathList)selectionList).findPath(*selPath);
667 selPath->unref();
668 }
669 }
670
671 return index;
672 }
673
674 //////////////////////////////////////////////////////////////////////////////
675 //
676 // returns TRUE if the path is already selected
677 //
678 // Use: public
679 //
680 SbBool
681 SoSelection::isSelected(const SoPath *path) const
682 //
683 //////////////////////////////////////////////////////////////////////////////
684 {
685 //??? should we copyFromThis() as a convenience?
686 return (findPath(path) != -1);
687 }
688 ////////////////////////////////////////////////////////////////////////
689 //
690 // Description:
691 // Search for the passed node under this, then return whether it
692 // is selected.
693 //
694 // Use: public
695 //
696 SbBool
697 SoSelection::isSelected(SoNode *node) const
698 //
699 ////////////////////////////////////////////////////////////////////////
700 {
701 SbBool itIs = FALSE;
702
703 if (node != NULL) {
704 node->ref();
705
706 if (searchAction == NULL)
707 searchAction = new SoSearchAction;
708 else
709 searchAction->reset();
710 searchAction->setInterest(SoSearchAction::FIRST);
711 searchAction->setFind(SoSearchAction::NODE);
712 searchAction->setNode(node);
713 searchAction->apply((SoSelection *) this); // const cast away
714 if (searchAction->getPath() != NULL)
715 itIs = isSelected(searchAction->getPath());
716
717 node->unref();
718 }
719
720 return itIs;
721 }
722
723 //////////////////////////////////////////////////////////////////////////////
724 //
725 // toggle adds path if it's not in the selectionList, removes path if it is.
726 //
727 // Use: public
728 //
729 void
730 SoSelection::toggle(const SoPath *path)
731 //
732 //////////////////////////////////////////////////////////////////////////////
733 {
734 // get a path whose head is this selection node
735 SoPath *selPath = copyFromThis(path);
736 if ((selPath != NULL) && (selPath->getLength() > 1)) {
737 selPath->ref();
738 int which = findPath(selPath);
739 if (which == -1)
740 addPath(selPath); // path not in list, add it
741 else removePath(which); // path in list, remove it
742 selPath->unref();
743 }
744 #ifdef DEBUG
745 else {
746 SoDebugError::post("SoSelection::toggle",
747 "Path does not pass through this selection node.");
748 }
749 #endif
750 }
751 ////////////////////////////////////////////////////////////////////////
752 //
753 // Description:
754 // Search for the passed node under this, then toggle that path.
755 //
756 // Use: public
757 //
758 void
759 SoSelection::toggle(SoNode *node)
760 //
761 ////////////////////////////////////////////////////////////////////////
762 {
763 if (node != NULL) {
764 node->ref();
765
766 if (searchAction == NULL)
767 searchAction = new SoSearchAction;
768 else
769 searchAction->reset();
770 searchAction->setInterest(SoSearchAction::FIRST);
771 searchAction->setFind(SoSearchAction::NODE);
772 searchAction->setNode(node);
773 searchAction->apply(this);
774 if (searchAction->getPath() != NULL)
775 toggle(searchAction->getPath());
776
777 node->unref();
778 }
779 }
780
781 ////////////////////////////////////////////////////////////////////////
782 //
783 // Description:
784 // removes every path in the selection list
785 //
786 // Use: public
787 void
788 SoSelection::deselectAll()
789 //
790 ////////////////////////////////////////////////////////////////////////
791 {
792 for(int i = selectionList.getLength() - 1; i >= 0; i--)
793 deselect(i);
794 }
795
796
797 //////////////////////////////////////////////////////////////////////////////
798 //
799 // Description:
800 // get the ith path.
801 //
802 // Use: public
803 //
804 SoPath *
805 SoSelection::getPath(int index) const
806 //
807 //////////////////////////////////////////////////////////////////////////////
808 {
809 SoPath *p;
810
811 #ifdef DEBUG
812 if ((index >= selectionList.getLength()) || (index < 0)) {
813 SoDebugError::post("SoSelection::getPath", "Index out of range. Index = %d, numSelected = %d",
814 index, selectionList.getLength());
815 p = NULL;
816 }
817 else
818 #endif
819 p = selectionList[index];
820
821 return p;
822 }
823
824
825 ////////////////////////////////////////////////////////////////////////
826 //
827 // Description:
828 // Methods for setting callback functions.
829 //
830 // Use: public
831 //
832 //
833 ////////////////////////////////////////////////////////////////////////
834
835 void
836 SoSelection::addSelectionCallback(SoSelectionPathCB *f, void *userData)
837 {
838 if (selCBList == NULL)
839 selCBList = new SoCallbackList;
840 selCBList->addCallback((SoCallbackListCB *) f, userData);
841 }
842 void
843 SoSelection::removeSelectionCallback(SoSelectionPathCB *f, void *userData)
844 {
845 if (selCBList != NULL)
846 selCBList->removeCallback((SoCallbackListCB *) f, userData);
847 }
848
849 void
850 SoSelection::addDeselectionCallback(SoSelectionPathCB *f, void *userData)
851 {
852 if (deselCBList == NULL)
853 deselCBList = new SoCallbackList;
854 deselCBList->addCallback((SoCallbackListCB *) f, userData);
855 }
856 void
857 SoSelection::removeDeselectionCallback(SoSelectionPathCB *f, void *userData)
858 {
859 if (deselCBList != NULL)
860 deselCBList->removeCallback((SoCallbackListCB *) f, userData);
861 }
862
863 void
864 SoSelection::addStartCallback(SoSelectionClassCB *f, void *userData)
865 {
866 if (startCBList == NULL)
867 startCBList = new SoCallbackList;
868 startCBList->addCallback((SoCallbackListCB *) f, userData);
869 }
870 void
871 SoSelection::removeStartCallback(SoSelectionClassCB *f, void *userData)
872 {
873 if (startCBList != NULL)
874 startCBList->removeCallback((SoCallbackListCB *) f, userData);
875 }
876
877 void
878 SoSelection::addFinishCallback(SoSelectionClassCB *f, void *userData)
879 {
880 if (finishCBList == NULL)
881 finishCBList = new SoCallbackList;
882 finishCBList->addCallback((SoCallbackListCB *) f, userData);
883 }
884 void
885 SoSelection::removeFinishCallback(SoSelectionClassCB *f, void *userData)
886 {
887 if (finishCBList != NULL)
888 finishCBList->removeCallback((SoCallbackListCB *) f, userData);
889 }
890
891 void
892 SoSelection::addChangeCallback(SoSelectionClassCB *f, void *userData)
893 {
894 if (changeCBList == NULL)
895 changeCBList = new SoCallbackList;
896 changeCBList->addCallback((SoCallbackListCB *) f, userData);
897 }
898 void
899 SoSelection::removeChangeCallback(SoSelectionClassCB *f, void *userData)
900 {
901 if (changeCBList != NULL)
902 changeCBList->removeCallback((SoCallbackListCB *) f, userData);
903 }
904
905 void
906 SoSelection::setPickFilterCallback(
907 SoSelectionPickCB *f,
908 void *userData,
909 SbBool callOnlyIfSelectable)
910 {
911 pickCBFunc = f;
912 pickCBData = userData;
913 callPickCBOnlyIfSelectable = callOnlyIfSelectable;
914 }