1// @configure_input@ 2 3/**************************************************************************\ 4 * Copyright (c) Kongsberg Oil & Gas Technologies AS 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are 9 * met: 10 * 11 * Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name of the copyright holder nor the names of its 19 * contributors may be used to endorse or promote products derived from 20 * this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33\**************************************************************************/ 34 35#include <assert.h> 36 37#include <Inventor/errors/SoDebugError.h> 38#include <Inventor/actions/SoGLRenderAction.h> 39#include <Inventor/actions/SoPickAction.h> 40#include <Inventor/actions/SoRayPickAction.h> 41#include <Inventor/actions/SoGetMatrixAction.h> 42#include <Inventor/elements/SoModelMatrixElement.h> 43#include <Inventor/SoPath.h> 44 45#include <Inventor/@Gui@/nodes/SoGuiPane.h> 46#include <Inventor/@Gui@/nodes/SoGuiTranslation.h> 47 48// ************************************************************************* 49 50SO_NODE_SOURCE(SoGuiTranslation); 51 52void 53SoGuiTranslation::initClass(void) 54{ 55 SO_NODE_INIT_CLASS(SoGuiTranslation, SoTransformation, "Transformation"); 56} 57 58SoGuiTranslation::SoGuiTranslation(void) 59{ 60 SO_NODE_CONSTRUCTOR(SoGuiTranslation); 61 SO_NODE_ADD_FIELD(translation, (SbVec3f(0.0f, 0.0f, 0.0f))); 62} 63 64SoGuiTranslation::~SoGuiTranslation(void) 65{ 66} 67 68void 69SoGuiTranslation::doAction(SoAction * action) 70{ 71 // SoDebugError::postInfo("SoGuiTranslation::doAction", "invoked by %s", action->getTypeId().getName().getString()); 72 int i; 73 SoGuiPane * pane = NULL; 74 const SoFullPath * path = (const SoFullPath *) action->getCurPath(); 75 for ( i = path->getLength() - 1; (i >= 0) && (pane == NULL); i-- ) { 76 SoNode * node = path->getNode(i); 77 assert(node); 78 if ( node->isOfType(SoGuiPane::getClassTypeId()) ) pane = (SoGuiPane *) node; 79 } 80 if ( pane == NULL ) { 81 SoDebugError::postInfo("SoGuiTranslation::doAction", "SoGuiTranslation only works below an SoGuiPane node"); 82 return; 83 } 84 SoModelMatrixElement::translateBy(action->getState(), this, 85 this->translation.getValue()); 86 87// pane->moveBy(action->getState(), this->translation.getValue()); 88} 89 90void 91SoGuiTranslation::GLRender(SoGLRenderAction * action) 92{ 93 this->doAction(action); 94} 95 96void 97SoGuiTranslation::pick(SoPickAction * action) 98{ 99 this->doAction(action); 100} 101 102void 103SoGuiTranslation::rayPick(SoRayPickAction * action) 104{ 105 this->doAction(action); 106} 107 108void 109SoGuiTranslation::getMatrix(SoGetMatrixAction * action) 110{ 111 SoDebugError::postInfo("SoGuiTranslation::getMatrix", "invoked"); 112 int i; 113 SoGuiPane * pane = NULL; 114 const SoFullPath * path = (const SoFullPath *) action->getCurPath(); 115 for ( i = path->getLength() - 1; (i >= 0) && (pane == NULL); i-- ) { 116 SoNode * node = path->getNode(i); 117 assert(node); 118 if ( node->isOfType(SoGuiPane::getClassTypeId()) ) pane = (SoGuiPane *) node; 119 } 120 if ( pane == NULL ) { 121 SoDebugError::postInfo("SoGuiTranslation::getMatrix", "SoGuiTranslation only works below an SoGuiPane node"); 122 return; 123 } 124 pane->applyMoveBy(action, this->translation.getValue()); 125} 126 127