Flatland
spawn_model_tool.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name spawn_model_tool.h
11  * @brief Rviz compatible tool for spawning flatland model
12  * @author Joseph Duchesne
13  * @author Mike Brousseau
14  *
15  * Software License Agreement (BSD License)
16  *
17  * Copyright (c) 2017, Avidbots Corp.
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions
22  * are met:
23  *
24  * * Redistributions of source code must retain the above copyright
25  * notice, this list of conditions and the following disclaimer.
26  * * Redistributions in binary form must reproduce the above
27  * copyright notice, this list of conditions and the following
28  * disclaimer in the documentation and/or other materials provided
29  * with the distribution.
30  * * Neither the name of the Avidbots Corp. nor the names of its
31  * contributors may be used to endorse or promote products derived
32  * from this software without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
37  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
38  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
39  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
40  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
42  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
44  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45  * POSSIBILITY OF SUCH DAMAGE.
46  */
47 
48 #ifndef SPAWN_MODEL_TOOL_H
49 #define SPAWN_MODEL_TOOL_H
50 
51 #include <rviz/tool.h>
52 
53 #include <OGRE/OgreEntity.h>
54 #include <OGRE/OgreSceneManager.h>
55 #include <OGRE/OgreSceneNode.h>
56 #include <OgreVector3.h>
57 
58 #include <ros/ros.h>
59 #include "rviz/ogre_helpers/arrow.h"
60 
61 namespace flatland_viz {
67 class SpawnModelTool : public rviz::Tool {
68  Q_OBJECT
69 
70  public:
72  ~SpawnModelTool();
73 
79  void BeginPlacement();
84  void SavePath(QString p);
89  void SaveName(QString n);
94  void SpawnModelInFlatland();
95 
96  private:
101  virtual void onInitialize();
107  virtual void activate();
112  virtual void deactivate();
118  virtual int processMouseEvent(rviz::ViewportMouseEvent &event);
124  void SetMovingModelColor(QColor c);
125 
126  Ogre::Vector3
127  intersection; // location cursor intersects ground plane, ie the
128  // location to create the model
129  float initial_angle; // the angle to create the model at
130  Ogre::SceneNode *moving_model_node_; // the node for the 3D object
131  std::string model_resource_; // path to 3d model
132  enum ModelState { m_hidden, m_dragging, m_rotating };
133  ModelState model_state; // model state, first hidden, then dragging to
134  // intersection point, then rotating to desired angle
135  static QString path_to_model_file; // full path to model file (yaml)
136  static QString model_name; // base file name with path and extension removed
137 
138  protected:
139  rviz::Arrow *arrow_; // Rviz 3d arrow to show axis of rotation
140  ros::NodeHandle nh; // ros service node handle
141  ros::ServiceClient client; // ros service client
142 };
143 
144 } // end namespace flatland_viz
145 
146 #endif // SPAWN_MODEL_TOOL_H
Definition: load_model_dialog.h:78
Definition: spawn_model_tool.h:67