00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <fps_motion_tool.h>
00028
00029 namespace rviz
00030 {
00031
00032 FPSMotionTool::FPSMotionTool()
00033 {
00034 shortcut_key_ = 'q';
00035 access_all_keys_ = true;
00036 }
00037
00038 FPSMotionTool::~FPSMotionTool() {}
00039
00040 void FPSMotionTool::onInitialize()
00041 {
00042 setName( "FPS Motion" );
00043
00044 step_length_property_ = new FloatProperty( "Step Length", 0.1,
00045 "The length by with the position is updated on each step.",
00046 getPropertyContainer(), SLOT( setOffset() ), this );
00047
00048 boost_property_ = new FloatProperty( "Boost Property", 0.5,
00049 "Gives the boost factor which is applied if pressing shift.",
00050 getPropertyContainer(), SLOT( setBoost() ), this );
00051
00052 fly_property_ = new BoolProperty( "Fly Mode", false,
00053 "In fly mode it is possible to move along the z axis as well.",
00054 getPropertyContainer(), SLOT( setFlyMode() ), this );
00055
00056 left_hand_property_ = new BoolProperty( "Left Hand Mode", false,
00057 "In left hand mode one uses the arrows to move around, instead of wasd.",
00058 getPropertyContainer(), SLOT( setLeftHandMode() ), this );
00059
00060 fallback_tool_property_ = new EnumProperty( "Fallback Tool", QString("rviz/Interact"),
00061 "Determines to which tool the control switches, if the tool is deactivated.",
00062 getPropertyContainer(), SLOT( setFallbackTool() ), this );
00063
00064 fallback_view_controller_property_ = new EnumProperty( "Fallback ViewController", QString("rviz/Orbit"),
00065 "Determines to which view controller the control switches, if the tool is deactivated.",
00066 getPropertyContainer(), SLOT( setFallbackViewController() ), this );
00067 m_pos_offset = 0.1;
00068 m_boost = 0.5;
00069 m_fly_mode = false;
00070 m_left_hand_mode = false;
00071
00072 setFallbackToolProperty();
00073 setFallbackViewControllerProperty();
00074 }
00075
00076 void FPSMotionTool::setFallbackViewControllerProperty()
00077 {
00078 fallback_view_controller_property_->clearOptions();
00079 m_view_controller_classes.clear();
00080
00081 m_view_controller_classes = context_->getViewManager()->getFactory()->getDeclaredClassIds();
00082
00083 for( int i = 0; i < m_view_controller_classes.size(); i++ )
00084 {
00085 if(m_view_controller_classes[i] != QString("rviz/FPSMotion"))
00086 {
00087 fallback_view_controller_property_->addOption(m_view_controller_classes[i], i);
00088 m_view_controller.push_back(context_->getViewManager()->getViewAt(i));
00089 }
00090
00091 }
00092
00093 fallback_view_controller_property_->show();
00094 setFallbackViewController();
00095 }
00096
00097 void FPSMotionTool::setFallbackToolProperty()
00098 {
00099 fallback_tool_property_->clearOptions();
00100 m_tools.clear();
00101
00102 m_tool_classes = context_->getToolManager()->getToolClasses();
00103
00104 for(int i = 0; i < m_tool_classes.size(); i++)
00105 {
00106 if(m_tool_classes[i] != getClassId())
00107 {
00108 fallback_tool_property_->addOption(m_tool_classes[i], i);
00109 m_tools.push_back(context_->getToolManager()->getTool(i));
00110 }
00111 }
00112
00113 fallback_tool_property_->show();
00114 setFallbackTool();
00115 }
00116
00117 void FPSMotionTool::activate()
00118 {
00119 context_->getViewManager()->setCurrentViewControllerType(QString("rviz/FPSMotion"));
00120 setFallbackToolProperty();
00121 setFallbackViewControllerProperty();
00122 }
00123
00124 void FPSMotionTool::deactivate(){ }
00125
00126 int FPSMotionTool::processKeyEvent(QKeyEvent *event, rviz::RenderPanel* panel)
00127 {
00128 if(panel->getViewController()->getClassId().toStdString() != "rviz/FPSMotion")
00129 {
00130 ROS_WARN("The FPS Motion Tool only works with an active rviz/FPSMotion ViewController. \n If you use the shortkeys to select ('e') and deselect ('e') this tool, the switching will be automatized for you.");
00131 }
00132 else
00133 {
00134 double update = m_pos_offset;
00135
00136 if(event->modifiers() & Qt::ShiftModifier)
00137 {
00138 update += m_boost * m_pos_offset;
00139 }
00140
00141
00142 if ((event->key() == Qt::Key_W && !m_left_hand_mode) || (event->key() == Qt::Key_Up && m_left_hand_mode))
00143 {
00144 if(m_fly_mode)
00145 ((rviz::FPSMotionViewController*) panel->getViewController())->fly(0.0, 0.0, -update);
00146 else
00147 ((rviz::FPSMotionViewController*) panel->getViewController())->move(0.0, 0.0, -update);
00148 }
00149
00150 if ((event->key() == Qt::Key_S && !m_left_hand_mode) || (event->key() == Qt::Key_Down && m_left_hand_mode))
00151 {
00152 if(m_fly_mode)
00153 ((rviz::FPSMotionViewController*) panel->getViewController())->fly(0.0, 0.0, update);
00154 else
00155 ((rviz::FPSMotionViewController*) panel->getViewController())->move(0.0, 0.0, update);
00156 }
00157
00158
00159 if ((event->key() == Qt::Key_A && !m_left_hand_mode) || (event->key() == Qt::Key_Left && m_left_hand_mode))
00160 {
00161 if(m_fly_mode)
00162 ((rviz::FPSMotionViewController*) panel->getViewController())->fly(-update, 0.0, 0.0);
00163 else
00164 ((rviz::FPSMotionViewController*) panel->getViewController())->move(-update, 0.0, 0.0);
00165 }
00166
00167 if ((event->key() == Qt::Key_D && !m_left_hand_mode) || (event->key() == Qt::Key_Right && m_left_hand_mode))
00168 {
00169 if(m_fly_mode)
00170 ((rviz::FPSMotionViewController*) panel->getViewController())->fly(update, 0.0, 0.0);
00171 else
00172 ((rviz::FPSMotionViewController*) panel->getViewController())->move(update, 0.0, 0.0);
00173 }
00174
00175
00176 if ((event->key() == Qt::Key_Up && !m_left_hand_mode) || (event->key() == Qt::Key_W && m_left_hand_mode))
00177 {
00178 ((rviz::FPSMotionViewController*) panel->getViewController())->changeZ(update);
00179 }
00180
00181 if ((event->key() == Qt::Key_Down && !m_left_hand_mode) || (event->key() == Qt::Key_S && m_left_hand_mode))
00182 {
00183 ((rviz::FPSMotionViewController*) panel->getViewController())->changeZ(-update);
00184 }
00185
00186
00187 if ((event->key() == Qt::Key_Left && !m_left_hand_mode) || (event->key() == Qt::Key_A && m_left_hand_mode))
00188 {
00189 ((rviz::FPSMotionViewController*) panel->getViewController())->yaw(update);
00190 }
00191
00192 if ((event->key() == Qt::Key_Right && !m_left_hand_mode) || (event->key() == Qt::Key_D && m_left_hand_mode))
00193 {
00194 ((rviz::FPSMotionViewController*) panel->getViewController())->yaw(-update);
00195 }
00196
00197
00198 if (event->key() == Qt::Key_F)
00199 {
00200 m_fly_mode = !m_fly_mode;
00201 fly_property_->setValue(m_fly_mode);
00202 fly_property_->show();
00203 }
00204
00205
00206 if (event->key() == Qt::Key_R)
00207 {
00208 m_fly_mode = false;
00209 fly_property_->setValue(m_fly_mode);
00210 fly_property_->show();
00211
00212 ((rviz::FPSMotionViewController*) panel->getViewController())->reset();
00213 }
00214
00215
00216 if (event->key() == Qt::Key_E)
00217 {
00218 context_->getToolManager()->setCurrentTool(m_fallback_tool);
00219 context_->getViewManager()->setCurrentViewControllerType(m_fallback_view_controller);
00220 }
00221 }
00222
00223 return Render;
00224 }
00225
00226 int FPSMotionTool::processMouseEvent(rviz::ViewportMouseEvent& event)
00227 {
00228 if (event.panel->getViewController())
00229 {
00230 event.panel->getViewController()->handleMouseEvent(event);
00231 setCursor( event.panel->getViewController()->getCursor() );
00232 }
00233 return 0;
00234 }
00235
00236 }
00237
00238 #include <pluginlib/class_list_macros.h>
00239 PLUGINLIB_EXPORT_CLASS(rviz::FPSMotionTool, rviz::Tool)