PlineRgn.cpp
上传用户:yklx818
上传日期:2013-04-13
资源大小:459k
文件大小:3k
源码类别:

GIS编程

开发平台:

Visual C++

  1. // PlineRgn.cpp: implementation of the CPlineRgn class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Draw.h"
  6. #include "PlineRgn.h"
  7. #include "DrawDoc.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. //CPlineRgn::CPlineRgn()
  17. //{
  18. //}
  19. //CPlineRgn::~CPlineRgn();
  20. extern float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
  21. BOOL CPlineRgn::IsRectCross(float minx,float miny,float maxx,float maxy)
  22. {
  23. if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
  24. return FALSE;  //如两个矩形不相交
  25. else
  26. return TRUE;
  27. }
  28. void CPlineRgn::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
  29. {
  30. if(b_Delete)
  31. {
  32. return ;
  33. }
  34. float minx,miny,maxx,maxy;
  35. GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
  36. if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
  37. return;
  38. short LineType=0;
  39. short ColorPen=m_ColorPen;
  40. if(m_DrawMode==0)
  41. pDC->SetROP2(R2_COPYPEN);
  42. else if(m_DrawMode==1)
  43. pDC->SetROP2(R2_NOT);
  44. short lt=0;
  45. if(m_DrawModel==1)
  46. {
  47. LineType=-1;
  48. lt=2;
  49. }
  50. else if(m_DrawModel==2)
  51. ColorPen=BackColor;
  52. short Numbl=m_Numble;
  53. m_PointList[Numbl++]=m_PointList[0];
  54. POINT* ppoint=new POINT[Numbl*4+1];
  55. CRgn rgn;
  56. for(int i=0;i<Numbl;i++)
  57. {
  58. int X1,Y1;
  59. DPtoVP(m_PointList[i].x,m_PointList[i].y,&X1,&Y1);
  60. ppoint[i].x=X1;
  61. ppoint[i].y=Y1;
  62. }
  63. CGraphPara m_GraphPara;
  64.     CGraphPara *p_GraphPara;
  65. p_GraphPara=&m_GraphPara;
  66.     CPen pen(lt,1,p_GraphPara->GetColor(ColorPen));
  67. CPen* pOldPen=pDC->SelectObject(&pen);
  68. for( i=0;i<Numbl-1;i++)
  69. {
  70. pDC->MoveTo(ppoint[i]);
  71. pDC->LineTo(ppoint[i+1]);
  72. }
  73. if(m_DrawModel==0||m_DrawModel==2)
  74. {
  75. if(m_bFill)
  76. {
  77. long lColor=p_GraphPara->GetColor(m_ColorBrush);
  78. if(m_DrawModel==2)
  79. lColor=p_GraphPara->GetColor(BackColor);
  80. CBrush brush(lColor);
  81. CBrush* pOldBrush=pDC->SelectObject(&brush);
  82. if(this->m_bTransparent)
  83. pDC->SetROP2(R2_NOP);
  84. else
  85. pDC->SetROP2(R2_COPYPEN);
  86. pDC->Polygon(ppoint,Numbl);
  87. pDC->SelectObject(pOldBrush);
  88. pDC->SetROP2(R2_COPYPEN);
  89. }
  90. }
  91. else if(m_DrawModel==1)
  92. {
  93. rgn.CreatePolygonRgn(ppoint,Numbl,1);
  94. pDC->InvertRgn(&rgn);
  95. }
  96. pDC->SelectObject(pOldPen);
  97. delete ppoint;
  98. }
  99. void CPlineRgn::CalArea()
  100. {
  101. float xx1,yy1,xx2,yy2;
  102. GetRect(&xx1,&yy1,&xx2,&yy2);
  103. m_fArea=0.0;
  104. m_PointList[this->m_Numble]=m_PointList[0];
  105. for(int i=0;i<m_Numble;i++)
  106. {
  107. m_fArea+=(m_PointList[i+1].x-m_PointList[i].x)*((m_PointList[i+1].y+m_PointList[i].y)/2-yy1);
  108. }
  109. }
  110. BOOL CPlineRgn::IsPoint(float x,float y,float j1,float blc)
  111. {
  112. int i;
  113. float xx,x1,y1,x2,y2;
  114. if(b_Delete)
  115. return FALSE;
  116. GetRect(&x1,&y1,&x2,&y2);
  117. if(!(x>=x1-j1&&x<=x2+j1&&y>=y1-j1&&y<=y2+j1))
  118. return FALSE;
  119. if(PointRgn(x,y,m_Numble,m_PointList,blc))
  120. return TRUE;
  121. return FALSE;
  122. }
  123. void CPlineRgn::Rotate(float baseX,float baseY,float angle)
  124. {
  125. CPline::Rotate(baseX,baseY,angle);
  126. }
  127. void CPlineRgn::Move(float x_Move,float y_Move)
  128. {
  129. CPline::Move(x_Move,y_Move);
  130. }
  131. BOOL CPlineRgn::IsFill()
  132. {
  133. return m_bFill;
  134. }