Go to the documentation of this file.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
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <QApplication>
00037 #include <QMenu>
00038 #include <QTimer>
00039 #include <ros/ros.h>
00040 #include <rviz/tool_manager.h>
00041 #include <rviz/display_context.h>
00042 #include <rviz/view_manager.h>
00043 #include <rviz/display_group.h>
00044 #include <rviz/display.h>
00045
00046 #include "overlay_picker_tool.h"
00047 #include "overlay_text_display.h"
00048 #include "plotter_2d_display.h"
00049 #include "pie_chart_display.h"
00050 #include "overlay_image_display.h"
00051 #include "overlay_diagnostic_display.h"
00052
00053 namespace jsk_rviz_plugins
00054 {
00055 OverlayPickerTool::OverlayPickerTool()
00056 : is_moving_(false), shift_pressing_(false), rviz::Tool()
00057 {
00058
00059 }
00060
00061 int OverlayPickerTool::processKeyEvent(QKeyEvent* event, rviz::RenderPanel* panel)
00062 {
00063 if (event->type() == QEvent::KeyPress && event->key() == 16777248) {
00064 shift_pressing_ = true;
00065 }
00066 else if (event->type() == QEvent::KeyRelease && event->key() == 16777248) {
00067 shift_pressing_ = false;
00068 }
00069 return 0;
00070 }
00071
00072
00073 int OverlayPickerTool::processMouseEvent(rviz::ViewportMouseEvent& event)
00074 {
00075 if (event.left() && event.leftDown()) {
00076 if (!is_moving_) {
00077 onClicked(event);
00078 }
00079 }
00080 else if (event.left() && is_moving_) {
00081 onMove(event);
00082 }
00083 else if (is_moving_ && !(event.left() && event.leftDown())) {
00084 onRelease(event);
00085 }
00086 return 0;
00087 }
00088
00089 bool OverlayPickerTool::handleDisplayClick(rviz::Property* property, rviz::ViewportMouseEvent& event)
00090 {
00091 if (isPropertyType<rviz::DisplayGroup>(property)) {
00092 rviz::DisplayGroup* group_property = isPropertyType<rviz::DisplayGroup>(property);
00093 for (int i = 0; i < group_property->numChildren(); i++) {
00094 if (handleDisplayClick(group_property->childAt(i), event)) {
00095 return true;
00096 }
00097 }
00098 }
00099 else {
00100 if (startMovement<OverlayTextDisplay>(property, event, "overlay_text_display")) {
00101 return true;
00102 }
00103 else if (startMovement<Plotter2DDisplay>(property, event, "plotter_2d_display")) {
00104 return true;
00105 }
00106 else if (startMovement<PieChartDisplay>(property, event, "pie_chart_display")) {
00107 return true;
00108 }
00109 else if (startMovement<OverlayImageDisplay>(property, event, "overlay_image_display")) {
00110 return true;
00111 }
00112 else if (startMovement<OverlayDiagnosticDisplay>(property, event, "overlay_diagnostic_display")) {
00113 return true;
00114 }
00115 else {
00116 return false;
00117 }
00118 }
00119 return false;
00120 }
00121
00122 void OverlayPickerTool::onClicked(rviz::ViewportMouseEvent& event)
00123 {
00124 ROS_DEBUG("onClicked");
00125 is_moving_ = true;
00126 ROS_DEBUG("clicked: (%d, %d)", event.x, event.y);
00127
00128 rviz::DisplayGroup* display_group = context_->getRootDisplayGroup();
00129 handleDisplayClick(display_group, event);
00130 }
00131
00132 void OverlayPickerTool::onMove(rviz::ViewportMouseEvent& event)
00133 {
00134 ROS_DEBUG("onMove");
00135 ROS_DEBUG("moving: (%d, %d)", event.x, event.y);
00136 if (target_property_) {
00137 if (target_property_type_ == "overlay_text_display") {
00138 movePosition<OverlayTextDisplay>(event);
00139 }
00140 else if (target_property_type_ == "plotter_2d_display") {
00141 movePosition<Plotter2DDisplay>(event);
00142 }
00143 else if (target_property_type_ == "pie_chart_display") {
00144 movePosition<PieChartDisplay>(event);
00145 }
00146 else if (target_property_type_ == "overlay_image_display") {
00147 movePosition<OverlayImageDisplay>(event);
00148 }
00149 else if (target_property_type_ == "overlay_diagnostic_display") {
00150 movePosition<OverlayDiagnosticDisplay>(event);
00151 }
00152 }
00153 }
00154
00155 void OverlayPickerTool::onRelease(rviz::ViewportMouseEvent& event)
00156 {
00157 ROS_DEBUG("onRelease");
00158 is_moving_ = false;
00159 ROS_DEBUG("released: (%d, %d)", event.x, event.y);
00160 if (target_property_) {
00161 if (target_property_type_ == "overlay_text_display") {
00162 setPosition<OverlayTextDisplay>(event);
00163 }
00164 else if (target_property_type_ == "plotter_2d_display") {
00165 setPosition<Plotter2DDisplay>(event);
00166 }
00167 else if (target_property_type_ == "pie_chart_display") {
00168 setPosition<PieChartDisplay>(event);
00169 }
00170 else if (target_property_type_ == "overlay_image_display") {
00171 setPosition<OverlayImageDisplay>(event);
00172 }
00173 else if (target_property_type_ == "overlay_diagnostic_display") {
00174 setPosition<OverlayDiagnosticDisplay>(event);
00175 }
00176 }
00177
00178 target_property_ = NULL;
00179 target_property_type_ = "";
00180 }
00181
00182 }
00183
00184 #include <pluginlib/class_list_macros.h>
00185 PLUGINLIB_EXPORT_CLASS( jsk_rviz_plugins::OverlayPickerTool, rviz::Tool )