Ignition Gazebo

API Reference

6.0.0~pre1
ResourceSpawner.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 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_RESOURCE_SPAWNER_HH_
19 #define IGNITION_GAZEBO_GUI_RESOURCE_SPAWNER_HH_
20 
21 #include <algorithm>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include <ignition/gui/Plugin.hh>
27 
28 namespace ignition
29 {
30 namespace gazebo
31 {
32  class ResourceSpawnerPrivate;
33 
35  struct Resource
36  {
39 
43 
46 
50 
52  // cppcheck-suppress unusedStructMember
53  bool isFuel = false;
54 
57  // cppcheck-suppress unusedStructMember
58  bool isDownloaded = false;
59  };
60 
63  struct Display
64  {
67  std::string searchKeyword = "";
68 
72  std::string sortMethod = "";
73 
76  std::string ownerPath = "";
77 
80  // cppcheck-suppress unusedStructMember
81  bool isFuel = false;
82  };
83 
86  class PathModel : public QStandardItemModel
87  {
88  Q_OBJECT
89 
91  public: explicit PathModel();
92 
94  public: ~PathModel() override = default;
95 
98  public slots: void AddPath(const std::string &_path);
99 
100  // Documentation inherited
101  public: QHash<int, QByteArray> roleNames() const override;
102  };
103 
106  class ResourceModel : public QStandardItemModel
107  {
108  Q_OBJECT
109 
111  public: explicit ResourceModel();
112 
114  public: ~ResourceModel() override = default;
115 
118  public: void AddResource(Resource &_resource);
119 
122  public: void AddResources(std::vector<Resource> &_resources);
123 
125  public: void Clear();
126 
132  public: void UpdateResourceModel(int index, Resource &_resource);
133 
134  // Documentation inherited
135  public: QHash<int, QByteArray> roleNames() const override;
136 
137  // \brief Index to keep track of the position of each resource in the qml
138  // grid, used primarily to access currently loaded resources for updates.
139  public: int gridIndex = 0;
140  };
141 
144  class ResourceSpawner : public ignition::gui::Plugin
145  {
146  Q_OBJECT
147 
149  public: ResourceSpawner();
150 
152  public: ~ResourceSpawner() override;
153 
154  // Documentation inherited
155  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
156 
159  public slots: void OnResourceSpawn(const QString &_sdfPath);
160 
164  public: Resource LocalResource(const std::string &_path);
165 
168  public: void AddPath(const std::string &_path);
169 
174  public: std::vector<Resource> LocalResources(const std::string &_path);
175 
180  public: std::vector<Resource> FuelResources(const std::string &_owner);
181 
185  public: void Resources(std::vector<Resource> &_resources);
186 
190  public: void FilterResources(std::vector<Resource> &_resources);
191 
197  public: void SortResources(std::vector<Resource> &_resources);
198 
201  public slots: void DisplayResources();
202 
206  public slots: void OnPathClicked(const QString &_path);
207 
212  public slots: void OnOwnerClicked(const QString &_owner);
213 
219  public slots: void OnDownloadFuelResource(const QString &_path,
220  const QString &_name, const QString &_owner, int index);
221 
226  public slots: void OnSortChosen(const QString &_sortType);
227 
231  public slots: void OnSearchEntered(const QString &_searchKeyword);
232 
238  public: void SetThumbnail(const std::string &_thumbnailPath,
239  Resource &_resource);
240 
244  };
245 }
246 }
247 
248 #endif
Resource used to update the ResourceModel.
Definition: ResourceSpawner.hh:35
Data used by the DisplayData() function to filter and sort the resources to be displayed.
Definition: ResourceSpawner.hh:63
std::string thumbnailPath
The absolute path to the thumbnail of the local model, will be empty if no thumbnail is found...
Definition: ResourceSpawner.hh:49
std::string sdfPath
The absolute path to the sdf corresponding to the local model.
Definition: ResourceSpawner.hh:45
std::string owner
The owner of the resource, if the resource is local, owner will be empty.
Definition: ResourceSpawner.hh:42
Provides interface for communicating to backend for generation of local models.
Definition: ResourceSpawner.hh:144
STL class.
bool isDownloaded
Bool to indicate if this model has been downloaded or not, will always be false with local models as ...
Definition: ResourceSpawner.hh:58
std::string name
The name of the resource.
Definition: ResourceSpawner.hh:38
STL class.
Provides a model by which the resource spawner qml plugin pulls and updates from. ...
Definition: ResourceSpawner.hh:86
Provides a model by which the resource spawner qml plugin pulls and updates from. ...
Definition: ResourceSpawner.hh:106
bool isFuel
Bool to indicate if this model is fuel or not.
Definition: ResourceSpawner.hh:53
This library is part of the Ignition Robotics project.