CADView.cpp
上传用户:shangwu01
上传日期:2013-04-22
资源大小:707k
文件大小:19k
源码类别:

CAD

开发平台:

Visual C++

  1. // CADView.cpp : implementation of the CCADView class
  2. //
  3. #include "stdafx.h"
  4. #include "CAD.h"
  5. #include "CADDoc.h"
  6. #include "CADView.h"
  7. #include "MainFrm.h"
  8. #include "DLG_ARC1.h"
  9. #include "DLG_ARC2.h"
  10. #include "DLG_LINE.h"
  11. #include "DLG_RECTANGE.h"
  12. #include "DLG_ELLIPS.h"
  13. #include "DLG_CIRCLE.h"
  14. #include "math.h"
  15. #include "DLG_Remove.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CCADView
  23. IMPLEMENT_DYNCREATE(CCADView, CScrollView)
  24. BEGIN_MESSAGE_MAP(CCADView, CScrollView)
  25. //{{AFX_MSG_MAP(CCADView)
  26. ON_WM_PAINT()
  27. ON_WM_LBUTTONDOWN()
  28. ON_WM_LBUTTONUP()
  29. ON_WM_MOUSEMOVE()
  30. ON_WM_RBUTTONDOWN()
  31. ON_WM_LBUTTONDBLCLK()
  32. ON_COMMAND(ID_BACK, OnBack)
  33. ON_COMMAND(ID_FRONT, OnFront)
  34. ON_COMMAND(ID_REMOVE, OnRemove)
  35. ON_COMMAND(ID_CATCH_certre, OnCATCHcertre)
  36. ON_UPDATE_COMMAND_UI(ID_CATCH_certre, OnUpdateCATCHcertre)
  37. ON_COMMAND(ID_CATCH_cross, OnCATCHcross)
  38. ON_UPDATE_COMMAND_UI(ID_CATCH_cross, OnUpdateCATCHcross)
  39. ON_COMMAND(ID_CATCH_cut, OnCATCHcut)
  40. ON_UPDATE_COMMAND_UI(ID_CATCH_cut, OnUpdateCATCHcut)
  41. ON_COMMAND(ID_CATCH_end, OnCATCHend)
  42. ON_UPDATE_COMMAND_UI(ID_CATCH_end, OnUpdateCATCHend)
  43. ON_COMMAND(ID_CATCH_middle, OnCATCHmiddle)
  44. ON_UPDATE_COMMAND_UI(ID_CATCH_middle, OnUpdateCATCHmiddle)
  45. ON_COMMAND(ID_DEL, OnDel)
  46. ON_WM_KEYDOWN()
  47. //}}AFX_MSG_MAP
  48. // Standard printing commands
  49. ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  50. ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  51. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CCADView construction/destruction
  55. CCADView::CCADView()
  56. {
  57. m_pBitmap=new CBitmap;
  58. m_pmdc=new CDC;
  59. m_click_times=1;
  60. ////////////////////
  61. catchend=false;
  62. catchcertre=false;
  63. catchmiddle=false;
  64. catchcross=false;
  65. catchcut=false;
  66. ///////////////////////
  67. m_selected=false;
  68. }
  69. CCADView::~CCADView()
  70. {
  71. }
  72. BOOL CCADView::PreCreateWindow(CREATESTRUCT& cs)
  73. {
  74. // TODO: Modify the Window class or styles here by modifying
  75. //  the CREATESTRUCT cs
  76. return CScrollView::PreCreateWindow(cs);
  77. }
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CCADView drawing
  80. void CCADView::OnDraw(CDC* pDC)
  81. {
  82. CCADDoc* pDoc = GetDocument();
  83. ASSERT_VALID(pDoc);
  84. pDC->FillSolidRect(0,0,1200,2000,RGB(230,230,250));
  85. //////////////draw/////////////////////
  86. pDoc->m_line.Line_drawAttribution(pDC);
  87. pDoc->m_rectange.rectange_drawAttribution(pDC);
  88. pDoc->m_circle.circle_drawAttribution(pDC);
  89. pDoc->m_ellips.ellips_drawAttribution(pDC);
  90. pDoc->m_multline.multline_drawAttribution(pDC);
  91. pDoc->m_arc.arc_drawAttribution(pDC);
  92. if(m_click_times==1)
  93. catchpoint(m_pointorg,pDC);
  94. else if(m_click_times==2)
  95. catchpoint(m_pointfal,pDC);
  96. else if(m_click_times==3)
  97. catchpoint(m_pointend,pDC);
  98. if(m_click_times==2&&!pDoc->m_mode_flage)
  99. editdraw(m_click,pDC);//选中元素
  100. if(!pDoc->m_mode_flage)
  101. if(m_nStyle==1)
  102. {
  103. if(m_click_times==3)
  104. if(select==1||select==2)
  105. pDoc->m_line.Line_editdraw(m_pointorg,m_pointfal,pDC);//旋转
  106. else if(select==3)
  107. pDoc->m_line.Line_editmove(m_pointorg,m_pointfal,m_Num,pDC);//平移
  108. }
  109. else if(m_nStyle==3)
  110. {
  111. if(m_click_times==3)
  112. pDoc->m_circle.circle_editmove(m_pointorg,m_pointfal,m_Num,pDC);//平移
  113. }
  114. else if(m_nStyle==5)
  115. {
  116. if(m_click_times==3)
  117. pDoc->m_ellips.ellips_editmove(m_pointorg,m_pointfal,m_Num,pDC);//平移
  118. }
  119. else if(m_nStyle==7)
  120. {
  121. if(m_click_times==3)
  122. pDoc->m_arc.arc_editmove(m_pointorg,m_pointfal,m_Num,pDC);//平移
  123. }
  124. if(pDoc->m_mode_flage)
  125. if(pDoc->m_DrawType==1&&m_click_times==2)
  126. pDoc->m_line.Line_drawMove(m_pointorg,m_pointfal,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  127. else if(pDoc->m_DrawType==2&&m_click_times==2)
  128. pDoc->m_rectange.rectange_drawMove(m_pointorg,m_pointfal,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  129. else if(pDoc->m_DrawType==3&&m_click_times==2)
  130. pDoc->m_circle.circle_drawMove(m_pointorg,m_pointfal,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  131. else if(pDoc->m_DrawType==4)
  132. pDoc->m_multline.multline_drawMove(m_pointfal,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  133. else if(pDoc->m_DrawType==5&&m_click_times==2)
  134. pDoc->m_ellips.ellips_drawMove(m_pointorg,m_pointfal,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  135. else if(pDoc->m_DrawType==7)
  136. {
  137. if(m_click_times==2)
  138. pDoc->m_arc.arc_drawMoveline(m_pointorg,m_pointfal,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  139. if(m_click_times==3)
  140. {
  141. pDoc->m_arc.arc_drawMovearc(m_pointorg,m_pointfal,m_pointend,pDC,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  142. }
  143. }
  144. }
  145. void CCADView::OnInitialUpdate()
  146. {
  147. CScrollView::OnInitialUpdate();
  148. if(m_pmdc->m_hDC==NULL)
  149. {
  150. CClientDC dc(this);
  151. m_pmdc->CreateCompatibleDC(&dc);
  152. m_pBitmap->CreateCompatibleBitmap(&dc,2000,1000);
  153. }//创建内存DC和缓存
  154. CSize sizeTotal;
  155. // TODO: calculate the total size of this view
  156. sizeTotal.cx = sizeTotal.cy = 100;
  157. SetScrollSizes(MM_TEXT, sizeTotal);
  158. }
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CCADView printing
  161. BOOL CCADView::OnPreparePrinting(CPrintInfo* pInfo)
  162. {
  163. return DoPreparePrinting(pInfo);
  164. }
  165. void CCADView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  166. {
  167. }
  168. void CCADView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  169. {
  170. // TODO: add cleanup after printing
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. // CCADView diagnostics
  174. #ifdef _DEBUG
  175. void CCADView::AssertValid() const
  176. {
  177. CScrollView::AssertValid();
  178. }
  179. void CCADView::Dump(CDumpContext& dc) const
  180. {
  181. CScrollView::Dump(dc);
  182. }
  183. CCADDoc* CCADView::GetDocument() // non-debug version is inline
  184. {
  185. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCADDoc)));
  186. return (CCADDoc*)m_pDocument;
  187. }
  188. #endif //_DEBUG
  189. /////////////////////////////////////////////////////////////////////////////
  190. // CCADView message handlers
  191. void CCADView::OnPaint() 
  192. {
  193. CPaintDC dc(this); 
  194. CBitmap *pOldBitmap=m_pmdc->SelectObject(m_pBitmap);
  195. OnDraw(m_pmdc);
  196. dc.BitBlt(0,0,2000,1000,m_pmdc,0,0,SRCCOPY);
  197. m_pmdc->SelectObject(pOldBitmap);
  198. }
  199. void CCADView::OnLButtonDown(UINT nFlags, CPoint point) 
  200. {
  201. CCADDoc* pDoc = GetDocument();
  202. /////////////////////////////edit mode///////////////////////////////////////////////////
  203. if(!pDoc->m_mode_flage)
  204. {
  205. if(m_click_times==1)
  206. {
  207. m_click=point;
  208. m_click_times=2;
  209. this->Invalidate(false);
  210. return;
  211. }
  212. if(m_click_times==2)
  213. {
  214.   if(m_selected)
  215. if(editselect(point))
  216. {
  217. m_click_times=3;
  218. return;
  219. }
  220. m_click=point;
  221. this->Invalidate(false);
  222. return;
  223. }
  224. if(m_click_times==3)
  225. {
  226. m_pointfal=point;
  227. if(m_nStyle==1)
  228. {
  229. if(select==1||select==2)
  230. pDoc->m_line.Line_editstore(m_pointorg,m_pointfal,m_Num);
  231. else if(select==3)
  232. pDoc->m_line.Line_editmovestore(m_pointorg,m_pointfal,m_Num);
  233. }
  234. else if(m_nStyle==3)
  235. pDoc->m_circle.circle_editmovestore(m_pointorg,m_pointfal,m_Num);
  236. else if(m_nStyle==5)
  237. pDoc->m_ellips.ellips_editmovestore(m_pointorg,m_pointfal,m_Num);
  238. else if(m_nStyle==7)
  239. pDoc->m_arc.arc_editmovestore(m_pointorg,m_pointfal,m_Num);
  240. m_selected=false;
  241. m_click_times=1;
  242. this->Invalidate(false);
  243. return;
  244. }
  245. }
  246. /////////////////////////draw mode///////////////////////////////////////////////////////
  247. if((m_click_times==1)&&(pDoc->m_DrawType!=0))
  248. {
  249. m_pointorg=point;
  250. if(search(point)!=CPoint(-1,-1))
  251. m_pointorg=search(point);//寻找最近点
  252. if(pDoc->m_DrawType==4)
  253. {
  254. CPoint *ppoint=new CPoint(point);
  255. pDoc->m_multline.m_pointtemp.Add(ppoint);
  256. return;
  257. }//绘制连续直线
  258. m_click_times=2;
  259. return;
  260. }
  261. if(m_click_times==2)
  262. {
  263. m_pointfal=point;
  264. if(search(point)!=CPoint(-1,-1))
  265. m_pointfal=search(point);//寻找最近点
  266. if(pDoc->m_DrawType==1)
  267. pDoc->m_line.Line_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  268. else if(pDoc->m_DrawType==2)
  269. pDoc->m_rectange.rectange_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  270. else if(pDoc->m_DrawType==3)
  271. pDoc->m_circle.circle_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  272. else if(pDoc->m_DrawType==5)
  273. pDoc->m_ellips.ellips_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  274. else if(pDoc->m_DrawType==7)
  275. {
  276. m_click_times=3;
  277. return;
  278. }//绘制圆弧
  279. m_click_times=1;
  280. return;
  281. }
  282. if(m_click_times==3)
  283. {
  284. if(pDoc->m_DrawType==7)
  285. {
  286. m_pointend=point;
  287. if(search(point)!=CPoint(-1,-1))
  288. m_pointend=search(point);//寻找最近点
  289. pDoc->m_arc.arc_drawstore(m_pointorg,m_pointfal,m_pointend,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  290. m_click_times=1;
  291. return;//绘制圆弧
  292. }
  293. }
  294. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  295. CScrollView::OnLButtonDown(nFlags, point);
  296. }
  297. void CCADView::OnLButtonUp(UINT nFlags, CPoint point) 
  298. {
  299. CScrollView::OnLButtonUp(nFlags, point);
  300. }
  301. void CCADView::OnMouseMove(UINT nFlags, CPoint point) 
  302. {
  303. ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
  304. CCADDoc* pDoc = GetDocument();
  305. CMainFrame * pMainFrame=(CMainFrame*)AfxGetMainWnd();
  306. CStatusBar * pStatusBar=&pMainFrame->m_wndStatusBar;
  307. CString str;
  308. str.Format("x=%d,y=%d",m_selected,m_click_times);
  309. pStatusBar->SetPaneText(0,str,true);//鼠标移动时显示坐标point.x,point.y m_nStyle
  310. /////////////////////////////////////////////////////////////////////////////////////
  311.  if(!pDoc->m_mode_flage)
  312.  {
  313.  if(m_click_times==3)
  314.  {
  315.  m_pointfal=point;
  316.  this->Invalidate(false);
  317.  return;
  318.  }
  319. return;
  320.  }
  321. /////////////////////////////////////////////////////////////////////////////////////
  322. if((pDoc->m_DrawType==1)||(pDoc->m_DrawType==2)||(pDoc->m_DrawType==3)||(pDoc->m_DrawType==5)||(pDoc->m_DrawType==7))
  323. {
  324. if(m_click_times==1)
  325. {
  326. m_pointorg=point;
  327. this->Invalidate(false);
  328. }
  329. if(m_click_times==2)
  330. {
  331. m_pointfal=point;
  332. this->Invalidate(false);
  333. return;
  334. }
  335. if(m_click_times==3)
  336. {
  337. m_pointend=point;
  338. this->Invalidate(false);
  339. return;
  340. }
  341. }
  342. if(pDoc->m_DrawType==4)
  343. {
  344. m_pointfal=point;
  345. this->Invalidate(false);
  346. }
  347. CScrollView::OnMouseMove(nFlags, point);
  348. }
  349. void CCADView::OnRButtonDown(UINT nFlags, CPoint point)
  350. {
  351. if(m_click_times!=1)
  352. {
  353. m_click_times=1;
  354. this->Invalidate(false);
  355. }
  356. /* else if(m_click_times==1)
  357. {
  358. ClientToScreen(&point);
  359. CMenu menuPopUp;
  360. menuPopUp.LoadMenu(IDR_POPMANU);
  361. menuPopUp.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,this);
  362. }*/
  363. CScrollView::OnRButtonDown(nFlags, point);
  364. }
  365. void CCADView::OnLButtonDblClk(UINT nFlags, CPoint point) 
  366. {
  367. CCADDoc* pDoc = GetDocument();
  368. if(pDoc->m_DrawType==4)
  369. {
  370. pDoc->m_multline.multline_store(pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  371. m_click_times=1;
  372. }
  373. CScrollView::OnLButtonDblClk(nFlags, point);
  374. }
  375. void CCADView::OnBack() 
  376. {
  377. }
  378. void CCADView::OnFront() 
  379. {
  380. }
  381. void CCADView::OnRemove() 
  382. {
  383. CCADDoc* pDoc = GetDocument();
  384. CDLG_Remove dlg;
  385. if(dlg.DoModal()==IDOK)
  386. {
  387.     pDoc->m_line.m_line_save.RemoveAll();;
  388. pDoc->m_rectange.m_rectange_save.RemoveAll();
  389. pDoc->m_circle.m_circle_save.RemoveAll();
  390. pDoc->m_ellips.m_ellips_save.RemoveAll();
  391. pDoc->m_multline.m_multline_save.RemoveAll();
  392. pDoc->m_arc.m_arc_save.RemoveAll();
  393. this->Invalidate(false);
  394. }
  395. else
  396. return;
  397. }
  398. //////////////////////////////////////////////////////////////////////////////////
  399. void CCADView::OnCATCHcertre() 
  400. {
  401. if(!catchcertre)
  402. {
  403. catchcertre=true;
  404. return;
  405. }
  406. if(catchcertre)
  407. {
  408. catchcertre=false;
  409. return;
  410. }
  411. }
  412. void CCADView::OnUpdateCATCHcertre(CCmdUI* pCmdUI) 
  413. {
  414. if(catchcertre)
  415. pCmdUI->SetCheck(1);
  416. else
  417. pCmdUI->SetCheck(0);
  418. }
  419. void CCADView::OnCATCHcross() 
  420. {
  421. if(!catchcross)
  422. {
  423. catchcross=true;
  424. return;
  425. }
  426. if(catchcross)
  427. {
  428. catchcross=false;
  429. return;
  430. }
  431. }
  432. void CCADView::OnUpdateCATCHcross(CCmdUI* pCmdUI) 
  433. {
  434. if(catchcross)
  435. pCmdUI->SetCheck(1);
  436. else
  437. pCmdUI->SetCheck(0);
  438. }
  439. void CCADView::OnCATCHcut() 
  440. {
  441. if(!catchcut)
  442. {
  443. catchcut=true;
  444. return;
  445. }
  446. if(catchcut)
  447. {
  448. catchcut=false;
  449. return;
  450. }
  451. }
  452. void CCADView::OnUpdateCATCHcut(CCmdUI* pCmdUI) 
  453. {
  454. if(catchcut)
  455. pCmdUI->SetCheck(1);
  456. else
  457. pCmdUI->SetCheck(0);
  458. }
  459. void CCADView::OnCATCHend() 
  460. {
  461. if(!catchend)
  462. {
  463. catchend=true;
  464. return;
  465. }
  466. if(catchend)
  467. {
  468. catchend=false;
  469. return;
  470. }
  471. }
  472. void CCADView::OnUpdateCATCHend(CCmdUI* pCmdUI) 
  473. {
  474. if(catchend)
  475. pCmdUI->SetCheck(1);
  476. else
  477. pCmdUI->SetCheck(0);
  478. }
  479. void CCADView::OnCATCHmiddle() 
  480. {
  481. if(!catchmiddle)
  482. {
  483. catchmiddle=true;
  484. return;
  485. }
  486. if(catchmiddle)
  487. {
  488. catchmiddle=false;
  489. return;
  490. }
  491. }
  492. void CCADView::OnUpdateCATCHmiddle(CCmdUI* pCmdUI) 
  493. {
  494. if(catchmiddle)
  495. pCmdUI->SetCheck(1);
  496. else
  497. pCmdUI->SetCheck(0);
  498. }
  499. ///////////////////////////catchpoint////////////////////////////////////////////////////////
  500. void CCADView::catchpoint(CPoint point,CDC*pDC)
  501. {
  502. CCADDoc* pDoc = GetDocument();
  503. CRgn rgn;
  504. rgn.CreateRectRgn(point.x-50,point.y-50,point.x+50,point.y+50);
  505. if(catchend)
  506. {
  507. pDoc->m_line.Line_catchend(point,&rgn,pDC);
  508. pDoc->m_arc.arc_catchend(point,&rgn,pDC);
  509. }
  510. if(catchmiddle)
  511. {
  512. pDoc->m_line.Line_catchmiddle(point,&rgn,pDC);
  513. }
  514. if(catchcross)
  515. {
  516. }
  517. if(catchcertre)
  518. {
  519. pDoc->m_arc.arc_catchcertre(point,&rgn,pDC);
  520. pDoc->m_circle.circle_catchcertre(point,&rgn,pDC);
  521. pDoc->m_ellips.ellips_catchcertre(point,&rgn,pDC);
  522. }
  523. if(catchcut)
  524. {
  525. }
  526. }
  527. CPoint CCADView::search(CPoint point)
  528. {
  529. CCADDoc* pDoc = GetDocument();
  530. CPoint nearpoint;
  531. nearpoint.x=-1;
  532. nearpoint.y=-1;
  533. CRgn rgn;
  534. rgn.CreateRectRgn(point.x-50,point.y-50,point.x+50,point.y+50);
  535. if(catchend)
  536. {
  537. pDoc->m_line.Line_searchend(point,&nearpoint,&rgn);
  538. pDoc->m_arc.arc_searchend(point,&nearpoint,&rgn);
  539. }
  540. if(catchmiddle)
  541. {
  542. pDoc->m_line.Line_searchmiddle(point,&nearpoint,&rgn);
  543. }
  544. if(catchcertre)
  545. {
  546. pDoc->m_arc.arc_searchcertre(point,&nearpoint,&rgn);
  547. pDoc->m_circle.circle_searchcertre(point,&nearpoint,&rgn);
  548. pDoc->m_ellips.ellips_searchcertre(point,&nearpoint,&rgn);
  549. }
  550. return(nearpoint);
  551. }
  552. void CCADView::editdraw(CPoint point,CDC* pDC)
  553. {
  554. CCADDoc* pDoc = GetDocument();
  555. int Num,nStyle;
  556. if( pDoc->m_line.Line_searchline(point,&Num,&nStyle,pDC)||
  557. pDoc->m_circle.circle_searchcircle(point,&Num,&nStyle,pDC)||
  558. pDoc->m_ellips.ellips_searchellips(point,&Num,&nStyle,pDC)||
  559. pDoc->m_arc.arc_searcharc(point,&Num,&nStyle,pDC))
  560. {
  561. m_selected=true;
  562. m_Num=Num;
  563. m_nStyle=nStyle;
  564. }
  565. else
  566. m_selected=false;
  567. }
  568. bool CCADView::editselect(CPoint point)
  569. {
  570. bool flag;
  571. CPoint selectpoint;
  572. CCADDoc* pDoc = GetDocument();
  573. if(m_nStyle==1)
  574. {
  575. flag=pDoc->m_line.Line_editselect(point,&selectpoint,m_Num,&select);
  576. if(flag)
  577. {
  578. m_pointorg=selectpoint;
  579. return(true);
  580. }
  581. }
  582. else if(m_nStyle==3)
  583. {
  584. flag=pDoc->m_circle.circle_editselect(point,&selectpoint,m_Num);
  585. if(flag)
  586. {
  587. m_pointorg=selectpoint;
  588. return(true);
  589. }
  590. }
  591. else if(m_nStyle==5)
  592. {
  593. flag=pDoc->m_ellips.ellips_editselect(point,&selectpoint,m_Num);
  594. if(flag)
  595. {
  596. m_pointorg=selectpoint;
  597. return(true);
  598. }
  599. }
  600. else if(m_nStyle==7)
  601. {
  602. flag=pDoc->m_arc.arc_editselect(point,&selectpoint,m_Num);
  603. if(flag)
  604. {
  605. m_pointorg=selectpoint;
  606. return(true);
  607. }
  608. }
  609. return(false);
  610. }
  611. void CCADView::OnDel() 
  612. {
  613. CCADDoc* pDoc = GetDocument();
  614. if(m_selected)
  615. if(m_nStyle==1)
  616. {
  617. pDoc->m_line.Line_del(m_Num);
  618. this->Invalidate(false);
  619. }
  620. else if(m_nStyle==3)
  621. {
  622. pDoc->m_circle.circle_del(m_Num);
  623. this->Invalidate(false);
  624. }
  625. else if(m_nStyle==5)
  626. {
  627. pDoc->m_ellips.ellips_del(m_Num);
  628. this->Invalidate(false);
  629. }
  630. else if(m_nStyle==7)
  631. {
  632. pDoc->m_arc.arc_del(m_Num);
  633. this->Invalidate(false);
  634. }
  635. }
  636. void CCADView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  637. {
  638. CCADDoc* pDoc = GetDocument();
  639.  if(pDoc->m_mode_flage)
  640.  {
  641.  if(pDoc->m_DrawType==1)
  642.  {
  643.  if(m_click_times==2)
  644.  {
  645.  CDLG_LINE dlg;
  646.  if(dlg.DoModal()==IDOK)
  647.  {
  648.  m_pointfal=CPoint(dlg.m_Xsecond,dlg.m_Ysecond);
  649.  pDoc->m_line.Line_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  650. m_click_times=1;
  651. this->Invalidate(false);
  652. return;
  653.  }
  654.  else
  655.  return;
  656.  }  
  657.  }
  658. else if(pDoc->m_DrawType==2)
  659. {
  660. if(m_click_times==2)
  661. {
  662. CDLG_RECTANGE dlg;
  663. if(dlg.DoModal()==IDOK)
  664. {
  665. m_pointfal=CPoint(dlg.m_Xbottomright,dlg.m_Ybottomright);
  666. pDoc->m_rectange.rectange_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  667. m_click_times=1;
  668. this->Invalidate(false);
  669. return;
  670. }
  671. else
  672. return;
  673. }
  674. }
  675. else if(pDoc->m_DrawType==3)
  676. {
  677. if(m_click_times==2)
  678. {
  679. CDLG_CIRCLE dlg;
  680. if(dlg.DoModal()==IDOK)
  681. {
  682. if(dlg.m_select==1)
  683. m_pointfal=CPoint(dlg.m_Xsecond,dlg.m_Ysecond);
  684. else if(dlg.m_select==0)
  685. m_pointfal=CPoint(m_pointorg.x+dlg.m_R,m_pointorg.y);
  686. pDoc->m_circle.circle_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  687. m_click_times=1;
  688. this->Invalidate(false);
  689. return;
  690. }
  691. else
  692. return;
  693. }
  694. }
  695. else if(pDoc->m_DrawType==5)
  696. {
  697. if(m_click_times==2)
  698. {
  699. CDLG_ELLIPS dlg;
  700. if(dlg.DoModal()==IDOK)
  701. {
  702. m_pointfal=CPoint(m_pointorg.x+dlg.m_Xlength/2,m_pointorg.y+dlg.m_Ylength/2);
  703. pDoc->m_ellips.ellips_store(m_pointorg,m_pointfal,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  704. m_click_times=1;
  705. this->Invalidate(false);
  706. return;
  707. }
  708. else
  709. return;
  710. }
  711. }
  712. else if(pDoc->m_DrawType==7)
  713. {
  714. if(m_click_times==2)
  715. {
  716. CDLG_ARC1 dlg;
  717. if(dlg.DoModal()==IDOK)
  718. {
  719. m_pointfal=CPoint(m_pointorg.x+dlg.m_R*cos(dlg.m_ARC1*3.1415926/180),m_pointorg.y-dlg.m_R*sin(dlg.m_ARC1*3.1415926/180));
  720. m_click_times=3;
  721. this->Invalidate(false);
  722. return;
  723. }
  724. else
  725. return;
  726. }
  727. else if(m_click_times==3)
  728. {
  729. CDLG_ARC2 dlg;
  730. if(dlg.DoModal()==IDOK)
  731. {
  732. float R;
  733. R=sqrt(pow(m_pointorg.x-m_pointfal.x,2)+pow(m_pointorg.y-m_pointfal.y,2));
  734. m_pointend=CPoint(m_pointorg.x+R*cos(dlg.m_ARC2*3.1415926/180),m_pointorg.y-R*sin(dlg.m_ARC2*3.1415926/180));
  735. pDoc->m_arc.arc_drawstore(m_pointorg,m_pointfal,m_pointend,pDoc->m_line_style,pDoc->m_line_width,pDoc->m_line_color);
  736. m_click_times=1;
  737. this->Invalidate(false);
  738. return;
  739. }
  740. else
  741. return;
  742. }
  743. }
  744. else
  745.  return;
  746.  }
  747. CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
  748. }