Skip to content

Commit 5918ecc

Browse files
MinyazevRiakov
authored andcommitted
Add Run after upload support for JavaScript
1 parent 967981d commit 5918ecc

File tree

9 files changed

+136
-13
lines changed

9 files changed

+136
-13
lines changed

plugins/robots/generators/trik/trikQtsGeneratorLibrary/include/trikQtsGeneratorLibrary/trikQtsGeneratorPluginBase.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ private slots:
8484
/// Reenables buttons when program uploading or robot stopping is complete (sucessfully or with error).
8585
void onProtocolFinished();
8686

87+
/// Runs after upload if needed
88+
void onUploadSuccess();
89+
8790
private:
8891
/// Disables "run", "upload" and "stop" buttons when there is pending command to a robot.
8992
void disableButtons();
@@ -116,6 +119,8 @@ private slots:
116119

117120
/// Protocol that is used to stop robot.
118121
QScopedPointer<utils::robotCommunication::StopRobotProtocol> mStopRobotProtocol;
122+
123+
QFileInfo mMainFile;
119124
};
120125

121126
}

plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
#include <utils/robotCommunication/networkCommunicationErrorReporter.h>
3232
#include <qrgui/textEditor/qscintillaTextEdit.h>
3333
#include <qrgui/textEditor/textManagerInterface.h>
34-
34+
#include <qrkernel/settingsManager.h>
35+
#include <qrutils/widgets/qRealMessageBox.h>
3536
#include "trikQtsMasterGenerator.h"
3637
#include "emptyShell.h"
3738

@@ -86,7 +87,7 @@ void TrikQtsGeneratorPluginBase::init(const kitBase::KitPluginConfigurator &conf
8687
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
8788

8889
connect(mUploadProgramProtocol.data(), &UploadProgramProtocol::success
89-
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
90+
, this, &TrikQtsGeneratorPluginBase::onUploadSuccess);
9091
connect(mRunProgramProtocol.data(), &RunProgramProtocol::success
9192
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
9293
connect(mStopRobotProtocol.data(), &StopRobotProtocol::success
@@ -215,6 +216,9 @@ void TrikQtsGeneratorPluginBase::uploadProgram()
215216
}
216217
if (!files.isEmpty()) {
217218
disableButtons();
219+
if (auto code = dynamic_cast<text::QScintillaTextEdit *>(mMainWindowInterface->currentTab())) {
220+
mMainFile = QFileInfo(mTextManager->path(code));
221+
}
218222
mUploadProgramProtocol->run(files);
219223
} else {
220224
mMainWindowInterface->errorReporter()->addError(
@@ -254,8 +258,41 @@ void TrikQtsGeneratorPluginBase::stopRobot()
254258
}
255259
}
256260

261+
void TrikQtsGeneratorPluginBase::onUploadSuccess()
262+
{
263+
auto runPolicy = static_cast<RunPolicy>(SettingsManager::value("trikRunPolicy").toInt());
264+
switch (runPolicy) {
265+
case RunPolicy::Ask:
266+
if (utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
267+
, tr("The program has been uploaded")
268+
, tr("Do you want to run it?")
269+
) != QMessageBox::Yes) {
270+
break;
271+
}
272+
Q_FALLTHROUGH();
273+
case RunPolicy::AlwaysRun:
274+
if (mMainFile != QFileInfo()) {
275+
if (mRunProgramProtocol) {
276+
mRunProgramProtocol->run(mMainFile);
277+
return;
278+
} else {
279+
QLOG_ERROR() << "Run program protocol is not initialized";
280+
}
281+
} else {
282+
utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
283+
,tr("Error"), tr("Unknown file to run after upload, please run manually"),
284+
QMessageBox::Ok);
285+
}
286+
break;
287+
case RunPolicy::NeverRun:
288+
break;
289+
}
290+
onProtocolFinished();
291+
}
292+
257293
void TrikQtsGeneratorPluginBase::onProtocolFinished()
258294
{
295+
mMainFile = QFileInfo();
259296
mUploadProgramAction->setEnabled(true);
260297
mRunProgramAction->setEnabled(true);
261298
mStopRobotAction->setEnabled(true);

plugins/robots/utils/src/robotCommunication/runProgramProtocol.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ void RunProgramProtocol::run(const QFileInfo &fileToRun, bool needUpload)
6262
communicator.requestCasingVersion();
6363
});
6464

