Ignition Gazebo

API Reference

3.5.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  // cppcheck-suppress unusedStructMember
80  bool isFuel = false;
81  };
82 
85  class PathModel : public QStandardItemModel
86  {
87  Q_OBJECT
88 
90  public: explicit PathModel();
91 
93  public: ~PathModel() override = default;
94 
97  public slots: void AddPath(const std::string &_path);
98 
99  // Documentation inherited
100  public: QHash<int, QByteArray> roleNames() const override;
101  };
102 
105  class ResourceModel : public QStandardItemModel
106  {
107  Q_OBJECT
108 
110  public: explicit ResourceModel();
111 
113  public: ~ResourceModel() override = default;
114 
117  public: void AddResource(Resource &_resource);
118 
121  public: void AddResources(std::vector<Resource> &_resources);
122 
124  public: void Clear();
125 
131  public: void UpdateResourceModel(int index, Resource &_resource);
132 
133  // Documentation inherited
134  public: QHash<int, QByteArray> roleNames() const override;
135 
136  // \brief Index to keep track of the position of each resource in the qml
137  // grid, used primarily to access currently loaded resources for updates.
138  public: int gridIndex = 0;
139  };
140 
143  class ResourceSpawner : public ignition::gui::Plugin
144  {
145  Q_OBJECT
146 
148  public: ResourceSpawner();
149 
151  public: ~ResourceSpawner() override;
152 
153  // Documentation inherited
154  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
155 
158  public slots: void OnResourceSpawn(const QString &_sdfPath);
159 
163  public: Resource LocalResource(const std::string &_path);
164 
167  public: void AddPath(const std::string &_path);
168 
173  public: std::vector<Resource> LocalResources(const std::string &_path);
174 
179  public: std::vector<Resource> FuelResources(const std::string &_owner);
180 
184  public: void Resources(std::vector<Resource> &_resources);
185 
189  public: void FilterResources(std::vector<Resource> &_resources);
190 
196  public: void SortResources(std::vector<Resource> &_resources);
197 
200  public slots: void DisplayResources();
201 
205  public slots: void OnPathClicked(const QString &_path);
206 
211  public slots: void OnOwnerClicked(const QString &_owner);
212 
216  public slots: void OnDownloadFuelResource(const QString &_path,
217  const QString &_name, const QString &_owner, int index);
218 
223  public slots: void OnSortChosen(const QString &_sortType);
224 
228  public slots: void OnSearchEntered(const QString &_searchKeyword);
229 
235  public: void SetThumbnail(const std::string &_thumbnailPath,
236  Resource &_resource);
237 
241  };
242 }
243 }
244 
245 #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:143
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:85
Provides a model by which the resource spawner qml plugin pulls and updates from. ...
Definition: ResourceSpawner.hh:105
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.