PlineRgn.cpp
资源名称:基本GIS系统开发.rar [点击查看]
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:3k
源码类别:
GIS编程
开发平台:
Visual C++
- // PlineRgn.cpp: implementation of the CPlineRgn class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Draw.h"
- #include "PlineRgn.h"
- #include "DrawDoc.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- //CPlineRgn::CPlineRgn()
- //{
- //}
- //CPlineRgn::~CPlineRgn();
- extern float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
- BOOL CPlineRgn::IsRectCross(float minx,float miny,float maxx,float maxy)
- {
- if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
- return FALSE; //如两个矩形不相交
- else
- return TRUE;
- }
- void CPlineRgn::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
- {
- if(b_Delete)
- {
- return ;
- }
- float minx,miny,maxx,maxy;
- GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
- if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
- return;
- short LineType=0;
- short ColorPen=m_ColorPen;
- if(m_DrawMode==0)
- pDC->SetROP2(R2_COPYPEN);
- else if(m_DrawMode==1)
- pDC->SetROP2(R2_NOT);
- short lt=0;
- if(m_DrawModel==1)
- {
- LineType=-1;
- lt=2;
- }
- else if(m_DrawModel==2)
- ColorPen=BackColor;
- short Numbl=m_Numble;
- m_PointList[Numbl++]=m_PointList[0];
- POINT* ppoint=new POINT[Numbl*4+1];
- CRgn rgn;
- for(int i=0;i<Numbl;i++)
- {
- int X1,Y1;
- DPtoVP(m_PointList[i].x,m_PointList[i].y,&X1,&Y1);
- ppoint[i].x=X1;
- ppoint[i].y=Y1;
- }
- CGraphPara m_GraphPara;
- CGraphPara *p_GraphPara;
- p_GraphPara=&m_GraphPara;
- CPen pen(lt,1,p_GraphPara->GetColor(ColorPen));
- CPen* pOldPen=pDC->SelectObject(&pen);
- for( i=0;i<Numbl-1;i++)
- {
- pDC->MoveTo(ppoint[i]);
- pDC->LineTo(ppoint[i+1]);
- }
- if(m_DrawModel==0||m_DrawModel==2)
- {
- if(m_bFill)
- {
- long lColor=p_GraphPara->GetColor(m_ColorBrush);
- if(m_DrawModel==2)
- lColor=p_GraphPara->GetColor(BackColor);
- CBrush brush(lColor);
- CBrush* pOldBrush=pDC->SelectObject(&brush);
- if(this->m_bTransparent)
- pDC->SetROP2(R2_NOP);
- else
- pDC->SetROP2(R2_COPYPEN);
- pDC->Polygon(ppoint,Numbl);
- pDC->SelectObject(pOldBrush);
- pDC->SetROP2(R2_COPYPEN);
- }
- }
- else if(m_DrawModel==1)
- {
- rgn.CreatePolygonRgn(ppoint,Numbl,1);
- pDC->InvertRgn(&rgn);
- }
- pDC->SelectObject(pOldPen);
- delete ppoint;
- }
- void CPlineRgn::CalArea()
- {
- float xx1,yy1,xx2,yy2;
- GetRect(&xx1,&yy1,&xx2,&yy2);
- m_fArea=0.0;
- m_PointList[this->m_Numble]=m_PointList[0];
- for(int i=0;i<m_Numble;i++)
- {
- m_fArea+=(m_PointList[i+1].x-m_PointList[i].x)*((m_PointList[i+1].y+m_PointList[i].y)/2-yy1);
- }
- }
- BOOL CPlineRgn::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;
- if(PointRgn(x,y,m_Numble,m_PointList,blc))
- return TRUE;
- return FALSE;
- }
- void CPlineRgn::Rotate(float baseX,float baseY,float angle)
- {
- CPline::Rotate(baseX,baseY,angle);
- }
- void CPlineRgn::Move(float x_Move,float y_Move)
- {
- CPline::Move(x_Move,y_Move);
- }
- BOOL CPlineRgn::IsFill()
- {
- return m_bFill;
- }