Debian Codegraph @

src/Gui/Inventor/SmSwitchboard.cpp

raw
1 /**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 \**************************************************************************/
32
33 /*!
34 \class SmSwitchboard SmSwitchboard.h SmallChange/nodes/SmSwitchboard.h
35 \brief The SmSwitchboard class is a group node that can toggle children
36 on and off arbitrarily.
37
38 FIXME: write doc
39
40 \ingroup nodes
41 */
42
43 // FIXME: implement proper searching / SearchAction handling 2002-02-07 larsa
44 // FIXME: implement proper writing / WriteAction handling 2002-02-07 larsa
45
46
47 #include <Inventor/actions/SoCallbackAction.h>
48 #include <Inventor/actions/SoGetBoundingBoxAction.h>
49 #include <Inventor/actions/SoGetMatrixAction.h>
50 #include <Inventor/actions/SoGLRenderAction.h>
51 #include <Inventor/actions/SoHandleEventAction.h>
52 #include <Inventor/actions/SoPickAction.h>
53 #include <Inventor/actions/SoSearchAction.h>
54 #include <Inventor/misc/SoChildList.h>
55
56
57 #include "SmSwitchboard.h"
58
59
60 /*!
61 \var SoMFBool SmSwitchboard::enable
62
63 Selects which child to traverse during rendering (and some other)
64 actions.
65
66 When the length of this multifield is larger than the number of children
67 this group has, the enable list is modulated over the children. This lets
68 you have full control over the number of times and order each child is
69 traversed.
70
71 Default enabled value is \c FALSE.
72 */
73
74 // *************************************************************************
75
76 // doc in super
77 void SmSwitchboard::initClass()
78 {
79 SO_NODE_INIT_CLASS(SmSwitchboard, SoGroup, SoGroup);
80 }
81
82 SO_NODE_SOURCE(SmSwitchboard)
83
84 /*!
85 Default constructor.
86 */
87 SmSwitchboard::SmSwitchboard()
88 {
89 SO_NODE_CONSTRUCTOR(SmSwitchboard);
90
91 SO_NODE_ADD_FIELD(enable, (FALSE));
92 }
93
94 /*!
95 Constructor.
96
97 The argument should be the approximate number of children which is
98 expected to be inserted below this node. The number need not be
99 exact, as it is only used as a hint for better memory resource
100 allocation.
101 */
102 SmSwitchboard::SmSwitchboard(int numchildren)
103 : inherited(numchildren)
104 {
105 SO_NODE_CONSTRUCTOR(SmSwitchboard);
106
107 SO_NODE_ADD_FIELD(enable, (FALSE));
108 }
109
110 /*!
111 Destructor.
112 */
113 SmSwitchboard::~SmSwitchboard() = default; // virtual, protected
114
115 // Documented in superclass.
116 void SmSwitchboard::doAction(SoAction* action)
117 {
118 // FIXME: take PathCode and stuff into consideration...
119 if (action->isOfType(SoGetBoundingBoxAction::getClassTypeId())) {
120 // calculate center of bbox if bboxaction. This makes the
121 // switchboard node behave exactly like a group node
122 auto bbaction = (SoGetBoundingBoxAction*)action;
123 // Initialize accumulation variables.
124 SbVec3f acccenter(0.0f, 0.0f, 0.0f);
125 int numcenters = 0;
126 for (int idx = 0; idx < this->enable.getNum(); idx++) {
127 const int numchildren = this->children->getLength();
128 if (numchildren > 0) {
129 this->children->traverse(action, (idx % numchildren));
130 }
131 // If center point is set, accumulate.
132 if (bbaction->isCenterSet()) {
133 acccenter += bbaction->getCenter();
134 numcenters++;
135 bbaction->resetCenter();
136 }
137 }
138 if (numcenters != 0) {
139 bbaction->setCenter(acccenter / float(numcenters), FALSE);
140 }
141 }
142 else { // not a GetBoundingBoxAction
143 for (int idx = 0; idx < this->enable.getNum(); idx++) {
144 if (this->enable[idx]) {
145 const int numchildren = this->children->getLength();
146 if (numchildren > 0) {
147 this->children->traverse(action, (idx % numchildren));
148 }
149 }
150 }
151 }
152 }
153
154 void SmSwitchboard::GLRender(SoGLRenderAction* action)
155 {
156 SmSwitchboard::doAction((SoAction*)action);
157 }
158
159 void SmSwitchboard::getBoundingBox(SoGetBoundingBoxAction* action)
160 {
161 SmSwitchboard::doAction((SoAction*)action);
162 }
163
164 void SmSwitchboard::getMatrix(SoGetMatrixAction* action)
165 {
166 switch (action->getCurPathCode()) {
167 case SoAction::OFF_PATH:
168 case SoAction::IN_PATH:
169 SmSwitchboard::doAction((SoAction*)action);
170 break;
171 default:
172 break;
173 }
174 }
175
176 void SmSwitchboard::callback(SoCallbackAction* action)
177 {
178 SmSwitchboard::doAction(action);
179 }
180
181 // Documented in superclass.
182 void SmSwitchboard::pick(SoPickAction* action)
183 {
184 SmSwitchboard::doAction((SoAction*)action);
185 }
186
187 // Documented in superclass.
188 void SmSwitchboard::handleEvent(SoHandleEventAction* action)
189 {
190 SmSwitchboard::doAction(action);
191 }
192
193 void SmSwitchboard::search(SoSearchAction* action)
194 {
195 SoNode::search(action); // clazy:exclude=skipped-base-method
196 if (action->isFound()) {
197 return;
198 }
199 SmSwitchboard::doAction(action);
200 }