OpenWalnut  1.5.0dev
WKeyboardHandler.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 "WFiberHandler.h"
26 #include "WKeyboardHandler.h"
27 
28 
29 static const unsigned int CTRL_DOWN = 65507;
30 static const unsigned int CTRL_UP = 16777249;
31 static const unsigned int SHIFT_DOWN = 65505;
32 static const unsigned int SHIFT_UP = 16777248;
33 
34 static const unsigned int KEY_A = 65;
35 static const unsigned int KEY_C = 67;
36 static const unsigned int KEY_T = 84;
37 static const unsigned int KEY_X = 88;
38 static const unsigned int KEY_Y = 89;
39 static const unsigned int KEY_Z = 90;
40 
41 static const double SCALING_FACTOR = 2.0;
42 
44  m_connector( connector )
45 {
46 }
47 
48 bool WKeyboardHandler::handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& )
49 {
50  if( ea.getEventType() == osgGA::GUIEventAdapter::KEYDOWN )
51  {
52  if( m_isCtrl )
53  {
54  switch( ea.getKey() )
55  {
56  case KEY_Y:
57  m_connector->pushEventQueue( std::bind( &WActionHandler::redo, m_connector->getFiberHandler()->getActionHandler() ) );
58  return true;
59  case KEY_Z:
60  m_connector->pushEventQueue( std::bind( &WActionHandler::undo, m_connector->getFiberHandler()->getActionHandler() ) );
61  return true;
62  }
63  }
64 
65  if( m_isShift )
66  {
67  switch( ea.getKey() )
68  {
69  case KEY_A:
70  m_connector->getFiberHandler()->createNewFiber();
71  return true;
72  case KEY_C:
74  return true;
75  case KEY_T:
76  m_connector->getFiberHandler()->toggleFiber( m_connector->getFiberHandler()->getSelectedFiber() );
77  return true;
78  }
79  }
80 
81  WPosition scal = m_connector->getScaling()->get();
82  switch( ea.getKey() )
83  {
84  case CTRL_DOWN:
85  m_isCtrl = true;
86  return true;
87  case SHIFT_DOWN:
88  m_isShift = true;
89  return true;
90  case KEY_X:
91  m_connector->getScaling()->set( WPosition( scal.x() * ( m_isShift ? 1.0 / SCALING_FACTOR : SCALING_FACTOR ), scal.y(), scal.z() ) );
92  return true;
93  case KEY_Y:
94  m_connector->getScaling()->set( WPosition( scal.x(), scal.y() * ( m_isShift ? 1.0 / SCALING_FACTOR : SCALING_FACTOR ), scal.z() ) );
95  return true;
96  case KEY_Z:
97  m_connector->getScaling()->set( WPosition( scal.y(), scal.x(), scal.z() * ( m_isShift ? 1.0 / SCALING_FACTOR : SCALING_FACTOR ) ) );
98  return true;
99  }
100  }
101 
102  if( ea.getEventType() == osgGA::GUIEventAdapter::KEYUP )
103  {
104  switch( ea.getKey() )
105  {
106  case CTRL_UP:
107  m_isCtrl = false;
108  return true;
109  case SHIFT_UP:
110  m_isShift = false;
111  return true;
112  }
113  }
114 
115  return false;
116 }
void redo()
Redos the last action and pushes it to the undo vector.
void undo()
Undos the last action and pushes it to the redo vector.
bool m_isCtrl
Whether ctrl is pressed or not.
WMPointConnector * m_connector
The WMPointConnector this handler belongs to.
WKeyboardHandler(WMPointConnector *connector)
Constructs one WKeyboardHandler.
bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
The callback for the event listener.
bool m_isShift
Whether shift is pressed or not.
This module connects the points in a point dataset.
WPropPosition getScaling()
void pushEventQueue(std::function< void() > func)
Pushes a function to the selection queue.
std::shared_ptr< WFiberHandler > getFiberHandler()
void acceptPrediction()
Accepts the current prediction.
This only is a 3d double vector.