-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathWbWorld.hpp
More file actions
219 lines (176 loc) · 7.47 KB
/
WbWorld.hpp
File metadata and controls
219 lines (176 loc) · 7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright 1996-2023 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef WB_WORLD_HPP
#define WB_WORLD_HPP
//
// Description: Webots world
//
#include "WbWorldInfo.hpp"
#include <QtCore/QMutex>
#include <QtCore/QObject>
#include <QtCore/QString>
class WbGroup;
class WbNode;
class WbPerspective;
class WbRobot;
class WbSolid;
class WbTokenizer;
class WbViewpoint;
struct dImmersionGeom;
class WbOdeContact;
class WbWorld : public QObject {
Q_OBJECT;
public:
// unique world instance (can be NULL)
static WbWorld *instance();
// constructor
// the world is read using 'tokenizer': the file syntax must have been checked with WbParser
// if 'tokenizer' is not specified, the world is created with default WorldInfo and Viewpoint nodes
explicit WbWorld(WbTokenizer *tokenizer = NULL);
// destructor
virtual ~WbWorld();
void finalize();
// current file name
const QString &fileName() const { return mFileName; }
bool needSaving() const;
bool isModifiedFromSceneTree() const { return mIsModifiedFromSceneTree; }
bool isModified() const { return mIsModified; }
void setModified(bool isModified = true);
void setModifiedFromSceneTree();
// world loading functions
bool isLoading() const { return mIsLoading; }
void setIsLoading(bool loading) { mIsLoading = loading; }
bool isCleaning() const { return mIsCleaning; }
void setIsCleaning(bool cleaning) { mIsCleaning = cleaning; }
bool wasWorldLoadingCanceled() { return mWorldLoadingCanceled; }
bool isVideoRecording() const { return mIsVideoRecording; }
static bool isW3dStreaming() { return cW3dStreaming; }
static void enableW3dStreaming() { cW3dStreaming = true; }
static bool printExternUrls() { return cPrintExternUrls; }
static void setPrintExternUrls() { cPrintExternUrls = true; }
// save
bool save();
virtual bool saveAs(const QString &fileName);
// save and replace Webots specific nodes by VRML/W3D nodes
bool exportAsHtml(const QString &fileName, bool animation) const;
bool exportAsW3d(const QString &fileName) const;
void write(WbWriter &writer) const;
// nodes that do always exist
WbGroup *root() const { return mRoot; }
WbWorldInfo *worldInfo() const { return mWorldInfo; }
WbViewpoint *viewpoint() const { return mViewpoint; }
void setWorldInfo(WbWorldInfo *worldInfo) { mWorldInfo = worldInfo; }
void setViewpoint(WbViewpoint *viewpoint);
double orthographicViewHeight() const;
void setOrthographicViewHeight(double ovh) const;
// current perspective
WbPerspective *perspective() const { return mPerspective; }
bool reloadPerspective();
// find a solid by its "name" field
WbSolid *findSolid(const QString &name) const;
// create a list of all solids (on the fly), look recursively
// if 'visibleNodes' is true: return list of Solid nodes visible in the scene tree
// if 'visibleNodes' is false: return instantiated Solid nodes (i.e. excluding proto parameter nodes)
QList<WbSolid *> findSolids(bool visibleNodes = false) const;
// return the list of all robots
const QList<WbRobot *> &robots() const { return mRobots; }
// return the list of all top solids (not looking recursively)
const QList<WbSolid *> &topSolids() const { return mTopSolids; }
// return the list of all solids that have a positive radar cross-section (radar target)
const QList<WbSolid *> &radarTargetSolids() const { return mRadarTargets; }
void addRadarTarget(WbSolid *target) { mRadarTargets.append(target); }
void removeRadarTarget(WbSolid *target) { mRadarTargets.removeAll(target); }
// return the list of all solids that have a non-empty 'recognitionColors' field
const QList<WbSolid *> &cameraRecognitionObjects() const { return mCameraRecognitionObjects; }
void addCameraRecognitionObject(WbSolid *object) { mCameraRecognitionObjects.append(object); }
void removeCameraRecognitionObject(WbSolid *object) { mCameraRecognitionObjects.removeAll(object); }
// functions to maintain global list of robots
void removeRobotIfPresent(WbRobot *robot);
void addRobotIfNotAlreadyPresent(WbRobot *robot);
// return the list of texture files used in this world (no duplicates)
QList<std::pair<QString, WbMFString *>> listTextureFiles() const;
// shortcut
double basicTimeStep() const { return mWorldInfo->basicTimeStep(); }
int optimalThreadCount() const { return mWorldInfo->optimalThreadCount(); }
const QList<WbOdeContact> &odeContacts() const { return mOdeContacts; }
const QList<dImmersionGeom> &immersionGeoms() const { return mImmersionGeoms; }
void appendOdeContact(const WbOdeContact &odeContact);
void appendOdeImmersionGeom(const dImmersionGeom &immersionGeom);
void retrieveNodeNamesWithOptionalRendering(QStringList ¢erOfMassNodeNames, QStringList ¢erOfBuoyancyNodeNames,
QStringList &supportPolygonNodeNames) const;
void setResetRequested(bool restartControllers) {
mResetRequested = true;
if (!mRestartControllers)
mRestartControllers = restartControllers;
}
virtual void reset(bool restartControllers) {
mResetRequested = false;
mRestartControllers = false;
}
signals:
void modificationChanged(bool modified);
void worldLoadingStatusHasChanged(QString status);
void worldLoadingHasProgressed(int percent);
void viewpointChanged();
void robotAdded(WbRobot *robot);
void robotRemoved(WbRobot *robot);
void resetRequested(bool restartControllers);
void checkDefDiff();
public slots:
void awake();
void updateVideoRecordingStatus(int status) {
mIsVideoRecording = (status == WB_SUPERVISOR_MOVIE_RECORDING || status == WB_SUPERVISOR_MOVIE_SAVING);
}
void resetModifiedFromSceneTree();
protected:
// collecting contact and immersion geometries
QList<WbOdeContact> mOdeContacts;
QList<dImmersionGeom> mImmersionGeoms;
bool mWorldLoadingCanceled;
bool mResetRequested;
bool mRestartControllers;
QString logWorldMetrics() const;
// called when a node is added to the children of a group which checks if a
// controller needs starting, should the added node be a Robot
virtual void setUpControllerForNewRobot(WbRobot *robot) {}
protected slots:
virtual void storeAddedNodeIfNeeded(WbNode *node) {}
private:
QString mFileName;
bool mIsModified;
bool mIsModifiedFromSceneTree;
WbGroup *mRoot;
WbWorldInfo *mWorldInfo;
WbViewpoint *mViewpoint;
WbPerspective *mPerspective;
QList<WbRobot *> mRobots;
QList<WbSolid *> mTopSolids;
QList<WbSolid *> mRadarTargets;
QList<WbSolid *> mCameraRecognitionObjects;
QMutex mOdeContactsMutex;
double mLastAwakeningTime;
bool mIsLoading;
bool mIsCleaning;
bool mIsVideoRecording;
bool isModifiedFromSceneTreeRestarted = false;
void checkPresenceOfMandatoryNodes();
WbNode *findTopLevelNode(const QString &modelName, int preferredPosition) const;
virtual void storeLastSaveTime(){};
static bool cW3dStreaming;
static bool cPrintExternUrls;
private slots:
void updateProjectPath(const QString &oldPath, const QString &newPath);
void updateTopLevelLists();
};
#endif