From 8fc148424accf484b4f331c7d5fb11eb7383cf89 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期六, 24 一月 2026 16:34:29 +0800
Subject: [PATCH] 1.点连接图子项时,如果显示生产面板则不显示属性页;

---
 SourceCode/Bond/Servo/Model.cpp |  170 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 157 insertions(+), 13 deletions(-)

diff --git a/SourceCode/Bond/Servo/Model.cpp b/SourceCode/Bond/Servo/Model.cpp
index 5087821..ed29052 100644
--- a/SourceCode/Bond/Servo/Model.cpp
+++ b/SourceCode/Bond/Servo/Model.cpp
@@ -10,6 +10,7 @@
 #include "RecipeManager.h"
 #include "GlassLogDb.h"
 #include "CParam.h"
+#include "CJobDataS.h"
 #include <algorithm>
 #include <iomanip>
 #include <sstream>
@@ -34,6 +35,79 @@
 
 	// PJobSpace: how many ProcessJobs can be created (current implementation supports 0/1).
 	m_hsmsPassive.setVariableValue("PJobSpace", (__int64)(m_master.isProcessJobsEmpty() ? 1 : 0));
+}
+
+void CModel::notifyControlJobChanged()
+{
+	// 1) 鍒锋柊娲剧敓 SV
+	refreshDerivedSVs();
+	// 2) 閫氱煡涓婂眰 UI锛圧X_CODE_CONTROLJOB_CHANGED锛�
+	notify(RX_CODE_CONTROLJOB_CHANGED);
+}
+
+bool CModel::raiseSoftAlarm(int alarmId,
+	const std::string& desc,
+	int level /*= -1*/,
+	int deviceId /*= 0*/,
+	int unitId /*= 0*/,
+	const char* deviceName /*= "Software"*/,
+	const char* unitName /*= "App"*/)
+{
+	AlarmManager& alarmManager = AlarmManager::getInstance();
+	const AlarmInfo* info = alarmManager.getAlarmInfoByID(alarmId);
+
+	int severity = level;
+	if (severity < 0 && info != nullptr) severity = info->nAlarmLevel;
+	if (severity < 0) severity = 0;
+
+	std::string descText = desc;
+	if (descText.empty() && info != nullptr) {
+		descText = !info->strDescription.empty() ? info->strDescription : info->strAlarmText;
+	}
+	if (descText.empty()) {
+		descText = CToolUnits::formatString("Alarm %d", alarmId);
+	}
+
+	AlarmData alarmData;
+	alarmData.nId = alarmId;
+	alarmData.nSeverityLevel = severity;
+	alarmData.nDeviceId = deviceId;
+	alarmData.nUnitId = unitId;
+	alarmData.strDeviceName = deviceName;
+	alarmData.strUnitName = unitName;
+	// 鑻ユ湭鏄惧紡鎻愪緵璁惧/鍗曞厓鍚嶇О锛屽皾璇曢�氳繃 deviceId/unitId 瑙f瀽锛坰oft alarm 榛樿鍧囦负 0锛�
+	if (alarmData.strDeviceName.empty()) {
+		alarmData.strDeviceName = alarmManager.getDeviceNameById(deviceId);
+	}
+	if (alarmData.strUnitName.empty()) {
+		alarmData.strUnitName = alarmManager.getUnitNameById(deviceId, unitId);
+	}
+	alarmData.strStartTime = CToolUnits::timeToString2(CToolUnits::getTimestamp());
+	alarmData.strEndTime = "";
+	alarmData.strDescription = descText;
+
+	int nAlarmEventId = 0;
+	bool result = alarmManager.addAlarm(alarmData, nAlarmEventId);
+	if (result) {
+		notify(RX_CODE_ALARM_SET);
+		if (m_master.isAlarmReportEnable()) {
+			m_hsmsPassive.requestAlarmReport(1, alarmId, descText.c_str());
+		}
+	}
+	return result;
+}
+
+void CModel::clearSoftAlarm(int alarmId, int deviceId, int unitId)
+{
+	AlarmManager& alarmManager = AlarmManager::getInstance();
+	alarmManager.clearAlarmByAttributes(alarmId, deviceId, unitId, CToolUnits::getCurrentTimeString());
+	notify(RX_CODE_ALARM_CLEAR);
+	if (m_master.isAlarmReportEnable()) {
+		const AlarmInfo* info = alarmManager.getAlarmInfoByID(alarmId);
+		std::string descText;
+		if (info != nullptr) descText = info->strAlarmText;
+		m_hsmsPassive.requestAlarmReport(0, alarmId, descText.c_str());
+	}
 }
 
 void CModel::setControlState(ControlState newState)
