Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class ROBOTS_TRIK_GENERATOR_BASE_EXPORT TrikGeneratorPluginBase : public generat
Q_OBJECT

public:
enum class RunPolicy {
Ask
, AlwaysRun
, NeverRun
};

TrikGeneratorPluginBase(kitBase::robotModel::RobotModelInterface * const robotModel
, const QSharedPointer<kitBase::blocksBase::BlocksFactoryInterface> &blocksFactory
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private slots:
/// Reenables buttons when program uploading or robot stopping is complete (sucessfully or with error).
void onProtocolFinished();

/// Runs after upload if needed
void onUploadSuccess();

private:
/// Disables "run", "upload" and "stop" buttons when there is pending command to a robot.
void disableButtons();
Expand Down Expand Up @@ -116,6 +119,8 @@ private slots:

/// Protocol that is used to stop robot.
QScopedPointer<utils::robotCommunication::StopRobotProtocol> mStopRobotProtocol;

QFileInfo mMainFile;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <utils/robotCommunication/networkCommunicationErrorReporter.h>
#include <qrgui/textEditor/qscintillaTextEdit.h>
#include <qrgui/textEditor/textManagerInterface.h>
#include <qrkernel/settingsManager.h>
#include <qrutils/widgets/qRealMessageBox.h>

#include "trikPythonMasterGenerator.h"
#include "emptyShell.h"
Expand Down Expand Up @@ -86,7 +88,7 @@ void TrikPythonGeneratorPluginBase::init(const kitBase::KitPluginConfigurator &c
, this, &TrikPythonGeneratorPluginBase::onProtocolFinished);

connect(mUploadProgramProtocol.data(), &UploadProgramProtocol::success
, this, &TrikPythonGeneratorPluginBase::onProtocolFinished);
, this, &TrikPythonGeneratorPluginBase::onUploadSuccess);
connect(mRunProgramProtocol.data(), &RunProgramProtocol::success
, this, &TrikPythonGeneratorPluginBase::onProtocolFinished);
connect(mStopRobotProtocol.data(), &StopRobotProtocol::success
Expand Down Expand Up @@ -200,6 +202,7 @@ void TrikPythonGeneratorPluginBase::uploadProgram()
const QFileInfo fileInfo = generateCodeForProcessing();
if (fileInfo != QFileInfo() && !fileInfo.absoluteFilePath().isEmpty()) {
disableButtons();
mMainFile = fileInfo;
mUploadProgramProtocol->run({fileInfo});
}
} else {
Expand All @@ -215,6 +218,9 @@ void TrikPythonGeneratorPluginBase::uploadProgram()
}
if (!files.isEmpty()) {
disableButtons();
if (auto code = dynamic_cast<text::QScintillaTextEdit *>(mMainWindowInterface->currentTab())) {
mMainFile = QFileInfo(mTextManager->path(code));
}
mUploadProgramProtocol->run(files);
} else {
mMainWindowInterface->errorReporter()->addError(
Expand Down Expand Up @@ -257,11 +263,44 @@ void TrikPythonGeneratorPluginBase::stopRobot()

void TrikPythonGeneratorPluginBase::onProtocolFinished()
{
mMainFile = QFileInfo();
mUploadProgramAction->setEnabled(true);
mRunProgramAction->setEnabled(true);
mStopRobotAction->setEnabled(true);
}

void TrikPythonGeneratorPluginBase::onUploadSuccess()
{
auto runPolicy = static_cast<RunPolicy>(SettingsManager::value("trikRunPolicy").toInt());
switch (runPolicy) {
case RunPolicy::Ask:
if (utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
, tr("The program has been uploaded")
, tr("Do you want to run it?")
) != QMessageBox::Yes) {
break;
}
Q_FALLTHROUGH();
case RunPolicy::AlwaysRun:
if (mMainFile != QFileInfo()) {
if (mRunProgramProtocol) {
mRunProgramProtocol->run(mMainFile);
return;
} else {
QLOG_ERROR() << "Run program protocol is not initialized";
}
} else {
utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
,tr("Error"), tr("Unknown file to run after upload, please run manually"),
QMessageBox::Ok);
}
break;
case RunPolicy::NeverRun:
break;
}
onProtocolFinished();
}

