DrawView.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:24k
源码类别:
GIS编程
开发平台:
Visual C++
- // DrawView.cpp : implementation of the CDrawView class
- //
- #include "stdafx.h"
- #include "Draw.h"
- #include "DrawDoc.h"
- #include "DrawView.h"
- #include "math.h"
- #define pi 3.1415926
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView
- //CGraphPara *p_GraphPara;
- IMPLEMENT_DYNCREATE(CDrawView, CView)
- BEGIN_MESSAGE_MAP(CDrawView, CView)
- //{{AFX_MSG_MAP(CDrawView)
- ON_WM_SIZE()
- ON_WM_MOUSEMOVE()
- ON_WM_LBUTTONDOWN()
- ON_WM_RBUTTONDOWN()
- ON_COMMAND(ID_DRAW_ARC,OnDrawArc)
- ON_COMMAND(ID_DRAW_CIRCLE,OnDrawCircle)
- ON_COMMAND(ID_DRAW_CIRCLE1,OnDrawCircle1)
- ON_COMMAND(ID_DRAW_LINE,OnDrawLine)
- ON_COMMAND(ID_DRAW_PLINE,OnDrawPline)
- ON_COMMAND(ID_DRAW_RGN,OnDrawPlineRgn)
- ON_COMMAND(ID_DRAW_TEXT,OnDrawText)
- ON_COMMAND(ID_DRAW_NET,OnDrawNet)
- ON_COMMAND(ID_DRAW_NET_LINK,OnDrawNetLink)
- ON_COMMAND(ID_GRAPH_REDRAW, OnGraphRedraw)
- ON_COMMAND(ID_GRAPH_ZOOM, OnGraphZoom)
- ON_COMMAND(ID_GRAPH_PAN, OnGraphPan)
- ON_COMMAND(ID_GRAPH_UP, OnGraphUp)
- ON_COMMAND(ID_GRAPH_FIRST, OnGraphFirst)
- ON_COMMAND(ID_GRAPH_ALL, OnGraphAll)
- ON_COMMAND(ID_SELECT_MOUSE, OnSelectMouse)
- ON_COMMAND(ID_SELECT_CLEAR, OnSelectClear)
- ON_COMMAND(ID_EDIT_MOVE, OnEditMove)
- ON_COMMAND(ID_SELECT_DELETE, OnSelectDelete)
- //}}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)
- ON_COMMAND(ID_TEXT_MESSAGE,DrawText)
- ON_COMMAND(ID_TEXT_ONOK,DrawTextOnOk)
- ON_COMMAND(ID_TEXT_ONCANCEL,DrawTextOnCancel)
- END_MESSAGE_MAP()
- CDrawView *p_View;
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView construction/destruction
- void DPtoVP(float x,float y,int *X,int *Y);
- void VPtoDP(int x,int y,float *X,float *Y);
- int DLtoVL(float l);
- float VLtoDL(int l);
- extern float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
- void DPtoVP(float x,float y,int *X,int *Y)
- {
- p_View->DPtoVP(x,y,X,Y);
- }
- void VPtoDP(int x,int y,float *X,float *Y)
- {
- p_View->VPtoDP(x,y,X,Y);
- }
- int DLtoVL(float l)
- {
- return p_View->DLtoVL(l);
- }
- float VLtoDL(int l)
- {
- return p_View->VLtoDL(l);
- }
- CDrawView::CDrawView()
- {
- // TODO: add construction code here
- m_xStart=0.0;
- m_yStart=0.0;
- blc=1.0;
- m_pColor=1;//设置笔色
- m_bColor=0;//当前底色的序号
- m_brColor=1;//设置填充色
- m_LineWide=1.0;//设置线宽
- m_LineType=0;//设置线型
- m_Layer=1;//选择当前图层
- PointXyz=new PointStruct[10000];
- pTextDlg=NULL;
- //以下设置初始字体大小
- m_FontHeight=20;
- m_FontWide=10;
- m_TextAngle=0;
- m_FontAngle=0;
- m_FontBetween=1;
- m_TextString.Empty();
- m_Text1=new CText();//创建一个标注文本对象
- }
- CDrawView::~CDrawView()
- {
- delete PointXyz;
- delete m_Text1;
- }
- BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView drawing
- void CDrawView::VPtoDP(int x,int y,float *X,float *Y)
- {
- *X=m_xStart+x*blc;
- if(m_MapMode==1)
- *Y=m_yStart+blc*(m_hScreen-y);
- else
- *Y=m_yStart+blc*(y+m_hScreen);
- }
- void CDrawView::DPtoVP(float x,float y,int *X,int *Y)
- {
- *X=(int)((x-m_xStart)/blc);
- if(m_MapMode==1)
- *Y=m_hScreen-(int)((y-m_yStart)/blc);
- else
- *Y=(int)((y-m_yStart)/blc)-m_hScreen;
- }
- float CDrawView::VLtoDL(int l)
- {
- return blc*l;
- }
- int CDrawView::DLtoVL(float l)
- {
- return (int)(l/blc);
- }
- void CDrawView::OnSize(UINT nType,int cx,int cy)
- {
- m_wScreen=cx;
- m_hScreen=cy;
- CView::OnSize(nType,cx,cy);
- }
- void CDrawView::DrawBack(CDC* pDC)
- {
- CGraphPara m_GraphPara;
- CGraphPara *p_GraphPara;
- p_GraphPara=&m_GraphPara;
- CBrush brush(p_GraphPara->GetColor(m_bColor));
- CBrush* pOldBrush=pDC->SelectObject(&brush);
- pDC->PatBlt(0,0,m_wScreen,m_hScreen,PATCOPY);
- pDC->SelectObject(pOldBrush);
- }
- void CDrawView::OnDraw(CDC* pDC)
- {
- CDrawDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- xMinScreen=m_xStart;
- yMinScreen=m_yStart;
- xMaxScreen=xMinScreen+blc*m_wScreen;
- yMaxScreen=yMinScreen+blc*m_hScreen;
- DrawBack(pDC);
- int a=m_bColor;
- pDoc->Draw(pDC,0,0,m_bColor);
- m_MapMode=pDC->SetMapMode(1);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView printing
- BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView diagnostics
- #ifdef _DEBUG
- void CDrawView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CDrawView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CDrawDoc* CDrawView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc)));
- return (CDrawDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView message handlers
- extern CGraphPara *p_GraphPara;
- void CDrawView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- // TODO: Add your specialized code here and/or call the base class
- p_View=this;
- CDrawDoc* pDoc=(CDrawDoc*)GetDocument();
- p_Screen=pDoc->m_Screen;
- CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- }
- void CDrawView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
- {
- // TODO: Add your specialized code here and/or call the base class
- CPaintDC dc(this);
- OnPrepareDC(&dc);
- OnDraw(&dc);
- CView::OnPrint(pDC, pInfo);
- }
- void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDrawDoc* pDoc=GetDocument();
- CClientDC ddd(this);
- CPen pen(0,0,RGB(0,0,0));
- CPen* pOldPen=ddd.SelectObject(&pen);//在绘图对象中选择CPen对象
- ddd.SetROP2(R2_NOT);
- BOOL pb;
- int x1,y1;
- CArc m_Arc1;
- if(m_DrawCurrent==1&&PushNumb==1)//直线
- {
- if(mPointOld!=point)
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(mPointOld);
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(point);
- mPointOld=point;
- }
- }
- else if((m_DrawCurrent==2||m_DrawCurrent==3)&&PushNumb>=1)
- {
- if(mPointOld!=point)
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(mPointOld);
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(point);
- mPointOld=point;
- }
- }
- else if((m_DrawCurrent==4||m_DrawCurrent==5)&&PushNumb>=1)
- //如果正在绘制圆或填充圆,并且已经按下圆心点
- {
- if(mPointOld!=point)
- {
- if(m_DrawCurrent==4)
- {
- ddd.SelectStockObject(NULL_BRUSH);
- }
- r=(int)sqrt(pow((float)(mPointOrign.x-mPointOld.x),2)+pow((float)(mPointOrign.y-mPointOld.y),2));
- ddd.Ellipse(mPointOrign.x-r,mPointOrign.y-r,mPointOrign.x+r,mPointOrign.y+r);
- r=(int)sqrt(pow((long)(mPointOrign.x-point.x),2)+pow((float)(mPointOrign.y-point.y),2));
- ddd.Ellipse(mPointOrign.x-r,mPointOrign.y-r,mPointOrign.x+r,mPointOrign.y+r);
- mPointOld=point;
- }
- //Invalidate();
- }
- else if(m_DrawCurrent==6)//圆弧
- {
- if(PushNumb==2&&mPointOld!=point)
- {
- if(DrawArcYes)
- m_Arc1.Draw(&ddd,1,0,m_bColor);
- pb=jsarc(mPointOrign1,mPointOrign,point,&m_CircleX,&m_CircleY,&m_CircleR,&m_Angle1,&m_Angle2);
- if(pb)
- {
- m_Arc1.Init(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,0,m_CircleX,m_CircleY,m_CircleR,m_Angle1,m_Angle2);
- m_Arc1.Draw(&ddd,1,0,m_bColor);
- }
- DrawArcYes=pb;
- mPointOld=point;
- }
- // Invalidate();
- }
- else if(m_DrawCurrent==10&&PushNumb==1)
- {
- if(mPointOld!=point)
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(mPointOld);
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(point);
- mPointOld=point;
- }
- }
- else if((m_DrawCurrent==11||m_DrawCurrent==12)&&PushNumb==1)
- {
- if(point!=mPointOld)
- {
- if(m_DrawCurrent==11)//放大
- {
- ddd.SelectStockObject(NULL_BRUSH); //设置不填充状态
- ddd.Rectangle(mPointOrign.x,mPointOrign.y,mPointOld.x,mPointOld.y);
- ddd.Rectangle(mPointOrign.x,mPointOrign.y,point.x,point.y);
- }
- else
- {
- ddd.MoveTo(mPointOrign);ddd.LineTo(mPointOld);
- ddd.MoveTo(mPointOrign);ddd.LineTo(point); //画新的橡皮线
- }
- mPointOld=point;
- }
- }
- else if(m_DrawCurrent==19)
- {
- if(point!=mPointOld&&PushNumb>0)
- {
- x1=VLtoDL(point.x-mPointOld.x);
- y1=-VLtoDL(point.y-mPointOld.y);
- x_Move+=x1;
- y_Move+=y1;
- for(int i=0;i<pDoc->n_GraphSelect;i++)
- pDoc->DrawGraph(&ddd,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index,1,1,0);
- for( i=0;i<pDoc->n_GraphSelect;i++)
- {
- CDraw* pDraw=pDoc->GetGraph(pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index);
- pDraw->Move(x1,y1);
- pDraw->Draw(&ddd,1,1,0);
- }
- }
- mPointOld=point;
- }
- CView::OnMouseMove(nFlags, point);
- }
- void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDrawDoc* pDoc=GetDocument();
- CClientDC ht(this);
- float r;
- float xx1,yy1,xx2,yy2;
- int x1,x2,y1,y2,Lb,index,pbh,id_only;
- float BackColor;
- BOOL m_bFill;
- int id;
- int m_sNetID;
- //画直线
- if(m_DrawCurrent==1)
- {
- if(PushNumb==0)
- {
- PushNumb++;
- mPointOrign=point;
- mPointOld=point;
- SetCapture();
- }
- else if(PushNumb==1)
- {
- VPtoDP(mPointOrign.x,mPointOrign.y,&xx1,&yy1);
- VPtoDP(point.x,point.y,&xx2,&yy2);
- id_only=pDoc->GetGraphID(1);
- int b=m_pColor;
- CLine* pLine=pDoc->AddLine(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,xx1,yy1,xx2,yy2);
- pLine->Draw(&ht,0,0,m_bColor);
- PushNumb=0;
- ReleaseCapture();
- }
- }
- //连续直线或者多边形区域
- else if(m_DrawCurrent==2||m_DrawCurrent==3)
- {
- PointXyz[PushNumb].x=m_xStart+blc*point.x;
- PointXyz[PushNumb].y=m_yStart+blc*(m_hScreen-point.y);
- if(PushNumb==0)
- {
- SetCapture();
- mPointOrign=point;
- mPointOld=point;
- }
- else
- {
- mPointOrign=mPointOld;
- mPointOld=point;
- }
- PushNumb++;//记录按下鼠标左键的次数
- }
- else if(m_DrawCurrent==4||m_DrawCurrent==5)//圆或者填充圆
- {
- if(PushNumb==0)
- {
- mPointOrign=point;
- mPointOld=point;
- PushNumb++;
- SetCapture();
- }
- else
- {
- r=(float)sqrt(pow((float)(mPointOrign.x-mPointOld.x),2)+pow((float)(mPointOrign.y-mPointOld.y),2));
- VPtoDP(mPointOrign.x,mPointOrign.y,&xx1,&yy1);
- if(m_DrawCurrent==4)
- m_bFill=0;
- else
- m_bFill=1;
- id_only=pDoc->GetGraphID(3);
- int a=m_pColor;
- pDoc->AddCircle(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,xx1,yy1,r,m_bFill)->Draw(&ht,0,0,m_bColor);
- PushNumb=0;
- ReleaseCapture();
- }
- }
- else if(m_DrawCurrent==6)//圆弧
- {
- if(PushNumb==0)
- {
- SetCapture();
- DrawArcYes=0;
- mPointOrign1=point;
- PushNumb++;
- }
- else if(PushNumb==1)
- {
- mPointOrign=point;
- PushNumb++;
- }
- else
- {
- jsarc(mPointOrign1,mPointOrign,point,&m_CircleX,&m_CircleY,&m_CircleR,&m_Angle1,&m_Angle2);
- id_only=pDoc->GetGraphID(4);
- pDoc->AddArc(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,m_CircleX,m_CircleY,m_CircleR,m_Angle1,m_Angle2)->Draw(&ht,0,0,m_bColor);
- PushNumb=0;
- ReleaseCapture();
- Invalidate();
- }
- }
- else if(m_DrawCurrent==7)//标注文本的交互绘制
- {
- VPtoDP(point.x,point.y,&m_TextX,&m_TextY);
- if(!pTextDlg)
- {
- pTextDlg=new TextWriteDlg(this,m_TextString);
- ASSERT(pTextDlg);
- }
- if(!(pTextDlg->IsOpen()))
- pTextDlg->Create(IDD_WRITE_TEXT,this);
- if(!(pTextDlg->IsVisible()))
- pTextDlg->ShowWindow(SW_SHOW);
- }
- else if(m_DrawCurrent==8)
- {
- VPtoDP(point.x,point.y,&xx1,&yy1);
- id=pDoc->GetGraphID(8);
- pDoc->AddNetPoint(xx1,yy1,3,m_Layer,id,m_pColor)->Draw(&ht,0,0,1);
- PushNumb=0;
- ReleaseCapture();
- }
- else if(m_DrawCurrent==9)
- {
- VPtoDP(point.x,point.y,&xx1,&yy1);
- int nn1=pDoc->PointSelect(8,xx1,yy1,blc,&Lb,&index,&pbh);
- if(nn1>0)
- {
- if(PushNumb==0)
- {
- PushNumb++;
- m_sNetID=pbh;
- mPointOrign=point;
- mPointOld=point;
- SetCapture();
- }
- else if(PushNumb==1)
- {
- ht.MoveTo(mPointOrign);
- ht.LineTo(point);
- pDoc->AddNetLink(m_sNetID,pbh)->Draw(&ht,0,0,m_bColor);
- PushNumb=0;
- ReleaseCapture();
- }
- }
- }
- else if(m_DrawCurrent==11||m_DrawCurrent==12)
- {
- if(PushNumb==0)
- {
- mPointOrign=point; //原点等于按中点
- mPointOld=point;
- PushNumb++;
- SetCapture();
- }
- else if(PushNumb==1)
- {
- if(m_DrawCurrent==11)//图形放大
- {
- x1=min(mPointOrign.x,point.x);
- y1=max(mPointOrign.y,point.y);
- x2=max(mPointOrign.x,point.x);
- y2=min(mPointOrign.y,point.y);
- VPtoDP(x1,y1,&m_xStart,&m_yStart);//得到视图屏幕原点实际坐标
- //改变原点的坐标
- m_xStart=m_xStart+blc*x1;
- m_yStart=m_yStart+blc*(m_hScreen-y1);
- //改变比例
- float b11=(float)m_wScreen/(float)(x2-x1);
- float b12=(float)m_hScreen/(float)(y1-y2);
- // float b11=(float)(x2-x1)/(float)m_wScreen;
- // float b12=(float)(y2-y1)/(float)m_hScreen;
- if(b12<b11)
- b11=b12;
- blc=blc/b11;
- }
- else
- {
- m_xStart=m_xStart-blc*(point.x-mPointOrign.x);
- m_yStart=m_yStart+blc*(point.y-mPointOrign.y);
- }
- PushNumb=0;//完成操作,左键按下数置0
- m_DrawCurrent=0;//完成一次后不继续运行此功能
- pDoc->AddScreen(m_xStart,m_yStart,blc);
- ReleaseCapture();
- Invalidate();
- }
- }
- else if(m_DrawCurrent==19)
- {
- if(PushNumb=0)
- {
- x_Move=0;
- y_Move=0;
- mPointOrign=point;
- mPointOld=point;
- PushNumb++;
- SetCapture();
- }
- else if(PushNumb==1)
- {
- PushNumb=0;
- ReleaseCapture();
- m_DrawCurrent=0;
- Invalidate();
- }
- }
- else if(m_DrawCurrent==30)//实现点选图形元素的功能
- {
- if(pDoc->n_GraphSelect==10000)
- {
- AfxMessageBox("最多只能选择10000个图形元素");
- return ;
- }
- VPtoDP(point.x,point.y,&xx1,&yy1);
- float j1=blc*4;
- BOOL pb=pDoc->PointSelect(xx1,yy1,j1,blc,&Lb,&index,&id_only);
- if(pb)
- {
- BOOL pb1=pDoc->AddSelectList(Lb,index,id_only);
- if(pb1)
- pDoc->DrawGraph(&ht,Lb,index,0,1,BackColor);
- // pDoc->DrawGraph(&ht,Lb,index,0,1);
- }
- }
- // CView::OnLButtonDown(nFlags, point);
- }
- void CDrawView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDrawDoc* pDoc=GetDocument();
- CClientDC ddd(this);
- CPen pen(0,0,RGB(0,0,0));
- CPen* pOldPen=ddd.SelectObject(&pen);
- ddd.SetROP2(R2_NOT);
- int id_only;
- CArc m_Arc1;
- if(m_DrawCurrent==1&&PushNumb==1)
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(mPointOld);
- PushNumb=0;
- ReleaseCapture();
- }
- else if((m_DrawCurrent==2||m_DrawCurrent==3)&&PushNumb>0)
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(mPointOld);
- if(m_DrawCurrent==2&&PushNumb>1)
- {
- id_only=pDoc->GetGraphID(2);
- pDoc->AddPLine(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,PushNumb,PointXyz)->Draw(&ddd,0,0,m_bColor);
- ReleaseCapture();
- }
- else if(m_DrawCurrent==3&&PushNumb>2)
- {
- id_only=pDoc->GetGraphID(2);
- pDoc->AddPLineRgn(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,PushNumb,PointXyz,0,1)->Draw(&ddd,0,0,m_bColor);
- ReleaseCapture();
- }
- PushNumb=0;
- ReleaseCapture();
- }
- else if((m_DrawCurrent==4||m_DrawCurrent==5)&&PushNumb>0)
- {
- if(m_DrawCurrent==4)
- ddd.SelectStockObject(NULL_BRUSH);
- r=(int)sqrt(pow((float)(mPointOrign.x-mPointOld.x),2)+pow((float)(mPointOrign.y-mPointOld.y),2));
- ddd.Ellipse(mPointOrign.x-r,mPointOrign.y-r,mPointOrign.x+r,mPointOrign.y+r);
- ReleaseCapture();
- PushNumb=0;
- }
- else if(m_DrawCurrent==6&&PushNumb>0)
- {
- if(PushNumb==2)
- m_Arc1.Draw(&ddd,1,0,m_bColor);
- PushNumb=0;
- ReleaseCapture();
- }
- else if(m_DrawCurrent==9&&PushNumb==1)
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(mPointOld);
- PushNumb=0;
- ReleaseCapture();
- }
- else if((m_DrawCurrent==11||m_DrawCurrent==12)&&PushNumb==1)
- {
- ddd.SelectStockObject(NULL_BRUSH);
- if(m_DrawCurrent==11)
- ddd.Rectangle(mPointOrign.x,mPointOrign.y,point.x,point.y);
- else
- {
- ddd.MoveTo(mPointOrign);
- ddd.LineTo(point);
- }
- ReleaseCapture();
- PushNumb=0;
- }
- else if(m_DrawCurrent==19&&PushNumb>0)
- {
- for(int i=0;i<pDoc->n_GraphSelect;i++)
- pDoc->DrawGraph(&ddd,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index,1,1,0);
- for(i=0;i<pDoc->n_GraphSelect;i++)
- pDoc->GetGraph(pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index)->Move(-x_Move,-y_Move);
- ReleaseCapture();
- PushNumb=0;
- // m_bPopup=1;
- Invalidate();
- }
- ddd.SelectObject(pOldPen);//恢复原来的画笔
- CView::OnRButtonDown(nFlags, point);
- }
- void CDrawView::OnDrawLine()
- {
- PushNumb=0;
- m_DrawCurrent=1;
- }
- void CDrawView::OnDrawCircle()
- {
- PushNumb=0;
- m_DrawCurrent=4;
- }
- void CDrawView::OnDrawCircle1()
- {
- PushNumb=0;
- m_DrawCurrent=5;
- }
- void CDrawView::OnDrawArc()
- {
- PushNumb=0;
- m_DrawCurrent=6;
- }
- void CDrawView::OnDrawText()
- {
- PushNumb=0;
- m_DrawCurrent=7;
- }
- void CDrawView::OnDrawPline()
- {
- PushNumb=0;
- m_DrawCurrent=2;
- }
- void CDrawView::OnDrawPlineRgn()
- {
- PushNumb=0;
- m_DrawCurrent=3;
- }
- void CDrawView::OnDrawNet()
- {
- PushNumb=0;
- m_DrawCurrent=8;
- }
- void CDrawView::OnDrawNetLink()
- {
- PushNumb=0;
- m_DrawCurrent=9;
- }
- BOOL CDrawView::jsarc(CPoint p1,CPoint p2,CPoint p3,float *CircleX,float *CircleY,float *CircleR,float *Angle1,float *Angle2)
- {
- float an1,an2,an3,k1,k2;
- float x1,y1,x2,y2,x3,y3,xx1,xx2,yy1,yy2,xx,yy,rr;
- x1=(float)p1.x;y1=(float)p1.y;x2=(float)p2.x;//将三个点的变量赋值给浮点变量
- y2=(float)p2.y;x3=(float)p3.x;y3=(float)p3.y;
- if(x1==x2&&y1==y2||x1==x3&&y1==y3||x2==x3&&y2==y3)//如果有两个点的坐标相同
- return FALSE; //操作不成功,返回FALSE
- xx1=(x1+x2)/2;yy1=(y1+y2)/2;
- xx2=(x2+x3)/2;yy2=(y2+y3)/2;
- if(fabs(y2-y1)>0.5) //如果第一条直线段的垂线不是竖直线
- k1=-(x2-x1)/(y2-y1);
- if(fabs(y3-y2)>0.5)
- k2=-(x3-x2)/(y3-y2);
- if(k1==k2&&k1==0.0)
- return 0;
- if(fabs(y2-y1)<0.5)
- {
- xx=xx1;
- if(fabs(y3-y2)<0.5)
- {
- yy=y2+10000;
- rr=10000;
- }
- else
- {
- yy=yy2+k2*(xx2-xx);
- rr=yy-y2;
- if(rr<0)
- rr=-rr;
- }
- }
- else if(fabs(y2-y3)<0.5)
- {
- yy=yy1+k1*(xx1-xx);
- rr=yy-y2;
- if(rr<0)
- rr=-rr;
- }
- else
- {
- if(k1==k2)
- {
- xx=x2+(float)(10000/sqrt(1+k1*k1));
- yy=y2+(float)(10000/sqrt((1+k1*k1)/(k1*k1)));
- rr=10000;
- }
- else
- {
- xx=(yy2-yy1+k1*xx1-k2*xx2)/(k1-k2);
- yy=yy1+k1*(xx-xx1);
- rr=(float)sqrt((xx-x1)*(xx-x1)+(yy-y1)*(yy-y1));
- }
- }
- *CircleX=m_xStart+blc*xx;
- *CircleY=m_yStart+blc*(m_hScreen-yy)*blc;
- *CircleR=blc*rr;
- an1=(float)acos((x1-xx)/rr);
- if(y1-yy>0)
- an1=(float)(pi*2-an1);
- an2=(float)acos((x2-xx)/rr);
- if(y2-yy>0)
- an2=(float)(pi*2-an2);
- an3=(float)acos((x3-xx)/rr);
- if(y3-yy>0)
- an3=(float)(pi*2-an3);
- if(an2>an1&&an2<an1+pi||an2<an1&&an2+pi<an1)
- {
- *Angle1=an1;
- *Angle2=an3;
- }
- else
- {
- *Angle1=an3;
- *Angle2=an1;
- }
- return TRUE;
- }
- void CDrawView::DrawText()
- {
- CClientDC ht(this);
- m_TextString=pTextDlg->m_Text; //从标注文本对话框中得到标注文本内容
- m_Text1->Init(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,m_TextX,m_TextY,m_TextAngle,m_FontAngle,m_FontHeight,m_FontWide,m_FontBetween,0,m_TextString);
- m_Text1->Draw(&ht,0,0,m_bColor);//绘制标准文本
- }
- void CDrawView::DrawTextOnOk()
- {
- CDrawDoc* pDoc=GetDocument();
- CClientDC ht(this);
- int TextLong;
- PushNumb=0;
- m_TextString=pTextDlg->m_Text;
- TextLong=m_TextString.GetLength();
- if(TextLong>0)
- {
- int id_only=pDoc->GetGraphID(5);
- pDoc->AddText(m_pColor,m_brColor,m_LineWide,m_LineType,m_Layer,id_only,
- m_TextX,m_TextY,m_TextAngle,m_FontAngle,m_FontHeight,m_FontWide,
- m_FontBetween,0,TextLong,m_TextString)->Draw(&ht,0,0,m_bColor);
- pTextDlg->m_Text.Empty(); //晴空字符串内容
- pTextDlg->SendMessage(WM_INITDIALOG);
- }
- }
- void CDrawView::DrawTextOnCancel()
- {
- pTextDlg->m_Text.Empty();//晴空标注文本对话框中编辑框内的内容
- pTextDlg->SendMessage(WM_INITDIALOG);
- }
- void CDrawView::OnGraphRedraw()
- {
- // TODO: Add your command handler code here
- CDrawDoc* pDoc=GetDocument();
- pDoc->UpdateAllViews(this);//使文档对象的所有视图重画
- Invalidate();
- }
- void CDrawView::OnGraphZoom()
- {
- // TODO: Add your command handler code here
- m_DrawCurrent=11;//标识进行图形放大操作
- PushNumb=0;
- }
- void CDrawView::OnGraphPan()
- {
- // TODO: Add your command handler code here
- m_DrawCurrent=12;//标识进行图形摆动操作
- PushNumb=0;
- }
- void CDrawView::OnGraphUp()
- {
- // TODO: Add your command handler code here
- CDrawDoc* pDoc=(CDrawDoc*)GetDocument();
- if(pDoc->m_CurrentScreen>0)
- pDoc->m_CurrentScreen--;
- m_xStart=p_Screen[pDoc->m_CurrentScreen].sx;
- m_yStart=p_Screen[pDoc->m_CurrentScreen].sy;
- blc=p_Screen[pDoc->m_CurrentScreen].blc;
- Invalidate(); //重画图形
- }
- void CDrawView::OnGraphFirst() //重画首屏
- {
- // TODO: Add your command handler code here
- CDrawDoc* pDoc=GetDocument();
- if(pDoc->m_CurrentScreen==0)
- return ;
- m_xStart=p_Screen[0].sx;
- m_yStart=p_Screen[0].sy;
- blc=p_Screen[0].blc;
- pDoc->AddScreen(m_xStart,m_yStart,blc);
- Invalidate();
- }
- //实现显示全屏功能
- void CDrawView::OnGraphAll()
- {
- // TODO: Add your command handler code here
- float minx,miny,maxx,maxy,bl1;
- CDrawDoc* pDoc=GetDocument();
- SetCapture();
- SetCursor(LoadCursor(NULL,IDC_WAIT));
- BOOL pb=pDoc->GetRect(&minx,&miny,&maxx,&maxy);
- SetCursor(LoadCursor(NULL,IDC_ARROW));
- ReleaseCapture();
- if(!pb)
- return ;
- bl1=(maxx-minx)/(m_wScreen-20);
- blc=(maxy-miny)/(m_hScreen-20);
- if(bl1>blc)
- blc=bl1;
- m_xStart=minx-10*blc;
- m_yStart=miny-10*blc;
- p_Screen[0].sx=m_xStart;
- p_Screen[0].sy=m_yStart;
- p_Screen[0].blc=blc;
- pDoc->m_CurrentScreen=0;
- Invalidate();
- }
- void CDrawView::OnSelectMouse()
- {
- // TODO: Add your command handler code here
- m_DrawCurrent=30; //标识进行图形元素点选操作
- PushNumb=0;
- }
- void CDrawView::OnSelectClear()
- {
- // TODO: Add your command handler code here
- CDrawDoc* pDoc=GetDocument();
- CClientDC ht(this);
- for(int i=0;i<pDoc->n_GraphSelect;i++)
- pDoc->DrawGraph(&ht,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index,0,0,0);
- pDoc->n_GraphSelect=0;
- }
- void CDrawView::OnEditMove()
- {
- // TODO: Add your command handler code here
- CDrawDoc* pDoc=GetDocument();
- m_DrawCurrent=19;
- PushNumb=0;
- }
- void CDrawView::Delete(CDC* pDC,int Lb,int index)
- {
- float x1,y1,x2,y2;
- CDrawDoc* pDoc=GetDocument();
- CDraw* pDraw;
- pDraw=pDoc->GetGraph(Lb,index);
- pDraw->Delete(1);
- if(Lb==1)
- pDraw->Draw(pDC,0,2,m_bColor);
- else if(Lb==2)
- pDraw->Draw(pDC,0,2,m_bColor);
- else if(Lb==3)
- {
- if(!pDraw->IsFill())
- pDraw->Draw(pDC,0,2,m_bColor);
- else
- {
- pDraw->GetRect(&x1,&y1,&x2,&y2);
- ReDrawRect(x1,y1,x2,y2);
- }
- }
- else if(Lb==4)
- pDraw->Draw(pDC,0,2,m_bColor);
- else if(Lb==5)
- {
- pDraw->GetRect(&x1,&y1,&x2,&y2);
- ReDrawRect(x1,y1,x2,y2);
- }
- else if(Lb==6)
- {
- pDraw->GetRect(&x1,&y1,&x2,&y2);
- ReDrawRect(x1,y1,x2,y2);
- }
- else if(Lb==7)
- {
- pDraw->GetRect(&x1,&y1,&x2,&y2);
- ReDrawRect(x1,y1,x2,y2);
- }
- else if(Lb==8)
- pDraw->Draw(pDC,0,2,m_bColor);
- }
- void CDrawView::ReDrawRect(float X1,float Y1,float X2,float Y2)
- {
- float xx1,xx2,yy1,yy2;
- CRect r1;
- //以下是视图屏幕矩形区域的实际坐标
- xx1=xMinScreen;
- xx2=xMaxScreen;
- yy1=yMinScreen;
- yy2=yMaxScreen;
- //得到需要绘制区域与视图屏幕区域相交的边界矩形
- BOOL IsCross=RectCross(&xx1,&yy1,&xx2,&yy2,X1,Y1,X2,Y2);
- if(IsCross)
- {
- r1.left=(int)((xx1-m_xStart)/blc)-1;
- r1.right=(int)((xx2-m_xStart)/blc)+1;
- r1.top=m_hScreen-(int)((yy2-m_yStart)/blc)-1;
- r1.bottom=m_hScreen-(int)((yy1-m_yStart)/blc)+1;
- InvalidateRect(r1);
- }
- }
- BOOL CDrawView::RectCross(float* x1,float* y1,float* x2,float* y2,float xx1,float yy1,float xx2,float yy2)
- {
- float m_X1,m_Y1,m_X2,m_Y2;
- m_X1=*x1;m_Y1=*y1;m_X2=*x2;m_Y2=*y2;
- if(m_X1>xx2||m_X2<xx1||m_Y1>yy2||m_Y2<yy1)
- return FALSE;
- else
- {
- *x1=max(m_X1,xx1);
- *y1=max(m_Y1,yy1);
- *x2=min(m_X2,xx2);
- *y2=min(m_X2,yy2);
- return TRUE;
- }
- }
- void CDrawView::OnSelectDelete()
- {
- // TODO: Add your command handler code here
- CDrawDoc* pDoc=GetDocument();
- CClientDC ht(this);
- for(int i=0;i<pDoc->n_GraphSelect;i++)
- {
- Delete(&ht,pDoc->GraphSelect[i].Lb,pDoc->GraphSelect[i].index);
- ReleaseCapture();
- pDoc->n_GraphSelect=0;
- }
- }