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

CAD

开发平台:

Visual C++

  1. // ELLIPS.cpp: implementation of the CELLIPS class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CAD.h"
  6. #include "ELLIPS.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. CELLIPS::CELLIPS()
  17. {
  18. }
  19. CELLIPS::~CELLIPS()
  20. {
  21. }
  22. void CELLIPS::ellips_drawAttribution(CDC*pDC)
  23. {
  24. if(m_ellips_save.GetSize())
  25. {
  26. for(int i=0;i<m_ellips_save.GetSize();i++)
  27. {
  28. CPoint topleft,bottomright;
  29. CPen pen;
  30. pen.CreatePen(((ellips_data*)(m_ellips_save.GetAt(i)))->m_line_style,
  31.  ((ellips_data*)(m_ellips_save.GetAt(i)))->m_line_width,
  32.  ((ellips_data*)(m_ellips_save.GetAt(i)))->m_line_color);
  33. pDC->SelectObject(&pen);
  34. topleft=CPoint(2*((ellips_data*)(m_ellips_save.GetAt(i)))->certrepoint.x-((ellips_data*)(m_ellips_save.GetAt(i)))->bottomright.x,
  35.    2*((ellips_data*)(m_ellips_save.GetAt(i)))->certrepoint.y-((ellips_data*)(m_ellips_save.GetAt(i)))->bottomright.y);
  36. bottomright=((ellips_data*)(m_ellips_save.GetAt(i)))->bottomright;
  37. pDC->Arc(CRect(topleft,bottomright),bottomright,bottomright);
  38. pen.DeleteObject();
  39. }
  40. }
  41. }
  42. void CELLIPS::ellips_drawMove(CPoint m_pointorg,CPoint m_pointfal,CDC *pDC,int m_line_style,int m_line_width,COLORREF m_line_color)
  43. {
  44. CPoint topleft,bottomright;
  45. topleft=CPoint(2*m_pointorg.x-m_pointfal.x,2*m_pointorg.y-m_pointfal.y);
  46. bottomright=m_pointfal;
  47. CPen pen;
  48. pen.CreatePen(m_line_style,m_line_width,m_line_color);
  49. pDC->SelectObject(&pen);
  50. pDC->Arc(CRect(topleft,bottomright),bottomright,bottomright);
  51. pen.DeleteObject();//椭圆输出
  52. pen.CreatePen(PS_DOT,1,RGB(0,0,255));
  53. pDC->SelectObject(&pen);
  54. pDC->MoveTo(CPoint(m_pointorg.x,topleft.y));
  55. pDC->LineTo(CPoint(m_pointorg.x,bottomright.y));
  56. pDC->MoveTo(CPoint(topleft.x,m_pointorg.y));
  57. pDC->LineTo(CPoint(bottomright.x,m_pointorg.y));
  58. pen.DeleteObject();//辅助线输出
  59. CString str1,str2;
  60. float width,high;
  61. width=fabs(bottomright.x-topleft.x);
  62. high=fabs(bottomright.y-topleft.y);
  63. str1.Format("长轴:%f",width);
  64. str2.Format("短轴:%f",high);
  65. pDC->TextOut(bottomright.x+5,m_pointorg.y+5,str1,7);
  66. pDC->TextOut(m_pointorg.x+5,topleft.y-20,str2,7);//文本输出
  67. }
  68. void CELLIPS::ellips_store(CPoint m_pointorg,CPoint m_pointfal,int m_line_style,int m_line_width,COLORREF m_line_color)
  69. {
  70. ellips_data *pellips_data=new ellips_data(m_pointorg,m_pointfal,m_line_style,m_line_width,m_line_color);
  71. m_ellips_save.Add(pellips_data);
  72. }
  73. void CELLIPS::ellips_catchcertre(CPoint point,CRgn *prgn,CDC *pDC)
  74. {
  75. if(m_ellips_save.GetSize())
  76. for(int i=0;i<m_ellips_save.GetSize();i++)
  77. {
  78. if(prgn->PtInRegion(((ellips_data*)m_ellips_save.GetAt(i))->certrepoint))
  79. ellips_fillpoint(((ellips_data*)m_ellips_save.GetAt(i))->certrepoint,pDC);
  80. }
  81. }
  82. void CELLIPS::ellips_fillpoint(CPoint point,CDC *pDC)
  83. {
  84. CBrush brush;
  85. brush.CreateSolidBrush( RGB(0,255,255));
  86. pDC->SelectObject(&brush);
  87. pDC->Rectangle(CRect(point.x-4,point.y-4,point.x+4,point.y+4));
  88. brush.DeleteObject();
  89. }
  90. void CELLIPS::ellips_searchcertre(CPoint point,CPoint *pnearpoint,CRgn *prgn)
  91. {
  92. CPoint nearpoint;
  93. nearpoint=*pnearpoint;
  94. float nearrest;
  95. nearrest=sqrt(pow(point.x-nearpoint.x,2)+pow(point.y-nearpoint.y,2));
  96. if(m_ellips_save.GetSize())
  97. for(int i=0;i<m_ellips_save.GetSize();i++)
  98. if(prgn->PtInRegion(((ellips_data*)m_ellips_save.GetAt(i))->certrepoint))
  99. {
  100. float length;
  101. length=sqrt(pow(((ellips_data*)m_ellips_save.GetAt(i))->certrepoint.x-point.x,2)+
  102. pow(((ellips_data*)m_ellips_save.GetAt(i))->certrepoint.y-point.y,2));
  103. if(length<nearrest)
  104. nearpoint=((ellips_data*)m_ellips_save.GetAt(i))->certrepoint;
  105. }
  106. *pnearpoint=nearpoint;
  107. }
  108. bool CELLIPS::ellips_searchellips(CPoint point,int *pNum,int *pnStyle,CDC* pmdc)
  109. {
  110. if(m_ellips_save.GetSize())
  111. for(int i=0;i<m_ellips_save.GetSize();i++)
  112. {
  113. CPoint topleft,bottomright;
  114. topleft=CPoint(2*((ellips_data*)(m_ellips_save.GetAt(i)))->certrepoint.x-((ellips_data*)(m_ellips_save.GetAt(i)))->bottomright.x,
  115.    2*((ellips_data*)(m_ellips_save.GetAt(i)))->certrepoint.y-((ellips_data*)(m_ellips_save.GetAt(i)))->bottomright.y);
  116. bottomright=((ellips_data*)(m_ellips_save.GetAt(i)))->bottomright;
  117. CRgn rgnin,rgnout;
  118. rgnin.CreateEllipticRgnIndirect(CRect(topleft+CSize(4,4),bottomright-CSize(4,4)));
  119. rgnout.CreateEllipticRgnIndirect(CRect(topleft-CSize(4,4),bottomright+CSize(4,4)));
  120. if(rgnout.PtInRegion(point)&&!rgnin.PtInRegion(point))
  121. {
  122. ellips_fillpoint(((ellips_data*)(m_ellips_save.GetAt(i)))->certrepoint,pmdc);
  123. *pNum=i;
  124. *pnStyle=5;
  125. return(true);
  126. }
  127. }
  128.   return(false);
  129. }
  130. bool CELLIPS::ellips_editselect(CPoint point,CPoint *ppointorg,int Num)
  131. {
  132. CPoint certrepoint;
  133. certrepoint=((ellips_data*)(m_ellips_save.GetAt(Num)))->certrepoint;
  134. CRgn rgn;
  135. rgn.CreateRectRgn(certrepoint.x-10,certrepoint.y-10,certrepoint.x+10,certrepoint.y+10);
  136. if(rgn.PtInRegion(point))
  137. {
  138. *ppointorg=certrepoint;
  139. return(true);
  140. }
  141. else
  142. return(false);
  143. }
  144. void CELLIPS::ellips_editmove(CPoint pointorg,CPoint pointfal,int Num,CDC *pDC)
  145. {
  146. CSize pointmove;
  147. pointmove=pointfal-pointorg;
  148. CPoint topleft,bottomright;
  149. topleft=CPoint(2*((ellips_data*)(m_ellips_save.GetAt(Num)))->certrepoint.x-((ellips_data*)(m_ellips_save.GetAt(Num)))->bottomright.x,
  150. 2*((ellips_data*)(m_ellips_save.GetAt(Num)))->certrepoint.y-((ellips_data*)(m_ellips_save.GetAt(Num)))->bottomright.y)+pointmove;
  151. bottomright=((ellips_data*)(m_ellips_save.GetAt(Num)))->bottomright+pointmove;
  152. CPen pen;
  153. pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
  154. pDC->SelectObject(&pen);
  155. pDC->Arc(CRect(topleft,bottomright),bottomright,bottomright);
  156. pen.DeleteObject();
  157. }
  158. void CELLIPS::ellips_editmovestore(CPoint pointorg,CPoint pointfal,int Num)
  159. {
  160. CSize pointmove;
  161. pointmove=pointfal-pointorg;
  162. ((ellips_data*)(m_ellips_save.GetAt(Num)))->bottomright+=pointmove;
  163. ((ellips_data*)(m_ellips_save.GetAt(Num)))->certrepoint+=pointmove;
  164. }
  165. void CELLIPS::ellips_del(int Num)
  166. {
  167. ellips_data *pdel=(ellips_data*)m_ellips_save.GetAt(Num);
  168. if(pdel!=NULL)
  169. {
  170. m_ellips_save.RemoveAt(Num);
  171. delete pdel;
  172. }
  173. }
  174. ///////////////////////////////
  175. CELLIPS::ellips_data::ellips_data(CPoint certrepoint,CPoint bottomright,int m_line_style,int m_line_width,COLORREF m_line_color)
  176. {
  177. this->certrepoint=certrepoint;
  178. this->bottomright=bottomright;
  179. this->m_line_style=m_line_style;
  180. this->m_line_width=m_line_width;
  181. this->m_line_color=m_line_color;
  182. }
  183. CELLIPS::ellips_data::~ellips_data()
  184. {
  185. }