GetVectorDlg.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 14k
Category:

Graph program

Development Platform:

Visual C++

  1. // GetVectorDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "..//..//Solidgraph.h"
  5. #include "GetVectorDlg.h"
  6. #include ".getvectordlg.h"
  7. // CGetVectorDlg dialog
  8. IMPLEMENT_DYNAMIC(CGetVectorDlg, CDialog)
  9. CGetVectorDlg::CGetVectorDlg(CWnd* pParent /*=NULL*/)
  10. : CDialog(CGetVectorDlg::IDD, pParent)
  11. {
  12. m_vector_type = USER_VECTOR;
  13. m_enable_history = NULL;
  14. m_was_diasabled = false;
  15. }
  16. CGetVectorDlg::~CGetVectorDlg()
  17. {
  18. if (m_enable_history)
  19. delete[] m_enable_history;
  20. }
  21. void CGetVectorDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. DDX_Control(pDX, IDC_VECTOR_X_EDIT, m_x_edit);
  25. DDX_Control(pDX, IDC_VECTOR_Y_EDIT, m_y_edit);
  26. DDX_Control(pDX, IDC_VECTOR_Z_EDIT, m_z_edit);
  27. DDX_Control(pDX, IDC_VECTOR_X_LOCK_BTN, m_x_lock_btn);
  28. DDX_Control(pDX, IDC_VECTOR_Y_LOCK_BTN, m_y_lock_btn);
  29. DDX_Control(pDX, IDC_VECTOR_Z_LOCK_BTN, m_z_lock_btn);
  30. DDX_Control(pDX, IDC_VECTOR_X_RADIO, m_x_radio);
  31. DDX_Control(pDX, IDC_VECTOR_Y_RADIO, m_y_radio);
  32. DDX_Control(pDX, IDC_VECTOR_Z_RADIO, m_z_radio);
  33. DDX_Control(pDX, IDC_VECTOR_USER_RADIO, m_user_radio);
  34. }
  35. BEGIN_MESSAGE_MAP(CGetVectorDlg, CDialog)
  36. ON_WM_CHAR()
  37. ON_BN_CLICKED(IDC_VECTOR_X_LOCK_BTN, OnBnClickedDirXLockBtn)
  38. ON_BN_CLICKED(IDC_VECTOR_Y_LOCK_BTN, OnBnClickedDirYLockBtn)
  39. ON_BN_CLICKED(IDC_VECTOR_Z_LOCK_BTN, OnBnClickedDirZLockBtn)
  40. ON_BN_CLICKED(IDC_VECTOR_X_RADIO, OnBnClickedVectorXRadio)
  41. ON_BN_CLICKED(IDC_VECTOR_Y_RADIO, OnBnClickedVectorYRadio)
  42. ON_BN_CLICKED(IDC_VECTOR_Z_RADIO, OnBnClickedVectorZRadio)
  43. ON_BN_CLICKED(IDC_VECTOR_USER_RADIO, OnBnClickedVectorUserRadio)
  44. ON_WM_ERASEBKGND()
  45. ON_WM_CTLCOLOR()
  46. ON_WM_SIZE()
  47. ON_WM_KEYDOWN()
  48. END_MESSAGE_MAP()
  49. IBaseInterfaceOfGetDialogs::DLG_TYPE CGetVectorDlg::GetType()
  50. {
  51. return IBaseInterfaceOfGetDialogs::GET_VECTOR_DLG;
  52. }
  53. CWnd*   CGetVectorDlg::GetWindow()
  54. {
  55. return this;
  56. }
  57. void    CGetVectorDlg::EnableControls(bool enbl)
  58. {
  59. if (m_enable_history==NULL)
  60. m_enable_history = new bool[13];
  61. if (enbl)
  62. {
  63. GetDlgItem(IDC_VECTOR_X_RADIO)->EnableWindow(m_enable_history[0]);
  64. GetDlgItem(IDC_VECTOR_Y_RADIO)->EnableWindow(m_enable_history[1]);
  65. GetDlgItem(IDC_VECTOR_Z_RADIO)->EnableWindow(m_enable_history[2]);
  66. GetDlgItem(IDC_VECTOR_USER_RADIO)->EnableWindow(m_enable_history[3]);
  67. GetDlgItem(IDC_VEC_X_STATIC)->EnableWindow(m_enable_history[4]);
  68. GetDlgItem(IDC_VEC_Y_STATIC)->EnableWindow(m_enable_history[5]);
  69. GetDlgItem(IDC_VEC_Z_STATIC)->EnableWindow(m_enable_history[6]);
  70. GetDlgItem(IDC_VECTOR_X_EDIT)->EnableWindow(m_enable_history[7]);
  71. GetDlgItem(IDC_VECTOR_Y_EDIT)->EnableWindow(m_enable_history[8]);
  72. GetDlgItem(IDC_VECTOR_Z_EDIT)->EnableWindow(m_enable_history[9]);
  73. GetDlgItem(IDC_VECTOR_X_LOCK_BTN)->EnableWindow(m_enable_history[10]);
  74. GetDlgItem(IDC_VECTOR_Y_LOCK_BTN)->EnableWindow(m_enable_history[11]);
  75. GetDlgItem(IDC_VECTOR_Z_LOCK_BTN)->EnableWindow(m_enable_history[12]);
  76. m_was_diasabled = false;
  77. GetDlgItem(IDC_VECTOR_X_EDIT)->SetFocus();
  78. }
  79. else
  80. {
  81. if (!m_was_diasabled)
  82. {
  83. m_enable_history[0] = GetDlgItem(IDC_VECTOR_X_RADIO)->IsWindowEnabled()!=0;
  84. m_enable_history[1] = GetDlgItem(IDC_VECTOR_Y_RADIO)->IsWindowEnabled()!=0;
  85. m_enable_history[2] = GetDlgItem(IDC_VECTOR_Z_RADIO)->IsWindowEnabled()!=0;
  86. m_enable_history[3] = GetDlgItem(IDC_VECTOR_USER_RADIO)->IsWindowEnabled()!=0;
  87. m_enable_history[4] = GetDlgItem(IDC_VEC_X_STATIC)->IsWindowEnabled()!=0;
  88. m_enable_history[5] = GetDlgItem(IDC_VEC_Y_STATIC)->IsWindowEnabled()!=0;
  89. m_enable_history[6] = GetDlgItem(IDC_VEC_Z_STATIC)->IsWindowEnabled()!=0;
  90. m_enable_history[7] = GetDlgItem(IDC_VECTOR_X_EDIT)->IsWindowEnabled()!=0;
  91. m_enable_history[8] = GetDlgItem(IDC_VECTOR_Y_EDIT)->IsWindowEnabled()!=0;
  92. m_enable_history[9] = GetDlgItem(IDC_VECTOR_Z_EDIT)->IsWindowEnabled()!=0;
  93. m_enable_history[10] = GetDlgItem(IDC_VECTOR_X_LOCK_BTN)->IsWindowEnabled()!=0;
  94. m_enable_history[11] = GetDlgItem(IDC_VECTOR_Y_LOCK_BTN)->IsWindowEnabled()!=0;
  95. m_enable_history[12] = GetDlgItem(IDC_VECTOR_Z_LOCK_BTN)->IsWindowEnabled()!=0;
  96. }
  97. GetDlgItem(IDC_VECTOR_X_RADIO)->EnableWindow(FALSE);
  98. GetDlgItem(IDC_VECTOR_Y_RADIO)->EnableWindow(FALSE);
  99. GetDlgItem(IDC_VECTOR_Z_RADIO)->EnableWindow(FALSE);
  100. GetDlgItem(IDC_VECTOR_USER_RADIO)->EnableWindow(FALSE);
  101. GetDlgItem(IDC_VEC_X_STATIC)->EnableWindow(FALSE);
  102. GetDlgItem(IDC_VEC_Y_STATIC)->EnableWindow(FALSE);
  103. GetDlgItem(IDC_VEC_Z_STATIC)->EnableWindow(FALSE);
  104. GetDlgItem(IDC_VECTOR_X_EDIT)->EnableWindow(FALSE);
  105. GetDlgItem(IDC_VECTOR_Y_EDIT)->EnableWindow(FALSE);
  106. GetDlgItem(IDC_VECTOR_Z_EDIT)->EnableWindow(FALSE);
  107. GetDlgItem(IDC_VECTOR_X_LOCK_BTN)->EnableWindow(FALSE);
  108. GetDlgItem(IDC_VECTOR_Y_LOCK_BTN)->EnableWindow(FALSE);
  109. GetDlgItem(IDC_VECTOR_Z_LOCK_BTN)->EnableWindow(FALSE);
  110. m_was_diasabled = true;
  111. }
  112. }
  113. void   CGetVectorDlg::UpdateRadios()
  114. {
  115. if (!m_x_radio.m_hWnd ||
  116. !m_y_radio.m_hWnd ||
  117. !m_z_radio.m_hWnd ||
  118. !m_user_radio.m_hWnd)
  119. return;
  120. m_x_radio.SetCheck(BST_UNCHECKED);
  121. m_y_radio.SetCheck(BST_UNCHECKED);
  122. m_z_radio.SetCheck(BST_UNCHECKED);
  123. m_user_radio.SetCheck(BST_UNCHECKED);
  124. switch(m_vector_type) {
  125. case X_VECTOR:
  126. m_x_radio.SetCheck(BST_CHECKED);
  127. break;
  128. case Y_VECTOR:
  129. m_y_radio.SetCheck(BST_CHECKED);
  130. break;
  131. case Z_VECTOR:
  132. m_z_radio.SetCheck(BST_CHECKED);
  133. break;
  134. case USER_VECTOR:
  135. m_user_radio.SetCheck(BST_CHECKED);
  136. break;
  137. default:
  138. ASSERT(0);
  139. break;
  140. }
  141. }
  142. // CGetVectorDlg message handlers
  143. void    CGetVectorDlg::SetVector(VECTOR_TYPE n_t, 
  144.  double x, double y, double z)
  145. {
  146. switch(n_t) {
  147. case X_VECTOR:
  148. m_x_edit.SetValue(1.0f);
  149. m_y_edit.SetValue(0.0f);
  150. m_z_edit.SetValue(0.0f);
  151. EnableUserNormalControls(FALSE);
  152. break;
  153. case Y_VECTOR:
  154. m_x_edit.SetValue(0.0f);
  155. m_y_edit.SetValue(1.0f);
  156. m_z_edit.SetValue(0.0f);
  157. EnableUserNormalControls(FALSE);
  158. break;
  159. case Z_VECTOR:
  160. m_x_edit.SetValue(0.0f);
  161. m_y_edit.SetValue(0.0f);
  162. m_z_edit.SetValue(1.0f);
  163. EnableUserNormalControls(FALSE);
  164. break;
  165. case USER_VECTOR:
  166. m_x_edit.SetValue(static_cast<float>(x));
  167. m_y_edit.SetValue(static_cast<float>(y));
  168. m_z_edit.SetValue(static_cast<float>(z));
  169. EnableUserNormalControls(TRUE);
  170. break;
  171. default:
  172. ASSERT(0);
  173. break;
  174. }
  175. UpdateData(FALSE);
  176. m_vector_type = n_t;
  177. UpdateRadios();
  178. }
  179. IGetVectorPanel::VECTOR_TYPE  CGetVectorDlg::GetVector(double& x, double& y, double& z)
  180. {
  181. switch(m_vector_type) {
  182. case X_VECTOR:
  183. x = 1.0;
  184. y = 0.0;
  185. z = 0.0;
  186. break;
  187. case Y_VECTOR:
  188. x = 0.0;
  189. y = 1.0;
  190. z = 0.0;
  191. break;
  192. case Z_VECTOR:
  193. x = 0.0;
  194. y = 0.0;
  195. z = 1.0;
  196. break;
  197. case USER_VECTOR:
  198. x = static_cast<double>(m_x_edit.GetValue());
  199. y = static_cast<double>(m_y_edit.GetValue());
  200. z = static_cast<double>(m_z_edit.GetValue());
  201. break;
  202. default:
  203. ASSERT(0);
  204. break;
  205. }
  206. return m_vector_type;
  207. }
  208. bool  CGetVectorDlg::IsXFixed()
  209. {
  210. if (m_vector_type!=USER_VECTOR)
  211. return true;
  212. return m_x_edit.IsFixed();
  213. }
  214. bool  CGetVectorDlg::IsYFixed()
  215. {
  216. if (m_vector_type!=USER_VECTOR)
  217. return true;
  218. return m_y_edit.IsFixed();
  219. }
  220. bool  CGetVectorDlg::IsZFixed() 
  221. {
  222. if (m_vector_type!=USER_VECTOR)
  223. return true;
  224. return m_z_edit.IsFixed();
  225. }
  226. bool CGetVectorDlg::XFix(bool fix)
  227. {
  228. if (m_vector_type!=USER_VECTOR)
  229. return false;
  230. m_x_lock_btn.SetPressed(fix);
  231. return true;
  232. }
  233. bool CGetVectorDlg::YFix(bool fix)
  234. {
  235. if (m_vector_type!=USER_VECTOR)
  236. return false;
  237. m_y_lock_btn.SetPressed(fix);
  238. return true;
  239. }
  240. bool CGetVectorDlg::ZFix(bool fix)
  241. {
  242. if (m_vector_type!=USER_VECTOR)
  243. return false;
  244. m_z_lock_btn.SetPressed(fix);
  245. return true;
  246. }
  247. void CGetVectorDlg::OnOK()
  248. {
  249. }
  250. void CGetVectorDlg::OnCancel()
  251. {
  252. }
  253. BOOL CGetVectorDlg::OnInitDialog()
  254. {
  255. CDialog::OnInitDialog();
  256. CString lab;
  257. lab.LoadString(IDS_X_LOCK);
  258. m_x_lock_btn.SetToolTipText(lab);
  259. m_x_lock_btn.LoadBitmap(::LoadImage(::AfxGetResourceHandle(),
  260. MAKEINTRESOURCE(IDB_LOCK_BUTTON_BITMAP), 
  261. IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS));
  262. m_x_edit.SetFixButton(&m_x_lock_btn);
  263. lab.LoadString(IDS_Y_LOCK);
  264. m_y_lock_btn.SetToolTipText(lab);
  265. m_y_lock_btn.LoadBitmap(::LoadImage(::AfxGetResourceHandle(),
  266. MAKEINTRESOURCE(IDB_LOCK_BUTTON_BITMAP), 
  267. IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS));
  268. m_y_edit.SetFixButton(&m_y_lock_btn);
  269. lab.LoadString(IDS_Z_LOCK);
  270. m_z_lock_btn.SetToolTipText(lab);
  271. m_z_lock_btn.LoadBitmap(::LoadImage(::AfxGetResourceHandle(),
  272. MAKEINTRESOURCE(IDB_LOCK_BUTTON_BITMAP), 
  273. IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS));
  274. m_z_edit.SetFixButton(&m_z_lock_btn);
  275. UpdateRadios();
  276. return TRUE;  // return TRUE unless you set the focus to a control
  277. // EXCEPTION: OCX Property Pages should return FALSE
  278. }
  279. void CGetVectorDlg::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  280. {
  281. if (m_vector_type!=USER_VECTOR)
  282. {
  283. if(nChar==VK_RETURN || nChar==VK_ESCAPE)
  284. GetParent()->SendMessage(WM_CHAR,nChar,0);
  285. //CDialog::OnChar(nChar, nRepCnt, nFlags);
  286. return;
  287. }
  288. switch(nChar) 
  289. {
  290. case VK_RETURN:
  291. case VK_ESCAPE:
  292. ASSERT(0);
  293. return;
  294. default:
  295. {
  296. CWnd* focW = GetFocus();
  297. if (focW==&m_y_edit)
  298. {
  299. m_y_edit.OnChar(nChar,nRepCnt,nFlags);
  300. return;
  301. }
  302. else
  303. if (focW==&m_z_edit)
  304. {
  305. m_z_edit.OnChar(nChar,nRepCnt,nFlags);
  306. return;
  307. }
  308. else
  309. if (focW==&m_x_edit)
  310. {
  311. m_x_edit.OnChar(nChar,nRepCnt,nFlags);
  312. return;
  313. }
  314. else
  315. {
  316. m_x_edit.SendMessage(GET_DIALOGS_MESSAGE_PRE_SET_FOCUS,nChar,nRepCnt);
  317. }
  318. return;
  319. }
  320. break;
  321. }
  322. CDialog::OnChar(nChar, nRepCnt, nFlags);
  323. }
  324. void CGetVectorDlg::EnableUserNormalControls(BOOL enbl)
  325. {
  326. GetDlgItem(IDC_VEC_X_STATIC)->EnableWindow(enbl);
  327. GetDlgItem(IDC_VECTOR_X_EDIT)->EnableWindow(enbl);
  328. GetDlgItem(IDC_VECTOR_X_LOCK_BTN)->EnableWindow(enbl);
  329. GetDlgItem(IDC_VEC_Y_STATIC)->EnableWindow(enbl);
  330. GetDlgItem(IDC_VECTOR_Y_EDIT)->EnableWindow(enbl);
  331. GetDlgItem(IDC_VECTOR_Y_LOCK_BTN)->EnableWindow(enbl);
  332. GetDlgItem(IDC_VEC_Z_STATIC)->EnableWindow(enbl);
  333. GetDlgItem(IDC_VECTOR_Z_EDIT)->EnableWindow(enbl);
  334. GetDlgItem(IDC_VECTOR_Z_LOCK_BTN)->EnableWindow(enbl);
  335. }
  336. void CGetVectorDlg::OnBnClickedDirXLockBtn()
  337. {
  338. m_x_lock_btn.SetPressed(!m_x_lock_btn.IsPressed());
  339. }
  340. void CGetVectorDlg::OnBnClickedDirYLockBtn()
  341. {
  342. m_y_lock_btn.SetPressed(!m_y_lock_btn.IsPressed());
  343. }
  344. void CGetVectorDlg::OnBnClickedDirZLockBtn()
  345. {
  346. m_z_lock_btn.SetPressed(!m_z_lock_btn.IsPressed());
  347. }
  348. void CGetVectorDlg::OnBnClickedVectorXRadio()
  349. {
  350. if (m_vector_type==X_VECTOR)
  351. return;
  352. m_vector_type = X_VECTOR;
  353. UpdateRadios();
  354. // GetParent()->PostMessage(WM_CHANGE_VECTOR);
  355. EnableUserNormalControls(FALSE);
  356. if (global_commander)
  357. global_commander->SendCommanderMessage(ICommander::CM_UPDATE_COMMAND_PANEL,NULL);
  358. }
  359. void CGetVectorDlg::OnBnClickedVectorYRadio()
  360. {
  361. if (m_vector_type==Y_VECTOR)
  362. return;
  363. m_vector_type = Y_VECTOR;
  364. UpdateRadios();
  365. // GetParent()->PostMessage(WM_CHANGE_VECTOR);
  366. EnableUserNormalControls(FALSE);
  367. if (global_commander)
  368. global_commander->SendCommanderMessage(ICommander::CM_UPDATE_COMMAND_PANEL,NULL);
  369. }
  370. void CGetVectorDlg::OnBnClickedVectorZRadio()
  371. {
  372. if (m_vector_type==Z_VECTOR)
  373. return;
  374. m_vector_type = Z_VECTOR;
  375. UpdateRadios();
  376. // GetParent()->PostMessage(WM_CHANGE_VECTOR);
  377. EnableUserNormalControls(FALSE);
  378. if (global_commander)
  379. global_commander->SendCommanderMessage(ICommander::CM_UPDATE_COMMAND_PANEL,NULL);
  380. }
  381. void CGetVectorDlg::OnBnClickedVectorUserRadio()
  382. {
  383. if (m_vector_type==USER_VECTOR)
  384. return;
  385. m_vector_type = USER_VECTOR;
  386. UpdateRadios();
  387. // GetParent()->PostMessage(WM_CHANGE_VECTOR);
  388. EnableUserNormalControls(TRUE);
  389. if (global_commander)
  390. global_commander->SendCommanderMessage(ICommander::CM_UPDATE_COMMAND_PANEL,NULL);
  391. }
  392. BOOL CGetVectorDlg::OnEraseBkgnd(CDC* pDC)
  393. {
  394. // TODO: Add your message handler code here and/or call default
  395. return  TRUE;//__super::OnEraseBkgnd(pDC);
  396. }
  397. HBRUSH CGetVectorDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  398. {
  399. // Call the base class implementation first! Otherwise, it may
  400. // undo what we are trying to accomplish here.
  401. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  402. if (nCtlColor==CTLCOLOR_STATIC && (pWnd!=&m_x_edit) 
  403. && (pWnd!=&m_y_edit) && (pWnd!=&m_z_edit))
  404. {
  405. pDC->SetTextColor(0);
  406. //pDC->SetBkColor(RGB(255,255,255));
  407. pDC->SetBkMode(TRANSPARENT);
  408. hbr = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
  409. }
  410. return hbr;
  411. }
  412. void CGetVectorDlg::OnSize(UINT nType, int cx, int cy)
  413. {
  414. __super::OnSize(nType, cx, cy);
  415. if (m_x_edit.m_hWnd && cx>10)
  416. {
  417. CRect rcEd;
  418. CRect rcBt;
  419. m_x_edit.GetWindowRect(rcEd);
  420. ScreenToClient(rcEd);
  421. m_x_lock_btn.GetWindowRect(rcBt);
  422. ScreenToClient(rcBt);
  423. m_x_edit.MoveWindow(rcEd.left,rcEd.top,cx-rcEd.left-rcBt.Width()-3,rcEd.Height());
  424. m_x_edit.GetWindowRect(rcEd);
  425. ScreenToClient(rcEd);
  426. m_x_lock_btn.MoveWindow(rcEd.right+1,rcBt.top,rcBt.Width(),rcBt.Height());
  427. m_y_edit.GetWindowRect(rcEd);
  428. ScreenToClient(rcEd);
  429. m_y_lock_btn.GetWindowRect(rcBt);
  430. ScreenToClient(rcBt);
  431. m_y_edit.MoveWindow(rcEd.left,rcEd.top,cx-rcEd.left-rcBt.Width()-3,rcEd.Height());
  432. m_y_edit.GetWindowRect(rcEd);
  433. ScreenToClient(rcEd);
  434. m_y_lock_btn.MoveWindow(rcEd.right+1,rcBt.top,rcBt.Width(),rcBt.Height());
  435. m_z_edit.GetWindowRect(rcEd);
  436. ScreenToClient(rcEd);
  437. m_z_lock_btn.GetWindowRect(rcBt);
  438. ScreenToClient(rcBt);
  439. m_z_edit.MoveWindow(rcEd.left,rcEd.top,cx-rcEd.left-rcBt.Width()-3,rcEd.Height());
  440. m_z_edit.GetWindowRect(rcEd);
  441. ScreenToClient(rcEd);
  442. m_z_lock_btn.MoveWindow(rcEd.right+1,rcBt.top,rcBt.Width(),rcBt.Height());
  443. }
  444. }
  445. void CGetVectorDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  446. {
  447. switch(nChar) 
  448. {
  449. case 120:  // X
  450. case _T('X'):
  451. m_x_lock_btn.SetPressed(!m_x_lock_btn.IsPressed());
  452. break;
  453. case 121:  // Y
  454. case _T('Y'):
  455. m_y_lock_btn.SetPressed(!m_y_lock_btn.IsPressed());
  456. break;
  457. case 122:  // Z
  458. case _T('Z'):
  459. m_z_lock_btn.SetPressed(!m_z_lock_btn.IsPressed());
  460. break;
  461. case VK_RETURN:
  462. case VK_ESCAPE:
  463. ASSERT(0);
  464. return;
  465. default:
  466. break;
  467. }
  468. __super::OnKeyDown(nChar, nRepCnt, nFlags);
  469. }