From bfe14e41fa5b07771d78af4511ba18d706bc23cc Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 28 七月 2025 17:07:52 +0800
Subject: [PATCH] 1.Spooling Config功能EAP模拟测试;

---
 SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp |  113 +++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 67 insertions(+), 46 deletions(-)

diff --git a/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp b/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp
index 004463c..d0391cb 100644
--- a/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp
+++ b/SourceCode/Bond/BondEq/FileManager/RecipeManager.cpp
@@ -10,28 +10,12 @@
 }
 
 // 构造函数
-RecipeManager::RecipeManager() : m_recipeFolder("Recipe") {}
+RecipeManager::RecipeManager() : m_recipeFolder("Recipe"), m_currentRecipeName("") {}
 
-// 设置配方文件夹
-void RecipeManager::setRecipeFolder(const std::string& folderPath) {
-    m_recipeFolder = folderPath;
-}
-
-// 加载配方(如果文件不存在,加载默认数据)
-bool RecipeManager::loadRecipe(const std::string& recipeName) {
-    std::string filePath = m_recipeFolder + "/" + recipeName + ".xml";
-    pugi::xml_document doc;
-
-    if (!doc.load_file(filePath.c_str())) {
-        std::cerr << "Recipe file not found: " << filePath << ". Loading default recipe." << std::endl;
-        generateDefaultRecipe();
-        return false; // 文件不存在,但加载了默认数据
-    }
-
+// 加载轴信息
+bool RecipeManager::loadAxes(pugi::xml_node axesNode) {
     m_axes.clear();
-
-    auto recipe = doc.child("Recipe");
-    for (auto axisNode : recipe.child("Axes").children("Axis")) {
+    for (auto axisNode : axesNode.children("Axis")) {
         AxisInfo axisInfo;
         axisInfo.id = axisNode.attribute("id").as_int();
         axisInfo.number = axisNode.attribute("number").value();
@@ -66,7 +50,9 @@
         );
 
         // 加载 PositionRange 值
+        axisInfo.positioningPointCount = axisNode.child("Positions").attribute("positioningPointCount").as_int();
         for (auto positionNode : axisNode.child("Positions").children("Position")) {
+            bool isEnable = positionNode.attribute("isEnable").as_bool();
             std::string description = positionNode.attribute("description").value();
             ValueRange positionRange(
                 positionNode.attribute("min").as_double(),
@@ -74,7 +60,7 @@
                 positionNode.attribute("current").as_double()
             );
 
-            axisInfo.positions.emplace_back(PositionRange(description, positionRange));
+            axisInfo.positions.emplace_back(PositionRange(isEnable, description, positionRange));
         }
 
         m_axes[axisInfo.id] = axisInfo;
@@ -83,26 +69,8 @@
     return true;
 }
 
-// 保存配方
-bool RecipeManager::saveRecipe(const std::string& recipeName) {
-    // 生成文件路径
-    std::string filePath = m_recipeFolder + "/" + recipeName + ".xml";
-
-    // 创建 XML 文档对象
-    pugi::xml_document doc;
-
-    // 如果轴数据为空,生成默认配方
-    if (m_axes.empty()) {
-        generateDefaultRecipe();
-    }
-
-    // 添加配方根节点
-    auto recipe = doc.append_child("Recipe");
-
-    // 添加轴列表节点
-    auto axesNode = recipe.append_child("Axes");
-
-    // 遍历所有轴数据并写入 XML
+// 保存轴信息
+void RecipeManager::saveAxes(pugi::xml_node& axesNode) {
     for (const auto& axisEntry : m_axes) {
         const AxisInfo& axisInfo = axisEntry.second;
 
@@ -140,14 +108,65 @@
 
         // 保存 PositionRange 值
         auto positionsNode = axisNode.append_child("Positions");
+        positionsNode.append_attribute("positioningPointCount") = axisInfo.positioningPointCount;
         for (const auto& position : axisInfo.positions) {
             auto positionNode = positionsNode.append_child("Position");
+            positionNode.append_attribute("isEnable") = position.isEnable;
             positionNode.append_attribute("description") = position.description.c_str();
             positionNode.append_attribute("min") = position.range.minValue;
             positionNode.append_attribute("max") = position.range.maxValue;
             positionNode.append_attribute("current") = position.range.currentValue;
         }
     }
+}
+
+// 设置配方文件夹
+void RecipeManager::setRecipeFolder(const std::string& folderPath) {
+    m_recipeFolder = folderPath;
+}
+
+// 获取当前配方名称
+std::string RecipeManager::getCurrentRecipeName() const {
+	return m_currentRecipeName;
+}
+
+// 加载配方(如果文件不存在,加载默认数据)
+bool RecipeManager::loadRecipe(const std::string& recipeName) {
+    std::string filePath = m_recipeFolder + "/" + recipeName + ".xml";
+    pugi::xml_document doc;
+
+    if (!doc.load_file(filePath.c_str())) {
+        std::cerr << "Recipe file not found: " << filePath << ". Loading default recipe." << std::endl;
+        return false; // 文件不存在
+    }
+	m_currentRecipeName = recipeName;
+
+    auto recipeNode = doc.child("Recipe");
+    auto axesNode = recipeNode.child("Axes");
+    loadAxes(axesNode);  // 加载轴信息
+
+    return true;
+}
+
+// 保存配方
+bool RecipeManager::saveRecipe(const std::string& recipeName) {
+    // 生成文件路径
+    std::string filePath = m_recipeFolder + "/" + recipeName + ".xml";
+
+    // 创建 XML 文档对象
+    pugi::xml_document doc;
+
+    // 如果轴数据为空,生成默认配方
+    if (m_axes.empty()) {
+        generateDefaultRecipe();
+    }
+
+    // 添加配方根节点
+    auto recipeNode = doc.append_child("Recipe");
+
+    // 添加轴信息
+    auto axesNode = recipeNode.append_child("Axes");
+    saveAxes(axesNode);
 
     // 保存 XML 文件
     return doc.save_file(filePath.c_str());
@@ -156,10 +175,12 @@
 // 生成默认配方
 void RecipeManager::generateDefaultRecipe() {
     m_axes.clear();
+	m_currentRecipeName = "Default";
 
     for (int axisId = 1; axisId <= 12; ++axisId) {
         AxisInfo axisInfo;
         axisInfo.id = axisId;
+        axisInfo.positioningPointCount = 25;
         axisInfo.number = "M100-M" + std::to_string(axisId);
         axisInfo.description = "Default_Axis" + std::to_string(axisId);
         axisInfo.startAddress = "ZR" + std::to_string(10000 + (axisId - 1) * 300);
@@ -172,10 +193,10 @@
         axisInfo.decelerationTime = ValueRange(1.0, 10.0, 1.0);
 
         // 添加定位点并设置默认的最小值和最大值
-        for (int posId = 1; posId <= 25; ++posId) {
-            double minPos = posId * 5.0;
-            double maxPos = posId * 20.0;
-            axisInfo.positions.emplace_back(PositionRange("Position " + std::to_string(posId), ValueRange(minPos, maxPos, posId * 10.0)));
+        for (int posId = 0; posId < axisInfo.positioningPointCount; ++posId) {
+            double minPos = (posId + 1) * 5.0;
+            double maxPos = (posId + 1) * 20.0;
+            axisInfo.positions.emplace_back(PositionRange(TRUE, "Position " + std::to_string(posId + 1), ValueRange(minPos, maxPos, (posId + 1) * 10.0)));
         }
 
         m_axes[axisId] = axisInfo;
@@ -195,7 +216,7 @@
     }
 
     // 如果没有找到该轴,返回一个默认的无效 AxisInfo
-    return AxisInfo{ -1, "", "", "", ValueRange(), ValueRange(), ValueRange(), ValueRange(), ValueRange(), {} };
+    return AxisInfo{ -1, 0, /*0.0, 0.0,*/ "", "", "", ValueRange(), ValueRange(), ValueRange(), ValueRange(), ValueRange(), {} };
 }
 
 // 更新轴信息

--
Gitblit v1.9.3