ModelCreator.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2015 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 <boost/unordered/unordered_map.hpp>
21 #include <sdf/sdf.hh>
22 
23 #include <list>
24 #include <string>
25 #include <vector>
26 
28 #include "gazebo/gui/qt.h"
30 #include "gazebo/math/Pose.hh"
32 #include "gazebo/util/system.hh"
33 
34 namespace gazebo
35 {
36  namespace msgs
37  {
38  class Visual;
39  }
40 
41  namespace gui
42  {
43  class PartData;
44 
47 
50  class GAZEBO_VISIBLE ModelCreator : public QObject
51  {
52  Q_OBJECT
53 
56  public: enum PartType
57  {
67  PART_CUSTOM
68  };
69 
71  public: ModelCreator();
72 
74  public: virtual ~ModelCreator();
75 
78  public: void SetModelName(const std::string &_modelName);
79 
82  public: std::string GetModelName() const;
83 
85  public: void FinishModel();
86 
91  public: std::string AddBox(
92  const math::Vector3 &_size = math::Vector3::One,
93  const math::Pose &_pose = math::Pose::Zero);
94 
99  public: std::string AddSphere(double _radius = 0.5,
100  const math::Pose &_pose = math::Pose::Zero);
101 
107  public: std::string AddCylinder(double _radius = 0.5,
108  double _length = 1.0, const math::Pose &_pose = math::Pose::Zero);
109 
115  public: std::string AddCustom(const std::string &_name,
116  const math::Vector3 &_scale = math::Vector3::One,
117  const math::Pose &_pose = math::Pose::Zero);
118 
121  public: void AddJoint(const std::string &_type);
122 
125  public: void RemovePart(const std::string &_partName);
126 
129  public: void SetStatic(bool _static);
130 
133  public: void SetAutoDisable(bool _auto);
134 
137  public: void SaveToSDF(const std::string &_savePath);
138 
140  public: void Reset();
141 
143  public: void Stop();
144 
147  public: JointMaker *GetJointMaker() const;
148 
151  public: void AddPart(PartType _type);
152 
154  public: void GenerateSDF();
155 
158  private slots: void OnEdit(bool _checked);
159 
161  private slots: void OnCopy();
162 
164  private slots: void OnPaste();
165 
169  private: bool OnMousePress(const common::MouseEvent &_event);
170 
174  private: bool OnMouseRelease(const common::MouseEvent &_event);
175 
179  private: bool OnMouseMove(const common::MouseEvent &_event);
180 
184  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
185 
189  private: bool OnKeyPress(const common::KeyEvent &_event);
190 
193  private: void OnManipMode(const std::string &_mode);
194 
198  private: void OnSetSelectedEntity(const std::string &_name,
199  const std::string &_mode);
200 
203  private: void CreatePart(const rendering::VisualPtr &_visual);
204 
207  private: void OpenInspector(const std::string &_name);
208 
209  // Documentation inherited
210  private: virtual void CreateTheEntity();
211 
213  private: bool Init();
214 
217  private: std::string CreateModel();
218 
221  private: std::string GetTemplateSDFString();
222 
229  private: void OnAlignMode(const std::string &_axis,
230  const std::string &_config, const std::string &_target,
231  bool _preview);
232 
234  private: void DeselectAll();
235 
238  private slots: void OnDelete(const std::string &_name="");
239 
241  Q_SIGNALS: void PartAdded();
242 
244  private: sdf::SDFPtr modelSDF;
245 
247  private: sdf::SDFPtr modelTemplateSDF;
248 
250  private: std::string modelName;
251 
253  private: rendering::VisualPtr modelVisual;
254 
256  private: rendering::VisualPtr mouseVisual;
257 
259  private: math::Pose modelPose;
260 
262  private: bool isStatic;
263 
265  private: bool autoDisable;
266 
268  private: std::vector<event::ConnectionPtr> connections;
269 
271  private: int boxCounter;
272 
274  private: int cylinderCounter;
275 
277  private: int sphereCounter;
278 
280  private: int customCounter;
281 
283  private: int modelCounter;
284 
286  private: double editTransparency;
287 
289  private: PartType addPartType;
290 
292  private: boost::unordered_map<std::string, PartData *> allParts;
293 
295  private: transport::NodePtr node;
296 
299  private: transport::PublisherPtr makerPub;
300 
303  private: transport::PublisherPtr requestPub;
304 
306  private: JointMaker *jointMaker;
307 
309  private: math::Pose origin;
310 
312  private: std::vector<rendering::VisualPtr> selectedVisuals;
313 
315  private: std::vector<std::string> copiedPartNames;
316 
318  private: common::MouseEvent lastMouseEvent;
319 
321  private: rendering::VisualPtr inspectVis;
322 
324  private: bool active;
325 
327  private: std::string manipMode;
328  };
330  }
331 }
332 
333 #endif
Box.
Definition: ModelCreator.hh:61
Generic description of a mouse event.
Definition: MouseEvent.hh:32
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
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Forward declarations for transport.
Sphere.
Definition: ModelCreator.hh:63
PartType
Definition: ModelCreator.hh:56
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:50
none
Definition: ModelCreator.hh:59
Joint visualization.
Definition: JointMaker.hh:57
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
static const Pose Zero
math::Pose(0, 0, 0, 0, 0, 0)
Definition: Pose.hh:43
Cylinder.
Definition: ModelCreator.hh:65
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48