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:
2026-04-02 11:16:37 +08:00
parent 975495b2b7
commit 7aa8c6750d
4 changed files with 133 additions and 17 deletions
+12
View File
@@ -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)
{
+104 -6
View File
@@ -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;
}