Modified some function name in JSON related classes && Removed the Null flag for Json_Pair && Added function interfaces for exporting and importing configurations in the base node class && Added experimental operation testing for the workflow.

This commit is contained in:
2026-04-28 19:08:31 +08:00
parent f9f10209ca
commit df949ce460
6 changed files with 71 additions and 29 deletions
+4 -8
View File
@@ -65,7 +65,7 @@ public:
Json_Value operator[](size_t index) const; Json_Value operator[](size_t index) const;
// 是否为空 // 是否为空
bool isNull(void) const; bool isEmpty(void) const;
}; };
// Json 值定义 // Json 值定义
@@ -130,7 +130,6 @@ public:
class Json_Pair class Json_Pair
{ {
private: private:
bool Null_Flag = true; // 空判定
std::string private_key_str; // 键 std::string private_key_str; // 键
Json_Value private_value; // 值 Json_Value private_value; // 值
public: public:
@@ -139,17 +138,14 @@ public:
Json_Value &value = this->private_value; 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(const Json_Pair &temp);
// 深拷贝 // 深拷贝
Json_Pair &operator=(const Json_Pair &another); Json_Pair &operator=(const Json_Pair &another);
// 空判定
bool isNull() const;
}; };
// Json 对象 // Json 对象
@@ -183,7 +179,7 @@ public:
Json_Value get(std::string key) const; Json_Value get(std::string key) const;
// 是否为空 // 是否为空
bool isNull(void) const; bool isEmpty(void) const;
}; };
#endif #endif
+7
View File
@@ -6,6 +6,7 @@
#include "imgui.h" #include "imgui.h"
#include "imnodes.h" #include "imnodes.h"
#include "ID_Generator.hpp" #include "ID_Generator.hpp"
#include "Json_Utilities.hpp"
// =====================================接口抽象====================================================== // =====================================接口抽象======================================================
@@ -123,6 +124,12 @@ public:
// 获取关闭信号 // 获取关闭信号
virtual bool Get_CloseFlag(void); virtual bool Get_CloseFlag(void);
// 获取节点配置参数
virtual Json_Arry Get_Arguments(void);
// 应用配置参数
virtual bool Apply_Arguments(Json_Arry Arg_Arry);
// 获取接口列表 // 获取接口列表
std::vector<std::shared_ptr<Abs_Connector>> &Get_Connector_List(void); std::vector<std::shared_ptr<Abs_Connector>> &Get_Connector_List(void);
}; };
+3
View File
@@ -73,6 +73,9 @@ public:
// 清除工作路由 true -> success / false -> failed // 清除工作路由 true -> success / false -> failed
bool Clear_Process_Route(void); bool Clear_Process_Route(void);
// 开始执行工作流
bool Execute_Workflow(void);
// 清除整个工作区 // 清除整个工作区
void Clear_All(void); void Clear_All(void);
+8 -15
View File
@@ -693,7 +693,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_
// 对象起始 // 对象起始
fprintf(pFile, "{"); fprintf(pFile, "{");
if (enable_pretty_print && (!obj.isNull())) if (enable_pretty_print && (!obj.isEmpty()))
fprintf(pFile, "\r\n"); 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); Export_Pair(pair, depth + 1);
fprintf(pFile, enable_pretty_print ? ",\r\n" : ","); fprintf(pFile, enable_pretty_print ? ",\r\n" : ",");
} }
if (!obj.isNull()) if (!obj.isEmpty())
{ {
fseek(pFile, enable_pretty_print ? -3 : -1, SEEK_CUR); fseek(pFile, enable_pretty_print ? -3 : -1, SEEK_CUR);
if (enable_pretty_print) 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++) for (size_t count = 0; count < depth; count++)
fprintf(pFile, " "); fprintf(pFile, " ");
@@ -772,7 +772,7 @@ std::string Json_Export(const char *path_to_file, Json_Value value, bool enable_
// 数组起始 // 数组起始
fprintf(pFile, "["); fprintf(pFile, "[");
if (enable_pretty_print && (!arry.isNull())) if (enable_pretty_print && (!arry.isEmpty()))
fprintf(pFile, "\r\n"); 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); Export_Value(value, depth + 1, true);
fprintf(pFile, enable_pretty_print ? ",\r\n" : ","); fprintf(pFile, enable_pretty_print ? ",\r\n" : ",");
} }
if (!arry.isNull()) if (!arry.isEmpty())
{ {
fseek(pFile, enable_pretty_print ? -3 : -1, SEEK_CUR); fseek(pFile, enable_pretty_print ? -3 : -1, SEEK_CUR);
if (enable_pretty_print) if (enable_pretty_print)
fprintf(pFile, "\r\n"); fprintf(pFile, "\r\n");
} }
// 尾部缩进 // 尾部缩进
if (enable_pretty_print && (!arry.isNull())) if (enable_pretty_print && (!arry.isEmpty()))
for (size_t count = 0; count < depth; count++) for (size_t count = 0; count < depth; count++)
fprintf(pFile, " "); fprintf(pFile, " ");
@@ -1027,7 +1027,6 @@ Json_Pair &Json_Pair::operator=(const Json_Pair &another)
{ {
if (this != &another) if (this != &another)
{ {
this->Null_Flag = another.Null_Flag;
this->private_key_str = another.private_key_str; this->private_key_str = another.private_key_str;
this->private_value = another.private_value; this->private_value = another.private_value;
} }
@@ -1035,12 +1034,6 @@ Json_Pair &Json_Pair::operator=(const Json_Pair &another)
return *this; 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); 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); return (this->private_element_list.size() == 0);
} }
+12
View File
@@ -256,6 +256,18 @@ bool Abs_Node::Get_CloseFlag(void)
return this->close_flag; 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<std::shared_ptr<Abs_Connector>> &Abs_Node::Get_Connector_List(void) std::vector<std::shared_ptr<Abs_Connector>> &Abs_Node::Get_Connector_List(void)
{ {
+37 -6
View File
@@ -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))) 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; 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; clipboard_paste_flag = true;
// 删除框选内容 // 删除框选内容
if (ImGui::MenuItem(u8"删除 Delete", nullptr, nullptr, (bounding_box_link_nums > 0) || (bounding_box_node_nums > 0))) 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")) if (ImGui::MenuItem(u8"加载工作区(Debug"))
config_load_flag = true; 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::EndPopup();
} }
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@@ -660,6 +664,30 @@ bool Workflow_Editor::Clear_Process_Route(void)
return true; 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) void Workflow_Editor::Clear_All(void)
{ {
@@ -700,11 +728,11 @@ Json_Object Workflow_Editor::Generate_Config(std::vector<std::shared_ptr<Abs_Nod
{"type", Node_List[node_index]->Get_Type()}, // {"type", Node_List[node_index]->Get_Type()}, //
{ {
"position", Json_Object({ "position", Json_Object({
{"x", position.x}, // {"x", position.x}, //
{"y", position.y} // {"y", position.y} //
}) // }) //
}, // }, //
{"args", Json_Arry()}} // {"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(), 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, 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)); 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()); Created_Node_List.push_back(this->Node_Pool.back());
} }
} }