void TrikPythonGeneratorPluginBase::disableButtons()
{
mUploadProgramAction->setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private slots:
/// Reenables buttons when program uploading or robot stopping is complete (sucessfully or with error).
void onProtocolFinished();

/// Runs after upload if needed
void onUploadSuccess();

private:
/// Disables "run", "upload" and "stop" buttons when there is pending command to a robot.
void disableButtons();
Expand Down Expand Up @@ -116,6 +119,8 @@ private slots:

/// Protocol that is used to stop robot.
QScopedPointer<utils::robotCommunication::StopRobotProtocol> mStopRobotProtocol;

QFileInfo mMainFile;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include <utils/robotCommunication/networkCommunicationErrorReporter.h>
#include <qrgui/textEditor/qscintillaTextEdit.h>
#include <qrgui/textEditor/textManagerInterface.h>

#include <qrkernel/settingsManager.h>
#include <qrutils/widgets/qRealMessageBox.h>
#include "trikQtsMasterGenerator.h"
#include "emptyShell.h"

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

connect(mUploadProgramProtocol.data(), &UploadProgramProtocol::success
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
, this, &TrikQtsGeneratorPluginBase::onUploadSuccess);
connect(mRunProgramProtocol.data(), &RunProgramProtocol::success
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
connect(mStopRobotProtocol.data(), &StopRobotProtocol::success
Expand Down Expand Up @@ -215,6 +216,9 @@ void TrikQtsGeneratorPluginBase::uploadProgram()
}
if (!files.isEmpty()) {
disableButtons();
if (auto code = dynamic_cast<text::QScintillaTextEdit *>(mMainWindowInterface->currentTab())) {
mMainFile = QFileInfo(mTextManager->path(code));
}
mUploadProgramProtocol->run(files);
} else {
mMainWindowInterface->errorReporter()->addError(
Expand Down Expand Up @@ -254,8 +258,41 @@ void TrikQtsGeneratorPluginBase::stopRobot()
}
}

void TrikQtsGeneratorPluginBase::onUploadSuccess()
{
auto runPolicy = static_cast<RunPolicy>(SettingsManager::value("trikRunPolicy").toInt());
switch (runPolicy) {
case RunPolicy::Ask:
if (utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
, tr("The program has been uploaded")
, tr("Do you want to run it?")
) != QMessageBox::Yes) {
break;
}
Q_FALLTHROUGH();
case RunPolicy::AlwaysRun:
if (mMainFile != QFileInfo()) {
if (mRunProgramProtocol) {
mRunProgramProtocol->run(mMainFile);
return;
} else {
QLOG_ERROR() << "Run program protocol is not initialized";
}
} else {
utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
,tr("Error"), tr("Unknown file to run after upload, please run manually"),
QMessageBox::Ok);
}
break;
case RunPolicy::NeverRun:
break;
}
onProtocolFinished();
}

