Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
MinyazevR committed Feb 27, 2025
1 parent a595200 commit 244004f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <utils/robotCommunication/uploadProgramProtocol.h>
#include <utils/robotCommunication/networkCommunicationErrorReporter.h>
#include <qrgui/textEditor/qscintillaTextEdit.h>
#include <qrgui/textEditor/textManagerInterface.h>
#include <qrkernel/settingsManager.h>
#include <qrutils/widgets/qRealMessageBox.h>

Expand Down Expand Up @@ -271,20 +272,19 @@ void TrikPythonGeneratorPluginBase::onProtocolFinished()
void TrikPythonGeneratorPluginBase::onUploadSuccess()
{
auto runPolicy = static_cast<RunPolicy>(SettingsManager::value("trikRunPolicy").toInt());
QFileInfo fileInfo;
switch (runPolicy) {
case RunPolicy::Ask:
if (utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
, tr("The program has been uploaded")
, tr("Do you want to run it?")
, 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->runUploaded(mMainFile);
mRunProgramProtocol->run(mMainFile);
return;
} else {
QLOG_ERROR() << "Run program protocol is not initialized";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +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);

/// Run uploaded program from given file on robot.
void runUploaded(const QFileInfo &fileToRun);
void run(const QFileInfo &fileToRun, bool needUpload = true);

signals:
/// Emitted when protocol completed successfully.
Expand Down
27 changes: 7 additions & 20 deletions plugins/robots/utils/src/robotCommunication/runProgramProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,18 @@ 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(mWaitingForRunComplete, [fileToRun](TcpRobotCommunicatorInterface &communicator) {
communicator.runProgram(fileToRun.fileName());
});

mProtocol->run();
}

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

mProtocol->setAction(mWaitingForUploadingComplete, [](TcpRobotCommunicatorInterface &communicator) {
emit communicator.uploadProgramDone();
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

0 comments on commit 244004f

Please sign in to comment.