From f76a9a773e0dc134acfcc90f35c3822b223f8cdc Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 1 May 2017 17:42:03 +0200 Subject: [PATCH] add SwitchBoard node class --- src/Gui/CMakeLists.txt | 2 + src/Gui/Inventor/SmSwitchboard.cpp | 210 +++++++++++++++++++++++++++++ src/Gui/Inventor/SmSwitchboard.h | 68 ++++++++++ src/Gui/SoFCDB.cpp | 2 + 4 files changed, 282 insertions(+) create mode 100644 src/Gui/Inventor/SmSwitchboard.cpp create mode 100644 src/Gui/Inventor/SmSwitchboard.h diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 440cdf9814..f332924b4d 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -932,6 +932,7 @@ SET(Inventor_CPP_SRCS Inventor/SoDrawingGrid.cpp Inventor/SoAutoZoomTranslation.cpp Inventor/MarkerBitmaps.cpp + Inventor/SmSwitchboard.cpp SoFCBackgroundGradient.cpp SoFCBoundingBox.cpp SoFCColorBar.cpp @@ -956,6 +957,7 @@ SET(Inventor_SRCS Inventor/SoDrawingGrid.h Inventor/SoAutoZoomTranslation.h Inventor/MarkerBitmaps.h + Inventor/SmSwitchboard.h SoFCBackgroundGradient.h SoFCBoundingBox.h SoFCColorBar.h diff --git a/src/Gui/Inventor/SmSwitchboard.cpp b/src/Gui/Inventor/SmSwitchboard.cpp new file mode 100644 index 0000000000..79210ac56b --- /dev/null +++ b/src/Gui/Inventor/SmSwitchboard.cpp @@ -0,0 +1,210 @@ +/**************************************************************************\ + * Copyright (c) Kongsberg Oil & Gas Technologies AS + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +\**************************************************************************/ + +/*! + \class SmSwitchboard SmSwitchboard.h SmallChange/nodes/SmSwitchboard.h + \brief The SmSwitchboard class is a group node that can toggle children + on and off arbitrarily. + + FIXME: write doc + + \ingroup nodes +*/ + +// FIXME: implement proper searching / SearchAction handling 2002-02-07 larsa +// FIXME: implement proper writing / WriteAction handling 2002-02-07 larsa + +#include "PreCompiled.h" +#include "SmSwitchboard.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +/*! + \var SoMFBool SmSwitchboard::enable + + Selects which child to traverse during rendering (and some other) + actions. + + When the length of this multifield is larger than the number of children + this group has, the enable list is modulated over the children. This lets + you have full control over the number of times and order each child is + traversed. + + Default enabled value is \c FALSE. +*/ + +// ************************************************************************* + +// doc in super +void +SmSwitchboard::initClass(void) +{ + SO_NODE_INIT_CLASS(SmSwitchboard, SoGroup, SoGroup); +} + +SO_NODE_SOURCE(SmSwitchboard); + +/*! + Default constructor. +*/ +SmSwitchboard::SmSwitchboard(void) +{ + SO_NODE_CONSTRUCTOR(SmSwitchboard); + + SO_NODE_ADD_FIELD(enable, (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. +*/ +SmSwitchboard::SmSwitchboard(int numchildren) + : inherited(numchildren) +{ + SO_NODE_CONSTRUCTOR(SmSwitchboard); + + SO_NODE_ADD_FIELD(enable, (FALSE)); +} + +/*! + Destructor. +*/ +SmSwitchboard::~SmSwitchboard(void) // virtual, protected +{ +} + +// Documented in superclass. +void +SmSwitchboard::doAction(SoAction * action) +{ + // FIXME: take PathCode and stuff into consideration... + if (action->isOfType(SoGetBoundingBoxAction::getClassTypeId())) { + // calculate center of bbox if bboxaction. This makes the + // switchboard node behave exactly like a group node + SoGetBoundingBoxAction * bbaction = (SoGetBoundingBoxAction*) action; + // Initialize accumulation variables. + SbVec3f acccenter(0.0f, 0.0f, 0.0f); + int numcenters = 0; + for (int idx = 0; idx < this->enable.getNum(); idx++) { + const int numchildren = this->children->getLength(); + if ( numchildren > 0 ) + action->traverse((*this->children)[idx % numchildren]); + // If center point is set, accumulate. + if (bbaction->isCenterSet()) { + acccenter += bbaction->getCenter(); + numcenters++; + bbaction->resetCenter(); + } + } + if (numcenters != 0) { + bbaction->setCenter(acccenter / float(numcenters), FALSE); + } + } else { // not a GetBoundingBoxAction + for ( int idx = 0; idx < this->enable.getNum(); idx++ ) { + if ( this->enable[idx] ) { + const int numchildren = this->children->getLength(); + if ( numchildren > 0 ) + action->traverse((*this->children)[idx % numchildren]); + } + } + } +} + +void +SmSwitchboard::GLRender(SoGLRenderAction * action) +{ + SmSwitchboard::doAction((SoAction *) action); +} + +void +SmSwitchboard::getBoundingBox(SoGetBoundingBoxAction * action) +{ + SmSwitchboard::doAction((SoAction *) action); +} + +void +SmSwitchboard::getMatrix(SoGetMatrixAction * action) +{ + switch (action->getCurPathCode()) { + case SoAction::OFF_PATH: + case SoAction::IN_PATH: + SmSwitchboard::doAction((SoAction *) action); + break; + default: + break; + } +} + +void +SmSwitchboard::callback(SoCallbackAction *action) +{ + SmSwitchboard::doAction(action); +} + +// Documented in superclass. +void +SmSwitchboard::pick(SoPickAction *action) +{ + SmSwitchboard::doAction((SoAction*)action); +} + +// Documented in superclass. +void +SmSwitchboard::handleEvent(SoHandleEventAction *action) +{ + SmSwitchboard::doAction(action); +} + +void +SmSwitchboard::search(SoSearchAction * action) +{ + SoNode::search(action); + if (action->isFound()) return; + SmSwitchboard::doAction(action); +} diff --git a/src/Gui/Inventor/SmSwitchboard.h b/src/Gui/Inventor/SmSwitchboard.h new file mode 100644 index 0000000000..19e6f580f9 --- /dev/null +++ b/src/Gui/Inventor/SmSwitchboard.h @@ -0,0 +1,68 @@ +#ifndef SMALLCHANGE_SWITCHBOARD_H +#define SMALLCHANGE_SWITCHBOARD_H + +/**************************************************************************\ + * Copyright (c) Kongsberg Oil & Gas Technologies AS + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +\**************************************************************************/ + +#include +#include +#include + +//#include + + +class GuiExport SmSwitchboard : public SoGroup { + typedef SoGroup inherited; + SO_NODE_HEADER(SmSwitchboard); + +public: + static void initClass(void); + SmSwitchboard(void); + SmSwitchboard(int numchildren); + + SoMFBool enable; + + virtual void doAction(SoAction * action); + virtual void callback(SoCallbackAction * action); + virtual void GLRender(SoGLRenderAction * action); + virtual void pick(SoPickAction * action); + virtual void getBoundingBox(SoGetBoundingBoxAction * action); + virtual void handleEvent(SoHandleEventAction * action); + virtual void getMatrix(SoGetMatrixAction * action); + virtual void search(SoSearchAction * action); + +protected: + virtual ~SmSwitchboard(void); + +}; + +#endif // !SMALLCHANGE_SWITCHBOARD_H diff --git a/src/Gui/SoFCDB.cpp b/src/Gui/SoFCDB.cpp index 92cfcdb3c6..e895bb9f93 100644 --- a/src/Gui/SoFCDB.cpp +++ b/src/Gui/SoFCDB.cpp @@ -54,6 +54,7 @@ #include "Inventor/SoDrawingGrid.h" #include "Inventor/SoAutoZoomTranslation.h" #include "Inventor/MarkerBitmaps.h" +#include "Inventor/SmSwitchboard.h" #include "SoFCCSysDragger.h" #include "propertyeditor/PropertyItem.h" @@ -118,6 +119,7 @@ void Gui::SoFCDB::init() SoAutoZoomTranslation ::initClass(); MarkerBitmaps ::initClass(); SoFCCSysDragger ::initClass(); + SmSwitchboard ::initClass(); PropertyItem ::init(); PropertySeparatorItem ::init();