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

绘图程序

开发平台:

Visual C++

  1. // Ellipse.cpp: implementation of the CEllipse class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GraphSoft.h"
  6. #include "Ellipse.h"
  7. #include "math.h"
  8. #include "GlobalFunction.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( CEllipse, CShape, 0 )
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. ///////////////////////////////////////////////////////////////////////
  20. CEllipse::CEllipse():CShape()
  21. {
  22. m_flaTemp=m_fla=0;
  23. m_flbTemp=m_flb=0;
  24. m_flCenterxTemp=m_flCenterx=0;
  25. m_flCenteryTemp=m_flCentery=0;
  26. m_flAnglePrev=0;
  27. }
  28. CEllipse::CEllipse(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
  29. {
  30. m_flaTemp=m_fla=0;
  31. m_flbTemp=m_flb=0;
  32. m_flCenterxTemp=m_flCenterx=0;
  33. m_flCenteryTemp=m_flCentery=0;
  34. m_flAnglePrev=angle;
  35. }
  36. CEllipse::CEllipse(CEllipse * const pEllipse):CShape(pEllipse)
  37. {
  38. m_fla=pEllipse->m_fla;
  39. m_flb=pEllipse->m_flb;
  40. m_flCenterx=pEllipse->m_flCenterx;
  41. m_flCentery=pEllipse->m_flCentery;
  42. //
  43. m_flaTemp=pEllipse->m_flaTemp;
  44. m_flbTemp=pEllipse->m_flbTemp;
  45. m_flCenterxTemp=pEllipse->m_flCenterxTemp;
  46. m_flCenteryTemp=pEllipse->m_flCenteryTemp;
  47. m_flAnglePrev=pEllipse->m_flAnglePrev;
  48. }
  49. CEllipse::~CEllipse()
  50. {
  51. }
  52. ////////////////////////////////////////////////////////////////////////// 
  53. void CEllipse::Serialize( CArchive& ar)
  54. {
  55. CShape::Serialize( ar ) ;
  56. if ( ar.IsLoading() ){  
  57. ar>>m_fla;
  58. ar>>m_flb;
  59. ar>>m_flCenterx;
  60. ar>>m_flCentery;
  61. //temp
  62. m_flaTemp=m_fla;
  63. m_flbTemp=m_flb;
  64. m_flCenterxTemp=m_flCenterx;
  65. m_flCenteryTemp=m_flCentery;
  66. m_flAnglePrev=GetAngle();
  67. } else {
  68. ar<<m_fla;
  69. ar<<m_flb;
  70. ar<<m_flCenterx;
  71. ar<<m_flCentery;  
  72. }
  73. return ;
  74. }
  75. ////////////////////////////////////////////////////////////////////////
  76. void CEllipse::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
  77. {
  78. CPen pen,*poldPen;   
  79. float angle=GetAngle();
  80. pen.CreatePen(PS_SOLID,2,fillColor);
  81. poldPen=pDC->SelectObject(&pen);
  82.     
  83. if(m_nFillStyle==_shape_solid_fill){
  84. FillEllipse(pDC,m_flCenterxTemp,m_flCenteryTemp,m_flaTemp,m_flbTemp,angle);
  85. }
  86. pen.DeleteObject();
  87. pen.CreatePen(PS_GEOMETRIC,penWidth, color);  
  88. pDC->SelectObject(&pen);  
  89. BreEllipse(pDC,m_flCenterxTemp,m_flCenteryTemp,m_flaTemp,m_flbTemp,color,angle,penWidth);
  90. if(GetDrawPointsFlag()==1){
  91. DrawPoints(pDC,color);
  92. }
  93. pDC->SelectObject(poldPen);  
  94. }
  95. ///////////////////////////////////////////
  96. void CEllipse::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
  97. {
  98. if(!IsInRect(m_rectFrom)){
  99. return;
  100. }
  101. //得到移动扩缩后的关键数据
  102. float  flCx,flCy,fla,flb;
  103. //移动
  104. float stepx=m_rectTo.left-m_rectFrom.left;
  105. float stepy=m_rectTo.top-m_rectFrom.top;
  106. flCx=m_flCenterxTemp+stepx;
  107. flCy=m_flCenteryTemp+stepy;
  108. fla=m_flaTemp;
  109. flb=m_flbTemp;
  110. //扩缩
  111. float cx,cy,flScale;
  112. cx=m_rectTo.left;
  113. cy=m_rectTo.top;  
  114. if(m_rectFrom.Width()<0.01){
  115. m_rectFrom.right=m_rectFrom.left +1;
  116. }
  117. if(m_rectFrom.Height()<0.01){
  118. m_rectFrom.bottom=m_rectFrom.top +1;
  119. }
  120. flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
  121. // flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
  122. fla=fla*flScale;
  123. flb=flb*flScale;
  124. flCx=(flCx-cx)*flScale+cx;
  125. flCy=(flCy-cy)*flScale+cy;
  126. CPen pen,*poldPen;
  127.     pen.CreatePen(PS_SOLID,1, color);
  128. poldPen=pDC->SelectObject(&pen);
  129. {
  130. pDC->MoveTo(flCx,flCy-1-GetPenWidth());
  131. pDC->LineTo(flCx,flCy+2+GetPenWidth());
  132. pDC->MoveTo(flCx-1-GetPenWidth(),flCy);
  133. pDC->LineTo(flCx+2+GetPenWidth(),flCy);
  134. }  
  135. float flX[4],flY[4];
  136. float a=fla;
  137. float b=flb;
  138. flX[0]=flCx;
  139. flX[1]=flCx;
  140. flX[2]=flCx-a;
  141. flX[3]=flCx+a;
  142. flY[0]=flCy-b;
  143. flY[1]=flCy+b;
  144. flY[2]=flCy;
  145. flY[3]=flCy;
  146. //four peak points
  147. float fx,fy,angle=GetAngle(),cosA,sinA;
  148. cosA=cos(angle);
  149. sinA=sin(angle);
  150. fx=(flX[0]-flCx)*cosA-(flY[0]-flCy)*sinA+flCx;
  151. fy=(flY[0]-flCy)*cosA+(flX[0]-flCx)*sinA+flCy;
  152. flX[0]=fx;
  153. flY[0]=fy;
  154. fx=(flX[1]-flCx)*cosA-(flY[1]-flCy)*sinA+flCx;
  155. fy=(flY[1]-flCy)*cosA+(flX[1]-flCx)*sinA+flCy;
  156. flX[1]=fx;
  157. flY[1]=fy;
  158. fx=(flX[2]-flCx)*cosA-(flY[2]-flCy)*sinA+flCx;
  159. fy=(flY[2]-flCy)*cosA+(flX[2]-flCx)*sinA+flCy;
  160. flX[2]=fx;
  161. flY[2]=fy;
  162. fx=(flX[3]-flCx)*cosA-(flY[3]-flCy)*sinA+flCx;
  163. fy=(flY[3]-flCy)*cosA+(flX[3]-flCx)*sinA+flCy;
  164. flX[3]=fx;
  165. flY[3]=fy;
  166. for(int i=0;i<4;i++){
  167. pDC->MoveTo(flX[i],flY[i]-1-GetPenWidth());
  168. pDC->LineTo(flX[i],flY[i]+2+GetPenWidth());
  169. pDC->MoveTo(flX[i]-1-GetPenWidth(),flY[i]);
  170. pDC->LineTo(flX[i]+2+GetPenWidth(),flY[i]);
  171. }
  172. pDC->SelectObject(poldPen);      
  173. return;
  174. }
  175. void CEllipse::DrawPoints(CDC *pDC,COLORREF color)
  176. {
  177. CPen pen,*poldPen;
  178.     pen.CreatePen(PS_SOLID,1, color);
  179. poldPen=pDC->SelectObject(&pen);
  180. {
  181. pDC->MoveTo(m_flCenterxTemp,m_flCenteryTemp-1-GetPenWidth());
  182. pDC->LineTo(m_flCenterxTemp,m_flCenteryTemp+2+GetPenWidth());
  183. pDC->MoveTo(m_flCenterxTemp-1-GetPenWidth(),m_flCenteryTemp);
  184. pDC->LineTo(m_flCenterxTemp+2+GetPenWidth(),m_flCenteryTemp);
  185. }  
  186. float flX[4],flY[4];
  187. float a=m_flaTemp;
  188. float b=m_flbTemp;
  189. flX[0]=m_flCenterxTemp;
  190. flX[1]=m_flCenterxTemp;
  191. flX[2]=m_flCenterxTemp-a;
  192. flX[3]=m_flCenterxTemp+a;
  193. flY[0]=m_flCenteryTemp-b;
  194. flY[1]=m_flCenteryTemp+b;
  195. flY[2]=m_flCenteryTemp;
  196. flY[3]=m_flCenteryTemp;
  197. //four peak points
  198. float fx,fy,angle=GetAngle(),cosA,sinA;
  199. cosA=cos(angle);
  200. sinA=sin(angle);
  201. fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  202. fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  203. flX[0]=fx;
  204. flY[0]=fy;
  205. fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  206. fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  207. flX[1]=fx;
  208. flY[1]=fy;
  209. fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  210. fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  211. flX[2]=fx;
  212. flY[2]=fy;
  213. fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  214. fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  215. flX[3]=fx;
  216. flY[3]=fy;
  217. for(int i=0;i<4;i++){
  218. pDC->MoveTo(flX[i],flY[i]-1-GetPenWidth());
  219. pDC->LineTo(flX[i],flY[i]+2+GetPenWidth());
  220. pDC->MoveTo(flX[i]-1-GetPenWidth(),flY[i]);
  221. pDC->LineTo(flX[i]+2+GetPenWidth(),flY[i]);
  222. }
  223. pDC->SelectObject(poldPen);      
  224. return;
  225. }
  226. ///////////////////////////////
  227. void CEllipse::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
  228. {
  229. // if(!IsInRect(m_rectFrom)){
  230. // return;
  231. // }
  232. //得到移动扩缩后的关键数据
  233. float  flCx,flCy,fla,flb;
  234. //移动
  235. float stepx=m_rectTo.left-m_rectFrom.left;
  236. float stepy=m_rectTo.top-m_rectFrom.top;
  237. flCx=m_flCenterxTemp+stepx;
  238. flCy=m_flCenteryTemp+stepy;
  239. fla=m_flaTemp;
  240. flb=m_flbTemp;
  241. //扩缩
  242. float cx,cy,flScale;
  243. cx=m_rectTo.left;
  244. cy=m_rectTo.top;  
  245. if(m_rectFrom.Width()<0.01){
  246. m_rectFrom.right=m_rectFrom.left +1;
  247. }
  248. if(m_rectFrom.Height()<0.01){
  249. m_rectFrom.bottom=m_rectFrom.top +1;
  250. }
  251. flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
  252. // flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
  253. fla=fla*flScale;
  254. flb=flb*flScale;
  255. flCx=(flCx-cx)*flScale+cx;
  256. flCy=(flCy-cy)*flScale+cy;
  257. //Draw
  258. CPen pen,*poldPen;    
  259. float angle=GetAngle();
  260. pen.CreatePen(PS_SOLID,2,fillColor);
  261. poldPen=pDC->SelectObject(&pen);    
  262. if(m_nFillStyle==_shape_solid_fill){
  263. FillEllipse(pDC,flCx,flCy,fla,flb,angle);
  264. }
  265. pen.DeleteObject();
  266. pen.CreatePen(PS_GEOMETRIC,penWidth, color);  
  267. pDC->SelectObject(&pen);  
  268. BreEllipse(pDC,flCx,flCy,fla,flb,color,angle,penWidth);
  269. if(GetDrawPointsFlag()==1){
  270. DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
  271. }
  272. pDC->SelectObject(poldPen);
  273. }
  274. ///////////////////////////////////////////////////////////////////////////// 
  275. /*
  276. void CEllipse::BreEllipse(CDC *pDC,CPoint m_pCenter,float fla,float flb,COLORREF color,double angle,int nPenWidth)
  277. {
  278. int i,a,b,x,y;
  279.     double xc,yc,dx,dy,di,aa,bb,sinA,cosA;
  280. cosA=cos(angle);
  281. sinA=sin(angle);
  282. xc=m_pCenter.x;
  283. yc=m_pCenter.y;
  284. a=fla;
  285.     b=flb;
  286. aa=a*a;
  287. bb=b*b;
  288. x=0;
  289. y=b;
  290. dx=0;
  291. dy=2*aa*y;
  292. di=bb-aa*b+aa/4;
  293. while(dx<dy)
  294. {
  295. for(i=0;i<nPenWidth;i++)
  296. {
  297. pDC->SetPixel(xc+x*cosA-y*sinA+i,yc+y*cosA+x*sinA,color);
  298. pDC->SetPixel(xc+x*cosA+y*sinA+i,yc-y*cosA+x*sinA,color);
  299. pDC->SetPixel(xc-x*cosA-y*sinA+i,yc+y*cosA-x*sinA,color);
  300. pDC->SetPixel(xc-x*cosA+y*sinA+i,yc-y*cosA-x*sinA,color);
  301. pDC->SetPixel(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA+i,color);
  302. pDC->SetPixel(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA+i,color);
  303. pDC->SetPixel(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA+i,color);
  304. pDC->SetPixel(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA+i,color);
  305. }
  306. x++;
  307. dx+=2*bb;
  308. di+=dx+bb;
  309. if(di>=0)
  310. {
  311. dy-=2*aa;
  312. di-=dy;
  313. y--;
  314. }
  315. }
  316. di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);
  317. while(y>0)
  318. {
  319. i=0;
  320. for(i=0;i<nPenWidth;i++)
  321. {
  322. pDC->SetPixel(xc+x*cosA-y*sinA+i,yc+y*cosA+x*sinA,color);
  323. pDC->SetPixel(xc+x*cosA+y*sinA+i,yc-y*cosA+x*sinA,color);
  324. pDC->SetPixel(xc-x*cosA-y*sinA+i,yc+y*cosA-x*sinA,color);
  325. pDC->SetPixel(xc-x*cosA+y*sinA+i,yc-y*cosA-x*sinA,color);
  326. pDC->SetPixel(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA+i,color);
  327. pDC->SetPixel(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA+i,color);
  328. pDC->SetPixel(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA+i,color);
  329. pDC->SetPixel(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA+i,color);
  330. }
  331. y--;
  332. dy-=2*aa;
  333. di+=aa-dy;
  334. if(di<0)
  335. {
  336.     dx+=2*bb;
  337. di+=dx;
  338. x++;
  339. }
  340. }
  341. }
  342. */
  343. void CEllipse::BreEllipse(CDC *pDC,float xc ,float yc,float fla,float flb,COLORREF color,double angle,int nPenWidth)
  344. {
  345. int i;
  346. float a,b,x,y;
  347.     double dx,dy,di,aa,bb,sinA,cosA;
  348. cosA=cos(angle);
  349. sinA=sin(angle);
  350. a=fla;
  351.     b=flb;
  352. aa=a*a;
  353. bb=b*b;
  354. float flX[4],flY[4];
  355. x=0;
  356. y=b;
  357. dx=0;
  358. dy=2*aa*y;
  359. di=bb-aa*b+aa/4;
  360. flX[0]=xc+x*cosA-y*sinA;
  361. flX[1]=xc+x*cosA+y*sinA;
  362. flX[2]=xc-x*cosA-y*sinA;
  363. flX[3]=xc-x*cosA+y*sinA;
  364. flY[0]=yc+y*cosA+x*sinA;
  365. flY[1]=yc-y*cosA+x*sinA;
  366. flY[2]=yc+y*cosA-x*sinA;
  367. flY[3]=yc-y*cosA-x*sinA;
  368. i=0;
  369. while(dx<dy)
  370. {
  371. i++;
  372. if(i==5)
  373. {
  374. pDC->MoveTo(flX[0],flY[0]);
  375. pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
  376. pDC->MoveTo(flX[1],flY[1]);
  377. pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
  378. pDC->MoveTo(flX[2],flY[2]);
  379. pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
  380. pDC->MoveTo(flX[3],flY[3]);
  381. pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
  382. flX[0]=xc+x*cosA-y*sinA;
  383. flX[1]=xc+x*cosA+y*sinA;
  384. flX[2]=xc-x*cosA-y*sinA;
  385. flX[3]=xc-x*cosA+y*sinA;
  386. flY[0]=yc+y*cosA+x*sinA;
  387. flY[1]=yc-y*cosA+x*sinA;
  388. flY[2]=yc+y*cosA-x*sinA;
  389. flY[3]=yc-y*cosA-x*sinA;
  390. i=0;
  391. }
  392. x++;
  393. dx+=2*bb;
  394. di+=dx+bb;
  395. if(di>=0)
  396. {
  397. dy-=2*aa;
  398. di-=dy;
  399. y--;
  400. }
  401. }
  402. pDC->MoveTo(flX[0],flY[0]);
  403. pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
  404. pDC->MoveTo(flX[1],flY[1]);
  405. pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
  406. pDC->MoveTo(flX[2],flY[2]);
  407. pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
  408. pDC->MoveTo(flX[3],flY[3]);
  409. pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
  410. di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);
  411. flX[0]=xc+x*cosA-y*sinA;
  412. flX[1]=xc+x*cosA+y*sinA;
  413. flX[2]=xc-x*cosA-y*sinA;
  414. flX[3]=xc-x*cosA+y*sinA;
  415. flY[0]=yc+y*cosA+x*sinA;
  416. flY[1]=yc-y*cosA+x*sinA;
  417. flY[2]=yc+y*cosA-x*sinA;
  418. flY[3]=yc-y*cosA-x*sinA;
  419. i=0;
  420. while(y>0)
  421. {
  422. i++;
  423. if(i==5)
  424. {
  425. pDC->MoveTo(flX[0],flY[0]);
  426. pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
  427. pDC->MoveTo(flX[1],flY[1]);
  428. pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
  429. pDC->MoveTo(flX[2],flY[2]);
  430. pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
  431. pDC->MoveTo(flX[3],flY[3]);
  432. pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
  433. flX[0]=xc+x*cosA-y*sinA;
  434. flX[1]=xc+x*cosA+y*sinA;
  435. flX[2]=xc-x*cosA-y*sinA;
  436. flX[3]=xc-x*cosA+y*sinA;
  437. flY[0]=yc+y*cosA+x*sinA;
  438. flY[1]=yc-y*cosA+x*sinA;
  439. flY[2]=yc+y*cosA-x*sinA;
  440. flY[3]=yc-y*cosA-x*sinA;
  441. i=0;
  442. }
  443. y--;
  444. dy-=2*aa;
  445. di+=aa-dy;
  446. if(di<0)
  447. {
  448. dx+=2*bb;
  449. di+=dx;
  450. x++;
  451. }
  452. }
  453. pDC->MoveTo(flX[0],flY[0]);
  454. pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
  455. pDC->MoveTo(flX[1],flY[1]);
  456. pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
  457. pDC->MoveTo(flX[2],flY[2]);
  458. pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
  459. pDC->MoveTo(flX[3],flY[3]);
  460. pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
  461. }
  462. ///////////////////////////////////////////////////////////////////////////// 
  463. void CEllipse::FillEllipse(CDC *pDC,float xc ,float yc,float fla,float flb,double angle)
  464. {
  465. int i;
  466. double a,b,x,y;
  467.     double dx,dy,di,aa,bb,sinA,cosA;
  468. cosA=cos(angle);
  469. sinA=sin(angle);
  470. a=fla;
  471.     b=flb;
  472. aa=a*a;
  473. bb=b*b;
  474. x=0;
  475. y=b;
  476. dx=0;
  477. dy=2*aa*y;
  478. di=bb-aa*b+aa/4;
  479. while(dx<dy)
  480. {
  481. pDC->MoveTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);  
  482. pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
  483.         pDC->MoveTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
  484. pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
  485. x++;
  486. dx+=2*bb;
  487. di+=dx+bb;
  488. if(di>=0)
  489. {
  490. dy-=2*aa;
  491. di-=dy;
  492. y--;
  493. }
  494. }
  495. di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);
  496. while(y>=0)
  497. {
  498. pDC->MoveTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
  499. pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
  500. pDC->MoveTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
  501. pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
  502. y--;
  503. dy-=2*aa;
  504. di+=aa-dy;
  505. if(di<0)
  506. {
  507. dx+=2*bb;
  508. di+=dx;
  509. x++;
  510. }
  511. }
  512. }
  513. ////////////////////////////////////////////////////////////////////////////
  514. ////////////////////////////////////////////////////////////////////////////
  515. void CEllipse::RefreshData(bool bRefresh)
  516. {
  517. if(bRefresh){
  518. m_fla=m_flaTemp;
  519. m_flb=m_flbTemp;
  520. m_flCenterx=m_flCenterxTemp;
  521. m_flCentery=m_flCenteryTemp;
  522. m_flAnglePrev=GetAngle();
  523. m_bModified=FALSE;
  524. m_ptMagnifyCenterTemp=CPoint(0,0);
  525. m_flScaleTemp=1;
  526. m_ptRotateCenterTemp=CPoint(0,0);
  527. m_flAngleTemp=0;
  528. }
  529. }
  530. void CEllipse::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
  531. {
  532. if(flArrayX.GetSize()<2){
  533. return;
  534. }
  535. CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
  536. m_flCenterx=m_flCenterxTemp=(flArrayX.GetAt(0));
  537. m_flCentery=m_flCenteryTemp=(flArrayY.GetAt(0));
  538. m_fla=m_flaTemp=fabs((sqrt(2.0)*(float(flArrayX.GetAt(1)-flArrayX.GetAt(0)))));
  539.     m_flb=m_flbTemp=fabs((sqrt(2.0)*(float(flArrayY.GetAt(1)-flArrayY.GetAt(0)))));
  540. m_flAnglePrev=GetAngle();
  541. }
  542. void CEllipse::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
  543. {
  544. if(ptArray.GetSize()<2){
  545. return;
  546. }
  547. CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
  548. m_flCenterx=m_flCenterxTemp=((CPoint)ptArray.GetAt(0)).x;
  549. m_flCentery=m_flCenteryTemp=((CPoint)ptArray.GetAt(0)).y;
  550. m_fla=m_flaTemp=sqrt(2)*fabs(((CPoint)ptArray.GetAt(1)).x-m_flCenterx);
  551.     m_flb=m_flbTemp=sqrt(2)*fabs(((CPoint)ptArray.GetAt(1)).y-m_flCentery);
  552. m_flAnglePrev=GetAngle();
  553. }
  554. //   特殊化处理,这里第二个点保存两条直径的长度
  555. void CEllipse::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
  556. {
  557. m_flCenterx=m_flCenterxTemp=((float)flArrayX.GetAt(0));
  558. m_flCentery=m_flCenteryTemp=((float)flArrayY.GetAt(0));
  559. m_fla=m_flaTemp=flArrayX.GetAt(1);
  560.     m_flb=m_flbTemp=flArrayY.GetAt(1);
  561. }
  562. //   特殊化处理,这里第二个点保存两条直径的长度
  563. void CEllipse::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
  564. {
  565. flArrayX.RemoveAll();
  566. flArrayY.RemoveAll();
  567. flArrayX.Add(m_flCenterxTemp);
  568. flArrayX.Add(m_flaTemp);
  569. flArrayY.Add(m_flCenteryTemp);
  570. flArrayY.Add(m_flbTemp);
  571. }
  572. CShape* CEllipse::GetCopy()
  573. {
  574. CShape* pGraph=new CEllipse(this);
  575. return pGraph;  
  576. }
  577. ////////////////////////////////////////////////////////////////////////////
  578. ////////////////////////////////////////////////////////////////////////////
  579. void CEllipse::Move(CDC *pDC,float stepx,float stepy)
  580. {
  581. RefreshData(m_bModified);
  582. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  583. m_flCenterx+=stepx;
  584. m_flCentery+=stepy;
  585. //temp
  586. m_flCenterxTemp+=stepx;
  587. m_flCenteryTemp+=stepy;
  588. }
  589. void CEllipse::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
  590. {
  591. //RefreshData(m_bModified);
  592.     if(m_nSelectPtNum>-1){
  593. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  594. //上下左右四顶点
  595. float flX[4],flY[4];
  596. float a=m_flaTemp;
  597. float b=m_flbTemp;
  598. flX[0]=m_flCenterxTemp;
  599. flX[1]=m_flCenterxTemp;
  600. flX[2]=m_flCenterxTemp-a;
  601. flX[3]=m_flCenterxTemp+a;
  602. flY[0]=m_flCenteryTemp-b;
  603. flY[1]=m_flCenteryTemp+b;
  604. flY[2]=m_flCenteryTemp;
  605. flY[3]=m_flCenteryTemp;
  606. float fx,fy,angle=GetAngle(),cosA,sinA;
  607. cosA=cos(angle);
  608. sinA=sin(angle);
  609. fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  610. fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  611. flX[0]=fx;
  612. flY[0]=fy;
  613. fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  614. fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  615. flX[1]=fx;
  616. flY[1]=fy;
  617. fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  618. fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  619. flX[2]=fx;
  620. flY[2]=fy;
  621. fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  622. fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  623. flX[3]=fx;
  624. flY[3]=fy;
  625. switch(m_nSelectPtNum) {
  626. case 0:
  627. // m_flCenterx+=point.x-ptPrev.x;
  628. // m_flCentery+=point.y-ptPrev.y;
  629. //temp
  630. m_flCenterxTemp+=CurX-PrevX;
  631. m_flCenteryTemp+=CurY-PrevY;
  632. break;
  633. case 1:
  634. case 2:
  635. {
  636. m_flbTemp=GetDisFromPtToLine(CurX,CurY,flX[2],flY[2],flX[3],flY[3]);
  637. break;
  638. }
  639. case 3:
  640. case 4:
  641. {
  642. m_flaTemp=GetDisFromPtToLine(CurX,CurY,flX[0],flY[0],flX[1],flY[1]);
  643. break;
  644. }
  645. break;
  646. default:
  647. break;
  648. }
  649. //CShape::Draw(pDC);
  650.     }else if(m_nSelectLineNum>-1){
  651. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  652. float dis1,dis2;
  653. dis1=GetDistance(m_flCenterxTemp,m_flCenteryTemp,PrevX,PrevY);
  654. dis2=GetDistance(m_flCenterxTemp,m_flCenteryTemp,CurX,CurY);
  655. if(dis1<0.1){
  656. dis1+=1;
  657. }
  658. if(dis2<0.1){
  659. dis2+=1;
  660. }
  661. m_flaTemp=dis2*m_flaTemp/dis1;
  662. m_flbTemp=dis2*m_flbTemp/dis1;
  663.     }
  664. }
  665. void CEllipse::Rotate(CDC *pDC,float CX, float CY, float flAngle)
  666. {
  667. if(m_flScaleTemp!=1){
  668. RefreshData(TRUE);
  669. }
  670. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  671. m_ptRotateCenterTemp=CPoint(CX,CY);
  672. m_flAngleTemp=flAngle;
  673. m_bModified=TRUE;
  674. SetAngle(m_flAnglePrev+flAngle);
  675. m_flCenterxTemp=((m_flCenterx-CX)*cos(flAngle)-(m_flCentery-CY)*sin(flAngle))+CX;
  676. m_flCenteryTemp=((m_flCentery-CY)*cos(flAngle)+(m_flCenterx-CX)*sin(flAngle))+CY;
  677. }
  678. void CEllipse::Magnify(CDC *pDC,float CX,float CY,float flScale)
  679. {
  680. if(m_flAngleTemp!=0){
  681. RefreshData(TRUE);
  682. }
  683. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  684. m_ptMagnifyCenterTemp=CPoint(CX,CY);
  685. m_flScaleTemp=flScale;
  686. m_bModified=TRUE;
  687. m_flaTemp=m_fla*flScale;
  688. m_flbTemp=m_flb*flScale;
  689. m_flCenterxTemp=(m_flCenterx-CX)*flScale+CX;
  690. m_flCenteryTemp=(m_flCentery-CY)*flScale+CY;
  691. }
  692. void CEllipse::TopToBottom(CDC* pDC,CRect rect)
  693. {
  694. RefreshData(m_bModified);
  695. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  696. m_flAnglePrev=GetAngle();
  697. m_flAnglePrev=-m_flAnglePrev;
  698. SetAngle(m_flAnglePrev);
  699. m_flCenteryTemp=rect.top/1000.0+rect.bottom/1000.0-m_flCenteryTemp;
  700. m_flCentery=rect.top/1000.0+rect.bottom/1000.0-m_flCentery;
  701. // CShape::Draw(pDC);
  702. }
  703. void CEllipse::LeftToRight(CDC* pDC,CRect rect)
  704. {
  705. RefreshData(m_bModified);
  706. // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
  707. m_flAnglePrev=GetAngle();
  708. m_flAnglePrev=PI-m_flAnglePrev;
  709. SetAngle(m_flAnglePrev);
  710. m_flCenterxTemp=rect.left/1000.0+rect.right/1000.0-m_flCenterxTemp;
  711. m_flCenterx=rect.left/1000.0+rect.right/1000.0-m_flCenterx;
  712. // CShape::Draw(pDC);
  713. ///
  714. ////////////////////////////////////////////////////////////////////////////
  715. ////////////////////////////////////////////////////////////////////////////
  716. int CEllipse::IsInRect(CRect rect)
  717. {
  718. int nRltVal=0;
  719. CPoint ptRectLT=rect.TopLeft();
  720. CPoint ptRectRB=rect.BottomRight();
  721. CPoint ptRectLB,ptRectRT;
  722. ptRectLB.x=rect.left;
  723. ptRectLB.y=rect.bottom;
  724. ptRectRT.x=rect.right;
  725. ptRectRT.y=rect.top;
  726. CPoint ptCircleCenter(m_flCenterxTemp,m_flCenteryTemp);
  727. int flag =0;
  728. if(IsPointinRegion(ptRectLT)){
  729. flag++;
  730. }
  731. if(IsPointinRegion(ptRectRB)){
  732. flag++;
  733. }
  734. if(IsPointinRegion(ptRectLB)){
  735. flag++;
  736. }
  737. if(IsPointinRegion(ptRectRT)){
  738. flag++;
  739. }
  740.     if(0<flag&&flag<4){
  741. nRltVal=1;
  742.     }else if(flag==4&&m_nFillStyle==_shape_solid_fill){
  743. nRltVal=3;
  744.     }else if(flag==0){//判断矩形与长短直径的关系
  745. float flX[4],flY[4];
  746. float a=m_flaTemp;
  747. float b=m_flbTemp;
  748. flX[0]=m_flCenterxTemp;
  749. flX[1]=m_flCenterxTemp;
  750. flX[2]=m_flCenterxTemp-a;
  751. flX[3]=m_flCenterxTemp+a;
  752. flY[0]=m_flCenteryTemp-b;
  753. flY[1]=m_flCenteryTemp+b;
  754. flY[2]=m_flCenteryTemp;
  755. flY[3]=m_flCenteryTemp;
  756. float fx,fy,angle=GetAngle(),cosA,sinA;
  757. cosA=cos(angle);
  758. sinA=sin(angle);
  759. fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  760. fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  761.     flX[0]=fx;
  762. flY[0]=fy;
  763. fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  764. fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  765. flX[1]=fx;
  766. flY[1]=fy;
  767. fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  768. fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  769. flX[2]=fx;
  770. flY[2]=fy;
  771. fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  772. fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  773. flX[3]=fx;
  774. flY[3]=fy;
  775. flag=0;
  776. flag|=GetLineStateToRect(flX[0],flY[0],flX[1],flY[1],rect);
  777. flag|=GetLineStateToRect(flX[2],flY[2],flX[3],flY[3],rect);
  778. if(flag==1||flag==3){
  779. nRltVal=1;
  780. }else if(flag==2){
  781. nRltVal=2;
  782. }
  783.     }
  784. return nRltVal;
  785. }
  786. CRect CEllipse::GetBoundaryRect()
  787. {
  788. CRect rect;
  789. float flX[4],flY[4];
  790. float a=m_flaTemp;
  791. float b=m_flbTemp;
  792. flX[0]=m_flCenterxTemp;
  793. flX[1]=m_flCenterxTemp;
  794. flX[2]=m_flCenterxTemp-a;
  795. flX[3]=m_flCenterxTemp+a;
  796. flY[0]=m_flCenteryTemp-b;
  797. flY[1]=m_flCenteryTemp+b;
  798. flY[2]=m_flCenteryTemp;
  799. flY[3]=m_flCenteryTemp;
  800. float fx,fy,angle=GetAngle(),cosA,sinA;
  801. cosA=cos(angle);
  802. sinA=sin(angle);
  803. fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  804. fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  805. flX[0]=fx;
  806. flY[0]=fy;
  807. fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  808. fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  809. flX[1]=fx;
  810. flY[1]=fy;
  811. fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  812. fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  813. flX[2]=fx;
  814. flY[2]=fy;
  815. fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  816. fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  817. flX[3]=fx;
  818. flY[3]=fy;
  819. rect.left=1000*min(min(flX[0],flX[1]),min(flX[2],flX[3]));
  820. rect.right=1000*max(max(flX[0],flX[1]),max(flX[2],flX[3]));
  821. rect.top=1000*min(min(flY[0],flY[1]),min(flY[2],flY[3]));
  822. rect.bottom=1000*max(max(flY[0],flY[1]),max(flY[2],flY[3]));
  823. return rect;
  824. }
  825. CPoint CEllipse::GetCenterPoint()
  826. {
  827. CRect rect=GetBoundaryRect();
  828. return rect.CenterPoint();
  829. }
  830. int CEllipse::IsPointinRegion(POINT point)
  831. {
  832. float angle=GetAngle();
  833. angle=0-angle;
  834.     float flx=(point.x-m_flCenterxTemp)*cos(angle)-(point.y-m_flCenteryTemp)*sin(angle)+m_flCenterxTemp;
  835. float fly=(point.y-m_flCenteryTemp)*cos(angle)+(point.x-m_flCenterxTemp)*sin(angle)+m_flCenteryTemp;
  836. int nRltVal=0;
  837. float a=m_flaTemp;
  838. float b=m_flbTemp;
  839. a=a*a;
  840. b=b*b;
  841. float r2=(flx-m_flCenterxTemp)*(flx-m_flCenterxTemp)/a+(fly-m_flCenteryTemp)*(fly-m_flCenteryTemp)/b;
  842. if(r2<1){
  843. nRltVal=1;
  844. }
  845. return nRltVal;
  846. }
  847. ///////////////////////////////////////////
  848. //GetPtState()
  849. //
  850. //       
  851. //       
  852. //        
  853. //
  854. ////////////////////////////////////////////////
  855. int CEllipse::GetPtState(float flx,float fly,float flRate)
  856. {
  857. //out point :包括中心带内,和四个顶点 
  858. //center   
  859. if(IsPtInRect(m_flCenterxTemp-3*flRate,m_flCenteryTemp-3*flRate,m_flCenterxTemp+3*flRate,m_flCenteryTemp+3*flRate,flx,fly)){
  860. m_nSelectLineNum=-1;
  861. m_nSelectPtNum=0;
  862. return 1;
  863. }
  864.     //out four peak points
  865. float flX[4],flY[4];
  866. float a=m_flaTemp;
  867. float b=m_flbTemp;
  868. flX[0]=m_flCenterxTemp;
  869. flX[1]=m_flCenterxTemp;
  870. flX[2]=m_flCenterxTemp-a;
  871. flX[3]=m_flCenterxTemp+a;
  872. flY[0]=m_flCenteryTemp-b;
  873. flY[1]=m_flCenteryTemp+b;
  874. flY[2]=m_flCenteryTemp;
  875. flY[3]=m_flCenteryTemp;
  876. float fx,fy,angle=GetAngle(),cosA,sinA;
  877. cosA=cos(angle);
  878. sinA=sin(angle);
  879. fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  880. fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  881. flX[0]=fx;
  882. flY[0]=fy;
  883. fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  884. fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  885. flX[1]=fx;
  886. flY[1]=fy;
  887. fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  888. fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  889. flX[2]=fx;
  890. flY[2]=fy;
  891. fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  892. fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  893. flX[3]=fx;
  894. flY[3]=fy;
  895. for(int i=0;i<4;i++){
  896. if(IsPtInRect(flX[i]-3*flRate,flY[i]-3*flRate,flX[i]+3*flRate,flY[i]+3*flRate,flx,fly)){
  897. m_nSelectLineNum=-1;
  898. m_nSelectPtNum=i+1;
  899. return 2;//should return 1! but now return 1 for Setting the cursor in CGraphSoftDoc::SetEditStateCursor(CPoint point)
  900. }
  901. }
  902. //out line
  903. angle=0-angle;
  904.     float X=(flx-m_flCenterxTemp)*cos(angle)-(fly-m_flCenteryTemp)*sin(angle)+m_flCenterxTemp;
  905. float Y=(fly-m_flCenteryTemp)*cos(angle)+(flx-m_flCenterxTemp)*sin(angle)+m_flCenteryTemp;
  906. int nRltVal=0;
  907. float aa=a*a;
  908. float bb=b*b;
  909. float r=1;
  910. float r2=(X-m_flCenterxTemp)*(X-m_flCenterxTemp)/aa+(Y-m_flCenteryTemp)*(Y-m_flCenteryTemp)/bb;
  911. r=sqrt(2*r*(aa+bb));
  912. r2=sqrt(2*r2*(aa+bb));
  913. if(fabs(r2-r) <= 5*flRate){
  914. m_nSelectLineNum=0;
  915. m_nSelectPtNum=-1;
  916. return 1;//should return 2! but now return 1 for Setting the cursor in CGraphSoftDoc::SetEditStateCursor(CPoint point)
  917. }
  918. //
  919. m_nSelectLineNum=-1;
  920. m_nSelectPtNum=-1;
  921. return 0;
  922. }
  923. /////////////
  924. ////////////
  925. float CEllipse::GetSelectLineRate()
  926. {
  927. float flX[4],flY[4];
  928. float a=m_flaTemp;
  929. float b=m_flbTemp;
  930. flX[0]=m_flCenterxTemp;
  931. flX[1]=m_flCenterxTemp;
  932. flX[2]=m_flCenterxTemp-a;
  933. flX[3]=m_flCenterxTemp+a;
  934. flY[0]=m_flCenteryTemp-b;
  935. flY[1]=m_flCenteryTemp+b;
  936. flY[2]=m_flCenteryTemp;
  937. flY[3]=m_flCenteryTemp;
  938. float fx,fy,angle=GetAngle(),cosA,sinA;
  939. cosA=cos(angle);
  940. sinA=sin(angle);
  941. fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  942. fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  943. flX[0]=fx;
  944. flY[0]=fy;
  945. fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  946. fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  947. flX[1]=fx;
  948. flY[1]=fy;
  949. fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  950. fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  951. flX[2]=fx;
  952. flY[2]=fy;
  953. fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
  954. fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
  955. flX[3]=fx;
  956. flY[3]=fy;
  957. if(m_nSelectPtNum==1||m_nSelectPtNum==2){
  958. if(fabs(flX[2]-flX[3])<0.1){
  959. return 1000;//
  960. }
  961. return -(flY[2]-flY[3])/(flX[2]-flX[3]);
  962. }
  963. if(m_nSelectPtNum==3||m_nSelectPtNum==4){
  964. if(fabs(flX[0]-flX[1])<0.1){
  965. return 1000;//
  966. }
  967. return -(flY[0]-flY[1])/(flX[0]-flX[1]);
  968. }
  969. return 0;
  970. }
  971. //////////////////////////////////////////////////////////////////////
  972. // MODULE   :ExPort
  973. // ABSTRACT :Export to a txt file
  974. // FUNCTION :File->Export...
  975. // NOTE     :
  976. // RETURN   :
  977. // ARGUMENTS:
  978. //              I/O           TYPE      NAME       EXPLANATION
  979. //               O            FILE*    outStream    Out put File
  980. // CREATE   :  FNST)handwolf  2004-4-14
  981. // UPDATE   :  
  982. //          : 
  983. //////////////////////////////////////////////////////////////////////
  984. void CEllipse::ExPort(FILE* outStream)//增加导出txt功能时用
  985. {
  986. fprintf(outStream, " CEllipse n");
  987. CShape::ExPort(outStream);
  988. fprintf( outStream, "%f %f %f %fn",m_fla,m_flb,m_flCenterx,m_flCentery);
  989. }
  990. //////////////////////////////////////////////////////////////////////
  991. // MODULE   :ImPort
  992. // ABSTRACT :ImPort from a txt file
  993. // FUNCTION :File->ImPort...
  994. // NOTE     :
  995. // RETURN   :
  996. // ARGUMENTS:
  997. //              I/O           TYPE      NAME       EXPLANATION
  998. //               I            FILE*    inStream    in put File
  999. // CREATE   :  FNST)handwolf  2004-4-14
  1000. // UPDATE   :  
  1001. //          : 
  1002. //////////////////////////////////////////////////////////////////////
  1003. void CEllipse::ImPort(FILE* inStream)
  1004. {
  1005. CShape::ImPort(inStream);
  1006. fscanf(inStream, "%f %f %f %f",&m_fla,&m_flb,&m_flCenterx,&m_flCentery);
  1007. m_flaTemp=m_fla;
  1008. m_flbTemp=m_flb;
  1009. m_flCenterxTemp=m_flCenterx;
  1010. m_flCenteryTemp=m_flCentery;
  1011. m_flAnglePrev=GetAngle();
  1012. }
  1013. CString CEllipse::GetNameString()
  1014. {
  1015. CString str;
  1016. str.LoadString(IDS_ELLIPSE);
  1017. return str;
  1018. }
  1019. //////////////////////////////////////////////////////////////////////
  1020. //End of File////////////////
  1021. ////////////////////////////////////////////////////////////////////////////
  1022. ////////////////////////////////////////////////////////////////////////////