Ignition Gazebo

API Reference

3.3.0
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 <memory>
22 #include <string>
23 #include <vector>
24 
25 #include <ignition/gui/Plugin.hh>
26 
27 namespace ignition
28 {
29 namespace gazebo
30 {
31  class ResourceSpawnerPrivate;
32 
34  struct Resource
35  {
38 
42 
45 
49 
51  // cppcheck-suppress unusedStructMember
52  bool isFuel = false;
53 
56  // cppcheck-suppress unusedStructMember
57  bool isDownloaded = false;
58  };
59 
62  struct Display
63  {
66  std::string searchKeyword = "";
67 
71  std::string sortMethod = "";
72 
75  std::string ownerPath = "";
76 
79  bool isFuel = false;
80  };
81 
84  class PathModel : public QStandardItemModel
85  {
86  Q_OBJECT
87 
89  public: explicit PathModel();
90 
92  public: ~PathModel() override = default;
93 
96  public slots: void AddPath(const std::string &_path);
97 
98  // Documentation inherited
99  public: QHash<int, QByteArray> roleNames() const override;
100  };
101 
104  class ResourceModel : public QStandardItemModel
105  {
106  Q_OBJECT
107 
109  public: explicit ResourceModel();
110 
112  public: ~ResourceModel() override = default;
113 
116  public: void AddResource(Resource &_resource);
117 
120  public: void AddResources(std::vector<Resource> &_resources);
121 
123  public: void Clear();
124 
130  public: void UpdateResourceModel(int index, Resource &_resource);
131 
132  // Documentation inherited
133  public: QHash<int, QByteArray> roleNames() const override;
134 
135  // \brief Index to keep track of the position of each resource in the qml
136  // grid, used primarily to access currently loaded resources for updates.
137  public: int gridIndex = 0;
138  };
139 
142  class ResourceSpawner : public ignition::gui::Plugin
143  {
144  Q_OBJECT
145 
147  public: ResourceSpawner();
148 
150  public: ~ResourceSpawner() override;
151 
152  // Documentation inherited
153  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
154 
157  public slots: void OnResourceSpawn(const QString &_sdfPath);
158 
162  public: Resource LocalResource(const std::string &_path);
163 
166  public: void AddPath(const std::string &_path);
167 
172  public: std::vector<Resource> LocalResources(const std::string &_path);
173 
178  public: std::vector<Resource> FuelResources(const std::string &_owner);
179 
183  public: void Resources(std::vector<Resource> &_resources);
184 
188  public: void FilterResources(std::vector<Resource> &_resources);
189 
195  public: void SortResources(std::vector<Resource> &_resources);
196 
199  public slots: void DisplayResources();
200 
204  public slots: void OnPathClicked(const QString &_path);
205 
210  public slots: void OnOwnerClicked(const QString &_owner);
211 
215  public slots: void OnDownloadFuelResource(const QString &_path,
216  const QString &_name, const QString &_owner, int index);
217 
222  public slots: void OnSortChosen(const QString &_sortType);
223 
227  public slots: void OnSearchEntered(const QString &_searchKeyword);
228 
234  public: void SetThumbnail(const std::string &_thumbnailPath,
235  Resource &_resource);
236 
240  };
241 }
242 }
243 
244 #endif
Resource used to update the ResourceModel.
Definition: ResourceSpawner.hh:34
Data used by the DisplayData() function to filter and sort the resources to be displayed.
Definition: ResourceSpawner.hh:62
std::string thumbnailPath
The absolute path to the thumbnail of the local model, will be empty if no thumbnail is found...
Definition: ResourceSpawner.hh:48
std::string sdfPath
The absolute path to the sdf corresponding to the local model.
Definition: ResourceSpawner.hh:44
std::string owner
The owner of the resource, if the resource is local, owner will be empty.
Definition: ResourceSpawner.hh:41
Provides interface for communicating to backend for generation of local models.
Definition: ResourceSpawner.hh:142
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:57
std::string name
The name of the resource.
Definition: ResourceSpawner.hh:37
STL class.
Provides a model by which the resource spawner qml plugin pulls and updates from. ...
Definition: ResourceSpawner.hh:84
Provides a model by which the resource spawner qml plugin pulls and updates from. ...
Definition: ResourceSpawner.hh:104
bool isFuel
Bool to indicate if this model is fuel or not.
Definition: ResourceSpawner.hh:52
This library is part of the Ignition Robotics project.