OSGView.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**************************************************************************************************
  2. 版本所有(C), 2020-2022, 北京普达迪泰
  3. ***************************************************************************************************
  4. 文 件 名: OSGView.cpp
  5. 功能描述: OSG视图封装类
  6. 版 本 号: 1.00初版
  7. 作 者: HYF
  8. 生成日期; 2021-12-20
  9. 最近修改:
  10. 函数列表:
  11. 修改历史:
  12. 1.日 期 :2021-12-20
  13. 作 者 : HYF
  14. 修改内容 : 创建文件
  15. **************************************************************************************************/
  16. // OSGView.cpp: 实现文件
  17. #include "pch.h"
  18. #include "DMS.h"
  19. #include "OSGView.h"
  20. #include "CoreOSG.h"
  21. #include <vector>
  22. // OSGView
  23. IMPLEMENT_DYNCREATE(OSGView, CView)
  24. OSGView::OSGView()
  25. :m_pOSG(NULL)
  26. {
  27. }
  28. OSGView::~OSGView()
  29. {
  30. if (m_pOSG != NULL)
  31. {
  32. delete m_pOSG;
  33. m_pOSG = NULL;
  34. }
  35. }
  36. BEGIN_MESSAGE_MAP(OSGView, CView)
  37. ON_WM_CREATE()
  38. ON_WM_ERASEBKGND()
  39. ON_WM_KEYDOWN()
  40. ON_WM_DESTROY()
  41. END_MESSAGE_MAP()
  42. // OSGView 绘图
  43. void OSGView::OnDraw(CDC* pDC)
  44. {
  45. CDocument* pDoc = GetDocument();
  46. }
  47. // OSGView 诊断
  48. #ifdef _DEBUG
  49. void OSGView::AssertValid() const
  50. {
  51. CView::AssertValid();
  52. }
  53. #ifndef _WIN32_WCE
  54. void OSGView::Dump(CDumpContext& dc) const
  55. {
  56. CView::Dump(dc);
  57. }
  58. #endif
  59. #endif //_DEBUG
  60. // OSGView 消息处理程序
  61. int OSGView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  62. {
  63. if (CView::OnCreate(lpCreateStruct) == -1)
  64. return -1;
  65. m_pOSG = new CoreOSG(this->m_hWnd);
  66. return 1;
  67. }
  68. // 初始化
  69. void OSGView::OnInitialUpdate()
  70. {
  71. CView::OnInitialUpdate();
  72. }
  73. // 背景
  74. BOOL OSGView::OnEraseBkgnd(CDC* pDC)
  75. {
  76. return TRUE;
  77. }
  78. /**************************************************************************************************
  79. 函 数 名 :LoadOSG
  80. 功能描述 :加载模型文件
  81. 输入参数 :略
  82. 输出参数 :略
  83. 返 回 值 :略
  84. **************************************************************************************************/
  85. BOOL OSGView::LoadOSG(LPCTSTR szEquipTypeCode, CStringArray& arrModel)
  86. {
  87. m_arrModel.RemoveAll();
  88. m_arrModel.SetSize(arrModel.GetCount());
  89. CString szPath = Utils::GetLocalUrlDir();
  90. szPath.Append("/Model/");
  91. szPath.Append(szEquipTypeCode);
  92. szPath.Append("/");
  93. std::vector<string> vecPath;
  94. BOOL bModelExist = true;
  95. for (int i = 0; i < arrModel.GetCount(); i++)
  96. {
  97. CString szModel = arrModel.GetAt(i);
  98. m_arrModel.SetAt(i, szModel);
  99. CString szModelPath(szPath);
  100. szModelPath.Append(szModel);
  101. szModelPath.Append(".OSGB");
  102. bModelExist = Utils::IsFileExist(szModelPath);
  103. if (!bModelExist) {
  104. MessageBox(_T("模型文件不完整,请联系管理员!"));
  105. return FALSE;
  106. }
  107. LOG::D(szModelPath);
  108. vecPath.push_back(szModelPath.GetBuffer());
  109. }
  110. CString szAxesPath(szPath);
  111. szAxesPath.Append("axes.osgt");
  112. // 加载模型
  113. m_pOSG->LoadModel(vecPath, szAxesPath.GetBuffer());
  114. // 启动渲染线程
  115. m_pRenderThread = new RenderingThread(m_pOSG);
  116. m_pRenderThread->start();
  117. return TRUE;
  118. }
  119. /**************************************************************************************************
  120. 函 数 名 :OnKeyDown
  121. 功能描述 :WM_OnKeyDown消息处理
  122. 输入参数 :略
  123. 输出参数 :略
  124. 返 回 值 :略
  125. **************************************************************************************************/
  126. void OSGView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  127. {
  128. m_pOSG->getViewer()->getEventQueue()->keyPress(nChar);
  129. }
  130. /**************************************************************************************************
  131. 函 数 名 :Terminate
  132. 功能描述 :终止展示
  133. 输入参数 :略
  134. 输出参数 :略
  135. 返 回 值 :略
  136. **************************************************************************************************/
  137. void OSGView::Terminate()
  138. {
  139. if (m_pRenderThread != NULL)
  140. {
  141. m_pRenderThread->Done(true);
  142. //m_pRenderThread->cancel();
  143. while (m_pRenderThread->isRunning()) {
  144. OpenThreads::Thread::YieldCurrentThread();
  145. }
  146. //delete m_pRenderThread;
  147. //m_pRenderThread = NULL;
  148. }
  149. //m_pOSG->ReleaseViewer();
  150. }
  151. /**************************************************************************************************
  152. 函 数 名 :OnDestroy
  153. 功能描述 :WM_DESTORY消息处理
  154. 输入参数 :略
  155. 输出参数 :略
  156. 返 回 值 :略
  157. **************************************************************************************************/
  158. void OSGView::OnDestroy()
  159. {
  160. if (m_pRenderThread != NULL)
  161. {
  162. m_pRenderThread->Done(true);
  163. delete m_pRenderThread;
  164. m_pRenderThread = NULL;
  165. }
  166. if (m_pOSG != NULL)
  167. {
  168. m_pOSG->Done(true);
  169. m_pOSG->ReleaseViewer();
  170. m_pOSG->Release();
  171. delete (CoreOSG *)m_pOSG;
  172. m_pOSG = NULL;
  173. }
  174. CView::OnDestroy();
  175. }
  176. /**************************************************************************************************
  177. 函 数 名 :RotateCurModel
  178. 功能描述 :旋转角度
  179. 输入参数 :略
  180. 输出参数 :略
  181. 返 回 值 :略
  182. **************************************************************************************************/
  183. void OSGView::RotateCurModel(const double fx, const double fy, const double fz)
  184. {
  185. if (m_pOSG != NULL)
  186. {
  187. m_pOSG->m_pModelRotateCallback->setRotateAnglexyz(fx, fy, fz);
  188. }
  189. }
  190. /**************************************************************************************************
  191. 函 数 名 :SetCurPlace
  192. 功能描述 :切换分机
  193. 输入参数 :iMearObj 表示当前要测试的发动机 0表示左发动机 1表示右发动机
  194. 输出参数 :略
  195. 返 回 值 :略
  196. **************************************************************************************************/
  197. void OSGView::SetCurEquipPlace(LPCTSTR szEquipPlace)
  198. {
  199. for (int i = 0; i < m_arrModel.GetCount(); i++)
  200. {
  201. CString szModel = m_arrModel.GetAt(i);
  202. if (szModel.Compare(szEquipPlace) == 0)
  203. {
  204. m_pOSG->VibrateEngine(i);
  205. }
  206. }
  207. }