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 
18 #ifndef _GAZEBO_GUI_MODEL_MODELCREATOR_HH_
19 #define _GAZEBO_GUI_MODEL_MODELCREATOR_HH_
20 
21 #include <memory>
22 #include <mutex>
23 #include <string>
24 
25 #include <ignition/math/Pose3.hh>
26 #include <ignition/math/Vector3.hh>
27 #include <sdf/sdf.hh>
28 
29 #include "gazebo/gui/qt.h"
30 #include "gazebo/math/Vector3.hh"
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 
107  public: void SetModelName(const std::string &_modelName);
108 
111  public: std::string ModelName() const;
112 
114  public: void ModelChanged();
115 
117  public: void SaveModelFiles();
118 
120  public: void FinishModel();
121 
128  public: void AddCustomLink(const EntityType _type,
129  const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
130  const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
131  const std::string &_uri = "", const unsigned int _samples = 5);
132 
140  public: LinkData *AddShape(const EntityType _type,
141  const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
142  const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
143  const std::string &_uri = "", const unsigned int _samples = 5);
144 
148  public: NestedModelData *AddModel(const sdf::ElementPtr &_sdf);
149 
152  public: void AddJoint(const std::string &_type);
153 
156  public: void RemoveEntity(const std::string &_entityName);
157 
160  public: void RemoveModelPlugin(const std::string &_pluginName);
161 
164  public: void SetStatic(const bool _static);
165 
168  public: void SetAutoDisable(const bool _auto);
169 
171  public: void Reset();
172 
174  public: void Stop();
175 
178  public: gui::JointMaker *JointMaker() const;
179 
183  public: void SetSelected(const std::string &_name, const bool selected);
184 
188  public: void SetSelected(const rendering::VisualPtr &_entityVis,
189  const bool selected);
190 
193  public: enum SaveState CurrentSaveState() const;
194 
197  public: void AddEntity(const sdf::ElementPtr &_sdf);
198 
201  public: void AddLink(const EntityType _type);
202 
207  public: void OnAddModelPlugin(const std::string &_name,
208  const std::string &_filename, const std::string &_innerxml);
209 
212  public: void AddModelPlugin(const sdf::ElementPtr &_pluginElem);
213 
217  public: ModelPluginData *ModelPlugin(const std::string &_name);
218 
220  public: void GenerateSDF();
221 
224  public slots: void ShowCollisions(const bool _show);
225 
228  public slots: void ShowVisuals(const bool _show);
229 
232  public slots: void ShowLinkFrames(const bool _show);
233 
237  private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
238 
240  private: void OnNew();
241 
244  private: bool OnSave();
245 
248  private: bool OnSaveAs();
249 
253  private: void OnNameChanged(const std::string &_modelName);
254 
258  private: void OnPropertiesChanged(const bool _static,
259  const bool _autoDisable);
260 
262  private: void OnExit();
263 
265  private: void Update();
266 
270  private: void RemoveNestedModelImpl(const std::string &_nestedModelName);
271 
275  private: void RemoveLinkImpl(const std::string &_linkName);
276 
279  private slots: void OnEdit(const bool _checked);
280 
283  private slots: void OnEditModel(const std::string &_modelName);
284 
286  private slots: void OnCopy();
287 
289  private slots: void OnPaste();
290 
294  private: bool OnMousePress(const common::MouseEvent &_event);
295 
299  private: bool OnMouseRelease(const common::MouseEvent &_event);
300 
304  private: bool OnMouseMove(const common::MouseEvent &_event);
305 
309  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
310 
314  private: bool OnKeyPress(const common::KeyEvent &_event);
315 
318  private: void OnManipMode(const std::string &_mode);
319 
323  private: void OnDeselectAll(const std::string &_name,
324  const std::string &_mode);
325 
330  private: void OnSetSelectedEntity(const std::string &_name,
331  const bool _selected);
332 
337  private: void OnSetSelectedModelPlugin(const std::string &_name,
338  const bool _selected);
339 
346  private: LinkData * CreateLink(const rendering::VisualPtr &_visual);
347 
351  private: NestedModelData *CloneNestedModel(const std::string &_modelName);
352 
356  private: LinkData *CloneLink(const std::string &_linkName);
357 
363  private: LinkData *CreateLinkFromSDF(const sdf::ElementPtr &_linkElem,
364  const rendering::VisualPtr &_parentVis);
365 
368  private: void OpenInspector(const std::string &_name);
369 
372  private: void OpenModelPluginInspector(const std::string &_name);
373 
375  private: virtual void CreateTheEntity();
376 
378  private: bool Init();
379 
382  private: std::string CreateModel();
383 
392  private: NestedModelData *CreateModelFromSDF(const sdf::ElementPtr &_sdf,
393  const rendering::VisualPtr &_parentVis = NULL,
394  const bool _emit = true);
395 
403  private: void OnAlignMode(const std::string &_axis,
404  const std::string &_config, const std::string &_target,
405  const bool _preview, const bool _inverted = false);
406 
410  private: void OnEntityScaleChanged(const std::string &_name,
411  const gazebo::math::Vector3 &_scale);
412 
415  private: void DeselectAll();
416 
418  private: void DeselectAllEntities();
419 
421  private: void DeselectAllModelPlugins();
422 
427  private: void SetModelVisible(const std::string &_name,
428  const bool _visible);
429 
434  private: void SetModelVisible(const rendering::VisualPtr &_visual,
435  const bool _visible);
436 
439  private: void ShowContextMenu(const std::string &_link);
440 
443  private: void ShowModelPluginContextMenu(const std::string &_name);
444 
447  private: void EmitNestedModelInsertedEvent(
448  const rendering::VisualPtr &_vis) const;
449 
452  private slots: void OnDelete();
453 
456  private slots: void OnDelete(const std::string &_name);
457 
459  private slots: void OnOpenInspector();
460 
463  private slots: void OnOpenModelPluginInspector(const QString &_name);
464 
467  private slots: void OnRemoveModelPlugin(const QString &_name);
468 
470  Q_SIGNALS: void LinkAdded();
471 
474  private: std::unique_ptr<ModelCreatorPrivate> dataPtr;
475  };
477  }
478 }
479 #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
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
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:77
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:277
Helper class to store link data.
Definition: ModelData.hh:90
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:112
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:245