Circle.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:18k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // Circle.cpp: implementation of the CCircle class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GraphSoft.h"
  6. #include "Circle.h"
  7. #include "GlobalFunction.h"
  8. #include "math.h"
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char THIS_FILE[]=__FILE__;
  12. #define new DEBUG_NEW
  13. #endif
  14. ///////////////////////////////////
  15. IMPLEMENT_SERIAL( CCircle, CShape, 0 )
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. ///////////////////////////////////////////////////////////////////////
  20. CCircle::CCircle():CShape()
  21. {
  22.  m_flRadiusTemp=m_flRadius=0;
  23.  m_flCenterxTemp=m_flCenterx=0;
  24.  m_flCenteryTemp=m_flCentery=0;
  25. }
  26. CCircle::CCircle(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
  27. {
  28. m_flRadiusTemp=m_flRadius=0;
  29. m_flCenterxTemp=m_flCenterx=0;
  30. m_flCenteryTemp=m_flCentery=0;
  31. }
  32. CCircle::CCircle(CCircle * const pCircle):CShape(pCircle)
  33. {
  34. m_flRadius=pCircle->m_flRadius;
  35. m_flCenterx=pCircle->m_flCenterx;
  36. m_flCentery=pCircle->m_flCentery;
  37. //
  38. m_flRadiusTemp=pCircle->m_flRadiusTemp;
  39. m_flCenterxTemp=pCircle->m_flCenterxTemp;
  40. m_flCenteryTemp=pCircle->m_flCenteryTemp;
  41. }
  42. CCircle::~CCircle()
  43. {
  44. }
  45. ////////////////////////////////////////////////////////////////////////// 
  46. void CCircle::Serialize( CArchive& ar)
  47. {
  48. CShape::Serialize( ar ) ;
  49. if ( ar.IsLoading() ){  
  50. ar>>m_flRadius;
  51. ar>>m_flCenterx;
  52. ar>>m_flCentery;
  53. //temp
  54. m_flRadiusTemp=m_flRadius;
  55. m_flCenterxTemp=m_flCenterx;
  56. m_flCenteryTemp=m_flCentery;
  57. } else {
  58. ar<<m_flRadius;
  59. ar<<m_flCenterx;
  60. ar<<m_flCentery;  
  61. }
  62. return ;
  63. }
  64. ////////////////////////////////////////////////////////////////////////
  65. void CCircle::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
  66. {
  67. CPen pen,*poldPen;
  68. CPoint ptCenter(m_flCenterxTemp,m_flCenteryTemp);
  69.     
  70. pen.CreatePen(PS_SOLID,1, fillColor);    
  71. poldPen=pDC->SelectObject(&pen);
  72. if(m_nFillStyle==_shape_solid_fill){
  73. FillBreCircle(pDC,ptCenter,m_flRadiusTemp,penWidth);
  74. }
  75. pen.DeleteObject();
  76. pen.CreatePen(PS_SOLID,penWidth, color);  
  77. pDC->SelectObject(&pen);      
  78. //CBrush brush ;
  79. //brush.CreateSolidBrush(::GetSysColor(COLOR_3DFACE)) ;
  80. //CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
  81. BreCircle(pDC,ptCenter,m_flRadiusTemp,color,penWidth);
  82. if(GetDrawPointsFlag()==1){
  83. DrawPoints(pDC,color);
  84. }
  85. pDC->SelectObject(poldPen);  
  86. //pDC->SelectObject(pOldBrush);
  87. }
  88. ///////////////////////////////////////////
  89. void CCircle::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
  90. {
  91. if(!IsInRect(m_rectFrom)){
  92. return;
  93. }
  94. //得到移动扩缩后的关键数据
  95. float  flCx,flCy,flR;
  96. //移动
  97. float stepx=m_rectTo.left-m_rectFrom.left;
  98. float stepy=m_rectTo.top-m_rectFrom.top;
  99. flCx=m_flCenterxTemp+stepx;
  100. flCy=m_flCenteryTemp+stepy;
  101. flR=m_flRadiusTemp;
  102. //扩缩
  103. float cx,cy,flScale;
  104. cx=m_rectTo.left;
  105. cy=m_rectTo.top;  
  106. if(m_rectFrom.Width()<0.01){
  107. m_rectFrom.right=m_rectFrom.left +1;
  108. }
  109. if(m_rectFrom.Height()<0.01){
  110. m_rectFrom.bottom=m_rectFrom.top +1;
  111. }
  112. flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
  113. // flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
  114. flR=flR*flScale;
  115. flCx=(flCx-cx)*flScale+cx;
  116. flCy=(flCy-cy)*flScale+cy;
  117. CPen pen,*poldPen;
  118.     pen.CreatePen(PS_SOLID,1, color);
  119. poldPen=pDC->SelectObject(&pen);
  120. {
  121. pDC->MoveTo(flCx,flCy-1-GetPenWidth());
  122. pDC->LineTo(flCx,flCy+2+GetPenWidth());
  123. pDC->MoveTo(flCx-1-GetPenWidth(),flCy);
  124. pDC->LineTo(flCx+2+GetPenWidth(),flCy);
  125. }
  126. pDC->SelectObject(poldPen);      
  127. return;
  128. }
  129. void CCircle::DrawPoints(CDC *pDC,COLORREF color)
  130. {
  131. CPen pen,*poldPen;
  132.     pen.CreatePen(PS_SOLID,1, color);
  133. poldPen=pDC->SelectObject(&pen);
  134. {
  135. pDC->MoveTo(m_flCenterxTemp,m_flCenteryTemp-1-GetPenWidth());
  136. pDC->LineTo(m_flCenterxTemp,m_flCenteryTemp+2+GetPenWidth());
  137. pDC->MoveTo(m_flCenterxTemp-1-GetPenWidth(),m_flCenteryTemp);
  138. pDC->LineTo(m_flCenterxTemp+2+GetPenWidth(),m_flCenteryTemp);
  139. }  
  140. pDC->SelectObject(poldPen);      
  141. return;
  142. }
  143. ///////////////////////////////
  144. void CCircle::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
  145. {
  146. // if(!IsInRect(m_rectFrom)){
  147. // return;
  148. // }
  149. //得到移动扩缩后的关键数据
  150. float  flCx,flCy,flR;
  151. //移动
  152. float stepx=m_rectTo.left-m_rectFrom.left;
  153. float stepy=m_rectTo.top-m_rectFrom.top;
  154. flCx=m_flCenterxTemp+stepx;
  155. flCy=m_flCenteryTemp+stepy;
  156. flR=m_flRadiusTemp;
  157. //扩缩
  158. float cx,cy,flScale;
  159. cx=m_rectTo.left;
  160. cy=m_rectTo.top;  
  161. if(m_rectFrom.Width()<0.01){
  162. m_rectFrom.right=m_rectFrom.left +1;
  163. }
  164. if(m_rectFrom.Height()<0.01){
  165. m_rectFrom.bottom=m_rectFrom.top +1;
  166. }
  167. flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
  168. // flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
  169. flR=flR*flScale;
  170. flCx=(flCx-cx)*flScale+cx;
  171. flCy=(flCy-cy)*flScale+cy;
  172. //Draw
  173. CPen pen,*poldPen;
  174. CPoint ptCenter(flCx,flCy);    
  175. pen.CreatePen(PS_SOLID,1, fillColor);    
  176. poldPen=pDC->SelectObject(&pen);
  177. if(m_nFillStyle==_shape_solid_fill){
  178. FillBreCircle(pDC,ptCenter,flR,penWidth);
  179. }
  180. pen.DeleteObject();
  181. pen.CreatePen(PS_SOLID,penWidth, color);  
  182. pDC->SelectObject(&pen);    
  183. BreCircle(pDC,ptCenter,flR,color,penWidth);
  184. if(GetDrawPointsFlag()==1){
  185. DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
  186. }
  187. pDC->SelectObject(poldPen);
  188. }
  189. //
  190. void CCircle::BreCircle(CDC *pDC,CPoint m_pCenter,int nRadius,COLORREF color,int nPenWidth)
  191. {
  192. int x,y,xc,yc,r,di,i;    
  193. xc=m_pCenter.x;
  194. yc=m_pCenter.y;
  195. x=xc+nRadius;
  196. y=yc;
  197. r=nRadius;
  198. x=0;
  199. y=r;
  200. di=3-2*r;
  201. float flX[8],flY[8];
  202. flX[0]=xc+x;
  203. flX[1]=xc+x;
  204. flX[2]=xc-x;
  205. flX[3]=xc-x;
  206. flX[4]=xc+y;
  207. flX[5]=xc+y;
  208. flX[6]=xc-y;
  209. flX[7]=xc-y;
  210. flY[0]=yc+y;
  211. flY[1]=yc-y;
  212. flY[2]=yc+y;
  213. flY[3]=yc-y;
  214. flY[4]=yc+x;
  215. flY[5]=yc-x;
  216. flY[6]=yc+x;
  217. flY[7]=yc-x;
  218. i=0;
  219. while(x<=y)
  220. {
  221. i++;
  222. // for(i=0;i<nPenWidth;i++)
  223. if(i==5)
  224. {   pDC->MoveTo(flX[0],flY[0]);
  225. pDC->LineTo(xc+x,yc+y);
  226. pDC->MoveTo(flX[1],flY[1]);
  227. pDC->LineTo(xc+x,yc-y);
  228. pDC->MoveTo(flX[2],flY[2]);
  229. pDC->LineTo(xc-x,yc+y);
  230. pDC->MoveTo(flX[3],flY[3]);
  231. pDC->LineTo(xc-x,yc-y);
  232. pDC->MoveTo(flX[4],flY[4]);
  233. pDC->LineTo(xc+y,yc+x);
  234. pDC->MoveTo(flX[5],flY[5]);
  235. pDC->LineTo(xc+y,yc-x);
  236. pDC->MoveTo(flX[6],flY[6]);
  237. pDC->LineTo(xc-y,yc+x);
  238. pDC->MoveTo(flX[7],flY[7]);
  239. pDC->LineTo(xc-y,yc-x);
  240. flX[0]=xc+x;
  241. flX[1]=xc+x;
  242. flX[2]=xc-x;
  243. flX[3]=xc-x;
  244. flX[4]=xc+y;
  245. flX[5]=xc+y;
  246. flX[6]=xc-y;
  247. flX[7]=xc-y;
  248. flY[0]=yc+y;
  249. flY[1]=yc-y;
  250. flY[2]=yc+y;
  251. flY[3]=yc-y;
  252. flY[4]=yc+x;
  253. flY[5]=yc-x;
  254. flY[6]=yc+x;
  255. flY[7]=yc-x;
  256. i=0;
  257. }
  258. if(di<0)
  259. {
  260. di+=4*x+6;
  261. }
  262. else
  263. {
  264. di+=4*(x-y)+10;
  265. y--;
  266. }
  267. x++;
  268. }
  269. pDC->MoveTo(flX[0],flY[0]);
  270. pDC->LineTo(xc+x,yc+y);
  271. pDC->MoveTo(flX[1],flY[1]);
  272. pDC->LineTo(xc+x,yc-y);
  273. pDC->MoveTo(flX[2],flY[2]);
  274. pDC->LineTo(xc-x,yc+y);
  275. pDC->MoveTo(flX[3],flY[3]);
  276. pDC->LineTo(xc-x,yc-y);
  277. pDC->MoveTo(flX[4],flY[4]);
  278. pDC->LineTo(xc+y,yc+x);
  279. pDC->MoveTo(flX[5],flY[5]);
  280. pDC->LineTo(xc+y,yc-x);
  281. pDC->MoveTo(flX[6],flY[6]);
  282. pDC->LineTo(xc-y,yc+x);
  283. pDC->MoveTo(flX[7],flY[7]);
  284. pDC->LineTo(xc-y,yc-x);
  285. }
  286. ///////////
  287. void CCircle::FillBreCircle(CDC *pDC,CPoint ptCenter,int flRadius,int penWidth)
  288. {
  289. int x,y,xc,yc,r,di,i;    
  290. xc=ptCenter.x;
  291. yc=ptCenter.y;
  292. x=xc+flRadius;
  293. y=yc;
  294. r=flRadius;
  295. x=0;
  296. y=r;
  297. di=3-2*r;
  298. while(x<=y)
  299. {
  300. pDC->MoveTo(xc+x,yc+y);
  301.         pDC->LineTo(xc+x,yc-y);
  302.     pDC->MoveTo(xc+y,yc+x);
  303. pDC->LineTo(xc+y,yc-x);
  304. pDC->MoveTo(xc-x,yc+y);
  305.         pDC->LineTo(xc-x,yc-y);
  306. pDC->MoveTo(xc-y,yc+x);
  307. pDC->LineTo(xc-y,yc-x);
  308. if(di<0)
  309. {
  310. di+=4*x+6;
  311. }
  312. else
  313. {
  314. di+=4*(x-y)+10;
  315. y-=1;
  316. }
  317. x+=1;
  318. }
  319. }
  320. ////////////////////////////////////////////////////////////////////////////
  321. ////////////////////////////////////////////////////////////////////////////
  322. void CCircle::RefreshData(bool bRefresh)
  323. {
  324. if(bRefresh){
  325. m_flRadius=m_flRadiusTemp;
  326. m_flCenterx=m_flCenterxTemp;
  327. m_flCentery=m_flCenteryTemp;
  328. m_bModified=FALSE;
  329. m_ptMagnifyCenterTemp=CPoint(0,0);
  330. m_flScaleTemp=1;
  331. m_ptRotateCenterTemp=CPoint(0,0);
  332. m_flAngleTemp=0;
  333. }
  334. }
  335. void CCircle::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
  336. {
  337. if(flArrayX.GetSize()<2){
  338. return;
  339. }
  340. CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
  341. m_flRadiusTemp=m_flRadius=GetDistance(flArrayX.GetAt(0),flArrayY.GetAt(0),flArrayX.GetAt(1),flArrayY.GetAt(1));
  342. m_flCenterx=m_flCenterxTemp=flArrayX.GetAt(0);
  343. m_flCentery=m_flCenteryTemp=flArrayY.GetAt(0);
  344. TRACE("m_flRadius=%fn",m_flRadius);
  345. return;
  346. }
  347. void CCircle::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
  348. {
  349. if(ptArray.GetSize()<2){
  350. return;
  351. }
  352. CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
  353. m_flRadiusTemp=m_flRadius=GetDistance(ptArray.GetAt(0),ptArray.GetAt(1));
  354. m_flCenterx=m_flCenterxTemp=((CPoint)ptArray.GetAt(0)).x;
  355. m_flCentery=m_flCenteryTemp=((CPoint)ptArray.GetAt(0)).y;
  356. return;
  357. }
  358. //   特殊化处理,第二个点x值保存半径长度
  359. void CCircle::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
  360. {
  361. m_flCenterx=m_flCenterxTemp=((float)flArrayX.GetAt(0));
  362. m_flCentery=m_flCenteryTemp=((float)flArrayY.GetAt(0));
  363. m_flRadius=m_flRadiusTemp=flArrayX.GetAt(1);    
  364. }
  365. //   特殊化处理,第二个点x值保存半径长度
  366. void CCircle::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
  367. {
  368. flArrayX.RemoveAll();
  369. flArrayY.RemoveAll();
  370. flArrayX.Add(m_flCenterxTemp);
  371. flArrayX.Add(m_flRadiusTemp);
  372. flArrayY.Add(m_flCenteryTemp);
  373. flArrayY.Add(m_flRadiusTemp);
  374. }
  375. CShape* CCircle::GetCopy()
  376. {
  377. CShape* pGraph=new CCircle(this);
  378. return pGraph;  
  379. }
  380. ////////////////////////////////////////////////////////////////////////////
  381. ////////////////////////////////////////////////////////////////////////////
  382. void CCircle::Move(CDC *pDC,float stepx,float stepy)
  383. {
  384. RefreshData(m_bModified);
  385. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  386. m_flCenterx+=stepx;
  387. m_flCentery+=stepy;
  388. //temp
  389. m_flCenterxTemp+=stepx;
  390. m_flCenteryTemp+=stepy;
  391. }
  392. void CCircle::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
  393. {
  394. RefreshData(m_bModified);
  395.     if(m_nSelectPtNum==1){
  396. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  397. m_flRadiusTemp=GetDistance(CurX,CurY,m_flCenterxTemp,m_flCenteryTemp);
  398. m_flRadius=m_flRadiusTemp; 
  399. m_flRadiusTemp=GetDistance(CurX,CurY,m_flCenterxTemp,m_flCenteryTemp);
  400. m_flRadius=m_flRadiusTemp; 
  401. // CShape::Draw(pDC);
  402.     }else if(m_nSelectPtNum==0){
  403. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  404. m_flCenterxTemp=CurX;
  405. m_flCenteryTemp=CurY;
  406. m_flCenterx=CurX;
  407. m_flCentery=CurY;
  408. // CShape::Draw(pDC);
  409.     }
  410. }
  411. void CCircle::Rotate(CDC *pDC,float CX,float CY,float flAngle)
  412. {
  413. if(m_flScaleTemp!=1){
  414. RefreshData(TRUE);
  415. }
  416. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  417. m_ptRotateCenterTemp=CPoint(CX,CY);
  418. m_flAngleTemp=flAngle;
  419. m_bModified=TRUE;
  420. m_flCenterxTemp=((m_flCenterx-CX)*cos(flAngle)-(m_flCentery-CY)*sin(flAngle))+CX;
  421. m_flCenteryTemp=((m_flCentery-CY)*cos(flAngle)+(m_flCenterx-CX)*sin(flAngle))+CY;
  422. }
  423. void CCircle::Magnify(CDC *pDC,float CX,float CY,float flScale)
  424. {
  425. if(m_flAngleTemp!=0){
  426. RefreshData(TRUE);
  427. }
  428. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));  
  429. m_ptMagnifyCenterTemp=CPoint(CX,CY);
  430. m_flScaleTemp=flScale;
  431. m_bModified=TRUE;
  432. m_flCenterxTemp=(m_flCenterx-CX)*flScale+CX;
  433. m_flCenteryTemp=(m_flCentery-CY)*flScale+CY;
  434. m_flRadiusTemp=m_flRadius*flScale;
  435. }
  436. void CCircle::TopToBottom(CDC* pDC,CRect rect)
  437. {
  438. RefreshData(m_bModified);
  439. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  440. m_flCenteryTemp=rect.top/1000.0+rect.bottom/1000.0-m_flCenteryTemp;
  441. m_flCentery=rect.top/1000.0+rect.bottom/1000.0-m_flCentery;
  442. // CShape::Draw(pDC);
  443. }
  444. void CCircle::LeftToRight(CDC* pDC,CRect rect)
  445. {
  446. RefreshData(m_bModified);
  447. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  448. m_flCenterxTemp=rect.left/1000.0+rect.right/1000.0-m_flCenterxTemp;
  449. m_flCenterx=rect.left/1000.0+rect.right/1000.0-m_flCenterx;
  450. // CShape::Draw(pDC);
  451. ///
  452. ////////////////////////////////////////////////////////////////////////////
  453. ////////////////////////////////////////////////////////////////////////////
  454. int CCircle::IsInRect(CRect rect)
  455. {
  456. int nRltVal=0;
  457. CPoint ptRectLT=rect.TopLeft();
  458. CPoint ptRectRB=rect.BottomRight();
  459. CPoint ptRectLB,ptRectRT;
  460. ptRectLB.x=rect.left;
  461. ptRectLB.y=rect.bottom;
  462. ptRectRT.x=rect.right;
  463. ptRectRT.y=rect.top;
  464. CPoint ptCircleCenter(m_flCenterxTemp,m_flCenteryTemp);
  465.     
  466. //求四条矩形边是否有和圆相交/在圆内
  467. float flX[4][2],flY[4][2];
  468. flY[0][0]=rect.top;
  469. flY[1][0]=rect.bottom;
  470. flY[0][1]=rect.top;
  471. flY[1][1]=rect.bottom;
  472. if(rect.left>m_flCenterxTemp){
  473. flX[0][0]=rect.left;
  474. flX[1][0]=rect.left;
  475. flX[0][1]=rect.right;
  476. flX[1][1]=rect.right;
  477. }else if(rect.right<m_flCenterxTemp) {
  478. flX[0][0]=rect.right;
  479. flX[1][0]=rect.right;
  480. flX[0][1]=rect.left;
  481. flX[1][1]=rect.left;
  482. }else{
  483. flX[0][0]=m_flCenterxTemp;
  484. flX[1][0]=m_flCenterxTemp;
  485. if(m_flCenterxTemp-rect.left > rect.right-m_flCenterxTemp){
  486. flX[0][1]=rect.left;
  487. flX[1][1]=rect.left;
  488. }else{
  489. flX[0][1]=rect.right;
  490. flX[1][1]=rect.right;
  491. }
  492. }
  493. flX[2][0]=rect.left;
  494. flX[3][0]=rect.right;
  495. flX[2][1]=rect.left;
  496. flX[3][1]=rect.right;
  497. if(rect.top>m_flCenteryTemp){
  498. flY[2][0]=rect.top;
  499. flY[3][0]=rect.top;
  500. flY[2][1]=rect.bottom;
  501. flY[3][1]=rect.bottom;
  502. }else if(rect.bottom<m_flCenteryTemp) {
  503. flY[2][0]=rect.bottom;
  504. flY[3][0]=rect.bottom;
  505. flY[2][1]=rect.top;
  506. flY[3][1]=rect.top;
  507. }else{
  508. flY[2][0]=m_flCenteryTemp;
  509. flY[3][0]=m_flCenteryTemp;
  510. if(m_flCenteryTemp-rect.top > rect.bottom-m_flCenteryTemp){
  511. flX[2][1]=rect.top;
  512. flX[3][1]=rect.top;
  513. }else{
  514. flX[2][1]=rect.bottom;
  515. flX[3][1]=rect.bottom;
  516. }
  517. }
  518. int flag=0;
  519. if(GetDistance(flX[0][0],flY[0][0],m_flCenterxTemp,m_flCenteryTemp)<=m_flRadiusTemp){
  520. if(GetDistance(flX[0][1],flY[0][1],m_flCenterxTemp,m_flCenteryTemp)>m_flRadiusTemp){
  521. nRltVal|=1;//cut
  522. }else{
  523. nRltVal|=2;
  524. }
  525. }else{
  526. flag++;
  527. }
  528. if(GetDistance(flX[1][0],flY[1][0],m_flCenterxTemp,m_flCenteryTemp)<=m_flRadiusTemp){
  529. if(GetDistance(flX[1][1],flY[1][1],m_flCenterxTemp,m_flCenteryTemp)>m_flRadiusTemp){
  530. nRltVal|=1;//cut
  531. }else{
  532. nRltVal|=2;
  533. }
  534. }else{
  535. flag++;
  536. }
  537. if(GetDistance(flX[2][0],flY[2][0],m_flCenterxTemp,m_flCenteryTemp)<=m_flRadiusTemp){
  538. if(GetDistance(flX[2][1],flY[2][1],m_flCenterxTemp,m_flCenteryTemp)>m_flRadiusTemp){
  539. nRltVal|=1;//cut
  540. }else{
  541. nRltVal|=2;
  542. }
  543. }else{
  544. flag++;
  545. }
  546. if(GetDistance(flX[3][0],flY[3][0],m_flCenterxTemp,m_flCenteryTemp)<=m_flRadiusTemp){
  547. if(GetDistance(flX[3][1],flY[3][1],m_flCenterxTemp,m_flCenteryTemp)>m_flRadiusTemp){
  548. nRltVal|=1;//cut
  549. }else{
  550. nRltVal|=2;
  551. }
  552. }else{
  553. flag++;
  554. }
  555. if(nRltVal==3){
  556. nRltVal=1;
  557. }
  558. if(nRltVal==2&&m_nFillStyle==_shape_none_fill){
  559. nRltVal=0;
  560. }
  561. if(flag==4&&rect.PtInRect(ptCircleCenter)){
  562. nRltVal=2;
  563. }
  564. return nRltVal;
  565. }
  566. CRect CCircle::GetBoundaryRect()
  567. {
  568. CRect rect;
  569. rect.left=1000*(m_flCenterxTemp-m_flRadiusTemp);
  570. rect.right=1000*(m_flCenterxTemp+m_flRadiusTemp);
  571. rect.top=1000*(m_flCenteryTemp-m_flRadiusTemp);
  572. rect.bottom=1000*(m_flCenteryTemp+m_flRadiusTemp);
  573. return rect;
  574. }
  575. CPoint CCircle::GetCenterPoint()
  576. {
  577. CPoint ptCenter(m_flCenterxTemp,m_flCenteryTemp);
  578. return ptCenter;
  579. }
  580. int CCircle::IsPointinRegion(POINT point)
  581. {
  582. CPoint ptCenter(m_flCenterxTemp,m_flCenteryTemp);
  583. if(GetDistance(ptCenter,point)>m_flRadiusTemp)
  584. return 0;
  585. return 1;
  586. }
  587. //////
  588. int CCircle::GetPtState(float flx,float fly,float flRate)
  589. {
  590. CPoint ptCenter(m_flCenterxTemp,m_flCenteryTemp);
  591. if(fabs(GetDistance(m_flCenterxTemp,m_flCenteryTemp,flx,fly)-m_flRadiusTemp) <= 3.0*flRate)
  592. {
  593. m_nSelectPtNum=1;
  594. return 1;
  595. }
  596. if(IsPtInRect(m_flCenterxTemp-3*flRate,m_flCenteryTemp-3*flRate,m_flCenterxTemp+3*flRate,m_flCenteryTemp+3*flRate,flx,fly)){
  597. m_nSelectPtNum=0;
  598. return 1;
  599. }
  600. m_nSelectPtNum=-1;
  601. return 0;
  602. }
  603. //////////////////////////////////////////////////////////////////////
  604. // MODULE   :ExPort
  605. // ABSTRACT :Export to a txt file
  606. // FUNCTION :File->Export...
  607. // NOTE     :
  608. // RETURN   :
  609. // ARGUMENTS:
  610. //              I/O           TYPE      NAME       EXPLANATION
  611. //               O            FILE*    outStream    Out put File
  612. // CREATE   :  FNST)handwolf  2004-4-14
  613. // UPDATE   :  
  614. //          : 
  615. //////////////////////////////////////////////////////////////////////
  616. void CCircle::ExPort(FILE* outStream)//增加导出txt功能时用
  617. {
  618. fprintf(outStream, " CCircle n");
  619. CShape::ExPort(outStream);
  620. fprintf( outStream, " %f %f %f n",m_flRadius,m_flCenterx,m_flCentery);
  621. }
  622. //////////////////////////////////////////////////////////////////////
  623. // MODULE   :ImPort
  624. // ABSTRACT :ImPort from a txt file
  625. // FUNCTION :File->ImPort...
  626. // NOTE     :
  627. // RETURN   :
  628. // ARGUMENTS:
  629. //              I/O           TYPE      NAME       EXPLANATION
  630. //               I            FILE*    inStream    in put File
  631. // CREATE   :  FNST)handwolf  2004-4-14
  632. // UPDATE   :  
  633. //          : 
  634. //////////////////////////////////////////////////////////////////////
  635. void CCircle::ImPort(FILE* inStream)
  636. {
  637. CShape::ImPort(inStream);
  638.     fscanf(inStream, "%f %f %f",&m_flRadius,&m_flCenterx,&m_flCentery);
  639.     m_flRadiusTemp=m_flRadius;
  640. m_flCenterxTemp=m_flCenterx;
  641. m_flCenteryTemp=m_flCentery;
  642. }
  643. CString CCircle::GetNameString()
  644. {
  645. CString str;
  646. str.LoadString(IDS_CIRCLE);
  647. return str;
  648. }
  649. //////////////////////////////////////////////////////////////////////
  650. //End of File////////////////
  651. ////////////////////////////////////////////////////////////////////////////
  652. ////////////////////////////////////////////////////////////////////////////