MiniCADView.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:32k
- // MiniCADView.cpp : implementation of the CMiniCADView class
- //
- #include "stdafx.h"
- #include "MiniCADView.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_CHANGE_DELETE, OnUpdateChangeDelete)
- ON_WM_ERASEBKGND()
- ON_CBN_SELCHANGE(IDC_FILESIZE, OnSelchangeFilesize)
- 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_COMPONENT_DEFINE, OnComponentDefine)
- ON_COMMAND(ID_COMPONENT_INSERT, OnComponentInsert)
- ON_COMMAND(ID_ALIGN_BOTTOM, OnAlignBottom)
- ON_COMMAND(ID_ALIGN_CONCENTRIC, OnAlignConcentric)
- ON_COMMAND(ID_ALIGN_LEFT, OnAlignLeft)
- ON_COMMAND(ID_ALIGN_ONLINE, OnAlignOnline)
- ON_COMMAND(ID_ALIGN_RIGHT, OnAlignRight)
- ON_COMMAND(ID_ALIGN_TOP, OnAlignTop)
- ON_COMMAND(ID_DRAW_FILL, OnDrawFill)
- ON_COMMAND(ID_MODIFY_BREAK, OnModifyBreak)
- //}}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()
- {
- // TODO: add construction code here
- pApp = (CMiniCADApp*)AfxGetApp();
- pMainWnd = (CMainFrame*)pApp->m_pMainWnd;
- }
-
- CMiniCADView::~CMiniCADView()
- {
- }
- BOOL CMiniCADView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the 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*/)
- {
- // TODO: add extra initialization before printing
- }
- void CMiniCADView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // 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* Doc = GetDocument();
- CClientDC dc(this);
-
- //在MDI子框架上显示标题,标题为图纸名
- CChildFrame* pChildWnd = (CChildFrame*)pMainWnd->MDIGetActive();
- pChildWnd->SetWindowText(Doc->FileInfo.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_FILESIZE);
- pSizeCombo->EnableWindow(TRUE);
- pSizeCombo->SetCurSel(3);
- //初始化绘图工具条 、光标
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- Doc->MyOperate.LineStyle = pApp->CADInfo.LineStyle;
- Doc->MyOperate.ForeColor = pApp->CADInfo.ForeColor;
- Proportion = 1.0;
- //根据图纸尺寸设置滚动条滚动区域(既客户区)
- Size.cx = Doc->FileInfo.size.cx + EXTRA_WIDTH * 2;
- Size.cy = Doc->FileInfo.size.cy + EXTRA_HIGTH * 2;
- SetScrollSizes(MM_TEXT, Size);
- Doc->MyOperate.size.cx = Size.cx;
- Doc->MyOperate.size.cy = Size.cy;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- //改变视图背景颜色
- void CMiniCADView::OnEraseBkgnd (CDC* pDC)
- {
- // Create a cyan brush.
- CBrush Brush (RGB (200, 255, 255));
- CBrush* pOldBrush = pDC->SelectObject (&Brush);
- // Get the area that needs to be erased .
- CRect rcClip ;
- pDC->GetClipBox (&rcClip);
- //Paint the area.
- pDC-> PatBlt (rcClip.left , rcClip.top , rcClip.Width ( ) , rcClip.Height ( ) , PATCOPY );
- //Unselect brush out of device context .
- pDC->SelectObject (pOldBrush );
- }
- // CMiniCADView drawing
- void CMiniCADView::OnDraw(CDC* pDC)
- {
- CMiniCADDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- CBrush brush;
- RECT rect;
- RECT shadow;
- rect.left = EXTRA_WIDTH;
- rect.top = EXTRA_HIGTH;
- rect.right = rect.left + (long)(pDoc->FileInfo.size.cx * Proportion) + 1;
- rect.bottom = rect.top + (long)(pDoc->FileInfo.size.cy * Proportion) + 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);
- //重画所有的图形对象
- pDoc->MyOperate.RedrawAllObject(pDC);
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- void CMiniCADView::OnDrawSelect()
- {
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- void CMiniCADView::OnDrawLine()
- {
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyOperate.UnselectObject())
- Invalidate();
- pApp->CADInfo.CurrentCommand = DRAW_LINE;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- void CMiniCADView::OnDrawRect()
- {
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyOperate.UnselectObject())
- Invalidate();
- pApp->CADInfo.CurrentCommand = DRAW_RECT;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- void CMiniCADView::OnDrawCircle()
- {
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyOperate.UnselectObject())
- Invalidate();
- pApp->CADInfo.CurrentCommand = DRAW_CIRCLE;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- void CMiniCADView::OnDrawArc()
- {
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyOperate.UnselectObject())
- Invalidate();
- pApp->CADInfo.CurrentCommand = DRAW_ARC;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- void CMiniCADView::OnDrawMultiline()
- {
-
- }
- void CMiniCADView::OnDrawPolygon()
- {
-
- }
- void CMiniCADView::OnDrawEllipse()
- {
-
- }
- void CMiniCADView::OnDrawDot()
- {
-
- }
- void CMiniCADView::OnDrawCurve()
- {
-
- }
- void CMiniCADView::OnDrawDefineline()
- {
- }
- void CMiniCADView::OnDrawText()
- {
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyOperate.UnselectObject())
- Invalidate();
- pApp->CADInfo.CurrentCommand = DRAW_TEXT;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- void CMiniCADView::OnUpdateDrawLine(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(pApp->CADInfo.CurrentCommand == DRAW_LINE);
- //继续传递当前命令
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawRect(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(pApp->CADInfo.CurrentCommand == DRAW_RECT);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(pApp->CADInfo.CurrentCommand == DRAW_CIRCLE);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawArc(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(pApp->CADInfo.CurrentCommand == DRAW_ARC);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnUpdateDrawText(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(pApp->CADInfo.CurrentCommand == DRAW_TEXT);
- pCmdUI->ContinueRouting();
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //mouse message
- void CMiniCADView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- int ObjectType;
- int ObjetcIndex;
- CMiniCADDoc* Doc = GetDocument();
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- //获取视相对窗口的偏移量
- switch(pApp->CADInfo.CurrentCommand)
- {
- case DRAW_SELECT:
- Doc->MyOperate.SelectObject(&dc, point);
- break;
- case DRAW_LINE:
- {
- pApp->CADInfo.LRepeatTimes++;
- switch(pApp->CADInfo.LRepeatTimes)
- {
- case 1:
- //窗口坐标等于视坐标加视相对窗口的偏移量
- Doc->MyOperate.StartPoint = point;
- Doc->MyOperate.oldEndPoint = Doc->MyOperate.StartPoint;
- break;
- case 2:
- {
- //窗口坐标等于视坐标加视相对窗口的偏移量
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawLineC(&dc);
- Doc->MyOperate.AddLine();
- ObjectType = OBJ_LINE;
- ObjetcIndex = Doc->MyOperate.m_LineArray.GetUpperBound();
- //清除序号在CommandPointer + 1之后的命令
- //因为执行一项新操作后,将不再有可以Redo的命令
- Doc->MyCommand.DelCommandFrom(Doc->MyCommand.CommandPointer + 1);
- Doc->MyCommand.AddCommand(ID_DRAW_LINE, 1, &ObjectType, &ObjetcIndex);
- //命令指针移到命令数组末尾
- Doc->MyCommand.CommandPointer = Doc->MyCommand.m_CommandArray.GetUpperBound();
- pApp->CADInfo.LRepeatTimes--;
- Doc->MyOperate.StartPoint = Doc->MyOperate.EndPoint;
- Doc->MyOperate.oldEndPoint = Doc->MyOperate.StartPoint;
- }
- break;
- }
- }
- break;
- case DRAW_RECT:
- {
- pApp->CADInfo.LRepeatTimes++;
- switch(pApp->CADInfo.LRepeatTimes)
- {
- case 1:
- //窗口坐标等于视坐标加视相对窗口的偏移量
- Doc->MyOperate.StartPoint = point;
- Doc->MyOperate.oldEndPoint = Doc->MyOperate.StartPoint;
- break;
- case 2:
- //窗口坐标等于视坐标加视相对窗口的偏移量
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawRectC(&dc);
- Doc->MyOperate.AddRect();
- ObjectType = OBJ_RECT;
- ObjetcIndex = Doc->MyOperate.m_RectArray.GetUpperBound();
- Doc->MyCommand.DelCommandFrom(Doc->MyCommand.CommandPointer + 1);
- Doc->MyCommand.AddCommand(ID_DRAW_RECT, 1, &ObjectType, &ObjetcIndex);
- Doc->MyCommand.CommandPointer = Doc->MyCommand.m_CommandArray.GetUpperBound();
- pApp->CADInfo.LRepeatTimes = 0;
- }
- }
- break;
- case DRAW_CIRCLE:
- {
- pApp->CADInfo.LRepeatTimes++;
- switch(pApp->CADInfo.LRepeatTimes)
- {
- case 1:
- //窗口坐标等于视坐标加视相对窗口的偏移量
- Doc->MyOperate.StartPoint = point;
- Doc->MyOperate.oldEndPoint = Doc->MyOperate.StartPoint;
- Doc->MyOperate.Radius = 0;
- break;
- case 2:
- //窗口坐标等于视坐标加视相对窗口的偏移量
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawCircleC(&dc);
- Doc->MyOperate.AddCircle();
- ObjectType = OBJ_CIRCLE;
- ObjetcIndex = Doc->MyOperate.m_CircleArray.GetUpperBound();
- Doc->MyCommand.DelCommandFrom(Doc->MyCommand.CommandPointer + 1);
- Doc->MyCommand.AddCommand(ID_DRAW_CIRCLE, 1, &ObjectType, &ObjetcIndex);
- Doc->MyCommand.CommandPointer = Doc->MyCommand.m_CommandArray.GetUpperBound();
- pApp->CADInfo.LRepeatTimes = 0;
- }
- }
- break;
- case DRAW_ARC:
- {
- pApp->CADInfo.LRepeatTimes++;
- switch(pApp->CADInfo.LRepeatTimes)
- {
- case 1:
- Doc->MyOperate.StartPoint = point;
- Doc->MyOperate.oldMidPoint = Doc->MyOperate.StartPoint;
- Doc->MyOperate.Radius = 0;
- break;
- case 2:
- Doc->MyOperate.MidPoint = point;
- break;
- case 3:
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawArcC(&dc);
- Doc->MyOperate.AddArc();
- ObjectType = OBJ_ARC;
- ObjetcIndex = Doc->MyOperate.m_ArcArray.GetUpperBound();
- Doc->MyCommand.DelCommandFrom(Doc->MyCommand.CommandPointer + 1);
- Doc->MyCommand.AddCommand(ID_DRAW_ARC, 1, &ObjectType, &ObjetcIndex);
- Doc->MyCommand.CommandPointer = Doc->MyCommand.m_CommandArray.GetUpperBound();
- pApp->CADInfo.LRepeatTimes = 0;
- break;
- }
- }
- break;
- case DRAW_TEXT:
- break;
- }
- CScrollView::OnLButtonDown(nFlags, point);
- }
- void CMiniCADView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CMiniCADDoc* Doc = GetDocument();
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- switch(pApp->CADInfo.CurrentCommand)
- {
- case DRAW_SELECT:
- if(Doc->MyOperate.UnselectObject())
- Invalidate();
- break;
- case DRAW_LINE:
- if(pApp->CADInfo.LRepeatTimes == 1)
- {
- Doc->MyOperate.CancelDrawLine(&dc);
- pApp->CADInfo.LRepeatTimes = 0;
- }
- else
- {
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- pApp->CADInfo.LRepeatTimes = 0;
- }
- break;
- case DRAW_RECT:
- if(pApp->CADInfo.LRepeatTimes == 1)
- {
- Doc->MyOperate.CancelDrawRect(&dc);
- pApp->CADInfo.LRepeatTimes = 0;
- }
- else
- {
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- pApp->CADInfo.LRepeatTimes = 0;
- }
- break;
- case DRAW_CIRCLE:
- if(pApp->CADInfo.LRepeatTimes == 1)
- {
- Doc->MyOperate.CancelDrawCircle(&dc);
- pApp->CADInfo.LRepeatTimes = 0;
- }
- else
- {
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- pApp->CADInfo.LRepeatTimes = 0;
- }
- break;
- case DRAW_ARC:
- if(pApp->CADInfo.LRepeatTimes > 0)
- {
- Doc->MyOperate.CancelDrawArc(&dc, pApp->CADInfo.LRepeatTimes);
- pApp->CADInfo.LRepeatTimes = 0;
- }
- else
- {
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- pApp->CADInfo.LRepeatTimes = 0;
- }
- break;
- }
- CScrollView::OnRButtonDown(nFlags, point);
- }
- void CMiniCADView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- char x[32];
- char y[32];
- int count;
- CMiniCADDoc* Doc = GetDocument();
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- count = sprintf(x, "%s", "X = ");
- sprintf(x + count, "%f", (float)(point.x - EXTRA_WIDTH) / Proportion);
- pMainWnd->m_wndStatusBar.SetPaneText(1, x, TRUE);
- count = sprintf(y, "%s", "Y = ");
- sprintf(y + count, "%f", (float)(Size.cy - point.y - EXTRA_HIGTH) / Proportion);
- pMainWnd->m_wndStatusBar.SetPaneText(2, y, TRUE);
- switch(pApp->CADInfo.CurrentCommand)
- {
- case DRAW_SELECT:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- break;
- case DRAW_LINE:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- if(pApp->CADInfo.LRepeatTimes == 1)
- {
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawLineA(&dc);
- }
- break;
- case DRAW_RECT:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- if(pApp->CADInfo.LRepeatTimes == 1)
- {
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawRectA(&dc);
- }
- break;
- case DRAW_CIRCLE:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- if(pApp->CADInfo.LRepeatTimes == 1)
- {
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawCircleA(&dc);
- }
- break;
- case DRAW_ARC:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- switch(pApp->CADInfo.LRepeatTimes)
- {
- case 1:
- Doc->MyOperate.MidPoint = point;
- Doc->MyOperate.DrawArcA(&dc, 1);
- break;
- case 2:
- Doc->MyOperate.EndPoint = point;
- Doc->MyOperate.DrawArcA(&dc, 2);
- break;
- }
- break;
- }
-
- CScrollView::OnMouseMove(nFlags, point);
- }
- void CMiniCADView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
- CMiniCADDoc* Doc = GetDocument();
- CClientDC dc(this);
- OnPrepareDC(&dc);
- switch(pApp->CADInfo.CurrentCommand)
- {
- case DRAW_LINE:
- //必须重画直线,因为在滚屏过程中原来的直线有可能被破坏
- if(pApp->CADInfo.LRepeatTimes == 1)
- Doc->MyOperate.DrawLineB(&dc);
- break;
- case DRAW_RECT:
- if(pApp->CADInfo.LRepeatTimes == 1)
- Doc->MyOperate.DrawRectB(&dc);
- break;
- case DRAW_CIRCLE:
- if(pApp->CADInfo.LRepeatTimes == 1)
- Doc->MyOperate.DrawCircleB(&dc);
- break;
- case DRAW_ARC:
- Doc->MyOperate.DrawArcB(&dc, pApp->CADInfo.LRepeatTimes);
- break;
- }
- CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- void CMiniCADView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
- CMiniCADDoc* Doc = GetDocument();
- CClientDC dc(this);
- OnPrepareDC(&dc);
-
- switch(pApp->CADInfo.CurrentCommand)
- {
- case DRAW_LINE:
- //必须重画直线,因为在滚屏过程中原来的直线有可能被破坏
- if(pApp->CADInfo.LRepeatTimes == 1)
- Doc->MyOperate.DrawLineB(&dc);
- break;
- case DRAW_RECT:
- //必须重画矩形,因为在滚屏过程中原来的矩形有可能被破坏
- if(pApp->CADInfo.LRepeatTimes == 1)
- Doc->MyOperate.DrawRectB(&dc);
- break;
- case DRAW_CIRCLE:
- if(pApp->CADInfo.LRepeatTimes == 1)
- Doc->MyOperate.DrawCircleB(&dc);
- break;
- case DRAW_ARC:
- Doc->MyOperate.DrawArcB(&dc, pApp->CADInfo.LRepeatTimes);
- break;
- }
- CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CMiniCADView::OnDestroy()
- {
- CScrollView::OnDestroy();
-
- // TODO: Add your message handler code here
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- //屏幕放大
- void CMiniCADView::OnZoomout()
- {
- // TODO: Add your command handler code here
- CMiniCADDoc* pDoc = GetDocument();
- if(Proportion < 4)
- {
- Proportion += 0.25;
- pDoc->MyOperate.Proportion = Proportion;
- //根据图纸尺寸设置滚动条滚动区域(既客户区)
- Size.cx = (long)(pDoc->FileInfo.size.cx * Proportion) + EXTRA_WIDTH * 2;
- Size.cy = (long)(pDoc->FileInfo.size.cy * Proportion) + EXTRA_HIGTH * 2;
- SetScrollSizes(MM_TEXT, Size);
- pDoc->MyOperate.size.cx = Size.cx;
- pDoc->MyOperate.size.cy = Size.cy;
- CComboBox* pSizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
- pSizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
- Invalidate();
- }
-
- }
- //屏幕缩小
- void CMiniCADView::OnZoomin()
- {
- // TODO: Add your command handler code here
- CMiniCADDoc* pDoc = GetDocument();
- if(Proportion > 0.25)
- {
- Proportion -= 0.25;
- pDoc->MyOperate.Proportion = Proportion;
- //根据图纸尺寸设置滚动条滚动区域(既客户区)
- Size.cx = (long)(pDoc->FileInfo.size.cx * Proportion) + EXTRA_WIDTH * 2;
- Size.cy = (long)(pDoc->FileInfo.size.cy * Proportion) + EXTRA_HIGTH * 2;
- SetScrollSizes(MM_TEXT, Size);
- pDoc->MyOperate.size.cx = Size.cx;
- pDoc->MyOperate.size.cy = Size.cy;
- CComboBox* pSizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
- pSizeCombo->SetCurSel((int)(Proportion / 0.25 - 1));
- Invalidate();
- }
- }
- //选择图纸尺寸
- void CMiniCADView::OnSelchangeFilesize()
- {
- // TODO: Add your control notification handler code here
- CMiniCADDoc* pDoc = GetDocument();
- int index;
- CComboBox* pSizeCombo = (CComboBox*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_FILESIZE);
- index = pSizeCombo->GetCurSel();
- Proportion = (index + 1) * (float)0.25;
- pDoc->MyOperate.Proportion = Proportion;
-
- //根据图纸尺寸设置滚动条滚动区域(既客户区)
- Size.cx = (long)(pDoc->FileInfo.size.cx * Proportion) + EXTRA_WIDTH * 2;
- Size.cy = (long)(pDoc->FileInfo.size.cy * Proportion) + EXTRA_HIGTH * 2;
- SetScrollSizes(MM_TEXT, Size);
- pDoc->MyOperate.size.cx = Size.cx;
- pDoc->MyOperate.size.cy = Size.cy;
- Invalidate();
- }
- void CMiniCADView::OnSelchangeColor()
- {
- // TODO: Add your control notification handler code here
- CMiniCADDoc* Doc = GetDocument();
- CComboBoxEx* ColorCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_COLOR);
- switch(ColorCombo->GetCurSel())
- {
- case 0:
- pApp->CADInfo.ForeColor = RGB(0, 0, 0);
- break;
- case 1:
- pApp->CADInfo.ForeColor = RGB(255, 0, 0);
- break;
- case 2:
- pApp->CADInfo.ForeColor = RGB(255, 255, 0);
- break;
- case 3:
- pApp->CADInfo.ForeColor = RGB(0, 255, 0);
- break;
- case 4:
- pApp->CADInfo.ForeColor = RGB(0, 255, 255);
- break;
- case 5:
- pApp->CADInfo.ForeColor = RGB(0, 0, 255);
- break;
- case 6:
- pApp->CADInfo.ForeColor = RGB( 255, 0, 255);
- break;
- }
- Doc->MyOperate.ForeColor = pApp->CADInfo.ForeColor;
- }
- void CMiniCADView::OnSelchangeLinestyle()
- {
- // TODO: Add your control notification handler code here
- CMiniCADDoc* Doc = GetDocument();
- CComboBoxEx* LineStyleCombo = (CComboBoxEx*)pMainWnd->m_MyOptionBar.GetDlgItem(IDC_LINESTYLE);
- switch(LineStyleCombo->GetCurSel())
- {
- case 0:
- pApp->CADInfo.LineStyle = PS_SOLID;
- break;
- case 1:
- pApp->CADInfo.LineStyle = PS_DASH;
- break;
- case 2:
- pApp->CADInfo.LineStyle = PS_DOT;
- break;
- case 3:
- pApp->CADInfo.LineStyle = PS_DASHDOT;
- break;
- case 4:
- pApp->CADInfo.LineStyle = PS_DASHDOTDOT;
- break;
- }
- Doc->MyOperate.LineStyle = pApp->CADInfo.LineStyle;
- }
- void CMiniCADView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
-
- // TODO: Add your message handler code here
- //当改变视图尺寸时取消当前的绘图命令
- pApp->CADInfo.CurrentCommand = DRAW_SELECT;
- pApp->CADInfo.LRepeatTimes = 0;
- }
- void CMiniCADView::OnViewRedraw()
- {
- // TODO: Add your command handler code here
- //激活OnDraw()函数,重画当前视图
- Invalidate();
- }
- void CMiniCADView::OnEditUndo()
- {
- // TODO: Add your command handler code here
- CMyCommandStruct* pCommand;
- CMyObjectInfo* pLineInfo;
- CMyObjectInfo* pRectInfo;
- CMyObjectInfo* pCircleInfo;
- CMyObjectInfo* pArcInfo;
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyCommand.CommandPointer < 0)
- return;
- pCommand = (CMyCommandStruct*)Doc->MyCommand.GetCommandAt(Doc->MyCommand.CommandPointer);
- switch(pCommand->m_command)
- {
- case ID_DRAW_LINE:
- pLineInfo = (CMyObjectInfo*)Doc->MyOperate.m_LineInfoArray.GetAt(pCommand->m_index[0]);
- pLineInfo->m_del = TRUE;
- break;
- case ID_DRAW_RECT:
- pRectInfo = (CMyObjectInfo*)Doc->MyOperate.m_RectInfoArray.GetAt(pCommand->m_index[0]);
- pRectInfo->m_del = TRUE;
- break;
- case ID_DRAW_CIRCLE:
- pCircleInfo = (CMyObjectInfo*)Doc->MyOperate.m_CircleInfoArray.GetAt(pCommand->m_index[0]);
- pCircleInfo->m_del = TRUE;
- break;
- case ID_DRAW_ARC:
- pArcInfo = (CMyObjectInfo*)Doc->MyOperate.m_ArcInfoArray.GetAt(pCommand->m_index[0]);
- pArcInfo->m_del = TRUE;
- break;
- case ID_CHANGE_DELETE:
- for(int index =0; index < pCommand->m_num; index++)
- {
- switch(pCommand->m_object[index])
- {
- case OBJ_LINE:
- pLineInfo = (CMyObjectInfo*)Doc->MyOperate.m_LineInfoArray.GetAt(pCommand->m_index[index]);
- pLineInfo->m_del = FALSE;
- break;
- case OBJ_RECT:
- pRectInfo = (CMyObjectInfo*)Doc->MyOperate.m_RectInfoArray.GetAt(pCommand->m_index[index]);
- pRectInfo->m_del = FALSE;
- break;
- case OBJ_CIRCLE:
- pCircleInfo = (CMyObjectInfo*)Doc->MyOperate.m_CircleInfoArray.GetAt(pCommand->m_index[index]);
- pCircleInfo->m_del = FALSE;
- break;
- case OBJ_ARC:
- pArcInfo = (CMyObjectInfo*)Doc->MyOperate.m_ArcInfoArray.GetAt(pCommand->m_index[index]);
- pArcInfo->m_del = FALSE;
- break;
- }
- }
- break;
- }
-
- Doc->MyCommand.CommandPointer--;
- Invalidate();
- }
- void CMiniCADView::OnUpdateEditUndo(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyCommand.m_CommandArray.GetSize() > 0 &&
- Doc->MyCommand.CommandPointer > -1)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMiniCADView::OnEditRedo()
- {
- // TODO: Add your command handler code here
- CMyCommandStruct* pCommand;
- CMyObjectInfo* pLineInfo;
- CMyObjectInfo* pRectInfo;
- CMyObjectInfo* pCircleInfo;
- CMyObjectInfo* pArcInfo;
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyCommand.CommandPointer == Doc->MyCommand.m_CommandArray.GetUpperBound())
- return;
- else
- Doc->MyCommand.CommandPointer++;
- pCommand = (CMyCommandStruct*)Doc->MyCommand.GetCommandAt(Doc->MyCommand.CommandPointer);
- switch(pCommand->m_command)
- {
- case ID_DRAW_LINE:
- pLineInfo = (CMyObjectInfo*)Doc->MyOperate.m_LineInfoArray.GetAt(pCommand->m_index[0]);
- pLineInfo->m_del = FALSE;
- break;
- case ID_DRAW_RECT:
- pRectInfo = (CMyObjectInfo*)Doc->MyOperate.m_RectInfoArray.GetAt(pCommand->m_index[0]);
- pRectInfo->m_del = FALSE;
- break;
- case ID_DRAW_CIRCLE:
- pCircleInfo = (CMyObjectInfo*)Doc->MyOperate.m_CircleInfoArray.GetAt(pCommand->m_index[0]);
- pCircleInfo->m_del = FALSE;
- break;
- case ID_DRAW_ARC:
- pArcInfo = (CMyObjectInfo*)Doc->MyOperate.m_ArcInfoArray.GetAt(pCommand->m_index[0]);
- pArcInfo->m_del = FALSE;
- break;
- case ID_CHANGE_DELETE:
- for(int index =0; index < pCommand->m_num; index++)
- {
- switch(pCommand->m_object[index])
- {
- case OBJ_LINE:
- pLineInfo = (CMyObjectInfo*)Doc->MyOperate.m_LineInfoArray.GetAt(pCommand->m_index[index]);
- pLineInfo->m_del = TRUE;
- break;
- case OBJ_RECT:
- pRectInfo = (CMyObjectInfo*)Doc->MyOperate.m_RectInfoArray.GetAt(pCommand->m_index[index]);
- pRectInfo->m_del = TRUE;
- break;
- case OBJ_CIRCLE:
- pCircleInfo = (CMyObjectInfo*)Doc->MyOperate.m_CircleInfoArray.GetAt(pCommand->m_index[index]);
- pCircleInfo->m_del = TRUE;
- break;
- case OBJ_ARC:
- pArcInfo = (CMyObjectInfo*)Doc->MyOperate.m_ArcInfoArray.GetAt(pCommand->m_index[index]);
- pArcInfo->m_del = TRUE;
- break;
- }
- }
- break;
- }
- Invalidate();
- }
- void CMiniCADView::OnUpdateEditRedo(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyCommand.m_CommandArray.GetSize() > 0 &&
- Doc->MyCommand.CommandPointer < Doc->MyCommand.m_CommandArray.GetUpperBound())
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMiniCADView::OnUpdateDrawSelect(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(pApp->CADInfo.CurrentCommand == DRAW_SELECT);
- pCmdUI->ContinueRouting();
- }
- void CMiniCADView::OnModifyDelete()
- {
- // TODO: Add your command handler code here
- int* pObjectType;
- int* pObjetcIndex;
- int nIndex;
- int num;
- CMyObjectInfo* pLineInfo;
- CMyObjectInfo* pRectInfo;
- CMyObjectInfo* pCircleInfo;
- CMyObjectInfo* pArcInfo;
- CMySelObjectInfo* pSelObjectInfo;
- CMiniCADDoc* Doc = GetDocument();
- num = Doc->MyOperate.m_SelObjInfoArray.GetSize();
- pObjectType = new int[num];
- pObjetcIndex = new int[num];
- for(nIndex = 0; nIndex < num; nIndex++)
- {
- pSelObjectInfo = (CMySelObjectInfo*)Doc->MyOperate.m_SelObjInfoArray.GetAt(nIndex);
- switch(pSelObjectInfo->m_type)
- {
- case OBJ_LINE:
- pLineInfo = (CMyObjectInfo*)Doc->MyOperate.m_LineInfoArray.GetAt(pSelObjectInfo->m_index);
- pLineInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJ_LINE;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- case OBJ_RECT:
- pRectInfo = (CMyObjectInfo*)Doc->MyOperate.m_RectInfoArray.GetAt(pSelObjectInfo->m_index);
- pRectInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJ_RECT;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- case OBJ_CIRCLE:
- pCircleInfo = (CMyObjectInfo*)Doc->MyOperate.m_CircleInfoArray.GetAt(pSelObjectInfo->m_index);
- pCircleInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJ_CIRCLE;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- case OBJ_ARC:
- pArcInfo = (CMyObjectInfo*)Doc->MyOperate.m_ArcInfoArray.GetAt(pSelObjectInfo->m_index);
- pArcInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJ_ARC;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- }
- }
- Doc->MyCommand.DelCommandFrom(Doc->MyCommand.CommandPointer + 1);
- Doc->MyCommand.AddCommand(ID_CHANGE_DELETE, num, pObjectType, pObjetcIndex);
- Doc->MyCommand.CommandPointer = Doc->MyCommand.m_CommandArray.GetUpperBound();
- Doc->MyOperate.UnselectObject();
- Invalidate();
-
- delete pObjectType;
- delete pObjetcIndex;
- }
- void CMiniCADView::OnUpdateChangeDelete(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- CMiniCADDoc* Doc = GetDocument();
- if(Doc->MyOperate.m_SelObjInfoArray.GetSize() > 0)
- pCmdUI->Enable(TRUE);
- else
- pCmdUI->Enable(FALSE);
- }
- void CMiniCADView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- 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::OnComponentDefine()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnComponentInsert()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnAlignBottom()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnAlignConcentric()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnAlignLeft()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnAlignOnline()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnAlignRight()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnAlignTop()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnDrawFill()
- {
- // TODO: Add your command handler code here
-
- }
- void CMiniCADView::OnModifyBreak()
- {
- // TODO: Add your command handler code here
-
- }