CIRCLE.cpp
上传用户:shangwu01
上传日期:2013-04-22
资源大小:707k
文件大小:6k
源码类别:

CAD

开发平台:

Visual C++

  1. // CIRCLE.cpp: implementation of the CCIRCLE class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CAD.h"
  6. #include "CIRCLE.h"
  7. #include "math.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. CCIRCLE::CCIRCLE()
  17. {
  18. }
  19. CCIRCLE::~CCIRCLE()
  20. {
  21. }
  22. void CCIRCLE::circle_drawMove(CPoint m_pointorg,CPoint m_pointfal,CDC* pDC,int m_line_style,int m_line_width,COLORREF m_line_color)
  23. {
  24. double R;
  25. R=sqrt(pow(m_pointorg.x-m_pointfal.x,2)+pow(m_pointorg.y-m_pointfal.y,2));
  26. CPen pen;
  27. pen.CreatePen(m_line_style,m_line_width,m_line_color);
  28. pDC->SelectObject(&pen);
  29. pDC->Arc(CRect(m_pointorg.x-R,m_pointorg.y-R,m_pointorg.x+R,m_pointorg.y+R),m_pointfal,m_pointfal);
  30. pen.DeleteObject();//鼠标输出
  31. pen.CreatePen(PS_DOT,1,RGB(0,0,255));
  32. pDC->SelectObject(&pen);
  33. pDC->MoveTo(m_pointorg);
  34. pDC->LineTo(m_pointfal);
  35. pen.DeleteObject();//半径输出
  36. CString str;
  37. str.Format("R:%f",R);
  38. pDC->TextOut((m_pointorg.x+m_pointfal.x)/2+10,(m_pointorg.y+m_pointfal.y)/2+10,str,7);//文本输出
  39. }
  40. void CCIRCLE::circle_drawAttribution(CDC*pDC)
  41. {
  42. if(m_circle_save.GetSize())
  43. for(int i=0;i<m_circle_save.GetSize();i++)
  44. {
  45. CPoint certrepoint;
  46. double circleR;
  47. CPen pen;
  48. pen.CreatePen(((circle_data *)(m_circle_save.GetAt(i)))->m_line_style,((circle_data *)(m_circle_save.GetAt(i)))->m_line_width,
  49. ((circle_data *)(m_circle_save.GetAt(i)))->m_line_color);
  50. pDC->SelectObject(&pen);
  51. certrepoint=((circle_data *)(m_circle_save.GetAt(i)))->certrepoint;
  52. circleR=((circle_data *)(m_circle_save.GetAt(i)))->circleR;
  53. pDC->Arc(CRect(certrepoint.x-circleR,certrepoint.y-circleR,certrepoint.x+circleR,certrepoint.y+circleR),
  54.      CPoint(certrepoint.x+circleR,certrepoint.y),CPoint(certrepoint.x+circleR,certrepoint.y));
  55. pen.DeleteObject();//圆的输出
  56. }
  57. }
  58. void CCIRCLE::circle_store(CPoint m_pointorg,CPoint m_pointfal,int m_line_style,int m_line_width,COLORREF m_line_color)
  59. {
  60. CPoint certrepoint;
  61. double circleR;
  62. certrepoint=m_pointorg;
  63. circleR=sqrt(pow(m_pointorg.x-m_pointfal.x,2)+pow(m_pointorg.y-m_pointfal.y,2));
  64. circle_data *pcircle_data=new circle_data(certrepoint,circleR,m_line_style,m_line_width,m_line_color); 
  65. m_circle_save.Add(pcircle_data);//数据储存
  66. }
  67. void CCIRCLE::circle_catchcertre(CPoint point,CRgn *prgn,CDC *pDC)
  68. {
  69. if(m_circle_save.GetSize())
  70. for(int i=0;i<m_circle_save.GetSize();i++)
  71. {
  72. if(prgn->PtInRegion(((circle_data*)m_circle_save.GetAt(i))->certrepoint))
  73. circle_fillpoint(((circle_data*)m_circle_save.GetAt(i))->certrepoint,pDC);
  74. }
  75. }
  76. void CCIRCLE::circle_fillpoint(CPoint point,CDC *pDC)
  77. {
  78. CBrush brush;
  79. brush.CreateSolidBrush( RGB(0,255,255));
  80. pDC->SelectObject(&brush);
  81. pDC->Rectangle(CRect(point.x-4,point.y-4,point.x+4,point.y+4));
  82. brush.DeleteObject();
  83. }
  84. void CCIRCLE::circle_searchcertre(CPoint point,CPoint *pnearpoint,CRgn *prgn)
  85. {
  86. CPoint nearpoint;
  87. nearpoint=*pnearpoint;
  88. float nearrest;
  89. nearrest=sqrt(pow(point.x-nearpoint.x,2)+pow(point.y-nearpoint.y,2));
  90. if(m_circle_save.GetSize())
  91. for(int i=0;i<m_circle_save.GetSize();i++)
  92. if(prgn->PtInRegion(((circle_data*)m_circle_save.GetAt(i))->certrepoint))
  93. {
  94. float length;
  95. length=sqrt(pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.x-point.x,2)+
  96. pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.y-point.y,2));
  97. if(length<nearrest)
  98. nearpoint=((circle_data*)m_circle_save.GetAt(i))->certrepoint;
  99. }
  100. *pnearpoint=nearpoint;
  101. }
  102. bool CCIRCLE::circle_searchcircle(CPoint point,int *pNum,int *pnStyle,CDC *pmdc)
  103. {
  104. if(m_circle_save.GetSize())
  105. for(int i=0;i<m_circle_save.GetSize();i++)
  106. {
  107. float r;
  108. r=sqrt(pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.x-point.x,2)+
  109.    pow(((circle_data*)m_circle_save.GetAt(i))->certrepoint.y-point.y,2));
  110. if(fabs(r-((circle_data*)m_circle_save.GetAt(i))->circleR)<3)
  111. {
  112. circle_fillpoint(((circle_data*)m_circle_save.GetAt(i))->certrepoint,pmdc);
  113. *pNum=i;
  114. *pnStyle=3;
  115. return(true);
  116. }
  117. }
  118. return(false);
  119. }
  120. bool CCIRCLE::circle_editselect(CPoint point,CPoint*ppointorg,int Num)
  121. {
  122. CPoint certrepoint;
  123. certrepoint=((circle_data*)m_circle_save.GetAt(Num))->certrepoint;
  124. CRgn rgn;
  125. rgn.CreateRectRgn(certrepoint.x-10,certrepoint.y-10,certrepoint.x+10,certrepoint.y+10);
  126. if(rgn.PtInRegion(point))
  127. {
  128. *ppointorg=certrepoint;
  129. return(true);
  130. }
  131. else
  132. return(false);
  133. }
  134. void CCIRCLE::circle_editmove(CPoint pointorg,CPoint pointfal,int Num,CDC* pDC)
  135. {
  136. CSize pointmove;
  137. pointmove=pointfal-pointorg;
  138. CPoint certrepoint;
  139. double circleR;
  140. certrepoint=((circle_data *)(m_circle_save.GetAt(Num)))->certrepoint+pointmove;
  141. circleR=((circle_data *)(m_circle_save.GetAt(Num)))->circleR;
  142. CPen pen;
  143. pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
  144. pDC->SelectObject(&pen);
  145. pDC->Arc(CRect(certrepoint.x-circleR,certrepoint.y-circleR,certrepoint.x+circleR,certrepoint.y+circleR),
  146. CPoint(certrepoint.x+circleR,certrepoint.y),CPoint(certrepoint.x+circleR,certrepoint.y));
  147. pen.DeleteObject();
  148. }
  149. void CCIRCLE::circle_editmovestore(CPoint pointorg,CPoint pointfal,int Num)
  150. {
  151. CSize pointmove;
  152. pointmove=pointfal-pointorg;
  153. ((circle_data *)(m_circle_save.GetAt(Num)))->certrepoint+=pointmove;
  154. }
  155. void CCIRCLE::circle_del(int Num)
  156. {
  157. circle_data *pdel=(circle_data*)m_circle_save.GetAt(Num);
  158. if(pdel!=NULL)
  159. {
  160. m_circle_save.RemoveAt(Num);
  161. delete pdel;
  162. }
  163. }
  164. ///////////////////////////////////////
  165. CCIRCLE::circle_data::circle_data(CPoint certrepoint,double circleR,int m_line_style,int m_line_width,COLORREF m_line_color)
  166. {
  167. this->certrepoint=certrepoint;
  168. this->circleR=circleR;
  169. this->m_line_style=m_line_style;
  170. this->m_line_width=m_line_width;
  171. this->m_line_color=m_line_color;
  172. }
  173. CCIRCLE::circle_data::~circle_data()
  174. {
  175. }