Expose some enum types within the public class namespace to remove redundant external definitions && Add node connection loop detection and provide a warning for it.
This commit is contained in:
parent
975495b2b7
commit
7aa8c6750d
@ -11,7 +11,7 @@
|
||||
|
||||
class Abs_Connector // 抽象接口类
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
typedef enum
|
||||
{
|
||||
CONNECTOR_TYPE_UNKNOWN, // 未知连接点类型
|
||||
@ -19,6 +19,7 @@ protected:
|
||||
CONNECTOR_TYPE_INPUT, // 输入
|
||||
} Connector_Type_Enum; // 接口类型枚举
|
||||
|
||||
protected:
|
||||
// ID 分配器
|
||||
Independent_ID_Generator *ID_Generator;
|
||||
|
||||
@ -60,6 +61,9 @@ public:
|
||||
// 获取ID
|
||||
virtual int Get_ID(void);
|
||||
|
||||
// 获取接口类型
|
||||
virtual Connector_Type_Enum Get_Type(void);
|
||||
|
||||
// 绘制连接点
|
||||
virtual void Show(void) = 0;
|
||||
};
|
||||
@ -68,7 +72,7 @@ public:
|
||||
|
||||
class Abs_Node // 抽象节点类
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
typedef enum
|
||||
{
|
||||
NODE_TYPE_UNKNOWN, // 未知节点类型
|
||||
@ -77,6 +81,7 @@ protected:
|
||||
NODE_TYPE_CSV_EXPORTER, // CSV输出节点
|
||||
} Node_Type_Enum; // 节点类型枚举
|
||||
|
||||
protected:
|
||||
// ID 分配器
|
||||
Independent_ID_Generator *Node_ID_Generator; // 节点ID生成器
|
||||
Independent_ID_Generator *Connector_ID_Generator; // 连接点ID生成器
|
||||
@ -112,6 +117,9 @@ public:
|
||||
// 获取ID
|
||||
virtual int Get_ID(void);
|
||||
|
||||
// 获取节点类型
|
||||
virtual Node_Type_Enum Get_Type(void);
|
||||
|
||||
// 获取关闭信号
|
||||
virtual bool Get_CloseFlag(void);
|
||||
|
||||
|
||||
@ -12,14 +12,6 @@
|
||||
class Workflow_Editor
|
||||
{
|
||||
protected:
|
||||
typedef enum
|
||||
{
|
||||
NODE_TYPE_UNKNOWN, // 未知节点类型
|
||||
NODE_TYPE_CONNECTOR_TEST, // 接口测试节点
|
||||
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生成器
|
||||
@ -58,7 +50,7 @@ public:
|
||||
void Show(void);
|
||||
|
||||
// 新增节点 true -> success / false -> failed
|
||||
bool Add_Node(Node_Type_Enum type, ImVec2 initial_position = ImVec2(0, 0));
|
||||
bool Add_Node(Abs_Node::Node_Type_Enum type, ImVec2 initial_position = ImVec2(0, 0));
|
||||
|
||||
// 删除节点 true -> success / false -> failed
|
||||
bool Del_Node(int target_node_id);
|
||||
@ -69,6 +61,12 @@ public:
|
||||
// 删除连接 true -> success / false -> failed
|
||||
bool Del_Link(int source_connector_id, int target_connector_id);
|
||||
|
||||
// 创建工作路由 true -> success / false -> failed
|
||||
bool Build_Process_Route(void);
|
||||
|
||||
// 清除工作路由 true -> success / false -> failed
|
||||
bool Clear_Process_Route(void);
|
||||
|
||||
// 读取配置文件
|
||||
bool Read_Config(const char *file_path);
|
||||
|
||||
|
||||
@ -198,6 +198,12 @@ int Abs_Connector::Get_ID(void)
|
||||
return this->id;
|
||||
}
|
||||
|
||||
// 获取接口类型
|
||||
Abs_Connector::Connector_Type_Enum Abs_Connector::Get_Type(void)
|
||||
{
|
||||
return this->type;
|
||||
}
|
||||
|
||||
// =================================================================================================
|
||||
|
||||
// 必要构造
|
||||
@ -237,6 +243,12 @@ int Abs_Node::Get_ID(void)
|
||||
return this->id;
|
||||
}
|
||||
|
||||
// 获取节点类型
|
||||
Abs_Node::Node_Type_Enum Abs_Node::Get_Type(void)
|
||||
{
|
||||
return this->type;
|
||||
}
|
||||
|
||||
// 获取关闭信号
|
||||
bool Abs_Node::Get_CloseFlag(void)
|
||||
{
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
#include "Workflow_Editor.hpp"
|
||||
#include "imgui_internal.h"
|
||||
#include "Global_Variables.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "windows.h"
|
||||
}
|
||||
|
||||
// 绘制节点编辑器
|
||||
void Workflow_Editor::Show(void)
|
||||
@ -44,9 +50,9 @@ void Workflow_Editor::Show(void)
|
||||
if (ImGui::BeginMenu(u8"创建节点"))
|
||||
{
|
||||
if (ImGui::MenuItem(u8"接口测试节点"))
|
||||
this->Add_Node(NODE_TYPE_CONNECTOR_TEST, click_pos);
|
||||
this->Add_Node(Abs_Node::NODE_TYPE_CONNECTOR_TEST, click_pos);
|
||||
if (ImGui::MenuItem(u8"DLT信息输入节点"))
|
||||
this->Add_Node(NODE_TYPE_MSG_LINE_INPUT, click_pos);
|
||||
this->Add_Node(Abs_Node::NODE_TYPE_MSG_LINE_INPUT, click_pos);
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
@ -115,7 +121,7 @@ void Workflow_Editor::Show(void)
|
||||
}
|
||||
|
||||
// 新增节点 true -> success / false -> failed
|
||||
bool Workflow_Editor::Add_Node(Node_Type_Enum type, ImVec2 initial_position)
|
||||
bool Workflow_Editor::Add_Node(Abs_Node::Node_Type_Enum type, ImVec2 initial_position)
|
||||
{
|
||||
// 新节点
|
||||
std::shared_ptr<Abs_Node> p_New_Node;
|
||||
@ -124,12 +130,12 @@ bool Workflow_Editor::Add_Node(Node_Type_Enum type, ImVec2 initial_position)
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case NODE_TYPE_CONNECTOR_TEST: // 接口测试节点
|
||||
case Abs_Node::NODE_TYPE_CONNECTOR_TEST: // 接口测试节点
|
||||
p_New_Node = std::make_shared<Connector_Test_Node>(&this->Node_ID_Generator,
|
||||
&this->Connector_ID_Generator,
|
||||
initial_position);
|
||||
break;
|
||||
case NODE_TYPE_MSG_LINE_INPUT: // 消息行输入 (头节点)
|
||||
case Abs_Node::NODE_TYPE_MSG_LINE_INPUT: // 消息行输入 (头节点)
|
||||
|
||||
// 创建节点
|
||||
p_New_Node = std::make_shared<MSG_Input_Node>(&this->Node_ID_Generator,
|
||||
@ -137,7 +143,7 @@ bool Workflow_Editor::Add_Node(Node_Type_Enum type, ImVec2 initial_position)
|
||||
initial_position);
|
||||
break;
|
||||
|
||||
case NODE_TYPE_CSV_EXPORTER: // CSV输出器
|
||||
case Abs_Node::NODE_TYPE_CSV_EXPORTER: // CSV输出器
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -264,6 +270,76 @@ bool Workflow_Editor::Add_Link(int source_connector_id, int target_connector_id)
|
||||
// 判定查找结果
|
||||
if (find)
|
||||
{
|
||||
// 检查下一步的连接是否会出现回环
|
||||
{
|
||||
// 工具Lambda表达式,查找接口id的所属节点
|
||||
auto Lambda_Find_Owner = [&](int connector_id) -> Abs_Node *
|
||||
{
|
||||
for (auto pNode : this->Node_Pool)
|
||||
{
|
||||
for (auto pConnector : pNode->Get_Connector_List())
|
||||
{
|
||||
if (pConnector->Get_ID() == connector_id)
|
||||
return pNode.get();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
// 关联关系查找(递归Lambda)
|
||||
auto Lambda_Find_Related = [&](auto self, Abs_Node *pSource, Abs_Node *pTarget) -> bool
|
||||
{
|
||||
std::vector<Abs_Node *> Sub_Node_List;
|
||||
for (auto pConnector : pSource->Get_Connector_List())
|
||||
{
|
||||
// 检索所有OutPut类型的接口的下位节点
|
||||
if (pConnector->Get_Type() == Abs_Connector::CONNECTOR_TYPE_OUTPUT)
|
||||
{
|
||||
for (auto pSubConnector : pConnector->Get_Related_List())
|
||||
{
|
||||
auto pSubNode = Lambda_Find_Owner(pSubConnector->Get_ID());
|
||||
bool duplicated = false;
|
||||
|
||||
// 查重并加入子节点列表
|
||||
for (auto pNode : Sub_Node_List)
|
||||
{
|
||||
if (pNode == pSubNode)
|
||||
{
|
||||
duplicated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!duplicated)
|
||||
Sub_Node_List.push_back(pSubNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 递归出口 无子节点时直接返回
|
||||
if (Sub_Node_List.size() == 0)
|
||||
return false;
|
||||
|
||||
// 检索所有的下位节点
|
||||
for (auto pNode : Sub_Node_List)
|
||||
{
|
||||
if (pNode == pTarget)
|
||||
return true;
|
||||
else if (self(self, pNode, pTarget) == true)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
// 检查连接关系
|
||||
if (Lambda_Find_Related(Lambda_Find_Related, Lambda_Find_Owner(target_connector_id), Lambda_Find_Owner(source_connector_id)))
|
||||
{
|
||||
MessageBoxW(Main_Window_hWnd, L"存在回环连线!!!", L"", MB_OK | MB_ICONERROR);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 先尝试连接,成功后再进行边池操作
|
||||
if (p_source_connector->Connect_To(p_target_connector.get()) == true)
|
||||
{
|
||||
@ -339,3 +415,25 @@ bool Workflow_Editor::Del_Link(int source_connector_id, int target_connector_id)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 创建工作路由 true -> success / false -> failed
|
||||
bool Workflow_Editor::Build_Process_Route(void)
|
||||
{
|
||||
// 找出所有的头节点
|
||||
std::vector<std::shared_ptr<Abs_Node>> Head_List;
|
||||
for (auto pNode : this->Node_Pool)
|
||||
{
|
||||
if (pNode->Get_Type() == Abs_Node::NODE_TYPE_MSG_LINE_INPUT)
|
||||
Head_List.push_back(pNode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// 清除工作路由 true -> success / false -> failed
|
||||
bool Workflow_Editor::Clear_Process_Route(void)
|
||||
{
|
||||
decltype(this->Process_Route) empty_route;
|
||||
this->Process_Route.swap(empty_route);
|
||||
return true;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user