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

绘图程序

开发平台:

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_MODIFY_DELETE, OnUpdateModifyDelete)
  46.     ON_WM_ERASEBKGND()
  47. ON_CBN_SELCHANGE(IDC_PROPORTION, OnSelchangeProportion)
  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. ON_WM_KEYDOWN()
  71. //}}AFX_MSG_MAP
  72. // Standard printing commands
  73. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  74. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  75. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CMiniCADView construction/destruction
  79. CMiniCADView::CMiniCADView()
  80. {
  81. pApp = (CMiniCADApp*)AfxGetApp();
  82. pMainWnd = (CMainFrame*)pApp->m_pMainWnd;
  83. EffectRect.top = 0;
  84. EffectRect.left = 0;
  85. EffectRect.bottom = 0;
  86. EffectRect.right = 0;
  87. }
  88. CMiniCADView::~CMiniCADView()
  89. {
  90. }
  91. BOOL CMiniCADView::PreCreateWindow(CREATESTRUCT& cs)
  92. {
  93. cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 0 ,(HBRUSH)::GetStockObject(WHITE_BRUSH), 0);
  94. return CView::PreCreateWindow(cs);
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CMiniCADView printing
  98. BOOL CMiniCADView::OnPreparePrinting(CPrintInfo* pInfo)
  99. {
  100. // default preparation
  101. return DoPreparePrinting(pInfo);
  102. }
  103. void CMiniCADView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  104. {
  105. }
  106. void CMiniCADView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  107. {
  108. }
  109. /////////////////////////////////////////////////////////////////////////////
  110. // CMiniCADView diagnostics
  111. #ifdef _DEBUG
  112. void CMiniCADView::AssertValid() const
  113. {
  114. CView::AssertValid();
  115. }
  116. void CMiniCADView::Dump(CDumpContext& dc) const
  117. {
  118. CView::Dump(dc);
  119. }
  120. CMiniCADDoc* CMiniCADView::GetDocument() // non-debug version is inline
  121. {
  122. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMiniCADDoc)));
  123. return (CMiniCADDoc*)m_pDocument;
  124. }
  125. #endif //_DEBUG
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CMiniCADView message handlers
  128. void CMiniCADView::OnInitialUpdate() 
  129. {
  130. CScrollView::OnInitialUpdate();
  131. CMiniCADDoc* pDoc = GetDocument();
  132. ASSERT_VALID(pDoc);
  133. pDoc->m_ManageGraphObject.GetView(this);
  134. CClientDC dc(this);
  135.     
  136. //在MDI子框架上显示标题,标题为图纸名
  137. CChildFrame* pChildWnd = (CChildFrame*)pMainWnd->MDIGetActive();
  138. pChildWnd->SetWindowText(pDoc->FileInfo.m_Name);
  139.     
  140. //初始化颜色复选框
  141. CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
  142. ColorCombo->EnableWindow(TRUE);
  143.     ColorCombo->SetCurSel(0);
  144. //初始化线形复选框
  145. CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
  146. LineStyleCombo->EnableWindow(TRUE);
  147. LineStyleCombo->SetCurSel(0);
  148. //初始化图纸尺寸复选框
  149. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
  150. psizeCombo->EnableWindow(TRUE);
  151. psizeCombo->SetCurSel(3);
  152.     Proportion = 1.0;
  153. //设置图纸尺寸
  154. SetDrawingSize(pDoc->FileInfo.m_Size);
  155. //获取逻辑区尺寸
  156. LogicViewSize = GetLogicViewSize();
  157. //设置滚动区域
  158. SetScrollSizes(MM_TEXT, LogicViewSize);
  159. pDoc->m_ManageGraphObject.SetLogicSize(LogicViewSize);
  160. }
  161. ////////////////////////////////////////////////////////////////////////////////////////////////
  162. //改变视图背景颜色
  163. void CMiniCADView::OnEraseBkgnd (CDC* pDC)
  164. {
  165. CBrush Brush (RGB(180, 255, 255));
  166.     CBrush* pOldBrush = pDC->SelectObject (&Brush);
  167.     CRect rcClip ;
  168.     pDC->GetClipBox (&rcClip);
  169.     pDC-> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height ( ) , PATCOPY );
  170.     pDC->SelectObject (pOldBrush );
  171. }
  172. // CMiniCADView drawing
  173. void CMiniCADView::OnDraw(CDC* pDC)
  174. {
  175. CMiniCADDoc* pDoc = GetDocument();
  176. ASSERT_VALID(pDoc);
  177. if(pDoc->DocumentReady == FALSE)
  178. return;
  179.   CBrush brush;
  180. CRect rect;
  181. CRect shadow;
  182. rect = GetDrawingLogicRect();
  183. rect.right = rect.right + 1;
  184. rect.bottom = rect.bottom + 1;
  185. /*绘制阴影*/
  186. brush.CreateSolidBrush(RGB(192, 192, 192));
  187.     shadow.left = rect.left + 3;
  188. shadow.top = rect.bottom;
  189. shadow.right = rect.right + 3;
  190. shadow.bottom = shadow.top + 3;
  191.     pDC->FillRect(&shadow, &brush);
  192. shadow.left = rect.right;
  193. shadow.top = rect.top + 3;
  194. shadow.right = shadow.left + 3;
  195. shadow.bottom = rect.bottom + 3;
  196.     pDC->FillRect(&shadow, &brush);
  197. /*绘制阴影*/
  198. pDC->Rectangle(&rect);
  199. GetClientRect(EffectRect);
  200.     pDC->DPtoLP(EffectRect);
  201.     //重画所有的图形对象
  202. pDoc->m_ManageGraphObject.GetDC(pDC);
  203. pDoc->m_ManageGraphObject.SetEffectRect(EffectRect);
  204. pDoc->m_ManageGraphObject.RedrawAllObject(pDC);
  205. }
  206. //////////////////////////////////////////////////////////////////////////////////////////////
  207. BOOL CMiniCADView::BeforeCommand(CMiniCADDoc* pDoc)
  208. {
  209. CString CurrentLayerName = pDoc->m_ManageFileLayer.GetCurrentLayerName();
  210. if(CurrentLayerName == "")
  211. {
  212. MessageBox("没有当前图层", "提示", MB_OK | MB_ICONWARNING);
  213. return FALSE;
  214. }
  215. CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(CurrentLayerName);
  216. if(!pLayer->IsShow())
  217. {
  218. MessageBox("当前图层被隐藏", "提示", MB_OK | MB_ICONWARNING);
  219. return FALSE;
  220. }
  221. if(pLayer->IsLocked())
  222. {
  223. MessageBox("当前图层被锁定", "提示", MB_OK | MB_ICONWARNING);
  224. return FALSE;
  225. }
  226. pDoc->m_ManageGraphObject.SetCurrentLayerName(CurrentLayerName);
  227. return TRUE;
  228. }
  229. void CMiniCADView::OnDrawSelect() 
  230. {
  231. CMiniCADDoc* pDoc = GetDocument();
  232. ASSERT_VALID(pDoc);
  233. if(!BeforeCommand(pDoc))
  234. {
  235. pDoc->CurrentCommand = NO_COMMAND;
  236. return;
  237. }
  238. pDoc->CurrentCommand = DRAW_SELECT;
  239. }
  240. void CMiniCADView::OnDrawLine() 
  241. {
  242. CMiniCADDoc* pDoc = GetDocument();
  243. ASSERT_VALID(pDoc);
  244. if(!BeforeCommand(pDoc))
  245. {
  246. pDoc->CurrentCommand = NO_COMMAND;
  247. return;
  248. }
  249. if(pDoc->m_ManageGraphObject.UnselectObject())
  250. Invalidate();
  251. pDoc->CurrentCommand = DRAW_LINE;
  252. }
  253. void CMiniCADView::OnDrawRect() 
  254. {
  255. CMiniCADDoc* pDoc = GetDocument();
  256. ASSERT_VALID(pDoc);
  257. if(!BeforeCommand(pDoc))
  258. {
  259. pDoc->CurrentCommand = NO_COMMAND;
  260. return;
  261. }
  262. if(pDoc->m_ManageGraphObject.UnselectObject())
  263. Invalidate();
  264. pDoc->CurrentCommand = DRAW_RECT;
  265. }
  266. void CMiniCADView::OnDrawCircle() 
  267. {
  268. CMiniCADDoc* pDoc = GetDocument();
  269. ASSERT_VALID(pDoc);
  270. if(!BeforeCommand(pDoc))
  271. {
  272. pDoc->CurrentCommand = NO_COMMAND;
  273. return;
  274. }
  275. if(pDoc->m_ManageGraphObject.UnselectObject())
  276. Invalidate();
  277. pDoc->CurrentCommand = DRAW_CIRCLE;
  278. }
  279. void CMiniCADView::OnDrawArc() 
  280. {
  281. CMiniCADDoc* pDoc = GetDocument();
  282. ASSERT_VALID(pDoc);
  283. if(!BeforeCommand(pDoc))
  284. {
  285. pDoc->CurrentCommand = NO_COMMAND;
  286. return;
  287. }
  288. if(pDoc->m_ManageGraphObject.UnselectObject())
  289. Invalidate();
  290. pDoc->CurrentCommand = DRAW_ARC;
  291. }
  292. void CMiniCADView::OnDrawMultiline() 
  293. {
  294. CMiniCADDoc* pDoc = GetDocument();
  295. ASSERT_VALID(pDoc);
  296. if(!BeforeCommand(pDoc))
  297. {
  298. pDoc->CurrentCommand = NO_COMMAND;
  299. return;
  300. }
  301. if(pDoc->m_ManageGraphObject.UnselectObject())
  302. Invalidate();
  303. pDoc->CurrentCommand = DRAW_MULTILINE;
  304. }
  305. void CMiniCADView::OnDrawPolygon() 
  306. {
  307. CMiniCADDoc* pDoc = GetDocument();
  308. ASSERT_VALID(pDoc);
  309. if(!BeforeCommand(pDoc))
  310. {
  311. pDoc->CurrentCommand = NO_COMMAND;
  312. return;
  313. }
  314. if(pDoc->m_ManageGraphObject.UnselectObject())
  315. Invalidate();
  316. pDoc->CurrentCommand = DRAW_POLYGON;
  317. }
  318. void CMiniCADView::OnDrawEllipse() 
  319. {
  320. CMiniCADDoc* pDoc = GetDocument();
  321. ASSERT_VALID(pDoc);
  322. if(!BeforeCommand(pDoc))
  323. {
  324. pDoc->CurrentCommand = NO_COMMAND;
  325. return;
  326. }
  327. if(pDoc->m_ManageGraphObject.UnselectObject())
  328. Invalidate();
  329. pDoc->CurrentCommand = DRAW_ELLIPSE;
  330. }
  331. void CMiniCADView::OnDrawDot() 
  332. {
  333. CMiniCADDoc* pDoc = GetDocument();
  334. ASSERT_VALID(pDoc);
  335. if(!BeforeCommand(pDoc))
  336. {
  337. pDoc->CurrentCommand = NO_COMMAND;
  338. return;
  339. }
  340. if(pDoc->m_ManageGraphObject.UnselectObject())
  341. Invalidate();
  342. pDoc->CurrentCommand = DRAW_DOT;
  343. }
  344. void CMiniCADView::OnDrawCurve() 
  345. {
  346. CMiniCADDoc* pDoc = GetDocument();
  347. ASSERT_VALID(pDoc);
  348. if(!BeforeCommand(pDoc))
  349. {
  350. pDoc->CurrentCommand = NO_COMMAND;
  351. return;
  352. }
  353. if(pDoc->m_ManageGraphObject.UnselectObject())
  354. Invalidate();
  355. pDoc->CurrentCommand = DRAW_CURVE;
  356. }
  357. void CMiniCADView::OnDrawDefineline() 
  358. {
  359. CMiniCADDoc* pDoc = GetDocument();
  360. ASSERT_VALID(pDoc);
  361. if(!BeforeCommand(pDoc))
  362. {
  363. pDoc->CurrentCommand = NO_COMMAND;
  364. return;
  365. }
  366. if(pDoc->m_ManageGraphObject.UnselectObject())
  367. Invalidate();
  368. pDoc->CurrentCommand = DRAW_DEFINELINE;
  369. }
  370. void CMiniCADView::OnDrawText() 
  371. {
  372. CMiniCADDoc* pDoc = GetDocument();
  373. ASSERT_VALID(pDoc);
  374. if(!BeforeCommand(pDoc))
  375. {
  376. pDoc->CurrentCommand = NO_COMMAND;
  377. return;
  378. }
  379. if(pDoc->m_ManageGraphObject.UnselectObject())
  380. Invalidate();
  381. pDoc->CurrentCommand = DRAW_TEXT;
  382. }
  383. ///////////////////////////////////////////////////////////////////////////////////////////////
  384. void CMiniCADView::OnUpdateDrawLine(CCmdUI* pCmdUI) 
  385. {
  386. CMiniCADDoc* pDoc = GetDocument();
  387. ASSERT_VALID(pDoc);
  388. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_LINE);
  389. //继续传递当前命令
  390. pCmdUI->ContinueRouting();
  391. }
  392. void CMiniCADView::OnUpdateDrawRect(CCmdUI* pCmdUI) 
  393. {
  394. CMiniCADDoc* pDoc = GetDocument();
  395. ASSERT_VALID(pDoc);
  396. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_RECT);
  397. pCmdUI->ContinueRouting();
  398. }
  399. void CMiniCADView::OnUpdateDrawCircle(CCmdUI* pCmdUI) 
  400. {
  401. CMiniCADDoc* pDoc = GetDocument();
  402. ASSERT_VALID(pDoc);
  403. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_CIRCLE);
  404. pCmdUI->ContinueRouting();
  405. }
  406. void CMiniCADView::OnUpdateDrawArc(CCmdUI* pCmdUI) 
  407. {
  408. CMiniCADDoc* pDoc = GetDocument();
  409. ASSERT_VALID(pDoc);
  410. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_ARC);
  411. pCmdUI->ContinueRouting();
  412. }
  413. void CMiniCADView::OnUpdateDrawText(CCmdUI* pCmdUI) 
  414. {
  415. CMiniCADDoc* pDoc = GetDocument();
  416. ASSERT_VALID(pDoc);
  417. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_TEXT);
  418. pCmdUI->ContinueRouting();
  419. }
  420. ///////////////////////////////////////////////////////////////////////////////////////////////
  421. //键盘消息处理函数
  422. void CMiniCADView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  423. {
  424. CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
  425. }
  426. //鼠标消息处理函数
  427. void CMiniCADView::OnLButtonDown(UINT nFlags, CPoint point) 
  428. {
  429.     CMiniCADDoc* pDoc = GetDocument();
  430. ASSERT_VALID(pDoc);
  431. CClientDC dc(this);
  432. OnPrepareDC(&dc);
  433. dc.DPtoLP(&point);
  434. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  435. {
  436. pDoc->m_ManageGraphObject.GetDC(&dc);
  437. pDoc->m_ManageGraphObject.OnLButtonDown(pDoc->CurrentCommand, point);
  438. }
  439. if(pDoc->CurrentCommand > MODIFY_MIN && pDoc->CurrentCommand < MODIFY_MAX)
  440. {
  441. pDoc->m_ManageGraphObject.GetDC(&dc);
  442. pDoc->m_ManageGraphObject.OnLButtonDown(pDoc->CurrentCommand, point);
  443. }
  444. CScrollView::OnLButtonDown(nFlags, point);
  445. }
  446. void CMiniCADView::OnRButtonDown(UINT nFlags, CPoint point) 
  447. {
  448. CMiniCADDoc* pDoc = GetDocument();
  449. ASSERT_VALID(pDoc);
  450. CClientDC dc(this);
  451. OnPrepareDC(&dc);
  452. dc.DPtoLP(&point);
  453. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  454. {
  455. pDoc->m_ManageGraphObject.GetDC(&dc);
  456. pDoc->CurrentCommand = pDoc->m_ManageGraphObject.OnRButtonDown(pDoc->CurrentCommand, point);
  457. }
  458. if(pDoc->CurrentCommand > MODIFY_MIN && pDoc->CurrentCommand < MODIFY_MAX)
  459. {
  460. pDoc->m_ManageGraphObject.GetDC(&dc);
  461. pDoc->CurrentCommand = pDoc->m_ManageGraphObject.OnRButtonDown(pDoc->CurrentCommand, point);
  462. }
  463. CScrollView::OnRButtonDown(nFlags, point);
  464. }
  465. void CMiniCADView::OnMouseMove(UINT nFlags, CPoint point) 
  466. {
  467. CMiniCADDoc* pDoc = GetDocument();
  468. ASSERT_VALID(pDoc);
  469. char x_coordinate[32];
  470. char y_coordinate[32];
  471. int count;
  472. CPoint pt;
  473. pt = point;
  474. CClientDC dc(this);
  475.     OnPrepareDC(&dc);
  476. dc.DPtoLP(&pt);
  477. /*
  478.     //将绘图区域限制在图纸范围内
  479. CRect rect;
  480. rect = GetDrawingLogicRect();
  481. if(pt.x < rect.left)
  482. pt.x = rect.left;
  483. if(pt.x > rect.right)
  484. pt.x = rect.right;
  485. if(pt.y < rect.top)
  486. pt.y = rect.top;
  487. if(pt.y > rect.bottom)
  488. pt.y = rect.bottom;
  489. */
  490. /*在状态栏中显示坐标*/
  491. count = sprintf(x_coordinate, "%s", "X = ");
  492. sprintf(x_coordinate + count, "%f", (float)(pt.x - EXTRA_WIDTH) / Proportion);
  493. pMainWnd->m_wndStatusBar.SetPaneText(1, x_coordinate, TRUE);
  494. count = sprintf(y_coordinate, "%s", "Y = ");
  495. sprintf(y_coordinate + count, "%f", (float)(LogicViewSize.cy - pt.y - EXTRA_HIGTH) / Proportion);
  496. pMainWnd->m_wndStatusBar.SetPaneText(2, y_coordinate, TRUE);
  497. /*在状态栏中显示坐标*/
  498. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  499. {
  500. pDoc->m_ManageGraphObject.GetDC(&dc);
  501. pDoc->m_ManageGraphObject.OnMouseMove(pDoc->CurrentCommand, pt);
  502. }
  503.     if(pDoc->CurrentCommand > MODIFY_MIN && pDoc->CurrentCommand < MODIFY_MAX)
  504. {
  505. pDoc->m_ManageGraphObject.GetDC(&dc);
  506. pDoc->m_ManageGraphObject.OnMouseMove(pDoc->CurrentCommand, pt);
  507. }
  508. CScrollView::OnMouseMove(nFlags, point);
  509. }
  510. void CMiniCADView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  511. {
  512. CMiniCADDoc* pDoc = GetDocument();
  513. ASSERT_VALID(pDoc);
  514. CClientDC dc(this);
  515. OnPrepareDC(&dc);
  516. /*计算垂直滚屏产生的影响区域*/
  517. CRect rect;
  518. CPoint Position;
  519. GetClientRect(&rect);
  520. dc.DPtoLP(&rect);
  521. Position = GetScrollPosition( );
  522.     if(Position.y <= (long)nPos)
  523. {
  524. EffectRect.top = rect.bottom ;
  525.         EffectRect.bottom = rect.bottom + ((long)nPos - Position.y);
  526. EffectRect.left = rect.left;
  527.         EffectRect.right = rect.right;
  528. }
  529. else
  530. {
  531. EffectRect.top = rect.top - (Position.y - (long)nPos);
  532.         EffectRect.bottom = rect.top;
  533. EffectRect.left = rect.left;
  534.         EffectRect.right = rect.right;
  535. }
  536. /*计算垂直滚屏产生的影响区域*/
  537. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  538. {
  539. pDoc->m_ManageGraphObject.GetDC(&dc);
  540. pDoc->m_ManageGraphObject.SetEffectRect(EffectRect);
  541. pDoc->m_ManageGraphObject.OnScroll(pDoc->CurrentCommand);
  542. }
  543.     
  544. CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
  545. }
  546. void CMiniCADView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  547. {
  548. CMiniCADDoc* pDoc = GetDocument();
  549. ASSERT_VALID(pDoc);
  550. CClientDC dc(this);
  551. OnPrepareDC(&dc);
  552. /*计算水平滚屏产生的影响区域*/
  553. CRect rect;
  554. GetClientRect(&rect);
  555.     dc.DPtoLP(&rect);
  556. CPoint Position = GetScrollPosition( );
  557.     if(Position.x <= (long)nPos)
  558. {
  559. EffectRect.top = rect.top ;
  560.         EffectRect.bottom = rect.bottom;
  561. EffectRect.left = rect.right;
  562.         EffectRect.right = rect.right + ((long)nPos - Position.x);
  563. }
  564. else
  565. {
  566. EffectRect.top = rect.top;
  567.         EffectRect.bottom = rect.bottom;
  568. EffectRect.left = rect.left - (Position.x - (long)nPos);
  569.         EffectRect.right = rect.left;
  570. }
  571. /*计算水平滚屏产生的影响区域*/
  572. if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
  573. {
  574. pDoc->m_ManageGraphObject.GetDC(&dc);
  575. pDoc->m_ManageGraphObject.OnScroll(pDoc->CurrentCommand);
  576. }
  577. CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
  578. }
  579. void CMiniCADView::OnDestroy() 
  580. {
  581. CScrollView::OnDestroy();
  582. CMiniCADDoc* pDoc = GetDocument();
  583. ASSERT_VALID(pDoc);
  584. pDoc->CurrentCommand = DRAW_SELECT;
  585. }
  586. //屏幕放大
  587. void CMiniCADView::OnZoomout() 
  588. {
  589. CMiniCADDoc* pDoc = GetDocument();
  590. ASSERT_VALID(pDoc);
  591. if(Proportion < 4)
  592. {
  593. Proportion += 0.25;
  594.         pDoc->m_ManageGraphObject.Proportion = Proportion;
  595. //设置滚动条滚动区域
  596. LogicViewSize = GetLogicViewSize(); 
  597. SetScrollSizes(MM_TEXT, LogicViewSize);
  598. pDoc->m_ManageGraphObject.SetLogicSize(LogicViewSize);
  599. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
  600.     psizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
  601.         
  602. CClientDC dc(this);
  603. OnPrepareDC(&dc);
  604. GetClientRect(EffectRect);
  605.         dc.DPtoLP(EffectRect); 
  606. pDoc->m_ManageGraphObject.GetObjectRange();
  607. Invalidate();
  608. }
  609. }
  610. //屏幕缩小
  611. void CMiniCADView::OnZoomin() 
  612. {
  613. CMiniCADDoc* pDoc = GetDocument();
  614. ASSERT_VALID(pDoc);
  615.     if(Proportion > 0.25)
  616. {
  617. Proportion -= 0.25;
  618.         pDoc->m_ManageGraphObject.Proportion = Proportion;
  619. //设置滚动条滚动区域
  620. LogicViewSize =GetLogicViewSize();
  621. SetScrollSizes(MM_TEXT, LogicViewSize);
  622. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
  623.     psizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
  624. pDoc->m_ManageGraphObject.SetLogicSize(LogicViewSize);
  625. CClientDC dc(this);
  626. OnPrepareDC(&dc);
  627. GetClientRect(EffectRect);
  628.         dc.DPtoLP(EffectRect); 
  629. pDoc->m_ManageGraphObject.GetObjectRange();
  630. Invalidate();
  631. }
  632. }
  633. //选择图纸尺寸
  634. void CMiniCADView::OnSelchangeProportion() 
  635. {
  636. CMiniCADDoc* pDoc = GetDocument();
  637. ASSERT_VALID(pDoc);
  638. int index;
  639. CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
  640. index = psizeCombo->GetCurSel();
  641.     Proportion = (index + 1) * (float)0.25;
  642. pDoc->m_ManageGraphObject.Proportion = Proportion;
  643. //设置滚动条滚动区域
  644. LogicViewSize = GetLogicViewSize();
  645. SetScrollSizes(MM_TEXT, LogicViewSize);
  646. pDoc->m_ManageGraphObject.SetLogicSize(LogicViewSize);
  647. CClientDC dc(this);
  648. OnPrepareDC(&dc);
  649. GetClientRect(EffectRect);
  650.     dc.DPtoLP(EffectRect); 
  651. pDoc->m_ManageGraphObject.GetObjectRange();
  652. Invalidate();
  653. }
  654. void CMiniCADView::OnSelchangeColor() 
  655. {
  656. CMiniCADDoc* pDoc = GetDocument();
  657. ASSERT_VALID(pDoc);
  658. CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
  659. switch(ColorCombo->GetCurSel())
  660. {
  661. case 0:
  662. pDoc->FileInfo.m_PenColor = RGB(0, 0, 0);
  663. break;
  664. case 1:
  665. pDoc->FileInfo.m_PenColor = RGB(255, 0, 0);
  666. break;
  667. case 2:
  668. pDoc->FileInfo.m_PenColor = RGB(255, 255, 0);
  669. break;
  670. case 3:
  671. pDoc->FileInfo.m_PenColor = RGB(0, 255, 0);
  672. break;
  673. case 4:
  674. pDoc->FileInfo.m_PenColor = RGB(0, 255, 255);
  675. break;
  676. case 5:
  677. pDoc->FileInfo.m_PenColor = RGB(0, 0, 255);
  678. break;
  679. case 6:
  680. pDoc->FileInfo.m_PenColor = RGB( 255, 0, 255);
  681. break;
  682. }
  683.     pDoc->m_ManageGraphObject.SetPenColor(pDoc->FileInfo.m_PenColor);
  684. }
  685. void CMiniCADView::OnSelchangeLinestyle() 
  686. {
  687. CMiniCADDoc* pDoc = GetDocument();
  688. ASSERT_VALID(pDoc);
  689. CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
  690. switch(LineStyleCombo->GetCurSel())
  691. {
  692. case 0:
  693. pDoc->FileInfo.m_LineStyle = PS_SOLID;
  694. break;
  695. case 1:
  696. pDoc->FileInfo.m_LineStyle = PS_DASH;
  697. break;
  698. case 2:
  699. pDoc->FileInfo.m_LineStyle = PS_DOT;
  700. break;
  701. case 3:
  702. pDoc->FileInfo.m_LineStyle = PS_DASHDOT;
  703. break;
  704. case 4:
  705. pDoc->FileInfo.m_LineStyle = PS_DASHDOTDOT;
  706. break;
  707. }
  708.     pDoc->m_ManageGraphObject.SetLineStyle(pDoc->FileInfo.m_LineStyle);
  709. }
  710. void CMiniCADView::OnSize(UINT nType, int cx, int cy) 
  711. {
  712. CScrollView::OnSize(nType, cx, cy);
  713. /* //当改变视图尺寸时取消当前的绘图命令
  714. pDoc->CurrentCommand = DRAW_SELECT;
  715. pDoc->LRepeatTimes = 0;
  716. */
  717. }
  718. void CMiniCADView::OnViewRedraw() 
  719. {
  720. CClientDC dc(this);
  721. OnPrepareDC(&dc);
  722. //激活OnDraw()函数,重画当前视图
  723. // CRect rect(0, 0 , 0, 0);
  724. // InvalidateRect(rect);
  725. Invalidate();
  726. }
  727. void CMiniCADView::OnEditUndo() 
  728. {
  729. CMiniCADDoc* pDoc = GetDocument();
  730. ASSERT_VALID(pDoc);
  731.     pDoc->m_ManageGraphObject.OnUndo();
  732. Invalidate();
  733. }
  734. void CMiniCADView::OnUpdateEditUndo(CCmdUI* pCmdUI) 
  735. {
  736. CMiniCADDoc* pDoc = GetDocument();
  737. if(pDoc->m_CommandStack.CanUndo())
  738. pCmdUI->Enable(TRUE);
  739. else
  740. pCmdUI->Enable(FALSE);
  741. }
  742. void CMiniCADView::OnEditRedo() 
  743. {
  744. CMiniCADDoc* pDoc = GetDocument();
  745. ASSERT_VALID(pDoc);
  746.     pDoc->m_ManageGraphObject.OnRedo();
  747. Invalidate();
  748. }
  749. void CMiniCADView::OnUpdateEditRedo(CCmdUI* pCmdUI) 
  750. {
  751. CMiniCADDoc* pDoc = GetDocument();
  752. ASSERT_VALID(pDoc);
  753. if(pDoc->m_CommandStack.CanRedo())
  754.     pCmdUI->Enable(TRUE);
  755. else
  756. pCmdUI->Enable(FALSE);
  757. }
  758. void CMiniCADView::OnUpdateDrawSelect(CCmdUI* pCmdUI) 
  759. {
  760. CMiniCADDoc* pDoc = GetDocument();
  761. ASSERT_VALID(pDoc);
  762. pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_SELECT);
  763. pCmdUI->ContinueRouting();
  764. }
  765. void CMiniCADView::OnModifyDelete() 
  766. {
  767. CMiniCADDoc* pDoc = GetDocument();
  768. ASSERT_VALID(pDoc);
  769. pDoc->m_ManageGraphObject.OnModifyDelete();
  770. }
  771. void CMiniCADView::OnUpdateModifyDelete(CCmdUI* pCmdUI) 
  772. {
  773. }
  774. void CMiniCADView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
  775. {
  776. CScrollView::OnPrepareDC(pDC, pInfo);
  777. }
  778. void CMiniCADView::OnModifyCopy() 
  779. {
  780. }
  781. void CMiniCADView::OnModifyCut() 
  782. {
  783. }
  784. void CMiniCADView::OnModifyCuttoangle() 
  785. {
  786. }
  787. void CMiniCADView::OnModifyLengthento() 
  788. {
  789. }
  790. void CMiniCADView::OnModifyJoin() 
  791. {
  792. }
  793. void CMiniCADView::OnModifyMirror() 
  794. {
  795. }
  796. void CMiniCADView::OnModifyVertical() 
  797. {
  798. }
  799. void CMiniCADView::OnModifyMove() 
  800. {
  801. }
  802. void CMiniCADView::OnModifyRotate() 
  803. {
  804.  
  805. }
  806. void CMiniCADView::OnModifyExcursion() 
  807. {
  808. }
  809. void CMiniCADView::OnEditCopy() 
  810. {
  811. }
  812. void CMiniCADView::OnEditCut() 
  813. {
  814. }
  815. void CMiniCADView::OnEditPaste() 
  816. {
  817. }
  818. void CMiniCADView::OnFormatDrawingAttribute() 
  819. {
  820. CDrawingAttributeDlg  dlg;
  821. dlg.DoModal();
  822. }
  823. void CMiniCADView::OnToolSelect() 
  824. {
  825. CSelectParameterDlg dlg;
  826. dlg.DoModal();
  827. }
  828. /////////////////////////////////////////////////////////////////////////////////////////////
  829. //Function
  830. void CMiniCADView::SetEffectRect(CRect rect)
  831. {
  832. EffectRect = rect;
  833. }
  834. void CMiniCADView::SetDrawingSize(CSize size)
  835. {
  836. DrawingSize = size;
  837. }
  838. CSize CMiniCADView::GetLogicViewSize()
  839. {
  840. CSize size;
  841. size.cx = (long)(DrawingSize.cx * Proportion) + EXTRA_WIDTH * 2; 
  842. size.cy = (long)(DrawingSize.cy * Proportion) + EXTRA_HIGTH * 2;
  843. return size;
  844. }
  845. CRect CMiniCADView::GetDrawingLogicRect()
  846. {
  847. CRect rect;
  848. rect.left = EXTRA_WIDTH;
  849. rect.top = EXTRA_HIGTH;
  850. rect.right = rect.left + (long)(DrawingSize.cx * Proportion);
  851. rect.bottom = rect.top + (long)(DrawingSize.cy * Proportion);
  852. return rect;
  853. }