www.pudn.com > 44757463.rar > Ellipse.cpp
// Ellipse.cpp: implementation of the CEllipse class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "GraphSoft.h"
#include "Ellipse.h"
#include "math.h"
#include "GlobalFunction.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
///////////////////////////////////
IMPLEMENT_SERIAL( CEllipse, CShape, 0 )
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
CEllipse::CEllipse():CShape()
{
m_flaTemp=m_fla=0;
m_flbTemp=m_flb=0;
m_flCenterxTemp=m_flCenterx=0;
m_flCenteryTemp=m_flCentery=0;
m_flAnglePrev=0;
}
CEllipse::CEllipse(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
{
m_flaTemp=m_fla=0;
m_flbTemp=m_flb=0;
m_flCenterxTemp=m_flCenterx=0;
m_flCenteryTemp=m_flCentery=0;
m_flAnglePrev=angle;
}
CEllipse::CEllipse(CEllipse * const pEllipse):CShape(pEllipse)
{
m_fla=pEllipse->m_fla;
m_flb=pEllipse->m_flb;
m_flCenterx=pEllipse->m_flCenterx;
m_flCentery=pEllipse->m_flCentery;
//
m_flaTemp=pEllipse->m_flaTemp;
m_flbTemp=pEllipse->m_flbTemp;
m_flCenterxTemp=pEllipse->m_flCenterxTemp;
m_flCenteryTemp=pEllipse->m_flCenteryTemp;
m_flAnglePrev=pEllipse->m_flAnglePrev;
}
CEllipse::~CEllipse()
{
}
//////////////////////////////////////////////////////////////////////////
void CEllipse::Serialize( CArchive& ar)
{
CShape::Serialize( ar ) ;
if ( ar.IsLoading() ){
ar>>m_fla;
ar>>m_flb;
ar>>m_flCenterx;
ar>>m_flCentery;
//temp
m_flaTemp=m_fla;
m_flbTemp=m_flb;
m_flCenterxTemp=m_flCenterx;
m_flCenteryTemp=m_flCentery;
m_flAnglePrev=GetAngle();
} else {
ar<SelectObject(&pen);
if(m_nFillStyle==_shape_solid_fill){
FillEllipse(pDC,m_flCenterxTemp,m_flCenteryTemp,m_flaTemp,m_flbTemp,angle);
}
pen.DeleteObject();
pen.CreatePen(PS_GEOMETRIC,penWidth, color);
pDC->SelectObject(&pen);
BreEllipse(pDC,m_flCenterxTemp,m_flCenteryTemp,m_flaTemp,m_flbTemp,color,angle,penWidth);
if(GetDrawPointsFlag()==1){
DrawPoints(pDC,color);
}
pDC->SelectObject(poldPen);
}
///////////////////////////////////////////
void CEllipse::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
{
if(!IsInRect(m_rectFrom)){
return;
}
//得到移动扩缩后的关键数据
float flCx,flCy,fla,flb;
//移动
float stepx=m_rectTo.left-m_rectFrom.left;
float stepy=m_rectTo.top-m_rectFrom.top;
flCx=m_flCenterxTemp+stepx;
flCy=m_flCenteryTemp+stepy;
fla=m_flaTemp;
flb=m_flbTemp;
//扩缩
float cx,cy,flScale;
cx=m_rectTo.left;
cy=m_rectTo.top;
if(m_rectFrom.Width()<0.01){
m_rectFrom.right=m_rectFrom.left +1;
}
if(m_rectFrom.Height()<0.01){
m_rectFrom.bottom=m_rectFrom.top +1;
}
flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
// flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
fla=fla*flScale;
flb=flb*flScale;
flCx=(flCx-cx)*flScale+cx;
flCy=(flCy-cy)*flScale+cy;
CPen pen,*poldPen;
pen.CreatePen(PS_SOLID,1, color);
poldPen=pDC->SelectObject(&pen);
{
pDC->MoveTo(flCx,flCy-1-GetPenWidth());
pDC->LineTo(flCx,flCy+2+GetPenWidth());
pDC->MoveTo(flCx-1-GetPenWidth(),flCy);
pDC->LineTo(flCx+2+GetPenWidth(),flCy);
}
float flX[4],flY[4];
float a=fla;
float b=flb;
flX[0]=flCx;
flX[1]=flCx;
flX[2]=flCx-a;
flX[3]=flCx+a;
flY[0]=flCy-b;
flY[1]=flCy+b;
flY[2]=flCy;
flY[3]=flCy;
//four peak points
float fx,fy,angle=GetAngle(),cosA,sinA;
cosA=cos(angle);
sinA=sin(angle);
fx=(flX[0]-flCx)*cosA-(flY[0]-flCy)*sinA+flCx;
fy=(flY[0]-flCy)*cosA+(flX[0]-flCx)*sinA+flCy;
flX[0]=fx;
flY[0]=fy;
fx=(flX[1]-flCx)*cosA-(flY[1]-flCy)*sinA+flCx;
fy=(flY[1]-flCy)*cosA+(flX[1]-flCx)*sinA+flCy;
flX[1]=fx;
flY[1]=fy;
fx=(flX[2]-flCx)*cosA-(flY[2]-flCy)*sinA+flCx;
fy=(flY[2]-flCy)*cosA+(flX[2]-flCx)*sinA+flCy;
flX[2]=fx;
flY[2]=fy;
fx=(flX[3]-flCx)*cosA-(flY[3]-flCy)*sinA+flCx;
fy=(flY[3]-flCy)*cosA+(flX[3]-flCx)*sinA+flCy;
flX[3]=fx;
flY[3]=fy;
for(int i=0;i<4;i++){
pDC->MoveTo(flX[i],flY[i]-1-GetPenWidth());
pDC->LineTo(flX[i],flY[i]+2+GetPenWidth());
pDC->MoveTo(flX[i]-1-GetPenWidth(),flY[i]);
pDC->LineTo(flX[i]+2+GetPenWidth(),flY[i]);
}
pDC->SelectObject(poldPen);
return;
}
void CEllipse::DrawPoints(CDC *pDC,COLORREF color)
{
CPen pen,*poldPen;
pen.CreatePen(PS_SOLID,1, color);
poldPen=pDC->SelectObject(&pen);
{
pDC->MoveTo(m_flCenterxTemp,m_flCenteryTemp-1-GetPenWidth());
pDC->LineTo(m_flCenterxTemp,m_flCenteryTemp+2+GetPenWidth());
pDC->MoveTo(m_flCenterxTemp-1-GetPenWidth(),m_flCenteryTemp);
pDC->LineTo(m_flCenterxTemp+2+GetPenWidth(),m_flCenteryTemp);
}
float flX[4],flY[4];
float a=m_flaTemp;
float b=m_flbTemp;
flX[0]=m_flCenterxTemp;
flX[1]=m_flCenterxTemp;
flX[2]=m_flCenterxTemp-a;
flX[3]=m_flCenterxTemp+a;
flY[0]=m_flCenteryTemp-b;
flY[1]=m_flCenteryTemp+b;
flY[2]=m_flCenteryTemp;
flY[3]=m_flCenteryTemp;
//four peak points
float fx,fy,angle=GetAngle(),cosA,sinA;
cosA=cos(angle);
sinA=sin(angle);
fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[0]=fx;
flY[0]=fy;
fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[1]=fx;
flY[1]=fy;
fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[2]=fx;
flY[2]=fy;
fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[3]=fx;
flY[3]=fy;
for(int i=0;i<4;i++){
pDC->MoveTo(flX[i],flY[i]-1-GetPenWidth());
pDC->LineTo(flX[i],flY[i]+2+GetPenWidth());
pDC->MoveTo(flX[i]-1-GetPenWidth(),flY[i]);
pDC->LineTo(flX[i]+2+GetPenWidth(),flY[i]);
}
pDC->SelectObject(poldPen);
return;
}
///////////////////////////////
void CEllipse::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
{
// if(!IsInRect(m_rectFrom)){
// return;
// }
//得到移动扩缩后的关键数据
float flCx,flCy,fla,flb;
//移动
float stepx=m_rectTo.left-m_rectFrom.left;
float stepy=m_rectTo.top-m_rectFrom.top;
flCx=m_flCenterxTemp+stepx;
flCy=m_flCenteryTemp+stepy;
fla=m_flaTemp;
flb=m_flbTemp;
//扩缩
float cx,cy,flScale;
cx=m_rectTo.left;
cy=m_rectTo.top;
if(m_rectFrom.Width()<0.01){
m_rectFrom.right=m_rectFrom.left +1;
}
if(m_rectFrom.Height()<0.01){
m_rectFrom.bottom=m_rectFrom.top +1;
}
flScale=(float)m_rectTo.Width()/m_rectFrom.Width();
// flScale=min((float)m_rectTo.Width()/m_rectFrom.Width(),(float)m_rectTo.Height()/m_rectFrom.Height());
fla=fla*flScale;
flb=flb*flScale;
flCx=(flCx-cx)*flScale+cx;
flCy=(flCy-cy)*flScale+cy;
//Draw
CPen pen,*poldPen;
float angle=GetAngle();
pen.CreatePen(PS_SOLID,2,fillColor);
poldPen=pDC->SelectObject(&pen);
if(m_nFillStyle==_shape_solid_fill){
FillEllipse(pDC,flCx,flCy,fla,flb,angle);
}
pen.DeleteObject();
pen.CreatePen(PS_GEOMETRIC,penWidth, color);
pDC->SelectObject(&pen);
BreEllipse(pDC,flCx,flCy,fla,flb,color,angle,penWidth);
if(GetDrawPointsFlag()==1){
DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
}
pDC->SelectObject(poldPen);
}
/////////////////////////////////////////////////////////////////////////////
/*
void CEllipse::BreEllipse(CDC *pDC,CPoint m_pCenter,float fla,float flb,COLORREF color,double angle,int nPenWidth)
{
int i,a,b,x,y;
double xc,yc,dx,dy,di,aa,bb,sinA,cosA;
cosA=cos(angle);
sinA=sin(angle);
xc=m_pCenter.x;
yc=m_pCenter.y;
a=fla;
b=flb;
aa=a*a;
bb=b*b;
x=0;
y=b;
dx=0;
dy=2*aa*y;
di=bb-aa*b+aa/4;
while(dxSetPixel(xc+x*cosA-y*sinA+i,yc+y*cosA+x*sinA,color);
pDC->SetPixel(xc+x*cosA+y*sinA+i,yc-y*cosA+x*sinA,color);
pDC->SetPixel(xc-x*cosA-y*sinA+i,yc+y*cosA-x*sinA,color);
pDC->SetPixel(xc-x*cosA+y*sinA+i,yc-y*cosA-x*sinA,color);
pDC->SetPixel(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA+i,color);
pDC->SetPixel(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA+i,color);
pDC->SetPixel(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA+i,color);
pDC->SetPixel(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA+i,color);
}
x++;
dx+=2*bb;
di+=dx+bb;
if(di>=0)
{
dy-=2*aa;
di-=dy;
y--;
}
}
di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);
while(y>0)
{
i=0;
for(i=0;iSetPixel(xc+x*cosA-y*sinA+i,yc+y*cosA+x*sinA,color);
pDC->SetPixel(xc+x*cosA+y*sinA+i,yc-y*cosA+x*sinA,color);
pDC->SetPixel(xc-x*cosA-y*sinA+i,yc+y*cosA-x*sinA,color);
pDC->SetPixel(xc-x*cosA+y*sinA+i,yc-y*cosA-x*sinA,color);
pDC->SetPixel(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA+i,color);
pDC->SetPixel(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA+i,color);
pDC->SetPixel(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA+i,color);
pDC->SetPixel(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA+i,color);
}
y--;
dy-=2*aa;
di+=aa-dy;
if(di<0)
{
dx+=2*bb;
di+=dx;
x++;
}
}
}
*/
void CEllipse::BreEllipse(CDC *pDC,float xc ,float yc,float fla,float flb,COLORREF color,double angle,int nPenWidth)
{
int i;
float a,b,x,y;
double dx,dy,di,aa,bb,sinA,cosA;
cosA=cos(angle);
sinA=sin(angle);
a=fla;
b=flb;
aa=a*a;
bb=b*b;
float flX[4],flY[4];
x=0;
y=b;
dx=0;
dy=2*aa*y;
di=bb-aa*b+aa/4;
flX[0]=xc+x*cosA-y*sinA;
flX[1]=xc+x*cosA+y*sinA;
flX[2]=xc-x*cosA-y*sinA;
flX[3]=xc-x*cosA+y*sinA;
flY[0]=yc+y*cosA+x*sinA;
flY[1]=yc-y*cosA+x*sinA;
flY[2]=yc+y*cosA-x*sinA;
flY[3]=yc-y*cosA-x*sinA;
i=0;
while(dxMoveTo(flX[0],flY[0]);
pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
pDC->MoveTo(flX[1],flY[1]);
pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
pDC->MoveTo(flX[2],flY[2]);
pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
pDC->MoveTo(flX[3],flY[3]);
pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
flX[0]=xc+x*cosA-y*sinA;
flX[1]=xc+x*cosA+y*sinA;
flX[2]=xc-x*cosA-y*sinA;
flX[3]=xc-x*cosA+y*sinA;
flY[0]=yc+y*cosA+x*sinA;
flY[1]=yc-y*cosA+x*sinA;
flY[2]=yc+y*cosA-x*sinA;
flY[3]=yc-y*cosA-x*sinA;
i=0;
}
x++;
dx+=2*bb;
di+=dx+bb;
if(di>=0)
{
dy-=2*aa;
di-=dy;
y--;
}
}
pDC->MoveTo(flX[0],flY[0]);
pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
pDC->MoveTo(flX[1],flY[1]);
pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
pDC->MoveTo(flX[2],flY[2]);
pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
pDC->MoveTo(flX[3],flY[3]);
pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);
flX[0]=xc+x*cosA-y*sinA;
flX[1]=xc+x*cosA+y*sinA;
flX[2]=xc-x*cosA-y*sinA;
flX[3]=xc-x*cosA+y*sinA;
flY[0]=yc+y*cosA+x*sinA;
flY[1]=yc-y*cosA+x*sinA;
flY[2]=yc+y*cosA-x*sinA;
flY[3]=yc-y*cosA-x*sinA;
i=0;
while(y>0)
{
i++;
if(i==5)
{
pDC->MoveTo(flX[0],flY[0]);
pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
pDC->MoveTo(flX[1],flY[1]);
pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
pDC->MoveTo(flX[2],flY[2]);
pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
pDC->MoveTo(flX[3],flY[3]);
pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
flX[0]=xc+x*cosA-y*sinA;
flX[1]=xc+x*cosA+y*sinA;
flX[2]=xc-x*cosA-y*sinA;
flX[3]=xc-x*cosA+y*sinA;
flY[0]=yc+y*cosA+x*sinA;
flY[1]=yc-y*cosA+x*sinA;
flY[2]=yc+y*cosA-x*sinA;
flY[3]=yc-y*cosA-x*sinA;
i=0;
}
y--;
dy-=2*aa;
di+=aa-dy;
if(di<0)
{
dx+=2*bb;
di+=dx;
x++;
}
}
pDC->MoveTo(flX[0],flY[0]);
pDC->LineTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
pDC->MoveTo(flX[1],flY[1]);
pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
pDC->MoveTo(flX[2],flY[2]);
pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
pDC->MoveTo(flX[3],flY[3]);
pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
}
/////////////////////////////////////////////////////////////////////////////
void CEllipse::FillEllipse(CDC *pDC,float xc ,float yc,float fla,float flb,double angle)
{
int i;
double a,b,x,y;
double dx,dy,di,aa,bb,sinA,cosA;
cosA=cos(angle);
sinA=sin(angle);
a=fla;
b=flb;
aa=a*a;
bb=b*b;
x=0;
y=b;
dx=0;
dy=2*aa*y;
di=bb-aa*b+aa/4;
while(dxMoveTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
pDC->MoveTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
pDC->LineTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
x++;
dx+=2*bb;
di+=dx+bb;
if(di>=0)
{
dy-=2*aa;
di-=dy;
y--;
}
}
di+=int((3*(aa-bb)-2*(dx-dy))/4+0.5);
while(y>=0)
{
pDC->MoveTo(xc+x*cosA-y*sinA,yc+y*cosA+x*sinA);
pDC->LineTo(xc-x*cosA-y*sinA,yc+y*cosA-x*sinA);
pDC->MoveTo(xc+x*cosA+y*sinA,yc-y*cosA+x*sinA);
pDC->LineTo(xc-x*cosA+y*sinA,yc-y*cosA-x*sinA);
y--;
dy-=2*aa;
di+=aa-dy;
if(di<0)
{
dx+=2*bb;
di+=dx;
x++;
}
}
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void CEllipse::RefreshData(bool bRefresh)
{
if(bRefresh){
m_fla=m_flaTemp;
m_flb=m_flbTemp;
m_flCenterx=m_flCenterxTemp;
m_flCentery=m_flCenteryTemp;
m_flAnglePrev=GetAngle();
m_bModified=FALSE;
m_ptMagnifyCenterTemp=CPoint(0,0);
m_flScaleTemp=1;
m_ptRotateCenterTemp=CPoint(0,0);
m_flAngleTemp=0;
}
}
void CEllipse::CreatGraph(CArray& flArrayX,CArray& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
{
if(flArrayX.GetSize()<2){
return;
}
CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
m_flCenterx=m_flCenterxTemp=(flArrayX.GetAt(0));
m_flCentery=m_flCenteryTemp=(flArrayY.GetAt(0));
m_fla=m_flaTemp=fabs((sqrt(2.0)*(float(flArrayX.GetAt(1)-flArrayX.GetAt(0)))));
m_flb=m_flbTemp=fabs((sqrt(2.0)*(float(flArrayY.GetAt(1)-flArrayY.GetAt(0)))));
m_flAnglePrev=GetAngle();
}
void CEllipse::CreatGraph(CArray& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
{
if(ptArray.GetSize()<2){
return;
}
CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
m_flCenterx=m_flCenterxTemp=((CPoint)ptArray.GetAt(0)).x;
m_flCentery=m_flCenteryTemp=((CPoint)ptArray.GetAt(0)).y;
m_fla=m_flaTemp=sqrt(2)*fabs(((CPoint)ptArray.GetAt(1)).x-m_flCenterx);
m_flb=m_flbTemp=sqrt(2)*fabs(((CPoint)ptArray.GetAt(1)).y-m_flCentery);
m_flAnglePrev=GetAngle();
}
// 特殊化处理,这里第二个点保存两条直径的长度
void CEllipse::SetPtData(CArray& flArrayX,CArray& flArrayY)
{
m_flCenterx=m_flCenterxTemp=((float)flArrayX.GetAt(0));
m_flCentery=m_flCenteryTemp=((float)flArrayY.GetAt(0));
m_fla=m_flaTemp=flArrayX.GetAt(1);
m_flb=m_flbTemp=flArrayY.GetAt(1);
}
// 特殊化处理,这里第二个点保存两条直径的长度
void CEllipse::GetPtData(CArray& flArrayX,CArray& flArrayY)
{
flArrayX.RemoveAll();
flArrayY.RemoveAll();
flArrayX.Add(m_flCenterxTemp);
flArrayX.Add(m_flaTemp);
flArrayY.Add(m_flCenteryTemp);
flArrayY.Add(m_flbTemp);
}
CShape* CEllipse::GetCopy()
{
CShape* pGraph=new CEllipse(this);
return pGraph;
}
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void CEllipse::Move(CDC *pDC,float stepx,float stepy)
{
RefreshData(m_bModified);
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
m_flCenterx+=stepx;
m_flCentery+=stepy;
//temp
m_flCenterxTemp+=stepx;
m_flCenteryTemp+=stepy;
}
void CEllipse::PartMove(CDC *pDC,float PrevX,float PrevY,float CurX,float CurY)
{
//RefreshData(m_bModified);
if(m_nSelectPtNum>-1){
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
//上下左右四顶点
float flX[4],flY[4];
float a=m_flaTemp;
float b=m_flbTemp;
flX[0]=m_flCenterxTemp;
flX[1]=m_flCenterxTemp;
flX[2]=m_flCenterxTemp-a;
flX[3]=m_flCenterxTemp+a;
flY[0]=m_flCenteryTemp-b;
flY[1]=m_flCenteryTemp+b;
flY[2]=m_flCenteryTemp;
flY[3]=m_flCenteryTemp;
float fx,fy,angle=GetAngle(),cosA,sinA;
cosA=cos(angle);
sinA=sin(angle);
fx=(flX[0]-m_flCenterxTemp)*cosA-(flY[0]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[0]-m_flCenteryTemp)*cosA+(flX[0]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[0]=fx;
flY[0]=fy;
fx=(flX[1]-m_flCenterxTemp)*cosA-(flY[1]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[1]-m_flCenteryTemp)*cosA+(flX[1]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[1]=fx;
flY[1]=fy;
fx=(flX[2]-m_flCenterxTemp)*cosA-(flY[2]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[2]-m_flCenteryTemp)*cosA+(flX[2]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[2]=fx;
flY[2]=fy;
fx=(flX[3]-m_flCenterxTemp)*cosA-(flY[3]-m_flCenteryTemp)*sinA+m_flCenterxTemp;
fy=(flY[3]-m_flCenteryTemp)*cosA+(flX[3]-m_flCenterxTemp)*sinA+m_flCenteryTemp;
flX[3]=fx;
flY[3]=fy;
switch(m_nSelectPtNum) {
case 0:
// m_flCenterx+=point.x-ptPrev.x;
// m_flCentery+=point.y-ptPrev.y;
//temp
m_flCenterxTemp+=CurX-PrevX;
m_flCenteryTemp+=CurY-PrevY;
break;
case 1:
case 2:
{
m_flbTemp=GetDisFromPtToLine(CurX,CurY,flX[2],flY[2],flX[3],flY[3]);
break;
}
case 3:
case 4:
{
m_flaTemp=GetDisFromPtToLine(CurX,CurY,flX[0],flY[0],flX[1],flY[1]);
break;
}
break;
default:
break;
}
//CShape::Draw(pDC);
}else if(m_nSelectLineNum>-1){
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
float dis1,dis2;
dis1=GetDistance(m_flCenterxTemp,m_flCenteryTemp,PrevX,PrevY);
dis2=GetDistance(m_flCenterxTemp,m_flCenteryTemp,CurX,CurY);
if(dis1<0.1){
dis1+=1;
}
if(dis2<0.1){
dis2+=1;
}
m_flaTemp=dis2*m_flaTemp/dis1;
m_flbTemp=dis2*m_flbTemp/dis1;
}
}
void CEllipse::Rotate(CDC *pDC,float CX, float CY, float flAngle)
{
if(m_flScaleTemp!=1){
RefreshData(TRUE);
}
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
m_ptRotateCenterTemp=CPoint(CX,CY);
m_flAngleTemp=flAngle;
m_bModified=TRUE;
SetAngle(m_flAnglePrev+flAngle);
m_flCenterxTemp=((m_flCenterx-CX)*cos(flAngle)-(m_flCentery-CY)*sin(flAngle))+CX;
m_flCenteryTemp=((m_flCentery-CY)*cos(flAngle)+(m_flCenterx-CX)*sin(flAngle))+CY;
}
void CEllipse::Magnify(CDC *pDC,float CX,float CY,float flScale)
{
if(m_flAngleTemp!=0){
RefreshData(TRUE);
}
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
m_ptMagnifyCenterTemp=CPoint(CX,CY);
m_flScaleTemp=flScale;
m_bModified=TRUE;
m_flaTemp=m_fla*flScale;
m_flbTemp=m_flb*flScale;
m_flCenterxTemp=(m_flCenterx-CX)*flScale+CX;
m_flCenteryTemp=(m_flCentery-CY)*flScale+CY;
}
void CEllipse::TopToBottom(CDC* pDC,CRect rect)
{
RefreshData(m_bModified);
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
m_flAnglePrev=GetAngle();
m_flAnglePrev=-m_flAnglePrev;
SetAngle(m_flAnglePrev);
m_flCenteryTemp=rect.top/1000.0+rect.bottom/1000.0-m_flCenteryTemp;
m_flCentery=rect.top/1000.0+rect.bottom/1000.0-m_flCentery;
// CShape::Draw(pDC);
}
void CEllipse::LeftToRight(CDC* pDC,CRect rect)
{
RefreshData(m_bModified);
// CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
m_flAnglePrev=GetAngle();
m_flAnglePrev=PI-m_flAnglePrev;
SetAngle(m_flAnglePrev);
m_flCenterxTemp=rect.left/1000.0+rect.right/1000.0-m_flCenterxTemp;
m_flCenterx=rect.left/1000.0+rect.right/1000.0-m_flCenterx;
// CShape::Draw(pDC);
}
///
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
int CEllipse::IsInRect(CRect rect)
{
int nRltVal=0;
CPoint ptRectLT=rect.TopLeft();
CPoint ptRectRB=rect.BottomRight();
CPoint ptRectLB,ptRectRT;
ptRectLB.x=rect.left;
ptRectLB.y=rect.bottom;
ptRectRT.x=rect.right;
ptRectRT.y=rect.top;
CPoint ptCircleCenter(m_flCenterxTemp,m_flCenteryTemp);
int flag =0;
if(IsPointinRegion(ptRectLT)){
flag++;
}
if(IsPointinRegion(ptRectRB)){
flag++;
}
if(IsPointinRegion(ptRectLB)){
flag++;
}
if(IsPointinRegion(ptRectRT)){
flag++;
}
if(0Export...
// NOTE :
// RETURN :
// ARGUMENTS:
// I/O TYPE NAME EXPLANATION
// O FILE* outStream Out put File
// CREATE : FNST)handwolf 2004-4-14
// UPDATE :
// :
//////////////////////////////////////////////////////////////////////
void CEllipse::ExPort(FILE* outStream)//增加导出txt功能时用
{
fprintf(outStream, " CEllipse \n");
CShape::ExPort(outStream);
fprintf( outStream, "%f %f %f %f\n",m_fla,m_flb,m_flCenterx,m_flCentery);
}
//////////////////////////////////////////////////////////////////////
// MODULE :ImPort
// ABSTRACT :ImPort from a txt file
// FUNCTION :File->ImPort...
// NOTE :
// RETURN :
// ARGUMENTS:
// I/O TYPE NAME EXPLANATION
// I FILE* inStream in put File
// CREATE : FNST)handwolf 2004-4-14
// UPDATE :
// :
//////////////////////////////////////////////////////////////////////
void CEllipse::ImPort(FILE* inStream)
{
CShape::ImPort(inStream);
fscanf(inStream, "%f %f %f %f",&m_fla,&m_flb,&m_flCenterx,&m_flCentery);
m_flaTemp=m_fla;
m_flbTemp=m_flb;
m_flCenterxTemp=m_flCenterx;
m_flCenteryTemp=m_flCentery;
m_flAnglePrev=GetAngle();
}
CString CEllipse::GetNameString()
{
CString str;
str.LoadString(IDS_ELLIPSE);
return str;
}
//////////////////////////////////////////////////////////////////////
//End of File////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////