ControlWnd.cpp
上传用户:wangdan
上传日期:2022-06-30
资源大小:739k
文件大小:12k
源码类别:

3D图形编程

开发平台:

Visual C++

  1. // ControlWnd.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Test1.h"
  5. #include "ControlWnd.h"
  6. #include "ProjectView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CControlWnd
  14. IMPLEMENT_DYNCREATE(CControlWnd, CFormView)
  15. extern GLfloat  xrof,yrof,zrof;
  16. extern bool   gbDataIsEmpty;
  17. CControlWnd::CControlWnd()
  18. : CFormView(CControlWnd::IDD)
  19. {
  20. //{{AFX_DATA_INIT(CControlWnd)
  21. m_nxZoom = 60;
  22. m_nyZoom = 5;
  23. m_nzZoom = 10;
  24. m_nMaxrange = 0.0f;
  25. m_nMinrange = 0.0f;
  26. //}}AFX_DATA_INIT
  27. m_bShowCoordinate = true;
  28. this->m_bShowConsult = true; 
  29. m_bXpWnd = false;
  30. pWnd = NULL;
  31. }
  32. CControlWnd::~CControlWnd()
  33. {
  34. if (pWnd)
  35. {
  36. delete pWnd;
  37. pWnd = NULL;
  38. }
  39. }
  40. void CControlWnd::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CFormView::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CControlWnd)
  44. DDX_Control(pDX, IDC_ZOOMBACK, m_ZoomBack);
  45. DDX_Control(pDX, IDC_ZOOMDEL, m_ZoomDel);
  46. DDX_Control(pDX, IDC_ZOOMADD, m_ZoomAdd);
  47. DDX_Control(pDX, IDC_SHOWTPWND, m_ShowXpWnd);
  48. DDX_Control(pDX, IDC_SHOWDATAWND, m_ShowDataWnd);
  49. DDX_Control(pDX, IDC_MINRANGE, m_Minrange);
  50. DDX_Control(pDX, IDC_MAXRANGE, m_Maxrange);
  51. DDX_Control(pDX, IDC_CLEAR_DATA, m_Clearbtn);
  52. DDX_Control(pDX, IDC_VIEWPIC, m_Viewpicbtn);
  53. DDX_Control(pDX, IDC_SETDEFAULT, m_SetDefaultbtn);
  54. DDX_Control(pDX, IDC_GETDATA, m_GetDatabtn);
  55. DDX_Control(pDX, IDC_PICVALUE, m_PicValue);
  56. DDX_Control(pDX, IDC_ALLVALUE, m_AllValue);
  57. DDX_Control(pDX, IDC_ZZOOM, m_zZoom);
  58. DDX_Control(pDX, IDC_YZOOM, m_yZoom);
  59. DDX_Control(pDX, IDC_XZOOM, m_xZoom);
  60. DDX_Text(pDX, IDC_XZOOM, m_nxZoom);
  61. DDX_Text(pDX, IDC_YZOOM, m_nyZoom);
  62. DDX_Text(pDX, IDC_ZZOOM, m_nzZoom);
  63. DDX_Text(pDX, IDC_MAXRANGE, m_nMaxrange);
  64. DDX_Text(pDX, IDC_MINRANGE, m_nMinrange);
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CControlWnd, CFormView)
  68. //{{AFX_MSG_MAP(CControlWnd)
  69. ON_BN_CLICKED(IDC_VIEWPIC, OnViewpic)
  70. ON_LBN_DBLCLK(IDC_ALLVALUE, OnDblclkAllvalue)
  71. ON_LBN_DBLCLK(IDC_PICVALUE, OnDblclkPicvalue)
  72. ON_BN_CLICKED(IDC_SETDEFAULT, OnSetdefault)
  73. ON_BN_CLICKED(IDC_RADIOTURN, OnRadioturn)
  74. ON_BN_CLICKED(IDC_RADIOSELECT, OnRadioselect)
  75. ON_BN_CLICKED(IDC_GETDATA, OnGetdata)
  76. ON_BN_CLICKED(IDC_CLEAR_DATA, OnClearData)
  77. ON_WM_CTLCOLOR()
  78. ON_BN_CLICKED(IDC_SHOWDATAWND, OnShowdatawnd)
  79. ON_BN_CLICKED(IDC_CHECKCONSULT, OnCheckconsult)
  80. ON_BN_CLICKED(IDC_CHECKCOOLDINATE, OnCheckcooldinate)
  81. ON_BN_CLICKED(IDC_RADIOTURNX, OnRadioturnx)
  82. ON_BN_CLICKED(IDC_RADIOTURNY, OnRadioturny)
  83. ON_BN_CLICKED(IDC_RADIOTURNZ, OnRadioturnz)
  84. ON_BN_CLICKED(IDC_SHOWTPWND, OnShowTpWnd)
  85. ON_BN_CLICKED(IDC_ZOOMADD, OnZoomAdd)
  86. ON_BN_CLICKED(IDC_ZOOMDEL, OnZoomdel)
  87. ON_BN_CLICKED(IDC_ZOOMBACK, OnZoomback)
  88. ON_BN_CLICKED(IDC_CHECKLIGHTING, OnChecklighting)
  89. //}}AFX_MSG_MAP
  90. ON_MESSAGE(MESSAGE_ENABLEBTN,EnableButton)
  91. ON_MESSAGE(MESSAGE_DISABLEBTN, DisableButton)
  92. ON_MESSAGE(MESSAGE_GETDATAFINISHED,GetData)
  93. END_MESSAGE_MAP()
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CControlWnd diagnostics
  96. #ifdef _DEBUG
  97. void CControlWnd::AssertValid() const
  98. {
  99. CFormView::AssertValid();
  100. }
  101. void CControlWnd::Dump(CDumpContext& dc) const
  102. {
  103. CFormView::Dump(dc);
  104. }
  105. #endif //_DEBUG
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CControlWnd message handlers
  108. void CControlWnd::OnViewpic() 
  109. {
  110. if(::gbDataIsEmpty)
  111. {
  112. MessageBox("当前没有任何数据,请重新加载数据!","提示信息",MB_ICONINFORMATION);
  113. return;
  114. }
  115. int nCount = this->m_PicValue.GetCount();
  116. if (nCount<3)
  117. {
  118. MessageBox("请选中三个数据进行交会成像","提示信息",MB_ICONINFORMATION);
  119. return;
  120. }
  121. CString Name = "";
  122. this->m_PicValue.GetText(0,Name);
  123. m_pFr->m_pView->m_First = GetPicData(Name);
  124. this->m_PicValue.GetText(1,Name);
  125. m_pFr->m_pView->m_Second = GetPicData(Name);
  126. this->m_PicValue.GetText(2,Name);
  127. m_pFr->m_pView->m_Third = GetPicData(Name);
  128. CString Angle;
  129. this->m_xZoom.GetWindowText(Angle);
  130. m_pFr->m_pView->m_Prox = atoi(Angle);
  131. this->m_yZoom.GetWindowText(Angle);
  132. m_pFr->m_pView->m_Proy = atoi(Angle);
  133. this->m_zZoom.GetWindowText(Angle);
  134. m_pFr->m_pView->m_Proz = atoi(Angle);
  135. this->m_Minrange.GetWindowText(Angle);
  136. m_pFr->m_pView->m_nMinDepth = atof(Angle);
  137. this->m_Maxrange.GetWindowText(Angle);
  138. m_pFr->m_pView->m_nMaxDepth = atof(Angle);
  139. m_pFr->InvalidateAllWnd();
  140. }
  141. void CControlWnd::FillListBox()
  142. {
  143. int nCount = m_AllValue.GetCount();
  144. for (int n=0; n<nCount; n++)
  145. m_AllValue.DeleteString(0);
  146. this->m_AllValue.InsertString(0,"ild");
  147. this->m_AllValue.InsertString(1,"ilm");
  148. this->m_AllValue.InsertString(2,"ll8");
  149. this->m_AllValue.InsertString(3,"lld");
  150. this->m_AllValue.InsertString(4,"lls");
  151. this->m_AllValue.InsertString(5,"rmll");
  152. this->m_AllValue.InsertString(6,"ml1");
  153. this->m_AllValue.InsertString(7,"ml2");
  154. this->m_AllValue.InsertString(8,"r04");
  155. this->m_AllValue.InsertString(9,"r4");
  156. this->m_AllValue.InsertString(10,"r25");
  157. this->m_AllValue.InsertString(11,"gr");
  158. nCount = this->m_PicValue.GetCount();
  159. for (n=0; n<nCount; n++)
  160. m_PicValue.DeleteString(0);
  161. this->m_PicValue.InsertString(0,"声波");
  162. this->m_PicValue.InsertString(1,"中子");
  163. this->m_PicValue.InsertString(2,"密度");
  164. }
  165. void CControlWnd::OnInitialUpdate() 
  166. {
  167. CFormView::OnInitialUpdate();
  168. this->m_pFr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
  169. /* m_pDataWnd = new CPicDataWnd;
  170. m_pDataWnd->Create(IDD_PICDATADLG,this);
  171. m_pDataWnd->ShowWindow(SW_HIDE);*/
  172. this->FillListBox();
  173. CButton* btn = (CButton*)GetDlgItem(IDC_RADIOTURN);
  174. btn->SetCheck(1);
  175. btn = (CButton*)GetDlgItem(IDC_CHECKCONSULT);
  176. btn->SetCheck(1);
  177. btn = (CButton*)GetDlgItem(IDC_CHECKCOOLDINATE);
  178. btn->SetCheck(1);
  179. btn = (CButton*)GetDlgItem(IDC_RADIOTURNX);
  180. btn->SetCheck(1);
  181. this->m_SetDefaultbtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  182. this->m_GetDatabtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  183. this->m_Viewpicbtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  184. this->m_Clearbtn.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  185. this->m_ShowDataWnd.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  186. m_ShowXpWnd.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  187. m_ZoomAdd.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  188. m_ZoomDel.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  189. m_ZoomBack.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
  190. GLfloat MaxDepth = m_pFr->m_pView->GetMaxDepth();
  191. }
  192. void CControlWnd::OnDblclkAllvalue() 
  193. {
  194. int index = this->m_AllValue.GetCurSel();
  195. int nCount = this->m_PicValue.GetCount();
  196. if (nCount>=3)
  197. return;
  198. CString name;
  199. this->m_AllValue.GetText(index,name);
  200. this->m_PicValue.InsertString(0,name);
  201. this->m_AllValue.DeleteString(index);
  202. }
  203. void CControlWnd::OnDblclkPicvalue() 
  204. {
  205. int index = this->m_PicValue.GetCurSel();
  206. CString name;
  207. this->m_PicValue.GetText(index,name);
  208. this->m_AllValue.InsertString(0,name);
  209. this->m_PicValue.DeleteString(index);
  210. }
  211. int CControlWnd::GetPicData(CString Name)
  212. {
  213. int nArrayValue = 0;
  214. if (Name == "声波")
  215. nArrayValue = 1;
  216. else if (Name == "中子")
  217. nArrayValue = 2;
  218. else if (Name == "密度")
  219. nArrayValue = 3;
  220. else if (Name == "ild")
  221. nArrayValue = 4;
  222. else if (Name == "ilm")
  223. nArrayValue = 5;
  224. else if (Name == "ll8")
  225. nArrayValue = 6;
  226. else if (Name == "lld")
  227. nArrayValue = 7;
  228. else if (Name == "lls")
  229. nArrayValue = 8;
  230. else if (Name == "rmll")
  231. nArrayValue = 9;
  232. else if (Name == "ml1")
  233. nArrayValue = 10;
  234. else if (Name == "ml2")
  235. nArrayValue = 11;
  236. else if (Name == "r04")
  237. nArrayValue = 12;
  238. else if (Name == "r4")
  239. nArrayValue = 13;
  240. else if (Name == "r25")
  241. nArrayValue = 14;
  242. else if (Name == "gr")
  243. nArrayValue = 15;
  244. return nArrayValue;
  245. }
  246. void CControlWnd::OnSetdefault() 
  247. {
  248. if(::gbDataIsEmpty)
  249. {
  250. MessageBox("当前没有任何数据,请重新加载数据!","提示信息",MB_ICONINFORMATION);
  251. return;
  252. }
  253. xrof = 0;
  254. yrof = 0;
  255. zrof = 0;
  256. m_pFr->m_pView->m_Prox = 60;
  257. m_pFr->m_pView->m_Proy = 5;
  258. m_pFr->m_pView->m_Proz = 10;
  259. m_pFr->m_pView->m_First = 1;
  260. m_pFr->m_pView->m_Second = 2;
  261. m_pFr->m_pView->m_Third = 3;
  262. m_pFr->m_pView->m_Zoom = 0;
  263. this->m_xZoom.SetWindowText("60");
  264. this->m_yZoom.SetWindowText("5");
  265. this->m_zZoom.SetWindowText("10");
  266. this->GetData(0,0);
  267. this->FillListBox();
  268. this->m_pFr->InvalidateAllWnd();
  269. }
  270. void CControlWnd::OnRadioturn() 
  271. {
  272. this->m_pFr->m_pView->m_bIsMove = true;
  273. this->m_pFr->m_pView->Invalidate();
  274. }
  275. void CControlWnd::OnRadioselect() 
  276. {
  277. this->m_pFr->m_pView->m_bIsMove = false;
  278. this->m_pFr->m_pView->Invalidate();
  279. }
  280. void CControlWnd::OnGetdata() 
  281. {
  282. CFileDialog dlg(TRUE,_T("3DSF"),_T("*.3DSF"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("三维交会图数据(*.3DSF)|*.3DSF|"));
  283. if (IDCANCEL == dlg.DoModal())
  284. return;
  285. CString FilePath = dlg.GetPathName();
  286. m_pFr->m_pView->m_FileName = FilePath;
  287. AfxBeginThread(CTest1View::ReadFile,m_pFr->m_pView);
  288. CString Wtext = "三维交会图演示系统,当前加载文件->";
  289. Wtext += FilePath;
  290. AfxGetMainWnd()->SetWindowText(Wtext);
  291. }
  292. void CControlWnd::OnClearData() 
  293. {
  294. if(::gbDataIsEmpty)
  295. {
  296. MessageBox("当前没有任何数据,请重新加载数据!","提示信息",MB_ICONINFORMATION);
  297. return;
  298. }
  299. this->m_pFr->m_pView->ZeroArray();
  300. ::gbDataIsEmpty = true;
  301. this->m_pFr->InvalidateAllWnd();//Invalidate();
  302. AfxGetMainWnd()->SetWindowText("三维交会图演示系统->没有任何数据");
  303. }
  304. void CControlWnd::EnableButton(LPARAM lp,WPARAM wp)
  305. {
  306. this->m_Clearbtn.EnableWindow(TRUE);
  307. this->m_GetDatabtn.EnableWindow();
  308. this->m_SetDefaultbtn.EnableWindow();
  309. this->m_Viewpicbtn.EnableWindow();
  310. }
  311. void CControlWnd::DisableButton(LPARAM lp, WPARAM wp)
  312. {
  313. this->m_Clearbtn.EnableWindow(FALSE);
  314. this->m_GetDatabtn.EnableWindow(FALSE);
  315. this->m_SetDefaultbtn.EnableWindow(FALSE);
  316. this->m_Viewpicbtn.EnableWindow(FALSE);
  317. }
  318. HBRUSH CControlWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  319. {
  320. HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
  321. /* if ( nCtlColor == CTLCOLOR_EDIT
  322.    ||nCtlColor == CTLCOLOR_LISTBOX 
  323.    || nCtlColor == CTLCOLOR_STATIC )
  324.    {
  325.    pDC->SetTextColor(RGB(255,0,0));
  326.    pDC->SetBkMode(1);
  327.    }*/
  328. return hbr;
  329. }
  330. void CControlWnd::OnShowdatawnd() 
  331. {
  332. this->m_pFr->SendMessage(WM_CLOSE);
  333. }
  334. void CControlWnd::GetData(LPARAM lp, WPARAM wp)
  335. {
  336. GLfloat Max = this->m_pFr->m_pView->m_nMaxDepth = this->m_pFr->m_pView->GetMaxDepth();
  337. GLfloat Min = this->m_pFr->m_pView->m_nMinDepth = this->m_pFr->m_pView->GetMinDepth();
  338. CString str;
  339. str.Format("%f",Max);
  340. this->m_Maxrange.SetWindowText(str);
  341. str.Format("%f",Min);
  342. this->m_Minrange.SetWindowText(str);
  343. this->m_pFr->InvalidateAllWnd();
  344. }
  345. void CControlWnd::OnCheckconsult() 
  346. {
  347. this->m_bShowConsult = !m_bShowConsult;
  348. this->m_pFr->m_pView->Invalidate();
  349. }
  350. void CControlWnd::OnCheckcooldinate() 
  351. {
  352. this->m_bShowCoordinate = !m_bShowCoordinate;
  353. this->m_pFr->m_pView->Invalidate();
  354. }
  355. void CControlWnd::OnRadioturnx() 
  356. {
  357. this->m_pFr->m_pView->nWithy = 0;
  358. }
  359. void CControlWnd::OnRadioturny() 
  360. {
  361. this->m_pFr->m_pView->nWithy = 1;
  362. }
  363. void CControlWnd::OnRadioturnz() 
  364. {
  365. this->m_pFr->m_pView->nWithy = 2;
  366. }
  367. void CControlWnd::OnShowTpWnd() 
  368. {
  369. if(!m_bXpWnd)
  370. {
  371. if (pWnd)
  372. {
  373. delete pWnd;
  374. pWnd = NULL;
  375. }
  376. GetDlgItem(IDC_SHOWTPWND)->SetWindowText("取消");
  377. m_bXpWnd = true;
  378. pWnd = new CXTPWnd;
  379. pWnd->XCreate("交会图外挂放大镜");
  380. }
  381. else
  382. {
  383. GetDlgItem(IDC_SHOWTPWND)->SetWindowText("放大镜");
  384. m_bXpWnd = false;
  385. pWnd->DestroyWindow();
  386. }
  387. }
  388. void CControlWnd::OnZoomAdd() 
  389. {
  390. if (this->m_pFr->m_pView->m_Zoom <3)
  391. {
  392. this->m_pFr->m_pView->m_Zoom ++;
  393. this->m_pFr->m_pView->Invalidate();
  394. }
  395. }
  396. void CControlWnd::OnZoomdel() 
  397. {
  398. if (this->m_pFr->m_pView->m_Zoom > 0)
  399. {
  400. this->m_pFr->m_pView->m_Zoom--;
  401. this->m_pFr->m_pView->Invalidate();
  402. }
  403. }
  404. void CControlWnd::OnZoomback() 
  405. {
  406. this->m_pFr->m_pView->m_Zoom = 0;
  407. this->m_pFr->m_pView->Invalidate();
  408. }
  409. void CControlWnd::OnChecklighting() 
  410. {
  411. this->m_pFr->m_pView->m_bLighting = !this->m_pFr->m_pView->m_bLighting; 
  412. this->m_pFr->m_pView->Invalidate();
  413. }