DrawDoc.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:12k
源码类别:
GIS编程
开发平台:
Visual C++
- // DrawDoc.cpp : implementation of the CDrawDoc class
- //
- #include "stdafx.h"
- #include "Draw.h"
- #include "DrawDoc.h"
- #include "math.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc
- IMPLEMENT_DYNCREATE(CDrawDoc, CDocument)
- BEGIN_MESSAGE_MAP(CDrawDoc, CDocument)
- //{{AFX_MSG_MAP(CDrawDoc)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc construction/destruction
- float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
- BOOL IsRectCross(float minx,float miny,float maxx,float maxy);
- CDrawDoc::~CDrawDoc()
- {
- delete m_Index;
- delete GraphSelect;
- }
- BOOL CDrawDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- COLORREF CGraphPara::GetColor(int n)
- {
- return m_ColorList[n];
- }
- BOOL CGraphPara::GetDisplayStatue(int n)
- {
- return m_LayerList[n].b_Display;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc serialization
- void CDrawDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- CLine* CDrawDoc::AddLine(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,int id_only,float X1,float Y1,float X2,float Y2)
- {
- CLine* p_Line=new CLine(ColorPen,ColorBrush,LineWide,LineType,Layer,id_only,0,X1,Y1,X2,Y2);
- m_LineArray.Add(p_Line);
- return p_Line;
- return NULL;
- }
- CCircle* CDrawDoc::AddCircle(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,int id_only,float CircleX,float CircleY,float CircleR,BOOL bFill)
- {
- CCircle* p_Circle=new CCircle(ColorPen,ColorBrush,LineWide,LineType,Layer,id_only,0,CircleX,CircleY,CircleR,bFill);
- m_CircleArray.Add(p_Circle);
- return p_Circle;
- return NULL;
- }
- CArc* CDrawDoc::AddArc(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,int id_only,float CircleX,float CircleY,float CircleR,float Angle1,float Angle2)
- {
- CArc* p_Arc=new CArc( ColorPen, ColorBrush, LineWide, LineType, Layer, id_only,0, CircleX, CircleY, CircleR, Angle1, Angle2);
- m_ArcArray.Add(p_Arc);
- return p_Arc;
- return NULL;
- }
- CText* CDrawDoc::AddText(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,int id_only,float StartX,float StartY,float Angle1,float Angle2,float TextHeight,float TextWide,float OffWide,unsigned char TextFont,int TextLong,CString Text)
- {
- CText* p_Text=new CText(ColorPen, ColorBrush, LineWide, LineType, Layer, id_only,0, StartX, StartY, Angle1, Angle2, TextHeight, TextWide, OffWide,0,Text);
- m_TextArray.Add(p_Text);
- return p_Text;
- return NULL;
- }
- /*CTag* CDrawDoc::AddTag(short ColorPen,int Layer,float xInsert,float yInsert,float xScale,float yScale,float angle,int only_id,int idBlock)
- {
- CTag* p_Tag=new CTag( ColorPen, Layer,0, xInsert, yInsert, xScale, yScale, angle, only_id, idBlock);
- m_TagArray.Add(p_Tag);
- return p_Tag;
- }*/
- CPline* CDrawDoc::AddPLine(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,int id_only,int Numble,PointStruct *PointList)
- {
- CPline* p_Pline=new CPline( ColorPen, ColorBrush, LineWide, LineType, Layer, id_only,0, Numble,PointList);
- m_PLineArray.Add(p_Pline);
- return p_Pline;
- return NULL;
- }
- CPlineRgn* CDrawDoc::AddPLineRgn(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,int id_only,int Numble,PointStruct *PointList,BOOL bTransparent,BOOL bFill)
- {
- CPlineRgn* p_PlineRgn=new CPlineRgn( ColorPen, ColorBrush, LineWide, LineType, Layer, id_only,0, Numble,PointList, bTransparent, bFill);
- m_PLineRgnArray.Add(p_PlineRgn);
- return p_PlineRgn;
- return NULL;
- }
- CLinkNet* CDrawDoc::AddNetPoint(float x,float y,float rRadiu,short Layer,int id_only,short ColorPen)
- {
- CLinkNet* p_Net=new CLinkNet( ColorPen, x, y, rRadiu, Layer, id_only);
- m_NetArray.Add(p_Net);
- return p_Net;
- return NULL;
- }
- CDraw* CDrawDoc::GetGraph(short Lb,int index)
- {
- switch(Lb)
- {
- case 1:
- if(index<0||index>m_LineArray.GetUpperBound())
- return 0;
- return m_LineArray.GetAt(index);
- break;
- case 2:
- if(index<0||index>m_PLineArray.GetUpperBound())
- return 0;
- return m_PLineArray.GetAt(index);
- break;
- case 3:
- if(index<0||index>m_CircleArray.GetUpperBound())
- return 0;
- return m_CircleArray.GetAt(index);
- break;
- case 4:
- if(index<0||index>m_ArcArray.GetUpperBound())
- return 0;
- return m_ArcArray.GetAt(index);
- break;
- case 5:
- if(index<0||index>m_TextArray.GetUpperBound())
- return 0;
- return m_TextArray.GetAt(index);
- break;
- case 6:
- if(index<0||index>m_TagArray.GetUpperBound())
- return 0;
- return m_TagArray.GetAt(index);
- break;
- case 7:
- if(index<0||index>m_PLineRgnArray.GetUpperBound())
- return 0;
- return m_PLineRgnArray.GetAt(index);
- break;
- case 8:
- if(index<0||index>m_NetArray.GetUpperBound())
- return 0;
- return m_NetArray.GetAt(index);
- break;
- default:
- return 0;
- }
- }
- void CDrawDoc::DeleteGraph(short Lb,int index)
- {
- switch(Lb)
- {
- case 1:
- if(index<0||index>m_LineArray.GetUpperBound())
- return ;
- m_LineArray.RemoveAt(index);
- break;
- case 2:
- if(index<0||index>m_PLineArray.GetUpperBound())
- return ;
- m_PLineArray.RemoveAt(index);
- break;
- case 3:
- if(index<0||index>m_CircleArray.GetUpperBound())
- return ;
- m_CircleArray.RemoveAt(index);
- break;
- case 4:
- if(index<0||index>m_ArcArray.GetUpperBound())
- return ;
- m_ArcArray.RemoveAt(index);
- break;
- case 5:
- if(index<0||index>m_TextArray.GetUpperBound())
- return ;
- m_TextArray.RemoveAt(index);
- break;
- case 6:
- if(index<0||index>m_TagArray.GetUpperBound())
- return ;
- m_TagArray.RemoveAt(index);
- break;
- case 7:
- if(index<0||index>m_PLineRgnArray.GetUpperBound())
- return ;
- m_PLineRgnArray.RemoveAt(index);
- break;
- case 8:
- if(index<0||index>m_NetArray.GetUpperBound())
- return ;
- m_NetArray.RemoveAt(index);
- break;
- default:
- return;
- }
- }
- int CDrawDoc::GetGraphNumb(short Lb)
- {
- switch(Lb)
- {
- case 1:
- return m_LineArray.GetSize();
- break;
- case 2:
- return m_PLineArray.GetSize();
- break;
- case 3:
- return m_CircleArray.GetSize();
- break;
- case 4:
- return m_ArcArray.GetSize();
- break;
- case 5:
- return m_TextArray.GetSize();
- break;
- case 6:
- return m_TagArray.GetSize();
- break;
- case 7:
- return m_PLineRgnArray.GetSize();
- break;
- case 8:
- return m_NetArray.GetSize();
- break;
- default:
- return 0;
- }
- }
- int CDrawDoc::GetGraphUpperBound(short Lb)
- {
- switch(Lb)
- {
- case 1:
- return m_LineArray.GetUpperBound();
- break;
- case 2:
- return m_PLineArray.GetUpperBound();
- break;
- case 3:
- return m_CircleArray.GetUpperBound();
- break;
- case 4:
- return m_ArcArray.GetUpperBound();
- break;
- case 5:
- return m_TextArray.GetUpperBound();
- break;
- case 6:
- return m_TagArray.GetUpperBound();
- break;
- case 7:
- return m_PLineRgnArray.GetUpperBound();
- break;
- case 8:
- return m_NetArray.GetUpperBound();
- break;
- default:
- return -1;
- break;
- }
- return -1;
- }
- int CDrawDoc::GetGraphIndex(short Lb,int ID)
- {
- int nn=this->GetGraphUpperBound(Lb)+1;
- for(int i=0;i<nn;i++)
- {
- CDraw* pDraw=this->GetGraph(Lb,i);
- if(pDraw&&pDraw->GetID()==ID)
- {
- return i;
- }
- }
- return -1;
- }
- CLinkNet* CDrawDoc::AddNetLink(float sID,float eID)
- {
- int xh=this->GetGraphIndex(8,(int)sID);
- CLinkNet* pNet=NULL;
- if(xh>=0)
- {
- pNet=(CLinkNet*)GetGraph(8,xh);
- pNet->AddLink((int)eID);
- }
- return pNet;
- }
- BOOL CDrawDoc::GetNetXy(int netID,float *x,float *y,BOOL *bDelete)
- {
- int nn=this->GetGraphIndex(8,netID);
- if(nn<0)
- return FALSE;
- CLinkNet* pNet=(CLinkNet*)GetGraph(8,nn);
- *bDelete=pNet->b_Delete;
- *x=pNet->m_x;
- *y=pNet->m_y;
- return TRUE;
- }
- void CDrawDoc::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
- {
- for(int i=0;i<=8;i++)
- {
- int nn=GetGraphUpperBound(i)+1;
- while(nn--)
- GetGraph(i,nn)->Draw(pDC,m_DrawMode,m_DrawModel,BackColor);
- }
- //实现对被选中的图形元素的特殊绘制
- for(i=0;i<n_GraphSelect;i++)
- {
- DrawGraph(pDC,GraphSelect[i].Lb,GraphSelect[i].index,0,1,BackColor);
- }
- }
- int CDrawDoc::GetGraphID(short Lb)
- {
- int nn=GetGraphUpperBound(Lb);
- for(int i=0;i<3000;i++)
- {
- m_Index[i]=0;
- }
- for(i=0;i<=nn;i++)
- {
- if(GetGraph(Lb,i))
- m_Index[GetGraph(Lb,i)->GetID()]=1;
- }
- for(i=0;i<30000;i++)
- {
- if(m_Index[i]==0)
- return i;
- }
- return -1;
- }
- float CDrawDoc::GetAngle(float xx,float yy,float m_x,float m_y)
- {
- float i;
- i=(float)acos((m_x-xx)/sqrt((m_y-yy)*(m_y-yy)+(m_x-xx)*(m_x-xx)));
- return i;
- }
- void CArc::Init(short ColorPen,short ColorBrush,float LineWide,short LineType,short Layer,BOOL Delete,float CircleX,float CircleY,float CircleR,float Angle1,float Angle2)
- {
- m_ColorPen=ColorPen;
- m_ColorBrush=ColorBrush;
- m_LineWide=LineWide;
- m_LineType=LineType;
- m_Layer=Layer;
- m_CircleX=CircleX;
- m_CircleY=CircleY;
- m_CircleR=CircleR;
- m_Angle1=Angle1;
- m_Angle2=Angle2;
- b_Delete=Delete;
- }
- BOOL CDrawDoc::PointSelect(float x,float y,float j1,float blc,int *Lb,int* index,int* id_only)
- {
- for(int i=0;i<=8;i++)
- {
- int nn=GetGraphUpperBound(i)+1;
- while(nn--)
- {
- if(GetGraph(i,nn)->IsPoint(x,y,j1,blc))
- {
- *index=nn;
- *Lb=i;
- *id_only=GetGraph(i,nn)->GetID();
- return TRUE;
- }
- }
- }
- return FALSE;
- }
- float CalDisp(int x,int y,int m_x,int m_y)
- {
- float l;
- l=(float)(sqrt((m_x-x)*(m_x-x)+(m_y-y)*(m_y-y)));
- return l;
- }
- void CDrawDoc::AddScreen(float StartX,float StartY,float blc)
- {
- int i;
- if(m_CurrentScreen==m_MaxScreen)
- {
- for(i=1;i<m_MaxScreen-1;i++)
- m_Screen[i]=m_Screen[i+1];
- }
- else
- m_CurrentScreen++;
- //记录下当前屏幕的参数,存到结构数组对应的项中
- m_Screen[m_CurrentScreen].sx=StartX;
- m_Screen[m_CurrentScreen].sy=StartY;
- m_Screen[m_CurrentScreen].blc=blc;
- }
- BOOL CDrawDoc::GetRect(float *m_Xmin,float *m_Ymin,float *m_Xmax,float *m_Ymax)
- {
- float m_minX,m_minY,m_maxX,m_maxY;
- BOOL pb;
- *m_Xmin=(float)(1E+20);
- *m_Ymin=(float)(1E+20);
- *m_Xmax=(float)(1E-20);
- *m_Ymax=(float)(1E-20);
- pb=0;
- for(int i=0;i<=8;i++)
- {
- int nn=GetGraphUpperBound(i)+1;
- while(nn--)
- {
- if(GetGraph(i,nn))
- GetGraph(i,nn)->GetRect(&m_minX,&m_minY,&m_maxX,&m_maxY);
- else
- continue;
- pb=1;
- if(*m_Xmin>m_minX)
- *m_Xmin=m_minX;
- if(*m_Xmax<m_maxX)
- *m_Xmax=m_maxX;
- if(*m_Ymin>m_minY)
- *m_Ymin=m_minY;
- if(*m_Ymax<m_maxY)
- *m_Ymax=m_maxY;
- }
- }
- return pb;
- }
- BOOL IsRectCross(float minx,float miny,float maxx,float maxy)
- {
- if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
- return FALSE; //如两个矩形不相交
- else
- return TRUE;
- }
- BOOL CDrawDoc::AddSelectList(int Lb,int index,int id_only)
- {
- for(int i=0;i<n_GraphSelect;i++)
- {
- if(Lb==GraphSelect[i].Lb&&index==GraphSelect[i].index&&id_only==GraphSelect[i].id_only)
- return FALSE;
- }
- GraphSelect[n_GraphSelect].Lb=Lb;
- GraphSelect[n_GraphSelect].index=index;
- GraphSelect[n_GraphSelect++].id_only=id_only;
- return TRUE;
- }
- void CDrawDoc::DrawGraph(CDC* pDC,int Lb,int index,int DrawMode,int DrawModel,short BackColor)
- {
- GetGraph(Lb,index)->Draw(pDC,DrawMode,DrawModel,BackColor);
- }
- /*BOOL CDrawDoc::PointSelect(float x,float y,float j1,float blc,int *Lb,int *index,int * id_only)
- {
- for(int i=1;i<=8;i++)
- {
- int nn=GetGraphUpperBound(i)+1;
- while(nn--)
- {
- if(GetGraph(i,nn)->IsPoint(x,y,j1,blc))
- {
- *index=nn;
- *Lb=i;
- *id_only=GetGraph(i,nn)->GetID();
- return TRUE;
- }
- }
- }
- return FALSE;
- }*/
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc diagnostics
- #ifdef _DEBUG
- void CDrawDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CDrawDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc commands