Gazebo Sim
API Reference
7.9.0
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
src
gz-sim
src
gui
plugins
resource_spawner
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 GZ_SIM_GUI_RESOURCE_SPAWNER_HH_
19
#define GZ_SIM_GUI_RESOURCE_SPAWNER_HH_
20
21
#include <qobjectdefs.h>
22
#include <algorithm>
23
#include <memory>
24
#include <string>
25
#include <vector>
26
#include <gz/fuel_tools/ClientConfig.hh>
27
#include <gz/fuel_tools/FuelClient.hh>
28
29
#include <gz/gui/Plugin.hh>
30
31
namespace
gz
32
{
33
namespace
sim
34
{
35
class
ResourceSpawnerPrivate;
36
38
struct
Resource
39
{
41
std::string
name
=
""
;
42
45
std::string
owner
=
""
;
46
48
std::string
sdfPath
=
""
;
49
52
std::string
thumbnailPath
=
""
;
53
55
// cppcheck-suppress unusedStructMember
56
bool
isFuel
=
false
;
57
60
// cppcheck-suppress unusedStructMember
61
bool
isDownloaded
=
false
;
62
};
63
66
struct
Display
67
{
70
std::string
searchKeyword
=
""
;
71
75
std::string
sortMethod
=
""
;
76
79
std::string
ownerPath
=
""
;
80
83
// cppcheck-suppress unusedStructMember
84
bool
isFuel
=
false
;
85
};
86
89
class
PathModel
:
public
QStandardItemModel
90
{
91
Q_OBJECT
92
94
public
:
explicit
PathModel
();
95
97
public
:
~PathModel
()
override
=
default
;
98
101
public
:
void
AddPath
(
const
std::string
&_path);
102
105
public
:
void
RemovePath
(
const
std::string
&_path);
106
107
// Documentation inherited
108
public
: QHash<int, QByteArray>
roleNames
()
const override
;
109
};
110
113
class
ResourceModel
:
public
QStandardItemModel
114
{
115
Q_OBJECT
116
119
Q_PROPERTY(
int
totalCount
MEMBER
gridIndex
NOTIFY
sizeChanged
)
120
121
122
public
:
explicit
ResourceModel
();
123
125
public
:
~ResourceModel
()
override
=
default
;
126
129
public
:
void
AddResource
(
const
Resource
&_resource);
130
133
public
:
void
AddResources
(
std::vector<Resource>
&_resources);
134
136
public
:
void
Clear
();
137
143
public
:
void
UpdateResourceModel
(
int
index,
Resource
&_resource);
144
145
// Documentation inherited
146
public
: QHash<int, QByteArray>
roleNames
()
const override
;
147
149
public
: signals:
void
sizeChanged
();
150
151
// \brief Index to keep track of the position of each resource in the qml
152
// grid, used primarily to access currently loaded resources for updates.
153
public
:
int
gridIndex
= 0;
154
};
155
158
class
ResourceSpawner
:
public
gz::gui::Plugin
159
{
160
Q_OBJECT
161
163
public
:
ResourceSpawner
();
164
166
public
:
~ResourceSpawner
()
override
;
167
168
// Documentation inherited
169
public
:
void
LoadConfig
(
const
tinyxml2::XMLElement *_pluginElem)
override
;
170
173
public
slots:
void
OnResourceSpawn
(
const
QString &_sdfPath);
174
178
public
:
Resource
LocalResource
(
const
std::string
&_path);
179
182
public
:
void
AddPath
(
const
std::string
&_path);
183
188
public
:
std::vector<Resource>
LocalResources
(
const
std::string
&_path);
189
194
public
:
std::vector<Resource>
FuelResources
(
const
std::string
&_owner);
195
199
public
:
void
Resources
(
std::vector<Resource>
&_resources);
200
204
public
:
void
FilterResources
(
std::vector<Resource>
&_resources);
205
211
public
:
void
SortResources
(
std::vector<Resource>
&_resources);
212
215
public
slots:
void
DisplayResources
();
216
220
public
slots:
void
OnPathClicked
(
const
QString &_path);
221
226
public
slots:
void
OnOwnerClicked
(
const
QString &_owner);
227
233
public
slots:
void
OnDownloadFuelResource
(
const
QString &_path,
234
const
QString &_name,
const
QString &_owner,
int
index);
235
240
public
slots:
void
OnSortChosen
(
const
QString &_sortType);
241
245
public
slots:
void
OnSearchEntered
(
const
QString &_searchKeyword);
246
252
public
:
void
SetThumbnail
(
const
std::string
&_thumbnailPath,
253
Resource
&_resource);
254
260
public
: Q_INVOKABLE
void
UpdateOwnerListModel
(
gz::sim::Resource
_resource);
261
266
public
: Q_INVOKABLE
bool
AddOwner
(
const
QString &_owner);
267
271
public
: Q_INVOKABLE
void
RemoveOwner
(
const
QString &_owner);
272
275
public
: Q_INVOKABLE
bool
IsDefaultOwner
(
const
QString &_owner)
const
;
276
279
signals:
void
resourceSpawnerError
(
const
QString &_errorMsg);
280
283
private
:
void
RunFetchResourceListThread(
const
std::string
&_owner);
284
287
private
:
std::unique_ptr<ResourceSpawnerPrivate>
dataPtr;
288
};
289
}
290
}
291
292
#endif