ModelCreator.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 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 
18 #ifndef GAZEBO_GUI_MODEL_MODELCREATOR_HH_
19 #define GAZEBO_GUI_MODEL_MODELCREATOR_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <mutex>
24 #include <string>
25 
26 #include <ignition/math/Pose3.hh>
27 #include <ignition/math/Vector3.hh>
28 #include <sdf/sdf.hh>
29 
30 #include "gazebo/gui/qt.h"
31 
33 
34 #include "gazebo/util/system.hh"
35 
36 namespace gazebo
37 {
38  namespace common
39  {
40  class KeyEvent;
41  class MouseEvent;
42  }
43 
44  namespace gui
45  {
46  class JointMaker;
47  class LinkData;
48  class ModelPluginData;
49  class NestedModelData;
50 
51  // Forward declare private data.
52  class ModelCreatorPrivate;
53 
56 
60  class GZ_GUI_VISIBLE ModelCreator : public QObject
61  {
62  Q_OBJECT
63 
66  public: enum EntityType
67  {
81  ENTITY_MODEL
82  };
83 
86  public: enum SaveState
87  {
90 
93 
95  UNSAVED_CHANGES
96  };
97 
100  public: ModelCreator(QObject *_parent = NULL);
101 
103  public: virtual ~ModelCreator();
104 
106  public: void EnableEventHandlers();
107 
109  public: void DisableEventHandlers();
110 
113  public: void SetModelName(const std::string &_modelName);
114 
117  public: std::string ModelName() const;
118 
120  public: void ModelChanged();
121 
123  public: void SaveModelFiles();
124 
126  public: void FinishModel();
127 
134  public: void AddCustomLink(const EntityType _type,
135  const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
136  const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
137  const std::string &_uri = "", const unsigned int _samples = 5);
138 
146  public: LinkData *AddShape(const EntityType _type,
147  const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
148  const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
149  const std::string &_uri = "", const unsigned int _samples = 5);
150 
154  public: NestedModelData *AddModel(const sdf::ElementPtr &_sdf);
155 
158  public: void AddJoint(const std::string &_type);
159 
162  public: void RemoveEntity(const std::string &_entityName);
163 
168  public: void RemoveModelPlugin(const std::string &_pluginName,
169  const bool _newCmd = true);
170 
173  public: void SetStatic(const bool _static);
174 
177  public: void SetAutoDisable(const bool _auto);
178 
180  public: void Reset();
181 
183  public: void Stop();
184 
187  public: gui::JointMaker *JointMaker() const;
188 
192  public: void SetSelected(const std::string &_name, const bool selected);
193 
197  public: void SetSelected(const rendering::VisualPtr &_entityVis,
198  const bool selected);
199 
202  public: enum SaveState CurrentSaveState() const;
203 
206  public: void AddEntity(const sdf::ElementPtr &_sdf);
207 
210  public: void AddLink(const EntityType _type);
211 
218  public: void OnAddModelPlugin(const std::string &_name,
219  const std::string &_filename, const std::string &_innerxml,
220  const bool _newCmd = true);
221 
224  public: void AddModelPlugin(const sdf::ElementPtr &_pluginElem);
225 
229  public: ModelPluginData *ModelPlugin(const std::string &_name);
230 
232  public: void GenerateSDF();
233 
236  public slots: void ShowCollisions(const bool _show);
237 
240  public slots: void ShowVisuals(const bool _show);
241 
244  public slots: void ShowLinkFrames(const bool _show);
245 
250  public: ignition::math::Pose3d WorldToLocal(
251  const ignition::math::Pose3d &_world) const;
252 
256  private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
257 
259  private: void OnNew();
260 
263  private: bool OnSave();
264 
267  private: bool OnSaveAs();
268 
272  private: void OnNameChanged(const std::string &_modelName);
273 
277  private: void OnPropertiesChanged(const bool _static,
278  const bool _autoDisable);
279 
281  private: void OnExit();
282 
286  private: void RemoveNestedModelImpl(const std::string &_nestedModelName);
287 
291  private: void RemoveLinkImpl(const std::string &_linkName);
292 
295  private slots: void OnEdit(const bool _checked);
296 
299  private slots: void OnEditModel(const std::string &_modelName);
300 
302  private slots: void OnCopy();
303 
305  private slots: void OnPaste();
306 
310  private: bool OnMousePress(const common::MouseEvent &_event);
311 
315  private: bool OnMouseRelease(const common::MouseEvent &_event);
316 
320  private: bool OnMouseMove(const common::MouseEvent &_event);
321 
325  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
326 
330  private: bool OnKeyPress(const common::KeyEvent &_event);
331 
334  private: void OnManipMode(const std::string &_mode);
335 
339  private: void OnDeselectAll(const std::string &_name,
340  const std::string &_mode);
341 
346  private: void OnSetSelectedEntity(const std::string &_name,
347  const bool _selected);
348 
353  private: void OnSetSelectedModelPlugin(const std::string &_name,
354  const bool _selected);
355 
362  private: LinkData *CreateLink(const rendering::VisualPtr &_visual);
363 
366  private: void InsertLinkFromSDF(sdf::ElementPtr _sdf);
367 
370  private: void InsertNestedModelFromSDF(sdf::ElementPtr _sdf);
371 
375  private: NestedModelData *CloneNestedModel(const std::string &_modelName);
376 
380  private: LinkData *CloneLink(const std::string &_linkName);
381 
387  private: LinkData *CreateLinkFromSDF(const sdf::ElementPtr &_linkElem,
388  const rendering::VisualPtr &_parentVis);
389 
392  private: void OpenInspector(const std::string &_name);
393 
396  private: void OpenModelPluginInspector(const std::string &_name);
397 
399  private: virtual void CreateTheEntity();
400 
402  private: bool Init();
403 
406  private: std::string CreateModel();
407 
416  private: NestedModelData *CreateModelFromSDF(const sdf::ElementPtr &_sdf,
417  const rendering::VisualPtr &_parentVis = NULL,
418  const bool _emit = true);
419 
427  private: void OnAlignMode(const std::string &_axis,
428  const std::string &_config, const std::string &_target,
429  const bool _preview, const bool _inverted = false);
430 
434  private: void OnEntityScaleChanged(const std::string &_name,
435  const ignition::math::Vector3d &_scale);
436 
442  private: void OnEntityMoved(const std::string &_name,
443  const ignition::math::Pose3d &_pose, const bool _isFinal);
444 
447  private: void DeselectAll();
448 
450  private: void DeselectAllEntities();
451 
453  private: void DeselectAllModelPlugins();
454 
458  private: void OnRequestLinkScale(const std::string &_name,
459  const std::map<std::string, ignition::math::Vector3d> &_scales);
460 
464  private: void OnRequestLinkMove(const std::string &_name,
465  const ignition::math::Pose3d &_pose);
466 
470  private: void OnRequestNestedModelMove(const std::string &_name,
471  const ignition::math::Pose3d &_pose);
472 
477  private: void SetModelVisible(const std::string &_name,
478  const bool _visible);
479 
484  private: void SetModelVisible(const rendering::VisualPtr &_visual,
485  const bool _visible);
486 
489  private: void ShowContextMenu(const std::string &_link);
490 
493  private: void ShowModelPluginContextMenu(const std::string &_name);
494 
497  private: void EmitNestedModelInsertedEvent(
498  const rendering::VisualPtr &_vis) const;
499 
502  private slots: void OnDelete();
503 
506  private slots: void OnDelete(const std::string &_name);
507 
509  private slots: void OnOpenInspector();
510 
513  private slots: void OnOpenModelPluginInspector(const QString &_name);
514 
517  private slots: void OnRemoveModelPlugin(const QString &_name);
518 
520  Q_SIGNALS: void LinkAdded();
521 
524  private: std::unique_ptr<ModelCreatorPrivate> dataPtr;
525  };
527  }
528 }
529 #endif
Extruded polyline.
Definition: ModelCreator.hh:79
none
Definition: ModelCreator.hh:69
EntityType
Definition: ModelCreator.hh:66
Generic description of a mouse event.
Definition: MouseEvent.hh:35
Forward declarations for the common classes.
Definition: Animation.hh:33
Generic description of a keyboard event.
Definition: KeyEvent.hh:32
Sphere.
Definition: ModelCreator.hh:73
Cylinder.
Definition: ModelCreator.hh:75
Helper class to store nested models data.
Definition: ModelData.hh:57
Create and manage 3D visuals of a model with links, nested models and joints.
Definition: ModelCreator.hh:60
Box.
Definition: ModelCreator.hh:71
Handles the creation of joints in the model editor.
Definition: JointMaker.hh:76
The model has never been saved.
Definition: ModelCreator.hh:89
SaveState
Save states for the model editor.
Definition: ModelCreator.hh:86
Helper class to store model plugin data.
Definition: ModelData.hh:309
Helper class to store link data.
Definition: ModelData.hh:94
Imported 3D mesh.
Definition: ModelCreator.hh:77
#define NULL
Definition: CommonTypes.hh:31
All changes have been saved.
Definition: ModelCreator.hh:92
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
A plugin with access to physics::Model.
Definition: Plugin.hh:260