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/SoGuiPosition.h>
47
48// *************************************************************************
49
50SO_NODE_SOURCE(SoGuiPosition);
51
52void
53SoGuiPosition::initClass(void)
54{
55  SO_NODE_INIT_CLASS(SoGuiPosition, SoTransformation, "Transformation");
56}
57
58SoGuiPosition::SoGuiPosition(void)
59{
60  SO_NODE_CONSTRUCTOR(SoGuiPosition);
61  SO_NODE_ADD_FIELD(position, (SbVec3f(0.0f, 0.0f, 0.0f)));
62}
63
64SoGuiPosition::~SoGuiPosition(void)
65{
66}
67
68void
69SoGuiPosition::doAction(SoAction * action)
70{
71  int i;
72  // SoDebugError::postInfo("SoGuiPosition::doAction", "invoked by %s", action->getTypeId().getName().getString());
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("SoGuiPosition::GLRender", "SoGuiPosition only works below an SoGuiPane node");
82    return;
83  }
84  pane->moveTo(action->getState(), this->position.getValue());
85}
86
87void
88SoGuiPosition::GLRender(SoGLRenderAction * action)
89{
90  this->doAction(action);
91}
92
93void
94SoGuiPosition::pick(SoPickAction * action)
95{
96  this->doAction(action);
97}
98
99void
100SoGuiPosition::rayPick(SoRayPickAction * action)
101{
102  this->doAction(action);
103}
104
105void
106SoGuiPosition::getMatrix(SoGetMatrixAction * action)
107{
108  SoDebugError::postInfo("SoGuiPosition::getMatrix", "invoked");
109  int i;
110  SoGuiPane * pane = NULL;
111  const SoFullPath * path = (const SoFullPath *) action->getCurPath();
112  for ( i = path->getLength() - 1; (i >= 0) && (pane == NULL); i-- ) {
113    SoNode * node = path->getNode(i);
114    assert(node);
115    if ( node->isOfType(SoGuiPane::getClassTypeId()) ) pane = (SoGuiPane *) node;
116  }
117  if ( pane == NULL ) {
118    SoDebugError::postInfo("SoGuiPosition::getMatrix", "SoGuiPosition only works below an SoGuiPane node");
119    return;
120  }
121  pane->applyMoveTo(action, this->position.getValue());
122}
123
124