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

GIS编程

开发平台:

Visual C++

  1. // Arc.cpp: implementation of the CArc class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. //#include "Draw.h"
  6. #include "Arc.h"
  7. #include "math.h"
  8. //#include "DrawDoc.h"
  9. #define pi 3.1415926
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char THIS_FILE[]=__FILE__;
  13. #define new DEBUG_NEW
  14. #endif
  15. //////////////////////////////////////////////////////////////////////
  16. // Construction/Destruction
  17. //////////////////////////////////////////////////////////////////////
  18. extern IsRectCross(float minx,float miny,float maxx,float maxy);
  19. //extern  CGraphPara *p_GraphPara;
  20. //CArc::CArc();
  21. //float xMinScreen,yMinScreen,xMaxScreen,yMaxScreen;
  22. //BOOL IsRectCross(float minx,float miny,float maxx,float maxy);
  23. //BOOL IsRectCross(float minx,float miny,float maxx,float maxy)
  24. //{
  25. // if(minx>xMaxScreen||maxx<xMinScreen||miny>yMaxScreen||maxy<yMinScreen)
  26. // return FALSE;  //如两个矩形不相交
  27. // else
  28. // return TRUE;
  29. //}
  30. void CArc::Draw(CDC* pDC,int m_DrawMode,int m_DrawModel,short BackColor)
  31. {
  32. if(b_Delete)
  33. return ;
  34. int x,y,rr;
  35. int x1,y1,x2,y2;
  36. float minx,miny,maxx,maxy;
  37. GetRect(&minx,&miny,&maxx,&maxy);//得到边界矩形
  38. if(!IsRectCross(minx,miny,maxx,maxy))//如果边界矩形不与屏幕窗口相交
  39. return;
  40. short LineType=m_LineType;
  41. short LineWide=max(1,DLtoVL(m_LineWide));
  42. short ColorPen=m_ColorPen;
  43. if(m_DrawModel==1)
  44. {
  45. if(m_LineType!=2)
  46. LineType=2;
  47. else
  48. LineType++;
  49. }
  50. else if(m_DrawModel==2)
  51. ColorPen=BackColor;
  52. CGraphPara m_GraphPara;
  53.     CGraphPara *p_GraphPara;
  54. p_GraphPara=&m_GraphPara;
  55. CPen pen((int)LineType,(int)LineWide,p_GraphPara->GetColor(ColorPen));
  56. CPen* pOldPen=pDC->SelectObject(&pen);
  57. if(m_DrawMode==0)
  58. pDC->SetROP2(R2_COPYPEN);
  59. else if(m_DrawMode==1)
  60. pDC->SetROP2(R2_NOT);
  61. DPtoVP(m_CircleX,m_CircleY,&x,&y);
  62. rr=DLtoVL(m_CircleR);
  63. x1=(int)(x+(DLtoVL(m_CircleR*cos(m_Angle1))));
  64. y1=(int)(y-DLtoVL(m_CircleR*sin(m_Angle1)));
  65. x2=(int)(x+DLtoVL(m_CircleR*cos(m_Angle2)));
  66. y2=(int)(y-DLtoVL(m_CircleR*sin(m_Angle2)));
  67.  //   Invalidate();
  68. pDC->Arc(x-rr,y-rr,x+rr,y+rr,x1,y1,x2,y2);
  69. pDC->SelectObject(pOldPen);
  70. }
  71. void CArc::GetRect(float* minX,float* minY,float* maxX,float* maxY)
  72. {
  73. float x,y,x1,y1,x2,y2;
  74. int i,pb;
  75. //得到圆弧的起点坐标
  76. x=m_CircleX+(float)(cos(m_Angle1)*m_CircleR);
  77. y=m_CircleY+(float)(sin(m_Angle1)*m_CircleR);
  78. //用圆弧起点坐标来初始化边界矩形
  79. x1=x;y1=y;
  80. x2=x;y2=y;
  81. //得到圆弧的中终点坐标
  82. x=m_CircleX+(float)(cos(m_Angle2)*m_CircleR);
  83. y=m_CircleY+(float)(sin(m_Angle2)*m_CircleR);
  84. //得到最小和最大坐标
  85. x1=min(x,x1);x2=max(x,x2);
  86. y1=min(y,y1);y2=max(y,y2);
  87. for(i=0;i<4;i++)
  88. {
  89. if(IsInArc(pi/2*i))
  90. {
  91. if(i==0)
  92. {
  93. x=m_CircleX+m_CircleR;
  94. y=m_CircleY;
  95. }
  96. else if(i==1)
  97. {
  98. x=m_CircleX;
  99. y=m_CircleY+m_CircleR;
  100. }
  101. else if(i==2)
  102. {
  103. x=m_CircleX-m_CircleR;
  104. y=m_CircleY;
  105. }
  106. else if(i==3)
  107. {
  108. x=m_CircleX;
  109. y=m_CircleY-m_CircleR;
  110. }
  111. x1=min(x,x1);x2=max(x,x2);
  112. y1=min(y,y1);y2=max(y,y2);
  113. }
  114. }
  115. *minX=x1;*maxX=x2;*minY=y1;*maxY=y2;
  116. }
  117. void CArc::CalLong()
  118. {
  119. float angle=m_Angle2;
  120. if(this->m_Angle2<this->m_Angle1)
  121. angle+=pi*2;
  122. CCircle::CalLong();
  123. m_fLong=m_fLong*(angle-m_Angle1)/(pi*2);
  124. }
  125. BOOL CArc::IsInArc(float angle)
  126. {
  127. if((m_Angle1<m_Angle2&&angle<m_Angle2&&angle>=m_Angle1)||
  128. m_Angle1>m_Angle2&&(!(angle<=m_Angle1&&angle>=m_Angle2)))
  129. return TRUE;
  130. else
  131. return FALSE;
  132. }
  133. BOOL CArc::IsPoint(float x,float y,float j1,float blc)
  134. {
  135. if(CCircle::IsPoint(x,y,j1,blc))//调用CCircle类的IsPoint函数判断是否选中了圆
  136. {
  137. float xx=CalDisp(x,y,m_CircleX,m_CircleY);
  138. float ang=(float)acos((x-m_CircleX)/xx);
  139. if(y-m_CircleY<0)
  140. ang=(float)pi*2-ang;
  141. if(IsInArc(ang))
  142. return TRUE;
  143. }
  144. return FALSE;
  145. }
  146. void CArc::Move(float x_Move,float y_Move)
  147. {
  148. CCircle::Move(x_Move,y_Move);
  149. }
  150. void CArc::Rotate(float baseX,float baseY,float angle)
  151. {
  152. RotatePoint(baseX,baseY,angle,&this->m_CircleX,&this->m_CircleY);
  153. this->m_Angle1+=angle;
  154. this->m_Angle2+=angle;
  155. }
  156. CArc::~CArc()
  157. {
  158. }