-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtwoDModelWidget.h
More file actions
280 lines (205 loc) · 7.54 KB
/
twoDModelWidget.h
File metadata and controls
280 lines (205 loc) · 7.54 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/* Copyright 2007-2015 QReal Research Group, Dmitry Mordvinov
*
* 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
*
* http://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. */
#pragma once
#include <QtCore/QSignalMapper>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QGraphicsView>
#include <qrutils/graphicsUtils/lineImpl.h>
#include <qrgui/plugins/toolPluginInterface/usedInterfaces/editorInterface.h>
#include <kitBase/readOnly.h>
#include <kitBase/devicesConfigurationWidget.h>
#include <kitBase/devicesConfigurationProvider.h>
#include "twoDModel/engine/twoDModelDisplayWidget.h"
#include "twoDModel/twoDModelDeclSpec.h"
class QComboBox;
class QPushButton;
class QDomDocument;
namespace Ui {
class TwoDModelWidget;
}
namespace graphicsUtils {
class AbstractItem;
}
namespace qReal {
class ControllerInterface;
}
namespace twoDModel {
namespace trajectory {
class ConnectionToVisualizer;
}
namespace model {
class Model;
class RobotModel;
}
namespace view {
class TwoDModelScene;
class SensorItem;
class RobotItem;
class ActionsBox;
class ColorItemPopup;
class ImageItemPopup;
class RobotItemPopup;
class SpeedPopup;
class TWO_D_MODEL_EXPORT TwoDModelWidget : public QWidget
, public kitBase::DevicesConfigurationProvider
, public qReal::EditorInterface
{
Q_OBJECT
public:
TwoDModelWidget(model::Model &model, QWidget *parent = nullptr);
~TwoDModelWidget();
/// Overrides default closing behaviour with just hiding window.
void close();
TwoDModelScene *scene();
engine::TwoDModelDisplayWidget *display();
SensorItem *sensorItem(const kitBase::robotModel::PortInfo &port);
void setSensorVisible(const kitBase::robotModel::PortInfo &port, bool isVisible);
void loadXmls(const QDomDocument &model, bool withUndo = false);
/// Returns a reference to a model part of 2D model MVC architecture.
model::Model &model() const;
/// Passes into view a reference to controller object that will execute commands.
void setController(qReal::ControllerInterface &controller);
/// Sets groups of items on 2d model that can not be modified by user. Used for "challenge" mode where student
/// shall provide program that makes robot do specific task in given unmodifyable world model.
/// @see ReadOnly
void setInteractivityFlags(kitBase::ReadOnlyFlags flags);
/// Enables or disables compact 2D model mode.
/// In a compact mode 2D model window has less controls, they may seem in another way.
void setCompactMode(bool enabled);
void setBackgroundMode();
/// Returns a reference to a connection to vizualizer tool
twoDModel::trajectory::ConnectionToVisualizer *connToVisualizer();
QString editorId() const override;
bool supportsZooming() const override;
void configure(QAction &zoomIn, QAction &zoomOut, QAction &undo, QAction &redo, QAction ©, QAction &paste
, QAction &cut, QAction &find, QAction &findAndeReplace, QAction &replaceBy) override;
QDomDocument generateWorldModelWithBlobsXml() const;
QDomDocument generateWorldModelXml() const;
QDomDocument generateBlobsXml() const;
public slots:
void zoomIn() override;
void zoomOut() override;
signals:
/// Emitted each time when user closes 2D model window.
void widgetClosed();
void robotWasIntersectedByWall(bool isNeedStop, const QPointF &oldPos);
/// Emitted when such features as motor or sensor noise were
///enabled or disabled by user
void noiseSettingsChanged();
/// Emitted when user has started intepretation from the 2D model window.
void runButtonPressed();
/// Emitted when user has stopped intepretation from the 2D model window.
void stopButtonPressed();
/// Emitted when user has stopped intepretation from the remote visualizator
void restartRequested();
protected:
void changeEvent(QEvent *e) override;
void showEvent(QShowEvent *e) override;
void closeEvent(QCloseEvent *event) override;
void focusInEvent(QFocusEvent *event) override;
void onDeviceConfigurationChanged(const QString &robotId
, const kitBase::robotModel::PortInfo &port
, const kitBase::robotModel::DeviceInfo &device
, Reason reason) override;
private slots:
void bringToFront();
void saveWorldModelToRepo();
void saveBlobsToRepo();
void saveWorldModel();
void loadWorldModel();
void loadWorldModelWithoutRobot();
void onSelectionChange();
void speedUp();
void speedDown();
void checkSpeedButtons();
void enableRobotFollowing(bool on);
void onHandCursorActionTriggered();
void onMultiselectionCursorActionTriggered();
void changePhysicsSettings();
void toggleDetailsVisibility();
void returnToStartMarker();
void setStartMarker();
void trainingModeChanged(bool enabled);
void updateUIPhysicsSettings();
private:
enum CursorType
{
noDrag = 0
, hand
, multiselection
, drawWall
, drawSkittle
, drawBall
, drawLine
, drawStylus
, drawEllipse
, drawRectangle
, drawBezier
};
static const int defaultPenWidth = 6;
void connectUiButtons();
void setPortsGroupBoxAndWheelComboBoxes();
void unsetPortsGroupBoxAndWheelComboBoxes();
void setDetailsVisibility(bool visible);
void setRunStopButtonsVisibility();
/// Set active panel toggle button and deactivate all others
void setActiveButton(int active);
/// Get QPushButton for current sensor
QPushButton *currentPortButton();
void setCursorTypeForDrawing(CursorType type);
void setCursorType(int cursorType);
void setCursorType(CursorType cursor);
void initWidget();
void initPalette();
void initDetailsTab();
QList<graphicsUtils::AbstractItem *> selectedColorItems() const;
bool isColorItem(graphicsUtils::AbstractItem * const item) const;
void centerOnRobot();
QGraphicsView::DragMode cursorTypeToDragType(CursorType type) const;
QCursor cursorTypeToCursor(CursorType type) const;
void refreshCursor();
void syncCursorButtons();
void onFirstShow();
void initRunStopButtons();
bool setSelectedPort(QComboBox * const comboBox, const kitBase::robotModel::PortInfo &port);
void updateWheelComboBoxes();
void onRobotListChange(RobotItem *robotItem);
void setSelectedRobotItem(RobotItem *robotItem);
void unsetSelectedRobotItem();
void incrementTimelineCounter();
Ui::TwoDModelWidget *mUi {};
QScopedPointer<TwoDModelScene> mScene;
QScopedPointer<ActionsBox> mActions;
ColorItemPopup *mColorFieldItemPopup {}; // Takes ownership
ImageItemPopup *mImageItemPopup {}; // Takes ownership
RobotItemPopup *mRobotItemPopup {}; // Takes ownership
SpeedPopup *mSpeedPopup {}; // Takes owneship
RobotItem *mSelectedRobotItem {};
kitBase::DevicesConfigurationWidget *mCurrentConfigurer {};
twoDModel::trajectory::ConnectionToVisualizer *mConnToVisualizer {}; // Takes ownership
model::Model &mModel;
qReal::ControllerInterface *mController {};
engine::TwoDModelDisplayWidget *mDisplay {}; // Transfers ownership to parent widget upon creation
engine::TwoDModelDisplayWidget *mNullDisplay {}; // Transfers ownership to parent widget upon creation
int mCurrentSpeed { -1 };
CursorType mNoneCursorType { CursorType::noDrag }; // cursorType for noneStatus
CursorType mCursorType { CursorType::noDrag }; // current cursorType
bool mFollowRobot {};
bool mDetailsAreVisible {};
bool mFirstShow { true };
bool mRobotPositionReadOnly {};
bool mBackgroundMode {false};
};
}
}