ModelCreator.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014-2016 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 _GAZEBO_GUI_MODEL_MODELCREATOR_HH_
18 #define _GAZEBO_GUI_MODEL_MODELCREATOR_HH_
19 
20 #include <sdf/sdf.hh>
21 
22 #include <list>
23 #include <map>
24 #include <string>
25 #include <vector>
26 #include <mutex>
27 
30 #include "gazebo/math/Pose.hh"
34 #include "gazebo/gui/qt.h"
35 
36 #include "gazebo/util/system.hh"
37 
38 namespace gazebo
39 {
40  namespace msgs
41  {
42  class Visual;
43  }
44 
45  namespace gui
46  {
47  class NestedModelData;
48  class LinkData;
49  class ModelPluginData;
50  class SaveDialog;
51  class JointMaker;
52 
55 
58  class GZ_GUI_VISIBLE ModelCreator : public QObject
59  {
60  Q_OBJECT
61 
64  public: enum EntityType
65  {
79  ENTITY_MODEL
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  public: void SaveModelFiles();
115 
117  public: void FinishModel();
118 
126  public: LinkData *AddShape(EntityType _type,
127  const math::Vector3 &_size = math::Vector3::One,
128  const math::Pose &_pose = math::Pose::Zero,
129  const std::string &_uri = "", unsigned int _samples = 5);
130 
134  public: NestedModelData *AddModel(const sdf::ElementPtr &_sdf);
135 
138  public: void AddJoint(const std::string &_type);
139 
142  public: void RemoveEntity(const std::string &_entityName);
143 
146  public: void RemoveModelPlugin(const std::string &_pluginName);
147 
150  public: void SetStatic(bool _static);
151 
154  public: void SetAutoDisable(bool _auto);
155 
157  public: void Reset();
158 
160  public: void Stop();
161 
164  public: JointMaker *GetJointMaker() const;
165 
169  public: void SetSelected(const std::string &_name, const bool selected);
170 
174  public: void SetSelected(rendering::VisualPtr _linkVis,
175  const bool selected);
176 
179  public: enum SaveState GetCurrentSaveState() const;
180 
183  public: void AddEntity(const sdf::ElementPtr &_sdf);
184 
187  public: void AddLink(EntityType _type);
188 
193  public: void OnAddModelPlugin(const std::string &_name,
194  const std::string &_filename, const std::string &_innerxml);
195 
198  public: void AddModelPlugin(const sdf::ElementPtr &_pluginElem);
199 
203  public: ModelPluginData *ModelPlugin(const std::string &_name);
204 
206  public: void GenerateSDF();
207 
211  private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
212 
214  private: void OnNew();
215 
218  private: bool OnSave();
219 
222  private: bool OnSaveAs();
223 
227  private: void OnNameChanged(const std::string &_modelName);
228 
232  private: void OnPropertiesChanged(const bool _static,
233  const bool _autoDisable);
234 
236  private: void OnExit();
237 
239  private: void Update();
240 
244  private: void RemoveNestedModelImpl(const std::string &_nestedModelName);
245 
249  private: void RemoveLinkImpl(const std::string &_linkName);
250 
253  private slots: void OnEdit(bool _checked);
254 
257  private slots: void OnEditModel(const std::string &_modelName);
258 
260  private slots: void OnCopy();
261 
263  private slots: void OnPaste();
264 
268  private: bool OnMousePress(const common::MouseEvent &_event);
269 
273  private: bool OnMouseRelease(const common::MouseEvent &_event);
274 
278  private: bool OnMouseMove(const common::MouseEvent &_event);
279 
283  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
284 
288  private: bool OnKeyPress(const common::KeyEvent &_event);
289 
292  private: void OnManipMode(const std::string &_mode);
293 
297  private: void OnSetSelectedEntity(const std::string &_name,
298  const std::string &_mode);
299 
304  private: void OnSetSelectedLink(const std::string &_name,
305  const bool _selected);
306 
311  private: void OnSetSelectedModelPlugin(const std::string &_name,
312  const bool _selected);
313 
320  private: LinkData * CreateLink(const rendering::VisualPtr &_visual);
321 
325  private: NestedModelData *CloneNestedModel(const std::string &_modelName);
326 
330  private: LinkData *CloneLink(const std::string &_linkName);
331 
337  private: LinkData *CreateLinkFromSDF(const sdf::ElementPtr &_linkElem,
338  const rendering::VisualPtr &_parentVis);
339 
342  private: void OpenInspector(const std::string &_name);
343 
346  private: void OpenModelPluginInspector(const std::string &_name);
347 
349  private: virtual void CreateTheEntity();
350 
352  private: bool Init();
353 
356  private: std::string CreateModel();
357 
366  private: NestedModelData *CreateModelFromSDF(const sdf::ElementPtr &_sdf,
367  const rendering::VisualPtr &_parentVis = NULL,
368  const bool _emit = true);
369 
377  private: void OnAlignMode(const std::string &_axis,
378  const std::string &_config, const std::string &_target,
379  const bool _preview, const bool _inverted = false);
380 
384  private: void OnEntityScaleChanged(const std::string &_name,
385  const math::Vector3 &_scale);
386 
389  private: void DeselectAll();
390 
392  private: void DeselectAllLinks();
393 
395  private: void DeselectAllNestedModels();
396 
398  private: void DeselectAllModelPlugins();
399 
404  private: void SetModelVisible(const std::string &_name, bool _visible);
405 
410  private: void SetModelVisible(rendering::VisualPtr _visual,
411  bool _visible);
412 
415  private: void ShowContextMenu(const std::string &_link);
416 
419  private: void ShowModelPluginContextMenu(const std::string &_name);
420 
423  private: void EmitNestedModelInsertedEvent(
424  const rendering::VisualPtr &_vis) const;
425 
428  private slots: void OnDelete();
429 
432  private slots: void OnDelete(const std::string &_name);
433 
435  private slots: void OnOpenInspector();
436 
439  private slots: void OnOpenModelPluginInspector(const QString &_name);
440 
443  private slots: void OnRemoveModelPlugin(const QString &_name);
444 
446  Q_SIGNALS: void LinkAdded();
447 
449  private: sdf::SDFPtr modelSDF;
450 
452  private: sdf::SDFPtr modelTemplateSDF;
453 
455  private: std::string modelName;
456 
458  private: std::string folderName;
459 
461  private: static const std::string previewName;
462 
464  private: rendering::VisualPtr previewVisual;
465 
468  private: rendering::VisualPtr mouseVisual;
469 
471  private: ignition::math::Pose3d modelPose;
472 
474  private: bool isStatic;
475 
477  private: bool autoDisable;
478 
480  private: std::vector<event::ConnectionPtr> connections;
481 
483  private: int linkCounter;
484 
486  private: int modelCounter;
487 
489  private: EntityType addEntityType;
490 
492  private: std::map<std::string, NestedModelData *> allNestedModels;
493 
495  private: std::map<std::string, LinkData *> allLinks;
496 
498  private: std::map<std::string, ModelPluginData *> allModelPlugins;
499 
501  private: transport::NodePtr node;
502 
505  private: transport::PublisherPtr makerPub;
506 
509  private: transport::PublisherPtr requestPub;
510 
512  private: JointMaker *jointMaker;
513 
515  private: math::Pose origin;
516 
518  private: std::vector<rendering::VisualPtr> selectedNestedModels;
519 
521  private: std::vector<rendering::VisualPtr> selectedLinks;
522 
524  private: std::vector<std::string> selectedModelPlugins;
525 
527  private: std::vector<std::string> copiedNames;
528 
530  private: common::MouseEvent lastMouseEvent;
531 
533  private: QAction *inspectAct;
534 
536  private: std::string inspectName;
537 
539  private: bool active;
540 
542  private: std::string manipMode;
543 
545  private: static const std::string modelDefaultName;
546 
548  private: SaveDialog *saveDialog;
549 
551  private: enum SaveState currentSaveState;
552 
554  private: std::recursive_mutex updateMutex;
555 
557  private: std::map<std::string, math::Vector3> linkScaleUpdate;
558 
561  private: std::string serverModelName;
562 
564  private: sdf::ElementPtr serverModelSDF;
565 
568  private: std::map<uint32_t, bool> serverModelVisible;
569 
571  private: std::string canonicalModel;
572 
574  private: std::string canonicalLink;
575  };
577  }
578 }
579 #endif
none
Definition: ModelCreator.hh:67
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
#define GZ_GUI_VISIBLE
Definition: system.hh:284
Imported 3D mesh.
Definition: ModelCreator.hh:75
Box.
Definition: ModelCreator.hh:69
Extruded polyline.
Definition: ModelCreator.hh:77
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Forward declarations for transport.
Definition: ModelCreator.hh:90
Definition: ModelCreator.hh:87
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:112
Sphere.
Definition: ModelCreator.hh:71
Helper class to store nested models data.
Definition: ModelData.hh:57
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:58
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:77
Helper class to store model plugin data.
Definition: ModelData.hh:224
Helper class to store link data.
Definition: ModelData.hh:90
#define NULL
Definition: CommonTypes.hh:31
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
SaveState
Save states for the model editor.
Definition: ModelCreator.hh:84
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
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
Cylinder.
Definition: ModelCreator.hh:73
A plugin with access to physics::Model.
Definition: Plugin.hh:245
EntityType
Definition: ModelCreator.hh:64