All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ModelCreator.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2013 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _MODEL_CREATOR_HH_
18 #define _MODEL_CREATOR_HH_
19 
20 #include <list>
21 #include <string>
22 #include <vector>
23 
24 #include <boost/unordered/unordered_map.hpp>
25 
26 #include <sdf/sdf.hh>
27 
30 #include "gazebo/math/Pose.hh"
32 
33 #include "gazebo/gui/qt.h"
35 #include "gazebo/util/system.hh"
36 
37 namespace gazebo
38 {
39  namespace msgs
40  {
41  class Visual;
42  }
43 
44  namespace gui
45  {
46  class PartData;
47 
50 
53  class GAZEBO_VISIBLE ModelCreator : public QObject
54  {
55  Q_OBJECT
56 
59  public: enum PartType
60  {
70  PART_CUSTOM
71  };
72 
74  public: ModelCreator();
75 
77  public: virtual ~ModelCreator();
78 
81  public: void SetModelName(const std::string &_modelName);
82 
85  public: std::string GetModelName() const;
86 
88  public: void FinishModel();
89 
94  public: std::string AddBox(
95  const math::Vector3 &_size = math::Vector3::One,
96  const math::Pose &_pose = math::Pose::Zero);
97 
102  public: std::string AddSphere(double _radius = 0.5,
103  const math::Pose &_pose = math::Pose::Zero);
104 
110  public: std::string AddCylinder(double _radius = 0.5,
111  double _length = 1.0, const math::Pose &_pose = math::Pose::Zero);
112 
118  public: std::string AddCustom(const std::string &_name,
119  const math::Vector3 &_scale = math::Vector3::One,
120  const math::Pose &_pose = math::Pose::Zero);
121 
125  public: void AddJoint(JointMaker::JointType _type);
126 
129  public: void RemovePart(const std::string &_partName);
130 
133  public: void SetStatic(bool _static);
134 
137  public: void SetAutoDisable(bool _auto);
138 
141  public: void SaveToSDF(const std::string &_savePath);
142 
144  public: void Reset();
145 
147  public: void Stop();
148 
151  public: JointMaker *GetJointMaker() const;
152 
155  public: void AddPart(PartType _type);
156 
158  public: void GenerateSDF();
159 
163  private: bool OnMouseMovePart(const common::MouseEvent &_event);
164 
168  private: bool OnMouseReleasePart(const common::MouseEvent &_event);
169 
173  private: bool OnMouseDoubleClickPart(const common::MouseEvent &_event);
174 
178  private: bool OnKeyPressPart(const common::KeyEvent &_event);
179 
182  private: void CreatePart(const rendering::VisualPtr &_visual);
183 
184  // Documentation inherited
185  private: virtual void CreateTheEntity();
186 
188  private: bool Init();
189 
192  private: std::string CreateModel();
193 
196  private: std::string GetTemplateSDFString();
197 
200  private slots: void OnDelete(const std::string &_name="");
201 
203  Q_SIGNALS: void PartAdded();
204 
206  private: sdf::SDFPtr modelSDF;
207 
209  private: sdf::SDFPtr modelTemplateSDF;
210 
212  private: std::string modelName;
213 
215  private: rendering::VisualPtr modelVisual;
216 
218  private: rendering::VisualPtr mouseVisual;
219 
221  private: math::Pose modelPose;
222 
224  private: bool isStatic;
225 
227  private: bool autoDisable;
228 
230  private: std::vector<event::ConnectionPtr> connections;
231 
233  private: int boxCounter;
234 
236  private: int cylinderCounter;
237 
239  private: int sphereCounter;
240 
242  private: int customCounter;
243 
245  private: int modelCounter;
246 
248  private: PartType addPartType;
249 
251  private: boost::unordered_map<std::string, PartData *> allParts;
252 
254  private: transport::NodePtr node;
255 
258  private: transport::PublisherPtr makerPub;
259 
262  private: transport::PublisherPtr requestPub;
263 
265  private: JointMaker *jointMaker;
266 
268  private: math::Pose origin;
269 
271  private: rendering::VisualPtr selectedVis;
272  };
274 
278  {
280  public: std::string name;
281 
283  public: std::string type;
284 
287 
289  public: bool visualize;
290 
292  public: bool alwaysOn;
293 
295  public: std::string topicName;
296  };
297 
300  class GAZEBO_VISIBLE PartData : public QObject
301  {
302  Q_OBJECT
303 
305  public: std::string name;
306 
308  public: std::vector<rendering::VisualPtr> visuals;
309 
311  public: bool gravity;
312 
314  public: bool selfCollide;
315 
317  public: bool kinematic;
318 
320  public: math::Pose pose;
321 
324 
326  public: std::vector<physics::CollisionPtr> collisions;
327 
330  };
331  }
332 }
333 #endif
Box.
Definition: ModelCreator.hh:64
Generic description of a mouse event.
Definition: MouseEvent.hh:32
std::vector< physics::CollisionPtr > collisions
Name of part.
Definition: ModelCreator.hh:326
std::string topicName
Sensor topic name.
Definition: ModelCreator.hh:295
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
bool visualize
True to visualize sensor.
Definition: ModelCreator.hh:289
bool selfCollide
True to allow self collision.
Definition: ModelCreator.hh:314
Generic description of a keyboard event.
Definition: KeyEvent.hh:31
Forward declarations for transport.
math::Pose pose
Pose of part.
Definition: ModelCreator.hh:320
std::string type
Type of sensor.
Definition: ModelCreator.hh:283
bool kinematic
True to make part kinematic.
Definition: ModelCreator.hh:317
Sphere.
Definition: ModelCreator.hh:66
default namespace for gazebo
PartType
Definition: ModelCreator.hh:59
std::vector< rendering::VisualPtr > visuals
Visuals of the part.
Definition: ModelCreator.hh:308
static const Vector3 One
math::Vector3(1, 1, 1)
Definition: Vector3.hh:49
Create and manage 3D visuals of a model with parts and joints.
Definition: ModelCreator.hh:53
none
Definition: ModelCreator.hh:62
Joint visualization.
Definition: JointMaker.hh:46
math::Vector3 pose
Pose of sensor.
Definition: ModelCreator.hh:286
JointType
Definition: JointMaker.hh:52
A class for inertial information about a link.
Definition: Inertial.hh:39
bool alwaysOn
True to set sensor to be always on.
Definition: ModelCreator.hh:292
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:52
std::string name
Name of sensor.
Definition: ModelCreator.hh:280
std::string name
Name of part.
Definition: ModelCreator.hh:305
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Helper class to store sensor data.
Definition: ModelCreator.hh:277
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:100
static const Pose Zero
math::Pose(0, 0, 0, 0, 0, 0)
Definition: Pose.hh:43
physics::Inertial * inertial
Name of part.
Definition: ModelCreator.hh:323
Cylinder.
Definition: ModelCreator.hh:68
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:44
SensorData * sensorData
Sensor data.
Definition: ModelCreator.hh:329
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
bool gravity
True to enable gravity on part.
Definition: ModelCreator.hh:311
Helper class to store part data.
Definition: ModelCreator.hh:300