@@ -110,6 +184,7 @@
 
 int CModel::init()
 {
+	const ULONGLONG boot_model_begin = GetTickCount64();
 	CString strIniFile;
 	CString strUnitId;
 	strIniFile.Format(_T("%s\\ServoConfiguration.ini"), (LPTSTR)(LPCTSTR)m_strWorkDir);
@@ -124,6 +199,9 @@
 	// CGlassPool
 	m_glassPool.initPool();
 
+	// 灏� Model 涓婁笅鏂囦紶閫掔粰 Master锛屼究浜� Master 瑙﹀彂杞欢绾ф姤璀︾瓑璺ㄥ眰鎿嶄綔
+	m_master.setModelCtx(this);
+
 
 	// Log
 	CString strLogDir;
@@ -137,6 +215,7 @@
 	CLog::GetLog()->SetLogsDir(strLogDir);
 	CLog::GetLog()->SetEquipmentId((LPTSTR)(LPCTSTR)strUnitId);
 	LOGI("\r\n\r\n~~~ Prog Start! ~~~");
+	LOGI("[BOOT][MODEL] init begin");
 
 
 	SECSListener listener;
@@ -165,18 +244,6 @@
 		}
 		else if (_strcmpi(pszName, "GoRemote") == 0 || _strcmpi(pszName, "REMOTE") == 0 || _strcmpi(pszName, "GoREMOTE") == 0) {
 			setControlState(ControlState::OnlineRemote);
-		}
-	};
-	listener.onEQConstantRequest = [&](void* pFrom, std::vector<EQConstant>& eqcs) -> void {
-		// 鍦ㄦ濉厖甯搁噺鍊硷紝鐩墠浠呮槸鍔�1鍚庤繑鍥�
-		for (auto& item : eqcs) {
-			sprintf_s(item.szValue, EQCONSTANT_VALUE_MAX, "Test%d", item.id + 1);
-		}
-	};
-	listener.onEQConstantSend = [&](void* pFrom, std::vector<EQConstant>& eqcs) -> void {
-		// 鍦ㄦ淇濆瓨鍜岃缃満鍣ㄥ父閲忓��
-		for (auto& item : eqcs) {
-			LOGI("onEQConstantRequest: %d, %s", item.id, item.szValue);
 		}
 	};
 	listener.onDatetimeSync = [&](void* pFrom, SYSTEMTIME& time) -> void {
@@ -244,6 +311,11 @@
 				// 鐪熸鐨勨�滃紑濮嬧�濈敱 ProceedWithSlotMap 鍐崇瓥瑙﹀彂銆�
 				// 浠呭綋鏈紑鍚� CompareMapsBeforeProceeding 鏃讹紝鎵嶆部鐢ㄦ棫閫昏緫鐩存帴 Start銆�
 				LOGI("<CModel>ProceedWithCarrier");
+				if (m_master.getControlJob() == nullptr || m_master.isProcessJobsEmpty()) {
+					strErrorTxt = "rejected - ControlJob/ProcessJob not ready";
+					LOGW("<CModel>ProceedWithCarrier rejected: no CJ/PJ, port=%d", portIndex + 1);
+					return CAACK_5;
+				}
 				if (pLoadPort == nullptr || !pLoadPort->isCompareMapsBeforeProceeding()) {
 					m_master.proceedWithCarrier(portIndex);
 				}
@@ -284,6 +356,23 @@
 		for (auto p : pjs) {
 			LOGI("<Model>onPRJobMultiCreate %s %s", p->id().c_str(), p->recipeSpec().c_str());
 		}
+
+		auto rejectAll = [&](uint32_t code, const std::string& msg) -> int {
+			LOGW("<Model>onPRJobMultiCreate rejected: %s", msg.c_str());
+			for (auto p : pjs) {
+				if (p != nullptr) p->addIssue(code, msg);
+			}
+			return -1;
+		};
+
+		// 鍗� PJ 妯″紡锛氬彧鎺ュ彈 1 鏉′笖褰撳墠鏃犲湪鍒� PJ
+		if (pjs.size() != 1) {
+			return rejectAll(1200, "Only 1 ProcessJob supported (single-PJ mode)");
+		}
+		if (!m_master.isProcessJobsEmpty()) {
+			return rejectAll(1201, "ProcessJob exists, cannot create new in single-PJ mode");
+		}
+
 		int nRet = m_master.setProcessJobs(pjs);
 		auto processJobs = m_master.getProcessJobs();
 		std::vector<SERVO::CVariable> vars;
@@ -310,6 +399,10 @@
 	CString strVarialbleFile;
 	strVarialbleFile.Format(_T("%s\\VariableList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir);
 	m_hsmsPassive.loadVarialbles((LPTSTR)(LPCTSTR)strVarialbleFile);
+	strVarialbleFile.Format(_T("%s\\DataVariableList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir);
+	m_hsmsPassive.loadDataVarialbles((LPTSTR)(LPCTSTR)strVarialbleFile);
+	strVarialbleFile.Format(_T("%s\\EquipmentConstantList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir);
+	m_hsmsPassive.loadEquipmentConstants((LPTSTR)(LPCTSTR)strVarialbleFile);
 	setControlState(m_currentControlState);
 	refreshDerivedSVs();
 	m_hsmsPassive.init(this, "APP", 7000);
@@ -317,8 +410,19 @@
 	m_hsmsPassive.loadReports((LPTSTR)(LPCTSTR)strVarialbleFile);
 	strVarialbleFile.Format(_T("%s\\CollectionEventList.txt"), (LPTSTR)(LPCTSTR)m_strWorkDir);
 	m_hsmsPassive.loadCollectionEvents((LPTSTR)(LPCTSTR)strVarialbleFile);
+	{
+		auto events = m_hsmsPassive.getCollectionEvents();
+		std::vector<unsigned int> ceids;
+		ceids.reserve(events.size());
+		for (auto e : events) {
+			if (e != nullptr) ceids.push_back(e->getEventId());
+		}
+		m_master.setAllowedCeids(ceids);
+	}
 	strVarialbleFile.Format(_T("%s\\HsmsPassive.cache"), (LPTSTR)(LPCTSTR)m_strWorkDir);
 	m_hsmsPassive.loadCacheFromFile(strVarialbleFile);
+	LOGI("[BOOT][MODEL] HSMS config loaded, cost=%llu ms",
+		(unsigned long long)(GetTickCount64() - boot_model_begin));
 
 
 	SERVO::MasterListener masterListener;
@@ -334,7 +438,7 @@
 	};
 	masterListener.onControlJobChanged = [this](void* pMaster) {
 		(void)pMaster;
-		this->refreshDerivedSVs();
+		this->notifyControlJobChanged();
 		};
 	masterListener.onEqAlive = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bAlive) -> void {
 		LOGI("<CModel>Equipment onAlive:%s(%s).", pEquipment->getName().c_str(),
@@ -509,6 +613,42 @@
 		}
 		notifyPtrAndInt(RX_CODE_EQ_ROBOT_TASK, pTask, nullptr, code);
 
+	};
+	masterListener.onJobReceived = [&](void* pMaster, SERVO::CEquipment* pEquipment, int port, SERVO::CJobDataS* pJobDataS) {
+		(void)pMaster;
+		(void)port;
+		if (pEquipment == nullptr || pJobDataS == nullptr) return;
+		const int eqId = pEquipment->getID();
+		const int recipeId = pJobDataS->getMasterRecipe();
+		std::string recipe = RecipeManager::getInstance().getPPIDById(recipeId);
+		if (recipe.empty()) {
+			recipe = std::to_string(recipeId);
+		}
+		const std::string prev = pEquipment->getCurrentRecipe();
+		if (recipe.empty() || recipe == prev) {
+			pEquipment->setCurrentRecipe(recipe);
+			return;
+		}
+		pEquipment->setCurrentRecipe(recipe);
+		m_hsmsPassive.withVariableLock([&] {
+			m_hsmsPassive.setVariableValue("Clock", CToolUnits::getCurrentTimeString().c_str());
+			m_hsmsPassive.setVariableValue("EQPPExecName", recipe.c_str());
+			m_hsmsPassive.setVariableValue("SubEqpName", pEquipment->getName().c_str());
+			const char* recipeVid = nullptr;
+			switch (eqId) {
+			case EQ_ID_Bonder1: recipeVid = "Bonder1CurrentRecipe"; break;
+			case EQ_ID_Bonder2: recipeVid = "Bonder2CurrentRecipe"; break;
+			case EQ_ID_VACUUMBAKE: recipeVid = "VacuumBakeCurrentRecipe"; break;
+			case EQ_ID_BAKE_COOLING: recipeVid = "BakeCoolingCurrentRecipe"; break;
+			case EQ_ID_MEASUREMENT: recipeVid = "MeasurementCurrentRecipe"; break;
+			case EQ_ID_EFEM: recipeVid = "EFEMCurrentRecipe"; break;
+			default: break;
+			}
+			if (recipeVid != nullptr) {
+				m_hsmsPassive.setVariableValue(recipeVid, recipe.c_str());
+			}
+			m_hsmsPassive.requestEventReportSend("RecipeChanged");
+		});
 	};
 	masterListener.onLoadPortStatusChanged = [&] (void* pMaster, SERVO::CEquipment* pEquipment, short status, __int64 data) {
 		LOGE("<CModel>onLoadPortStatusChanged. status = %d", status);
@@ -786,6 +926,8 @@
 	char szBuffer[MAX_PATH];
 	sprintf_s(szBuffer, MAX_PATH, "%s\\AlarmList.csv", (LPTSTR)(LPCTSTR)m_strWorkDir);
 	alarmManager.readAlarmFile(szBuffer);
+	LOGI("[BOOT][MODEL] Alarm list loaded, cost=%llu ms",
+		(unsigned long long)(GetTickCount64() - boot_model_begin));
 
 
 	// Glass鏁版嵁搴�
@@ -794,6 +936,8 @@
 	GlassLogDb::Init(path);
 
 
+	LOGI("[BOOT][MODEL] init finished, total cost=%llu ms",
+		(unsigned long long)(GetTickCount64() - boot_model_begin));
 	return 0;
 }
 

--
Gitblit v1.9.3