Ignition Gazebo

API Reference

6.6.0
EntityTree.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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 IGNITION_GAZEBO_GUI_ENTITYTREE_HH_
19 #define IGNITION_GAZEBO_GUI_ENTITYTREE_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <vector>
24 
27 
28 namespace ignition
29 {
30 namespace gazebo
31 {
32  class EntityTreePrivate;
33 
35  class TreeModel : public QStandardItemModel
36  {
37  Q_OBJECT
38 
40  public: explicit TreeModel();
41 
43  public: ~TreeModel() override = default;
44 
45  // Documentation inherited
46  public: QHash<int, QByteArray> roleNames() const override;
47 
54  public slots: void AddEntity(Entity _entity,
55  const QString &_entityName,
56  Entity _parentEntity = kNullEntity,
57  const QString &_type = QString());
58 
61  public slots: void RemoveEntity(Entity _entity);
62 
66  public: Q_INVOKABLE QString EntityType(const QModelIndex &_index) const;
67 
71  public: Q_INVOKABLE QString ScopedName(const QModelIndex &_index) const;
72 
76  public: Q_INVOKABLE Entity EntityId(const QModelIndex &_index) const;
77 
79  private: std::map<Entity, QStandardItem *> entityItems;
80 
82  struct EntityInfo
83  {
85  // cppcheck-suppress unmatchedSuppression
86  // cppcheck-suppress unusedStructMember
87  Entity entity;
88 
90  QString name;
91 
93  // cppcheck-suppress unmatchedSuppression
94  // cppcheck-suppress unusedStructMember
95  Entity parentEntity;
96 
98  QString type;
99  };
100 
103  private: std::vector<EntityInfo> pendingEntities;
104  };
105 
111  {
112  Q_OBJECT
113 
115  public: EntityTree();
116 
118  public: ~EntityTree() override;
119 
120  // Documentation inherited
121  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
122 
123  // Documentation inherited
124  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
125 
129  public: Q_INVOKABLE void OnEntitySelectedFromQml(Entity _entity);
130 
133  public: Q_INVOKABLE void DeselectAllEntities();
134 
137  public: Q_INVOKABLE void OnInsertEntity(const QString &_type);
138 
141  public: Q_INVOKABLE void OnLoadMesh(const QString &_mesh);
142 
143  // Documentation inherited
144  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
145 
148  private: std::unique_ptr<EntityTreePrivate> dataPtr;
149  };
150 }
151 }
152 
153 #endif
void AddEntity(Entity _entity, const QString &_entityName, Entity _parentEntity=kNullEntity, const QString &_type=QString())
Add an entity to the tree.
Q_INVOKABLE Entity EntityId(const QModelIndex &_index) const
Get the entity ID of a tree item at specified index.
~TreeModel() override=default
Destructor.
STL class.
Information passed to systems on the update callback.
Definition: include/ignition/gazebo/Types.hh:38
TODO.
Definition: EntityTree.hh:35
The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent.
Definition: EntityComponentManager.hh:66
void RemoveEntity(Entity _entity)
Remove an entity from the tree.
Q_INVOKABLE QString EntityType(const QModelIndex &_index) const
Get the entity type of a tree item at specified index.
QHash< int, QByteArray > roleNames() const override
const Entity kNullEntity
Indicates a non-existant or invalid Entity.
Definition: Entity.hh:62
Displays a tree view with all the entities in the world.
Definition: EntityTree.hh:110
This library is part of the Ignition Robotics project.
Base class for a GUI System.
Definition: GuiSystem.hh:44
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light. At its core, an Entity is just an identifier.
Definition: Entity.hh:59
Q_INVOKABLE QString ScopedName(const QModelIndex &_index) const
Get the scoped name of a tree item at specified index.