diff --git a/Inc/Json_Utilities.hpp b/Inc/Json_Utilities.hpp index 2bf383e..3add539 100644 --- a/Inc/Json_Utilities.hpp +++ b/Inc/Json_Utilities.hpp @@ -65,7 +65,7 @@ public: Json_Value operator[](size_t index) const; // 是否为空 - bool isNull(void) const; + bool isEmpty(void) const; }; // Json 值定义 @@ -130,7 +130,6 @@ public: class Json_Pair { private: - bool Null_Flag = true; // 空判定 std::string private_key_str; // 键 Json_Value private_value; // 值 public: @@ -139,17 +138,14 @@ public: Json_Value &value = this->private_value; // 默认构造 - Json_Pair() : Null_Flag(true) {}; + Json_Pair() = default; // 必要构造 - Json_Pair(std::string key, Json_Value value) : Null_Flag(false), private_key_str(key), private_value(value) {}; + Json_Pair(std::string key, Json_Value value) : private_key_str(key), private_value(value) {}; // 浅拷贝构造 Json_Pair(const Json_Pair &temp); // 深拷贝 Json_Pair &operator=(const Json_Pair &another); - - // 空判定 - bool isNull() const; }; // Json 对象 @@ -183,7 +179,7 @@ public: Json_Value get(std::string key) const; // 是否为空 - bool isNull(void) const; + bool isEmpty(void) const; }; #endif \ No newline at end of file diff --git a/Inc/Nodes_And_Connectors.hpp b/Inc/Nodes_And_Connectors.hpp index a3622e1..2722da1 100644 --- a/Inc/Nodes_And_Connectors.hpp +++ b/Inc/Nodes_And_Connectors.hpp @@ -6,6 +6,7 @@ #include "imgui.h" #include "imnodes.h" #include "ID_Generator.hpp" +#include "Json_Utilities.hpp" // =====================================接口抽象====================================================== @@ -123,6 +124,12 @@ public: // 获取关闭信号 virtual bool Get_CloseFlag(void); + // 获取节点配置参数 + virtual Json_Arry Get_Arguments(void); + + // 应用配置参数 + virtual bool Apply_Arguments(Json_Arry Arg_Arry); + // 获取接口列表 std::vector> &Get_Connector_List(void); }; diff --git a/Inc/Workflow_Editor.hpp b/Inc/Workflow_Editor.hpp index 767416d..32a0b77 100644 --- a/Inc/Workflow_Editor.hpp +++ b/Inc/Workflow_Editor.hpp @@ -73,6 +73,9 @@ public: // 清除工作路由 true -> success / false -> failed bool Clear_Process_Route(void); + // 开始执行工作流 + bool Execute_Workflow(void); + // 清除整个工作区 void Clear_All(void); diff --git a/Src/Json_Utilities.cpp b/Src/Json_Utilities.cpp index 28dafcd..cf5c224 100644 --- a/Src/Json_Utilities.cpp +++ b/Src/Json_Utilities.cpp @@ -693,7 +693,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_ // 对象起始 fprintf(pFile, "{"); - if (enable_pretty_print && (!obj.isNull())) + if (enable_pretty_print && (!obj.isEmpty())) fprintf(pFile, "\r\n"); // 输出键值对 @@ -702,7 +702,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_ Export_Pair(pair, depth + 1); fprintf(pFile, enable_pretty_print ? ",\r\n" : ","); } - if (!obj.isNull()) + if (!obj.isEmpty()) { fseek(pFile, enable_pretty_print ? -3 : -1, SEEK_CUR); if (enable_pretty_print) @@ -710,7 +710,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_ } // 尾部缩进 - if (enable_pretty_print && (!obj.isNull())) + if (enable_pretty_print && (!obj.isEmpty())) for (size_t count = 0; count < depth; count++) fprintf(pFile, " "); @@ -772,7 +772,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_ // 数组起始 fprintf(pFile, "["); - if (enable_pretty_print && (!arry.isNull())) + if (enable_pretty_print && (!arry.isEmpty())) fprintf(pFile, "\r\n"); // 输出数组数值 @@ -781,14 +781,14 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_ Export_Value(value, depth + 1, true); fprintf(pFile, enable_pretty_print ? ",\r\n" : ","); } - if (!arry.isNull()) + if (!arry.isEmpty()) { fseek(pFile, enable_pretty_print ? -3 : -1, SEEK_CUR); if (enable_pretty_print) fprintf(pFile, "\r\n"); } // 尾部缩进 - if (enable_pretty_print && (!arry.isNull())) + if (enable_pretty_print && (!arry.isEmpty())) for (size_t count = 0; count < depth; count++) fprintf(pFile, " "); @@ -1027,7 +1027,6 @@ Json_Pair &Json_Pair::operator=(const Json_Pair &another) { if (this != &another) { - this->Null_Flag = another.Null_Flag; this->private_key_str = another.private_key_str; this->private_value = another.private_value; } @@ -1035,12 +1034,6 @@ Json_Pair &Json_Pair::operator=(const Json_Pair &another) return *this; } -// 空判定 -bool Json_Pair::isNull() const -{ - return this->Null_Flag; -} - // ================================================================================================= // 浅拷贝构造 @@ -1077,7 +1070,7 @@ Json_Value Json_Arry::operator[](size_t index) const } // 是否为空 -bool Json_Arry::isNull(void) const +bool Json_Arry::isEmpty(void) const { return (this->private_element_list.size() == 0); } @@ -1128,7 +1121,7 @@ Json_Value Json_Object::get(std::string key) const } // 是否为空 -bool Json_Object::isNull(void) const +bool Json_Object::isEmpty(void) const { return (this->private_element_list.size() == 0); } \ No newline at end of file diff --git a/Src/Nodes_And_Connectors.cpp b/Src/Nodes_And_Connectors.cpp index c49d697..680c696 100644 --- a/Src/Nodes_And_Connectors.cpp +++ b/Src/Nodes_And_Connectors.cpp @@ -256,6 +256,18 @@ bool Abs_Node::Get_CloseFlag(void) return this->close_flag; } +// 获取节点配置参数 +Json_Arry Abs_Node::Get_Arguments(void) +{ + return Json_Arry(); +} + +// 应用配置参数 +bool Abs_Node::Apply_Arguments(Json_Arry Arg_Arry) +{ + return true; +} + // 获取接口列表 std::vector> &Abs_Node::Get_Connector_List(void) { diff --git a/Src/Workflow_Editor.cpp b/Src/Workflow_Editor.cpp index e4bdd6a..8dcd4f9 100644 --- a/Src/Workflow_Editor.cpp +++ b/Src/Workflow_Editor.cpp @@ -73,7 +73,7 @@ void Workflow_Editor::Show(void) if (ImGui::MenuItem(u8"剪切 Ctrl + X", nullptr, nullptr, (bounding_box_link_nums > 0) || (bounding_box_node_nums > 0))) clipboard_copy_flag = bounding_box_delete_flag = true; // 粘贴框选内容 - if (ImGui::MenuItem(u8"粘贴 Ctrl + V", nullptr, nullptr, !this->Config_Clipboard.isNull())) + if (ImGui::MenuItem(u8"粘贴 Ctrl + V", nullptr, nullptr, !this->Config_Clipboard.isEmpty())) clipboard_paste_flag = true; // 删除框选内容 if (ImGui::MenuItem(u8"删除 Delete", nullptr, nullptr, (bounding_box_link_nums > 0) || (bounding_box_node_nums > 0))) @@ -89,6 +89,10 @@ void Workflow_Editor::Show(void) if (ImGui::MenuItem(u8"加载工作区(Debug)")) config_load_flag = true; + if (ImGui::MenuItem(u8"执行工作流(Debug)")) + if (this->Execute_Workflow() == true) + MessageBoxW(Main_Window_hWnd, L"工作流执行完成!!", L"", MB_OK); + ImGui::EndPopup(); } ImGui::PopStyleVar(); @@ -660,6 +664,30 @@ bool Workflow_Editor::Clear_Process_Route(void) return true; } +// 开始执行工作流 +bool Workflow_Editor::Execute_Workflow(void) +{ + + /** + * @todo 线程分离 + * 将任务单独分离到线程中,并跟随进度条 + */ + + bool status = this->Build_Process_Route(); + if (status == false) + return status; + + for (auto Route : this->Process_Route) + for (auto pNode : Route) + { + status = pNode->Execute_Process(); + if (status == false) + return false; + } + + return true; +} + // 清除整个工作区 void Workflow_Editor::Clear_All(void) { @@ -700,11 +728,11 @@ Json_Object Workflow_Editor::Generate_Config(std::vectorGet_Type()}, // { "position", Json_Object({ - {"x", position.x}, // - {"y", position.y} // - }) // - }, // - {"args", Json_Arry()}} // + {"x", position.x}, // + {"y", position.y} // + }) // + }, // + {"args", Node_List[node_index]->Get_Arguments()}} // )); // 查询是有相关联的连接 @@ -813,7 +841,10 @@ bool Workflow_Editor::Apply_Config(Json_Object Config_Object, ImVec2 initial_pos this->Add_Node((Abs_Node::Node_Type_Enum)Node_Info.asObject().get("type").asInteger(), ImVec2(Node_Info.asObject().get("position").asObject().get("x").asFloat() + Position_Offset.x, Node_Info.asObject().get("position").asObject().get("y").asFloat() + Position_Offset.y)); + // 应用配置参数 + this->Node_Pool.back()->Apply_Arguments(Node_Info.asObject().get("args").asArry()); + // 加入列表 Created_Node_List.push_back(this->Node_Pool.back()); } }