MiniCADView.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:20k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // MiniCADView.cpp : implementation of the CMiniCADView class
  2. //
  3. #include "stdafx.h"
  4. #include "MiniCADView.h"
  5. #include "DrawingAttribute.h"
  6. #include "SelectParameterDlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMiniCADView
  14. IMPLEMENT_DYNCREATE(CMiniCADView, CScrollView)
  15. BEGIN_MESSAGE_MAP(CMiniCADView, CScrollView)
  16. //{{AFX_MSG_MAP(CMiniCADView)
  17. ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
  18. ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
  19. ON_WM_LBUTTONDOWN()
  20. ON_WM_RBUTTONDOWN()
  21. ON_WM_MOUSEMOVE()
  22. ON_WM_VSCROLL()
  23. ON_WM_DESTROY()
  24. ON_WM_HSCROLL()
  25. ON_COMMAND(ID_VIEW_ZOOMOUT, OnZoomout)
  26. ON_COMMAND(ID_VIEW_ZOOMIN, OnZoomin)
  27. ON_CBN_SELCHANGE(IDC_COLOR, OnSelchangeColor)
  28. ON_CBN_SELCHANGE(IDC_LINESTYLE, OnSelchangeLinestyle)
  29. ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
  30. ON_WM_SIZE()
  31. ON_COMMAND(ID_VIEW_REDRAW, OnViewRedraw)
  32. ON_COMMAND(ID_DRAW_SELECT, OnDrawSelect)
  33. ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  34. ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
  35. ON_COMMAND(ID_DRAW_ARC, OnDrawArc)
  36. ON_COMMAND(ID_DRAW_TEXT, OnDrawText)
  37. ON_UPDATE_COMMAND_UI(ID_DRAW_SELECT, OnUpdateDrawSelect)
  38. ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
  39. ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
  40. ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
  41. ON_UPDATE_COMMAND_UI(ID_DRAW_ARC, OnUpdateDrawArc)
  42. ON_UPDATE_COMMAND_UI(ID_DRAW_TEXT, OnUpdateDrawText)
  43. ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
  44. ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  45. ON_UPDATE_COMMAND_UI(ID_CHANGE_DELETE, OnUpdateChangeDelete)
  46.     ON_WM_ERASEBKGND()
  47. ON_CBN_SELCHANGE(IDC_FILESIZE, OnSelchangeFilesize)
  48. ON_COMMAND(ID_DRAW_MULTILINE, OnDrawMultiline)
  49. ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
  50. ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
  51. ON_COMMAND(ID_MODIFY_DELETE, OnModifyDelete)
  52. ON_COMMAND(ID_MODIFY_COPY, OnModifyCopy)
  53. ON_COMMAND(ID_MODIFY_CUT, OnModifyCut)
  54. ON_COMMAND(ID_MODIFY_CUTTOANGLE, OnModifyCuttoangle)
  55. ON_COMMAND(ID_MODIFY_LENGTHENTO, OnModifyLengthento)
  56. ON_COMMAND(ID_MODIFY_JOIN, OnModifyJoin)
  57. ON_COMMAND(ID_MODIFY_MIRROR, OnModifyMirror)
  58. ON_COMMAND(ID_MODIFY_VERTICAL, OnModifyVertical)
  59. ON_COMMAND(ID_DRAW_DOT, OnDrawDot)
  60. ON_COMMAND(ID_DRAW_CURVE, OnDrawCurve)
  61. ON_COMMAND(ID_MODIFY_MOVE, OnModifyMove)
  62. ON_COMMAND(ID_MODIFY_ROTATE, OnModifyRotate)
  63. ON_COMMAND(ID_DRAW_DEFINELINE, OnDrawDefineline)
  64. ON_COMMAND(ID_MODIFY_EXCURSION, OnModifyExcursion)
  65. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  66. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  67. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  68. ON_COMMAND(ID_FORMAT_DRAWINGATTRIBUTE, OnFormatDrawingAttribute)
  69. ON_COMMAND(ID_TOOL_SELECT, OnToolSelect)
  70. //}}AFX_MSG_MAP
  71. // Standard printing commands
  72. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  73. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  74. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CMiniCADView construction/destruction
  78. CMiniCADView::CMiniCADView()
  79. {
  80. pApp = (CMiniCADApp*)AfxGetApp();
  81. pMainWnd = (CMainFrame*)pApp->m_pMainWnd;
  82. }
  83. CMiniCADView::~CMiniCADView()
  84. {
  85. }
  86. BOOL CMiniCADView::PreCreateWindow(CREATESTRUCT& cs)
  87. {
  88. cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 0 ,(HBRUSH)::GetStockObject(WHITE_BRUSH), 0);
  89. return CView::PreCreateWindow(cs);
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMiniCADView printing
  93. BOOL CMiniCADView::OnPreparePrinting(CPrintInfo* pInfo)
  94. {
  95. // default preparation
  96. return DoPreparePrinting(pInfo);
  97. }
  98. void CMiniCADView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  99. {
  100. }
  101. void CMiniCADView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  102. {
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CMiniCADView diagnostics
  106. #ifdef _DEBUG
  107. void CMiniCADView::AssertValid() const
  108. {
  109. CView::AssertValid();
  110. }
  111. void CMiniCADView::Dump(CDumpContext& dc) const
  112. {
  113. CView::Dump(dc);
  114. }
  115. CMiniCADDoc* CMiniCADView::GetDocument() // non-debug version is inline
  116. {
  117. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMiniCADDoc)));
  118. return (CMiniCADDoc*)m_pDocument;
  119. }
  120. #endif //_DEBUG
  121. /////////////////////////////////////////////////////////////////////////////
  122. // CMiniCADView message handlers
  123. void CMiniCADView::OnInitialUpdate() 
  124. {
  125. CScrollView::OnInitialUpdate();
  126. CMiniCADDoc* pDoc = GetDocument();
  127. ASSERT_VALID(pDoc);
  128. CClientDC dc(this);
  129.     
  130. //在MDI子框架上显示标题,标题为图纸名
  131. CChildFrame* pChildWnd = (CChildFrame*)pMainWnd->MDIGetActive();
  132. pChildWnd->SetWindowText(pDoc->FileInfo.Name);
  133.     
  134. //初始化颜色复选框
  135. CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
  136. ColorCombo->EnableWindow(TRUE);
  137.     ColorCombo->SetCurSel(0);
  138. //初始化线形复选框
  139. CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
  140. LineStyleCombo->EnableWindow(TRUE);
  141. LineStyleCombo->SetCurSel(0);
  142. //初始化图纸尺寸复选框
  143. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
  144. psizeCombo->EnableWindow(TRUE);
  145. psizeCombo->SetCurSel(3);
  146.     //初始化绘图工具条 、光标
  147. SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
  148.     Proportion = 1.0;
  149. //根据图纸尺寸设置滚动条滚动区域(既客户区)
  150. size.cx = pDoc->FileInfo.size.cx + EXTRA_WIDTH * 2; 
  151.     size.cy = pDoc->FileInfo.size.cy + EXTRA_HIGTH * 2;
  152. SetScrollSizes(MM_TEXT, size);
  153. pDoc->m_ManageGraphObject.PageSize.cx = size.cx;
  154. pDoc->m_ManageGraphObject.PageSize.cy = size.cy;
  155. }
  156. ////////////////////////////////////////////////////////////////////////////////////////////////
  157. //改变视图背景颜色
  158. void CMiniCADView::OnEraseBkgnd (CDC* pDC)
  159. {
  160. CBrush Brush (RGB (200, 255, 255));
  161.     CBrush* pOldBrush = pDC->SelectObject (&Brush);
  162.     CRect rcClip ;
  163.     pDC->GetClipBox (&rcClip);
  164.     pDC-> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height ( ) , PATCOPY );
  165.     pDC->SelectObject (pOldBrush );
  166. }
  167. // CMiniCADView drawing
  168. void CMiniCADView::OnDraw(CDC* pDC)
  169. {
  170. CMiniCADDoc* pDoc = GetDocument();
  171. ASSERT_VALID(pDoc);
  172.   CBrush brush;
  173. RECT rect;
  174. RECT shadow;
  175. rect.left = EXTRA_WIDTH;
  176. rect.top = EXTRA_HIGTH;
  177. rect.right = rect.left + (long)(pDoc->FileInfo.size.cx * Proportion) + 1;
  178. rect.bottom = rect.top + (long)(pDoc->FileInfo.size.cy * Proportion) + 1;
  179. brush.CreateSolidBrush(RGB(192, 192, 192));
  180.     shadow.left = rect.left + 3;
  181. shadow.top = rect.bottom;
  182. shadow.right = rect.right + 3;
  183. shadow.bottom = shadow.top + 3;
  184.     pDC->FillRect(&shadow, &brush);
  185. shadow.left = rect.right;
  186. shadow.top = rect.top + 3;
  187. shadow.right = shadow.left + 3;
  188. shadow.bottom = rect.bottom + 3;
  189.     pDC->FillRect(&shadow, &brush);
  190. pDC->Rectangle(&rect);
  191.     //重画所有的图形对象
  192. pDoc->m_ManageGraphObject.RedrawAllObject(pDC);
  193. }
  194. //////////////////////////////////////////////////////////////////////////////////////////////
  195. void CMiniCADView::OnDrawSelect() 
  196. {
  197. CMiniCADDoc* pDoc = GetDocument();
  198. ASSERT_VALID(pDoc);
  199. pDoc->CurrentCommand = DRAW_SELECT;
  200. }
  201. void CMiniCADView::OnDrawLine() 
  202. {
  203. CMiniCADDoc* pDoc = GetDocument();
  204. ASSERT_VALID(pDoc);
  205. if(pDoc->m_ManageGraphObject.UnselectObject())
  206. Invalidate();
  207. pDoc->CurrentCommand = DRAW_LINE;
  208. }
  209. void CMiniCADView::OnDrawRect() 
  210. {
  211. CMiniCADDoc* pDoc = GetDocument();
  212. ASSERT_VALID(pDoc);
  213. if(pDoc->m_ManageGraphObject.UnselectObject())
  214. Invalidate();
  215. pDoc->CurrentCommand = DRAW_RECT;
  216. }
  217. void CMiniCADView::OnDrawCircle() 
  218. {
  219. CMiniCADDoc* pDoc = GetDocument();
  220. ASSERT_VALID(pDoc);
  221. if(pDoc->m_ManageGraphObject.UnselectObject())
  222. Invalidate();
  223. pDoc->CurrentCommand = DRAW_CIRCLE;
  224. }
  225. void CMiniCADView::OnDrawArc() 
  226. {
  227. CMiniCADDoc* pDoc = GetDocument();
  228. ASSERT_VALID(pDoc);
  229. if(pDoc->m_ManageGraphObject.UnselectObject())
  230. Invalidate();
  231. pDoc->CurrentCommand = DRAW_ARC;
  232. }
  233. void CMiniCADView::OnDrawMultiline() 
  234. {
  235. }
  236. void CMiniCADView::OnDrawPolygon() 
  237. {
  238. }
  239. void CMiniCADView::OnDrawEllipse() 
  240. {
  241. }
  242. void CMiniCADView::OnDrawDot() 
  243. {
  244. }
  245. void CMiniCADView::OnDrawCurve() 
  246. {
  247. }
  248. void CMiniCADView::OnDrawDefineline() 
  249. {
  250. }
  251. void CMiniCADView::OnDrawText() 
  252. {
  253. CMiniCADDoc* pDoc = GetDocument();
  254. ASSERT_VALID(pDoc);
  255. if(pDoc->m_ManageGraphObject.UnselectObject())
  256. Invalidate();
  257. pDoc->CurrentCommand = DRAW_TEXT;
  258. }
  259. ///////////////////////////////////////////////////////////////////////////////////////////////
  260. void CMiniCADView::OnUpdateDrawLine(CCmdUI* pCmdUI) 
  261. {
  262. CMiniCADDoc* pDoc = GetDocument();
  263. ASSERT_VALID(pDoc);
  264. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_LINE);
  265. //继续传递当前命令
  266. pCmdUI->ContinueRouting();
  267. }
  268. void CMiniCADView::OnUpdateDrawRect(CCmdUI* pCmdUI) 
  269. {
  270. CMiniCADDoc* pDoc = GetDocument();
  271. ASSERT_VALID(pDoc);
  272. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_RECT);
  273. pCmdUI->ContinueRouting();
  274. }
  275. void CMiniCADView::OnUpdateDrawCircle(CCmdUI* pCmdUI) 
  276. {
  277. CMiniCADDoc* pDoc = GetDocument();
  278. ASSERT_VALID(pDoc);
  279. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_CIRCLE);
  280. pCmdUI->ContinueRouting();
  281. }
  282. void CMiniCADView::OnUpdateDrawArc(CCmdUI* pCmdUI) 
  283. {
  284. CMiniCADDoc* pDoc = GetDocument();
  285. ASSERT_VALID(pDoc);
  286. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_ARC);
  287. pCmdUI->ContinueRouting();
  288. }
  289. void CMiniCADView::OnUpdateDrawText(CCmdUI* pCmdUI) 
  290. {
  291. CMiniCADDoc* pDoc = GetDocument();
  292. ASSERT_VALID(pDoc);
  293. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_TEXT);
  294. pCmdUI->ContinueRouting();
  295. }
  296. ///////////////////////////////////////////////////////////////////////////////////////////////
  297. //mouse message
  298. void CMiniCADView::OnLButtonDown(UINT nFlags, CPoint point) 
  299. {
  300.     CMiniCADDoc* pDoc = GetDocument();
  301. ASSERT_VALID(pDoc);
  302. CClientDC dc(this);
  303. OnPrepareDC(&dc);
  304. dc.DPtoLP(&point);
  305. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  306. {
  307. pDoc->m_ManageGraphObject.GetDC(&dc);
  308. pDoc->m_ManageGraphObject.OnLButtonDown(pDoc->CurrentCommand, point);
  309. }
  310. CScrollView::OnLButtonDown(nFlags, point);
  311. }
  312. void CMiniCADView::OnRButtonDown(UINT nFlags, CPoint point) 
  313. {
  314. CMiniCADDoc* pDoc = GetDocument();
  315. ASSERT_VALID(pDoc);
  316. CClientDC dc(this);
  317. OnPrepareDC(&dc);
  318. dc.DPtoLP(&point);
  319. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  320. {
  321. pDoc->m_ManageGraphObject.GetDC(&dc);
  322. pDoc->CurrentCommand = pDoc->m_ManageGraphObject.OnRButtonDown(pDoc->CurrentCommand, point);
  323. }
  324. CScrollView::OnRButtonDown(nFlags, point);
  325. }
  326. void CMiniCADView::OnMouseMove(UINT nFlags, CPoint point) 
  327. {
  328. CMiniCADDoc* pDoc = GetDocument();
  329. ASSERT_VALID(pDoc);
  330. char x[32];
  331. char y[32];
  332. int count;
  333. CClientDC dc(this);
  334.     OnPrepareDC(&dc);
  335. dc.DPtoLP(&point);
  336. /*在状态栏中显示坐标*/
  337. count = sprintf(x, "%s", "X = ");
  338. sprintf(x + count, "%f", (float)(point.x - EXTRA_WIDTH) / Proportion);
  339. pMainWnd->m_wndStatusBar.SetPaneText(1, x, TRUE);
  340. count = sprintf(y, "%s", "Y = ");
  341. sprintf(y + count, "%f", (float)(size.cy - point.y - EXTRA_HIGTH) / Proportion);
  342. pMainWnd->m_wndStatusBar.SetPaneText(2, y, TRUE);
  343. /*在状态栏中显示坐标*/
  344. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  345. {
  346. pDoc->m_ManageGraphObject.GetDC(&dc);
  347. pDoc->m_ManageGraphObject.OnMouseMove(pDoc->CurrentCommand, point);
  348. }
  349. CScrollView::OnMouseMove(nFlags, point);
  350. }
  351. void CMiniCADView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  352. {
  353. CMiniCADDoc* pDoc = GetDocument();
  354. ASSERT_VALID(pDoc);
  355. CClientDC dc(this);
  356. OnPrepareDC(&dc);
  357. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  358. {
  359. pDoc->m_ManageGraphObject.GetDC(&dc);
  360. pDoc->m_ManageGraphObject.OnScroll(pDoc->CurrentCommand);
  361. }
  362.     
  363.     CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
  364. }
  365. void CMiniCADView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  366. {
  367. CMiniCADDoc* pDoc = GetDocument();
  368. ASSERT_VALID(pDoc);
  369. CClientDC dc(this);
  370. OnPrepareDC(&dc);
  371. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  372. {
  373. pDoc->m_ManageGraphObject.GetDC(&dc);
  374. pDoc->m_ManageGraphObject.OnScroll(pDoc->CurrentCommand);
  375. }
  376. CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
  377. }
  378. void CMiniCADView::OnDestroy() 
  379. {
  380. CScrollView::OnDestroy();
  381. CMiniCADDoc* pDoc = GetDocument();
  382. ASSERT_VALID(pDoc);
  383. pDoc->CurrentCommand = DRAW_SELECT;
  384. }
  385. //屏幕放大
  386. void CMiniCADView::OnZoomout() 
  387. {
  388. CMiniCADDoc* pDoc = GetDocument();
  389. ASSERT_VALID(pDoc);
  390. if(Proportion < 4)
  391. {
  392. Proportion += 0.25;
  393.         pDoc->m_ManageGraphObject.Proportion = Proportion;
  394. //根据图纸尺寸设置滚动条滚动区域(既客户区)
  395. size.cx = (long)(pDoc->FileInfo.size.cx * Proportion) + EXTRA_WIDTH * 2; 
  396. size.cy = (long)(pDoc->FileInfo.size.cy * Proportion) + EXTRA_HIGTH * 2;
  397. SetScrollSizes(MM_TEXT, size);
  398. pDoc->m_ManageGraphObject.PageSize.cx = size.cx;
  399. pDoc->m_ManageGraphObject.PageSize.cy = size.cy;
  400. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
  401.     psizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
  402. Invalidate();
  403. }
  404. }
  405. //屏幕缩小
  406. void CMiniCADView::OnZoomin() 
  407. {
  408. CMiniCADDoc* pDoc = GetDocument();
  409. ASSERT_VALID(pDoc);
  410.     if(Proportion > 0.25)
  411. {
  412. Proportion -= 0.25;
  413.         pDoc->m_ManageGraphObject.Proportion = Proportion;
  414. //根据图纸尺寸设置滚动条滚动区域(既客户区)
  415. size.cx = (long)(pDoc->FileInfo.size.cx * Proportion) + EXTRA_WIDTH * 2; 
  416. size.cy = (long)(pDoc->FileInfo.size.cy * Proportion) + EXTRA_HIGTH * 2;
  417. SetScrollSizes(MM_TEXT, size);
  418. pDoc->m_ManageGraphObject.PageSize.cx = size.cx;
  419. pDoc->m_ManageGraphObject.PageSize.cy = size.cy;
  420. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
  421.     psizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
  422. Invalidate();
  423. }
  424. }
  425. //选择图纸尺寸
  426. void CMiniCADView::OnSelchangeFilesize() 
  427. {
  428. CMiniCADDoc* pDoc = GetDocument();
  429. ASSERT_VALID(pDoc);
  430. int index;
  431. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
  432. index = psizeCombo->GetCurSel();
  433.     Proportion = (index + 1) * (float)0.25;
  434. pDoc->m_ManageGraphObject.Proportion = Proportion;
  435. //根据图纸尺寸设置滚动条滚动区域(既客户区)
  436. size.cx = (long)(pDoc->FileInfo.size.cx * Proportion) + EXTRA_WIDTH * 2; 
  437. size.cy = (long)(pDoc->FileInfo.size.cy * Proportion) + EXTRA_HIGTH * 2;
  438. SetScrollSizes(MM_TEXT, size);
  439. pDoc->m_ManageGraphObject.PageSize.cx = size.cx;
  440. pDoc->m_ManageGraphObject.PageSize.cy = size.cy;
  441. Invalidate();
  442. }
  443. void CMiniCADView::OnSelchangeColor() 
  444. {
  445. CMiniCADDoc* pDoc = GetDocument();
  446. ASSERT_VALID(pDoc);
  447. CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
  448. switch(ColorCombo->GetCurSel())
  449. {
  450. case 0:
  451. pDoc->PenColor = RGB(0, 0, 0);
  452. break;
  453. case 1:
  454. pDoc->PenColor = RGB(255, 0, 0);
  455. break;
  456. case 2:
  457. pDoc->PenColor = RGB(255, 255, 0);
  458. break;
  459. case 3:
  460. pDoc->PenColor = RGB(0, 255, 0);
  461. break;
  462. case 4:
  463. pDoc->PenColor = RGB(0, 255, 255);
  464. break;
  465. case 5:
  466. pDoc->PenColor = RGB(0, 0, 255);
  467. break;
  468. case 6:
  469. pDoc->PenColor = RGB( 255, 0, 255);
  470. break;
  471. }
  472.     pDoc->m_ManageGraphObject.SetPenColor(pDoc->PenColor);
  473. }
  474. void CMiniCADView::OnSelchangeLinestyle() 
  475. {
  476. CMiniCADDoc* pDoc = GetDocument();
  477. ASSERT_VALID(pDoc);
  478. CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
  479. switch(LineStyleCombo->GetCurSel())
  480. {
  481. case 0:
  482. pDoc->LineStyle = PS_SOLID;
  483. break;
  484. case 1:
  485. pDoc->LineStyle = PS_DASH;
  486. break;
  487. case 2:
  488. pDoc->LineStyle = PS_DOT;
  489. break;
  490. case 3:
  491. pDoc->LineStyle = PS_DASHDOT;
  492. break;
  493. case 4:
  494. pDoc->LineStyle = PS_DASHDOTDOT;
  495. break;
  496. }
  497.     pDoc->m_ManageGraphObject.SetLineStyle(pDoc->LineStyle);
  498. }
  499. void CMiniCADView::OnSize(UINT nType, int cx, int cy) 
  500. {
  501. CScrollView::OnSize(nType, cx, cy);
  502. /* //当改变视图尺寸时取消当前的绘图命令
  503. pDoc->CurrentCommand = DRAW_SELECT;
  504. pDoc->LRepeatTimes = 0;
  505. */
  506. }
  507. void CMiniCADView::OnViewRedraw() 
  508. {
  509. //激活OnDraw()函数,重画当前视图
  510. Invalidate();
  511. }
  512. void CMiniCADView::OnEditUndo() 
  513. {
  514. CMiniCADDoc* pDoc = GetDocument();
  515. ASSERT_VALID(pDoc);
  516.     pDoc->m_ManageGraphObject.OnUndo();
  517. Invalidate();
  518. }
  519. void CMiniCADView::OnUpdateEditUndo(CCmdUI* pCmdUI) 
  520. {
  521. CMiniCADDoc* pDoc = GetDocument();
  522. if(pDoc->m_CommandStack.CanUndo())
  523. pCmdUI->Enable(TRUE);
  524. else
  525. pCmdUI->Enable(FALSE);
  526. }
  527. void CMiniCADView::OnEditRedo() 
  528. {
  529. CMiniCADDoc* pDoc = GetDocument();
  530. ASSERT_VALID(pDoc);
  531.     pDoc->m_ManageGraphObject.OnRedo();
  532. Invalidate();
  533. }
  534. void CMiniCADView::OnUpdateEditRedo(CCmdUI* pCmdUI) 
  535. {
  536. CMiniCADDoc* pDoc = GetDocument();
  537. ASSERT_VALID(pDoc);
  538. if(pDoc->m_CommandStack.CanRedo())
  539.     pCmdUI->Enable(TRUE);
  540. else
  541. pCmdUI->Enable(FALSE);
  542. }
  543. void CMiniCADView::OnUpdateDrawSelect(CCmdUI* pCmdUI) 
  544. {
  545. CMiniCADDoc* pDoc = GetDocument();
  546. ASSERT_VALID(pDoc);
  547. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_SELECT);
  548. pCmdUI->ContinueRouting();
  549. }
  550. void CMiniCADView::OnModifyDelete() 
  551. {
  552. int* pObjectType;
  553. int* pObjetcIndex;
  554. int nIndex;
  555. int num;
  556. CGraphObjectInfo* pLineInfo;
  557. CGraphObjectInfo* pRectInfo;
  558. CGraphObjectInfo* pCircleInfo;
  559. CGraphObjectInfo* pArcInfo;
  560. CSelectedObjectInfo* pSelObjectInfo;
  561. CMiniCADDoc* pDoc = GetDocument();
  562. ASSERT_VALID(pDoc);
  563. num = pDoc->m_ManageGraphObject.m_SelObjInfoArray.GetSize();
  564. pObjectType = new int[num];
  565. pObjetcIndex = new int[num];
  566. for(nIndex = 0; nIndex < num; nIndex++)
  567. {
  568. pSelObjectInfo = (CSelectedObjectInfo*)pDoc->m_ManageGraphObject.m_SelObjInfoArray.GetAt(nIndex);
  569. switch(pSelObjectInfo->m_type)
  570. {
  571. case OBJECT_LINE:
  572. pLineInfo = (CGraphObjectInfo*)pDoc->m_ManageGraphObject.m_LineInfoArray.GetAt(pSelObjectInfo->m_index);
  573. pLineInfo->m_del = TRUE;
  574. pObjectType[nIndex] = OBJECT_LINE;
  575. pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
  576. break;
  577. case OBJECT_RECT:
  578. pRectInfo = (CGraphObjectInfo*)pDoc->m_ManageGraphObject.m_RectInfoArray.GetAt(pSelObjectInfo->m_index);
  579. pRectInfo->m_del = TRUE;
  580. pObjectType[nIndex] = OBJECT_RECT;
  581. pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
  582. break;
  583. case OBJECT_CIRCLE:
  584. pCircleInfo = (CGraphObjectInfo*)pDoc->m_ManageGraphObject.m_CircleInfoArray.GetAt(pSelObjectInfo->m_index);
  585. pCircleInfo->m_del = TRUE;
  586. pObjectType[nIndex] = OBJECT_CIRCLE;
  587. pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
  588. break;
  589. case OBJECT_ARC:
  590. pArcInfo = (CGraphObjectInfo*)pDoc->m_ManageGraphObject.m_ArcInfoArray.GetAt(pSelObjectInfo->m_index);
  591. pArcInfo->m_del = TRUE;
  592. pObjectType[nIndex] = OBJECT_ARC;
  593. pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
  594. break;
  595. }
  596. }
  597. pDoc->m_CommandStack.PushCommand(ID_CHANGE_DELETE, num, pObjectType, pObjetcIndex);
  598.     pDoc->m_ManageGraphObject.UnselectObject();
  599. Invalidate();
  600. delete pObjectType;
  601. delete pObjetcIndex;
  602. }
  603. void CMiniCADView::OnUpdateChangeDelete(CCmdUI* pCmdUI) 
  604. {
  605. CMiniCADDoc* pDoc = GetDocument();
  606. ASSERT_VALID(pDoc);
  607. if(pDoc->m_ManageGraphObject.m_SelObjInfoArray.GetSize() > 0)
  608. pCmdUI->Enable(TRUE);
  609. else
  610. pCmdUI->Enable(FALSE);
  611. }
  612. void CMiniCADView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  613. {
  614. CScrollView::OnPrepareDC(pDC, pInfo);
  615. }
  616. void CMiniCADView::OnModifyCopy() 
  617. {
  618. }
  619. void CMiniCADView::OnModifyCut() 
  620. {
  621. }
  622. void CMiniCADView::OnModifyCuttoangle() 
  623. {
  624. }
  625. void CMiniCADView::OnModifyLengthento() 
  626. {
  627. }
  628. void CMiniCADView::OnModifyJoin() 
  629. {
  630. }
  631. void CMiniCADView::OnModifyMirror() 
  632. {
  633. }
  634. void CMiniCADView::OnModifyVertical() 
  635. {
  636. }
  637. void CMiniCADView::OnModifyMove() 
  638. {
  639. }
  640. void CMiniCADView::OnModifyRotate() 
  641. {
  642.   
  643. }
  644. void CMiniCADView::OnModifyExcursion() 
  645. {
  646. }
  647. void CMiniCADView::OnEditCopy() 
  648. {
  649. }
  650. void CMiniCADView::OnEditCut() 
  651. {
  652. }
  653. void CMiniCADView::OnEditPaste() 
  654. {
  655. }
  656. void CMiniCADView::OnFormatDrawingAttribute() 
  657. {
  658. CDrawingAttributeDlg  dlg;
  659. dlg.DoModal();
  660. }
  661. void CMiniCADView::OnToolSelect() 
  662. {
  663. CSelectParameterDlg dlg;
  664. dlg.DoModal();
  665. }