LinkNet.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:3k
源码类别:
GIS编程
开发平台:
Visual C++
- // LinkNet.cpp: implementation of the CLinkNet class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Draw.h"
- #include "LinkNet.h"
- #include "math.h"
- #define pi 3.1415926
- #include "DrawDoc.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- //CLinkNet::CLinkNet()
- extern IsRectCross(float minx,float miny,float maxx,float maxy);
- CLinkNet::~CLinkNet()
- {
- }
- float CLinkNet::CalDisp(float x1,float y1,float x2,float y2)
- {
- return (float)sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
- }
- void CLinkNet::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
- {
- if(this->b_Delete)
- {
- return ;
- }
- float minx,miny,maxx,maxy;
- GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
- if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
- return;
- if(m_DrawMode==0)
- pDC->SetROP2(R2_COPYPEN);
- else if(m_DrawMode==1)
- pDC->SetROP2(R2_NOT);
- short ColorPen=m_ColorPen;
- if(m_DrawModel==2)
- ColorPen=BackColor;
- CGraphPara m_GraphPara;
- CGraphPara *p_GraphPara;
- p_GraphPara=&m_GraphPara;
- CPen pen(0,1,p_GraphPara->GetColor(ColorPen));
- CPen* pOldPen=pDC->SelectObject(&pen);
- int x1,y1,x2,y2,x3,y3;
- DPtoVP(m_x,m_y,&x1,&y1);
- int rr=DLtoVL(m_rRadiu);
- pDC->SelectStockObject(NULL_BRUSH);
- pDC->Ellipse(x1-rr,y1-rr,x1+rr,y1+rr);
- BOOL bDelete;
- float xx,yy;
- if(m_DrawModel==0)
- {
- for(int i=0;i<this->m_LinkNumb;i++)
- {
- CDrawDoc* p_Doc;
- BOOL pb=p_Doc->GetNetXy(this->m_LinkID[i],&xx,&yy,&bDelete);
- if(!pb||b_Delete)
- continue;
- float angle=p_Doc->GetAngle(xx,yy,m_x,m_y);
- DPtoVP(xx,yy,&x2,&y2);
- pDC->MoveTo(x1,y1);
- pDC->LineTo(x2,y2);
- x2=(int)(x2*0.75+x1*0.25);
- y2=(int)(y2*0.75+y1*0.25);
- pDC->MoveTo(x2,y2);
- x3=x2+(int)(10*cos(angle+pi/6));
- y3=y2-(int)(10*sin(angle+pi/6));
- pDC->LineTo(x3,y3);
- pDC->MoveTo(x2,y2);
- x3=x2+(int)(10*cos(angle-pi/6));
- y3=y2-(int)(10*sin(angle-pi/6));
- pDC->LineTo(x3,y3);
- }
- }
- pDC->SelectObject(pOldPen);
- }
- void CLinkNet::AddLink(int nID)
- {
- for(int i=0;i<m_LinkNumb;i++)
- {
- if(nID==this->m_LinkID[i])
- return;
- }
- m_LinkID[m_LinkNumb++]=nID;
- }
- void CLinkNet::GetRect(float* minX,float* minY,float* maxX,float* maxY)
- {
- *minX=m_x-m_rRadiu;
- *minY=m_y-m_rRadiu;
- *maxX=m_x+m_rRadiu;
- *maxY=m_y+m_rRadiu;
- // return TRUE;
- }
- BOOL CLinkNet::IsPoint(float x,float y,float j1,float blc)
- {
- float jl1;
- if(b_Delete)
- return FALSE;
- jl1=CalDisp(x,y,j1,blc);
- if(jl1<m_rRadiu+j1)
- return TRUE;
- return FALSE;
- }
- void CLinkNet::Move(float x_Move,float y_Move)
- {
- this->m_x+=x_Move;
- this->m_y+=y_Move;
- }
- void CLinkNet::Rotate(float baseX,float baseY,float angle)
- {
- RotatePoint(baseX,baseY,angle,&m_x,&m_y);
- }