| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- /**************************************************************************************************
- 版本所有(C), 2020-2022, 北京普达迪泰
- ***************************************************************************************************
- 文 件 名: OSGView.cpp
- 功能描述: OSG视图封装类
- 版 本 号: 1.00初版
- 作 者: HYF
- 生成日期; 2021-12-20
- 最近修改:
- 函数列表:
- 修改历史:
- 1.日 期 :2021-12-20
- 作 者 : HYF
- 修改内容 : 创建文件
- **************************************************************************************************/
- // OSGView.cpp: 实现文件
- #include "pch.h"
- #include "DMS.h"
- #include "OSGView.h"
- #include "CoreOSG.h"
- #include <vector>
- // OSGView
- IMPLEMENT_DYNCREATE(OSGView, CView)
- OSGView::OSGView()
- :m_pOSG(NULL)
- {
- }
- OSGView::~OSGView()
- {
- if (m_pOSG != NULL)
- {
- delete m_pOSG;
- m_pOSG = NULL;
- }
- }
- BEGIN_MESSAGE_MAP(OSGView, CView)
- ON_WM_CREATE()
- ON_WM_ERASEBKGND()
- ON_WM_KEYDOWN()
- ON_WM_DESTROY()
- END_MESSAGE_MAP()
- // OSGView 绘图
- void OSGView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- }
- // OSGView 诊断
- #ifdef _DEBUG
- void OSGView::AssertValid() const
- {
- CView::AssertValid();
- }
- #ifndef _WIN32_WCE
- void OSGView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif
- #endif //_DEBUG
- // OSGView 消息处理程序
- int OSGView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- m_pOSG = new CoreOSG(this->m_hWnd);
- return 1;
- }
- // 初始化
- void OSGView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
- }
- // 背景
- BOOL OSGView::OnEraseBkgnd(CDC* pDC)
- {
- return TRUE;
- }
- /**************************************************************************************************
- 函 数 名 :LoadOSG
- 功能描述 :加载模型文件
- 输入参数 :略
- 输出参数 :略
- 返 回 值 :略
- **************************************************************************************************/
- BOOL OSGView::LoadOSG(LPCTSTR szEquipTypeCode, CStringArray& arrModel)
- {
- m_arrModel.RemoveAll();
- m_arrModel.SetSize(arrModel.GetCount());
-
- CString szPath = Utils::GetLocalUrlDir();
- szPath.Append("/Model/");
- szPath.Append(szEquipTypeCode);
- szPath.Append("/");
- std::vector<string> vecPath;
- BOOL bModelExist = true;
- for (int i = 0; i < arrModel.GetCount(); i++)
- {
- CString szModel = arrModel.GetAt(i);
- m_arrModel.SetAt(i, szModel);
- CString szModelPath(szPath);
- szModelPath.Append(szModel);
- szModelPath.Append(".OSGB");
- bModelExist = Utils::IsFileExist(szModelPath);
- if (!bModelExist) {
- MessageBox(_T("模型文件不完整,请联系管理员!"));
- return FALSE;
- }
- LOG::D(szModelPath);
- vecPath.push_back(szModelPath.GetBuffer());
- }
- CString szAxesPath(szPath);
- szAxesPath.Append("axes.osgt");
- // 加载模型
- m_pOSG->LoadModel(vecPath, szAxesPath.GetBuffer());
- // 启动渲染线程
- m_pRenderThread = new RenderingThread(m_pOSG);
- m_pRenderThread->start();
- return TRUE;
- }
- /**************************************************************************************************
- 函 数 名 :OnKeyDown
- 功能描述 :WM_OnKeyDown消息处理
- 输入参数 :略
- 输出参数 :略
- 返 回 值 :略
- **************************************************************************************************/
- void OSGView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- m_pOSG->getViewer()->getEventQueue()->keyPress(nChar);
- }
- /**************************************************************************************************
- 函 数 名 :Terminate
- 功能描述 :终止展示
- 输入参数 :略
- 输出参数 :略
- 返 回 值 :略
- **************************************************************************************************/
- void OSGView::Terminate()
- {
- if (m_pRenderThread != NULL)
- {
- m_pRenderThread->Done(true);
- //m_pRenderThread->cancel();
- while (m_pRenderThread->isRunning()) {
- OpenThreads::Thread::YieldCurrentThread();
- }
-
- //delete m_pRenderThread;
- //m_pRenderThread = NULL;
- }
- //m_pOSG->ReleaseViewer();
- }
- /**************************************************************************************************
- 函 数 名 :OnDestroy
- 功能描述 :WM_DESTORY消息处理
- 输入参数 :略
- 输出参数 :略
- 返 回 值 :略
- **************************************************************************************************/
- void OSGView::OnDestroy()
- {
- if (m_pRenderThread != NULL)
- {
- m_pRenderThread->Done(true);
- delete m_pRenderThread;
- m_pRenderThread = NULL;
- }
- if (m_pOSG != NULL)
- {
- m_pOSG->Done(true);
- m_pOSG->ReleaseViewer();
- m_pOSG->Release();
- delete (CoreOSG *)m_pOSG;
- m_pOSG = NULL;
- }
-
- CView::OnDestroy();
- }
- /**************************************************************************************************
- 函 数 名 :RotateCurModel
- 功能描述 :旋转角度
- 输入参数 :略
- 输出参数 :略
- 返 回 值 :略
- **************************************************************************************************/
- void OSGView::RotateCurModel(const double fx, const double fy, const double fz)
- {
- if (m_pOSG != NULL)
- {
- m_pOSG->m_pModelRotateCallback->setRotateAnglexyz(fx, fy, fz);
- }
- }
- /**************************************************************************************************
- 函 数 名 :SetCurPlace
- 功能描述 :切换分机
- 输入参数 :iMearObj 表示当前要测试的发动机 0表示左发动机 1表示右发动机
- 输出参数 :略
- 返 回 值 :略
- **************************************************************************************************/
- void OSGView::SetCurEquipPlace(LPCTSTR szEquipPlace)
- {
- for (int i = 0; i < m_arrModel.GetCount(); i++)
- {
- CString szModel = m_arrModel.GetAt(i);
- if (szModel.Compare(szEquipPlace) == 0)
- {
- m_pOSG->VibrateEngine(i);
- }
- }
- }
|