From 6dc80508b1c0f431007f8a8c947c152ec00c3d15 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期一, 08 九月 2025 09:24:05 +0800
Subject: [PATCH] Merge branch 'clh' into liuyang

---
 SourceCode/Bond/Servo/CGlass.cpp |  307 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 293 insertions(+), 14 deletions(-)

diff --git a/SourceCode/Bond/Servo/CGlass.cpp b/SourceCode/Bond/Servo/CGlass.cpp
index a21bd7b..ac69f80 100644
--- a/SourceCode/Bond/Servo/CGlass.cpp
+++ b/SourceCode/Bond/Servo/CGlass.cpp
@@ -6,9 +6,20 @@
 	CGlass::CGlass()
 	{
 		m_pPath = nullptr;
+		m_type = MaterialsType::G1;
+		m_pBuddy = nullptr;
+		m_nOriginPort = 0;
+		m_nOriginSlot = 0;
+		m_bScheduledForProcessing = FALSE;
+		m_pProcessJob = nullptr;
 	}
 
 	CGlass::~CGlass()
+	{
+		reset();
+	}
+
+	void CGlass::reset()
 	{
 		CPath* pPath = m_pPath;
 		while (pPath != nullptr) {
@@ -17,6 +28,10 @@
 			pPath = pTemp;
 		}
 		m_pPath = nullptr;
+
+		if (m_pBuddy != nullptr) {
+			m_pBuddy->release();
+		}
 	}
 
 	std::string& CGlass::getClassName()
@@ -35,6 +50,16 @@
 		return strText;
 	}
 
+	MaterialsType CGlass::getType()
+	{
+		return m_type;
+	}
+
+	void CGlass::setType(MaterialsType type)
+	{
+		m_type = type;
+	}
+
 	void CGlass::setID(const char* pszID)
 	{
 		m_strID = pszID;
@@ -45,17 +70,36 @@
 		return m_strID;
 	}
 
-	CPath* CGlass::getPathWithSiteID(unsigned int nSiteId)
+	void CGlass::setOriginPort(int port, int slot)
 	{
-		CPath* pPath = m_pPath;
-		while (pPath != nullptr) {
-			if (nSiteId == pPath->getSiteID()) {
-				return pPath;
-			}
-			pPath = pPath->getNext();
-		}
+		m_nOriginPort = port;
+		m_nOriginSlot = slot;
+	}
 
-		return nullptr;
+	void CGlass::getOrginPort(int& port, int& slot)
+	{
+		port = m_nOriginPort;
+		slot = m_nOriginSlot;
+	}
+
+	BOOL CGlass::isScheduledForProcessing()
+	{
+		return m_bScheduledForProcessing;
+	}
+	
+	void CGlass::setScheduledForProcessing(BOOL bProcessing)
+	{
+		m_bScheduledForProcessing = bProcessing;
+	}
+
+	CProcessJob* CGlass::getProcessJob()
+	{
+		return m_pProcessJob;
+	}
+
+	void CGlass::setProcessJob(CProcessJob* pProcessJob)
+	{
+		m_pProcessJob = pProcessJob;
 	}
 
 	CPath* CGlass::getPath()
@@ -63,9 +107,23 @@
 		return m_pPath;
 	}
 
-	void CGlass::addPath(unsigned int nSiteId)
+	CPath* CGlass::getPathWithEq(unsigned int nEqId, unsigned int nUnit)
 	{
-		CPath* pPath = new CPath(nSiteId);
+		CPath* pTemp = m_pPath;
+		while (pTemp != nullptr) {
+			if (pTemp->getEqID() == nEqId && pTemp->getUnit() == nUnit) {
+				return pTemp;
+			}
+
+			pTemp = pTemp->getNext();
+		}
+
+		return nullptr;
+	}
+
+	void CGlass::addPath(unsigned int nEqId, unsigned int nUnit)
+	{
+		CPath* pPath = new CPath(nEqId, nUnit);
 		if (m_pPath == nullptr) {
 			m_pPath = pPath;
 		}
@@ -79,25 +137,246 @@
 		if (ar.IsStoring())
 		{
 			Lock();
+			ar << (int)m_type;
 			WriteString(ar, m_strID);
+			ar << m_nOriginPort;
+			ar << m_nOriginSlot;
+			ar << m_bScheduledForProcessing;
 			ar << (ULONGLONG)m_pPath;
 			if (m_pPath != nullptr) {
 				m_pPath->serialize(ar);
 			}
+			char temp[JOBDATAS_SIZE] = { 0 };
+			m_jobDataS.serialize(temp, JOBDATAS_SIZE);
+			ar.Write(temp, JOBDATAS_SIZE);
+			ar << (ULONGLONG)m_pBuddy;
+			WriteString(ar, m_strBuddyId);
 			Unlock();
 		}
 		else
 		{
-			Lock();
-			ReadString(ar, m_strID);
 			ULONGLONG ullPath;
+			int type;
+
+			Lock();
+			ar >> type;
+			m_type = (MaterialsType)type;
+			ReadString(ar, m_strID);
+			ar >> m_nOriginPort;
+			ar >> m_nOriginSlot;
+			ar >> m_bScheduledForProcessing;
 			ar >> ullPath;
 			if (ullPath != 0) {
 				m_pPath = new CPath();
 				m_pPath->serialize(ar);
 			}
-
+			char temp[JOBDATAS_SIZE];
+			ar.Read(temp, JOBDATAS_SIZE);
+			m_jobDataS.unserialize(temp, JOBDATAS_SIZE);
+			ar >> ullPath;	m_pBuddy = (CGlass*)ullPath;
+			ReadString(ar, m_strBuddyId);
 			Unlock();
 		}
 	}
