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 
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 
166  public: void RemoveModelPlugin(const std::string &_pluginName);
167 
170  public: void SetStatic(const bool _static);
171 
174  public: void SetAutoDisable(const bool _auto);
175 
177  public: void Reset();
178 
180  public: void Stop();
181 
184  public: gui::JointMaker *JointMaker() const;
185 
189  public: void SetSelected(const std::string &_name, const bool selected);
190 
194  public: void SetSelected(const rendering::VisualPtr &_entityVis,
195  const bool selected);
196 
199  public: enum SaveState CurrentSaveState() const;
200 
203  public: void AddEntity(const sdf::ElementPtr &_sdf);
204 
207  public: void AddLink(const EntityType _type);
208 
213  public: void OnAddModelPlugin(const std::string &_name,
214  const std::string &_filename, const std::string &_innerxml);
215 
218  public: void AddModelPlugin(const sdf::ElementPtr &_pluginElem);
219 
223  public: ModelPluginData *ModelPlugin(const std::string &_name);
224 
226  public: void GenerateSDF();
227 
231  private: sdf::ElementPtr GenerateLinkSDF(LinkData *_link);
232 
234  private: void OnNew();
235 
238  private: bool OnSave();
239 
242  private: bool OnSaveAs();
243 
247  private: void OnNameChanged(const std::string &_modelName);
248 
252  private: void OnPropertiesChanged(const bool _static,
253  const bool _autoDisable);
254 
256  private: void OnExit();
257 
259  private: void Update();
260 
264  private: void RemoveNestedModelImpl(const std::string &_nestedModelName);
265 
269  private: void RemoveLinkImpl(const std::string &_linkName);
270 
273  private slots: void OnEdit(const bool _checked);
274 
277  private slots: void OnEditModel(const std::string &_modelName);
278 
280  private slots: void OnCopy();
281 
283  private slots: void OnPaste();
284 
288  private: bool OnMousePress(const common::MouseEvent &_event);
289 
293  private: bool OnMouseRelease(const common::MouseEvent &_event);
294 
298  private: bool OnMouseMove(const common::MouseEvent &_event);
299 
303  private: bool OnMouseDoubleClick(const common::MouseEvent &_event);
304 
308  private: bool OnKeyPress(const common::KeyEvent &_event);
309 
312  private: void OnManipMode(const std::string &_mode);
313 
317  private: void OnSetSelectedEntity(const std::string &_name,
318  const std::string &_mode);
319 
324  private: void OnSetSelectedLink(const std::string &_name,
325  const bool _selected);
326 
331  private: void OnSetSelectedModelPlugin(const std::string &_name,
332  const bool _selected);
333 
340  private: LinkData *CreateLink(const rendering::VisualPtr &_visual);
341 
344  private: void InsertLinkFromSDF(sdf::ElementPtr _sdf);
345 
348  private: void InsertNestedModelFromSDF(sdf::ElementPtr _sdf);
349 
353  private: NestedModelData *CloneNestedModel(const std::string &_modelName);
354 
358  private: LinkData *CloneLink(const std::string &_linkName);
359 
365  private: LinkData *CreateLinkFromSDF(const sdf::ElementPtr &_linkElem,
366  const rendering::VisualPtr &_parentVis);
367 
370  private: void OpenInspector(const std::string &_name);
371 
374  private: void OpenModelPluginInspector(const std::string &_name);
375 
377  private: virtual void CreateTheEntity();
378 
380  private: bool Init();
381 
384  private: std::string CreateModel();
385 
394  private: NestedModelData *CreateModelFromSDF(const sdf::ElementPtr &_sdf,
395  const rendering::VisualPtr &_parentVis = NULL,
396  const bool _emit = true);
397 
405  private: void OnAlignMode(const std::string &_axis,
406  const std::string &_config, const std::string &_target,
407  const bool _preview, const bool _inverted = false);
408 
412  private: void OnEntityScaleChanged(const std::string &_name,
413  const gazebo::math::Vector3 &_scale);
414 
417  private: void DeselectAll();
418 
420  private: void DeselectAllLinks();
421 
423  private: void DeselectAllNestedModels();
424 
426  private: void DeselectAllModelPlugins();
427 
432  private: void SetModelVisible(const std::string &_name,
433  const bool _visible);
434 
439  private: void SetModelVisible(const rendering::VisualPtr &_visual,
440  const bool _visible);
441 
444  private: void ShowContextMenu(const std::string &_link);
445 
448  private: void ShowModelPluginContextMenu(const std::string &_name);
449 
452  private: void EmitNestedModelInsertedEvent(
453  const rendering::VisualPtr &_vis) const;
454 
457  private slots: void OnDelete();
458 
461  private slots: void OnDelete(const std::string &_name);
462 
464  private slots: void OnOpenInspector();
465 
468  private slots: void OnOpenModelPluginInspector(const QString &_name);
469 
472  private slots: void OnRemoveModelPlugin(const QString &_name);
473 
475  Q_SIGNALS: void LinkAdded();
476 
479  private: std::unique_ptr<ModelCreatorPrivate> dataPtr;
480  };
482  }
483 }
484 #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
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:78
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:252
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: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