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 <sdf/sdf.hh>
21 
22 #include <list>
23 #include <map>
24 #include <string>
25 #include <vector>
26 
29 #include "gazebo/math/Pose.hh"
33 #include "gazebo/gui/qt.h"
34 
35 #include "gazebo/util/system.hh"
36 
37 namespace boost
38 {
39  class recursive_mutex;
40 }
41 
42 namespace gazebo
43 {
44  namespace msgs
45  {
46  class Visual;
47  }
48 
49  namespace gui
50  {
51  class LinkData;
52  class SaveDialog;
53  class JointMaker;
54 
57 
60  class GZ_GUI_MODEL_VISIBLE ModelCreator : public QObject
61  {
62  Q_OBJECT
63 
66  public: enum LinkType
67  {
79  LINK_POLYLINE
80  };
81 
84  public: enum SaveState
85  {
86  // NEVER_SAVED: The model has never been saved.
88 
89  // ALL_SAVED: All changes have been saved.
91 
92  // UNSAVED_CHANGES: Has been saved before, but has unsaved changes.
93  UNSAVED_CHANGES
94  };
95 
97  public: ModelCreator();
98 
100  public: virtual ~ModelCreator();
101 
104  public: void SetModelName(const std::string &_modelName);
105 
108  public: std::string GetModelName() const;
109 
111  public: void ModelChanged();
112 
114  private: void OnNew();
115 
117  public: void SaveModelFiles();
118 
121  private: bool OnSave();
122 
125  private: bool OnSaveAs();
126 
129  private: void OnNameChanged(const std::string &_modelName);
130 
132  private: void OnExit();
133 
135  private: void Update();
136 
138  public: void FinishModel();
139 
146  public: std::string AddShape(LinkType _type,
147  const math::Vector3 &_size = math::Vector3::One,
148  const math::Pose &_pose = math::Pose::Zero,
149  const std::string &_uri = "", unsigned int _samples = 5);
150 
155  public: std::string AddBox(
156  const math::Vector3 &_size = math::Vector3::One,
157  const math::Pose &_pose = math::Pose::Zero);
158 
163  public: std::string AddSphere(double _radius = 0.5,
164  const math::Pose &_pose = math::Pose::Zero);
165 
171  public: std::string AddCylinder(double _radius = 0.5,
172  double _length = 1.0, const math::Pose &_pose = math::Pose::Zero);
173 
179  public: std::string AddCustom(const std::string &_name,
180  const math::Vector3 &_scale = math::Vector3::One,
181  const math::Pose &_pose = math::Pose::Zero);
182 
185  public: void AddJoint(const std::string &_type);
186 
189  public: void RemoveLink(const std::string &_linkName);
190 
193  public: void SetStatic(bool _static);
194 
197  public: void SetAutoDisable(bool _auto);
198 
200  public: void Reset();
201 
203  public: void Stop();
204 
207  public: JointMaker *GetJointMaker() const;
208 
212  public: void SetSelected(const std::string &_name, const bool selected);
213 
217  public: void SetSelected(rendering::VisualPtr _linkVis,
218  const bool selected);
219 
222  public: enum SaveState GetCurrentSaveState() const;
223 
226  public: void AddLink(LinkType _type);
227 
229  public: void GenerateSDF();
230 
234  private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
235 
239  private: void RemoveLinkImpl(const std::string &_linkName);
240 
243  private slots: void OnEdit(bool _checked);
244 
247  private slots: void OnEditModel(const std::string &_modelName);
248 
250  private slots: void OnCopy();
251 
253  private slots: void OnPaste();
254 
258  private: bool OnMousePress(const common::MouseEvent &_event);
259 
263  private: bool OnMouseRelease(const common::MouseEvent &_event);
264 
268  private: bool OnMouseMove(const common::MouseEvent &_event);
269 
273  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
274 
278  private: bool OnKeyPress(const common::KeyEvent &_event);
279 
282  private: void OnManipMode(const std::string &_mode);
283 
287  private: void OnSetSelectedEntity(const std::string &_name,
288  const std::string &_mode);
289 
294  private: void OnSetSelectedLink(const std::string &_name,
295  const bool _selected);
296 
302  private: void CreateLink(const rendering::VisualPtr &_visual);
303 
307  private: LinkData *CloneLink(const std::string &_linkName);
308 
312  private: void CreateLinkFromSDF(sdf::ElementPtr _linkElem);
313 
316  private: void OpenInspector(const std::string &_name);
317 
318  // Documentation inherited
319  private: virtual void CreateTheEntity();
320 
322  private: bool Init();
323 
326  private: std::string CreateModel();
327 
331  private: void LoadSDF(sdf::ElementPtr _sdf);
332 
339  private: void OnAlignMode(const std::string &_axis,
340  const std::string &_config, const std::string &_target,
341  bool _preview);
342 
346  private: void OnEntityScaleChanged(const std::string &_name,
347  const math::Vector3 &_scale);
348 
350  private: void DeselectAll();
351 
356  private: void SetModelVisible(const std::string &_name, bool _visible);
357 
362  private: void SetModelVisible(rendering::VisualPtr _visual,
363  bool _visible);
364 
367  private: void ShowContextMenu(const std::string &_link);
368 
371  private slots: void OnDelete();
372 
375  private slots: void OnDelete(const std::string &_name);
376 
378  private slots: void OnOpenInspector();
379 
381  Q_SIGNALS: void LinkAdded();
382 
384  private: sdf::SDFPtr modelSDF;
385 
387  private: sdf::SDFPtr modelTemplateSDF;
388 
390  private: std::string modelName;
391 
393  private: std::string folderName;
394 
396  private: static const std::string previewName;
397 
399  private: rendering::VisualPtr previewVisual;
400 
402  private: rendering::VisualPtr mouseVisual;
403 
405  private: math::Pose modelPose;
406 
408  private: bool isStatic;
409 
411  private: bool autoDisable;
412 
414  private: std::vector<event::ConnectionPtr> connections;
415 
417  private: int linkCounter;
418 
420  private: int modelCounter;
421 
423  private: LinkType addLinkType;
424 
426  private: std::map<std::string, LinkData *> allLinks;
427 
429  private: transport::NodePtr node;
430 
433  private: transport::PublisherPtr makerPub;
434 
437  private: transport::PublisherPtr requestPub;
438 
440  private: JointMaker *jointMaker;
441 
443  private: math::Pose origin;
444 
446  private: std::vector<rendering::VisualPtr> selectedLinks;
447 
449  private: std::vector<std::string> copiedLinkNames;
450 
452  private: common::MouseEvent lastMouseEvent;
453 
455  private: QAction *inspectAct;
456 
458  private: std::string inspectName;
459 
461  private: bool active;
462 
464  private: std::string manipMode;
465 
467  private: static const std::string modelDefaultName;
468 
470  private: SaveDialog *saveDialog;
471 
473  private: enum SaveState currentSaveState;
474 
476  private: boost::recursive_mutex *updateMutex;
477 
479  private: std::map<std::string, math::Vector3> linkScaleUpdate;
480 
483  private: std::string serverModelName;
484 
486  private: sdf::ElementPtr serverModelSDF;
487 
490  private: std::map<uint32_t, bool> serverModelVisible;
491 
493  private: std::string canonicalLink;
494  };
496  }
497 }
498 
499 #endif
none
Definition: ModelCreator.hh:69
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Dialog for saving to file.
Definition: SaveDialog.hh:37
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Forward declarations for transport.
Sphere.
Definition: ModelCreator.hh:73
Definition: ModelCreator.hh:90
Definition: ModelCreator.hh:87
static const Vector3 One
math::Vector3(1, 1, 1)
Definition: Vector3.hh:45
Create and manage 3D visuals of a model with links and joints.
Definition: ModelCreator.hh:60
Joint visualization.
Definition: JointMaker.hh:58
LinkType
Definition: ModelCreator.hh:66
Helper class to store link data.
Definition: ModelData.hh:56
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
#define GZ_GUI_MODEL_VISIBLE
Definition: system.hh:418
Cylinder.
Definition: ModelCreator.hh:75
Imported 3D mesh.
Definition: ModelCreator.hh:77
SaveState
Save states for the model editor.
Definition: ModelCreator.hh:84
Box.
Definition: ModelCreator.hh:71
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:107
static const Pose Zero
math::Pose(0, 0, 0, 0, 0, 0)
Definition: Pose.hh:40
boost::shared_ptr< Publisher > PublisherPtr
Definition: TransportTypes.hh:49