Refactored the implementation of the Workflow_Editor class: now uses shared_ptr and vector for automatic lifecycle management && decoupled nodes and interfaces with abstract base class implementation && implemented an independent unique ID generator && implemented test nodes and interfaces && implemented automatic connection drawing.
This commit is contained in:
@@ -5,15 +5,15 @@
|
||||
#include "imgui_impl_win32.h"
|
||||
#include "imgui_impl_dx11.h"
|
||||
|
||||
#include "Workflow_Editor.hpp"
|
||||
#include "Type_Descriptions.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "windows.h"
|
||||
#include "d3d11.h"
|
||||
}
|
||||
|
||||
#include "Type_Descriptions.hpp"
|
||||
#include "Workflow-Editor.hpp"
|
||||
|
||||
// 主窗体句柄
|
||||
extern HWND Main_Window_hWnd;
|
||||
|
||||
@@ -31,6 +31,6 @@ extern Input_File_Node *input_dlt_file_list_head;
|
||||
extern size_t input_dlt_file_count;
|
||||
|
||||
// 节点编辑器
|
||||
extern Workflow_Editor_Class Workflow_Editor;
|
||||
extern class Workflow_Editor Workflow_Editor;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef __ID_GENERATOR__
|
||||
#define __ID_GENERATOR__
|
||||
|
||||
#include <vector>
|
||||
|
||||
// 唯一ID生成器
|
||||
class Independent_ID_Generator
|
||||
{
|
||||
protected:
|
||||
// 连续ID串
|
||||
typedef struct
|
||||
{
|
||||
int begin;
|
||||
int end;
|
||||
} Continuous_ID_Section;
|
||||
std::vector<Continuous_ID_Section> continuous_id_list;
|
||||
|
||||
public:
|
||||
// 获取ID
|
||||
int Request_ID(void);
|
||||
// 释放ID true-> success / false -> fail
|
||||
bool Release_ID(const int ID);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,214 @@
|
||||
#ifndef __NODES_AND_CONNECTORS__
|
||||
#define __NODES_AND_CONNECTORS__
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "imgui.h"
|
||||
#include "imnodes.h"
|
||||
#include "ID_Generator.hpp"
|
||||
|
||||
// =====================================接口抽象======================================================
|
||||
|
||||
class Abs_Connector // 抽象接口类
|
||||
{
|
||||
protected:
|
||||
typedef enum
|
||||
{
|
||||
CONNECTOR_TYPE_UNKNOWN, // 未知连接点类型
|
||||
CONNECTOR_TYPE_OUTPUT, // 输出
|
||||
CONNECTOR_TYPE_INPUT, // 输入
|
||||
} Connector_Type_Enum; // 接口类型枚举
|
||||
|
||||
// ID 分配器
|
||||
Independent_ID_Generator *ID_Generator;
|
||||
|
||||
int id; // ID
|
||||
Connector_Type_Enum type; // 类型标识
|
||||
const char *socket_str; // 套接字字符串
|
||||
|
||||
Abs_Connector *provider; // 提供者
|
||||
std::vector<Abs_Connector *> receiver_list; // 接收方
|
||||
void *product; // 产物
|
||||
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
Abs_Connector() = delete;
|
||||
|
||||
// 必要构造
|
||||
Abs_Connector(Independent_ID_Generator *ID_Generator, Connector_Type_Enum type, const char *socket_str);
|
||||
|
||||
// 析构
|
||||
~Abs_Connector();
|
||||
|
||||
// 连接到目标连接点
|
||||
virtual bool Connect_To(Abs_Connector *target);
|
||||
|
||||
// 断开连接
|
||||
virtual void Disconnect(void);
|
||||
|
||||
// 注册产物
|
||||
virtual bool Register_Product(void *product, size_t size);
|
||||
|
||||
// 获取上级节点
|
||||
virtual Abs_Connector *Get_Provider(void);
|
||||
|
||||
// 获取产物
|
||||
virtual void *Get_Product(void);
|
||||
|
||||
// 获取ID
|
||||
virtual int Get_ID(void);
|
||||
|
||||
// 绘制连接点
|
||||
virtual void Show(void) = 0;
|
||||
};
|
||||
|
||||
// =====================================节点抽象======================================================
|
||||
|
||||
class Abs_Node // 抽象节点类
|
||||
{
|
||||
protected:
|
||||
typedef enum
|
||||
{
|
||||
NODE_TYPE_UNKNOWN, // 未知节点类型
|
||||
NODE_TYPE_MSG_LINE_INPUT, // 消息输入节点
|
||||
NODE_TYPE_CSV_EXPORTER, // CSV输出节点
|
||||
} Node_Type_Enum; // 节点类型枚举
|
||||
|
||||
// ID 分配器
|
||||
Independent_ID_Generator *Node_ID_Generator; // 节点ID生成器
|
||||
Independent_ID_Generator *Connector_ID_Generator; // 连接点ID生成器
|
||||
|
||||
int id; // ID
|
||||
Node_Type_Enum type; // 类型
|
||||
ImVec2 initial_position; // 初始位置
|
||||
|
||||
bool close_flag; // 关闭标志位
|
||||
|
||||
// 接口列表
|
||||
std::vector<std::shared_ptr<Abs_Connector>> Connector_List;
|
||||
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
Abs_Node() = delete;
|
||||
|
||||
// 必要构造
|
||||
Abs_Node(Independent_ID_Generator *Node_ID_Generator,
|
||||
Independent_ID_Generator *Connector_ID_Generator,
|
||||
Node_Type_Enum type,
|
||||
ImVec2 initial_position = ImVec2(0, 0));
|
||||
|
||||
// 析构
|
||||
~Abs_Node();
|
||||
|
||||
// 绘制节点
|
||||
virtual void Show(void) = 0;
|
||||
|
||||
// 执行处理流程
|
||||
virtual bool Execute_Process(void) = 0;
|
||||
|
||||
// 获取关闭信号
|
||||
virtual bool Get_CloseFlag(void);
|
||||
|
||||
// 获取接口列表
|
||||
std::vector<std::shared_ptr<Abs_Connector>> &Get_Connector_List(void);
|
||||
};
|
||||
|
||||
// ====================================接口类声明================================================
|
||||
|
||||
// DLT信息输出接口
|
||||
class MSG_OutPut_Connector : public Abs_Connector
|
||||
{
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
MSG_OutPut_Connector() = delete;
|
||||
|
||||
// 必要构造
|
||||
explicit MSG_OutPut_Connector(Independent_ID_Generator *ID_Generator);
|
||||
|
||||
// 绘制接口
|
||||
virtual void Show(void);
|
||||
};
|
||||
|
||||
// DLT信息输入接口
|
||||
class MSG_InPut_Connector : public Abs_Connector
|
||||
{
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
MSG_InPut_Connector() = delete;
|
||||
|
||||
// 必要构造
|
||||
explicit MSG_InPut_Connector(Independent_ID_Generator *ID_Generator);
|
||||
|
||||
// 绘制接口
|
||||
virtual void Show(void);
|
||||
};
|
||||
|
||||
// CSV 列输入接口
|
||||
class CSV_Column_Input_Connector : public Abs_Connector
|
||||
{
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
CSV_Column_Input_Connector() = delete;
|
||||
|
||||
// 必要构造
|
||||
explicit CSV_Column_Input_Connector(Independent_ID_Generator *ID_Generator);
|
||||
|
||||
// 绘制接口
|
||||
virtual void Show(void);
|
||||
};
|
||||
|
||||
// CSV 列输出接口
|
||||
class CSV_Column_Output_Connector : public Abs_Connector
|
||||
{
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
CSV_Column_Output_Connector() = delete;
|
||||
|
||||
// 必要构造
|
||||
explicit CSV_Column_Output_Connector(Independent_ID_Generator *ID_Generator);
|
||||
|
||||
// 绘制接口
|
||||
virtual void Show(void);
|
||||
};
|
||||
|
||||
// ====================================节点类声明================================================
|
||||
|
||||
// 接口测试节点
|
||||
class Connector_Test_Node : public Abs_Node
|
||||
{
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
Connector_Test_Node() = delete;
|
||||
|
||||
// 必要构造
|
||||
Connector_Test_Node(Independent_ID_Generator *Node_ID_Generator,
|
||||
Independent_ID_Generator *Connector_ID_Generator,
|
||||
ImVec2 initial_position = ImVec2(0, 0));
|
||||
|
||||
// 绘制节点
|
||||
virtual void Show(void);
|
||||
|
||||
// 执行处理流程
|
||||
virtual bool Execute_Process(void);
|
||||
};
|
||||
|
||||
// DLT信息输入类,起始点
|
||||
class MSG_Input_Node : public Abs_Node
|
||||
{
|
||||
public:
|
||||
// 显式禁用默认构造
|
||||
MSG_Input_Node() = delete;
|
||||
|
||||
// 必要构造
|
||||
MSG_Input_Node(Independent_ID_Generator *Node_ID_Generator,
|
||||
Independent_ID_Generator *Connector_ID_Generator,
|
||||
ImVec2 initial_position = ImVec2(0, 0));
|
||||
|
||||
// 绘制节点
|
||||
virtual void Show(void);
|
||||
|
||||
// 执行处理流程
|
||||
virtual bool Execute_Process(void);
|
||||
};
|
||||
|
||||
#endif
|
||||
+44
-75
@@ -1,89 +1,58 @@
|
||||
#ifndef __WORKFLOW_EDITOR_HPP__
|
||||
#define __WORKFLOW_EDITOR_HPP__
|
||||
|
||||
#include "imgui.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "stdint.h"
|
||||
}
|
||||
|
||||
#include <vector>
|
||||
|
||||
// // 并行工作链
|
||||
// class Parallel_Working_List
|
||||
// {
|
||||
// private:
|
||||
// // 节点计数
|
||||
// size_t node_count;
|
||||
|
||||
// // 内部迭代器
|
||||
// class iterator
|
||||
// {
|
||||
// };
|
||||
|
||||
// public:
|
||||
// iterator begin() { return iterator(arr); }
|
||||
// iterator end() { return iterator(arr + SIZE); }
|
||||
// };
|
||||
|
||||
// 节点类型枚举
|
||||
typedef enum
|
||||
{
|
||||
NODE_TYPE_MSG_LINE_INPUT, // 消息输入节点
|
||||
NODE_TYPE_CSV_EXPORTER, // CSV输出节点
|
||||
} NodeType;
|
||||
|
||||
// 节点基类
|
||||
class Node_Class
|
||||
{
|
||||
protected:
|
||||
int id; // 节点ID
|
||||
bool initial_state; // 初始状态
|
||||
ImVec2 initial_position; // 初始位置
|
||||
|
||||
public:
|
||||
// 初始化列表构造
|
||||
explicit Node_Class(int id, ImVec2 initial_position = ImVec2(0, 0)) : id(id), initial_state(true), initial_position(initial_position) {}
|
||||
int getID() { return this->id; }
|
||||
|
||||
/**
|
||||
* 显示节点并获取状态(子类必须实现)
|
||||
* @param null
|
||||
* @return 0 -> normal : 1-> close
|
||||
*/
|
||||
virtual bool show_and_get_state(void) = 0;
|
||||
|
||||
virtual ~Node_Class() = default; // 抽象基类必须有虚析构函数
|
||||
};
|
||||
|
||||
// 消息输出节点
|
||||
class MsgLine_Input_Node_Class : public Node_Class
|
||||
{
|
||||
public:
|
||||
explicit MsgLine_Input_Node_Class(int id, ImVec2 initial_position = ImVec2(0, 0)) : Node_Class(id, initial_position) {};
|
||||
bool show_and_get_state(void) override;
|
||||
};
|
||||
#include <memory>
|
||||
#include "imgui.h"
|
||||
#include "imnodes.h"
|
||||
#include "ID_Generator.hpp"
|
||||
#include "Nodes_And_Connectors.hpp"
|
||||
|
||||
// 节点编辑器类
|
||||
class Workflow_Editor_Class
|
||||
class Workflow_Editor
|
||||
{
|
||||
protected:
|
||||
// 节点列表
|
||||
std::vector<Node_Class *> Node_List;
|
||||
typedef enum
|
||||
{
|
||||
NODE_TYPE_UNKNOWN, // 未知节点类型
|
||||
NODE_TYPE_MSG_LINE_INPUT, // 消息输入节点
|
||||
NODE_TYPE_CSV_EXPORTER, // CSV输出节点
|
||||
} Node_Type_Enum; // 节点类型枚举
|
||||
|
||||
// ID 分配器
|
||||
Independent_ID_Generator Connector_ID_Generator; // 连接点ID生成器
|
||||
Independent_ID_Generator Node_ID_Generator; // 节点ID生成器
|
||||
Independent_ID_Generator Edge_ID_Generator; // 边ID生成器
|
||||
|
||||
// 边定义
|
||||
typedef struct
|
||||
{
|
||||
int id = -1; // 边ID
|
||||
int source_connector_id = -1; // 源连接点
|
||||
int target_connector_id = -1; // 目标连接点
|
||||
} Edge;
|
||||
|
||||
// 数据池
|
||||
std::vector<std::shared_ptr<Abs_Connector>> Connector_Pool; // 连接点池
|
||||
std::vector<std::shared_ptr<Abs_Node>> Node_Pool; // 节点池
|
||||
std::vector<Edge> Edge_Pool; // 边池
|
||||
|
||||
/**
|
||||
* 顶层索引为启示工作流节点(N个元素即N个处理流程)
|
||||
* 次级索引为工作流分层
|
||||
* 三级索引为平级工作流节点
|
||||
* 不参与工作流节点仅存于散点列表
|
||||
*/
|
||||
std::vector<std::vector<std::vector<std::shared_ptr<Abs_Node>>>> Process_Route; // 工作层级路由
|
||||
std::vector<std::shared_ptr<Abs_Node>> Separate_Node_List; // 散点列表
|
||||
|
||||
// =====================================函数声明=================================================
|
||||
// 新增节点 true -> success / false -> failed
|
||||
bool Add_Node(Node_Type_Enum type, ImVec2 initial_position = ImVec2(0, 0));
|
||||
|
||||
public:
|
||||
// 构造函数
|
||||
Workflow_Editor_Class();
|
||||
|
||||
// 析构函数
|
||||
~Workflow_Editor_Class();
|
||||
|
||||
// 显示工作流节点编辑器
|
||||
// 绘制节点编辑器
|
||||
void Show(void);
|
||||
|
||||
// 新增节点
|
||||
void Add_Node(NodeType type, ImVec2 initial_position = ImVec2(0, 0));
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user