Old fashion design for PC-104
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

353 lines
9.7 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //----------------------------------------------------------------------------
  2. // Laser Guard Ltd.
  3. // Copyright � 2000-2002. All Rights Reserved.
  4. // Version 1.0 01/01/2000
  5. // Last modification: 31/07/2001
  6. // PROJECT:
  7. // SUBSYSTEM:
  8. // FILE: PropDCLinkDlg.cpp
  9. // AUTHOR: Sergey Chizhevskiy
  10. // OVERVIEW
  11. // ~~~~~~~~
  12. // Source file of PropDCLinkDlg.cpp
  13. //----------------------------------------------------------------------------
  14. // PropDCLinkDlg.cpp : implementation file
  15. //
  16. #include "stdafx.h"
  17. #include "setuplgs.h"
  18. //#include "PropDCLinkDlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CPropDCLinkDlg dialog
  26. CPropDCLinkDlg::CPropDCLinkDlg(CWnd* pParent /*=NULL*/)
  27. : CDialog(CPropDCLinkDlg::IDD, pParent)
  28. {
  29. //{{AFX_DATA_INIT(CPropDCLinkDlg)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. m_pDryContact = NULL;
  33. m_pDevice = NULL;
  34. }
  35. void CPropDCLinkDlg::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CDialog::DoDataExchange(pDX);
  38. //{{AFX_DATA_MAP(CPropDCLinkDlg)
  39. DDX_Control(pDX, IDC_LIST_TEMPLATE, m_ListTemplate);
  40. DDX_Control(pDX, IDC_LIST_LINK, m_ListLink);
  41. DDX_Control(pDX, IDC_LIST_DEVICE, m_ListDevice);
  42. DDX_Control(pDX, IDC_BUTTON_DELALL, m_ButtonDelAll);
  43. DDX_Control(pDX, IDC_BUTTON_DEL, m_ButtonDel);
  44. DDX_Control(pDX, IDC_BUTTON_ADDALL, m_ButtonAddAll);
  45. DDX_Control(pDX, IDC_BUTTON_ADD, m_ButtonAdd);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CPropDCLinkDlg, CDialog)
  49. //{{AFX_MSG_MAP(CPropDCLinkDlg)
  50. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  51. ON_BN_CLICKED(IDC_BUTTON_ADDALL, OnButtonAddall)
  52. ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
  53. ON_BN_CLICKED(IDC_BUTTON_DELALL, OnButtonDelall)
  54. ON_LBN_SELCHANGE(IDC_LIST_DEVICE, OnSelchangeList)
  55. ON_LBN_SELCHANGE(IDC_LIST_LINK, OnSelchangeList)
  56. ON_LBN_SELCHANGE(IDC_LIST_TEMPLATE, OnSelchangeList)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. typedef struct
  60. {
  61. PVOID dataD;
  62. PVOID dataT;
  63. }DATAPTR, *PDATAPTR;
  64. void CPropDCLinkDlg::OnButtonAdd()
  65. {
  66. int nIndexD = m_ListDevice.GetCurSel();
  67. int nIndexT = m_ListTemplate.GetCurSel();
  68. if( nIndexD >= 0 && nIndexT >= 0 )
  69. {
  70. PDATAPTR pDataPtr = new DATAPTR;
  71. CString dname;
  72. m_ListDevice.GetText( nIndexD, dname );
  73. pDataPtr->dataD = m_ListDevice.GetItemDataPtr( nIndexD );
  74. CString tname;
  75. m_ListTemplate.GetText( nIndexT, tname );
  76. pDataPtr->dataT = m_ListTemplate.GetItemDataPtr( nIndexT );
  77. CString linkname;
  78. linkname.Format( _T("D(%s) <-> T(%s)"), dname, tname );
  79. int nIndex = m_ListLink.AddString( linkname );
  80. m_ListLink.SetItemDataPtr( nIndex, pDataPtr );
  81. m_ListDevice.DeleteString( nIndexD );
  82. m_ListTemplate.DeleteString( nIndexT );
  83. }
  84. OnSelchangeList();
  85. }
  86. void CPropDCLinkDlg::OnButtonAddall()
  87. {
  88. while( m_ListDevice.GetCount() && m_ListTemplate.GetCount() )
  89. {
  90. m_ListDevice.SetCurSel( 0 );
  91. m_ListTemplate.SetCurSel( 0 );
  92. OnButtonAdd();
  93. }
  94. }
  95. void CPropDCLinkDlg::OnButtonDel()
  96. {
  97. int nIndex = m_ListLink.GetCurSel();
  98. if( nIndex >= 0 )
  99. {
  100. PDATAPTR pDataPtr = (PDATAPTR)m_ListLink.GetItemData( nIndex );
  101. CString dname;
  102. dname.Format( _T("%02d"), (int)pDataPtr->dataD );
  103. int nIndexD = m_ListDevice.AddString( dname );
  104. m_ListDevice.SetItemDataPtr( nIndexD, pDataPtr->dataD );
  105. CString tname;
  106. tname.Format( _T("%s"), ((COFTemplateDCBit*)pDataPtr->dataT)->GetName() );
  107. int nIndexT = m_ListTemplate.AddString( tname );
  108. m_ListTemplate.SetItemDataPtr( nIndexT, pDataPtr->dataT );
  109. m_ListLink.DeleteString( nIndex );
  110. delete pDataPtr;
  111. }
  112. OnSelchangeList();
  113. }
  114. void CPropDCLinkDlg::OnButtonDelall()
  115. {
  116. while( m_ListLink.GetCount() )
  117. {
  118. m_ListLink.SetCurSel( 0 );
  119. OnButtonDel();
  120. }
  121. }
  122. void CPropDCLinkDlg::OnSelchangeList()
  123. {
  124. m_ButtonAdd.EnableWindow( m_ListDevice.GetCurSel() >= 0 &&
  125. m_ListTemplate.GetCurSel() >= 0 );
  126. m_ButtonAddAll.EnableWindow( m_ListDevice.GetCount() &&
  127. m_ListTemplate.GetCount() );
  128. m_ButtonDel.EnableWindow( m_ListLink.GetCurSel() >= 0 );
  129. m_ButtonDelAll.EnableWindow( m_ListLink.GetCount() );
  130. }
  131. void CPropDCLinkDlg::FillControls()
  132. {
  133. CObjectFactory *pOF = m_pDevice->GetOF();
  134. /*
  135. for( int i = 0; i < pOF->TemplateGetCount(); i++ )
  136. {
  137. int nIndex = m_ComboTemplate.AddString( pOF->TemplateGet(i)->GetName() );
  138. m_ComboTemplate.SetItemDataPtr( nIndex, (PVOID)pOF->TemplateGet(i) );
  139. }
  140. */
  141. /*
  142. for( int i = 0; i < m_pDevice->m_nDryContact; i++ )
  143. {
  144. // if bit link to this dry contact or bit link free
  145. if( ( m_pDevice->m_pDryContact[i].nIndex == m_pDryContact->GetIndex() &&
  146. m_pDevice->m_pDryContact[i].nType == m_pDryContact->GetType() ) ||
  147. m_pDevice->m_pDryContact[i].nBit == -1 )
  148. {
  149. CString pinname;
  150. pinname.Format( _T("%02d"), i );
  151. int nIndex = m_ListDevice.AddString( pinname );
  152. m_ListDevice.SetItemDataPtr( nIndex, (PVOID)i );
  153. }
  154. }
  155. */
  156. while( m_ListLink.GetCount() )
  157. m_ListLink.DeleteString( 0 );
  158. // draw image
  159. if( m_pDryContact->m_nTemplate >= 0 )
  160. {
  161. COFTemplateDC *pTempl = (COFTemplateDC*)pOF->TemplateGet( m_pDryContact->m_nTemplate );
  162. while( m_ListTemplate.GetCount() )
  163. m_ListTemplate.DeleteString( 0 );
  164. for( int i = 0; i < pTempl->BitGetCount(); i++ )
  165. {
  166. CString bitname;
  167. bitname.Format( _T("%s"), pTempl->BitGet(i)->GetName() );
  168. int nIndex = m_ListTemplate.AddString( bitname );
  169. m_ListTemplate.SetItemDataPtr( nIndex, (PVOID)pTempl->BitGet(i) );
  170. }
  171. while( m_ListLink.GetCount() )
  172. m_ListLink.DeleteString( 0 );
  173. m_ImageWnd.GetBitList()->RemoveAll();
  174. for( i = 0; i < pTempl->BitGetCount(); i++ )
  175. m_ImageWnd.GetBitList()->AddTail( pTempl->BitGet( i ) );
  176. HBITMAP hBitmap = pTempl->GetFileGroup()->LoadImage( pTempl->GetBG(), IMAGE_BITMAP, 0, 0, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE );
  177. m_ImageWnd.SetImage( hBitmap );
  178. // m_ImageWnd.SetImage( pTempl->FileGroupGetTemp( pTempl->GetBG() ) );
  179. // m_ImageWnd.SetImage( pTempl->GetBG() );
  180. }
  181. // fill links
  182. for( i = 0; i < m_pDevice->m_nDryContact; i++ )
  183. {
  184. // if bit link to this dry contact and bit link exist
  185. if( m_pDevice->m_pDryContact[i].nIndex == m_pDryContact->GetIndex() &&
  186. m_pDevice->m_pDryContact[i].nType == m_pDryContact->GetType() &&
  187. m_pDevice->m_pDryContact[i].nBit != -1 )
  188. {
  189. int nIndex;
  190. for( int j = 0; j < m_ListDevice.GetCount(); j++ )
  191. {
  192. if( (int)m_ListDevice.GetItemDataPtr( j ) == i )
  193. {
  194. nIndex = j;
  195. break;
  196. }
  197. }
  198. m_ListDevice.SetCurSel( nIndex );
  199. COFTemplateDC *pTempl = (COFTemplateDC*)pOF->TemplateGet( m_pDryContact->m_nTemplate );
  200. nIndex = m_ListTemplate.FindString( -1, pTempl->BitGet( m_pDevice->m_pDryContact[i].nBit )->GetName() );
  201. m_ListTemplate.SetCurSel( nIndex );
  202. OnButtonAdd();
  203. }
  204. }
  205. OnSelchangeList();
  206. }
  207. BOOL CPropDCLinkDlg::OnInitDialog()
  208. {
  209. CDialog::OnInitDialog();
  210. CRect rect;
  211. GetDlgItem( IDC_STATIC_TEMPLATE )->GetWindowRect( &rect );
  212. ScreenToClient( &rect );
  213. m_ImageWnd.Create( this, &rect );
  214. FillControls();
  215. return TRUE;
  216. }
  217. BOOL CPropDCLinkDlg::DestroyWindow()
  218. {
  219. while( m_ListLink.GetCount() )
  220. {
  221. delete (PDATAPTR)m_ListLink.GetItemData( 0 );
  222. m_ListLink.DeleteString( 0 );
  223. }
  224. return CDialog::DestroyWindow();
  225. }
  226. int CPropDCLinkDlg::DoModal(COFDevice *pSensor, COFDevice *pDryContact)
  227. {
  228. ASSERT( pDryContact );
  229. ASSERT( pSensor );
  230. m_pDevice = pSensor;
  231. m_pDryContact = (COFDeviceDryContacts*)pDryContact;
  232. return CDialog::DoModal();
  233. }
  234. void CPropDCLinkDlg::OnOK()
  235. {
  236. // m_pDryContact->m_nTemplate = m_ComboTemplate.GetCurSel();
  237. for( int i = 0; i < m_pDevice->GetPinCount(); i++ )
  238. {
  239. // search for sensor (RABBIT) d/c pin
  240. COFPin *pPin = m_pDevice->GetPin(i);
  241. if( pPin->GetType() == PT_SENSOR_INPUT )
  242. {
  243. CObjectFactory *pOF = m_pDevice->GetOF();
  244. // delete all links in pin belong this dry-contacts
  245. for( int j = 0; j < pPin->m_nDeviceCount; )
  246. {
  247. COFDevice *pD2 = pOF->DeviceGet( pPin->m_pDevice[j].nIndex, pPin->m_pDevice[j].nType );
  248. if( pD2 == m_pDryContact )
  249. {
  250. COFPin *pP2 = pD2->GetPin( pPin->m_pDevice[j].nPin );
  251. pOF->ConnectionDisconnect( pPin, pP2 );
  252. // pPin->Disconnect( pP2 );
  253. // pP2->Disconnect( pPin );
  254. j = 0; // after delete start again
  255. }
  256. else j++;
  257. }
  258. // clear all dry contacts links
  259. for( j = 0; j < m_pDevice->m_nDryContact; j++ )
  260. {
  261. // if bit link to this dry contact
  262. if( m_pDevice->m_pDryContact[i].nIndex == m_pDryContact->GetIndex() &&
  263. m_pDevice->m_pDryContact[i].nType == m_pDryContact->GetType() )
  264. {
  265. m_pDevice->m_pDryContact[j].nBit = -1;
  266. m_pDevice->m_pDryContact[j].nIndex = -1;
  267. m_pDevice->m_pDryContact[j].nType = -1;
  268. }
  269. }
  270. // add link to pin
  271. if( m_ListLink.GetCount() )
  272. {
  273. // connect dry contact pin with sensor pin
  274. pPin->Connect( m_pDryContact->GetPin(0) );
  275. // connect d/c bits with template bits
  276. for( int nIndex = 0; nIndex < m_ListLink.GetCount(); nIndex++ )
  277. {
  278. PDATAPTR pDataPtr = (PDATAPTR)m_ListLink.GetItemDataPtr( nIndex );
  279. COFTemplateDCBit *pBit = (COFTemplateDCBit*)pDataPtr->dataT;
  280. COFTemplateDC *pTempl = pOF->TemplateGet( m_pDryContact->m_nTemplate ); //(COFTemplateDC*)m_ComboTemplate.GetItemDataPtr( 0 );
  281. for( j = 0; j < pTempl->BitGetCount(); j++ )
  282. {
  283. if( pTempl->BitGet( j ) == pDataPtr->dataT )
  284. {
  285. m_pDevice->m_pDryContact[ (int)pDataPtr->dataD ].nBit = j;
  286. m_pDevice->m_pDryContact[ (int)pDataPtr->dataD ].nIndex = m_pDryContact->GetIndex();
  287. m_pDevice->m_pDryContact[ (int)pDataPtr->dataD ].nType = m_pDryContact->GetType();
  288. break;
  289. }
  290. }
  291. }
  292. }
  293. break;
  294. }
  295. }
  296. CDialog::OnOK();
  297. }