Files
ssp/services/productionworker.cpp
T

109 lines
3.0 KiB
C++
Raw Normal View History

2026-08-20 11:22:55 +08:00
#include "productionworker.h"
ProductionWorker::ProductionWorker(QObject *parent)
: QObject(parent)
, m_service(nullptr)
{
}
void ProductionWorker::ensureService()
{
if (m_service) {
return;
}
m_service = new ProductionService(this);
connect(m_service, &ProductionService::stateChanged,
this, &ProductionWorker::stateChanged);
connect(m_service, &ProductionService::currentWorkpieceChanged,
this, &ProductionWorker::currentWorkpieceChanged);
connect(m_service, &ProductionService::currentWorkpieceSnapshotChanged,
this, &ProductionWorker::currentWorkpieceSnapshotChanged);
connect(m_service, &ProductionService::currentPositionChanged,
this, &ProductionWorker::currentPositionChanged);
connect(m_service, &ProductionService::productionFinished,
this, &ProductionWorker::productionFinished);
connect(m_service, &ProductionService::productionError,
this, &ProductionWorker::productionError);
connect(m_service, &ProductionService::alarmRaised,
this, &ProductionWorker::alarmRaised);
connect(m_service, &ProductionService::processElapsedChanged,
this, &ProductionWorker::processElapsedChanged);
connect(m_service, &ProductionService::timeoutWarning,
this, &ProductionWorker::timeoutWarning);
connect(m_service, &ProductionService::timeoutRecoveryRequired,
this, &ProductionWorker::timeoutRecoveryRequired);
connect(m_service, &ProductionService::recoveryCompleted,
this, &ProductionWorker::recoveryCompleted);
}
void ProductionWorker::reportFailure(bool success, const QString &error)
{
if (!success && !error.isEmpty()) {
emit productionError(error);
}
}
void ProductionWorker::requestStart(int orderId)
{
ensureService();
QString error;
reportFailure(m_service->start(orderId, &error), error);
}
void ProductionWorker::requestPause()
{
ensureService();
QString error;
reportFailure(m_service->pause(&error), error);
}
void ProductionWorker::requestResume()
{
ensureService();
QString error;
reportFailure(m_service->resume(&error), error);
}
void ProductionWorker::requestStop()
{
ensureService();
QString error;
reportFailure(m_service->stop(&error), error);
}
void ProductionWorker::requestReset()
{
ensureService();
QString error;
reportFailure(m_service->reset(&error), error);
}
void ProductionWorker::requestRecover()
{
ensureService();
QString error;
reportFailure(m_service->recover(&error), error);
}
void ProductionWorker::requestRetry()
{
ensureService();
QString error;
reportFailure(m_service->retry(&error), error);
}
void ProductionWorker::requestMarkNg()
{
ensureService();
QString error;
reportFailure(m_service->markCurrentWorkpieceNg(&error), error);
}
void ProductionWorker::requestRestore()
{
ensureService();
QString error;
reportFailure(m_service->restoreActiveRun(&error), error);
}