65-
mProtocol->setAction(mWaitingForUploadingComplete, [fileToRun, needUpload](TcpRobotCommunicatorInterface &communicator) {
65+
mProtocol->setAction(mWaitingForUploadingComplete,
66+
[fileToRun, needUpload](TcpRobotCommunicatorInterface &communicator) {
6667
if (needUpload) {
6768
communicator.uploadProgram(fileToRun.canonicalFilePath());
6869
} else {

qrtranslations/fr/plugins/robots/interpreterCore_fr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@
493493
<translation>Aucune extension n&apos;est chargée</translation>
494494
</message>
495495
<message>
496-
<location line="+134"/>
496+
<location line="+138"/>
497497
<source>No robot models available for </source>
498498
<translation>Modèle de robot n&apos;est pas défini dans l&apos;extension</translation>
499499
</message>

qrtranslations/fr/plugins/robots/trikPythonGeneratorLibrary_fr.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<context>
6969
<name>trik::python::TrikPythonGeneratorPluginBase</name>
7070
<message>
71-
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+73"/>
71+
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+75"/>
7272
<source>Network operation timed out</source>
7373
<translation type="unfinished"></translation>
7474
</message>
@@ -118,9 +118,29 @@
118118
<translation type="unfinished"></translation>
119119
</message>
120120
<message>
121-
<location line="+72"/>
121+
<location line="+76"/>
122122
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
123123
<translation type="unfinished"></translation>
124124
</message>
125+
<message>
126+
<location line="+51"/>
127+
<source>The program has been uploaded</source>
128+
<translation>Le téléversement du programme est terminé</translation>
129+
</message>
130+
<message>
131+
<location line="+1"/>
132+
<source>Do you want to run it?</source>
133+
<translation>Est-ce que vous voulez l&apos;executer ?</translation>
134+
</message>
135+
<message>
136+
<location line="+15"/>
137+
<source>Error</source>
138+
<translation>Erreur</translation>
139+
</message>
140+
<message>
141+
<location line="+0"/>
142+
<source>Unknown file to run after upload, please run manually</source>
143+
<translation>Fichier inconnu à exécuter après le téléchargement, veuillez l&apos;exécuter manuellement</translation>
144+
</message>
125145
</context>
126146
</TS>

qrtranslations/fr/plugins/robots/trikQtsGeneratorLibrary_fr.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<context>
6969
<name>trik::qts::TrikQtsGeneratorPluginBase</name>
7070
<message>
71-
<location filename="../../../../plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp" line="+73"/>
71+
<location filename="../../../../plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp" line="+74"/>
7272
<source>Network operation timed out</source>
7373
<translation type="unfinished"></translation>
7474
</message>
@@ -118,9 +118,29 @@
118118
<translation type="unfinished"></translation>
119119
</message>
120120
<message>
121-
<location line="+72"/>
121+
<location line="+75"/>
122122
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
123123
<translation type="unfinished"></translation>
124124
</message>
125+
<message>
126+
<location line="+42"/>
127+
<source>The program has been uploaded</source>
128+
<translation>Le téléversement du programme est terminé</translation>
129+
</message>
130+
<message>
131+
<location line="+1"/>
132+
<source>Do you want to run it?</source>
133+
<translation>Est-ce que vous voulez l&apos;executer ?</translation>
134+
</message>
135+
<message>
136+
<location line="+15"/>
137+
<source>Error</source>
138+
<translation>Erreur</translation>
139+
</message>
140+
<message>
141+
<location line="+0"/>
142+
<source>Unknown file to run after upload, please run manually</source>
143+
<translation>Fichier inconnu à exécuter après le téléchargement, veuillez l&apos;exécuter manuellement</translation>
144+
</message>
125145
</context>
126146
</TS>

qrtranslations/ru/plugins/robots/interpreterCore_ru.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@
380380
<translation>Не загружено ни одного плагина с описанием робоплатформы</translation>
381381
</message>
382382
<message>
383-
<location line="+134"/>
383+
<location line="+138"/>
384384
<source>No robot models available for </source>
385385
<translation>Ни одной модели робота не найдено в плагине </translation>
386386
</message>

qrtranslations/ru/plugins/robots/trikPythonGeneratorLibrary_ru.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<context>
6969
<name>trik::python::TrikPythonGeneratorPluginBase</name>
7070
<message>
71-
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+73"/>
71+
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+75"/>
7272
<source>Network operation timed out</source>
7373
<translation>Не удалось получить ответ от робота, проверьте настройки, проверьте, включён ли робот</translation>
7474
</message>
@@ -118,9 +118,29 @@
118118
<translation>Остановить выполнение программы для TRIK</translation>
119119
</message>
120120
<message>
121-
<location line="+72"/>
121+
<location line="+76"/>
122122
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
123123
<translation>Нет файлов для загрузки. Вы должны открыть или сгенерировать хотя бы один *.js или *.py файл.</translation>
124124
</message>
125+
<message>
126+
<location line="+51"/>
127+
<source>The program has been uploaded</source>
128+
<translation>Загрузка завершена</translation>
129+
</message>
130+
<message>
131+
<location line="+1"/>
132+
<source>Do you want to run it?</source>
133+
<translation>Хотите ли Вы запустить эту программу?</translation>
134+
</message>
135+
<message>
136+
<location line="+15"/>
137+
<source>Error</source>
138+
<translation>Ошибка</translation>
139+
</message>
140+
<message>
141+
<location line="+0"/>
142+
<source>Unknown file to run after upload, please run manually</source>
143+
<translation>Не удалось запустить программу после загрузки, пожалуйста, попробуйте запустить программу напрямую</translation>
144+
</message>
125145
</context>
126146
</TS>

qrtranslations/ru/plugins/robots/trikQtsGeneratorLibrary_ru.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
<context>
124124
<name>trik::qts::TrikQtsGeneratorPluginBase</name>
125125
<message>
126-
<location filename="../../../../plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp" line="+73"/>
126+
<location filename="../../../../plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp" line="+74"/>
127127
<source>Network operation timed out</source>
128128
<translation>Не удалось получить ответ от робота, проверьте настройки, проверьте, включён ли робот</translation>
129129
</message>
@@ -173,10 +173,30 @@
173173
<translation>Остановить выполнение программы для TRIK</translation>
174174
</message>
175175
<message>
176-
<location line="+72"/>
176+
<location line="+75"/>
177177
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
178178
<translation>Нет файлов для загрузки. Вы должны открыть или сгенерировать хотя бы один *.js или *.py файл.</translation>
179179
</message>
180+
<message>
181+
<location line="+42"/>
182+
<source>The program has been uploaded</source>
183+
<translation>Загрузка завершена</translation>
184+
</message>
185+
<message>
186+
<location line="+1"/>
187+
<source>Do you want to run it?</source>
188+
<translation>Хотите ли Вы запустить эту программу?</translation>
189+
</message>
190+
<message>
191+
<location line="+15"/>
192+
<source>Error</source>
193+
<translation>Ошибка</translation>
194+
</message>
195+
<message>
196+
<location line="+0"/>
197+
<source>Unknown file to run after upload, please run manually</source>
198+
<translation>Не удалось запустить программу после загрузки, пожалуйста, попробуйте запустить программу напрямую</translation>
199+
</message>
180200
<message>
181201
<source>No connection to robot</source>
182202
<translation type="vanished">Нет соединения с роботом, проверьте настройки, проверьте, включён ли робот</translation>

0 commit comments

Comments
 (0)