OpenWalnut  1.5.0dev
WPanTransformCallback.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 "WPanTransformCallback.h"
33 
34 
36  WPropDouble timePos,
37  WPropDouble timeRange,
38  WPropInt graphWidth,
39  WPropDouble yPos )
40  : m_currentLabelsWidth( 0 ),
41  m_currentTimePos( 0.0 ),
42  m_currentTimeRange( 1.0 ),
43  m_currentGraphWidth( 1 ),
44  m_currentYPos( 0.0 ),
45  m_labelsWidth( labelsWidth ),
46  m_timePos( timePos ),
47  m_timeRange( timeRange ),
48  m_graphWidth( graphWidth ),
49  m_yPos( yPos )
50 {
51 }
52 
53 void WPanTransformCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
54 {
55  const int labelsWidth = m_labelsWidth->get();
56  const double timePos = m_timePos->get();
57  const double timeRange = m_timeRange->get();
58  const int graphWidth = m_graphWidth->get();
59  const double yPos = m_yPos->get();
60 
61  if( labelsWidth != m_currentLabelsWidth || timePos != m_currentTimePos || timeRange != m_currentTimeRange
62  || graphWidth != m_currentGraphWidth || yPos != m_currentYPos )
63  {
64  osg::MatrixTransform* transform = static_cast< osg::MatrixTransform* >( node );
65  if( transform )
66  {
67  transform->setMatrix( osg::Matrix::scale( graphWidth / timeRange, 1.0, 1.0 )
68  * osg::Matrix::translate( labelsWidth - timePos * graphWidth / timeRange, -yPos, 0.0 ) );
69  }
70 
71  m_currentLabelsWidth = labelsWidth;
72  m_currentTimePos = timePos;
73  m_currentTimeRange = timeRange;
74  m_currentGraphWidth = graphWidth;
75  m_currentYPos = yPos;
76  }
77 
78  traverse( node, nv );
79 }
WPropDouble m_timeRange
the width of the graph in seconds as property
WPanTransformCallback(WPropInt labelsWidth, WPropDouble timePos, WPropDouble timeRange, WPropInt graphWidth, WPropDouble yPos)
Constructor.
int m_currentGraphWidth
the width of the graph in pixel which is currently used
double m_currentTimePos
the time position in seconds where to start the graph at the left edge which is currently used
double m_currentTimeRange
the width of the graph in seconds which is currently used
WPropDouble m_yPos
the y position in pixel at the lower edge as property
WPropInt m_graphWidth
the width of the graph in pixel as property
int m_currentLabelsWidth
the width of the label display in pixel which is currently used
double m_currentYPos
the y position in pixel at the lower edge which is currently used
WPropInt m_labelsWidth
the width of the label display in pixel as property
WPropDouble m_timePos
the time position in seconds where to start the graph at the left edge as property
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.