VMSFORM0F.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <vcl.h>
  5. #include "AppGlobalF.h"
  6. #include "ITSSkinF.h"
  7. #include "ITSUtilF.h"
  8. #include "FrmVmsOprMainF.h"
  9. #include "VitzroCommF.h"
  10. #pragma hdrstop
  11. #if 0
  12. //GDIPLUS - start
  13. #ifndef ULONG_PTR
  14. #define ULONG_PTR unsigned long *
  15. #endif
  16. #include <math.h>
  17. #include <map>
  18. #include <list>
  19. #include <algorithm>
  20. using std::min;
  21. using std::max;
  22. #include <Gdiplus.h>
  23. #include <GdiplusBase.h>
  24. //GDIPLUS - end
  25. #endif
  26. #include "VMSFORM0F.h"
  27. //---------------------------------------------------------------------------
  28. //---------------------------------------------------------------------------
  29. #pragma package(smart_init)
  30. #pragma link "cxContainer"
  31. #pragma link "cxControls"
  32. #pragma link "cxEdit"
  33. #pragma link "cxGraphics"
  34. #pragma link "cxGroupBox"
  35. #pragma link "cxLookAndFeelPainters"
  36. #pragma link "cxLookAndFeels"
  37. #pragma link "dxSkinBlack"
  38. #pragma link "dxSkinMcSkin"
  39. #pragma link "dxSkinsCore"
  40. //#pragma link "ITSVmsDispF"
  41. #pragma link "dxSkinBlue"
  42. #pragma link "dxSkinCaramel"
  43. #pragma link "dxSkinCoffee"
  44. #pragma link "dxSkinDarkRoom"
  45. #pragma link "dxSkinDarkSide"
  46. #pragma link "dxSkinFoggy"
  47. #pragma link "dxSkinGlassOceans"
  48. #pragma link "dxSkiniMaginary"
  49. #pragma link "dxSkinLilian"
  50. #pragma link "dxSkinLiquidSky"
  51. #pragma link "dxSkinLondonLiquidSky"
  52. #pragma link "dxSkinMoneyTwins"
  53. #pragma link "dxSkinOffice2007Black"
  54. #pragma link "dxSkinOffice2007Blue"
  55. #pragma link "dxSkinOffice2007Green"
  56. #pragma link "dxSkinOffice2007Pink"
  57. #pragma link "dxSkinOffice2007Silver"
  58. #pragma link "dxSkinOffice2010Black"
  59. #pragma link "dxSkinOffice2010Blue"
  60. #pragma link "dxSkinOffice2010Silver"
  61. #pragma link "dxSkinSeven"
  62. #pragma link "dxSkinSharp"
  63. #pragma link "dxSkinSilver"
  64. #pragma link "dxSkinStardust"
  65. #pragma resource "*.dfm"
  66. #define WIDTH_GAP 3
  67. #define HEIGHT_GAP 3
  68. //TVMSFORM0 *VMSFORM0 = NULL;
  69. //---------------------------------------------------------------------------
  70. __fastcall TVMSFORM0::TVMSFORM0(TComponent* Owner, TVmsCtlr *AVmsObj)
  71. : TForm(Owner)
  72. {
  73. FVmsObj = AVmsObj;
  74. FScrollBox = NULL;
  75. FSelected = false;
  76. FDisplayMode = 0;
  77. FZoomRate = 1.0;
  78. FDispIndex = 0;
  79. FPlay = false;
  80. FWndParent = NULL;
  81. FZoomView = false;
  82. PnlForm->ParentColor = false;
  83. PnlForm->Color = clBtnFace;
  84. FDispW = FVmsObj->WIDTH;
  85. FDispH = FVmsObj->HEIGHT;
  86. //PnlName->Caption = "[" + FVmsObj->VMS_CTLR_ID + "] " + FVmsObj->VMS_NM;
  87. PnlName->Caption = FVmsObj->VMS_NM;
  88. PnlName->Hint = String(FVmsObj->VMS_CTLR_NMBR) + " [" + FVmsObj->VMS_CTLR_ID + "] \r\n" + FVmsObj->VMS_NM;
  89. FGapW = 16;
  90. FGapH = 8;
  91. PnlForm->Align = alCustom;
  92. PnlForm->Anchors = TAnchors() >> akLeft >> akTop >> akRight >> akBottom;
  93. //PnlForm->Locked = true;
  94. #if 0
  95. ImgCommError->Parent = ImgCommNormal->Parent;
  96. ImgCommError->Left = ImgCommNormal->Left;
  97. ImgCommError->Top = ImgCommNormal->Top;
  98. ImgCommError->Visible = false;
  99. ImgCommNormal->Visible= true;
  100. #else
  101. ImgState1->Parent = ImgState0->Parent;
  102. ImgState2->Parent = ImgState0->Parent;
  103. ImgState1->Left = ImgState0->Left;
  104. ImgState1->Top = ImgState0->Top;
  105. ImgState2->Left = ImgState0->Left;
  106. ImgState2->Top = ImgState0->Top;
  107. ImgState1->Visible = false;
  108. ImgState2->Visible = false;
  109. #endif
  110. LoadLocalSkin();
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TVMSFORM0::LoadLocalSkin()
  114. {
  115. PnlMain->ParentColor = false;
  116. PnlMain->Color = clBtnFace;
  117. PnlForm->ParentColor = false;
  118. PnlForm->Color = clBlack;
  119. PnlDoor->ParentColor = false;
  120. PnlFan->ParentColor = false;
  121. PnlHeater->ParentColor = false;
  122. PnlModule->ParentColor = false;
  123. PnlPower->ParentColor = false;
  124. PnlTemp->ParentColor = false;
  125. PnlOprMode->ParentColor = false;
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TVMSFORM0::FormDestroy(TObject *Sender)
  129. {
  130. TmrDisp->Enabled = false;
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TVMSFORM0::FormShow(TObject *Sender)
  134. {
  135. TmrShow->Enabled = true;
  136. RefreshVmsStatus();
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TVMSFORM0::SetFormSize(int AFormW)
  140. {
  141. AFormW = 288;
  142. AFormW = 365;
  143. //AFormW = 384;
  144. try
  145. {
  146. #if 0
  147. if (AFormW < FVmsObj->WIDTH)
  148. {
  149. FZoomRate = (float)AFormW/(float)FVmsObj->WIDTH;
  150. FDispW = FVmsObj->WIDTH * FZoomRate;
  151. FDispH = FVmsObj->HEIGHT * FZoomRate;
  152. }
  153. else
  154. {
  155. FDispW = FVmsObj->WIDTH;
  156. FDispH = FVmsObj->HEIGHT;
  157. }
  158. #else
  159. if (FVmsObj->VMS_USAG_TYPE_CD == "VUTN") FZoomRate = 0.75;
  160. else FZoomRate = 0.90;
  161. FZoomRate = 0.95;
  162. FDispW = FVmsObj->WIDTH * FZoomRate;
  163. FDispH = FVmsObj->HEIGHT * FZoomRate;
  164. #endif
  165. LockWindowUpdate(Handle);
  166. int nBaseH = (FDispH+8);
  167. Width = AFormW + FGapW;
  168. Height = nBaseH + PnlTitle->Height + PnlBottom->Height + FGapH;
  169. PnlForm->Width = FDispW + 4;
  170. PnlForm->Height = FDispH + 4;
  171. PnFormBack->Width = PnlForm->Width + 4;
  172. PnFormBack->Height = PnlForm->Height + 4;
  173. PnlForm->Left = (PnFormBack->Width - PnlForm->Width) / 2;
  174. PnlForm->Top = (nBaseH - PnlForm->Height) / 2;
  175. PnlForm->Visible = true;
  176. ImgForm->Width = FDispW;
  177. ImgForm->Height= FDispH;
  178. ImgForm->Picture->Bitmap->Width = ImgForm->Width;
  179. ImgForm->Picture->Bitmap->Height = ImgForm->Height;
  180. APP_ImageClear(ImgForm->Canvas, 0, 0, ImgForm->Width, ImgForm->Height, clBlack);
  181. }
  182. __finally
  183. {
  184. LockWindowUpdate(0);
  185. }
  186. }
  187. //---------------------------------------------------------------------------
  188. void __fastcall TVMSFORM0::SelectForm(bool ASelect)
  189. {
  190. FSelected = ASelect;
  191. if (ASelect)
  192. {
  193. PopupMenu = PopupMenu1;
  194. PnlMain->ParentColor = false;
  195. PnlMain->Color = clBtnHighlight;//clBackground;
  196. this->ParentColor = false;
  197. this->Color = clRed;
  198. }
  199. else
  200. {
  201. PopupMenu = NULL;
  202. PnlMain->ParentColor = false;
  203. PnlMain->Color = clBtnFace;
  204. this->ParentColor = true;
  205. }
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TVMSFORM0::TmrShowTimer(TObject *Sender)
  209. {
  210. TmrShow->Enabled = false;
  211. PopupMenu = NULL;
  212. if (!FVmsObj)
  213. {
  214. PnlName->Caption = "VMS";
  215. ImgForm->Visible = false;
  216. }
  217. RefreshVmsStatus();
  218. TmrDisp->Enabled = true;
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TVMSFORM0::SetPlay(bool APlay)
  222. {
  223. FPlay = APlay;
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TVMSFORM0::TmrDispTimer(TObject *Sender)
  227. {
  228. int nDispTime = 1000;
  229. TCanvas *pCanvas = ImgForm->Canvas;
  230. try
  231. {
  232. TmrDisp->Enabled = false;
  233. FVmsObj->Lock();
  234. pCanvas->Lock();
  235. try {
  236. if (FVmsObj->VmsMsg->Total == 0)
  237. {
  238. PnlSeq->Caption = "0/0";
  239. ImgForm->Visible = false;
  240. FDispIndex = -1;
  241. //PnlSvcTime->Caption = " 제공시각: -";
  242. PnlSvcTime->Caption = " Provided time: -";
  243. return;
  244. }
  245. if (ImgForm->Visible == false) ImgForm->Visible = true;
  246. if (FDispIndex >= FVmsObj->VmsMsg->Total || FDispIndex >= INT_MAX_VMS_FORM)
  247. {
  248. FDispIndex = 0;
  249. }
  250. //PnlSvcTime->Caption = " 제공시각: " + ITSUtil_FormatStr(FVmsObj->VmsMsg->OFFER_DT, STR_DATETIME);
  251. PnlSvcTime->Caption = " Provided time: " + ITSUtil_FormatStr(FVmsObj->VmsMsg->OFFER_DT, STR_DATETIME);
  252. #if 1
  253. nDispTime = FVmsObj->VMS_PHSE_CHNG_CYCL;
  254. if (nDispTime < 3) nDispTime = 3;
  255. if (nDispTime > 9) nDispTime = 10;
  256. nDispTime = nDispTime * 1000;
  257. #else
  258. nDispTime = FVmsObj->VmsMsg->PHASE[FDispIndex].DSPL_HH * 1000;
  259. #endif
  260. if (FPlay == false)
  261. {
  262. return;
  263. }
  264. PnlSeq->Caption = String(FDispIndex+1) + "/" + String(FVmsObj->VmsMsg->Total);
  265. Graphics::TBitmap *pBitmap = FVmsObj->VmsMsg->PHASE[FDispIndex].pVmsBmp;
  266. if (pBitmap)
  267. {
  268. SetStretchBltMode(ImgForm->Canvas->Handle, MAXSTRETCHBLTMODE);//HALFTONE);//MAXSTRETCHBLTMODE)//STRETCH_HALFTONE;
  269. ImgForm->Canvas->CopyRect(Classes::Rect(0, 0, ImgForm->Width, ImgForm->Height),
  270. pBitmap->Canvas,
  271. Classes::Rect(0, 0, pBitmap->Width, pBitmap->Height));
  272. }
  273. } catch(...) {}
  274. }
  275. __finally
  276. {
  277. FVmsObj->UnLock();
  278. ImgForm->Refresh();
  279. pCanvas->Unlock();
  280. FDispIndex++;
  281. PnlSvcTime->Font->Color = FVmsObj->VmsMsg->OFFER_YN ? clNavy : clRed;
  282. TmrDisp->Interval = nDispTime;
  283. TmrDisp->Enabled = true;
  284. }
  285. }
  286. //---------------------------------------------------------------------------
  287. void __fastcall TVMSFORM0::FormClose(TObject *Sender, TCloseAction &Action)
  288. {
  289. TmrDisp->Enabled = false;
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TVMSFORM0::OnFormClick(TObject *Sender)
  293. {
  294. if (FScrollBox) FScrollBox->SetFocus();
  295. }
  296. //---------------------------------------------------------------------------
  297. void __fastcall TVMSFORM0::RefreshVmsMessage()
  298. {
  299. TmrDisp->Enabled = false;
  300. FDispIndex = 0;
  301. TmrDisp->Interval= 300;
  302. TmrDisp->Enabled = true;
  303. }
  304. //---------------------------------------------------------------------------
  305. void __fastcall TVMSFORM0::RefreshVmsStatus()
  306. {
  307. PnlDoor->Caption = VmsModuleDoor(FVmsObj); //도어
  308. PnlFan->Caption = VmsModuleFan(FVmsObj); //팬
  309. PnlHeater->Caption = VmsModuleHeater(FVmsObj); //히터
  310. PnlModule->Caption = VmsModuleState(FVmsObj); //모듈상태
  311. PnlPower->Caption = VmsModulePower(FVmsObj); //전원상태
  312. PnlTemp->Caption = VmsModuleTemp(FVmsObj); //온도
  313. PnlOprMode->Caption = VmsOperMode(FVmsObj);
  314. #if 0
  315. if (FVmsObj->WSTATE.Comm == vms_normal)
  316. {
  317. if (!ImgCommNormal->Visible) ImgCommNormal->Visible = true;
  318. if ( ImgCommError->Visible) ImgCommError->Visible = false;
  319. }
  320. else
  321. {
  322. if (!ImgCommError->Visible) ImgCommError->Visible = true;
  323. if (ImgCommNormal->Visible) ImgCommNormal->Visible = false;
  324. }
  325. #else
  326. switch(FVmsObj->RunState)
  327. {
  328. case state_normal:
  329. if (!ImgState0->Visible) ImgState0->Visible = true;
  330. if ( ImgState1->Visible) ImgState1->Visible = false;
  331. if ( ImgState2->Visible) ImgState2->Visible = false;
  332. break;
  333. case state_module:
  334. if ( ImgState0->Visible) ImgState0->Visible = false; //false
  335. if ( ImgState1->Visible) ImgState1->Visible = false;
  336. if (!ImgState2->Visible) ImgState2->Visible = true; //true
  337. break;
  338. default:
  339. if ( ImgState0->Visible) ImgState0->Visible = false;
  340. if (!ImgState1->Visible) ImgState1->Visible = true;
  341. if ( ImgState2->Visible) ImgState2->Visible = false;
  342. break;
  343. }
  344. #endif
  345. TColor clrState = clLime;
  346. //운영모드
  347. #if 0
  348. if (FVmsObj->OPER_MODE != "A")
  349. {
  350. clrState = clYellow;
  351. }
  352. #else
  353. String sVmsMode = PnlOprMode->Caption;
  354. #if 0
  355. if (sVmsMode == "자동") clrState = clLime;
  356. else if (sVmsMode == "고정") clrState = clFuchsia;
  357. else clrState = clYellow;
  358. #else
  359. if (sVmsMode == "Auto") clrState = clLime;
  360. else if (sVmsMode == "Fixed") clrState = clFuchsia;
  361. else clrState = clYellow;
  362. #endif
  363. #endif
  364. if (PnlOprMode->Color != clrState) PnlOprMode->Color = clrState;
  365. if (FVmsObj->WSTATE.Comm != vms_normal)
  366. {
  367. PnlDoor->Color = clGray; //도어
  368. PnlFan->Color = clGray; //팬
  369. PnlHeater->Color = clGray; //히터
  370. PnlModule->Color = clGray; //모듈상태
  371. PnlPower->Color = clGray; //전원상태
  372. PnlTemp->Color = clGray; //온도
  373. return;
  374. }
  375. //모듈상태
  376. clrState = clLime;
  377. if (FVmsObj->WSTATE.ModuleState == vms_error)
  378. clrState = clRed;
  379. if (PnlModule->Color != clrState) PnlModule->Color = clrState;
  380. //전원상태
  381. clrState = clLime;
  382. if (FVmsObj->WSTATE.ModulePowerStatus == vms_off)
  383. clrState = clRed;
  384. if (PnlPower->Color != clrState) PnlPower->Color = clrState;
  385. //도어상태
  386. clrState = clLime;
  387. if (FVmsObj->WSTATE.DoorStatus == vms_open)
  388. clrState = clRed;
  389. if (PnlDoor->Color != clrState) PnlDoor->Color = clrState;
  390. //팬상태
  391. clrState = clLime;
  392. if (FVmsObj->WSTATE.FanStatus == vms_on)
  393. clrState = clYellow;
  394. if (PnlFan->Color != clrState) PnlFan->Color = clrState;
  395. //히터상태
  396. clrState = clLime;
  397. if (FVmsObj->WSTATE.HeaterStatus == vms_on)
  398. clrState = clYellow;
  399. if (PnlHeater->Color != clrState) PnlHeater->Color = clrState;
  400. //온도
  401. clrState = clLime;
  402. if (PnlTemp->Color != clrState) PnlTemp->Color = clrState;
  403. }
  404. //---------------------------------------------------------------------------
  405. void __fastcall TVMSFORM0::PopupMenu1Popup(TObject *Sender)
  406. {
  407. #if 0
  408. MnuVmsInfId->Caption = "[" + FVmsObj->VMS_CTLR_ID + "]";
  409. MnuCtlrPing->Caption = "제어기 Ping - " + FVmsObj->VMS_CTLR_IP;
  410. if (FVmsObj->WEB_CMRA_IP == "")
  411. {
  412. MnuWebcamPing->Caption = "웹카메라 Ping";
  413. MnuWebcamPing->Enabled = false;
  414. }
  415. else
  416. {
  417. MnuWebcamPing->Caption = "웹카메라 Ping - " + FVmsObj->WEB_CMRA_IP;
  418. MnuWebcamPing->Enabled = true;
  419. }
  420. #else
  421. MnuVmsInfId->Caption = "[" + FVmsObj->VMS_CTLR_ID + "]";
  422. MnuCtlrPing->Caption = "Controller Ping - " + FVmsObj->VMS_CTLR_IP;
  423. if (FVmsObj->WEB_CMRA_IP == "")
  424. {
  425. MnuWebcamPing->Caption = "Web camera Ping";
  426. MnuWebcamPing->Enabled = false;
  427. }
  428. else
  429. {
  430. MnuWebcamPing->Caption = "Web camera Ping - " + FVmsObj->WEB_CMRA_IP;
  431. MnuWebcamPing->Enabled = true;
  432. }
  433. #endif
  434. }
  435. //---------------------------------------------------------------------------
  436. void __fastcall TVMSFORM0::MnuNetworkPingClick(TObject *Sender)
  437. {
  438. String sIp = FVmsObj->VMS_CTLR_IP;
  439. TMenuItem *pMenu = (TMenuItem*)Sender;
  440. if (pMenu->Tag == 1)
  441. {
  442. sIp = FVmsObj->WEB_CMRA_IP;
  443. }
  444. ITSUtil_NetworkPing(sIp);
  445. }
  446. //---------------------------------------------------------------------------
  447. void __fastcall TVMSFORM0::MnuClick(TObject *Sender)
  448. {
  449. if (!FVmsObj) return;
  450. #if 0
  451. TMenuItem *pMenu = (TMenuItem*)Sender;
  452. ST_WMMESSAGE *pWmMsg = new ST_WMMESSAGE;
  453. pWmMsg->hWnd = (HWND)Handle;
  454. pWmMsg->pForm = (void*)this;
  455. pWmMsg->nMsg = D_FORMCALL;
  456. pWmMsg->sSender = "VMS0000M"; // 동적생성된 폼은 폼의 이름 +_1, +_2, ... 식으로 이름이 바뀐다.
  457. pWmMsg->sReceiver = String(pMenu->Tag);
  458. pWmMsg->sMsg = FVmsObj->Id;
  459. PostMessage(Application->MainForm->Handle, WM_PLUGINFORM, (WPARAM)pWmMsg, 0);
  460. #endif
  461. }
  462. //---------------------------------------------------------------------------
  463. void __fastcall TVMSFORM0::PnlNameClick(TObject *Sender)
  464. {
  465. if (FScrollBox) FScrollBox->SetFocus();
  466. if (FWndParent)
  467. {
  468. POST_MSG(FWndParent, WM_VMS_SELECT, (WPARAM)FVmsObj, (LPARAM)this);
  469. }
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TVMSFORM0::PnlNameDblClick(TObject *Sender)
  473. {
  474. if (FScrollBox) FScrollBox->SetFocus();
  475. if (FWndParent)
  476. {
  477. POST_MSG(FWndParent, WM_VMS_SELECT_DBLCLICK, (WPARAM)FVmsObj, (LPARAM)this);
  478. }
  479. }
  480. //---------------------------------------------------------------------------