+
+	void CGlass::setJobDataS(CJobDataS* pJobDataS)
+	{
+		m_jobDataS.copy(pJobDataS);
+	}
+
+	void CGlass::updateJobDataS(CJobDataS* pJobDataS)
+	{
+		m_jobDataS.update(pJobDataS);
+	}
+
+	CJobDataS* CGlass::getJobDataS()
+	{
+		return &m_jobDataS;
+	}
+
+	BOOL CGlass::setBuddy(CGlass* pGlass)
+	{
+		if (m_pBuddy != nullptr) return FALSE;
+		if (pGlass->getType() == this->getType()) return FALSE;
+		m_pBuddy = pGlass;
+		m_pBuddy->addRef();
+		m_strBuddyId = m_pBuddy->getID();
+
+		return TRUE;
+	}
+
+	BOOL CGlass::forceSetBuddy(CGlass* pGlass)
+	{
+		m_pBuddy = pGlass;
+		m_pBuddy->addRef();
+		m_strBuddyId = m_pBuddy->getID();
+
+		return TRUE;
+	}
+
+	CGlass* CGlass::getBuddy()
+	{
+		return m_pBuddy;
+	}
+
+	std::string& CGlass::getBuddyId()
+	{
+		return m_strBuddyId;
+	}
+
+	int CGlass::processEnd(unsigned int nEqId, unsigned int nUnit)
+	{
+		CPath* pPath = getPathWithEq(nEqId, nUnit);
+		if (pPath == nullptr) return -1;
+
+		pPath->processEnd();
+		return 0;
+	}
+
+	BOOL CGlass::isProcessed(unsigned int nEqId, unsigned int nUnit)
+	{
+		CPath* pPath = getPathWithEq(nEqId, nUnit);
+		if (pPath == nullptr) return FALSE;
+
+		return pPath->isProcessEnd();
+	}
+
+	int CGlass::setInspResult(unsigned int nEqId, unsigned int nUnit, InspResult result)
+	{
+		CPath* pPath = getPathWithEq(nEqId, nUnit);
+		if (pPath == nullptr) return -1;
+			
+		pPath->setInspResult(result);
+		return 0;
+	}
+
+	InspResult CGlass::getInspResult(unsigned int nEqId, unsigned int nUnit)
+	{
+		CPath* pPath = getPathWithEq(nEqId, nUnit);
+		if (pPath == nullptr) return InspResult::NotInspected;
+
+		return pPath->getInspResult();
+	}
+
+	std::string CGlass::getStateText()
+	{
+		switch (m_state)
+		{
+		case SERVO::GlsState::NoState:
+			return "NoState";
+			break;
+		case SERVO::GlsState::Queued:
+			return "Queued";
+			break;
+		case SERVO::GlsState::InProcess:
+			return "InProcess";
+			break;
+		case SERVO::GlsState::Paused:
+			return "Queued";
+			break;
+		case SERVO::GlsState::Completed:
+			return "Queued";
+			break;
+		case SERVO::GlsState::Aborted:
+			return "Aborted";
+			break;
+		case SERVO::GlsState::Failed:
+			return "Failed";
+			break;
+		default:
+			break;
+		}
+
+		return "";
+	}
+
+	bool CGlass::queue() {
+		if (m_state != GlsState::NoState) return false;
+		markQueued();
+		return true;
+	}
+
+	bool CGlass::start() {
+		if (m_state != GlsState::Queued && m_state != GlsState::Paused)
+			return false;
+		if (!m_tStart.has_value()) markStart();
+		m_state = GlsState::InProcess;
+		return true;
+	}
+
+	bool CGlass::pause() {
+		if (m_state != GlsState::InProcess) return false;
+		m_state = GlsState::Paused;
+		return true;
+	}
+
+	bool CGlass::resume() {
+		if (m_state != GlsState::Paused) return false;
+		m_state = GlsState::InProcess;
+		return true;
+	}
+
+	bool CGlass::complete() {
+		if (m_state != GlsState::InProcess && m_state != GlsState::Paused) return false;
+		m_state = GlsState::Completed;
+		markEnd();
+		return true;
+	}
+
+	bool CGlass::abort() {
+		if (m_state == GlsState::Completed || m_state == GlsState::Aborted || m_state == GlsState::Failed)
+			return false;
+		m_state = GlsState::Aborted;
+		markEnd();
+		return true;
+	}
+
+	bool CGlass::fail(std::string reason)
+	{
+		m_failReason = trimCopy(reason);
+		clampString(m_failReason, 128);
+		m_state = GlsState::Failed;
+		markEnd();
+		return true;
+	}
+
+	std::string CGlass::trimCopy(std::string s)
+	{
+		auto notspace = [](int ch) { return !std::isspace(ch); };
+		s.erase(s.begin(), std::find_if(s.begin(), s.end(), notspace));
+		s.erase(std::find_if(s.rbegin(), s.rend(), notspace).base(), s.end());
+		return s;
+	}
+
+	void CGlass::clampString(std::string& s, size_t maxLen)
+	{
+		if (s.size() > maxLen) s.resize(maxLen);
+	}
+
+	// —— 时间戳 & 工具 —— 
+	void CGlass::markQueued() 
+	{
+		m_state = GlsState::Queued;
+		m_tQueued = std::chrono::system_clock::now();
+	}
+
+	void CGlass::markStart()
+	{
+		m_tStart = std::chrono::system_clock::now();
+	}
+
+	void CGlass::markEnd()
+	{
+		m_tEnd = std::chrono::system_clock::now();
+	}
+
+	void CGlass::addParams(std::vector<CParam>& params)
+	{
+		m_params.insert(m_params.end(), params.begin(), params.end());
+	}
+
+	std::vector<CParam>& CGlass::getParams()
+	{
+		return m_params;
+	}
 }

--
Gitblit v1.9.3