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
36namespace 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
83
86 public: enum SaveState
87 {
90
93
95 UNSAVED_CHANGES
96 };
97
100 public: explicit 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
124 public: bool SaveModelFiles();
125
127 public: void FinishModel();
128
135 public: void AddCustomLink(const EntityType _type,
136 const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
137 const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
138 const std::string &_uri = "", const unsigned int _samples = 5);
139
147 public: LinkData *AddShape(const EntityType _type,
148 const ignition::math::Vector3d &_size = ignition::math::Vector3d::One,
149 const ignition::math::Pose3d &_pose = ignition::math::Pose3d::Zero,
150 const std::string &_uri = "", const unsigned int _samples = 5);
151
155 public: NestedModelData *AddModel(const sdf::ElementPtr &_sdf);
156
159 public: void AddJoint(const std::string &_type);
160
163 public: void RemoveEntity(const std::string &_entityName);
164
169 public: void RemoveModelPlugin(const std::string &_pluginName,
170 const bool _newCmd = true);
171
174 public: void SetStatic(const bool _static);
175
178 public: void SetAutoDisable(const bool _auto);
179
181 public: void Reset();
182
184 public: void Stop();
185
188 public: gui::JointMaker *JointMaker() const;
189
193 public: void SetSelected(const std::string &_name, const bool selected);
194
198 public: void SetSelected(const rendering::VisualPtr &_entityVis,
199 const bool selected);
200
203 public: enum SaveState CurrentSaveState() const;
204
207 public: void AddEntity(const sdf::ElementPtr &_sdf);
208
211 public: void AddLink(const EntityType _type);
212
219 public: void OnAddModelPlugin(const std::string &_name,
220 const std::string &_filename, const std::string &_innerxml,
221 const bool _newCmd = true);
222
225 public: void AddModelPlugin(const sdf::ElementPtr &_pluginElem);
226
230 public: ModelPluginData *ModelPlugin(const std::string &_name);
231
233 public: void GenerateSDF();
234
237 public slots: void ShowCollisions(const bool _show);
238
241 public slots: void ShowVisuals(const bool _show);
242
245 public slots: void ShowLinkFrames(const bool _show);
246
251 public: ignition::math::Pose3d WorldToLocal(
252 const ignition::math::Pose3d &_world) const;
253
257 private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
258
260 private: void OnNew();
261
264 private: bool OnSave();
265
268 private: bool OnSaveAs();
269
273 private: void OnNameChanged(const std::string &_modelName);
274
278 private: void OnPropertiesChanged(const bool _static,
279 const bool _autoDisable);
280
282 private: void OnExit();
283
287 private: void RemoveNestedModelImpl(const std::string &_nestedModelName);
288
292 private: void RemoveLinkImpl(const std::string &_linkName);
293
296 private slots: void OnEdit(const bool _checked);
297
300 private slots: void OnEditModel(const std::string &_modelName);
301
303 private slots: void OnCopy();
304
306 private slots: void OnPaste();
307
311 private: bool OnMousePress(const common::MouseEvent &_event);
312
316 private: bool OnMouseRelease(const common::MouseEvent &_event);
317
321 private: bool OnMouseMove(const common::MouseEvent &_event);
322
326 private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
327
331 private: bool OnKeyPress(const common::KeyEvent &_event);
332
335 private: void OnManipMode(const std::string &_mode);
336
340 private: void OnDeselectAll(const std::string &_name,
341 const std::string &_mode);
342
347 private: void OnSetSelectedEntity(const std::string &_name,
348 const bool _selected);
349
354 private: void OnSetSelectedModelPlugin(const std::string &_name,
355 const bool _selected);
356
363 private: LinkData *CreateLink(const rendering::VisualPtr &_visual);
364
367 private: void InsertLinkFromSDF(sdf::ElementPtr _sdf);
368
371 private: void InsertNestedModelFromSDF(sdf::ElementPtr _sdf);
372
376 private: NestedModelData *CloneNestedModel(const std::string &_modelName);
377
381 private: LinkData *CloneLink(const std::string &_linkName);
382
388 private: LinkData *CreateLinkFromSDF(const sdf::ElementPtr &_linkElem,
389 const rendering::VisualPtr &_parentVis);
390
393 private: void OpenInspector(const std::string &_name);
394
397 private: void OpenModelPluginInspector(const std::string &_name);
398
400 private: virtual void CreateTheEntity();
401
403 private: bool Init();
404
407 private: std::string CreateModel();
408
417 private: NestedModelData *CreateModelFromSDF(const sdf::ElementPtr &_sdf,
418 const rendering::VisualPtr &_parentVis = NULL,
419 const bool _emit = true);
420
428 private: void OnAlignMode(const std::string &_axis,
429 const std::string &_config, const std::string &_target,
430 const bool _preview, const bool _inverted = false);
431
435 private: void OnEntityScaleChanged(const std::string &_name,
436 const ignition::math::Vector3d &_scale);
437
443 private: void OnEntityMoved(const std::string &_name,
444 const ignition::math::Pose3d &_pose, const bool _isFinal);
445
448 private: void DeselectAll();
449
451 private: void DeselectAllEntities();
452
454 private: void DeselectAllModelPlugins();
455
459 private: void OnRequestLinkScale(const std::string &_name,
460 const std::map<std::string, ignition::math::Vector3d> &_scales);
461
465 private: void OnRequestLinkMove(const std::string &_name,
466 const ignition::math::Pose3d &_pose);
467
471 private: void OnRequestNestedModelMove(const std::string &_name,
472 const ignition::math::Pose3d &_pose);
473
478 private: void SetModelVisible(const std::string &_name,
479 const bool _visible);
480
485 private: void SetModelVisible(const rendering::VisualPtr &_visual,
486 const bool _visible);
487
490 private: void ShowContextMenu(const std::string &_link);
491
494 private: void ShowModelPluginContextMenu(const std::string &_name);
495
498 private: void EmitNestedModelInsertedEvent(
499 const rendering::VisualPtr &_vis) const;
500
503 private slots: void OnDelete();
504
507 private slots: void OnDelete(const std::string &_name);
508
510 private slots: void OnOpenInspector();
511
514 private slots: void OnOpenModelPluginInspector(const QString &_name);
515
518 private slots: void OnRemoveModelPlugin(const QString &_name);
519
521 Q_SIGNALS: void LinkAdded();
522
525 private: std::unique_ptr<ModelCreatorPrivate> dataPtr;
526 };
528 }
529}
530#endif
#define NULL
Definition CommonTypes.hh:31
common
Definition FuelModelDatabase.hh:42
gui
Definition KeyEventHandler.hh:29
Generic description of a keyboard event.
Definition KeyEvent.hh:33
Generic description of a mouse event.
Definition MouseEvent.hh:36
Handles the creation of joints in the model editor.
Definition JointMaker.hh:77
Helper class to store link data.
Definition ModelData.hh:95
Create and manage 3D visuals of a model with links, nested models and joints.
Definition ModelCreator.hh:61
ignition::math::Pose3d WorldToLocal(const ignition::math::Pose3d &_world) const
Convert a given pose from the world frame to the local frame of the model being edited.
void AddJoint(const std::string &_type)
Add a joint to the model.
void Stop()
Stop the process of adding a link or joint to the model.
void AddCustomLink(const EntityType _type, const ignition::math::Vector3d &_size=ignition::math::Vector3d::One, const ignition::math::Pose3d &_pose=ignition::math::Pose3d::Zero, const std::string &_uri="", const unsigned int _samples=5)
Begin the process of inserting a custom link using the mouse.
LinkData * AddShape(const EntityType _type, const ignition::math::Vector3d &_size=ignition::math::Vector3d::One, const ignition::math::Pose3d &_pose=ignition::math::Pose3d::Zero, const std::string &_uri="", const unsigned int _samples=5)
Add a link to the model.
void SetSelected(const std::string &_name, const bool selected)
Set the select state of an entity.
void AddLink(const EntityType _type)
Add a link to the model.
void AddModelPlugin(const sdf::ElementPtr &_pluginElem)
Add a model plugin to the model.
gui::JointMaker * JointMaker() const
Get joint maker.
void Reset()
Reset the model creator and the SDF.
void DisableEventHandlers()
Disable the mouse and key event handlers.
void FinishModel()
Finish the model and create the entity on the gzserver.
ModelCreator(QObject *_parent=NULL)
Constructor.
void OnAddModelPlugin(const std::string &_name, const std::string &_filename, const std::string &_innerxml, const bool _newCmd=true)
Add a model plugin to the model.
void ShowCollisions(const bool _show)
Show or hide collision visuals.
SaveState
Save states for the model editor.
Definition ModelCreator.hh:87
@ ALL_SAVED
All changes have been saved.
Definition ModelCreator.hh:92
@ NEVER_SAVED
The model has never been saved.
Definition ModelCreator.hh:89
@ UNSAVED_CHANGES
Has been saved before, but has unsaved changes.
Definition ModelCreator.hh:95
ModelPluginData * ModelPlugin(const std::string &_name)
Get a model plugin data by its name.
void SetStatic(const bool _static)
Set the model to be static.
void ModelChanged()
Set save state upon a change to the model.
void ShowVisuals(const bool _show)
Show or hide visual visuals.
void LinkAdded()
Qt signal when the a link has been added.
std::string ModelName() const
Get the name of the model.
void RemoveEntity(const std::string &_entityName)
Remove an entity from the model.
void SetModelName(const std::string &_modelName)
Set the name of the model.
void RemoveModelPlugin(const std::string &_pluginName, const bool _newCmd=true)
Remove a model plugin from the model.
virtual ~ModelCreator()
Destructor.
void AddEntity(const sdf::ElementPtr &_sdf)
Add an entity to the model.
void GenerateSDF()
Generate the SDF from model link and joint visuals.
enum SaveState CurrentSaveState() const
Get current save state.
void SetAutoDisable(const bool _auto)
Set the model to allow auto disable at rest.
NestedModelData * AddModel(const sdf::ElementPtr &_sdf)
Add a nested model to the model.
void EnableEventHandlers()
Enable the mouse and key event handlers.
EntityType
Definition ModelCreator.hh:67
@ ENTITY_POLYLINE
Extruded polyline.
Definition ModelCreator.hh:79
@ ENTITY_MESH
Imported 3D mesh.
Definition ModelCreator.hh:77
@ ENTITY_BOX
Box.
Definition ModelCreator.hh:71
@ ENTITY_CYLINDER
Cylinder.
Definition ModelCreator.hh:75
@ ENTITY_SPHERE
Sphere.
Definition ModelCreator.hh:73
@ ENTITY_NONE
none
Definition ModelCreator.hh:69
@ ENTITY_MODEL
Nested model.
Definition ModelCreator.hh:81
void SetSelected(const rendering::VisualPtr &_entityVis, const bool selected)
Set the select state of a entity visual.
bool SaveModelFiles()
Helper function to manage writing files to disk.
void ShowLinkFrames(const bool _show)
Show or hide link frame visuals.
Helper class to store model plugin data.
Definition ModelData.hh:313
Helper class to store nested models data.
Definition ModelData.hh:58
std::shared_ptr< Visual > VisualPtr
Definition RenderTypes.hh:114
Forward declarations for the common classes.
Definition Animation.hh:27