OpenWalnut  1.5.0dev
WLabelsTransformCallback.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include <osg/Matrix>
26 #include <osg/MatrixTransform>
27 #include <osg/Node>
28 #include <osg/NodeVisitor>
29 
30 #include "core/common/WPropertyTypes.h"
31 #include "core/common/WPropertyVariable.h"
32 #include "WLabelsTransformCallback.h"
33 
34 
35 WLabelsTransformCallback::WLabelsTransformCallback( WPropDouble yPos, WPropDouble ySpacing )
36  : m_currentYPos( 0.0 ),
37  m_currentYSpacing( 1.0 ),
38  m_yPos( yPos ),
39  m_ySpacing( ySpacing )
40 {
41 }
42 
43 void WLabelsTransformCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
44 {
45  const double yPos = m_yPos->get();
46  const double ySpacing = m_ySpacing->get();
47 
48  if( yPos != m_currentYPos || ySpacing != m_currentYSpacing )
49  {
50  osg::MatrixTransform* transform = static_cast< osg::MatrixTransform* >( node );
51  if( transform )
52  {
53  transform->setMatrix( osg::Matrix::scale( 1.0, ySpacing, 1.0 ) * osg::Matrix::translate( 0.0, -yPos, 0.0 ) );
54  }
55 
56  m_currentYPos = yPos;
57  m_currentYSpacing = ySpacing;
58  }
59 
60  traverse( node, nv );
61 }
double m_currentYPos
the y position in pixel at the lower edge which is currently used
double m_currentYSpacing
the distance between two curves of the graph in pixel which is currently used
WPropDouble m_yPos
the y position in pixel at the lower edge as property
WPropDouble m_ySpacing
the distance between two curves of the graph in pixel as property
WLabelsTransformCallback(WPropDouble yPos, WPropDouble ySpacing)
Constructor.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.