Pline.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:3k
源码类别:
GIS编程
开发平台:
Visual C++
- // Pline.cpp: implementation of the CPline class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Draw.h"
- #include "Pline.h"
- #include "DrawDoc.h"
- #include "math.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- extern IsRectCross(float minx,float miny,float maxx,float maxy);
- CPline::CPline();
- void CPline::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
- {
- int x1,y1;
- if(b_Delete)
- {
- return ;
- }
- float minx,miny,maxx,maxy;
- GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
- if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
- return;
- short LineType=m_LineType;
- short LineWide=max(1,DLtoVL(m_LineWide));
- short ColorPen=m_ColorPen;
- if(m_DrawModel==1)
- {
- if(m_LineType!=2)
- LineType=2;
- else
- LineType++;
- }
- else if(m_DrawModel==2)
- ColorPen=BackColor;
- CGraphPara m_GraphPara;
- CGraphPara *p_GraphPara;
- p_GraphPara=&m_GraphPara;
- CPen pen(LineType,LineWide,p_GraphPara->GetColor(ColorPen));
- CPen* pOldPen=pDC->SelectObject(&pen);
- if(m_DrawMode==0)
- pDC->SetROP2(R2_COPYPEN);
- else if(m_DrawMode==1)
- pDC->SetROP2(R2_NOT);
- POINT* ppoint=new POINT[m_Numble+1];
- for(int i=0;i<m_Numble;i++)
- {
- DPtoVP(m_PointList[i].x,m_PointList[i].y,&x1,&y1);
- if(i==0)
- pDC->MoveTo(x1,y1);
- else
- pDC->LineTo(x1,y1);
- }
- pDC->SelectObject(pOldPen);
- }
- void CPline::CalLong()
- {
- m_fLength=0;
- for(int i=0;i<this->m_Numble-1;i++)
- {
- m_fLength+=sqrt((m_PointList[i].x-m_PointList[i+1].x)*(m_PointList[i].x-m_PointList[i+1].x)+
- (m_PointList[i].y-m_PointList[i+1].y)*(m_PointList[i].y-m_PointList[i+1].y));
- }
- }
- void CPline::GetRect(float* minX,float* minY,float* maxX,float* maxY)
- {
- float x1,y1,x2,y2;
- //用第一个顶点的坐标初始化变量
- x1=m_PointList[0].x;
- x2=m_PointList[0].y;
- y1=m_PointList[0].x;
- y2=m_PointList[0].y;
- for(int i=1;i<m_Numble;i++)
- {
- x1=min(x1,m_PointList[i].x);
- x2=min(x2,m_PointList[i].x);
- y1=min(y1,m_PointList[i].y);
- y2=min(y2,m_PointList[i].y);
- }
- *minX=x1;
- *maxX=x2;
- *minY=y1;
- *maxY=y2;
- }
- BOOL CPline::IsPoint(float x,float y,float j1,float blc)
- {
- int i;
- float xx,x1,y1,x2,y2;
- if(b_Delete)
- return FALSE;
- GetRect(&x1,&y1,&x2,&y2);
- if(!(x>=x1-j1&&x<=x2+j1&&y>=y1-j1&&y<=y2+j1))
- return FALSE;
- for(i=0;i<m_Numble-1;i++)
- {
- xx=PointLine(x,y,m_PointList[i].x,m_PointList[i].y,
- m_PointList[i+1].x,m_PointList[i+1].y);
- if(xx<j1)
- return TRUE;
- }
- return FALSE;
- }
- void CPline::Move(float x_Move,float y_Move)
- {
- for(int i=0;i<m_Numble;i++)
- {
- m_PointList[i].x+=x_Move;
- m_PointList[i].y+=y_Move;
- }
- }
- void CPline::Rotate(float baseX,float baseY,float angle)
- {
- for(int i=0;i<this->m_Numble;i++)
- {
- RotatePoint(baseX,baseY,angle,&m_PointList[i].x,&m_PointList[i].y);
- }
- }
- CPline::~CPline();