LAPTOP-SNT8I5JK\Boounion
2025-03-21 4eaefee05c987e352dd6d761e601aa450f7f92b4
SourceCode/Bond/Servo/CPageGraph2.cpp
@@ -133,6 +133,7 @@
void CPageGraph2::OnDestroy()
{
   CDialogEx::OnDestroy();
   SaveEqsGraphData();
   if (m_hbrBkgnd != nullptr) {
      ::DeleteObject(m_hbrBkgnd);
@@ -154,8 +155,15 @@
#define OUTPIN      2
void CPageGraph2::AddEqToGraphWnd(SERVO::CEquipment* pEquipment)
{
   int x, y;
   GetItemDataFormIni(pEquipment->getName().c_str(), x, y);
   EQITEM* pItem = m_pEqsGraphWnd->AddItem(0, pEquipment->getName().c_str(), (DWORD_PTR)pEquipment);
   m_pEqsGraphWnd->SetItemType(pItem, ITEM_SMALL);
   if (x > 0 && y > 0) {
      m_pEqsGraphWnd->SetItemPos(pItem, x, y);
   }
   std::vector<SERVO::CPin*>& inPins = pEquipment->getInputPins();
   for (auto inPin : inPins) {
      m_pEqsGraphWnd->AddPin(pItem, INPIN, inPin->getName().c_str(), (DWORD_PTR)inPin);
@@ -172,10 +180,47 @@
   if (1 == nIDEvent) {
      KillTimer(1);
      std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
      for (auto item : eqs) {
         AddEqToGraphWnd(item);
      for (auto eq : eqs) {
         AddEqToGraphWnd(eq);
      }
      for (auto eq : eqs) {
         auto& pins = eq->getOutputPins();
         for (auto pin : pins) {
            SERVO::CPin* pPin2 = pin->getConnectedPin();
            if (pPin2 != nullptr) {
               m_pEqsGraphWnd->ConnectPin((DWORD_PTR)eq, (DWORD_PTR)pin, (DWORD_PTR)pPin2->getEquipment(), (DWORD_PTR)pPin2);
            }
         }
      }
   }
   CDialogEx::OnTimer(nIDEvent);
}
void CPageGraph2::SaveEqsGraphData()
{
   char szFilepath[MAX_PATH];
   CString strValue;
   sprintf_s(szFilepath, MAX_PATH, "%s\\EqsGraph.ini", (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
   std::list<SERVO::CEquipment*>& eqs = theApp.m_model.m_master.getEquipmentList();
   for (auto item : eqs) {
      EQITEM* pEqItem = m_pEqsGraphWnd->GetItem((DWORD_PTR)item);
      strValue.Format(_T("%d"), pEqItem->rect.left);
      WritePrivateProfileString(item->getName().c_str(), _T("Left"),
         (LPTSTR)(LPCTSTR)strValue, szFilepath);
      strValue.Format(_T("%d"), pEqItem->rect.top);
      WritePrivateProfileString(item->getName().c_str(), _T("Top"),
         (LPTSTR)(LPCTSTR)strValue, szFilepath);
   }
}
void CPageGraph2::GetItemDataFormIni(const char* pszItemName, int& left, int& top)
{
   char szFilepath[MAX_PATH];
   CString strValue;
   sprintf_s(szFilepath, MAX_PATH, "%s\\EqsGraph.ini", (LPTSTR)(LPCTSTR)theApp.m_strAppDir);
   left = GetPrivateProfileInt(pszItemName, _T("Left"), 0, szFilepath);
   top = GetPrivateProfileInt(pszItemName, _T("Top"), 0, szFilepath);
}