void TrikQtsGeneratorPluginBase::onProtocolFinished()
{
mMainFile = QFileInfo();
mUploadProgramAction->setEnabled(true);
mRunProgramAction->setEnabled(true);
mStopRobotAction->setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@

void RobotsSettingsPage::initializeAdditionalWidgets()
{
for (const QString &kitId : mKitPluginManager.kitIds()) {

Check warning on line 64 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
for (KitPluginInterface * const kitPlugin : mKitPluginManager.kitsById(kitId)) {

Check warning on line 65 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
QList<AdditionalPreferences *> const kitPreferences = kitPlugin->settingsWidgets();
for (AdditionalPreferences * const kitPreference: kitPreferences) {
if (kitPreference) {
Expand All @@ -77,8 +77,8 @@
{
QLabel * const emptyCaseLabel = new QLabel(tr("No constructor kit plugins loaded"), this);
mKitButtons = new QButtonGroup(this);
for (const QString &kitId : mKitPluginManager.kitIds()) {

Check warning on line 80 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
for (KitPluginInterface * const kitPlugin : mKitPluginManager.kitsById(kitId)) {

Check warning on line 81 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
const QString &kitFriendlyName = kitPlugin->friendlyKitName();
if (!kitFriendlyName.isEmpty()) {
QRadioButton * const kitRadioButton = new QRadioButton(kitFriendlyName, this);
Expand All @@ -99,12 +99,12 @@
{
QButtonGroup * const result = new QButtonGroup(kitButton);
QList<robotModel::RobotModelInterface *> robotModels;
for (KitPluginInterface * const kitPlugin : mKitPluginManager.kitsById(kitId)) {

Check warning on line 102 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
robotModels += kitPlugin->robotModels();
}

robotModel::RobotModelUtils::sortRobotModels(robotModels);
for (auto robotModel : robotModels) {

Check warning on line 107 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
QRadioButton * const button = new QRadioButton(robotModel->friendlyName(), this);
button->setObjectName(kitId + robotModel->name());
button->hide();
Expand All @@ -126,12 +126,14 @@
SettingsManager::setValue("nxtFlashToolRunPolicy", mUi->runningAfterUploadingComboBox->currentIndex());
} else if (mRobotModelManager.model().kitId().contains("ev3", Qt::CaseInsensitive)) {
SettingsManager::setValue("ev3RunPolicy", mUi->runningAfterUploadingComboBox->currentIndex());
} else if (mRobotModelManager.model().kitId().contains("trik", Qt::CaseInsensitive)) {
SettingsManager::setValue("trikRunPolicy", mUi->runningAfterUploadingComboBox->currentIndex());
}

mUi->devicesConfigurer->save();

for (const QString &kitId : mKitPluginManager.kitIds()) {

Check warning on line 135 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
for (KitPluginInterface * const kitPlugin : mKitPluginManager.kitsById(kitId)) {

Check warning on line 136 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
QList<AdditionalPreferences *> const kitPreferences = kitPlugin->settingsWidgets();
for (AdditionalPreferences * const kitPreference: kitPreferences) {
if (kitPreference) {
Expand Down Expand Up @@ -169,11 +171,13 @@
mUi->runningAfterUploadingComboBox->setCurrentIndex(SettingsManager::value("nxtFlashToolRunPolicy").toInt());
} else if (mRobotModelManager.model().kitId().contains("ev3", Qt::CaseInsensitive)) {
mUi->runningAfterUploadingComboBox->setCurrentIndex(SettingsManager::value("ev3RunPolicy").toInt());
} else if (mRobotModelManager.model().kitId().contains("trik", Qt::CaseInsensitive)) {
mUi->runningAfterUploadingComboBox->setCurrentIndex(SettingsManager::value("trikRunPolicy").toInt());
}
mUi->devicesConfigurer->refresh();

for (const QString &kitId : mKitPluginManager.kitIds()) {

Check warning on line 179 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
for (KitPluginInterface * const kitPlugin : mKitPluginManager.kitsById(kitId)) {

Check warning on line 180 in plugins/robots/interpreters/interpreterCore/src/ui/robotsSettingsPage.cpp

View workflow job for this annotation

GitHub Actions / build-ubuntu-release-tests / build

c++11 range-loop might detach Qt container (QList) [-Wclazy-range-loop-detach]
QList<AdditionalPreferences *> const kitPreferences = kitPlugin->settingsWidgets();
for (AdditionalPreferences * const kitPreference: kitPreferences) {
if (kitPreference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ FSharpPath=C:/Program Files (x86)/Microsoft SDKs/F#/3.1/Framework/v4.0/Fsc.exe
WinScpPath=./winscp/WinSCP.com
trikRobot2DImage=./images/trik-robot.png
trikCameraImitationImagesDir=@AppDataLocation@/cameraImitation
trikRunPolicy=0
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ROBOTS_UTILS_EXPORT RunProgramProtocol : public QObject
~RunProgramProtocol() override;

/// Upload and run program from given file on a robot.
void run(const QFileInfo &fileToRun);
void run(const QFileInfo &fileToRun, bool needUpload = true);

signals:
/// Emitted when protocol completed successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,19 @@ RunProgramProtocol::~RunProgramProtocol()
{
}

void RunProgramProtocol::run(const QFileInfo &fileToRun)
void RunProgramProtocol::run(const QFileInfo &fileToRun, bool needUpload)
{
mProtocol->setAction(mWaitingForCasingModel, [](TcpRobotCommunicatorInterface &communicator) {
communicator.requestCasingVersion();
});

mProtocol->setAction(mWaitingForUploadingComplete, [fileToRun](TcpRobotCommunicatorInterface &communicator) {
communicator.uploadProgram(fileToRun.canonicalFilePath());
mProtocol->setAction(mWaitingForUploadingComplete,
[fileToRun, needUpload](TcpRobotCommunicatorInterface &communicator) {
if (needUpload) {
communicator.uploadProgram(fileToRun.canonicalFilePath());
} else {
emit communicator.uploadProgramDone();
}
});

mProtocol->setAction(mWaitingForRunComplete, [fileToRun](TcpRobotCommunicatorInterface &communicator) {
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/fr/plugins/robots/interpreterCore_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
<translation>Aucune extension n&apos;est chargée</translation>
</message>
<message>
<location line="+134"/>
<location line="+138"/>
<source>No robot models available for </source>
<translation>Modèle de robot n&apos;est pas défini dans l&apos;extension</translation>
</message>
Expand Down
24 changes: 22 additions & 2 deletions qrtranslations/fr/plugins/robots/trikPythonGeneratorLibrary_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<context>
<name>trik::python::TrikPythonGeneratorPluginBase</name>
<message>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+73"/>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+75"/>
<source>Network operation timed out</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -118,9 +118,29 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+72"/>
<location line="+76"/>
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+51"/>
<source>The program has been uploaded</source>
<translation>Le téléversement du programme est terminé</translation>
</message>
<message>
<location line="+1"/>
<source>Do you want to run it?</source>
<translation>Est-ce que vous voulez l&apos;executer ?</translation>
</message>
<message>
<location line="+15"/>
<source>Error</source>
<translation>Erreur</translation>
</message>
<message>
<location line="+0"/>
<source>Unknown file to run after upload, please run manually</source>
<translation>Fichier inconnu à exécuter après le téléchargement, veuillez l&apos;exécuter manuellement</translation>
</message>
</context>
</TS>
24 changes: 22 additions & 2 deletions qrtranslations/fr/plugins/robots/trikQtsGeneratorLibrary_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<context>
<name>trik::qts::TrikQtsGeneratorPluginBase</name>
<message>
<location filename="../../../../plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp" line="+73"/>
<location filename="../../../../plugins/robots/generators/trik/trikQtsGeneratorLibrary/src/trikQtsGeneratorPluginBase.cpp" line="+74"/>
<source>Network operation timed out</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -118,9 +118,29 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+72"/>
<location line="+75"/>
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+42"/>
<source>The program has been uploaded</source>
<translation>Le téléversement du programme est terminé</translation>
</message>
<message>
<location line="+1"/>
<source>Do you want to run it?</source>
<translation>Est-ce que vous voulez l&apos;executer ?</translation>
</message>
<message>
<location line="+15"/>
<source>Error</source>
<translation>Erreur</translation>
</message>
<message>
<location line="+0"/>
<source>Unknown file to run after upload, please run manually</source>
<translation>Fichier inconnu à exécuter après le téléchargement, veuillez l&apos;exécuter manuellement</translation>
</message>
</context>
</TS>
2 changes: 1 addition & 1 deletion qrtranslations/ru/plugins/robots/interpreterCore_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@
<translation>Не загружено ни одного плагина с описанием робоплатформы</translation>
</message>
<message>
<location line="+134"/>
<location line="+138"/>
<source>No robot models available for </source>
<translation>Ни одной модели робота не найдено в плагине </translation>
</message>
Expand Down
24 changes: 22 additions & 2 deletions qrtranslations/ru/plugins/robots/trikPythonGeneratorLibrary_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<context>
<name>trik::python::TrikPythonGeneratorPluginBase</name>
<message>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+73"/>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+75"/>
<source>Network operation timed out</source>
<translation>Не удалось получить ответ от робота, проверьте настройки, проверьте, включён ли робот</translation>
</message>
Expand Down Expand Up @@ -118,9 +118,29 @@
<translation>Остановить выполнение программы для TRIK</translation>
</message>
<message>
<location line="+72"/>
<location line="+76"/>
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
<translation>Нет файлов для загрузки. Вы должны открыть или сгенерировать хотя бы один *.js или *.py файл.</translation>
</message>
<message>
<location line="+51"/>
<source>The program has been uploaded</source>
<translation>Загрузка завершена</translation>
</message>
<message>
<location line="+1"/>
<source>Do you want to run it?</source>
<translation>Хотите ли Вы запустить эту программу?</translation>
</message>
<message>
<location line="+15"/>
<source>Error</source>
<translation>Ошибка</translation>
</message>
<message>
<location line="+0"/>
<source>Unknown file to run after upload, please run manually</source>
<translation>Не удалось запустить программу после загрузки, пожалуйста, попробуйте запустить программу напрямую</translation>
</message>
</context>
</TS>
Loading
Loading