GraphSoftView.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:84k
源码类别:
绘图程序
开发平台:
Visual C++
- // GraphSoftView.cpp : implementation of the CGraphSoftView class
- //
- #include "stdafx.h"
- #include "stdAfx.h"
- #include "GraphSoft.h"
- #include "GraphDefines.h"
- #include "GraphSoftDoc.h"
- #include "GraphSoftView.h"
- #include "FullViewBtn.h"
- #include "GraphInfoDlg.h"
- #include "FullScreenHandler.h"
- #include "ColorSetDlg.h"
- #include "GlobalFunction.h"
- #include "MainFrm.h"
- #include "UND_Create.h"
- #include "UND_Move.h"
- #include "UND_Rotate.h"
- #include "UND_Magnify.h"
- #include "UND_ShowPoints.h"
- #include "UND_TopToBtm.h"
- #include "UND_LeftToRight.h"
- #include "UND_Delete.h"
- #include "UND_Copy.h"
- #include "UND_Edit.h"
- #include "UND_Property.h"
- #include <windowsx.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CGraphSoftView
- IMPLEMENT_DYNCREATE(CGraphSoftView, CScrollView)
- BEGIN_MESSAGE_MAP(CGraphSoftView, CScrollView)
- //{{AFX_MSG_MAP(CGraphSoftView)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_COMMAND(ID_DRAW_DDALINE, OnDrawDdaline)
- ON_COMMAND(ID_FILE_EXPORT, OnFileExport)
- ON_WM_CONTEXTMENU()
- ON_COMMAND(ID_GRAPH_MOVE, OnGraphMove)
- ON_WM_LBUTTONDBLCLK()
- ON_UPDATE_COMMAND_UI(ID_DRAW_DDALINE, OnUpdateDrawDdaline)
- ON_COMMAND(ID_DRAW_RECTANGLE, OnDrawRectangle)
- ON_COMMAND(ID_DRAW_ROUNDRECT, OnDrawRoundrect)
- ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
- ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
- ON_UPDATE_COMMAND_UI(ID_DRAW_RECTANGLE, OnUpdateDrawRectangle)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ROUNDRECT, OnUpdateDrawRoundrect)
- ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
- ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
- ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
- ON_COMMAND(ID_DRAW_NONE, OnDrawNone)
- ON_UPDATE_COMMAND_UI(ID_DRAW_NONE, OnUpdateDrawNone)
- ON_COMMAND(ID_GRAPH_MAGNIFY, OnGraphMagnify)
- ON_COMMAND(ID_GRAPH_ROTATE, OnGraphRotate)
- ON_COMMAND(ID_GRAPH_PROPERTIY, OnGraphPropertiy)
- ON_COMMAND(ID_GRAPH_DELETE, OnGraphDelete)
- ON_COMMAND(ID_GRAPH_COPY, OnGraphCopy)
- ON_WM_DESTROY()
- ON_COMMAND(ID_SELECT_ALL, OnSelectAll)
- ON_UPDATE_COMMAND_UI(ID_SELECT_ALL, OnUpdateSelectAll)
- ON_COMMAND(ID_OPERATION_OVER, OnOperationOver)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_DELETE, OnUpdateGraphDelete)
- ON_COMMAND(ID_SELECT_PENWIDTH, OnSelectPenwidth)
- ON_UPDATE_COMMAND_UI(ID_SELECT_PENWIDTH, OnUpdateSelectPenwidth)
- ON_WM_SETCURSOR()
- ON_COMMAND(ID_DRAW_PARALLELOGRAM, OnDrawParallelogram)
- ON_UPDATE_COMMAND_UI(ID_DRAW_PARALLELOGRAM, OnUpdateDrawParallelogram)
- ON_COMMAND(ID_GRAPH_ROTATECENTER_SET, OnGraphRotatecenterSet)
- ON_COMMAND(ID_GRAPH_ROTATE_LEFT, OnGraphRotateLeft)
- ON_COMMAND(ID_GRAPH_ROTATE_RIGHT, OnGraphRotateRight)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATECENTER_SET, OnUpdateGraphRotatecenterSet)
- ON_COMMAND(ID_INPUT_CONFIRM, OnInputConfirm)
- ON_COMMAND(ID_SHAPE_OVER, OnShapeOver)
- ON_COMMAND(ID_DRAW_MODELCURVE2AVB, OnDrawModelcurve2avb)
- ON_UPDATE_COMMAND_UI(ID_DRAW_MODELCURVE2AVB, OnUpdateDrawModelcurve2avb)
- ON_COMMAND(ID_DRAW_MODELCURVE3PARAM, OnDrawModelcurve3param)
- ON_UPDATE_COMMAND_UI(ID_DRAW_MODELCURVE3PARAM, OnUpdateDrawModelcurve3param)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_COPY, OnUpdateGraphCopy)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_MAGNIFY, OnUpdateGraphMagnify)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_MOVE, OnUpdateGraphMove)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_PROPERTIY, OnUpdateGraphPropertiy)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATE, OnUpdateGraphRotate)
- ON_COMMAND(ID_DRAW_BEZIERCURVE, OnDrawBeziercurve)
- ON_UPDATE_COMMAND_UI(ID_DRAW_BEZIERCURVE, OnUpdateDrawBeziercurve)
- ON_UPDATE_COMMAND_UI(ID_INPUT_CONFIRM, OnUpdateInputConfirm)
- ON_COMMAND(ID_SELECT_FILL_COLOR, OnSelectFillColor)
- ON_COMMAND(ID_GRAPH_EDIT, OnGraphEdit)
- ON_COMMAND(ID_GRAPH_POINTSHIDE, OnGraphPointshide)
- ON_COMMAND(ID_GRAPH_POINTSSHOW, OnGraphPointsshow)
- ON_COMMAND(ID_GRAPH_LEFTTORIGHT, OnGraphLefttoright)
- ON_COMMAND(ID_GRAPH_TOPTOBOTTOM, OnGraphToptobottom)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_TOPTOBOTTOM, OnUpdateGraphToptobottom)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_EDIT, OnUpdateGraphEdit)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_LEFTTORIGHT, OnUpdateGraphLefttoright)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_POINTSHIDE, OnUpdateGraphPointshide)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_POINTSSHOW, OnUpdateGraphPointsshow)
- ON_UPDATE_COMMAND_UI(ID_OPERATION_OVER, OnUpdateOperationOver)
- ON_WM_INITMENUPOPUP()
- ON_WM_CREATE()
- ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATE_LEFT, OnUpdateGraphRotateLeft)
- ON_UPDATE_COMMAND_UI(ID_GRAPH_ROTATE_RIGHT, OnUpdateGraphRotateRight)
- ON_WM_ERASEBKGND()
- ON_MESSAGE(WM_SELGRAPH_POINT,OnSelGraphPoint)
- ON_MESSAGE(WM_SELGRAPH_ROTATE,OnSelGraphRotate)
- ON_MESSAGE(WM_SELGRAPH_COLOR,OnSelGraphColor)
- ON_MESSAGE(WM_SELGRAPH_FILLCOLOR,OnSelGraphFillClr)
- ON_MESSAGE(WM_SELGRAPH_FILLSTYLE,OnSelGraphFillSty)
- ON_MESSAGE(WM_SELGRAPH_PENWIDTH,OnSelGraphPenWidth)
- ON_WM_HSCROLL()
- ON_WM_VSCROLL()
- ON_COMMAND(ID_HELPFILE, OnHelpfile)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CGraphSoftView construction/destruction
- CGraphSoftView::CGraphSoftView()
- {
- // TODO: add construction code here
- m_nMouseFlag=0;
- m_bDrawFlag=FALSE;
- //m_mouseStatePrev=_MOUSE_NONESTATE;
- m_nCurrentPenWidth=1;
- m_clrCurrentColor=RGB(0,0,0);
- m_clrCurrentFill=RGB(255,255,255);
- m_clrBkColor=RGB(255,255,255);
- m_clrDefaultColor=RGB(0,0,0);
- m_flPrevX=m_flPrevY=0;
- m_flStartX=m_flStartY=0;
- m_graph_op=_graph_noneOp;
- m_bGraphOp=FALSE;
- m_bCanSelectGraphType=TRUE;
- m_ptSelectGraphCenter=CPoint(0,0);
- m_flRotCenterX=m_flRotCenterY=0;
- m_bSelectRotateCenter=FALSE;
- m_rectSelectGraph=CRect(0,0,0,0);
- m_rectMaxWindow=CRect(0,0,800,650);
- m_rectTarget=m_rectMaxWindow;
- m_pCurrentShape=NULL;
- m_shapeCurFillStyle=_shape_none_fill;
- m_flRate = 1;
- m_unPrevCur=0;
- }
- CGraphSoftView::~CGraphSoftView()
- {
- }
- BOOL CGraphSoftView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CScrollView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CGraphSoftView drawing
- void CGraphSoftView::OnDraw(CDC* pDC)
- {
- CGraphSoftDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- POSITION pos;
- pos=pDoc->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=pDoc->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- //pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
- pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
- }else{
- pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
- }
- }
- CClientDC dc(this);
- CBrush brush,*pOldBr;
- brush.CreateSolidBrush(RGB(255,0,0));
- pOldBr = dc.SelectObject(&brush);
- SelectObject(dc.GetSafeHdc(),&brush);
- dc.SelectObject(pOldBr);
- pDC->TextOut(0,0,FullScreenHandler.InFullScreenMode() ?_T("恢复窗口按 Ctrl-U ") : _T(""));
- }
- ////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////
- // MODULE :Redraw
- // ABSTRACT :重绘所给矩形区域内的图形
- // FUNCTION :
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // I CRect* pRect 所画矩形对应的逻辑坐标矩形
- // CREATE : FNST)handwolf 2004-4-20
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CGraphSoftView::Redraw(CDC* pDC,CRect* const pRect,bool bDrawRect,COLORREF color)
- {
- CRect rect,rect2;
- POSITION pos;
- pRect->NormalizeRect();
- rect=*pRect;
- rect2.left=rect.left-m_nCurrentPenWidth-1;
- rect2.right=rect.right+m_nCurrentPenWidth+1;
- rect2.top=rect.top-m_nCurrentPenWidth+1;
- rect2.bottom=rect.bottom+m_nCurrentPenWidth+1;
- float left=rect.left;
- float top=rect.top;
- float right=rect.right;
- float bottom=rect.bottom;
- Lp2Dp(left,top);
- Lp2Dp(right,bottom);
- rect=CRect(left,top,right,bottom);
- if(bDrawRect==TRUE&&color==RGB(255,255,255))
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- pDC->MoveTo(rect.TopLeft());
- pDC->LineTo(rect.left,rect.bottom);
- pDC->LineTo(rect.right,rect.bottom);
- pDC->LineTo(rect.right,rect.top);
- pDC->LineTo(rect.TopLeft());
- pDC->SelectObject(poldPen);
- }
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsInRect(rect2)){
- pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
- }
- }
- if(bDrawRect==TRUE&&color!=RGB(255,255,255))
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- pDC->MoveTo(rect.TopLeft());
- pDC->LineTo(rect.left,rect.bottom);
- pDC->LineTo(rect.right,rect.bottom);
- pDC->LineTo(rect.right,rect.top);
- pDC->LineTo(rect.TopLeft());
- pDC->SelectObject(poldPen);
- }
- }
- // CGraphSoftView printing
- BOOL CGraphSoftView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CGraphSoftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CGraphSoftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CGraphSoftView diagnostics
- #ifdef _DEBUG
- void CGraphSoftView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CGraphSoftView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CGraphSoftDoc* CGraphSoftView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGraphSoftDoc)));
- return (CGraphSoftDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CGraphSoftView message handlers
- void CGraphSoftView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- float flX=point.x;
- float flY=point.y;
- Dp2Lp(flX,flY);
- m_nMouseFlag=1;
- m_flPrevX=flX;
- m_flPrevY=flY;
- m_flStartX=flX;
- m_flStartY=flY;
- CUND_Base* pUndo;
- if(m_bGraphOp){
- m_bDrawFlag=FALSE;
- }else{
- m_bDrawFlag=TRUE;
- switch(GetDocument()->m_nCurrentShapeType) {
- case _shape_none:
- break;
- case _shape_Line:
- m_flArrayX.Add(flX);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CLine();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- case _shape_Parallelogram:
- {
- if(m_flArrayX.GetSize()==0){
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- }else if(m_flArrayX.GetSize()==1)
- {
- m_flArrayX.Add(flX);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CParallelogram();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- int old_rop = dc.SetROP2(R2_XORPEN);
- // m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- float x1=m_flArrayX.GetAt(0);
- float y1=m_flArrayY.GetAt(0);
- float x2=m_flArrayX.GetAt(1);
- float y2=m_flArrayY.GetAt(1);
- Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
- Lp2Dp(x2,y2);
- DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);
- dc.SetROP2(old_rop);
- }
- }
- break;
- case _shape_Rectangle:
- m_flArrayX.Add(flX);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CRectangle();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- case _shape_RoundRect:
- m_flArrayX.Add(flX);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CRoundRect();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- case _shape_Circle:
- m_flArrayX.Add(flX);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CCircle();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- case _shape_Ellipse:
- m_flArrayX.Add(flX);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CEllipse();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- case _shape_Polygon:
- if(m_flArrayX.GetSize()==0){
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CPolygon();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- }
- break;
- case _shape_ModelCurve3Param:
- if(m_flArrayX.GetSize()==0){
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CModelCurve3Param();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- }
- break;
- case _shape_ModelCurve2AvB:
- if(m_flArrayX.GetSize()==0){
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CModelCurve2AvB();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- }
- break;
- case _shape_BezierCurve:
- if(m_flArrayX.GetSize()==0){
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_pCurrentShape=new CBezierCurve();
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- pUndo = new CUND_Create(m_pCurrentShape);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- GetDocument()->m_shapeList.AddTail(m_pCurrentShape);
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- }
- break;
- default:
- break;
- }
- }
- CRect rect;//矩形
- GetClientRect(&rect);
- ClientToScreen(&rect);
- ClipCursor(&rect);
- CScrollView::OnLButtonDown(nFlags, point);
- }
- void CGraphSoftView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- float flX=point.x;
- float flY=point.y;
- Dp2Lp(flX,flY);
- CRect rect;
- m_nMouseFlag=0;
- if(m_bGraphOp==FALSE&&m_bDrawFlag)
- {
- switch(GetDocument()->m_nCurrentShapeType) {
- case _shape_none:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- dc.SetBkMode(TRANSPARENT);
- CPen pen,*poldPen;
- CBrush brush,*pOldbr;
- pen.CreatePen(PS_SOLID,1, RGB(0,200,0));
- poldPen=dc.SelectObject(&pen);
- brush.CreateSolidBrush(RGB(50,0,0));
- //brush.CreateSysColorBrush(2);
- pOldbr=dc.SelectObject(&brush);
- float x1,y1,x2,y2;
- x1=m_flStartX;
- y1=m_flStartY;
- x2=m_flPrevX;
- y2=m_flPrevY;
- Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
- Lp2Dp(x2,y2);
- CRect rt(x1,y1,x2,y2);
- rt.NormalizeRect();
- dc.Rectangle(&rt);
- dc.SelectObject(poldPen);
- dc.SelectObject(pOldbr);
- dc.SetROP2(old_rop);
- // Redraw(&dc,&rect,FALSE);
- rt=CRect(m_flStartX,m_flStartY,m_flPrevX,m_flPrevY);//用逻辑坐标,利于操作
- GetDocument()->SelectInRect(&rt,&dc,nFlags,TRUE);
- // SetDrawMenuEnable(!GetDocument()->HasGraphSelected());//协调一直
- m_bDrawFlag=FALSE;
- break;
- }
- case _shape_Line:
- case _shape_Rectangle:
- case _shape_RoundRect:
- case _shape_Circle:
- case _shape_Ellipse:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- // m_pCurrentShape->Draw(&dc,RGB(0,255,0),m_nCurrentPenWidth+1);
- dc.SetROP2(old_rop);
- m_pCurrentShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- // m_pCurrentShape->Draw(&dc);
- }
- m_bDrawFlag=FALSE;
- break;
- case _shape_Parallelogram:
- {
- int nTemp=m_flArrayX.GetSize();
- if(nTemp==3){
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- m_flArrayX.SetAt(2,flX);
- m_flArrayY.SetAt(2,flY);
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- dc.SetROP2(old_rop);
- m_pCurrentShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- m_bDrawFlag=FALSE;
- }
- }
- break;
- case _shape_Polygon:
- case _shape_ModelCurve3Param:
- case _shape_ModelCurve2AvB:
- case _shape_BezierCurve:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- m_flArrayX.SetAt(m_flArrayX.GetSize()-1,flX);
- m_flArrayY.SetAt(m_flArrayY.GetSize()-1,flY);
- m_flArrayX.Add(flX);
- m_flArrayY.Add(flY);
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- }
- break;
- default:
- m_bDrawFlag=FALSE;
- break;
- }
- //
- }
- if(m_bGraphOp){
- float flxTemp,flyTemp;
- if(m_bSelectRotateCenter){
- int old_rop = dc.SetROP2(R2_XORPEN);
- float flxTemp,flyTemp;
- flxTemp=m_ptSelectGraphCenter.x/1000.0;
- flyTemp=m_ptSelectGraphCenter.y/1000.0;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- m_bSelectRotateCenter=FALSE;
- m_flRotCenterX=flX;//逻辑坐标点
- m_flRotCenterY=flY;
- flxTemp=m_flRotCenterX;
- flyTemp=m_flRotCenterY;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- dc.SetROP2(old_rop);
- }else{
- CUND_Base* pUndo;
- switch(m_graph_op)
- {
- case _graph_magnify:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- flxTemp=m_ptSelectGraphCenter.x/1000.0;
- flyTemp=m_ptSelectGraphCenter.y/1000.0;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, RGB(255,255,0));
- poldPen=dc.SelectObject(&pen);
- float flLx,flRx,flTy,flBy;
- flLx=m_rectSelectGraph.left/1000.0;
- flTy=m_rectSelectGraph.top/1000.0;
- flRx=m_rectSelectGraph.right/1000.0;
- flBy=m_rectSelectGraph.bottom/1000.0;
- Lp2Dp(flLx,flTy);
- Lp2Dp(flRx,flBy);
- dc.MoveTo(flLx,flTy);
- dc.LineTo(flLx,flBy);
- dc.LineTo(flRx,flBy);
- dc.LineTo(flRx,flTy);
- dc.LineTo(flLx,flTy);
- dc.SelectObject(poldPen);
- dc.SetROP2(old_rop);
- GetDocument()->RefreshSelectGraph();
- SUNDMagnify *pStructMagnify=new SUNDMagnify();
- GetDocument()->GetSelGraphIDArray(pStructMagnify->ArrId);
- float flDisA,flDisB;
- flDisA=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,m_flStartX,m_flStartY);//attention: m_ptStart
- flDisB=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,m_flPrevX,m_flPrevY);
- if(flDisA<0.5){
- flDisA=0.5;
- }
- pStructMagnify->flScale=flDisB/flDisA;
- pStructMagnify->flCX=m_ptSelectGraphCenter.x/1000.0;
- pStructMagnify->flCY=m_ptSelectGraphCenter.y/1000.0;
- pUndo = new CUND_Magnify(pStructMagnify);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- }
- case _graph_rotate:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- flxTemp=m_flRotCenterX;
- flyTemp=m_flRotCenterY;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- TRACE("OnLButtonUp()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
- TRACE("OnLButtonUp()---Device RotateCenter(%f,%f)n",flxTemp,flyTemp);
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
- dc.SetROP2(old_rop);
- GetDocument()->RefreshSelectGraph();
- SUNDRotate *pStructRotate=new SUNDRotate();
- GetDocument()->GetSelGraphIDArray(pStructRotate->ArrId);
- pStructRotate->flAngle=
- GetAngleFromPoints(m_flRotCenterX,m_flRotCenterY,
- m_flStartX,m_flStartY,m_flPrevX,m_flPrevY);
- pStructRotate->flCX=m_flRotCenterX;
- pStructRotate->flCY=m_flRotCenterY;
- pUndo = new CUND_Rotate(pStructRotate);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- }
- case _graph_edit:
- // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
- GetDocument()->RefreshSelectGraph();
- break;
- case _graph_move:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- SUNDMove *pStructMove=new SUNDMove();
- GetDocument()->GetSelGraphIDArray(pStructMove->ArrId);
- pStructMove->nStepX=m_flPrevX-m_flStartX;
- pStructMove->nStepY=m_flPrevY-m_flStartY;
- pUndo = new CUND_Move(pStructMove);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- break;
- }
- case _graph_property:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_delete:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_leftToRight:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_topTobottom:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_pointsShow:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_pointsHide:
- {
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_copy:
- // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
- {
- SUNDCopy *pStructCopy=new SUNDCopy();
- GetDocument()->GetSelGraphArray(pStructCopy->ArrShape);
- CUND_Base* pUndo = new CUND_Copy(pStructCopy);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- SendMessage(WM_COMMAND,WPARAM(ID_GRAPH_COPY));
- break;
- }
- default:
- break;
- }
- }
- }
- if(!m_bDrawFlag){ //如果不画了,删除缓存的点。
- m_flArrayX.RemoveAll();
- m_flArrayY.RemoveAll();
- m_pCurrentShape=NULL;
- ClipCursor(NULL);
- }
- CScrollView::OnLButtonUp(nFlags, point);
- }
- void CGraphSoftView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CClientDC dc(this);
- OnPrepareDC(&dc);
- dc.DPtoLP(&point);
- float flX=point.x;
- float flY=point.y;
- Dp2Lp(flX,flY);
- CRect rect;
- if(m_bDrawFlag)
- {
- switch(GetDocument()->m_nCurrentShapeType) {
- case _shape_none:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- CPen pen,*poldPen;
- CBrush brush,*pOldbr;
- pen.CreatePen(PS_SOLID,1, RGB(0,200,0));
- poldPen=dc.SelectObject(&pen);
- brush.CreateSolidBrush(RGB(50,0,0));
- pOldbr=dc.SelectObject(&brush);
- dc.SetBkMode(TRANSPARENT);
- float x1,y1,x2,y2;
- x1=m_flStartX;
- y1=m_flStartY;
- x2=m_flPrevX;
- y2=m_flPrevY;
- Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
- Lp2Dp(x2,y2);
- CRect rt(x1,y1,x2,y2);
- rt.NormalizeRect();
- x2=flX;
- y2=flY;
- Lp2Dp(x2,y2);
- CRect rectTmp(x1,y1,x2,y2);
- //if(rect.left<rectTmp.left||rect.right>rectTmp.right||rect.top<rectTmp.top||rect.bottom>rectTmp.bottom){
- dc.Rectangle(&rt);
- dc.Rectangle(&rectTmp);
- // Redraw(&dc,&rectTmp,FALSE);
- dc.SelectObject(poldPen);
- dc.SelectObject(pOldbr);
- dc.SetROP2(old_rop);
- break;
- }
- case _shape_Line:
- case _shape_Rectangle:
- case _shape_RoundRect:
- case _shape_Circle:
- case _shape_Ellipse:
- case _shape_Polygon:
- case _shape_ModelCurve3Param:
- case _shape_ModelCurve2AvB:
- case _shape_BezierCurve:
- {
- //m_pCurrentShape=GetDocument()->m_shapeList.GetTail();
- if(m_flArrayX.GetSize()>0){
- int old_rop = dc.SetROP2(R2_XORPEN);
- rect=m_pCurrentShape->GetBoundaryRect();
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- // m_pCurrentShape->Draw(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1);
- m_flArrayX.SetAt(m_flArrayX.GetSize()-1,flX);
- m_flArrayY.SetAt(m_flArrayY.GetSize()-1,flY);
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- // m_pCurrentShape->Draw(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1);
- dc.SetROP2(old_rop);
- }
- break;
- }
- case _shape_Parallelogram:
- {
- if(m_flArrayX.GetSize()>0&&m_flArrayX.GetSize()<=2){
- int old_rop = dc.SetROP2(R2_XORPEN);
- //rect=GetRectFromPoint(m_ptStart,m_ptPrev);
- float x1=m_flStartX;
- float y1=m_flStartY;
- float x2=m_flPrevX;
- float y2=m_flPrevY;
- Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
- Lp2Dp(x2,y2);
- DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);
- // Redraw(&dc,&rect);
- x2=flX;
- y2=flY;
- Lp2Dp(x2,y2);
- DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);
- dc.SetROP2(old_rop);
- } else if(m_flArrayX.GetSize()==3){
- int old_rop = dc.SetROP2(R2_XORPEN);
- // rect=m_pCurrentShape->GetBoundaryRect();
- // Redraw(&dc,&rect,FALSE);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- m_flArrayX.SetAt(2,flX);
- m_flArrayY.SetAt(2,flY);
- m_pCurrentShape->CreatGraph(m_flArrayX,m_flArrayY,m_nCurrentPenWidth,m_clrCurrentColor,m_clrCurrentFill,m_shapeCurFillStyle);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- }
- }
- break;
- default:
- break;
- }//switch{case:}
- }//if
- if(m_bGraphOp&&(nFlags&MK_LBUTTON)&&!m_bSelectRotateCenter){
- GraphOperator(&dc,m_graph_op,m_flPrevX,m_flPrevY,flX,flY);
- }else if(m_bGraphOp&&m_graph_op==_graph_copy){//copy 例外
- GraphOperator(&dc,m_graph_op,m_flPrevX,m_flPrevY,flX,flY);
- }else if(m_bGraphOp&&m_graph_op==_graph_edit){
- GetDocument()->SetEditStateCursor(flX,flY,((float)m_rectTarget.Width())/m_rectMaxWindow.Width());
- }
- m_flPrevX=flX;
- m_flPrevY=flY;
- CString strTemp;
- strTemp.Format("屏幕:(%d,%d) 逻辑:(%d,%d)",point.x,point.y,(int)flX,(int)flY);
- //TRACE("%sn",strTemp);
- ((CMainFrame*)(AfxGetApp()->GetMainWnd()))->SetPaneText(1,LPCSTR(strTemp),TRUE);
- // CScrollView::OnMouseMove(nFlags, point);
- }
- ////////////////////////////////////////////////////////////////
- //function GraphOperator(...)
- //param
- //opId-----the ID if Graph Operation that should be execute
- //nstepx---the step in x direction
- //nstepy---the step in y direction
- //point----the present point of mouse
- ///////////////////////////////////////////////////////////////
- void CGraphSoftView::GraphOperator(CDC *pDC,GRAPH_OPERATION opId,float PrevX,float PrevY,float CurX,float CurY)
- {
- CPoint ptPrev(PrevX,PrevY);
- CPoint ptPresent(CurX,CurY);
- POSITION pos;
- CRect rect=GetSelectGraphBoundaryRect();
- CPoint ptCenter=rect.CenterPoint();
- float flAngle;
- float flScale=1;
- CPoint ptStart(m_flStartX,m_flStartY);
- //Get the angle that should rotate
- //先求出两点(前点与移动后点)向中心点的连线与水平线的交角
- //然后减一下即可得到转过的角度
- int old_rop = pDC->SetROP2(R2_XORPEN);
- pDC->SetBkMode(TRANSPARENT);
- switch(opId){
- case _graph_magnify:
- {
- float flDisA,flDisB;
- flDisA=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,m_flStartX,m_flStartY);//attention: m_ptStart
- flDisB=GetDistance(m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,CurX,CurY);
- if(flDisA<0.5){
- flDisA=0.5;
- }
- flScale=flDisB/flDisA;
- //Redraw(pDC,&rect,TRUE,RGB(255,255,255));
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, RGB(255,255,0));
- poldPen=pDC->SelectObject(&pen);
- float flLx,flRx,flTy,flBy;
- flLx=rect.left/1000.0;
- flTy=rect.top/1000.0;
- flRx=rect.right/1000.0;
- flBy=rect.bottom/1000.0;
- Lp2Dp(flLx,flTy);
- Lp2Dp(flRx,flBy);
- pDC->MoveTo(flLx,flTy);
- pDC->LineTo(flLx,flBy);
- pDC->LineTo(flRx,flBy);
- pDC->LineTo(flRx,flTy);
- pDC->LineTo(flLx,flTy);
- float flxTemp,flyTemp;
- flxTemp=m_ptSelectGraphCenter.x/1000.0;
- flyTemp=m_ptSelectGraphCenter.y/1000.0;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(pDC,flxTemp,flyTemp,RGB(0,255,0));
- pDC->SelectObject(poldPen);
- //TRACE("SCALE:%fn",flScale);
- break;
- }
- case _graph_rotate:
- {
- if(ptPresent==ptPrev)
- return;
- //Redraw(pDC,&rect,FALSE);
- float flx,fly;
- flx=m_flRotCenterX;
- fly=m_flRotCenterY;
- Lp2Dp(flx,fly);
- DrawOutRectPoint(pDC,flx,fly,RGB(0,255,0));
- TRACE("GraphOperator()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
- TRACE("GraphOperator()---Device RotateCenter(%f,%f)n",flx,fly);
- flAngle=GetAngleFromPoints(m_flRotCenterX,m_flRotCenterY,m_flStartX,m_flStartY,CurX,CurY);
- //TRACE("ANGLE:-%f,Cos----%f,Sin-----%fn",flAngle,cos(flAngle),sin(flAngle));
- break;
- }
- default:
- break;
- }//end switch
- ////////////
- pDC->SetROP2(old_rop);
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- pShape->DrawCutToRect(pDC,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
- switch(opId)
- {
- case _graph_move:
- {
- pShape->Move(pDC,CurX-PrevX,CurY-PrevY);
- break;
- }
- case _graph_rotate:
- {
- pShape->Rotate(pDC,m_flRotCenterX,m_flRotCenterY,flAngle);
- break;
- }
- case _graph_magnify:
- {
- pShape->Magnify(pDC,m_ptSelectGraphCenter.x/1000.0,m_ptSelectGraphCenter.y/1000.0,flScale);
- break;
- }
- case _graph_property:
- case _graph_delete:
- break;
- case _graph_copy:
- pShape->Move(pDC,CurX-PrevX,CurY-PrevY);
- break;
- case _graph_edit:
- pShape->PartMove(pDC,m_flPrevX,m_flPrevY,CurX,CurY);
- SetCursor(AfxGetApp()->LoadCursor(m_unPrevCur));
- break;
- default:
- break;
- }
- }
- pShape->DrawCutToRect(pDC,m_rectTarget,m_rectMaxWindow);
- }
- pDC->SetROP2(R2_XORPEN);
- switch(opId){
- case _graph_move:
- //rect=GetSelectGraphBoundaryRect();
- //Redraw(pDC,&rect,FALSE);
- break;
- case _graph_copy:
- // Redraw(pDC,&rect,FALSE);
- // rect=GetSelectGraphBoundaryRect();
- //Redraw(pDC,&rect,FALSE);
- break;
- case _graph_rotate:
- {
- //rect=GetSelectGraphBoundaryRect();
- float flx,fly;
- flx=m_flRotCenterX;
- fly=m_flRotCenterY;
- Lp2Dp(flx,fly);
- TRACE("GraphOperator()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
- TRACE("GraphOperator()---Device RotateCenter(%f,%f)n",flx,fly);
- DrawOutRectPoint(pDC,flx,fly,RGB(0,255,0));
- //Redraw(pDC,&rect,FALSE);
- break;
- }
- case _graph_magnify:
- {
- rect=GetSelectGraphBoundaryRect();
- // Redraw(pDC,&rect,TRUE,RGB(255,255,0));
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, RGB(255,255,0));
- poldPen=pDC->SelectObject(&pen);
- float flLx,flRx,flTy,flBy;
- flLx=m_rectSelectGraph.left/1000.0;
- flTy=m_rectSelectGraph.top/1000.0;
- flRx=m_rectSelectGraph.right/1000.0;
- flBy=m_rectSelectGraph.bottom/1000.0;
- Lp2Dp(flLx,flTy);
- Lp2Dp(flRx,flBy);
- pDC->MoveTo(flLx,flTy);
- pDC->LineTo(flLx,flBy);
- pDC->LineTo(flRx,flBy);
- pDC->LineTo(flRx,flTy);
- pDC->LineTo(flLx,flTy);
- float flxTemp,flyTemp;
- flxTemp=m_ptSelectGraphCenter.x/1000.0;
- flyTemp=m_ptSelectGraphCenter.y/1000.0;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(pDC,flxTemp,flyTemp,RGB(0,255,0));
- pDC->SelectObject(poldPen);
- break;
- }
- case _graph_edit:
- // rect=GetSelectGraphBoundaryRect();
- // Redraw(pDC,&rect,FALSE);
- break;
- default:
- break;
- }//end switch
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::OnDrawDdaline()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_Line)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_Line;
- OnOperationOver() ;
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::OnFileExport()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- // OnPrepareDC(&dc);
- CDC memDC;
- CRect rect;
- GetClientRect(rect);
- memDC.CreateCompatibleDC(&dc);
- CBitmap bm;
- int Width = rect.Width();
- int Height = rect.Height();
- bm.CreateCompatibleBitmap(&dc, Width, Height);
- CBitmap* pOld = memDC.SelectObject(&bm);
- memDC.BitBlt(0, 0, Width, Height, &dc, 0, 0, SRCCOPY);
- memDC.SelectObject(pOld);
- BITMAP btm;
- bm.GetBitmap(&btm);
- DWORD size = btm.bmWidthBytes * btm.bmHeight;
- LPSTR lpData = (LPSTR)GlobalAllocPtr(GPTR, size);
- BITMAPFILEHEADER bfh;
- /////////////////////////////////////////////
- BITMAPINFOHEADER bih;
- bih.biBitCount = btm.bmBitsPixel;
- bih.biClrImportant = 0;
- bih.biClrUsed = 0;
- bih.biCompression = 0;
- bih.biHeight = btm.bmHeight;
- bih.biPlanes = 1;
- bih.biSize = sizeof(BITMAPINFOHEADER);
- bih.biSizeImage = size;
- bih.biWidth = btm.bmWidth;
- bih.biXPelsPerMeter = 0;
- bih.biYPelsPerMeter = 0;
- GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);
- //bm.GetBitmapBits(size,lpData);//此函数在处理5-5-5模式的16位色下会出现颜色混乱
- bfh.bfReserved1 = bfh.bfReserved2 = 0;
- bfh.bfType = ((WORD)('M'<< 8)|'B');
- bfh.bfSize = 54 + size;
- bfh.bfOffBits = 54;
- CFileDialog dlg(false,_T("BMP"),_T("*.bmp"),OFN_OVERWRITEPROMPT,_T("*.bmp|*.bmp|*.lld|*.lld|*.*|*.*|"));
- if (dlg.DoModal()==IDOK)
- {
- if(dlg.GetFileExt()=="bmp"){
- CFile bf;
- CString ss=dlg.GetPathName();
- if(bf.Open(ss, CFile::modeCreate | CFile::modeWrite))
- {
- bf.WriteHuge(&bfh, sizeof(BITMAPFILEHEADER));
- bf.WriteHuge(&bih, sizeof(BITMAPINFOHEADER));
- bf.WriteHuge(lpData, size);
- bf.Close();
- CString str;
- str.LoadString(IDS_STRING_SAVE_SUCCESS);
- AfxMessageBox(str);
- }
- }else if(dlg.GetFileExt()=="lld"){
- FILE *OutStream;
- OutStream = fopen(dlg.GetPathName(), "w" );
- GetDocument()->ExPort(OutStream);
- fclose(OutStream);
- }
- }
- GlobalFreePtr(lpData);
- }
- //////////////////////////////////////////////////
- int CGraphSoftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CScrollView::OnCreate(lpCreateStruct) == -1)
- return -1;
- GetDocument()->m_pCore->m_pView=this;
- // TODO: Add your specialized creation code here
- return 0;
- }
- void CGraphSoftView::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
- {
- CWnd ::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
- // TODO: Add your message handler code here
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- // TODO: Add your message handler code here
- CMenu popup;
- // CMenu* pPopup;
- CMenuEx menu;
- CString str;
- if(!m_nMouseFlag)
- {
- //图形操作
- if(GetDocument()->HasGraphSelected()&&m_graph_op==_graph_noneOp)
- {
- m_pToolBar=&(((CMainFrame*)(AfxGetApp()->GetMainWnd()))->m_wndTBarGraphOp);
- menu.CreatePopupMenu();
- str.LoadString(ID_GRAPH_MOVE);//移动
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_MOVE,str);
- str.LoadString(ID_GRAPH_ROTATE);//旋转
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATE,str);
- str.LoadString(ID_GRAPH_MAGNIFY);//缩放
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_MAGNIFY,str);
- str.LoadString(ID_GRAPH_COPY);//拷贝
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_COPY,str);
- str.LoadString(ID_GRAPH_DELETE);//删除
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_DELETE,str);
- CMenuEx menuTemp; //显示/隐藏组成点---弹出菜单
- menuTemp.CreatePopupMenu();
- str.LoadString(ID_GRAPH_POINTSSHOW);//显示组成点
- str=str.Left(str.FindOneOf(_T("n")));
- menuTemp.AppendMenu(MF_ENABLED,ID_GRAPH_POINTSSHOW,str);
- str.LoadString(ID_GRAPH_POINTSHIDE);//隐藏组成点
- str=str.Left(str.FindOneOf(_T("n")));
- menuTemp.AppendMenu(MF_ENABLED,ID_GRAPH_POINTSHIDE,str);
- menuTemp.InitPopupMenu(&menuTemp,IDR_GRAPH_OPERATION,m_pToolBar);
- str.LoadString(IDS_GRAPH_POINTS);
- menu.AppendMenu(MF_POPUP,(UINT)(menuTemp.GetSafeHmenu()),str);
- if(GetDocument()->GetSelectNum()==1){
- str.LoadString(ID_GRAPH_EDIT);//编辑
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_EDIT,str);
- }
- str.LoadString(ID_GRAPH_PROPERTIY);
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_PROPERTIY,str);//属性
- menu.AppendMenu(MF_GRAYED,ID_SEPARATOR);
- str.LoadString(ID_GRAPHOP_MORE);
- menu.AppendMenu(MF_ENABLED,ID_GRAPHOP_MORE,str);
- menu.InitPopupMenu(&menu,IDR_GRAPH_OPERATION,m_pToolBar);
- UINT nMenuID=menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD ,
- point.x,point.y, this);
- while(nMenuID==ID_GRAPHOP_MORE||nMenuID==ID_GRAPHOP_LESS){
- if(nMenuID==ID_GRAPHOP_MORE){
- menu.DeleteMenu(ID_GRAPHOP_MORE,MF_BYCOMMAND);
- menu.DeleteItem(ID_GRAPHOP_MORE);
- str.LoadString(ID_GRAPHOP_LESS);
- menu.AppendMenu(MF_ENABLED,ID_GRAPHOP_LESS,str);
- str.LoadString(ID_GRAPH_LEFTTORIGHT);
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_LEFTTORIGHT,str);//左右变换
- str.LoadString(ID_GRAPH_TOPTOBOTTOM);
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_TOPTOBOTTOM,str);//上下变换
- }else{
- menu.DeleteMenu(ID_GRAPHOP_LESS,MF_BYCOMMAND);
- menu.DeleteItem(ID_GRAPHOP_LESS);
- menu.DeleteMenu(ID_GRAPH_LEFTTORIGHT,MF_BYCOMMAND);
- menu.DeleteItem(ID_GRAPH_LEFTTORIGHT);
- menu.DeleteMenu(ID_GRAPH_TOPTOBOTTOM,MF_BYCOMMAND);
- menu.DeleteItem(ID_GRAPH_TOPTOBOTTOM);
- str.LoadString(ID_GRAPHOP_MORE);
- menu.AppendMenu(MF_ENABLED,ID_GRAPHOP_MORE,str);
- }
- menu.m_bInitial=FALSE;
- menu.ChangeStyle(&menu,m_pToolBar,TRUE);
- nMenuID=menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON|TPM_RETURNCMD ,
- point.x,point.y, this); ;
- }
- this->SendMessage(WM_COMMAND,WPARAM(nMenuID));
- menu.DestroyMenu();
- menuTemp.DestroyMenu();
- }
- //图形操作子操作
- else if(GetDocument()->HasGraphSelected()){
- m_pToolBar=&(((CMainFrame*)(AfxGetApp()->GetMainWnd()))->m_wndTBarGraphOp);
- menu.CreatePopupMenu();
- switch(m_graph_op){
- case _graph_rotate:
- str.LoadString(ID_GRAPH_ROTATE_LEFT);
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATE_LEFT,str);
- str.LoadString(ID_GRAPH_ROTATE_RIGHT);
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATE_RIGHT,str);
- str.LoadString(ID_GRAPH_ROTATECENTER_SET);
- str=str.Left(str.FindOneOf(_T("n")));
- if(m_bSelectRotateCenter){
- menu.AppendMenu(MF_ENABLED|MF_CHECKED,ID_GRAPH_ROTATECENTER_SET,str);
- }else{
- menu.AppendMenu(MF_ENABLED,ID_GRAPH_ROTATECENTER_SET,str);
- }
- menu.AppendMenu(MF_ENABLED,ID_SEPARATOR);
- break;
- case _graph_magnify:
- break;
- case _graph_copy:
- break;
- default:
- break;
- }
- str.LoadString(ID_OPERATION_OVER);
- str=str.Left(str.FindOneOf(_T("n")));
- menu.AppendMenu(MF_ENABLED,ID_OPERATION_OVER,str);
- menu.InitPopupMenu(&menu,IDR_GRAPH_OPERATION,m_pToolBar);
- menu.TrackPopupMenu(TPM_LEFTALIGN ,point.x,point.y,this);
- menu.DestroyMenu();
- }
- //画图时的操作
- else if(GetDocument()->m_nCurrentShapeType!=_shape_none){
- CString strMenuTitle;
- popup.CreatePopupMenu();
- switch(GetDocument()->m_nCurrentShapeType){
- case _shape_Polygon:
- if(m_pCurrentShape!=NULL){
- strMenuTitle.LoadString(ID_INPUT_CONFIRM);
- popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
- }
- break;
- case _shape_ModelCurve3Param:
- if(m_pCurrentShape!=NULL){
- strMenuTitle.LoadString(ID_INPUT_CONFIRM);
- popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
- }
- break;
- case _shape_ModelCurve2AvB:
- if(m_pCurrentShape!=NULL){
- strMenuTitle.LoadString(ID_INPUT_CONFIRM);
- popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
- }
- break;
- case _shape_BezierCurve:
- if(m_pCurrentShape!=NULL){
- strMenuTitle.LoadString(ID_INPUT_CONFIRM);
- popup.AppendMenu(MF_ENABLED,ID_INPUT_CONFIRM,strMenuTitle);
- }
- break;
- default:
- break;
- }
- strMenuTitle.LoadString(ID_SHAPE_OVER);
- strMenuTitle=strMenuTitle.Left(strMenuTitle.FindOneOf(_T("n")));
- popup.AppendMenu(MF_ENABLED,ID_SHAPE_OVER,strMenuTitle);
- //popup.EnableMenuItem(1,MF_BYPOSITION|MF_GRAYED);
- popup.TrackPopupMenu(TPM_LEFTALIGN ,point.x,point.y,this);
- popup.DestroyMenu();
- }
- }
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- if(GetDocument()->m_nCurrentShapeType!=_shape_none){
- SendMessage(WM_COMMAND,WPARAM(ID_INPUT_CONFIRM));
- }
- if(m_graph_op!=_graph_noneOp){
- SendMessage(WM_COMMAND,WPARAM(ID_OPERATION_OVER));
- }
- CScrollView::OnLButtonDblClk(nFlags, point);
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::SetDrawMenuEnable(bool bEnable)
- {
- m_bCanSelectGraphType=bEnable;
- }
- void CGraphSoftView::OnUpdateDrawDdaline(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Line?1:0);
- }
- void CGraphSoftView::OnDrawRectangle()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_Rectangle)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_Rectangle;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnDrawRoundrect()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_RoundRect)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_RoundRect;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnDrawPolygon()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_Polygon)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_Polygon;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawPolygon(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Polygon?1:0);
- }
- void CGraphSoftView::OnUpdateDrawRectangle(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Rectangle?1:0);
- }
- void CGraphSoftView::OnUpdateDrawRoundrect(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_RoundRect?1:0);
- }
- void CGraphSoftView::OnDrawEllipse()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_Ellipse)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_Ellipse;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Ellipse?1:0);
- }
- void CGraphSoftView::OnDrawCircle()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_Circle)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_Circle;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawCircle(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Circle?1:0);
- }
- void CGraphSoftView::OnDrawParallelogram()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_Parallelogram)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_Parallelogram;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawParallelogram(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_Parallelogram?1:0);
- }
- void CGraphSoftView::OnDrawNone()
- {
- // TODO: Add your command handler code here
- GetDocument()->m_nCurrentShapeType=_shape_none;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawNone(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_none?1:0);
- }
- void CGraphSoftView::OnDrawModelcurve2avb()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_ModelCurve2AvB)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_ModelCurve2AvB;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawModelcurve2avb(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_ModelCurve2AvB?1:0);
- }
- void CGraphSoftView::OnDrawModelcurve3param()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_ModelCurve3Param)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_ModelCurve3Param;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawModelcurve3param(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_ModelCurve3Param?1:0);
- }
- void CGraphSoftView::OnDrawBeziercurve()
- {
- // TODO: Add your command handler code here
- if(GetDocument()->m_nCurrentShapeType ==_shape_BezierCurve)
- GetDocument()->m_nCurrentShapeType=_shape_none;
- else
- GetDocument()->m_nCurrentShapeType=_shape_BezierCurve;
- OnOperationOver() ;
- }
- void CGraphSoftView::OnUpdateDrawBeziercurve(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_bCanSelectGraphType);
- pCmdUI->SetCheck(GetDocument()->m_nCurrentShapeType==_shape_BezierCurve?1:0);
- }
- //////////////////////////////////////////////////////
- CRect CGraphSoftView::GetSelectGraphBoundaryRect()
- {
- CRect rectRltVal(0,0,0,0);
- rectRltVal=GetDocument()->GetSelectGraphBoundaryRect();
- m_rectSelectGraph=rectRltVal;
- return rectRltVal;
- }
- ///////////////////////////////////////////////////////
- //function----RefreshSelectGraph
- //一般用于旋转和缩放选中图形后对数据的图形数据的更新
- ////////////////////////////////////////////////////
- //////////////////////////////////////////////////////
- CPoint CGraphSoftView::GetSelectGraphCenter()
- {
- CRect rect=GetSelectGraphBoundaryRect();
- //m_ptSelectGraphCenter=rect.CenterPoint();
- return m_ptSelectGraphCenter;
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::OnGraphMove()
- {
- // TODO: Add your command handler code here
- m_bDrawFlag=FALSE;
- m_graph_op=_graph_move;
- m_bGraphOp=TRUE;
- }
- void CGraphSoftView::OnGraphMagnify()
- {
- // TODO: Add your command handler code here
- m_bDrawFlag=FALSE;
- m_graph_op=_graph_magnify;
- m_bGraphOp=TRUE;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int old_rop = dc.SetROP2(R2_XORPEN);
- CRect rect;
- rect=GetSelectGraphBoundaryRect();
- m_ptSelectGraphCenter=rect.CenterPoint();
- //Redraw(&dc,&rect,TRUE,RGB(255,255,0));
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, RGB(255,255,0));
- poldPen=dc.SelectObject(&pen);
- float flLx,flRx,flTy,flBy;
- flLx=m_rectSelectGraph.left/1000.0;
- flTy=m_rectSelectGraph.top/1000.0;
- flRx=m_rectSelectGraph.right/1000.0;
- flBy=m_rectSelectGraph.bottom/1000.0;
- Lp2Dp(flLx,flTy);
- Lp2Dp(flRx,flBy);
- dc.MoveTo(flLx,flTy);
- dc.LineTo(flLx,flBy);
- dc.LineTo(flRx,flBy);
- dc.LineTo(flRx,flTy);
- dc.LineTo(flLx,flTy);
- dc.SelectObject(poldPen);
- float flxTemp,flyTemp;
- flxTemp=m_ptSelectGraphCenter.x/1000.0;
- flyTemp=m_ptSelectGraphCenter.y/1000.0;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- dc.SetROP2(old_rop);
- }
- void CGraphSoftView::OnGraphRotate()
- {
- // TODO: Add your command handler code here
- m_bDrawFlag=FALSE;
- m_graph_op=_graph_rotate;
- m_bGraphOp=TRUE;
- m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
- m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
- m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
- float flx,fly;
- flx=m_flRotCenterX;
- fly=m_flRotCenterY;
- Lp2Dp(flx,fly);
- m_bSelectRotateCenter=FALSE;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int old_rop = dc.SetROP2(R2_XORPEN);
- DrawOutRectPoint(&dc,flx,fly,RGB(0,255,0));
- TRACE("OnGraphRotate()---Logical RotateCenter(%f,%f)n",m_flRotCenterX,m_flRotCenterY);
- TRACE("OnGraphRotate()---Device RotateCenter(%f,%f)n",flx,fly);
- // dc.SetPixel(m_ptRotateCenter.x-1,m_ptRotateCenter.y-1,RGB(0,255,0));
- // dc.SetPixel(m_ptRotateCenter.x-1,m_ptRotateCenter.y+1,RGB(0,255,0));
- // dc.SetPixel(m_ptRotateCenter.x+1,m_ptRotateCenter.y-1,RGB(0,255,0));
- // dc.SetPixel(m_ptRotateCenter.x+1,m_ptRotateCenter.y+1,RGB(0,255,0));
- dc.SetROP2(old_rop);
- }
- void CGraphSoftView::OnGraphPropertiy()
- {
- // TODO: Add your command handler code here
- CGraphInfoDlg dlg(this);
- SUNDProperty *pSProperty=new SUNDProperty();
- GetDocument()->GetSelGraphPropertyArr(pSProperty->ArrPropertyPrev);
- if(dlg.DoModal()==IDOK){
- GetDocument()->GetSelGraphPropertyArr(pSProperty->ArrPropertyCur);
- for(int i=0;i<pSProperty->ArrPropertyCur.GetSize();i++){
- SUNDPropertyUnit& SPropertyUnitPrev = pSProperty->ArrPropertyPrev.GetAt(i);
- SPropertyUnitPrev.flRCX=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().x/1000.0;
- SPropertyUnitPrev.flRCY=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().y/1000.0;
- SPropertyUnitPrev.flAngle=dlg.m_nAngle*PI/180;
- pSProperty->ArrPropertyPrev.SetAt(i,SPropertyUnitPrev);
- SUNDPropertyUnit& SPropertyUnitCur = pSProperty->ArrPropertyCur.GetAt(i);
- SPropertyUnitCur.flRCX=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().x/1000.0;
- SPropertyUnitCur.flRCY=GetDocument()->GetSelectGraphBoundaryRect().CenterPoint().y/1000.0;
- SPropertyUnitCur.flAngle=-dlg.m_nAngle*PI/180;
- pSProperty->ArrPropertyCur.SetAt(i,SPropertyUnitCur);
- }
- CUND_Base* pUndo = new CUND_Property(pSProperty);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- }else{
- delete pSProperty;
- }
- }
- void CGraphSoftView::OnGraphDelete()
- {
- // TODO: Add your command handler code here
- m_bDrawFlag=FALSE;
- m_graph_op=_graph_delete;
- m_bGraphOp=TRUE;
- SUNDDelete *pStructDel=new SUNDDelete();
- GetDocument()->GetSelGraphArray(pStructDel->ArrShape);
- CUND_Base* pUndo = new CUND_Delete(pStructDel);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- CClientDC dc(this);
- OnPrepareDC(&dc);
- CRect rect=GetSelectGraphBoundaryRect();
- POSITION pos,posPrev;
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- posPrev=pos;
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- GetDocument()->m_shapeList.RemoveAt(posPrev);
- pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
- }
- }
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect,FALSE);
- }
- void CGraphSoftView::OnGraphCopy()
- {
- // TODO: Add your command handler code here
- m_bDrawFlag=FALSE;
- m_graph_op=_graph_copy;
- m_bGraphOp=TRUE;
- CGraphSoftDoc * pDoc=(CGraphSoftDoc *)GetDocument();
- CClientDC dc(this);
- OnPrepareDC(&dc);
- //CRect rect=GetSelectGraphBoundaryRect();
- POSITION pos;
- pos=pDoc->m_shapeList.GetHeadPosition();
- int nshapeCount=pDoc->m_shapeList.GetCount();
- while ((nshapeCount--)!=0) {
- CShape* pShape=pDoc->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- CShape* pShapeNew=pShape->GetCopy();
- pDoc->m_shapeList.AddTail(pShapeNew);
- pShape->SetSelectFlag(FALSE);
- }
- }
- }
- void CGraphSoftView::OnGraphEdit()
- {
- // TODO: Add your command handler code here
- m_bDrawFlag=FALSE;
- m_graph_op=_graph_edit;
- m_bGraphOp=TRUE;
- CShape* pShape=NULL;
- POSITION pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- break;
- }
- }
- if(pShape!=NULL){
- pShape->GetPtData(m_ArrDataPrevX,m_ArrDataPrevY);
- }
- }
- void CGraphSoftView::OnGraphPointshide()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- OnPrepareDC(&dc);
- GetDocument()->SetGraphDrawPtFlag(0,&dc);
- SUNDShowPoints *pStructShowPts=new SUNDShowPoints();
- GetDocument()->GetSelGraphIDArray(pStructShowPts->ArrId);
- pStructShowPts->nShowFlag=0;
- CUND_Base* pUndo = new CUND_ShowPoints(pStructShowPts);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- // m_bDrawFlag=FALSE;
- // m_bGraphOp=TRUE;
- // m_graph_op= _graph_pointsHide;
- }
- void CGraphSoftView::OnGraphPointsshow()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- OnPrepareDC(&dc);
- GetDocument()->SetGraphDrawPtFlag(1,&dc);
- SUNDShowPoints *pStructShowPts=new SUNDShowPoints();
- GetDocument()->GetSelGraphIDArray(pStructShowPts->ArrId);
- pStructShowPts->nShowFlag=1;
- CUND_Base* pUndo = new CUND_ShowPoints(pStructShowPts);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- // m_bDrawFlag=FALSE;
- // m_bGraphOp=TRUE;
- // m_graph_op= _graph_pointsShow;
- }
- void CGraphSoftView::OnGraphLefttoright()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- OnPrepareDC(&dc);
- SUNDLeftToRight *pStructLfToRt=new SUNDLeftToRight();
- GetDocument()->GetSelGraphIDArray(pStructLfToRt->ArrId);
- pStructLfToRt->rtOut=GetDocument()->GetSelectGraphBoundaryRect();
- CUND_Base* pUndo = new CUND_LeftToRight(pStructLfToRt);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- GetDocument()->GraphLeftToRight(&dc);
- // m_bDrawFlag=FALSE;
- // m_bGraphOp=TRUE;
- // m_graph_op= _graph_leftToRight;
- }
- void CGraphSoftView::OnGraphToptobottom()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- OnPrepareDC(&dc);
- SUNDLeftToRight *pStructTpToBm=new SUNDLeftToRight();
- GetDocument()->GetSelGraphIDArray(pStructTpToBm->ArrId);
- pStructTpToBm->rtOut=GetDocument()->GetSelectGraphBoundaryRect();
- CUND_Base* pUndo = new CUND_TopToBtm(pStructTpToBm);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- GetDocument()->GraphTopToBottom(&dc);
- // m_bDrawFlag=FALSE;
- // m_bGraphOp=TRUE;
- // m_graph_op= _graph_topTobottom;
- }
- /////////////////////////////////////////////////////////
- void CGraphSoftView::OnDestroy()
- {
- // TODO: Add your message handler code here
- CScrollView::OnDestroy();
- }
- BOOL CGraphSoftView::DestroyWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
- return CScrollView::DestroyWindow();
- }
- //////////////////////////////////////////////////////////
- void CGraphSoftView::OnSelectAll()
- {
- // TODO: Add your command handler code here
- POSITION pos;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- pShape->SetSelectFlag(TRUE);
- pShape->DrawCutToRect(&dc,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
- }
- }
- //////////////////////////////////////////////////////
- void CGraphSoftView::OnUpdateSelectAll(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- if(m_graph_op==_graph_noneOp&&GetDocument()->m_nCurrentShapeType==_shape_none
- && GetDocument()->m_shapeList.GetCount()!=0){
- pCmdUI->Enable(TRUE);
- }else{
- pCmdUI->Enable(FALSE);
- }
- }
- /////////////////////////////////////////////////////////////////
- void CGraphSoftView::OnOperationOver()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int old_rop = dc.SetROP2(R2_XORPEN);
- if(m_bGraphOp!=FALSE){
- float flxTemp,flyTemp;
- switch(m_graph_op){
- case _graph_copy:
- {
- dc.SetROP2(old_rop);
- CRect rect=GetSelectGraphBoundaryRect();
- POSITION pos,posPrev;
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- posPrev=pos;
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- GetDocument()->m_shapeList.RemoveAt(posPrev);
- pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
- delete pShape;
- }
- }
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect,FALSE);
- dc.SetROP2(R2_XORPEN);
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_magnify:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- flxTemp=m_ptSelectGraphCenter.x/1000.0;
- flyTemp=m_ptSelectGraphCenter.y/1000.0;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, RGB(255,255,0));
- poldPen=dc.SelectObject(&pen);
- float flLx,flRx,flTy,flBy;
- flLx=m_rectSelectGraph.left/1000.0;
- flTy=m_rectSelectGraph.top/1000.0;
- flRx=m_rectSelectGraph.right/1000.0;
- flBy=m_rectSelectGraph.bottom/1000.0;
- Lp2Dp(flLx,flTy);
- Lp2Dp(flRx,flBy);
- dc.MoveTo(flLx,flTy);
- dc.LineTo(flLx,flBy);
- dc.LineTo(flRx,flBy);
- dc.LineTo(flRx,flTy);
- dc.LineTo(flLx,flTy);
- dc.SelectObject(poldPen);
- dc.SetROP2(old_rop);
- break;
- }
- case _graph_rotate:
- {
- flxTemp=m_flRotCenterX;
- flyTemp=m_flRotCenterY;
- Lp2Dp(flxTemp,flyTemp);
- DrawOutRectPoint(&dc,flxTemp,flyTemp,RGB(0,255,0));
- // Redraw(&dc,&m_rectSelectGraph,TRUE,RGB(255,255,255));
- // CPen pen,*poldPen;
- // pen.CreatePen(PS_SOLID,1, RGB(255,255,0));
- // poldPen=pDC->SelectObject(&pen);
- // pDC->MoveTo(rect.TopLeft());
- // pDC->LineTo(rect.left,rect.bottom);
- // pDC->LineTo(rect.right,rect.bottom);
- // pDC->LineTo(rect.right,rect.top);
- // pDC->LineTo(rect.TopLeft());
- // pDC->SelectObject(poldPen);
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- break;
- }
- case _graph_edit:
- {
- CShape* pShape=NULL;
- POSITION pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- break;
- }
- }
- if(pShape!=NULL){
- SUNDEdit *pStructEdit=new SUNDEdit();
- pStructEdit->nID=pShape->GetID();
- pStructEdit->ArrDataPrevX.Copy(m_ArrDataPrevX);
- pStructEdit->ArrDataPrevY.Copy(m_ArrDataPrevY);
- pShape->GetPtData(pStructEdit->ArrDataCurX,pStructEdit->ArrDataCurY);
- CUND_Base* pUndo = new CUND_Edit(pStructEdit);
- GetDocument()->m_pCore->AddUndoItem(pUndo);
- }
- }
- default:
- // m_bGraphOp=FALSE;
- // m_graph_op=_graph_noneOp;
- break;
- }
- }
- m_bGraphOp=FALSE;
- m_graph_op=_graph_noneOp;
- dc.SetROP2(old_rop);
- CRect rect(0,0,0,0);
- //SetDrawMenuEnable(TRUE);
- GetDocument()->SelectInRect(&rect,&dc,0,TRUE);
- }
- void CGraphSoftView::OnUpdateGraphDelete(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphCopy(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphMagnify(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphMove(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphPropertiy(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphRotate(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphToptobottom(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphEdit(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->GetSelectNum()==1);
- }
- void CGraphSoftView::OnUpdateGraphLefttoright(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphPointshide(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphPointsshow(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphRotateLeft(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateGraphRotateRight(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(GetDocument()->HasGraphSelected());
- }
- void CGraphSoftView::OnUpdateOperationOver(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_graph_op!=_graph_noneOp);
- }
- void CGraphSoftView::OnUpdateSelectPenwidth(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- }
- /////////////////////////////////////////////////////////
- BOOL CGraphSoftView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- // TODO: Add your message handler code here and/or call default
- if(m_graph_op==_graph_noneOp&&GetDocument()->m_nCurrentShapeType==_shape_none) {
- if(GetDocument()->HasGraphSelected()){
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECT_ANY));
- }else{
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECT_NONE));
- }
- return true ;
- }
- switch(GetDocument()->m_nCurrentShapeType){
- case _shape_Line:
- //SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_LINE));
- //SetCursor(LoadCursorFromFile("dinosaur.ani"));
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_LINE));
- return true;
- case _shape_Parallelogram:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_PARAGLLELOGRAM));
- return true;
- case _shape_Rectangle:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_RECTANGLE));
- return true;
- case _shape_RoundRect:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_ROUNDRECT));
- return true;
- case _shape_Circle:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_CIRCLE));
- return true;
- case _shape_Ellipse:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_ELLIPSE));
- return true;
- case _shape_Polygon:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_POLYGON));
- return true;
- case _shape_ModelCurve3Param:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_MODELCURVE3PARAM));
- return true;
- case _shape_ModelCurve2AvB:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_MODELCURVE2AVB));
- return true;
- case _shape_BezierCurve:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SHAPE_BEZIERCURVE));
- return true;
- default:
- break;
- }
- switch(m_graph_op){
- case _graph_rotate:
- SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_ROTATE));
- return true;
- case _graph_move:
- SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_MOVE));
- return true;
- case _graph_magnify:
- SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_MAGNIFY));
- return true;
- case _graph_copy:
- SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_COPY));
- return true;
- case _graph_edit:
- //SetCursor(AfxGetApp()->LoadCursor(IDC_GRAPH_POINTSEL));
- //return true;
- default:
- break;
- }
- return false;
- //return CScrollView::OnSetCursor(pWnd, nHitTest, message);
- }
- void CGraphSoftView::OnGraphRotatecenterSet()
- {
- // TODO: Add your command handler code here
- m_bSelectRotateCenter=!m_bSelectRotateCenter;
- if(!m_bSelectRotateCenter){
- m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
- m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
- }
- }
- void CGraphSoftView::OnUpdateGraphRotatecenterSet(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_bSelectRotateCenter?1:0);
- }
- void CGraphSoftView::OnGraphRotateLeft()
- {
- // TODO: Add your command handler code here
- m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
- m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
- m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
- POSITION pos;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- //int old_rop = dc.SetROP2(R2_XORPEN);
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
- pShape->Rotate(&dc,m_flRotCenterX,m_flRotCenterY,-PI/2);
- pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- }
- }
- CRect rect=GetDocument()->GetSelectGraphBoundaryRect();
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect);
- GetDocument()->RefreshSelectGraph();
- rect=GetDocument()->GetSelectGraphBoundaryRect();
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect);
- //dc.SetROP2(old_rop);
- }
- void CGraphSoftView::OnGraphRotateRight()
- {
- // TODO: Add your command handler code here
- m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
- m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
- m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
- POSITION pos;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
- pShape->Rotate(&dc,m_flRotCenterX,m_flRotCenterY,PI/2);
- pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- }
- }
- CRect rect=GetDocument()->GetSelectGraphBoundaryRect();
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect);
- GetDocument()->RefreshSelectGraph();
- rect=GetDocument()->GetSelectGraphBoundaryRect();
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect);
- }
- void CGraphSoftView::OnInputConfirm()
- {
- // TODO: Add your command handler code here
- if(m_pCurrentShape!=NULL){
- CClientDC dc(this);
- OnPrepareDC(&dc);
- m_flArrayX.RemoveAll();
- m_flArrayY.RemoveAll();
- switch(GetDocument()->m_nCurrentShapeType) {
- case _shape_Polygon:
- case _shape_ModelCurve3Param:
- case _shape_ModelCurve2AvB:
- case _shape_BezierCurve:
- {
- int old_rop = dc.SetROP2(R2_XORPEN);
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- dc.SetROP2(old_rop);
- m_pCurrentShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- break;
- }
- default:
- break;
- }//switch{case:}
- }
- m_pCurrentShape=NULL;
- m_bDrawFlag=FALSE;
- ClipCursor(NULL);
- return;
- }
- void CGraphSoftView::OnShapeOver()
- {
- // TODO: Add your command handler code here
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int old_rop = dc.SetROP2(R2_XORPEN);
- CRect rect;
- if(m_flArrayX.GetSize()>0){
- if(GetDocument()->m_nCurrentShapeType==_shape_Parallelogram){
- if(m_flArrayX.GetSize()<3){
- int old_rop = dc.SetROP2(R2_XORPEN);
- //rect=GetRectFromPoint(m_ptStart,m_ptPrev);
- float x1=m_flStartX;
- float y1=m_flStartY;
- float x2=m_flPrevX;
- float y2=m_flPrevY;
- Lp2Dp(x1,y1);//转回屏幕坐标,易于画图
- Lp2Dp(x2,y2);
- DrawLine(&dc,x1,y1,x2,y2,RGB(0,255,0),m_nCurrentPenWidth+1);
- dc.SetROP2(old_rop);
- }
- }
- m_flArrayX.RemoveAll();
- m_flArrayY.RemoveAll();
- if(m_pCurrentShape!=NULL){
- rect=m_pCurrentShape->GetBoundaryRect();
- m_pCurrentShape->DrawCutToRect(&dc,RGB(0,255,0),RGB(255,0,255),m_nCurrentPenWidth+1,m_rectTarget,m_rectMaxWindow);
- GetDocument()->m_shapeList.RemoveTail();
- // delete m_pCurrentShape;//内存泄漏
- m_pCurrentShape=NULL;
- // Redraw(&dc,&rect,FALSE);
- GetDocument()->m_pCore->DelLastUndoItem();//删除撤消项,这里将删除为新图形分配的空间
- }
- }
- GetDocument()->m_nCurrentShapeType=_shape_none;
- m_bDrawFlag=FALSE;
- ClipCursor(NULL);
- dc.SetROP2(old_rop);
- return;
- }
- void CGraphSoftView::OnUpdateInputConfirm(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- }
- void CGraphSoftView::OnSelectPenwidth()
- {
- // TODO: Add your command handler code here
- }
- void CGraphSoftView::OnSelectFillColor()
- {
- // TODO: Add your command handler code here
- }
- BOOL CGraphSoftView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
- {
- // TODO: Add your specialized code here and/or call the base class
- BOOL rlt= CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
- return rlt;
- }
- void CGraphSoftView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
- {
- // TODO: Add your specialized code here and/or call the base class
- CScrollView::CalcWindowRect(lpClientRect, nAdjustType);
- }
- void CGraphSoftView::DrawCut()
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- OnEraseBkgnd(&dc) ;
- CGraphSoftDoc* pDoc=GetDocument();
- POSITION pos;
- pos=pDoc->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=pDoc->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- pShape->DrawCutToRect(&dc,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
- }else{
- pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- }
- }
- }
- BOOL CGraphSoftView::OnEraseBkgnd(CDC* pDC)
- {
- // TODO: Add your message handler code here and/or call default
- CBrush* pBrush = new CBrush ;
- // pBrush->CreateSolidBrush(RGB(0,0,0));
- CRect rect ;
- CBrush *pOldBrush = (CBrush*)pDC->SelectObject(pBrush) ;
- pDC->GetClipBox(&rect) ;
- pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY) ;
- pDC->SelectObject(pOldBrush) ;
- // pDC->SetBkColor(COLORREF(RGB(128,128,128))) ;
- // GetClientRect(rect) ;
- delete pBrush;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////
- void CGraphSoftView::Lp2Dp(CPoint* pPt)
- {
- pPt->x=((float)pPt->x)*m_rectMaxWindow.Width()/m_rectTarget.Width()+0.5;
- pPt->y=((float)pPt->y)*m_rectMaxWindow.Height()/m_rectTarget.Height()+0.5;
- }
- void CGraphSoftView::Lp2Dp(CRect* pRect)
- {
- float flRate=((float)m_rectMaxWindow.Width())/m_rectTarget.Width();
- pRect->left=((float)pRect->left-m_rectTarget.left)*flRate+0.5;
- pRect->right=((float)pRect->right-m_rectTarget.left)*flRate+0.5;
- pRect->top=((float)pRect->top-m_rectTarget.top)*flRate+0.5;
- pRect->bottom=((float)pRect->bottom-m_rectTarget.top)*flRate+0.5;
- }
- void CGraphSoftView::Dp2Lp(CPoint* pPt)
- {
- pPt->x=m_rectTarget.left+((float)pPt->x)*m_rectTarget.Width()/(float)m_rectMaxWindow.Width()+0.5;
- pPt->y=m_rectTarget.top+((float)pPt->y)*m_rectTarget.Width()/(float)m_rectMaxWindow.Width()+0.5;
- }
- void CGraphSoftView::Dp2Lp(CRect* pRect)
- {
- pRect->left=m_rectTarget.left+((float)pRect->left)*m_rectTarget.Width()/m_rectMaxWindow.Width()+0.5;
- pRect->right=m_rectTarget.left+((float)pRect->right)*m_rectTarget.Width()/m_rectMaxWindow.Width()+0.5;
- pRect->top=m_rectTarget.top+((float)pRect->top)*m_rectTarget.Height()/m_rectMaxWindow.Height()+0.5;
- pRect->bottom=m_rectTarget.top+((float)pRect->bottom)*m_rectTarget.Height()/m_rectMaxWindow.Height()+0.5;
- }
- void CGraphSoftView::Lp2Dp(float& flX,float& flY)
- {
- // CSize sz;
- // this->GetScrollBarSizes(sz);
- // float flRate=((float)m_rectMaxWindow.Width())/sz.cx;
- flX=flX*m_flRate;
- flY=flY*m_flRate;
- // float flRate=((float)m_rectMaxWindow.Width()/m_rectTarget.Width());
- // flX=(flX-m_rectTarget.left)*flRate+0.5;
- // flY=(flY-m_rectTarget.top)*flRate+0.5;
- }
- void CGraphSoftView::Dp2Lp(float& flX,float& flY)
- {
- // CSize sz;
- // this->GetScrollBarSizes(sz);
- // float flRate=((float)sz.cx)/m_rectMaxWindow.Width();
- flX=flX/m_flRate;
- flY=flY/m_flRate;
- // flX=m_rectTarget.left+flX*m_rectTarget.Width()/(float)m_rectMaxWindow.Width();
- // flY=m_rectTarget.top+flY*m_rectTarget.Width()/(float)m_rectMaxWindow.Width();
- }
- //////////////////////////////////////////////////////////////////////////////////
- void CGraphSoftView::OnSelGraphPoint(WPARAM wParam,LPARAM lParam)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int nFlag=(int)wParam;
- GetDocument()->SetGraphDrawPtFlag(nFlag,&dc);
- }
- void CGraphSoftView::OnSelGraphRotate(WPARAM wParam,LPARAM lParam)
- {
- float angle=(int)wParam;
- m_ptSelectGraphCenter=GetSelectGraphBoundaryRect().CenterPoint();
- m_flRotCenterX=m_ptSelectGraphCenter.x/1000.0;
- m_flRotCenterY=m_ptSelectGraphCenter.y/1000.0;
- POSITION pos;
- CClientDC dc(this);
- OnPrepareDC(&dc);
- //int old_rop = dc.SetROP2(R2_XORPEN);
- pos=GetDocument()->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=GetDocument()->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- pShape->DrawCutToRect(&dc,RGB(255,255,255),RGB(255,255,255),m_rectTarget,m_rectMaxWindow);
- pShape->Rotate(&dc,m_flRotCenterX,m_flRotCenterY,-angle*PI/180);
- pShape->DrawCutToRect(&dc,m_rectTarget,m_rectMaxWindow);
- }
- }
- CRect rect=GetDocument()->GetSelectGraphBoundaryRect();
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect);
- GetDocument()->RefreshSelectGraph();
- rect=GetDocument()->GetSelectGraphBoundaryRect();
- rect.left/=1000;
- rect.top/=1000;
- rect.right/=1000;
- rect.bottom/=1000;
- Redraw(&dc,&rect);
- }
- void CGraphSoftView::OnSelGraphColor(WPARAM wParam,LPARAM lParam)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- COLORREF color=(COLORREF)wParam;
- GetDocument()->SetSelGraphColor(color,&dc);
- }
- void CGraphSoftView::OnSelGraphFillClr(WPARAM wParam,LPARAM lParam)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- COLORREF color=(COLORREF)wParam;
- GetDocument()->SetSelGraphFillClr(color,&dc);
- }
- void CGraphSoftView::OnSelGraphFillSty(WPARAM wParam,LPARAM lParam)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int nStyle=(int)wParam;
- GetDocument()->SetSelGraphFillSty((SHAPE_FILLSTYLE)nStyle,&dc);
- }
- void CGraphSoftView::OnSelGraphPenWidth(WPARAM wParam,LPARAM lParam)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc);
- int nWidth=(int)wParam;
- GetDocument()->SetSelGraphPenWidth(nWidth,&dc);
- }
- //////////////////////////////////////////////////////////////////////////////////
- //End of File
- void CGraphSoftView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: Add your specialized code here and/or call the base class
- CRect rect=pInfo->m_rectDraw;//转窗口大小
- rect.DeflateRect(rect.Width()/15,rect.Height()/16);
- //画图
- CGraphSoftDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- POSITION pos;
- pos=pDoc->m_shapeList.GetHeadPosition();
- while (pos!=NULL) {
- CShape* pShape=pDoc->m_shapeList.GetNext(pos);
- if(pShape->IsSelected()){
- //pShape->DrawCutToRect(pDC,RGB(255,0,0),RGB(255,0,0),m_rectTarget,m_rectMaxWindow);
- pShape->DrawCutToRect(pDC,m_rectTarget,rect);
- }else{
- pShape->DrawCutToRect(pDC,m_rectTarget,rect);
- }
- }
- //清除四边空间
- CBrush newBrush;
- newBrush.CreateSolidBrush(RGB(255,255,255));
- CBrush *pOldBrush = (CBrush*)pDC->SelectObject(&newBrush) ;
- this->GetClientRect(&rect) ;
- rect.InflateRect(3,2);
- pDC->PatBlt(0,0,pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height(),PATCOPY) ;
- pDC->PatBlt(0,0,pInfo->m_rectDraw.Width(),pInfo->m_rectDraw.Height()/16.0,PATCOPY) ;
- pDC->PatBlt(0,15*pInfo->m_rectDraw.Height()/16.0,pInfo->m_rectDraw.Width(),pInfo->m_rectDraw.Height()/16.0,PATCOPY) ;
- pDC->PatBlt(14*pInfo->m_rectDraw.Width()/15.0,0,pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height(),PATCOPY) ;
- //画页眉底线
- CPen pen,*pOldPen;
- pen.CreatePen(PS_SOLID,pInfo->m_rectDraw.Width()/200+1,RGB(0,0,0));
- pOldPen=pDC->SelectObject(&pen);
- pDC->MoveTo(pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height()/20.0);
- pDC->LineTo(14.0*pInfo->m_rectDraw.Width()/15.0,pInfo->m_rectDraw.Height()/20);
- pDC->SelectObject(pOldPen);
- //写页眉
- CRect rectTop(0,0,pInfo->m_rectDraw.Width(),pInfo->m_rectDraw.Height()/16.0);
- CFont font;
- LOGFONT lf;
- memset(&lf, 0, sizeof(LOGFONT)); // zero out structure
- lf.lfHeight = pInfo->m_rectDraw.Height()/40;
- lf.lfWidth = pInfo->m_rectDraw.Width()/40;
- // request a 12-pixel-height font
- strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial"
- VERIFY(font.CreateFontIndirect(&lf)); // create the font
- // Do something with the font just created...
- CFont* def_font = pDC->SelectObject(&font);
- pDC->DrawText("Made by GraphSoft",&rectTop,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- pDC->SelectObject(pOldBrush) ;
- pDC->SelectObject(def_font);
- // Done with the font. Delete the font object.
- font.DeleteObject();
- newBrush.DeleteObject();
- ScrollToPosition(m_rectMaxWindow.TopLeft());
- }
- void CGraphSoftView::OnInitialUpdate()
- {
- SetScrollSizes(MM_TEXT,CSize(0,0));
- // TODO: Add your specialized code here and/or call the base class
- }
- void CGraphSoftView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: Add your specialized code here and/or call the base class
- CScrollView::OnPrepareDC(pDC, pInfo);
- }
- void CGraphSoftView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
- float left = this->GetScrollPos(SB_HORZ);
- CMainFrame* pMainFrm = (CMainFrame*) AfxGetApp()->GetMainWnd();
- float flOffsetRate = ((float)left-m_rectMaxWindow.left)/(m_flRate*m_rectMaxWindow.Width());
- float flViewMaxOffset = left-m_rectMaxWindow.left;
- float flViewTargetOffset = flViewMaxOffset*((float)m_rectTarget.Width())/m_rectMaxWindow.Width();
- float flFullViewOffset = flOffsetRate*pMainFrm->m_wndFullView.m_pBtn->m_MaxRect.Width();
- pMainFrm->m_wndFullView.m_pBtn->m_targetrect.OffsetRect(flFullViewOffset,0);
- m_rectMaxWindow.OffsetRect(flViewMaxOffset,0);
- m_rectTarget.OffsetRect(flViewTargetOffset,0);
- pMainFrm->m_wndFullView.m_pBtn->Invalidate(TRUE);
- // Invalidate(TRUE);
- CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CGraphSoftView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- // TODO: Add your message handler code here and/or call default
- float limit = this->GetScrollLimit(SB_VERT);
- float top = this->GetScrollPos(SB_VERT);
- CMainFrame* pMainFrm = (CMainFrame*) AfxGetApp()->GetMainWnd();
- float flOffsetRate = ((float)top-m_rectMaxWindow.top)/(m_flRate*m_rectMaxWindow.Height());
- float flViewMaxOffset = top-m_rectMaxWindow.top;
- float flViewTargetOffset = flViewMaxOffset*((float)m_rectTarget.Width())/m_rectMaxWindow.Width();
- float flFullViewOffset = flOffsetRate*pMainFrm->m_wndFullView.m_pBtn->m_MaxRect.Height();
- pMainFrm->m_wndFullView.m_pBtn->m_targetrect.OffsetRect(0,flFullViewOffset);
- m_rectMaxWindow.OffsetRect(0,flViewMaxOffset);
- m_rectTarget.OffsetRect(0,flViewTargetOffset);
- pMainFrm->m_wndFullView.m_pBtn->Invalidate(TRUE);
- // Invalidate(TRUE);
- CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- void CGraphSoftView::OnHelpfile()
- {
- // TODO: Add your command handler code here
- ShellExecute(NULL, "open", "GSHelpFile.chm", NULL, NULL, SW_SHOWNORMAL);
- }