00001 // ***************************************************************************** 00002 // 00003 // Copyright (c) 2014, Southwest Research Institute® (SwRI®) 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // * Redistributions of source code must retain the above copyright 00009 // notice, this list of conditions and the following disclaimer. 00010 // * Redistributions in binary form must reproduce the above copyright 00011 // notice, this list of conditions and the following disclaimer in the 00012 // documentation and/or other materials provided with the distribution. 00013 // * Neither the name of Southwest Research Institute® (SwRI®) nor the 00014 // names of its contributors may be used to endorse or promote products 00015 // derived from this software without specific prior written permission. 00016 // 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 // 00028 // ***************************************************************************** 00029 00030 #ifndef MAPVIZ_PLUGINS_PLAN_ROUTE_PLUGIN_H_ 00031 #define MAPVIZ_PLUGINS_PLAN_ROUTE_PLUGIN_H_ 00032 00033 // C++ standard libraries 00034 #include <string> 00035 #include <vector> 00036 00037 #include <mapviz/mapviz_plugin.h> 00038 00039 // QT libraries 00040 #include <QGLWidget> 00041 #include <QObject> 00042 #include <QWidget> 00043 00044 // ROS libraries 00045 #include <ros/ros.h> 00046 #include <tf/transform_datatypes.h> 00047 00048 // Mapviz libraries 00049 #include <mapviz/map_canvas.h> 00050 #include <swri_route_util/route.h> 00051 00052 // Messages 00053 #include <geometry_msgs/Pose.h> 00054 #include <marti_nav_msgs/Route.h> 00055 00056 // QT autogenerated files 00057 #include "ui_plan_route_config.h" 00058 00059 namespace mapviz_plugins 00060 { 00061 class PlanRoutePlugin : public mapviz::MapvizPlugin 00062 { 00063 Q_OBJECT 00064 00065 public: 00066 00067 PlanRoutePlugin(); 00068 virtual ~PlanRoutePlugin(); 00069 00070 bool Initialize(QGLWidget* canvas); 00071 void Shutdown() 00072 { 00073 } 00074 00075 void Draw(double x, double y, double scale); 00076 void Paint(QPainter* painter, double x, double y, double scale); 00077 00078 void Transform() {}; 00079 00080 void LoadConfig(const YAML::Node& node, const std::string& path); 00081 void SaveConfig(YAML::Emitter& emitter, const std::string& path); 00082 00083 QWidget* GetConfigWidget(QWidget* parent); 00084 00085 bool SupportsPainting() 00086 { 00087 return true; 00088 } 00089 00090 protected: 00091 void PrintError(const std::string& message); 00092 void PrintInfo(const std::string& message); 00093 void PrintWarning(const std::string& message); 00094 bool eventFilter(QObject *object, QEvent* event); 00095 bool handleMousePress(QMouseEvent *); 00096 bool handleMouseRelease(QMouseEvent *); 00097 bool handleMouseMove(QMouseEvent *); 00098 00099 protected Q_SLOTS: 00100 void PublishRoute(); 00101 void PlanRoute(); 00102 void Clear(); 00103 00104 private: 00105 void Retry(const ros::TimerEvent& e); 00106 00107 Ui::plan_route_config ui_; 00108 QWidget* config_widget_; 00109 mapviz::MapCanvas* map_canvas_; 00110 00111 std::string route_topic_; 00112 00113 ros::Publisher route_pub_; 00114 ros::Timer retry_timer_; 00115 00116 bool failed_service_; 00117 swri_route_util::RoutePtr route_preview_; 00118 00119 std::vector<geometry_msgs::Pose> waypoints_; 00120 00121 int selected_point_; 00122 bool is_mouse_down_; 00123 QPointF mouse_down_pos_; 00124 qint64 mouse_down_time_; 00125 00126 qint64 max_ms_; 00127 qreal max_distance_; 00128 }; 00129 } 00130 00131 #endif // MAPVIZ_PLUGINS_PLAN_ROUTE_PLUGIN_H_