MainFrm.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:43k
源码类别:

界面编程

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "GLViews.h"
  5. #include "MainFrm.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. static struct
  12. {
  13. GLfloat
  14. m_fLocalTranslationX,
  15. m_fLocalTranslationY,
  16. m_fLocalTranslationZ,
  17. m_fLocalAngleRadsPitch,
  18. m_fLocalAngleRadsYaw,
  19. m_fLocalAngleRadsRoll;
  20. } g_arrInitCameraData[ GL_VIEWS_CAMERA_COUNT ] =
  21. {
  22. {     0.00f,   0.00f,   0.04f,       -0.0f,  -0.0f,  0.0f    },    //  0
  23. {     0.20f,   0.20f,   0.20f,        0.7f,  -0.4f,  0.0f    },    //  1
  24. {    -0.10f,  -0.30f,  -0.10f,       -1.6f,   0.4f,  0.0f    },    //  2
  25. {    -0.20f,   0.00f,   0.20f,       -0.0f,   0.5f,  0.0f    },    //  3
  26. {     0.00f,  -0.20f,  -0.20f,       -0.8f,  -0.0f,  0.0f    },    //  4
  27. {     0.40f,   0.00f,   0.00f,       -0.0f,  -1.1f,  0.0f    },    //  5
  28. {     0.31f,  -0.15f,   0.00f,       -0.3f,  -1.2f,  0.0f    },    //  6
  29. {    -0.15f,   0.31f,   0.00f,        1.2f,   0.6f,  0.0f    },    //  7
  30. {     0.28f,  -0.09f,   0.24f,       -1.4f,  -1.5f,  0.0f    },    //  8
  31. {    -0.09f,   0.31f,  -0.05f,        1.7f,  -0.0f,  0.0f    },    //  9
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CSimpleSplashWnd
  35. static bool g_bSplashWndClassRegistered = false;
  36. CSimpleSplashWnd::CSimpleSplashWnd()
  37. : m_sStatusText( _T("Initializing ...") )
  38. {
  39. VERIFY( RegisterSplashWndClass() );
  40. }
  41. CSimpleSplashWnd::CSimpleSplashWnd(
  42. CWnd * pWndParent,
  43. UINT nBitmapID
  44. )
  45. : m_sStatusText( _T("Initializing ...") )
  46. {
  47. VERIFY( Create( pWndParent, nBitmapID ) );
  48. }
  49. CSimpleSplashWnd::~CSimpleSplashWnd()
  50. {
  51. }
  52. BEGIN_MESSAGE_MAP(CSimpleSplashWnd, CWnd)
  53. //{{AFX_MSG_MAP(CSimpleSplashWnd)
  54. ON_WM_ERASEBKGND()
  55. ON_WM_PAINT()
  56. ON_WM_NCCALCSIZE()
  57. __EXT_MFC_ON_WM_NCHITTEST()
  58. ON_WM_CLOSE()
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CSimpleSplashWnd message handlers
  63. void CSimpleSplashWnd::SetStatusText(
  64. LPCTSTR sStatusText
  65. )
  66. {
  67. ASSERT_VALID( this );
  68. ASSERT( GetSafeHwnd() != NULL );
  69. ASSERT( ::IsWindow( GetSafeHwnd() ) );
  70. LPCTSTR sText = (sStatusText == NULL) ? _T("") : sStatusText;
  71. if( m_sStatusText == sText )
  72. return;
  73. m_sStatusText = sText;
  74. if( (GetStyle() & WS_VISIBLE) == 0 )
  75. return;
  76. Invalidate();
  77. UpdateWindow();
  78. }
  79. bool CSimpleSplashWnd::Create(
  80. CWnd * pWndParent,
  81. UINT nBitmapID
  82. )
  83. {
  84. ASSERT_VALID( this );
  85. ASSERT( GetSafeHwnd() == NULL );
  86. ASSERT( m_bitmap.GetSafeHandle() == NULL );
  87. if( ! RegisterSplashWndClass() )
  88. {
  89. ASSERT( FALSE );
  90. return false;
  91. }
  92. if( ! m_bitmap.LoadBitmap(nBitmapID) )
  93. {
  94. ASSERT( FALSE );
  95. return false;
  96. }
  97. BITMAP _bmpInfo;
  98. ::memset( &_bmpInfo, 0, sizeof(BITMAP) );
  99. m_bitmap.GetBitmap( &_bmpInfo );
  100. m_sizeBitmap.cx = _bmpInfo.bmWidth;
  101. m_sizeBitmap.cy = _bmpInfo.bmHeight;
  102. CRect rcDesktop;
  103. VERIFY( ::SystemParametersInfo( SPI_GETWORKAREA, 0, PVOID(&rcDesktop), 0 ) );
  104. CRect rcWnd( 0, 0, m_sizeBitmap.cx, m_sizeBitmap.cy );
  105. rcWnd.OffsetRect(
  106. ( rcDesktop.Width() - m_sizeBitmap.cx ) / 2,
  107. ( rcDesktop.Height() - m_sizeBitmap.cy ) / 2
  108. );
  109. if( ! m_wndInvisibleParent.CreateEx( 0, _T("STATIC"), _T(""), WS_POPUP, 0,0,0,0, pWndParent->GetSafeHwnd(), (HMENU)NULL ) )
  110. {
  111. ASSERT( FALSE );
  112. m_bitmap.DeleteObject();
  113. return false;
  114. }
  115. if( ! CWnd::CreateEx(
  116. 0, GL_VIEWS_SPLASHWND_WNDCLASS, _T("GLViews initizlizing ..."), WS_POPUP,
  117. rcWnd.left, rcWnd.top, m_sizeBitmap.cx, m_sizeBitmap.cy,
  118. m_wndInvisibleParent.GetSafeHwnd(), (HMENU)NULL
  119. )
  120. )
  121. {
  122. ASSERT( FALSE );
  123. m_bitmap.DeleteObject();
  124. m_wndInvisibleParent.DestroyWindow();
  125. return false;
  126. }
  127. VERIFY(
  128. ::SetWindowPos(
  129. m_hWnd, HWND_TOP, 0, 0, 0, 0,
  130. SWP_NOSIZE|SWP_NOMOVE|SWP_SHOWWINDOW|SWP_NOACTIVATE|SWP_NOOWNERZORDER
  131. )
  132. );
  133. CExtPopupMenuWnd::PassMsgLoop( false );
  134. return true;
  135. }
  136. BOOL CSimpleSplashWnd::OnEraseBkgnd(CDC* pDC) 
  137. {
  138. pDC;
  139. return TRUE;
  140. }
  141. void CSimpleSplashWnd::OnPaint() 
  142. {
  143. ASSERT( m_bitmap.GetSafeHandle() != NULL );
  144. CPaintDC dcPaint( this );
  145. CDC dcMem;
  146. if( !dcMem.CreateCompatibleDC( &dcPaint ) )
  147. {
  148. ASSERT( FALSE );
  149. return;
  150. }
  151. CBitmap * pOldBmp = dcMem.SelectObject( &m_bitmap );
  152. dcPaint.BitBlt(
  153. 0, 0, m_sizeBitmap.cx, m_sizeBitmap.cy,
  154. &dcMem,
  155. 0, 0,
  156. SRCCOPY
  157. );
  158. if( !m_sStatusText.IsEmpty() )
  159. {
  160. CRect rcText;
  161. GetClientRect( &rcText );
  162. rcText.bottom -= 6;
  163. rcText.top = rcText.bottom - 48;
  164. rcText.DeflateRect( 16, 0 );
  165. int nOldBkMode = dcPaint.SetBkMode( TRANSPARENT );
  166. COLORREF clrTextOld = dcPaint.SetTextColor( RGB(0,0,0) );
  167. CFont * pOldFont = dcPaint.SelectObject( &g_PaintManager->m_FontNormal );
  168. dcPaint.DrawText(
  169. m_sStatusText,
  170. &rcText,
  171. DT_SINGLELINE|DT_CENTER|DT_VCENTER|DT_END_ELLIPSIS  
  172. );
  173. dcPaint.SelectObject( pOldFont );
  174. dcPaint.SetTextColor( clrTextOld );
  175. dcPaint.SetBkMode( nOldBkMode );
  176. } // if( !m_sStatusText.IsEmpty() )
  177. dcMem.SelectObject( pOldBmp );
  178. }
  179. void CSimpleSplashWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
  180. {
  181. bCalcValidRects;
  182. lpncsp;
  183. }
  184. UINT CSimpleSplashWnd::OnNcHitTest(CPoint point) 
  185. {
  186. point;
  187. return HTCLIENT;
  188. }
  189. void CSimpleSplashWnd::OnClose() 
  190. {
  191. }
  192. BOOL CSimpleSplashWnd::PreCreateWindow(CREATESTRUCT& cs) 
  193. {
  194. if( ( !RegisterSplashWndClass() )
  195. || ( !CWnd::PreCreateWindow(cs) )
  196. )
  197. {
  198. ASSERT( FALSE );
  199. return FALSE;
  200. }
  201. cs.lpszClass = GL_VIEWS_SPLASHWND_WNDCLASS;
  202. return TRUE;
  203. }
  204. bool CSimpleSplashWnd::RegisterSplashWndClass()
  205. {
  206. if( g_bSplashWndClassRegistered )
  207. return true;
  208. WNDCLASS _wndClassInfo;
  209. HINSTANCE hInst = AfxGetInstanceHandle();
  210. if( ! ::GetClassInfo(
  211. hInst,
  212. GL_VIEWS_SPLASHWND_WNDCLASS,
  213. &_wndClassInfo
  214. )
  215. )
  216. {
  217. // otherwise we need to register a new class
  218. _wndClassInfo.style =
  219. CS_GLOBALCLASS
  220. //|CS_DBLCLKS
  221. |CS_HREDRAW|CS_VREDRAW
  222. |CS_NOCLOSE
  223. |CS_SAVEBITS
  224. ;
  225. _wndClassInfo.lpfnWndProc = ::DefWindowProc;
  226. _wndClassInfo.cbClsExtra = _wndClassInfo.cbWndExtra = 0;
  227. _wndClassInfo.hInstance = hInst;
  228. _wndClassInfo.hIcon = NULL;
  229. _wndClassInfo.hCursor =
  230. ::LoadCursor(
  231. NULL, //hInst,
  232. IDC_WAIT
  233. )
  234. ;
  235. ASSERT( _wndClassInfo.hCursor != NULL );
  236. _wndClassInfo.hbrBackground = NULL; 
  237. _wndClassInfo.lpszMenuName = NULL;
  238. _wndClassInfo.lpszClassName = GL_VIEWS_SPLASHWND_WNDCLASS;
  239. if( !::AfxRegisterClass( &_wndClassInfo ) )
  240. {
  241. ASSERT( FALSE );
  242. //AfxThrowResourceException();
  243. return false;
  244. }
  245. }
  246. g_bSplashWndClassRegistered = true;
  247. return true;
  248. }
  249. BOOL CSimpleSplashWnd::DestroyWindow() 
  250. {
  251. ShowWindow( SW_HIDE );
  252. CExtPopupMenuWnd::PassMsgLoop( false );
  253. CWnd::DestroyWindow();
  254. if( m_wndInvisibleParent.GetSafeHwnd() != NULL )
  255. m_wndInvisibleParent.DestroyWindow();
  256. return TRUE;
  257. }
  258. /////////////////////////////////////////////////////////////////////////////
  259. // CSimpleHtmlCtrl
  260. CSimpleHtmlCtrl::CSimpleHtmlCtrl()
  261. : m_pBrowser( NULL )
  262. {
  263. }
  264. CSimpleHtmlCtrl::~CSimpleHtmlCtrl()
  265. {
  266. }
  267. BEGIN_MESSAGE_MAP(CSimpleHtmlCtrl, CWnd)
  268. //{{AFX_MSG_MAP(CSimpleHtmlCtrl)
  269. //}}AFX_MSG_MAP
  270. END_MESSAGE_MAP()
  271. /////////////////////////////////////////////////////////////////////////////
  272. // CSimpleHtmlCtrl message handlers
  273. bool CSimpleHtmlCtrl::Create( CWnd * pWndParent )
  274. {
  275. UINT nID = pWndParent->GetDlgCtrlID();
  276. CString sWindowName;
  277. pWndParent->GetWindowText( sWindowName );
  278. if( ! CreateControl(
  279. CLSID_WebBrowser,
  280. LPCTSTR(sWindowName),
  281. WS_VISIBLE|WS_CHILD,
  282. CRect(0,0,0,0),
  283. pWndParent,
  284. nID
  285. )
  286. )
  287. { // if IWebBrowser2 is not created successfully
  288. ASSERT( FALSE );
  289. DestroyWindow();
  290. return false;
  291. } // if IWebBrowser2 is not created successfully
  292. LPUNKNOWN lpUnk = GetControlUnknown();
  293. ASSERT( lpUnk != NULL );
  294. HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowser);
  295. if( FAILED(hr) )
  296. {
  297. ASSERT( FALSE );
  298. DestroyWindow();
  299. return false;
  300. }
  301. return true;
  302. }
  303. void CSimpleHtmlCtrl::NavigateURL( LPCTSTR lpszURL )
  304. {
  305. ASSERT_VALID( this );
  306. ASSERT( m_pBrowser != NULL );
  307. COleSafeArray vPostData;
  308. COleVariant vURL( lpszURL, VT_BSTR );
  309. COleVariant vHeaders( LPCTSTR(NULL), VT_BSTR);
  310. COleVariant vTargetFrameName( LPCTSTR(NULL), VT_BSTR );
  311. COleVariant vFlags( 0L, VT_I4 );
  312. m_pBrowser->Navigate2(
  313. vURL,
  314. vFlags,
  315. vTargetFrameName,
  316. vPostData,
  317. vHeaders
  318. );
  319. }
  320. void CSimpleHtmlCtrl::NavigateResourceID(
  321. UINT nResourceID
  322. )
  323. {
  324. ASSERT_VALID( this );
  325. ASSERT( m_pBrowser != NULL );
  326. CString sAppName;
  327. ::GetModuleFileName(
  328. NULL,
  329. sAppName.GetBuffer( _MAX_PATH + 1 ),
  330. _MAX_PATH
  331. );
  332. sAppName.ReleaseBuffer();
  333. CString sResourseID;
  334. sResourseID.Format( _T("%d"), INT(nResourceID) );
  335. CString sNavigatePath;
  336. sNavigatePath =
  337. _T("res://")
  338. + sAppName
  339. + _T("/") //+ _T(".exe/")
  340. + sResourseID
  341. ;
  342. NavigateURL( sNavigatePath );
  343. }
  344. /////////////////////////////////////////////////////////////////////////////
  345. // CMainFrame
  346. IMPLEMENT_DYNAMIC( CMainFrame, CFrameWnd )
  347. BEGIN_MESSAGE_MAP( CMainFrame, CFrameWnd )
  348. //{{AFX_MSG_MAP(CMainFrame)
  349. ON_WM_CREATE()
  350. ON_WM_SETFOCUS()
  351. ON_COMMAND(ID_ANIMATE, OnAnimate)
  352. ON_UPDATE_COMMAND_UI(ID_ANIMATE, OnUpdateAnimate)
  353. ON_COMMAND(ID_SHOW_CAMERAS, OnShowCameras)
  354. ON_UPDATE_COMMAND_UI(ID_SHOW_CAMERAS, OnUpdateShowCameras)
  355. ON_COMMAND(ID_SHOW_MIRROR, OnShowMirror)
  356. ON_UPDATE_COMMAND_UI(ID_SHOW_MIRROR, OnUpdateShowMirror)
  357. ON_COMMAND(ID_SHOW_AVI_PLAYER, OnShowAviPlayer)
  358. ON_UPDATE_COMMAND_UI(ID_SHOW_AVI_PLAYER, OnUpdateShowAviPlayer)
  359. ON_COMMAND(ID_RESET_CAMERAS, OnResetCameras)
  360. ON_COMMAND(ID_SHOW_OUTER_OBJECTS, OnShowOuterObjects)
  361. ON_UPDATE_COMMAND_UI(ID_SHOW_OUTER_OBJECTS, OnUpdateShowOuterObjects)
  362. ON_COMMAND(ID_SHOW_TEXT_OBJECTS, OnShowTextObjects)
  363. ON_UPDATE_COMMAND_UI(ID_SHOW_TEXT_OBJECTS, OnUpdateShowTextObjects)
  364. ON_COMMAND(ID_SHOW_CUBE_OBJECTS, OnShowCubeObjects)
  365. ON_UPDATE_COMMAND_UI(ID_SHOW_CUBE_OBJECTS, OnUpdateShowCubeObjects)
  366. ON_COMMAND(ID_SHOW_PLANET_OBJECTS, OnShowPlanetObjects)
  367. ON_UPDATE_COMMAND_UI(ID_SHOW_PLANET_OBJECTS, OnUpdateShowPlanetObjects)
  368. //}}AFX_MSG_MAP
  369. ON_COMMAND_EX(ID_VIEW_MENUBAR, OnBarCheck )
  370. ON_UPDATE_COMMAND_UI(ID_VIEW_MENUBAR, OnUpdateControlBarMenu)
  371. ON_COMMAND_EX(ID_VIEW_BAR_CAM0, OnBarCheck )
  372. ON_UPDATE_COMMAND_UI(ID_VIEW_BAR_CAM0, OnUpdateControlBarMenu)
  373. ON_COMMAND_EX(ID_VIEW_BAR_CAM1, OnBarCheck )
  374. ON_UPDATE_COMMAND_UI(ID_VIEW_BAR_CAM1, OnUpdateControlBarMenu)
  375. ON_COMMAND_EX(ID_VIEW_BAR_TREE, OnBarCheck )
  376. ON_UPDATE_COMMAND_UI(ID_VIEW_BAR_TREE, OnUpdateControlBarMenu)
  377. ON_COMMAND_EX(ID_VIEW_BAR_HELP, OnBarCheck )
  378. ON_UPDATE_COMMAND_UI(ID_VIEW_BAR_HELP, OnUpdateControlBarMenu)
  379. ON_COMMAND_EX(ID_VIEW_UI_LOOK_BAR, OnBarCheck )
  380. ON_UPDATE_COMMAND_UI(ID_VIEW_UI_LOOK_BAR, OnUpdateControlBarMenu)
  381. END_MESSAGE_MAP()
  382. static UINT indicators[] =
  383. {
  384. ID_SEPARATOR,           // status line indicator
  385. ID_INDICATOR_CAPS,
  386. ID_INDICATOR_NUM,
  387. ID_INDICATOR_SCRL,
  388. };
  389. /////////////////////////////////////////////////////////////////////////////
  390. // CMainFrame construction/destruction
  391. CMainFrame::CMainFrame()
  392. : m_wndViewCamMain( IDC_CURSOR_GL_GREEN )
  393. , m_wndViewCam0( IDC_CURSOR_GL_RED )
  394. , m_wndViewCam1( IDC_CURSOR_GL_BLUE )
  395. {
  396. CWinApp * pApp = ::AfxGetApp();
  397. ASSERT( pApp != NULL );
  398. ASSERT( pApp->m_pszRegistryKey != NULL );
  399. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  400. ASSERT( pApp->m_pszProfileName != NULL );
  401. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  402. if( ! g_PaintManager.PaintManagerStateLoad(
  403. pApp->m_pszRegistryKey,
  404. pApp->m_pszProfileName,
  405. pApp->m_pszProfileName
  406. )
  407. )
  408. g_PaintManager.InstallPaintManager(
  409. RUNTIME_CLASS(CExtPaintManagerOffice2010_R1)
  410. );
  411. CExtPopupMenuWnd::g_bMenuExpanding = false;
  412. CExtPopupMenuWnd::g_bMenuHighlightRarely = false;
  413. if( ! g_PaintManager.m_bIsWin2000orLater )
  414. CExtPopupMenuWnd::g_bMenuWithShadows = false;
  415. // window placement persistence
  416. ::memset( &m_dataFrameWP, 0, sizeof(WINDOWPLACEMENT) );
  417. m_dataFrameWP.length = sizeof(WINDOWPLACEMENT);
  418. m_dataFrameWP.showCmd = SW_HIDE;
  419. }
  420. CMainFrame::~CMainFrame()
  421. {
  422. }
  423. void CMainFrame::OnUpdateControlBarMenu(CCmdUI* pCmdUI)
  424. {
  425. CExtControlBar::DoFrameBarCheckUpdate(
  426. this,
  427. pCmdUI,
  428. false
  429. );
  430. }
  431. BOOL CMainFrame::OnBarCheck(UINT nID)
  432. {
  433. return
  434. CExtControlBar::DoFrameBarCheckCmd(
  435. this,
  436. nID,
  437. false
  438. );
  439. }
  440. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  441. {
  442. if( CExtNCW < CFrameWnd > :: OnCreate( lpCreateStruct ) == -1 )
  443. {
  444. ASSERT( FALSE );
  445. return -1;
  446. }
  447. CSimpleSplashWnd _splash( this, IDB_BITMAP_SPLASH );
  448. _splash.SetStatusText(
  449. _T("Initializing the Command Manager ...")
  450. );
  451. HINSTANCE hInst = ::AfxGetInstanceHandle();
  452. HICON hIcon =
  453. ::LoadIcon(
  454. hInst,
  455. MAKEINTRESOURCE(IDR_MAINFRAME)
  456. );
  457. ASSERT( hIcon != NULL );
  458. SetIcon( hIcon, TRUE );
  459. hIcon = (HICON)
  460. ::LoadImage(
  461. hInst,
  462. MAKEINTRESOURCE(IDR_MAINFRAME),
  463. IMAGE_ICON,
  464. 16,
  465. 16,
  466. 0
  467. );
  468. ASSERT( hIcon != NULL );
  469. SetIcon( hIcon, FALSE );
  470. CWinApp * pApp = ::AfxGetApp();
  471. ASSERT( pApp != NULL );
  472. ASSERT( pApp->m_pszRegistryKey != NULL );
  473. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  474. ASSERT( pApp->m_pszProfileName != NULL );
  475. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  476. ASSERT( pApp->m_pszProfileName != NULL );
  477. g_CmdManager->ProfileSetup(
  478. pApp->m_pszProfileName,
  479. GetSafeHwnd()
  480. );
  481. VERIFY(
  482. g_CmdManager->UpdateFromMenu(
  483. pApp->m_pszProfileName,
  484. IDR_MAINFRAME
  485. )
  486. );
  487. VERIFY(
  488. g_CmdManager->UpdateFromMenu(
  489. pApp->m_pszProfileName,
  490. IDR_MENU_CAM_ROTATE
  491. )
  492. );
  493. VERIFY(
  494. g_CmdManager->UpdateFromMenu(
  495. pApp->m_pszProfileName,
  496. IDR_MENU_CAM_TRANSLATE
  497. )
  498. );
  499. VERIFY(
  500. g_CmdManager->UpdateFromToolBar(
  501. pApp->m_pszProfileName,
  502. IDR_TOOLBAR_INVIEW
  503. )
  504. );
  505. VERIFY(
  506. g_CmdManager->UpdateFromToolBar(
  507. pApp->m_pszProfileName,
  508. IDR_TOOLBAR_HELPER_ICONS
  509. )
  510. );
  511. CExtCmdItem * pCmd =
  512. g_CmdManager->CmdGetPtr( pApp->m_pszProfileName, ID_BTN_MENU_ROTATION );
  513. ASSERT( pCmd != NULL );
  514. pCmd->m_sMenuText = _T("Camera &Rotation");
  515. pCmd =
  516. g_CmdManager->CmdGetPtr( pApp->m_pszProfileName, ID_BTN_MENU_TRANSLATION );
  517. ASSERT( pCmd != NULL );
  518. pCmd->m_sMenuText = _T("Camera &Translation");
  519. // create a view to occupy the client area of the frame
  520. _splash.SetStatusText(
  521. _T("Creating the user interface: main view ...")
  522. );
  523. if( !m_wndViewCamMain.Create(
  524. NULL,
  525. NULL,
  526. WS_CHILD|WS_VISIBLE,
  527. CRect( 0, 0, 0, 0 ),
  528. this,
  529. AFX_IDW_PANE_FIRST,
  530. NULL
  531. )
  532. )
  533. {
  534. ASSERT( FALSE );
  535. TRACE0("Failed to create view windown");
  536. return -1;
  537. }
  538. _splash.SetStatusText(
  539. _T("Creating the user interface: bars ...")
  540. );
  541. if( ! m_wndMenuBar.Create(
  542. NULL, // _T("Menu Bar"),
  543. this,
  544. ID_VIEW_MENUBAR
  545. )
  546. )
  547.     {
  548. ASSERT( FALSE );
  549.         TRACE0("Failed to create menubarn");
  550.         return -1;      // failed to create
  551.     }
  552. if( (! m_wndToolBarUiLook.Create( NULL, this, ID_VIEW_UI_LOOK_BAR ) )
  553. || (! m_wndToolBarUiLook.ThemeSwitcherInit() )
  554. )
  555.     {
  556. ASSERT( FALSE );
  557.         TRACE0("Failed to create menubarn");
  558.         return -1;      // failed to create
  559.     }
  560. _splash.SetStatusText(
  561. _T("Creating the user interface: dockable view 0 ...")
  562. );
  563. if( !m_wndResizableBar0.Create(
  564. NULL,
  565. this,
  566. ID_VIEW_BAR_CAM0
  567. )
  568. )
  569. {
  570. ASSERT( FALSE );
  571. TRACE0("Failed to create m_wndResizableBar0n");
  572. return -1; // fail to create
  573. }
  574. if( !m_wndViewCam0.Create(
  575. NULL,
  576. NULL,
  577. WS_CHILD|WS_VISIBLE,
  578. CRect( 0, 0, 0, 0 ),
  579. &m_wndResizableBar0,
  580. ID_VIEW_BAR_CAM0,
  581. NULL
  582. )
  583. )
  584. {
  585. ASSERT( FALSE );
  586. return -1; // fail to create
  587. }
  588. _splash.SetStatusText(
  589. _T("Creating the user interface: dockable view 1 ...")
  590. );
  591. if( !m_wndResizableBar1.Create(
  592. NULL,
  593. this,
  594. ID_VIEW_BAR_CAM1
  595. )
  596. )
  597. {
  598. ASSERT( FALSE );
  599. TRACE0("Failed to create m_wndResizableBar1n");
  600. return -1; // fail to create
  601. }
  602. if( !m_wndViewCam1.Create(
  603. NULL,
  604. NULL,
  605. WS_CHILD|WS_VISIBLE,
  606. CRect( 0, 0, 0, 0 ),
  607. &m_wndResizableBar1,
  608. ID_VIEW_BAR_CAM1,
  609. NULL
  610. )
  611. )
  612. {
  613. ASSERT( FALSE );
  614. return -1; // fail to create
  615. }
  616. _splash.SetStatusText(
  617. _T("Creating the user interface: hierarchy view ...")
  618. );
  619. if( !m_wndResizableBar2.Create(
  620. NULL,
  621. this,
  622. ID_VIEW_BAR_TREE
  623. )
  624. )
  625. {
  626. ASSERT( FALSE );
  627. TRACE0("Failed to create m_wndResizableBar2n");
  628. return -1; // fail to create
  629. }
  630. if( !m_wndObjectHierarchyTree.Create(
  631. WS_CHILD|WS_VISIBLE
  632. |TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS
  633. |TVS_INFOTIP|TVS_TRACKSELECT
  634. |TVS_NONEVENHEIGHT|TVS_SHOWSELALWAYS,
  635. CRect( 0, 0, 0, 0 ),
  636. &m_wndResizableBar2,
  637. ID_VIEW_BAR_TREE
  638. )
  639. )
  640. {
  641. ASSERT( FALSE );
  642. return -1; // fail to create
  643. }
  644. m_wndObjectHierarchyTree.ModifyStyleEx( 0, WS_EX_STATICEDGE, SWP_FRAMECHANGED );
  645. VERIFY(
  646. m_ilObjectHierarchyTree.Create(
  647. IDB_BITMAP_TREE_IMG_LIST,
  648. 16,
  649. 1,
  650. RGB(255,0,255)
  651. )
  652. );
  653. m_wndObjectHierarchyTree.SetImageList(
  654. &m_ilObjectHierarchyTree,
  655. TVSIL_NORMAL
  656. );
  657. _splash.SetStatusText(
  658. _T("Creating the user interface: help view ...")
  659. );
  660. if( !m_wndResizableBar3.Create(
  661. NULL,
  662. this,
  663. ID_VIEW_BAR_HELP
  664. )
  665. )
  666. {
  667. ASSERT( FALSE );
  668. TRACE0("Failed to create m_wndResizableBar3n");
  669. return -1; // fail to create
  670. }
  671. if( !m_wndHelpHtmlCtrl.Create(
  672. &m_wndResizableBar3
  673. )
  674. || !( (new CSimpleThinFrame)->
  675. CreateDynamicThinFrame(
  676. &m_wndHelpHtmlCtrl
  677. )
  678. )
  679. )
  680. {
  681. ASSERT( FALSE );
  682. return -1; // fail to create
  683. }
  684. m_wndHelpHtmlCtrl.NavigateResourceID(
  685. ID_WEB_BROWSER_PAGE
  686. );
  687. if (!m_wndStatusBar.Create(this) ||
  688. !m_wndStatusBar.SetIndicators(indicators,
  689.   sizeof(indicators)/sizeof(UINT)))
  690. {
  691. TRACE0("Failed to create status barn");
  692. return -1;      // fail to create
  693. }
  694. _splash.SetStatusText(
  695. _T("Configuring control bars ...")
  696. );
  697. m_wndResizableBar0.EnableDocking(CBRS_ALIGN_ANY);
  698. m_wndResizableBar1.EnableDocking(CBRS_ALIGN_ANY);
  699. m_wndResizableBar2.EnableDocking(CBRS_ALIGN_ANY);
  700. m_wndResizableBar3.EnableDocking(CBRS_ALIGN_ANY);
  701. m_wndToolBarUiLook.EnableDocking(CBRS_ALIGN_ANY);
  702. if( !CExtControlBar::FrameEnableDocking(this) )
  703. {
  704. ASSERT( FALSE );
  705. return -1;
  706. }
  707. #if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
  708. if( !CExtControlBar::FrameInjectAutoHideAreas(this) )
  709. {
  710. ASSERT( FALSE );
  711. return -1;
  712. }
  713. #endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
  714. _splash.SetStatusText(
  715. _T("Loading last UI state ...")
  716. );
  717. if( !CExtControlBar::ProfileBarStateLoad(
  718. this,
  719. pApp->m_pszRegistryKey,
  720. pApp->m_pszProfileName,
  721. pApp->m_pszProfileName,
  722. &m_dataFrameWP
  723. )
  724. )
  725. {
  726. _splash.SetStatusText(
  727. _T("Docking control bars ...")
  728. );
  729. DockControlBar( &m_wndToolBarUiLook, AFX_IDW_DOCKBAR_RIGHT );
  730. RecalcLayout();
  731. CSize _sizeDesired( 200, 200 );
  732. m_wndResizableBar0.SetInitDesiredSizeFloating(   _sizeDesired );
  733. m_wndResizableBar0.SetInitDesiredSizeHorizontal( _sizeDesired );
  734. m_wndResizableBar0.SetInitDesiredSizeVertical(   _sizeDesired );
  735. m_wndResizableBar1.SetInitDesiredSizeFloating(   _sizeDesired );
  736. m_wndResizableBar1.SetInitDesiredSizeHorizontal( _sizeDesired );
  737. m_wndResizableBar1.SetInitDesiredSizeVertical(   _sizeDesired );
  738. m_wndResizableBar2.SetInitDesiredSizeFloating(   _sizeDesired );
  739. m_wndResizableBar2.SetInitDesiredSizeHorizontal( _sizeDesired );
  740. m_wndResizableBar2.SetInitDesiredSizeVertical(   _sizeDesired );
  741. m_wndResizableBar3.SetInitDesiredSizeFloating(   _sizeDesired );
  742. m_wndResizableBar3.SetInitDesiredSizeHorizontal( _sizeDesired );
  743. m_wndResizableBar3.SetInitDesiredSizeVertical(   _sizeDesired );
  744. m_wndResizableBar1.DockControlBar( AFX_IDW_DOCKBAR_LEFT, 1, this, false );
  745. m_wndResizableBar1.DockControlBar( &m_wndResizableBar0, true, true, this, false );
  746. m_wndResizableBar2.DockControlBar( AFX_IDW_DOCKBAR_RIGHT, 1, this, false );
  747. m_wndResizableBar3.DockControlBar( AFX_IDW_DOCKBAR_BOTTOM, 2, this, false );
  748. RecalcLayout();
  749. }
  750. _splash.SetStatusText(
  751. _T("Initializing 3D objects ...")
  752. );
  753. ASSERT_VALID( m_wndViewCamMain.m_wndGlPanel.GetView3D() );
  754. ASSERT_VALID( m_wndViewCam0.m_wndGlPanel.GetView3D() );
  755. ASSERT_VALID( m_wndViewCam1.m_wndGlPanel.GetView3D() );
  756. m_wndViewCamMain.m_wndGlPanel.GetView3D()->m_strViewName = _T("main view (green cursor)");
  757. m_wndViewCam0.m_wndGlPanel.GetView3D()->m_strViewName = _T("view 0 (red cursor)");
  758. m_wndViewCam1.m_wndGlPanel.GetView3D()->m_strViewName = _T("view 1 (blue cursor)");
  759. C3DObject * pObjRoot3D = the3DPipe.GetRoot();
  760. ASSERT_VALID( pObjRoot3D );
  761. pObjRoot3D->AddChild( new C3DOuterScene );
  762. C3DMirror * pObjWndMirror = new C3DMirror;
  763. pObjRoot3D->AddChild( pObjWndMirror );
  764. C3DAviPlayer * pObjWndAviPlayer = new C3DAviPlayer;
  765. pObjRoot3D->AddChild( pObjWndAviPlayer );
  766. C3DModifier * pObjCenterCubeModifier = new C3DModifier;
  767. C3DCube * pObjCubeCenter = new C3DCube( GL_VIEWS_NONAME, true );
  768. pObjCenterCubeModifier->AddChild( pObjCubeCenter );
  769. pObjRoot3D->AddChild( pObjCenterCubeModifier );
  770. C3DCube * pObjCubeLeaf = new C3DCube;
  771. pObjCubeCenter->AddChild( pObjCubeLeaf );
  772. pObjCubeLeaf->m_v3LocalTranslation += _v3t( 0.0f, 0.0f, C3DCube::g_fTranslateCubeVal );
  773. pObjCubeLeaf = new C3DCube;
  774. pObjCubeCenter->AddChild( pObjCubeLeaf );
  775. pObjCubeLeaf->m_v3LocalTranslation += _v3t( 0.0f, 0.0f, -C3DCube::g_fTranslateCubeVal );
  776. pObjCubeLeaf = new C3DCube;
  777. pObjCubeCenter->AddChild( pObjCubeLeaf );
  778. pObjCubeLeaf->m_v3LocalTranslation += _v3t( 0.0f, C3DCube::g_fTranslateCubeVal, 0.0f );
  779. pObjCubeLeaf = new C3DCube;
  780. pObjCubeCenter->AddChild( pObjCubeLeaf );
  781. pObjCubeLeaf->m_v3LocalTranslation += _v3t( 0.0f, -C3DCube::g_fTranslateCubeVal, 0.0f );
  782. pObjCubeLeaf = new C3DCube;
  783. pObjCubeCenter->AddChild( pObjCubeLeaf );
  784. pObjCubeLeaf->m_v3LocalTranslation += _v3t( C3DCube::g_fTranslateCubeVal, 0.0f, 0.0f );
  785. pObjCubeLeaf = new C3DCube;
  786. pObjCubeCenter->AddChild( pObjCubeLeaf );
  787. pObjCubeLeaf->m_v3LocalTranslation += _v3t( -C3DCube::g_fTranslateCubeVal, 0.0f, 0.0f );
  788. C3DModifier * pObjModifierForEarth = new C3DModifier;
  789. C3DPlanet * pObjPlanetEarth =
  790. new C3DPlanet(
  791. GL_VIEWS_PLANET_EARTH,
  792. GL_VIEWS_TEXTURE_IDX_EARTH,
  793. C3DPlanet::g_nPlanetSphereStacks,
  794. C3DPlanet::g_fPlanetRadiusEarth,
  795. C3DPlanet::g_fAnglePlayStepPitchEarth,
  796. C3DPlanet::g_fAnglePlayStepYawEarth,
  797. C3DPlanet::g_fAnglePlayStepRollEarth
  798. );
  799. pObjPlanetEarth->m_v3LocalTranslation += _v3t( 0.0f, C3DCube::g_fTranslateCubeVal*4.0f, 0.0f );
  800. pObjModifierForEarth->AddChild( pObjPlanetEarth );
  801. pObjCubeCenter->AddChild( pObjModifierForEarth );
  802. C3DModifier * pObjModifierForMoon = new C3DModifier;
  803. C3DPlanet * pObjPlanetMoon =
  804. new C3DPlanet(
  805. GL_VIEWS_PLANET_MOON,
  806. GL_VIEWS_TEXTURE_IDX_MOON,
  807. C3DPlanet::g_nPlanetSphereStacks,
  808. C3DPlanet::g_fPlanetRadiusMoon,
  809. C3DPlanet::g_fAnglePlayStepPitchMoon,
  810. C3DPlanet::g_fAnglePlayStepYawMoon,
  811. C3DPlanet::g_fAnglePlayStepRollMoon
  812. );
  813. pObjPlanetMoon->m_v3LocalTranslation += _v3t( 0.0f, C3DCube::g_fTranslateCubeVal, 0.0f );
  814. pObjModifierForMoon->AddChild( pObjPlanetMoon );
  815. pObjPlanetEarth->AddChild( pObjModifierForMoon );
  816. static TCHAR sTextProfUIS[] = _T("Professional User Interface Suite");
  817. C3DModifier * pObjTextGroupProfUIS = new C3DModifier( sTextProfUIS );
  818. pObjCubeCenter->AddChild( pObjTextGroupProfUIS );
  819. static const int nLenTextProfUIS = sizeof( sTextProfUIS ) / sizeof( TCHAR ) - 1;
  820. _q4t _qTextProfUISRotAdjust2( _ntr::get_pi() / 2.0f, 0.0, -1.0, 0.0 );
  821. _qTextProfUISRotAdjust2 *= _q4t( _ntr::get_pi() / 2.0f, 0.0, 0.0, 1.0 );
  822. int nChar;
  823. for( nChar = 0; nChar < nLenTextProfUIS; nChar++ )
  824. {
  825. if( sTextProfUIS[nChar] == _T(' ') )
  826. continue;
  827. TCHAR sText[2] = { sTextProfUIS[nChar], _T('') };
  828. C3DText * pObjTextLetter =
  829. new C3DText(
  830. sText,
  831. RGB( 16, 128, 16 ),
  832. _ntr::d2r( 0.0f ),
  833. _ntr::d2r( 0.0f ),
  834. _ntr::d2r( 2.0f )
  835. );
  836. pObjTextLetter->m_v3LocalTranslation +=
  837. _v3t( C3DCube::g_fTranslateCubeVal*2.0f, 0.0f, 0.0f );
  838. _q4t _qTextProfUISRotAdjust1(
  839. 0.12f * float(nChar), 0.0f, 0.0f, 1.0f );
  840. pObjTextLetter->m_quatLocalOrientation = _qTextProfUISRotAdjust2;
  841. C3DModifier * pObjModifier = new C3DModifier;
  842. pObjModifier->m_quatLocalOrientation = _qTextProfUISRotAdjust1;
  843. pObjTextGroupProfUIS->AddChild( pObjModifier );
  844. pObjModifier->AddChild( pObjTextLetter );
  845. }
  846. static TCHAR sTextWWW[] = _T("http://www.prof-uis.com");
  847. C3DModifier * pObjTextGroupWWW = new C3DModifier( sTextWWW );
  848. pObjCubeCenter->AddChild( pObjTextGroupWWW );
  849. static const int nLenTextWWW = sizeof( sTextWWW ) / sizeof( TCHAR ) - 1;
  850. _q4t _qTextWWWRotAdjust2( _ntr::get_pi() / 2.0f, 0.0, -1.0, 0.0 );
  851. _qTextWWWRotAdjust2 *= _q4t( _ntr::get_pi() / 2.0f, 0.0, 0.0, 1.0 );
  852. for( nChar = 0; nChar < nLenTextWWW; nChar++ )
  853. {
  854. if( sTextWWW[nChar] == _T(' ') )
  855. continue;
  856. TCHAR sText[2] = { sTextWWW[nChar], _T('') };
  857. C3DText * pObjTextLetter =
  858. new C3DText(
  859. sText,
  860. RGB( 16, 16, 128 ),
  861. _ntr::d2r( 0.0f ),
  862. _ntr::d2r( 2.0f ),
  863. _ntr::d2r( 0.0f )
  864. );
  865. pObjTextLetter->m_v3LocalTranslation +=
  866. _v3t( C3DCube::g_fTranslateCubeVal*2.2f, 0.0f, 0.0f );
  867. _q4t _qTextWWWRotAdjust1(
  868. 0.13f * float(nChar), 0.0f, 0.0f, 1.0f );
  869. pObjTextLetter->m_quatLocalOrientation = _qTextWWWRotAdjust2;
  870. C3DModifier * pObjModifier = new C3DModifier;
  871. pObjModifier->m_quatLocalOrientation = _qTextWWWRotAdjust1;
  872. pObjTextGroupWWW->AddChild( pObjModifier );
  873. pObjModifier->AddChild( pObjTextLetter );
  874. }
  875. _splash.SetStatusText(
  876. _T("Initializing cameras ...")
  877. );
  878. for( int nCamIdx = 0; nCamIdx < GL_VIEWS_CAMERA_COUNT; nCamIdx++ )
  879. {
  880. CString sCamName;
  881. sCamName.Format( GL_VIEWS_CAMERA_NAME_FMT, nCamIdx );
  882. C3DCamera * pCam =
  883. new C3DCamera(
  884. ID_SELCAM0 + nCamIdx,
  885. (LPCTSTR)sCamName
  886. );
  887. the3DPipe.AddCamera( pCam );
  888. }
  889. _ResetCameras( false );
  890. SerializeCameraState(
  891. GL_VIEWS_CAMERA_STATE,
  892. pApp->m_pszRegistryKey,
  893. pApp->m_pszProfileName,
  894. false
  895. );
  896. SyncCameraFovValue();
  897. _splash.SetStatusText(
  898. _T("Initializing the Object Hierarchy View ...")
  899. );
  900. the3DPipe.GetRoot()->WalkTree(
  901. C3DObject::EWTQ_ADD_TO_TREE,
  902. NULL,
  903. NULL,
  904. &m_wndObjectHierarchyTree,
  905. NULL
  906. );
  907. m_wndObjectHierarchyTree.Expand(  // expand root
  908. the3DPipe.GetRoot()->GetHTREEITEM(),
  909. TVE_EXPAND
  910. );
  911. _splash.SetStatusText(
  912. _T("Initializing the 3D Redering Pipe Thread ...")
  913. );
  914. if( (!pApp->SetThreadPriority(THREAD_PRIORITY_HIGHEST))
  915. || (!the3DPipe.CreateThread(CREATE_SUSPENDED))
  916. || (!the3DPipe.SetThreadPriority(THREAD_PRIORITY_HIGHEST))
  917. || the3DPipe.ResumeThread() == 0xFFFFFFFF
  918. )
  919. {
  920. ASSERT( FALSE );
  921. return -1;
  922. }
  923. _splash.DestroyWindow();
  924. PostMessage( GL_VIEWS_WM_RENDER_INITIAL );
  925. return 0;
  926. }
  927. void CMainFrame::_ResetCameras( bool bLockViews )
  928. {
  929. ASSERT_VALID( this );
  930. if( bLockViews )
  931. {
  932. int nViewCount = the3DPipe.GetViewCount();
  933. for( int nViewIdx = 0; nViewIdx < nViewCount; nViewIdx++ )
  934. {
  935. C3DView * pView3D = the3DPipe.GetView( nViewIdx );
  936. ASSERT_VALID( pView3D );
  937. pView3D->Lock();
  938. }
  939. }
  940. int nCamCount = the3DPipe.GetCameraCount();
  941. ASSERT( nCamCount == GL_VIEWS_CAMERA_COUNT );
  942. for( int nCamIdx = 0; nCamIdx < nCamCount; nCamIdx++ )
  943. {
  944. C3DCamera * pCam = the3DPipe.GetCamera( nCamIdx );
  945. ASSERT_VALID( pCam );
  946. pCam->m_fNearPlane = GL_VIEWS_CAMERA_DEF_NEAR_PLANE;
  947. pCam->m_fFarPlane = GL_VIEWS_CAMERA_DEF_FAR_PLANE;
  948. pCam->m_nFovIndex = GL_VIEWS_FOV_DEF_INDEX;
  949. ASSERT( 0 <= pCam->m_nFovIndex && pCam->m_nFovIndex < GL_VIEWS_FOV_COUNT );
  950. pCam->LocalLoadIdentity();
  951. pCam->m_v3LocalTranslation =
  952. _v3t(
  953. g_arrInitCameraData[nCamIdx].m_fLocalTranslationX,
  954. g_arrInitCameraData[nCamIdx].m_fLocalTranslationY,
  955. g_arrInitCameraData[nCamIdx].m_fLocalTranslationZ
  956. );
  957. pCam->LocalAdjustOrientation(
  958. g_arrInitCameraData[nCamIdx].m_fLocalAngleRadsPitch,
  959. g_arrInitCameraData[nCamIdx].m_fLocalAngleRadsYaw,
  960. g_arrInitCameraData[nCamIdx].m_fLocalAngleRadsRoll
  961. );
  962. } // for( int nCamIdx = 0; nCamIdx < nCamCount; nCamIdx++ )
  963. if( bLockViews )
  964. {
  965. int nViewCount = the3DPipe.GetViewCount();
  966. for( int nViewIdx = 0; nViewIdx < nViewCount; nViewIdx++ )
  967. {
  968. C3DView * pView3D = the3DPipe.GetView( nViewIdx );
  969. ASSERT_VALID( pView3D );
  970. pView3D->Unlock();
  971. }
  972. }
  973. SyncCameraFovValue();
  974. }
  975. static CString productsection2regkeypath(
  976. LPCTSTR sProfileName,
  977. LPCTSTR sSectionNameCompany, // under HKEY_CURRENT_USERSoftware
  978. LPCTSTR sSectionNameProduct // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%
  979. )
  980. {
  981. ASSERT( sProfileName != NULL );
  982. ASSERT( sSectionNameCompany != NULL );
  983. ASSERT( sSectionNameProduct != NULL );
  984. // use the same version numbers with Prof-UIS
  985. DWORD dwVersion = g_CmdManager.GetVersionDWORD( false );
  986. ASSERT( dwVersion != 0 );
  987. CString strVer;
  988. strVer.Format(
  989. _T("%d%d%d%d"),
  990. INT( (dwVersion>>24)&0x0FF ),
  991. INT( (dwVersion>>16)&0x0FF ),
  992. INT( (dwVersion>>8)&0x0FF ),
  993. INT( dwVersion&0x0FF )
  994. );
  995. CString s;
  996. s.Format(
  997. _T("Software\%s\%s\%s\fmt-spec-%s"),
  998. sSectionNameCompany,
  999. sSectionNameProduct,
  1000. sProfileName,
  1001. strVer
  1002. );
  1003. s.Replace('r','_');
  1004. s.Replace('t','_');
  1005. s.Replace('n','_');
  1006. s.Replace('?','_');
  1007. s.Replace('*','_');
  1008. s.Replace('.','_');
  1009. s.Replace(',','_');
  1010. return s;
  1011. }
  1012. static bool fileobj_to_registry(
  1013. CFile & _file,
  1014. LPCTSTR sProfileName,
  1015. LPCTSTR sSectionNameCompany, // under HKEY_CURRENT_USERSoftware
  1016. LPCTSTR sSectionNameProduct // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%
  1017. )
  1018. {
  1019. ASSERT( sProfileName != NULL );
  1020. ASSERT( sSectionNameCompany != NULL );
  1021. ASSERT( sSectionNameProduct != NULL );
  1022. CString sRegKeyPath =
  1023. productsection2regkeypath(
  1024. sProfileName,
  1025. sSectionNameCompany,
  1026. sSectionNameProduct
  1027. );
  1028. return CExtCmdManager::FileObjToRegistry( _file, (LPCTSTR)sRegKeyPath );
  1029. }
  1030. static bool fileobj_from_registry(
  1031. CFile & _file,
  1032. LPCTSTR sProfileName,
  1033. LPCTSTR sSectionNameCompany, // under HKEY_CURRENT_USERSoftware
  1034. LPCTSTR sSectionNameProduct // under HKEY_CURRENT_USERSoftware%sSectionNameCompany%
  1035. )
  1036. {
  1037. ASSERT( sProfileName != NULL );
  1038. ASSERT( sSectionNameCompany != NULL );
  1039. ASSERT( sSectionNameProduct != NULL );
  1040. ASSERT( _file.GetLength() == 0 );
  1041. CString sRegKeyPath =
  1042. productsection2regkeypath(
  1043. sProfileName,
  1044. sSectionNameCompany,
  1045. sSectionNameProduct
  1046. );
  1047. return CExtCmdManager::FileObjFromRegistry( _file, (LPCTSTR)sRegKeyPath );
  1048. }
  1049. void CMainFrame::SerializeCameraState(
  1050. LPCTSTR sProfileName,
  1051. LPCTSTR sSectionNameCompany,
  1052. LPCTSTR sSectionNameProduct,
  1053. bool bSave
  1054. )
  1055. {
  1056. ASSERT_VALID( this );
  1057. ASSERT( sProfileName != NULL );
  1058. ASSERT( sSectionNameCompany != NULL );
  1059. ASSERT( sSectionNameProduct != NULL );
  1060. try
  1061. {
  1062. CMemFile _file;
  1063. if( bSave )
  1064. {
  1065. { // BLOCK: CArchive usage
  1066. CArchive ar(
  1067. &_file,
  1068. CArchive::store
  1069. );
  1070. SerializeCameraState( ar );
  1071. ar.Flush();
  1072. } // BLOCK: CArchive usage
  1073. // ... write _file to registty
  1074. _file.Seek( 0, CFile::begin );
  1075. if( !fileobj_to_registry(
  1076. _file,
  1077. sProfileName,
  1078. sSectionNameCompany,
  1079. sSectionNameProduct
  1080. )
  1081. )
  1082. return;
  1083. } // if( bSave )
  1084. else
  1085. {
  1086. // ... read _file from registty
  1087. if( !fileobj_from_registry(
  1088. _file,
  1089. sProfileName,
  1090. sSectionNameCompany,
  1091. sSectionNameProduct
  1092. )
  1093. )
  1094. {
  1095. int nCamIndexMain = GL_VIEWS_CAMERA_DEFIDX_MAIN,
  1096. nCamIndex0 = GL_VIEWS_CAMERA_DEFIDX_0,
  1097. nCamIndex1 = GL_VIEWS_CAMERA_DEFIDX_1;
  1098. m_wndViewCamMain.m_wndToolbar.m_wndCameraSelCombo.SetCurSel( nCamIndexMain );
  1099. m_wndViewCam0.m_wndToolbar.m_wndCameraSelCombo.SetCurSel( nCamIndex0 );
  1100. m_wndViewCam1.m_wndToolbar.m_wndCameraSelCombo.SetCurSel( nCamIndex1 );
  1101. return;
  1102. }
  1103. _file.Seek( 0, CFile::begin );
  1104. CArchive ar(
  1105. &_file,
  1106. CArchive::load
  1107. );
  1108. SerializeCameraState( ar );
  1109. } // else from if( bSave )
  1110. } // try
  1111. catch( CException * pXept )
  1112. {
  1113. pXept->Delete();
  1114. ASSERT( FALSE );
  1115. } // catch( CException * pXept )
  1116. catch( ... )
  1117. {
  1118. ASSERT( FALSE );
  1119. } // catch( ... )
  1120. }
  1121. void CMainFrame::SerializeCameraState(
  1122. CArchive & ar
  1123. )
  1124. {
  1125. ASSERT_VALID( this );
  1126. int nCamIndexMain = GL_VIEWS_CAMERA_DEFIDX_MAIN,
  1127. nCamIndex0 = GL_VIEWS_CAMERA_DEFIDX_0,
  1128. nCamIndex1 = GL_VIEWS_CAMERA_DEFIDX_1;
  1129. try
  1130. {
  1131. if( ar.IsStoring() )
  1132. {
  1133. nCamIndexMain = m_wndViewCamMain.m_wndToolbar.m_wndCameraSelCombo.GetCurSel();
  1134. nCamIndex0 = m_wndViewCam0.m_wndToolbar.m_wndCameraSelCombo.GetCurSel();
  1135. nCamIndex1 = m_wndViewCam1.m_wndToolbar.m_wndCameraSelCombo.GetCurSel();
  1136. ASSERT( 0 <= nCamIndexMain && nCamIndexMain < GL_VIEWS_CAMERA_COUNT );
  1137. ASSERT( 0 <= nCamIndex0 && nCamIndex0 < GL_VIEWS_CAMERA_COUNT );
  1138. ASSERT( 0 <= nCamIndex1 && nCamIndex1 < GL_VIEWS_CAMERA_COUNT );
  1139. ar << DWORD(nCamIndexMain);
  1140. ar << DWORD(nCamIndex0);
  1141. ar << DWORD(nCamIndex1);
  1142. } // if( ar.IsStoring() )
  1143. else
  1144. {
  1145. DWORD dwTmp;
  1146. ar >> dwTmp; nCamIndexMain = int(dwTmp);
  1147. ar >> dwTmp; nCamIndex0 = int(dwTmp);
  1148. ar >> dwTmp; nCamIndex1 = int(dwTmp);
  1149. ASSERT( 0 <= nCamIndexMain && nCamIndexMain < GL_VIEWS_CAMERA_COUNT );
  1150. ASSERT( 0 <= nCamIndex0 && nCamIndex0 < GL_VIEWS_CAMERA_COUNT );
  1151. ASSERT( 0 <= nCamIndex1 && nCamIndex1 < GL_VIEWS_CAMERA_COUNT );
  1152. } // else from if( ar.IsStoring() )
  1153. int nCamCount = the3DPipe.GetCameraCount();
  1154. ASSERT( nCamCount == GL_VIEWS_CAMERA_COUNT );
  1155. for( int nCamIdx = 0; nCamIdx < nCamCount; nCamIdx++ )
  1156. {
  1157. C3DCamera * pCam = the3DPipe.GetCamera( nCamIdx );
  1158. ASSERT_VALID( pCam );
  1159. pCam->SerializeState( ar );
  1160. } // for( int nCamIdx = 0; nCamIdx < nCamCount; nCamIdx++ )
  1161. } // try
  1162. catch( CException * pXept )
  1163. {
  1164. pXept->Delete();
  1165. ASSERT( FALSE );
  1166. } // catch( CException * pXept )
  1167. catch( ... )
  1168. {
  1169. ASSERT( FALSE );
  1170. } // catch( ... )
  1171. if( !ar.IsStoring() )
  1172. {
  1173. if( 0 > nCamIndexMain || nCamIndexMain >= GL_VIEWS_CAMERA_COUNT )
  1174. nCamIndexMain = 8;
  1175. if( 0 > nCamIndex0 || nCamIndex0 >= GL_VIEWS_CAMERA_COUNT )
  1176. nCamIndex0 = 9;
  1177. if( 0 > nCamIndex1 || nCamIndex1 >= GL_VIEWS_CAMERA_COUNT )
  1178. nCamIndex1 = 5;
  1179. m_wndViewCamMain.m_wndToolbar.m_wndCameraSelCombo.SetCurSel( nCamIndexMain );
  1180. m_wndViewCam0.m_wndToolbar.m_wndCameraSelCombo.SetCurSel( nCamIndex0 );
  1181. m_wndViewCam1.m_wndToolbar.m_wndCameraSelCombo.SetCurSel( nCamIndex1 );
  1182. } // if( !ar.IsStoring() )
  1183. }
  1184. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  1185. {
  1186. if( ! CExtNCW < CFrameWnd > :: PreCreateWindow( cs ) )
  1187. return FALSE;
  1188. cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  1189. cs.lpszClass = AfxRegisterWndClass(0);
  1190. return TRUE;
  1191. }
  1192. /////////////////////////////////////////////////////////////////////////////
  1193. // CMainFrame diagnostics
  1194. #ifdef _DEBUG
  1195. void CMainFrame::AssertValid() const
  1196. {
  1197. CExtNCW < CFrameWnd > :: AssertValid();
  1198. }
  1199. void CMainFrame::Dump(CDumpContext& dc) const
  1200. {
  1201. CExtNCW < CFrameWnd > :: Dump( dc );
  1202. }
  1203. #endif //_DEBUG
  1204. /////////////////////////////////////////////////////////////////////////////
  1205. // CMainFrame message handlers
  1206. void CMainFrame::OnSetFocus(CWnd* pOldWnd)
  1207. {
  1208. pOldWnd;
  1209. // forward focus to the view window
  1210. m_wndViewCamMain.SetFocus();
  1211. }
  1212. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
  1213. {
  1214. switch( nID )
  1215. {
  1216. case ID_SELCAM0:
  1217. case ID_SELCAM1:
  1218. case ID_SELCAM2:
  1219. case ID_SELCAM3:
  1220. case ID_SELCAM4:
  1221. case ID_SELCAM5:
  1222. case ID_SELCAM6:
  1223. case ID_SELCAM7:
  1224. case ID_SELCAM8:
  1225. case ID_SELCAM9:
  1226. case ID_ROTATE_ABOUT_X0:
  1227. case ID_ROTATE_ABOUT_X1:
  1228. case ID_ROTATE_ABOUT_Y0:
  1229. case ID_ROTATE_ABOUT_Y1:
  1230. case ID_ROTATE_ABOUT_Z0:
  1231. case ID_ROTATE_ABOUT_Z1:
  1232. case ID_TRANSLATE_X0:
  1233. case ID_TRANSLATE_X1:
  1234. case ID_TRANSLATE_Y0:
  1235. case ID_TRANSLATE_Y1:
  1236. case ID_TRANSLATE_Z0:
  1237. case ID_TRANSLATE_Z1:
  1238. case ID_CAM_FOV_INC:
  1239. case ID_CAM_FOV_DEC:
  1240. {
  1241. HWND hWndFocus = ::GetFocus();
  1242. if( hWndFocus != NULL )
  1243. {
  1244. if( m_wndViewCam0.m_hWnd != NULL
  1245. && ::IsWindowVisible( m_wndViewCam0.m_hWnd )
  1246. && ::IsChild( m_wndViewCam0.m_hWnd, hWndFocus )
  1247. )
  1248. {
  1249. if( m_wndViewCam0.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo) )
  1250. return TRUE;
  1251. }
  1252. if( m_wndViewCam1.m_hWnd != NULL
  1253. && ::IsWindowVisible( m_wndViewCam1.m_hWnd )
  1254. && ::IsChild( m_wndViewCam1.m_hWnd, hWndFocus )
  1255. )
  1256. {
  1257. if( m_wndViewCam1.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo) )
  1258. return TRUE;
  1259. }
  1260. } // if( hWndFocus != NULL )
  1261. }
  1262. break;
  1263. } // switch( nID )
  1264. if( m_wndViewCamMain.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo) )
  1265. return TRUE;
  1266. // otherwise, do default handling
  1267. return CExtNCW < CFrameWnd > :: OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
  1268. }
  1269. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  1270. {
  1271. if( pMsg->message == GL_VIEWS_WM_RENDER_INITIAL )
  1272. {
  1273. the3DPipe.Render();
  1274. return TRUE;
  1275. }
  1276. if( m_wndToolBarUiLook.PreTranslateMessage( pMsg ) )
  1277. return TRUE;
  1278. if( m_wndMenuBar.TranslateMainFrameMessage( pMsg ) )
  1279. return TRUE;
  1280. return CExtNCW < CFrameWnd > :: PreTranslateMessage( pMsg );
  1281. }
  1282. BOOL CMainFrame::DestroyWindow() 
  1283. {
  1284. m_wndViewCamMain.m_wndGlPanel.TimerAnimationEnable( false );
  1285. the3DPipe.ShutdownAndWaitFor();
  1286. CWinApp * pApp = ::AfxGetApp();
  1287. ASSERT( pApp != NULL );
  1288. ASSERT( pApp->m_pszRegistryKey != NULL );
  1289. ASSERT( pApp->m_pszRegistryKey[0] != _T('') );
  1290. ASSERT( pApp->m_pszProfileName != NULL );
  1291. ASSERT( pApp->m_pszProfileName[0] != _T('') );
  1292. SerializeCameraState(
  1293. GL_VIEWS_CAMERA_STATE,
  1294. pApp->m_pszRegistryKey,
  1295. pApp->m_pszProfileName,
  1296. true
  1297. );
  1298. VERIFY(
  1299. CExtControlBar::ProfileBarStateSave(
  1300. this,
  1301. pApp->m_pszRegistryKey,
  1302. pApp->m_pszProfileName,
  1303. pApp->m_pszProfileName
  1304. )
  1305. );
  1306. VERIFY(
  1307. g_PaintManager.PaintManagerStateSave(
  1308. pApp->m_pszRegistryKey,
  1309. pApp->m_pszProfileName,
  1310. pApp->m_pszProfileName
  1311. )
  1312. );
  1313. g_CmdManager->ProfileWndRemove( GetSafeHwnd() );
  1314. return CExtNCW < CFrameWnd > :: DestroyWindow();
  1315. }
  1316. void CMainFrame::ActivateFrame(int nCmdShow) 
  1317. {
  1318. // window placement persistence
  1319. if( m_dataFrameWP.showCmd != SW_HIDE )
  1320. {
  1321. SetWindowPlacement( &m_dataFrameWP );
  1322. CExtNCW < CFrameWnd > :: ActivateFrame( m_dataFrameWP.showCmd );
  1323. m_dataFrameWP.showCmd = SW_HIDE;
  1324. return;
  1325. }
  1326. CExtNCW < CFrameWnd > :: ActivateFrame( nCmdShow );
  1327. }
  1328. void CMainFrame::OnAnimate() 
  1329. {
  1330. ASSERT_VALID( this );
  1331. m_wndViewCamMain.m_wndGlPanel.TimerAnimationEnable(
  1332. !the3DPipe.m_bTimerAnimationEnabled
  1333. );
  1334. }
  1335. void CMainFrame::OnUpdateAnimate(CCmdUI* pCmdUI) 
  1336. {
  1337. ASSERT_VALID( this );
  1338. ASSERT( pCmdUI != NULL );
  1339. pCmdUI->Enable();
  1340. pCmdUI->SetCheck(
  1341. the3DPipe.m_bTimerAnimationEnabled ? TRUE : FALSE
  1342. );
  1343. }
  1344. void CMainFrame::OnShowCameras() 
  1345. {
  1346. ASSERT_VALID( this );
  1347. C3DCamera::g_bRenderCameraAxes =
  1348. !C3DCamera::g_bRenderCameraAxes;
  1349. the3DPipe.Render();
  1350. }
  1351. void CMainFrame::OnUpdateShowCameras(CCmdUI* pCmdUI) 
  1352. {
  1353. ASSERT_VALID( this );
  1354. ASSERT( pCmdUI != NULL );
  1355. pCmdUI->Enable();
  1356. pCmdUI->SetCheck(
  1357. C3DCamera::g_bRenderCameraAxes ? TRUE : FALSE
  1358. );
  1359. }
  1360. void CMainFrame::OnShowMirror() 
  1361. {
  1362. ASSERT_VALID( this );
  1363. C3DMirror::g_bRenderMirrors =
  1364. !C3DMirror::g_bRenderMirrors;
  1365. the3DPipe.Render();
  1366. }
  1367. void CMainFrame::OnUpdateShowMirror(CCmdUI* pCmdUI) 
  1368. {
  1369. ASSERT_VALID( this );
  1370. ASSERT( pCmdUI != NULL );
  1371. pCmdUI->Enable();
  1372. pCmdUI->SetCheck(
  1373. C3DMirror::g_bRenderMirrors ? TRUE : FALSE
  1374. );
  1375. }
  1376. void CMainFrame::OnShowAviPlayer() 
  1377. {
  1378. ASSERT_VALID( this );
  1379. C3DAviPlayer::g_bRenderAviPlayers =
  1380. !C3DAviPlayer::g_bRenderAviPlayers;
  1381. the3DPipe.Render();
  1382. }
  1383. void CMainFrame::OnUpdateShowAviPlayer(CCmdUI* pCmdUI) 
  1384. {
  1385. ASSERT_VALID( this );
  1386. ASSERT( pCmdUI != NULL );
  1387. pCmdUI->Enable();
  1388. pCmdUI->SetCheck(
  1389. C3DAviPlayer::g_bRenderAviPlayers ? TRUE : FALSE
  1390. );
  1391. }
  1392. void CMainFrame::OnShowOuterObjects() 
  1393. {
  1394. ASSERT_VALID( this );
  1395. C3DOuterScene::g_bRenderOuterScene =
  1396. !C3DOuterScene::g_bRenderOuterScene;
  1397. the3DPipe.Render();
  1398. }
  1399. void CMainFrame::OnUpdateShowOuterObjects(CCmdUI* pCmdUI) 
  1400. {
  1401. ASSERT_VALID( this );
  1402. ASSERT( pCmdUI != NULL );
  1403. pCmdUI->Enable();
  1404. pCmdUI->SetCheck(
  1405. C3DOuterScene::g_bRenderOuterScene ? TRUE : FALSE
  1406. );
  1407. }
  1408. void CMainFrame::OnShowTextObjects() 
  1409. {
  1410. ASSERT_VALID( this );
  1411. C3DText::g_bRenderTextObjects =
  1412. !C3DText::g_bRenderTextObjects;
  1413. the3DPipe.Render();
  1414. }
  1415. void CMainFrame::OnUpdateShowTextObjects(CCmdUI* pCmdUI) 
  1416. {
  1417. ASSERT_VALID( this );
  1418. ASSERT( pCmdUI != NULL );
  1419. pCmdUI->Enable();
  1420. pCmdUI->SetCheck(
  1421. C3DText::g_bRenderTextObjects ? TRUE : FALSE
  1422. );
  1423. }
  1424. void CMainFrame::OnShowCubeObjects() 
  1425. {
  1426. ASSERT_VALID( this );
  1427. C3DCube::g_bRenderCubeObjects =
  1428. !C3DCube::g_bRenderCubeObjects;
  1429. the3DPipe.Render();
  1430. }
  1431. void CMainFrame::OnUpdateShowCubeObjects(CCmdUI* pCmdUI) 
  1432. {
  1433. ASSERT_VALID( this );
  1434. ASSERT( pCmdUI != NULL );
  1435. pCmdUI->Enable();
  1436. pCmdUI->SetCheck(
  1437. C3DCube::g_bRenderCubeObjects ? TRUE : FALSE
  1438. );
  1439. }
  1440. void CMainFrame::OnShowPlanetObjects() 
  1441. {
  1442. ASSERT_VALID( this );
  1443. C3DPlanet::g_bRenderPlanetObjects =
  1444. !C3DPlanet::g_bRenderPlanetObjects;
  1445. the3DPipe.Render();
  1446. }
  1447. void CMainFrame::OnUpdateShowPlanetObjects(CCmdUI* pCmdUI) 
  1448. {
  1449. ASSERT_VALID( this );
  1450. ASSERT( pCmdUI != NULL );
  1451. pCmdUI->Enable();
  1452. pCmdUI->SetCheck(
  1453. C3DPlanet::g_bRenderPlanetObjects ? TRUE : FALSE
  1454. );
  1455. }
  1456. void CMainFrame::OnResetCameras() 
  1457. {
  1458. ASSERT_VALID( this );
  1459. CString sMsg;
  1460. sMsg.Format(
  1461. _T("This command will reset position, orientation ")
  1462. _T("and FOV parameters for all %d cameras. ")
  1463. _T("Whish you see cameras in initial state?"),
  1464. GL_VIEWS_CAMERA_COUNT
  1465. );
  1466. if( ::AfxMessageBox(
  1467. (LPCTSTR)sMsg,
  1468. MB_YESNO|MB_ICONQUESTION
  1469. ) != IDYES
  1470. )
  1471. return;
  1472. _ResetCameras( true );
  1473. SyncCameraFovValue();
  1474. the3DPipe.Render();
  1475. }
  1476. void CMainFrame::SyncCameraFovValue( int nCamIdx, int nFovIdx )
  1477. {
  1478. ASSERT_VALID( this );
  1479. ASSERT( 0 <= nCamIdx && nCamIdx < GL_VIEWS_CAMERA_COUNT );
  1480. ASSERT( 0 <= nFovIdx && nFovIdx < GL_VIEWS_FOV_COUNT );
  1481. if( m_wndViewCamMain.m_wndToolbar.m_wndCameraSelCombo.GetCurSel() == nCamIdx )
  1482. m_wndViewCamMain.m_wndToolbar.m_wndCameraFovCombo.SetCurSel( nFovIdx );
  1483. if( m_wndViewCam0.m_wndToolbar.m_wndCameraSelCombo.GetCurSel() == nCamIdx )
  1484. m_wndViewCam0.m_wndToolbar.m_wndCameraFovCombo.SetCurSel( nFovIdx );
  1485. if( m_wndViewCam1.m_wndToolbar.m_wndCameraSelCombo.GetCurSel() == nCamIdx )
  1486. m_wndViewCam1.m_wndToolbar.m_wndCameraFovCombo.SetCurSel( nFovIdx );
  1487. }
  1488. void CMainFrame::SyncCameraFovValue()
  1489. {
  1490. the3DPipe.ObjectWriteAccessSet( true );
  1491. int nCamCount = the3DPipe.GetCameraCount();
  1492. ASSERT( nCamCount == GL_VIEWS_CAMERA_COUNT );
  1493. for( int nCamIdx = 0; nCamIdx < nCamCount; nCamIdx++ )
  1494. {
  1495. C3DCamera * pCam = the3DPipe.GetCamera( nCamIdx );
  1496. ASSERT_VALID( pCam );
  1497. SyncCameraFovValue( nCamIdx, pCam->m_nFovIndex );
  1498. } // for( int nCamIdx = 0; nCamIdx < nCamCount; nCamIdx++ )
  1499. the3DPipe.ObjectWriteAccessSet( false );
  1500. }