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
|
/**************************************************************************\
*
* 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/ sales@sim.no coin-support@coin3d.org
*
\**************************************************************************/
/*!
\class SoPathSwitch SoPathSwitch.h Inventor/nodes/SoPathSwitch.h
\brief The SoPathSwitch class traverses only when current path matches a configurable path.
\ingroup nodes
<b>FILE FORMAT/DEFAULTS:</b>
\code
PathSwitch {
path NULL
}
\endcode
*/
// *************************************************************************
#include <Inventor/nodes/SoPathSwitch.h>
#include <Inventor/actions/SoGetBoundingBoxAction.h>
#include <Inventor/actions/SoGLRenderAction.h>
#include <Inventor/actions/SoGetMatrixAction.h>
#include <Inventor/actions/SoHandleEventAction.h>
#include <Inventor/actions/SoGetPrimitiveCountAction.h>
#include <Inventor/actions/SoPickAction.h>
#include <Inventor/actions/SoSearchAction.h>
#include <Inventor/actions/SoCallbackAction.h>
#include <Inventor/actions/SoAudioRenderAction.h>
#include "nodes/SoSubNodeP.h"
// *************************************************************************
/*!
\var SoSFPath SoPathSwitch::path
The path that must match the current action path. A \c NULL path
will never match. An empty path will always match. The path should
go up to (not including) the SoPathSwitch node, but need not go all
the way back to the root node.
*/
// *************************************************************************
SO_NODE_SOURCE(SoPathSwitch);
// *************************************************************************
/*!
Default constructor.
*/
SoPathSwitch::SoPathSwitch(void)
{
this->commonConstructor();
}
static SbBool
is_matching_paths(const SoPath * currentpath, const SoPath * pathswitchpath)
{
if (pathswitchpath == NULL) return FALSE;
const SoFullPath * current = (const SoFullPath*) currentpath;
const SoFullPath * swpath = (const SoFullPath *) pathswitchpath;
int swidx = swpath->getLength() - 1;
if (swidx < 0) return TRUE; // an empty path will always match
int curidx = current->getLength() - 2; // last node is this node. Skip it.
// test if swpath is a valid path. Return FALSE if not.
if (swidx > curidx) return FALSE;
// we know curidx >= swidx
while (swidx > 0) {
if ((swpath->getNode(swidx) != current->getNode(curidx)) ||
(swpath->getIndex(swidx) != current->getIndex(curidx))) break;
swidx--;
curidx--;
}
if (swidx == 0) { // don't test index for head node
return swpath->getHead() == current->getNode(curidx);
}
return FALSE;
}
/*!
Constructor.
The argument should be the approximate number of children which is
expected to be inserted below this node. The number need not be
exact, as it is only used as a hint for better memory resource
allocation.
*/
SoPathSwitch::SoPathSwitch(int numchildren)
: inherited(numchildren)
{
this->commonConstructor();
}
// private
void
SoPathSwitch::commonConstructor(void)
{
SO_NODE_INTERNAL_CONSTRUCTOR(SoPathSwitch);
SO_NODE_ADD_FIELD(path, (NULL));
}
/*!
Destructor.
*/
SoPathSwitch::~SoPathSwitch()
{
}
// doc in parent
void
SoPathSwitch::initClass(void)
{
SO_NODE_INTERNAL_INIT_CLASS(SoPathSwitch, SO_FROM_INVENTOR_1);
}
// doc in parent
void
SoPathSwitch::getBoundingBox(SoGetBoundingBoxAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::getBoundingBox(action);
}
}
// doc in parent
void
SoPathSwitch::doAction(SoAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::doAction(action);
}
}
// doc in parent
void
SoPathSwitch::GLRender(SoGLRenderAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::GLRender(action);
}
}
// doc in parent
void
SoPathSwitch::pick(SoPickAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::pick(action);
}
}
// doc in parent
void
SoPathSwitch::audioRender(SoAudioRenderAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::audioRender(action);
}
}
// doc in parent
void
SoPathSwitch::handleEvent(SoHandleEventAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::handleEvent(action);
}
}
// doc in parent
void
SoPathSwitch::getMatrix(SoGetMatrixAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::getMatrix(action);
}
}
// doc in parent
void
SoPathSwitch::search(SoSearchAction * action)
{
if (action->isSearchingAll()) inherited::search(action);
else {
SoNode::search(action);
if (!action->isFound()) {
SoPathSwitch::doAction(action);
}
}
}
// doc in parent
void
SoPathSwitch::callback(SoCallbackAction *action)
{
if (action->isCallbackAll()) inherited::doAction(action);
else SoPathSwitch::doAction(action);
}
// doc in parent
void
SoPathSwitch::getPrimitiveCount(SoGetPrimitiveCountAction * action)
{
if (is_matching_paths(action->getCurPath(), this->path.getValue())) {
inherited::getPrimitiveCount(action);
}
}
|