MiniCADView.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:24k
- // MiniCADView.cpp : implementation of the CMiniCADView class
- //
- #include "stdafx.h"
- #include "MiniCADView.h"
- #include "DrawingAttribute.h"
- #include "SelectParameterDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADView
- IMPLEMENT_DYNCREATE(CMiniCADView, CScrollView)
- BEGIN_MESSAGE_MAP(CMiniCADView, CScrollView)
- //{{AFX_MSG_MAP(CMiniCADView)
- ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
- ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_WM_MOUSEMOVE()
- ON_WM_VSCROLL()
- ON_WM_DESTROY()
- ON_WM_HSCROLL()
- ON_COMMAND(ID_VIEW_ZOOMOUT, OnZoomout)
- ON_COMMAND(ID_VIEW_ZOOMIN, OnZoomin)
- ON_CBN_SELCHANGE(IDC_COLOR, OnSelchangeColor)
- ON_CBN_SELCHANGE(IDC_LINESTYLE, OnSelchangeLinestyle)
- ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
- ON_WM_SIZE()
- ON_COMMAND(ID_VIEW_REDRAW, OnViewRedraw)
- ON_COMMAND(ID_DRAW_SELECT, OnDrawSelect)
- ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
- ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
- ON_COMMAND(ID_DRAW_ARC, OnDrawArc)
- ON_COMMAND(ID_DRAW_TEXT, OnDrawText)
- ON_UPDATE_COMMAND_UI(ID_DRAW_SELECT, OnUpdateDrawSelect)
- ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
- ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
- ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ARC, OnUpdateDrawArc)
- ON_UPDATE_COMMAND_UI(ID_DRAW_TEXT, OnUpdateDrawText)
- ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
- ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
- ON_UPDATE_COMMAND_UI(ID_MODIFY_DELETE, OnUpdateModifyDelete)
- ON_WM_ERASEBKGND()
- ON_CBN_SELCHANGE(IDC_PROPORTION, OnSelchangeProportion)
- ON_COMMAND(ID_DRAW_MULTILINE, OnDrawMultiline)
- ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
- ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
- ON_COMMAND(ID_MODIFY_DELETE, OnModifyDelete)
- ON_COMMAND(ID_MODIFY_COPY, OnModifyCopy)
- ON_COMMAND(ID_MODIFY_CUT, OnModifyCut)
- ON_COMMAND(ID_MODIFY_CUTTOANGLE, OnModifyCuttoangle)
- ON_COMMAND(ID_MODIFY_LENGTHENTO, OnModifyLengthento)
- ON_COMMAND(ID_MODIFY_JOIN, OnModifyJoin)
- ON_COMMAND(ID_MODIFY_MIRROR, OnModifyMirror)
- ON_COMMAND(ID_MODIFY_VERTICAL, OnModifyVertical)
- ON_COMMAND(ID_DRAW_DOT, OnDrawDot)
- ON_COMMAND(ID_DRAW_CURVE, OnDrawCurve)
- ON_COMMAND(ID_MODIFY_MOVE, OnModifyMove)
- ON_COMMAND(ID_MODIFY_ROTATE, OnModifyRotate)
- ON_COMMAND(ID_DRAW_DEFINELINE, OnDrawDefineline)
- ON_COMMAND(ID_MODIFY_EXCURSION, OnModifyExcursion)
- ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
- ON_COMMAND(ID_EDIT_CUT, OnEditCut)
- ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
- ON_COMMAND(ID_FORMAT_DRAWINGATTRIBUTE, OnFormatDrawingAttribute)
- ON_COMMAND(ID_TOOL_SELECT, OnToolSelect)
- ON_WM_KEYDOWN()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADView construction/destruction
- CMiniCADView::CMiniCADView()
- {
- pApp = (CMiniCADApp*)AfxGetApp();
- pMainWnd = (CMainFrame*)pApp->m_pMainWnd;
- EffectRect.top = 0;
- EffectRect.left = 0;
- EffectRect.bottom = 0;
- EffectRect.right = 0;
- }
- CMiniCADView::~CMiniCADView()
- {
- }
- BOOL CMiniCADView::PreCreateWindow(CREATESTRUCT& cs)
- {
- cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 0 ,(HBRUSH)::GetStockObject(WHITE_BRUSH), 0);
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADView printing
- BOOL CMiniCADView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CMiniCADView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
-
- }
- void CMiniCADView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADView diagnostics
- #ifdef _DEBUG
- void CMiniCADView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CMiniCADView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CMiniCADDoc* CMiniCADView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMiniCADDoc)));
- return (CMiniCADDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMiniCADView message handlers
- void CMiniCADView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pDoc->m_ManageGraphObject.GetView(this);
- CClientDC dc(this);
-
- //在MDI子框架上显示标题,标题为图纸名
- CChildFrame* pChildWnd = (CChildFrame*)pMainWnd->MDIGetActive();
- pChildWnd->SetWindowText(pDoc->FileInfo.m_Name);
-
- //初始化颜色复选框
- CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
- ColorCombo->EnableWindow(TRUE);
- ColorCombo->SetCurSel(0);
- //初始化线形复选框
- CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
- LineStyleCombo->EnableWindow(TRUE);
- LineStyleCombo->SetCurSel(0);
- //初始化图纸尺寸复选框
- CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
- psizeCombo->EnableWindow(TRUE);
- psizeCombo->SetCurSel(3);
- Proportion = 1.0;
- //设置图纸尺寸
- SetDrawingSize(pDoc->FileInfo.m_Size);
- //获取逻辑区尺寸
- LogicViewSize = GetLogicViewSize();
- //设置滚动区域
- SetScrollSizes(MM_TEXT, LogicViewSize);
- pDoc->m_ManageGraphObject.SetLogicViewSize(LogicViewSize);
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //改变视图背景颜色
- void CMiniCADView::OnEraseBkgnd (CDC* pDC)
- {
- CBrush Brush (RGB(180, 255, 255));
- CBrush* pOldBrush = pDC->SelectObject (&Brush);
- CRect rcClip ;
- pDC->GetClipBox (&rcClip);
- pDC-> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height ( ) , PATCOPY );
- pDC->SelectObject (pOldBrush );
- }
- // CMiniCADView drawing
- void CMiniCADView::OnDraw(CDC* pDC)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(pDoc->DocumentReady == FALSE)
- return;
- CBrush brush;
- CRect rect;
- CRect shadow;
- rect = GetDrawingLogicRect();
- rect.right = rect.right + 1;
- rect.bottom = rect.bottom + 1;
- /*绘制阴影*/
- brush.CreateSolidBrush(RGB(192, 192, 192));
- shadow.left = rect.left + 3;
- shadow.top = rect.bottom;
- shadow.right = rect.right + 3;
- shadow.bottom = shadow.top + 3;
- pDC->FillRect(&shadow, &brush);
- shadow.left = rect.right;
- shadow.top = rect.top + 3;
- shadow.right = shadow.left + 3;
- shadow.bottom = rect.bottom + 3;
- pDC->FillRect(&shadow, &brush);
- /*绘制阴影*/
- pDC->Rectangle(&rect);
- GetClientRect(EffectRect);
- pDC->DPtoLP(EffectRect);
- //重画所有的图形对象
- pDoc->m_ManageGraphObject.GetDC(pDC);
- pDoc->m_ManageGraphObject.SetEffectRect(EffectRect);
- pDoc->m_ManageGraphObject.RedrawAllObject(pDC);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- BOOL CMiniCADView::BeforeCommand(CMiniCADDoc* pDoc)
- {
- CString CurrentLayerName = pDoc->m_ManageFileLayer.GetCurrentLayerName();
- if(CurrentLayerName == "")
- {
- MessageBox("没有当前图层", "提示", MB_OK | MB_ICONWARNING);
- return FALSE;
- }
- CFileLayer* pLayer = pDoc->m_ManageFileLayer.GetLayer(CurrentLayerName);
- if(!pLayer->IsShow())
- {
- MessageBox("当前图层被隐藏", "提示", MB_OK | MB_ICONWARNING);
- return FALSE;
- }
- if(pLayer->IsLocked())
- {
- MessageBox("当前图层被锁定", "提示", MB_OK | MB_ICONWARNING);
- return FALSE;
- }
- pDoc->m_ManageGraphObject.SetCurrentLayerName(CurrentLayerName);
- return TRUE;
- }
- void CMiniCADView::OnDrawSelect()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
-
- pDoc->CurrentCommand = DRAW_SELECT;
- }
- void CMiniCADView::OnDrawLine()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_LINE;
- }
- void CMiniCADView::OnDrawRect()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_RECT;
- }
- void CMiniCADView::OnDrawCircle()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_CIRCLE;
- }
- void CMiniCADView::OnDrawArc()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_ARC;
- }
- void CMiniCADView::OnDrawMultiline()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_MULTILINE;
- }
- void CMiniCADView::OnDrawPolygon()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_POLYGON;
- }
- void CMiniCADView::OnDrawEllipse()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_ELLIPSE;
- }
-
- void CMiniCADView::OnDrawDot()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_DOT;
- }
- void CMiniCADView::OnDrawCurve()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_CURVE;
- }
- void CMiniCADView::OnDrawDefineline()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_DEFINELINE;
- }
- void CMiniCADView::OnDrawText()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(!BeforeCommand(pDoc))
- {
- pDoc->CurrentCommand = NO_COMMAND;
- return;
- }
- if(pDoc->m_ManageGraphObject.UnselectObject())
- Invalidate();
- pDoc->CurrentCommand = DRAW_TEXT;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- void CMiniCADView::OnUpdateDrawLine(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_LINE);
- //继续传递当前命令
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawRect(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_RECT);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_CIRCLE);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawArc(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_ARC);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawText(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_TEXT);
- pCmdUI->ContinueRouting();
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //键盘消息处理函数
- void CMiniCADView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
-
- CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- //鼠标消息处理函数
- void CMiniCADView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->m_ManageGraphObject.OnLButtonDown(pDoc->CurrentCommand, point);
- }
- if(pDoc->CurrentCommand > MODIFY_MIN && pDoc->CurrentCommand < MODIFY_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->m_ManageGraphObject.OnLButtonDown(pDoc->CurrentCommand, point);
- }
-
- CScrollView::OnLButtonDown(nFlags, point);
- }
- void CMiniCADView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->CurrentCommand = pDoc->m_ManageGraphObject.OnRButtonDown(pDoc->CurrentCommand, point);
- }
- if(pDoc->CurrentCommand > MODIFY_MIN && pDoc->CurrentCommand < MODIFY_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->CurrentCommand = pDoc->m_ManageGraphObject.OnRButtonDown(pDoc->CurrentCommand, point);
- }
- CScrollView::OnRButtonDown(nFlags, point);
- }
- void CMiniCADView::OnMouseMove(UINT nFlags, CPoint point)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- char x_coordinate[32];
- char y_coordinate[32];
- int count;
-
- CPoint pt;
- pt = point;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&pt);
- /*
- //将绘图区域限制在图纸范围内
- CRect rect;
- rect = GetDrawingLogicRect();
-
- if(pt.x < rect.left)
- pt.x = rect.left;
- if(pt.x > rect.right)
- pt.x = rect.right;
- if(pt.y < rect.top)
- pt.y = rect.top;
- if(pt.y > rect.bottom)
- pt.y = rect.bottom;
- */
- /*在状态栏中显示坐标*/
- count = sprintf(x_coordinate, "%s", "X = ");
- sprintf(x_coordinate + count, "%f", (float)(pt.x - EXTRA_WIDTH) / Proportion);
- pMainWnd->m_wndStatusBar.SetPaneText(1, x_coordinate, TRUE);
- count = sprintf(y_coordinate, "%s", "Y = ");
- sprintf(y_coordinate + count, "%f", (float)(LogicViewSize.cy - pt.y - EXTRA_HIGTH) / Proportion);
- pMainWnd->m_wndStatusBar.SetPaneText(2, y_coordinate, TRUE);
- /*在状态栏中显示坐标*/
- if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->m_ManageGraphObject.OnMouseMove(pDoc->CurrentCommand, pt);
- }
- if(pDoc->CurrentCommand > MODIFY_MIN && pDoc->CurrentCommand < MODIFY_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->m_ManageGraphObject.OnMouseMove(pDoc->CurrentCommand, pt);
- }
- CScrollView::OnMouseMove(nFlags, point);
- }
- void CMiniCADView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- CClientDC dc(this);
- OnPrepareDC(&dc);
-
- /*计算垂直滚屏产生的影响区域*/
- CRect rect;
- CPoint Position;
- GetClientRect(&rect);
- dc.DPtoLP(&rect);
- Position = GetScrollPosition( );
- if(Position.y <= (long)nPos)
- {
- EffectRect.top = rect.bottom ;
- EffectRect.bottom = rect.bottom + ((long)nPos - Position.y);
- EffectRect.left = rect.left;
- EffectRect.right = rect.right;
- }
- else
- {
- EffectRect.top = rect.top - (Position.y - (long)nPos);
- EffectRect.bottom = rect.top;
- EffectRect.left = rect.left;
- EffectRect.right = rect.right;
- }
- /*计算垂直滚屏产生的影响区域*/
-
- if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->m_ManageGraphObject.SetEffectRect(EffectRect);
- pDoc->m_ManageGraphObject.OnScroll(pDoc->CurrentCommand);
- }
-
- CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- void CMiniCADView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CClientDC dc(this);
- OnPrepareDC(&dc);
- /*计算水平滚屏产生的影响区域*/
- CRect rect;
- GetClientRect(&rect);
- dc.DPtoLP(&rect);
- CPoint Position = GetScrollPosition( );
- if(Position.x <= (long)nPos)
- {
- EffectRect.top = rect.top ;
- EffectRect.bottom = rect.bottom;
- EffectRect.left = rect.right;
- EffectRect.right = rect.right + ((long)nPos - Position.x);
- }
- else
- {
- EffectRect.top = rect.top;
- EffectRect.bottom = rect.bottom;
- EffectRect.left = rect.left - (Position.x - (long)nPos);
- EffectRect.right = rect.left;
- }
- /*计算水平滚屏产生的影响区域*/
- if(pDoc->CurrentCommand > DRAW_MIN && pDoc->CurrentCommand < DRAW_MAX)
- {
- pDoc->m_ManageGraphObject.GetDC(&dc);
- pDoc->m_ManageGraphObject.OnScroll(pDoc->CurrentCommand);
- }
-
- CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CMiniCADView::OnDestroy()
- {
- CScrollView::OnDestroy();
-
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pDoc->CurrentCommand = DRAW_SELECT;
- }
- //屏幕放大
- void CMiniCADView::OnZoomout()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(Proportion < 4)
- {
- Proportion += 0.25;
- pDoc->m_ManageGraphObject.Proportion = Proportion;
- //设置滚动条滚动区域
- LogicViewSize = GetLogicViewSize();
- SetScrollSizes(MM_TEXT, LogicViewSize);
- pDoc->m_ManageGraphObject.SetLogicViewSize(LogicViewSize);
- CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
- psizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
-
- CClientDC dc(this);
- OnPrepareDC(&dc);
- GetClientRect(EffectRect);
- dc.DPtoLP(EffectRect);
-
- pDoc->m_ManageGraphObject.GetObjectRange();
- Invalidate();
- }
-
- }
- //屏幕缩小
- void CMiniCADView::OnZoomin()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(Proportion > 0.25)
- {
- Proportion -= 0.25;
- pDoc->m_ManageGraphObject.Proportion = Proportion;
- //设置滚动条滚动区域
- LogicViewSize =GetLogicViewSize();
- SetScrollSizes(MM_TEXT, LogicViewSize);
- CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
- psizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
-
- pDoc->m_ManageGraphObject.SetLogicViewSize(LogicViewSize);
- CClientDC dc(this);
- OnPrepareDC(&dc);
- GetClientRect(EffectRect);
- dc.DPtoLP(EffectRect);
-
- pDoc->m_ManageGraphObject.GetObjectRange();
- Invalidate();
- }
- }
- //选择图纸尺寸
- void CMiniCADView::OnSelchangeProportion()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- int index;
- CComboBox* psizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_PROPORTION);
- index = psizeCombo->GetCurSel();
- Proportion = (index + 1) * (float)0.25;
- pDoc->m_ManageGraphObject.Proportion = Proportion;
-
- //设置滚动条滚动区域
- LogicViewSize = GetLogicViewSize();
- SetScrollSizes(MM_TEXT, LogicViewSize);
- pDoc->m_ManageGraphObject.SetLogicViewSize(LogicViewSize);
- CClientDC dc(this);
- OnPrepareDC(&dc);
- GetClientRect(EffectRect);
- dc.DPtoLP(EffectRect);
- pDoc->m_ManageGraphObject.GetObjectRange();
- Invalidate();
- }
- void CMiniCADView::OnSelchangeColor()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
- switch(ColorCombo->GetCurSel())
- {
- case 0:
- pDoc->FileInfo.m_PenColor = RGB(0, 0, 0);
- break;
- case 1:
- pDoc->FileInfo.m_PenColor = RGB(255, 0, 0);
- break;
- case 2:
- pDoc->FileInfo.m_PenColor = RGB(255, 255, 0);
- break;
- case 3:
- pDoc->FileInfo.m_PenColor = RGB(0, 255, 0);
- break;
- case 4:
- pDoc->FileInfo.m_PenColor = RGB(0, 255, 255);
- break;
- case 5:
- pDoc->FileInfo.m_PenColor = RGB(0, 0, 255);
- break;
- case 6:
- pDoc->FileInfo.m_PenColor = RGB( 255, 0, 255);
- break;
- }
- pDoc->m_ManageGraphObject.SetPenColor(pDoc->FileInfo.m_PenColor);
- }
- void CMiniCADView::OnSelchangeLinestyle()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
- switch(LineStyleCombo->GetCurSel())
- {
- case 0:
- pDoc->FileInfo.m_LineStyle = PS_SOLID;
- break;
- case 1:
- pDoc->FileInfo.m_LineStyle = PS_DASH;
- break;
- case 2:
- pDoc->FileInfo.m_LineStyle = PS_DOT;
- break;
- case 3:
- pDoc->FileInfo.m_LineStyle = PS_DASHDOT;
- break;
- case 4:
- pDoc->FileInfo.m_LineStyle = PS_DASHDOTDOT;
- break;
- }
- pDoc->m_ManageGraphObject.SetLineStyle(pDoc->FileInfo.m_LineStyle);
- }
- void CMiniCADView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
-
- }
- void CMiniCADView::OnViewRedraw()
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- Invalidate();
- }
- void CMiniCADView::OnEditUndo()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pDoc->m_ManageGraphObject.OnUndo();
- Invalidate();
- }
- void CMiniCADView::OnUpdateEditUndo(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- if(pDoc->m_CommandStack.CanUndo())
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMiniCADView::OnEditRedo()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pDoc->m_ManageGraphObject.OnRedo();
- Invalidate();
- }
- void CMiniCADView::OnUpdateEditRedo(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if(pDoc->m_CommandStack.CanRedo())
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMiniCADView::OnUpdateDrawSelect(CCmdUI* pCmdUI)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pCmdUI->SetRadio(pDoc->CurrentCommand == DRAW_SELECT);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnModifyDelete()
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pDoc->CurrentCommand = pDoc->m_ManageGraphObject.OnModifyDelete();
- }
- void CMiniCADView::OnUpdateModifyDelete(CCmdUI* pCmdUI)
- {
- }
- void CMiniCADView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
-
- CScrollView::OnPrepareDC(pDC, pInfo);
- }
- void CMiniCADView::OnModifyCopy()
- {
-
- }
- void CMiniCADView::OnModifyCut()
- {
- }
- void CMiniCADView::OnModifyCuttoangle()
- {
-
-
- }
- void CMiniCADView::OnModifyLengthento()
- {
-
- }
- void CMiniCADView::OnModifyJoin()
- {
- }
- void CMiniCADView::OnModifyMirror()
- {
-
- }
- void CMiniCADView::OnModifyVertical()
- {
-
- }
- void CMiniCADView::OnModifyMove()
- {
- }
- void CMiniCADView::OnModifyRotate()
- {
-
- }
- void CMiniCADView::OnModifyExcursion()
- {
- }
- void CMiniCADView::OnEditCopy()
- {
- }
- void CMiniCADView::OnEditCut()
- {
- }
- void CMiniCADView::OnEditPaste()
- {
- }
- void CMiniCADView::OnFormatDrawingAttribute()
- {
- CDrawingAttributeDlg dlg;
- dlg.DoModal();
- }
- void CMiniCADView::OnToolSelect()
- {
- CSelectParameterDlg dlg;
- dlg.DoModal();
- }
- /////////////////////////////////////////////////////////////////////////////////////////////
- //Function
- void CMiniCADView::SetEffectRect(CRect rect)
- {
-
- EffectRect = rect;
- }
- void CMiniCADView::SetDrawingSize(CSize size)
- {
- DrawingSize = size;
- }
- CSize CMiniCADView::GetLogicViewSize()
- {
- CSize size;
- size.cx = (long)(DrawingSize.cx * Proportion) + EXTRA_WIDTH * 2;
- size.cy = (long)(DrawingSize.cy * Proportion) + EXTRA_HIGTH * 2;
- return size;
- }
- CRect CMiniCADView::GetDrawingLogicRect()
- {
- CRect rect;
- rect.left = EXTRA_WIDTH;
- rect.top = EXTRA_HIGTH;
- rect.right = rect.left + (long)(DrawingSize.cx * Proportion);
- rect.bottom = rect.top + (long)(DrawingSize.cy * Proportion);
- return rect;
- }