From 80a18b6a792ca9c92fe215163dd1426a03e31631 Mon Sep 17 00:00:00 2001 From: LuChiChick <1084116302@qq.com> Date: Tue, 19 May 2026 20:18:50 +0800 Subject: [PATCH] Implemented Show() method for the connector base class; all inheriting connectors no longer need to maintain their own separate Show() methods. && Assigned distinct drawing colors for exclusive input type connectors and their associated connections. && Improved the workflow packet passing execution process among existing connectors. && Removed some redundant code. --- Inc/Nodes_And_Connectors.hpp | 58 +++++--------- Inc/Workflow_Editor.hpp | 5 ++ Src/Nodes_And_Connectors.cpp | 142 +++++++++++++---------------------- Src/Workflow_Editor.cpp | 26 ++++++- 4 files changed, 101 insertions(+), 130 deletions(-) diff --git a/Inc/Nodes_And_Connectors.hpp b/Inc/Nodes_And_Connectors.hpp index 59cc025..72e454a 100644 --- a/Inc/Nodes_And_Connectors.hpp +++ b/Inc/Nodes_And_Connectors.hpp @@ -84,8 +84,8 @@ public: // 获取套接字字符串 virtual const char *Get_Socket_Str(void); - // 绘制连接点 - virtual void Show(void) = 0; + // 默认风格连接点绘制 + virtual void Show(void); }; // =====================================节点抽象====================================================== @@ -156,20 +156,6 @@ public: // ====================================接口类声明================================================ -// Boolean 状态输出接口 -class Boolean_OutPut_Connector : public Abs_Connector -{ -public: - // 显式禁用默认构造 - Boolean_OutPut_Connector() = delete; - - // 必要构造 - explicit Boolean_OutPut_Connector(Independent_ID_Generator *ID_Generator); - - // 绘制接口 - virtual void Show(void); -}; - // Boolean 状态输入接口 class Boolean_InPut_Connector : public Abs_Connector { @@ -178,24 +164,18 @@ public: Boolean_InPut_Connector() = delete; // 必要构造 - explicit Boolean_InPut_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag = false); - - // 绘制接口 - virtual void Show(void); + explicit Boolean_InPut_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag = false) : Abs_Connector(ID_Generator, exclusive_flag ? CONNECTOR_TYPE_INPUT_EXCLUSIVE : CONNECTOR_TYPE_INPUT, "Boolean") {} }; -// DLT信息输出接口 -class MSG_OutPut_Connector : public Abs_Connector +// Boolean 状态输出接口 +class Boolean_OutPut_Connector : public Abs_Connector { public: // 显式禁用默认构造 - MSG_OutPut_Connector() = delete; + Boolean_OutPut_Connector() = delete; // 必要构造 - explicit MSG_OutPut_Connector(Independent_ID_Generator *ID_Generator); - - // 绘制接口 - virtual void Show(void); + explicit Boolean_OutPut_Connector(Independent_ID_Generator *ID_Generator) : Abs_Connector(ID_Generator, CONNECTOR_TYPE_OUTPUT, "Boolean") {} }; // DLT信息输入接口 @@ -206,10 +186,18 @@ public: MSG_InPut_Connector() = delete; // 必要构造 - explicit MSG_InPut_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag = false); + explicit MSG_InPut_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag = false) : Abs_Connector(ID_Generator, exclusive_flag ? CONNECTOR_TYPE_INPUT_EXCLUSIVE : CONNECTOR_TYPE_INPUT, "DLT MSG") {} +}; - // 绘制接口 - virtual void Show(void); +// DLT信息输出接口 +class MSG_OutPut_Connector : public Abs_Connector +{ +public: + // 显式禁用默认构造 + MSG_OutPut_Connector() = delete; + + // 必要构造 + explicit MSG_OutPut_Connector(Independent_ID_Generator *ID_Generator) : Abs_Connector(ID_Generator, CONNECTOR_TYPE_OUTPUT, "DLT MSG") {} }; // CSV 列输入接口 @@ -220,10 +208,7 @@ public: CSV_Column_Input_Connector() = delete; // 必要构造 - explicit CSV_Column_Input_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag = false); - - // 绘制接口 - virtual void Show(void); + explicit CSV_Column_Input_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag = false) : Abs_Connector(ID_Generator, exclusive_flag ? CONNECTOR_TYPE_INPUT_EXCLUSIVE : CONNECTOR_TYPE_INPUT, "CSV Column") {} }; // CSV 列输出接口 @@ -234,10 +219,7 @@ public: CSV_Column_Output_Connector() = delete; // 必要构造 - explicit CSV_Column_Output_Connector(Independent_ID_Generator *ID_Generator); - - // 绘制接口 - virtual void Show(void); + explicit CSV_Column_Output_Connector(Independent_ID_Generator *ID_Generator) : Abs_Connector(ID_Generator, CONNECTOR_TYPE_OUTPUT, "CSV Column") {} }; // ====================================节点类声明================================================ diff --git a/Inc/Workflow_Editor.hpp b/Inc/Workflow_Editor.hpp index 32a0b77..e8d1b63 100644 --- a/Inc/Workflow_Editor.hpp +++ b/Inc/Workflow_Editor.hpp @@ -24,6 +24,11 @@ protected: int id = -1; // 边ID int source_connector_id = -1; // 源连接点 int target_connector_id = -1; // 目标连接点 + enum Edge_Type_Enum + { + EDGE_TYPE_NORMAL, // 普通边 + EDGE_TYPE_EXCLUSIVE, // 独占边 + } type = EDGE_TYPE_NORMAL; } Edge; // 数据池 diff --git a/Src/Nodes_And_Connectors.cpp b/Src/Nodes_And_Connectors.cpp index bc5bc21..b140360 100644 --- a/Src/Nodes_And_Connectors.cpp +++ b/Src/Nodes_And_Connectors.cpp @@ -230,6 +230,45 @@ const char *Abs_Connector::Get_Socket_Str(void) { return this->socket_str; } + +// 默认风格连接点绘制 +void Abs_Connector::Show(void) +{ + switch (this->type) + { + case CONNECTOR_TYPE_OUTPUT: // 常规输出接口 + + ImNodes::BeginOutputAttribute(this->id, ImNodesPinShape_CircleFilled); + ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); // 填充高度为字符高度 + ImNodes::EndOutputAttribute(); + break; + + case CONNECTOR_TYPE_INPUT: // 常规输入接口 + + ImNodes::BeginInputAttribute(this->id, ImNodesPinShape_CircleFilled); + ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); // 填充高度为字符高度 + ImNodes::EndInputAttribute(); + break; + + case CONNECTOR_TYPE_INPUT_EXCLUSIVE: // 独占输入接口 + + ImNodes::PushColorStyle(ImNodesCol_Pin, IM_COL32(50, 120, 160, 160)); // 常规配色 + ImNodes::PushColorStyle(ImNodesCol_PinHovered, IM_COL32(0, 110, 175, 255)); // Hover 配色 + + ImNodes::BeginInputAttribute(this->id, ImNodesPinShape_CircleFilled); + ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); // 填充高度为字符高度 + ImNodes::EndInputAttribute(); + + ImNodes::PopColorStyle(); + ImNodes::PopColorStyle(); + break; + + default: + + break; + } +} + // ================================================================================================= // 必要构造 @@ -301,86 +340,6 @@ std::vector> &Abs_Node::Get_Connector_List(void) // ================================================================================================= -// 必要构造 -Boolean_InPut_Connector::Boolean_InPut_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag) : Abs_Connector(ID_Generator, exclusive_flag ? CONNECTOR_TYPE_INPUT_EXCLUSIVE : CONNECTOR_TYPE_INPUT, "Boolean") {} - -// 绘制接口 -void Boolean_InPut_Connector::Show(void) -{ - // 输出接口点 - ImNodes::BeginInputAttribute(this->id, ImNodesPinShape_CircleFilled); - // 填充占位 - ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); - ImNodes::EndInputAttribute(); -} - -// 必要构造 -Boolean_OutPut_Connector::Boolean_OutPut_Connector(Independent_ID_Generator *ID_Generator) : Abs_Connector(ID_Generator, CONNECTOR_TYPE_OUTPUT, "Boolean") {} - -// 绘制接口 -void Boolean_OutPut_Connector::Show(void) -{ - // 输出接口点 - ImNodes::BeginOutputAttribute(this->id, ImNodesPinShape_CircleFilled); - // 填充占位 - ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); - ImNodes::EndOutputAttribute(); -} - -// 必要构造 -MSG_InPut_Connector::MSG_InPut_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag) : Abs_Connector(ID_Generator, exclusive_flag ? CONNECTOR_TYPE_INPUT_EXCLUSIVE : CONNECTOR_TYPE_INPUT, "DLT MSG") {} - -// 绘制接口 -void MSG_InPut_Connector::Show(void) -{ - // 输出接口点 - ImNodes::BeginInputAttribute(this->id, ImNodesPinShape_CircleFilled); - // 填充占位 - ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); - ImNodes::EndInputAttribute(); -} - -// 必要构造 -MSG_OutPut_Connector::MSG_OutPut_Connector(Independent_ID_Generator *ID_Generator) : Abs_Connector(ID_Generator, CONNECTOR_TYPE_OUTPUT, "DLT MSG") {} - -// 绘制接口 -void MSG_OutPut_Connector::Show(void) -{ - // 输出接口点 - ImNodes::BeginOutputAttribute(this->id, ImNodesPinShape_CircleFilled); - // 填充占位 - ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); - ImNodes::EndOutputAttribute(); -} - -// 必要构造 -CSV_Column_Input_Connector::CSV_Column_Input_Connector(Independent_ID_Generator *ID_Generator, bool exclusive_flag) : Abs_Connector(ID_Generator, exclusive_flag ? CONNECTOR_TYPE_INPUT_EXCLUSIVE : CONNECTOR_TYPE_INPUT, "CSV Column") {} - -// 绘制接口 -void CSV_Column_Input_Connector::Show() -{ - // 输出接口点 - ImNodes::BeginInputAttribute(this->id, ImNodesPinShape_TriangleFilled); - // 填充占位 - ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); - ImNodes::EndInputAttribute(); -} - -// 必要构造 -CSV_Column_Output_Connector::CSV_Column_Output_Connector(Independent_ID_Generator *ID_Generator) : Abs_Connector(ID_Generator, CONNECTOR_TYPE_OUTPUT, "CSV Column") {} - -// 绘制接口 -void CSV_Column_Output_Connector::Show() -{ - // 输出接口点 - ImNodes::BeginOutputAttribute(this->id, ImNodesPinShape_TriangleFilled); - // 填充占位 - ImGui::Dummy(ImVec2(0.0f, ImGui::GetTextLineHeight())); - ImNodes::EndOutputAttribute(); -} - -// ================================================================================================= - // 必要构造 Connector_Test_Node::Connector_Test_Node(Independent_ID_Generator *Node_ID_Generator, Independent_ID_Generator *Connector_ID_Generator, @@ -553,6 +512,8 @@ bool Connector_Test_Node::Execute_Process(void) auto pkg = this->Connector_List[0]->Get_Related_List()[0]->Get_Package(); this->Connector_List[1]->Register_Package(pkg.p_content_mem, pkg.content_size, pkg.package_count, pkg.total_count); } + else + this->Connector_List[1]->Register_Package(nullptr, 0, 0, 0); // Boolean 相关接口 if (!this->Connector_List[2]->Get_Related_List().empty()) @@ -562,6 +523,8 @@ bool Connector_Test_Node::Execute_Process(void) auto pkg = this->Connector_List[2]->Get_Related_List()[0]->Get_Package(); this->Connector_List[3]->Register_Package(pkg.p_content_mem, pkg.content_size, pkg.package_count, pkg.total_count); } + else + this->Connector_List[3]->Register_Package(nullptr, 0, 0, 0); // CSV 相关接口 if (!this->Connector_List[4]->Get_Related_List().empty()) @@ -571,6 +534,8 @@ bool Connector_Test_Node::Execute_Process(void) auto pkg = this->Connector_List[4]->Get_Related_List()[0]->Get_Package(); this->Connector_List[5]->Register_Package(pkg.p_content_mem, pkg.content_size, pkg.package_count, pkg.total_count); } + else + this->Connector_List[5]->Register_Package(nullptr, 0, 0, 0); return true; } @@ -774,7 +739,7 @@ Filter_Node::Filter_Node(Independent_ID_Generator *Node_ID_Generator, if (this->id != -1) { // Boolean 输入节点 - this->Connector_List.push_back(std::make_shared(Connector_ID_Generator, true)); // [0] -> Boolean + this->Connector_List.push_back(std::make_shared(Connector_ID_Generator)); // [0] -> Boolean // 消息输出节点 this->Connector_List.push_back(std::make_shared(Connector_ID_Generator, true)); // [1] -> MSG @@ -905,23 +870,22 @@ bool Filter_Node::Execute_Process(void) bool pass_allow = false; for (auto input : this->Connector_List[0]->Get_Related_List()) - if (*((bool *)input->Get_Package().p_content_mem) == true) + { + auto pkg = input->Get_Package(); + if ((pkg.content_size != 0) && ((*((bool *)pkg.p_content_mem)) == true)) { pass_allow = true; break; } - - auto pkg = this->Connector_List[1]->Get_Package(); + } if (pass_allow) { + auto pkg = this->Connector_List[1]->Get_Package(); + this->Connector_List[2]->Register_Package(pkg.p_content_mem, pkg.content_size, pkg.package_count, pkg.total_count); } else - { - } - - // 注册产物 - this->Connector_List[2]->Register_Package(pkg.p_content_mem, pkg.content_size, pkg.package_count, pkg.total_count); + this->Connector_List[2]->Register_Package(nullptr, 0, 0, 0); return true; } diff --git a/Src/Workflow_Editor.cpp b/Src/Workflow_Editor.cpp index 5556088..aa84526 100644 --- a/Src/Workflow_Editor.cpp +++ b/Src/Workflow_Editor.cpp @@ -102,8 +102,20 @@ void Workflow_Editor::Show(void) // 显示所有的连线 for (auto Edge : this->Edge_Pool) - ImNodes::Link(Edge.id, Edge.source_connector_id, Edge.target_connector_id); - + { + if (Edge.type == Edge::Edge_Type_Enum::EDGE_TYPE_EXCLUSIVE) + { + ImNodes::PushColorStyle(ImNodesCol_Link, IM_COL32(50, 120, 160, 160)); + ImNodes::PushColorStyle(ImNodesCol_LinkHovered, IM_COL32(0, 110, 175, 255)); + ImNodes::PushColorStyle(ImNodesCol_LinkSelected, IM_COL32(0, 110, 175, 255)); + ImNodes::Link(Edge.id, Edge.source_connector_id, Edge.target_connector_id); + ImNodes::PopColorStyle(); + ImNodes::PopColorStyle(); + ImNodes::PopColorStyle(); + } + else + ImNodes::Link(Edge.id, Edge.source_connector_id, Edge.target_connector_id); + } // 缩略图 ImNodes::MiniMap(0.2f, ImNodesMiniMapLocation_TopRight); } @@ -433,9 +445,13 @@ bool Workflow_Editor::Add_Link(int source_connector_id, int target_connector_id) } } + // 连接点独占标记 + bool is_connector_exclusive = false; + // 独占输入类型,清除所有其它的连接 if (p_source_connector->Get_Type() == Abs_Connector::CONNECTOR_TYPE_INPUT_EXCLUSIVE) { + is_connector_exclusive = true; auto source_id = p_source_connector->Get_ID(); auto List = p_source_connector->Get_Related_List(); for (auto connector : List) @@ -445,6 +461,7 @@ bool Workflow_Editor::Add_Link(int source_connector_id, int target_connector_id) // 独占输入类型,清除所有其它的连接 if (p_target_connector->Get_Type() == Abs_Connector::CONNECTOR_TYPE_INPUT_EXCLUSIVE) { + is_connector_exclusive = true; auto target_id = p_target_connector->Get_ID(); auto List = p_target_connector->Get_Related_List(); for (auto connector : List) @@ -453,7 +470,10 @@ bool Workflow_Editor::Add_Link(int source_connector_id, int target_connector_id) // 先尝试连接,成功后再记录到边池 if (p_source_connector->Connect_To(p_target_connector.get()) == true) - this->Edge_Pool.push_back({this->Edge_ID_Generator.Request_ID(), source_connector_id, target_connector_id}); + this->Edge_Pool.push_back({this->Edge_ID_Generator.Request_ID(), + source_connector_id, + target_connector_id, + is_connector_exclusive ? Edge::Edge_Type_Enum::EDGE_TYPE_EXCLUSIVE : Edge::Edge_Type_Enum::EDGE_TYPE_NORMAL}); return true; }