From 81df82be1f5f401b80780f65e5811685d9a8e4c4 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期五, 19 九月 2025 18:03:24 +0800
Subject: [PATCH] 1.修复打开软件加载CControlJob时,玻璃context丢失的问题;
---
SourceCode/Bond/Servo/ProcessJob.h | 1
SourceCode/Bond/Servo/ProcessJob.cpp | 12 ++++++
SourceCode/Bond/Servo/CMaster.cpp | 51 +++++++++++++++++++++----
SourceCode/Bond/Servo/CMaster.h | 4 +
SourceCode/Bond/Servo/Model.cpp | 5 +-
5 files changed, 61 insertions(+), 12 deletions(-)
diff --git a/SourceCode/Bond/Servo/CMaster.cpp b/SourceCode/Bond/Servo/CMaster.cpp
index ac0a419..3c1adba 100644
--- a/SourceCode/Bond/Servo/CMaster.cpp
+++ b/SourceCode/Bond/Servo/CMaster.cpp
@@ -213,10 +213,9 @@
-
-
// 读缓存数据
readCache();
+ loadState();
// 定时器
@@ -2576,13 +2575,9 @@
return true;
}
- bool CMaster::loadState(const std::string& path)
+ bool CMaster::loadState()
{
- // 保存文件路径
- m_strStatePath = path;
-
-
- std::ifstream ifs(path, std::ios::binary);
+ std::ifstream ifs(m_strStatePath, std::ios::binary);
if (!ifs) return false;
// 文件头
@@ -2635,10 +2630,33 @@
m_pControlJob->setPJs(tempPjs);
+ // 更新contexts
+ auto pjs = m_pControlJob->getPjs();
+ for (auto pj : pjs) {
+ for (auto& c : pj->carriers()) {
+ auto p = getPortWithCarrierId(c.carrierId);
+ if (p == nullptr) continue;
+
+ std::vector<void*> contexts;
+ for (auto s : c.slots) {
+ auto g = getGlass(p->getIndex(), s - 1);
+ if (g == nullptr) continue;
+ contexts.push_back(g);
+ }
+ pj->setCarrierContexts(c.carrierId, contexts);
+ }
+ }
+
+
// 如果版本升级,可在这里判断 version 来加载新字段
return true;
+ }
+
+ void CMaster::setStateFile(const std::string& path)
+ {
+ m_strStatePath = path;
}
CProcessJob* CMaster::acquireNextProcessJob()
@@ -2899,4 +2917,21 @@
return true;
}
+
+ CGlass* CMaster::getGlass(int scrPort, int scrSlot)
+ {
+ for (auto eq : m_listEquipment) {
+ std::vector<CGlass*> glasses;
+ eq->getAllGlass(glasses);
+ for (auto g : glasses) {
+ int p, s;
+ g->getOrginPort(p, s);
+ if (p == scrPort && s == scrSlot) {
+ return g;
+ }
+ }
+ }
+
+ return nullptr;
+ }
}
diff --git a/SourceCode/Bond/Servo/CMaster.h b/SourceCode/Bond/Servo/CMaster.h
index 6a17fb1..47bf8cf 100644
--- a/SourceCode/Bond/Servo/CMaster.h
+++ b/SourceCode/Bond/Servo/CMaster.h
@@ -128,13 +128,15 @@
CControlJob* getControlJob();
CLoadPort* getPortWithCarrierId(const std::string& carrierId) const;
bool saveState() const;
- bool loadState(const std::string& path);
+ bool loadState();
+ void setStateFile(const std::string& path);
int getWipGlasses(std::vector<CGlass*>& glasses);
void test();
bool moveGlassToBuf(int eqid, int slotNo);
bool moveGlassToSlot(int eqid, int slotNo);
int getPortCassetteSnSeed(int port);
void setPortCassetteSnSeed(int port, int seed);
+ CGlass* getGlass(int scrPort, int scrSlot);
private:
inline void lock() { EnterCriticalSection(&m_criticalSection); }
diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 8d987b6..c3a438d 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -468,9 +468,8 @@
// 加截Job
strMasterDataFile.Format(_T("%s\\MasterState.dat"), (LPTSTR)(LPCTSTR)m_strWorkDir);
std::string strPath = std::string((LPTSTR)(LPCTSTR)strMasterDataFile);
- if (!m_master.loadState(strPath)) {
- LOGE("<Master>加载MasterState.dat文件失败.");
- }
+ m_master.setStateFile(strPath);
+
// 加载警告信息
diff --git a/SourceCode/Bond/Servo/ProcessJob.cpp b/SourceCode/Bond/Servo/ProcessJob.cpp
index 62872f1..e58845b 100644
--- a/SourceCode/Bond/Servo/ProcessJob.cpp
+++ b/SourceCode/Bond/Servo/ProcessJob.cpp
@@ -290,6 +290,18 @@
return false;
}
+ bool CProcessJob::setCarrierContexts(std::string carrierId, std::vector<void*> contexts)
+ {
+ for (auto& c : m_carriers) {
+ if (c.carrierId.compare(carrierId) == 0) {
+ c.contexts = std::move(contexts);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
// --------- 核心:serialize/deserialize ---------
void CProcessJob::serialize(std::ostream& os) const {
// 头
diff --git a/SourceCode/Bond/Servo/ProcessJob.h b/SourceCode/Bond/Servo/ProcessJob.h
index 6fdba9f..35fd2da 100644
--- a/SourceCode/Bond/Servo/ProcessJob.h
+++ b/SourceCode/Bond/Servo/ProcessJob.h
@@ -156,6 +156,7 @@
// 设置载具slots和contexts
bool setCarrierSlotsAndContexts(std::string carrierId, std::vector<uint8_t> slots, std::vector<void*> contexts);
+ bool setCarrierContexts(std::string carrierId, std::vector<void*> contexts);
// 访问器
const std::vector<CarrierSlotInfo>& carriers() const noexcept { return m_carriers; }
--
Gitblit v1.9.3