MainDlg.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // MainDlg.cpp : implementation of the CMainDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "resource.h"
  6. #include <vector>
  7. #include <string>
  8. #include <json/json.h>
  9. #include <json/writer.h>
  10. #include <fstream>
  11. #include <array>
  12. #include "../common/comm.h"
  13. #include "RenderWindow.h"
  14. #include "MainDlg.h"
  15. LRESULT CMainDlg::OnInitDialog(HWND, LPARAM)
  16. {
  17. // center the dialog on the screen
  18. CenterWindow();
  19. // set icons
  20. HICON hIcon = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
  21. SetIcon(hIcon, TRUE);
  22. HICON hIconSmall = AtlLoadIconImage(IDR_MAINFRAME, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON));
  23. SetIcon(hIconSmall, FALSE);
  24. _control = GetEgoController(this);
  25. std::array<IRender*, RenderPosition::ALL> _array;
  26. for (int32_t i = 0; i < RenderPosition::ALL; i++)
  27. {
  28. auto p = std::make_unique<CRenderWindow>();
  29. p->Start();
  30. _array[i] = p.get();
  31. _WindowArray.push_back(std::move(p));
  32. }
  33. _control->Start(_array);
  34. Json::Value root;
  35. Json::Reader jsonReader;
  36. std::ifstream ifile("Config.json");
  37. std::string ip;
  38. if (jsonReader.parse(ifile, root))
  39. {
  40. _name = root["name"].asString();
  41. _account = root["account"].asString();
  42. _password = root["password"].asString();
  43. _control->Login(_account, _password);
  44. }
  45. return TRUE;
  46. }
  47. void CMainDlg::OnDestroy()
  48. {
  49. }
  50. void CMainDlg::OnNotifyConnected(bool bRet)
  51. {
  52. }
  53. void CMainDlg::OnNotifySigin(bool ret)
  54. {
  55. }
  56. void CMainDlg::OnNotifyImu(int32_t x, int32_t y)
  57. {
  58. }
  59. void CMainDlg::OnCarConnect(WORD, WORD, HWND)
  60. {
  61. if (_carpeer != -1) return;
  62. CListViewCtrl box;
  63. box.Attach(GetDlgItem(IDC_CARLIST));
  64. int32_t cursel = box.GetSelectedIndex();
  65. if (cursel == -1) return;
  66. _carpeer = box.GetItemData(cursel);
  67. _control->OnCarConnect(_carpeer);
  68. }
  69. void CMainDlg::OnCarLeave(WORD, WORD, HWND)
  70. {
  71. _control->OnCarLeave();
  72. _carpeer = -1;
  73. }
  74. void CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND)
  75. {
  76. EndDialog(wID);
  77. }
  78. void CMainDlg::OnSigin(bool bRet)
  79. {
  80. PostMessage(WM_NOTIFYSIGIN, (WPARAM)bRet);
  81. }
  82. void CMainDlg::OnRobot(std::unique_ptr<UserCamera>& node)
  83. {
  84. CListViewCtrl box;
  85. box.Attach(GetDlgItem(IDC_CARLIST));
  86. std::string info = node->name;
  87. switch (node->state)
  88. {
  89. case UserState::Busy:
  90. info += " (busy)";
  91. break;
  92. case UserState::Offline:
  93. info += " (offline)";
  94. break;
  95. case UserState::Online:
  96. info += " (online)";
  97. break;
  98. }
  99. int32_t index = box.AddItem(0, 0, info.c_str());
  100. //box.SetItemText(index, 1, robot.type() == EgoType::Car ? "Car" : "Cave");
  101. auto users = std::make_unique<UserCamera>();
  102. users->uid = node->uid;
  103. users->name = info;
  104. users->type = static_cast<EgoType>(node->type);
  105. users->state = static_cast<UserState>(node->state);
  106. // for (int32_t i = 0; i < robot.info().size(); i++)
  107. // {
  108. // auto& node = robot.info(i);
  109. // CameraInfo camera;
  110. // camera.index = static_cast<RenderPosition>(node.pos());
  111. // camera.label = node.label();
  112. // camera.solution = static_cast<DisplayResolution>(node.solution());
  113. // users->info.push_back(camera);
  114. // }
  115. box.SetItemData(index, users->uid);
  116. _userInfo.push_back(std::move(users));
  117. }
  118. void CMainDlg::OnNotifyDel(int32_t peer)
  119. {
  120. CListViewCtrl box;
  121. box.Attach(GetDlgItem(IDC_CARLIST));
  122. int32_t Count = box.GetItemCount();
  123. for (int32_t i = 0; i < Count; i++)
  124. {
  125. auto id = box.GetItemData(i);
  126. if (id == peer)
  127. {
  128. box.DeleteItem(i);
  129. break;
  130. }
  131. }
  132. for (auto it = _userInfo.begin(); it != _userInfo.end(); ++it)
  133. {
  134. if ((*it)->uid == peer)
  135. {
  136. _userInfo.erase(it);
  137. break;
  138. }
  139. }
  140. }
  141. void CMainDlg::OnNotifyPing(int32_t value)
  142. {
  143. }
  144. void CMainDlg::OnNotifyRadar(int32_t r0, int32_t r1, int32_t r2, int32_t r3, int32_t r4, int32_t r5)
  145. {
  146. }
  147. void CMainDlg::OnNotifyKickOff()
  148. {
  149. }