Ignition Gazebo

API Reference

6.1.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 unusedStructMember
86  Entity entity;
87 
89  QString name;
90 
92  // cppcheck-suppress unusedStructMember
93  Entity parentEntity;
94 
96  QString type;
97  };
98 
101  private: std::vector<EntityInfo> pendingEntities;
102  };
103 
109  {
110  Q_OBJECT
111 
113  public: EntityTree();
114 
116  public: ~EntityTree() override;
117 
118  // Documentation inherited
119  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
120 
121  // Documentation inherited
122  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
123 
127  public: Q_INVOKABLE void OnEntitySelectedFromQml(Entity _entity);
128 
131  public: Q_INVOKABLE void DeselectAllEntities();
132 
135  public: Q_INVOKABLE void OnInsertEntity(const QString &_type);
136 
139  public: Q_INVOKABLE void OnLoadMesh(const QString &_type);
140 
141  // Documentation inherited
142  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
143 
146  private: std::unique_ptr<EntityTreePrivate> dataPtr;
147  };
148 }
149 }
150 
151 #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: 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:108
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.