Skip to content

Commit 7c5c114

Browse files
Put robot's console in the same window with twoDModelWidget (#791)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a6fde9b commit 7c5c114

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

plugins/robots/checker/twoDModelRunner/runner.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Runner::Runner(const QString &report, const QString &trajectory)
4444
, mQRealFacade.events()
4545
, mTextManager)
4646
, mReporter(report, trajectory)
47-
, mRobotConsole(new qReal::ui::ConsoleDock(tr("Robot console")))
4847
{
4948
mPluginFacade.init(mConfigurator);
5049
for (const QString &defaultSettingsFile : mPluginFacade.defaultSettingsFiles()) {
@@ -95,14 +94,20 @@ bool Runner::interpret(const QString &saveFile, bool background)
9594
for (view::TwoDModelWidget * const twoDModelWindow : twoDModelWindows) {
9695
connect(twoDModelWindow, &view::TwoDModelWidget::widgetClosed, &mMainWindow
9796
, [this]() { this->mMainWindow.emulateClose(); });
97+
auto layout = dynamic_cast<QGridLayout*>(twoDModelWindow->layout());
98+
qReal::ui::ConsoleDock* console = nullptr;
99+
if (layout) {
100+
console = new qReal::ui::ConsoleDock(tr("Robot console"), mMainWindow.windowWidget());
101+
mRobotConsoles << console;
102+
// TODO: hack to add console for each widget
103+
layout->addWidget(console, layout->rowCount(), 0, 1, -1);
104+
}
98105
twoDModelWindow->model().timeline().setImmediateMode(background);
99106
for (const model::RobotModel *robotModel : twoDModelWindow->model().robotModels()) {
100-
connectRobotModel(robotModel);
107+
connectRobotModel(robotModel, console);
101108
}
102109
}
103110

104-
mRobotConsole->show();
105-
106111
mReporter.onInterpretationStart();
107112
if (mMode == "script") {
108113
return mPluginFacade.interpretCode(mInputsFile);
@@ -113,7 +118,7 @@ bool Runner::interpret(const QString &saveFile, bool background)
113118
return true;
114119
}
115120

116-
void Runner::connectRobotModel(const model::RobotModel *robotModel)
121+
void Runner::connectRobotModel(const model::RobotModel *robotModel, const qReal::ui::ConsoleDock* console)
117122
{
118123
connect(robotModel, &model::RobotModel::positionRecalculated
119124
, this, &Runner::onRobotRided, Qt::UniqueConnection);
@@ -125,10 +130,11 @@ void Runner::connectRobotModel(const model::RobotModel *robotModel)
125130
, [=](const QString &property, const QVariant &value) {
126131
onDeviceStateChanged(robotModel->info().robotId(), device, property, value);
127132
});
128-
129-
if (auto * shell = dynamic_cast<kitBase::robotModel::robotParts::Shell*>(device)) {
130-
connect(shell, &kitBase::robotModel::robotParts::Shell::textPrinted
131-
, mRobotConsole, &qReal::ui::ConsoleDock::print);
133+
if (console) {
134+
if (auto * shell = dynamic_cast<kitBase::robotModel::robotParts::Shell*>(device)) {
135+
connect(shell, &kitBase::robotModel::robotParts::Shell::textPrinted
136+
, console, &qReal::ui::ConsoleDock::print);
137+
}
132138
}
133139
});
134140
}
@@ -160,4 +166,8 @@ void Runner::onDeviceStateChanged(const QString &robotId
160166
void Runner::close()
161167
{
162168
mMainWindow.emulateClose(mReporter.lastMessageIsError() ? 1 : 0);
169+
while (!mRobotConsoles.empty()) {
170+
mRobotConsoles.first()->deleteLater();
171+
mRobotConsoles.removeFirst();
172+
}
163173
}

plugins/robots/checker/twoDModelRunner/runner.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private slots:
6969
void close();
7070

7171
private:
72-
void connectRobotModel(const model::RobotModel *robotModel);
72+
void connectRobotModel(const model::RobotModel *robotModel, const qReal::ui::ConsoleDock* console);
7373
void onRobotRided(const QPointF &newPosition, const qreal newRotation);
7474
void onDeviceStateChanged(const QString &robotId, const kitBase::robotModel::robotParts::Device *device
7575
, const QString &property, const QVariant &value);
@@ -84,7 +84,7 @@ private slots:
8484
qReal::PluginConfigurator mConfigurator;
8585
interpreterCore::RobotsPluginFacade mPluginFacade;
8686
Reporter mReporter;
87-
qReal::ui::ConsoleDock *mRobotConsole;
87+
QList<qReal::ui::ConsoleDock *> mRobotConsoles;
8888
QString mInputsFile;
8989
QString mMode;
9090
};

qrtranslations/fr/plugins/robots/twoDModelRunner_fr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ In background mode the session will be terminated just after the execution ended
4949
<context>
5050
<name>twoDModel::Runner</name>
5151
<message>
52-
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+47"/>
52+
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+100"/>
5353
<source>Robot console</source>
5454
<translation type="unfinished"></translation>
5555
</message>

qrtranslations/ru/plugins/robots/twoDModelRunner_ru.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ In background mode the session will be terminated just after the execution ended
5959
<context>
6060
<name>twoDModel::Runner</name>
6161
<message>
62-
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+47"/>
62+
<location filename="../../../../plugins/robots/checker/twoDModelRunner/runner.cpp" line="+100"/>
6363
<source>Robot console</source>
6464
<translation>Консоль робота</translation>
6565
</message>

0 commit comments

Comments
 (0)