first commit
This commit is contained in:
172
procedure/procedureengine.h
Normal file
172
procedure/procedureengine.h
Normal file
@@ -0,0 +1,172 @@
|
||||
#ifndef PROCEDUREENGINE_H
|
||||
#define PROCEDUREENGINE_H
|
||||
|
||||
#include "proceduredata.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QDateTime>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
|
||||
class ProcedureParser;
|
||||
class FunctionRegistry;
|
||||
class QTimer;
|
||||
|
||||
/**
|
||||
* @brief 程序執行狀態
|
||||
*/
|
||||
enum class ProcedureStatus
|
||||
{
|
||||
Idle, // 空閒
|
||||
Loaded, // 已載入
|
||||
Running, // 運行中
|
||||
Paused, // 已暫停
|
||||
Stopped, // 已停止
|
||||
Completed, // 已完成
|
||||
Error // 錯誤
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 執行上下文
|
||||
*/
|
||||
struct ExecutionContext
|
||||
{
|
||||
int currentActivityIndex = -1;
|
||||
int currentStageIndex = -1;
|
||||
int currentActionIndex = -1;
|
||||
int loopIteration = 0;
|
||||
QDateTime startTime;
|
||||
QDateTime endTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 程序執行引擎
|
||||
*
|
||||
* 負責程序的載入、執行、暫停、恢復和停止。
|
||||
* 管理執行上下文、活動序列和表格數據。
|
||||
*/
|
||||
class ProcedureEngine : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static ProcedureEngine *instance();
|
||||
|
||||
// 配置載入
|
||||
bool loadProcedure(const QString &configPath);
|
||||
|
||||
// 程序控制
|
||||
void startProcedure();
|
||||
void pauseProcedure();
|
||||
void resumeProcedure();
|
||||
void stopProcedure();
|
||||
void resetProcedure();
|
||||
|
||||
// 活動導航
|
||||
bool moveToNextActivity();
|
||||
bool moveToPreviousActivity();
|
||||
bool jumpToActivity(int index);
|
||||
|
||||
// 狀態查詢
|
||||
ProcedureStatus status() const;
|
||||
ProcedureConfig config() const;
|
||||
ExecutionContext executionContext() const;
|
||||
|
||||
// 獲取當前執行項
|
||||
ActivityStep getCurrentActivity() const;
|
||||
TestTaskGroup getCurrentTaskGroup() const;
|
||||
TestActivityGroup getCurrentStage() const;
|
||||
TestAction getCurrentAction() const;
|
||||
|
||||
// 進度
|
||||
int getActivityCount() const;
|
||||
int getCurrentActivityIndex() const;
|
||||
double getProgress() const;
|
||||
|
||||
// 表格數據管理
|
||||
QVariant getTableCellValue(const QString &tableRef, int row, int column) const;
|
||||
void setTableCellValue(const QString &tableRef, int row, int column, const QVariant &value);
|
||||
QVector<QVector<QVariant>> getTableData(const QString &tableRef) const;
|
||||
|
||||
public slots:
|
||||
void onActionCompleted(const QString &actionId, const QVariantMap &results);
|
||||
void onActionFailed(const QString &actionId, const QString &error);
|
||||
|
||||
signals:
|
||||
// 程序狀態信號
|
||||
void procedureLoaded(const QString &name);
|
||||
void procedureStarted();
|
||||
void procedurePaused();
|
||||
void procedureResumed();
|
||||
void procedureStopped();
|
||||
void procedureCompleted();
|
||||
void statusChanged(ProcedureStatus status);
|
||||
void errorOccurred(const QString &error);
|
||||
|
||||
// 活動信號
|
||||
void activityStarted(int index, const ActivityStep &step);
|
||||
void taskGroupStarted(const QString &ref, const QString &name);
|
||||
void taskGroupCompleted(const QString &ref);
|
||||
void stageStarted(int index, const QString &name);
|
||||
void stageCompleted(int index);
|
||||
void actionStarted(int index, const QString &actionId);
|
||||
void actionCompleted(int index, const QString &actionId, const QVariantMap &results);
|
||||
void actionFailed(int index, const QString &actionId, const QString &error);
|
||||
|
||||
// 執行請求
|
||||
void executeActionRequested(const TestAction &action);
|
||||
void resultDisplayRequested(const QString &displayRef, const ResultDisplay &display);
|
||||
|
||||
// 表格信號
|
||||
void tableInitialized(const QString &tableRef, const TableDefinition &definition);
|
||||
void tableDataChanged(const QString &tableRef, int row, int column, const QVariant &value);
|
||||
|
||||
private:
|
||||
explicit ProcedureEngine(QObject *parent = nullptr);
|
||||
~ProcedureEngine();
|
||||
|
||||
// 執行控制
|
||||
void resetExecutionContext();
|
||||
void setStatus(ProcedureStatus status);
|
||||
|
||||
// 活動執行
|
||||
void moveToFirstActivity();
|
||||
void enterCurrentActivity();
|
||||
void startTaskGroupExecution(const QString &taskGroupRef);
|
||||
void enterCurrentStage(const QString &taskGroupRef);
|
||||
void moveToNextStage(const QString &taskGroupRef);
|
||||
void completeTaskGroup(const QString &taskGroupRef);
|
||||
|
||||
// 動作執行
|
||||
void executeCurrentAction();
|
||||
void moveToNextAction();
|
||||
void processActionResults(const QString &actionId, const QVariantMap &results);
|
||||
|
||||
// 結果顯示
|
||||
void displayResult(const QString &displayRef);
|
||||
void completeProcedure();
|
||||
|
||||
// 表格管理
|
||||
void initializeTable(const QString &tableRef);
|
||||
|
||||
// 條件評估
|
||||
bool evaluateCondition(const QString &condition);
|
||||
|
||||
private slots:
|
||||
void onExecutionTimeout();
|
||||
|
||||
private:
|
||||
static ProcedureEngine *s_instance;
|
||||
|
||||
ProcedureParser *m_parser;
|
||||
ProcedureStatus m_status;
|
||||
ProcedureConfig m_config;
|
||||
ExecutionContext m_context;
|
||||
QString m_configPath;
|
||||
|
||||
QTimer *m_executionTimer;
|
||||
QMap<QString, QVector<QVector<QVariant>>> m_tableData;
|
||||
};
|
||||
|
||||
#endif // PROCEDUREENGINE_H
|
||||
Reference in New Issue
Block a user