QEllipseObj.cpp
资源名称:QGIS.rar [点击查看]
上传用户:oybseng
上传日期:2015-04-27
资源大小:7831k
文件大小:18k
源码类别:
GDI/图象编程
开发平台:
Visual C++
- // QEllipseObj.cpp: implementation of the CQEllipseObj class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "..stdafx.h"
- #include "..includeResource.h"
- #include "..INCLUDEQEllipseObj.h"
- #include "..includeQCoordSys.h"
- #include "..includeQGISAlgorithmLib.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CQEllipseObj::CQEllipseObj():CQBaseObj()
- {
- m_bFill = FALSE;
- m_ptCenter.SetX(0);
- m_ptCenter.SetY(0);
- m_fStartAngleRad = 0.0f;
- m_fEndAngleRad = PI;
- m_fRotateAngleRad = 0.0f;
- m_fLongAxis = 0.0f;
- m_fShortAxis = 0.0f;
- m_szObjName.Format("椭圆弧%ld",m_lObjID);
- m_nObjType = QGIS_OBJ_CIRCLE; //QGIS的圆类型
- m_nLineType = 0; //实线
- }
- CQEllipseObj::CQEllipseObj(double dx,double dy,double fLongAxis,double fShortAxis,double fStartAngle, double fEndAngle,double fRotateAngle):CQBaseObj()
- {
- m_szObjName.Format("椭圆弧%ld",m_lObjID);
- m_nObjType = QGIS_OBJ_CIRCLE;
- m_nLineType = 0;
- m_bFill = FALSE;
- m_ptCenter.SetX(dx);
- m_ptCenter.SetY(dy);
- m_fLongAxis = fLongAxis;
- m_fShortAxis = fShortAxis;
- m_fStartAngleRad = fStartAngle;
- m_fEndAngleRad = fEndAngle;
- m_fRotateAngleRad = fRotateAngle;
- RecalculatePtlist();
- }
- CQEllipseObj::CQEllipseObj(CQEllipseObj & tmEllipse):CQBaseObj(tmEllipse)
- {
- m_szObjName.Format("椭圆弧%ld",m_lObjID);
- m_nObjType = QGIS_OBJ_CIRCLE;
- m_nLineType = 0;
- m_bFill = FALSE;
- tmEllipse.GetCenterPoint(m_ptCenter);
- m_fLongAxis = tmEllipse.GetLongAxis();
- m_fShortAxis = tmEllipse.GetShortAxis();
- m_fStartAngleRad = tmEllipse.GetStartAngleRad();
- m_fEndAngleRad = tmEllipse.GetEndAngleRad();
- m_fRotateAngleRad = tmEllipse.GetRotateAngleRad();
- RecalculatePtlist();
- }
- void CQEllipseObj::Copy(CQEllipseObj & tmEllipse)
- {
- CQBaseObj::Copy(tmEllipse);
- m_szObjName.Format("椭圆弧%ld",m_lObjID);
- m_nObjType = QGIS_OBJ_CIRCLE;
- m_nLineType = 0;
- m_bFill = FALSE;
- tmEllipse.GetCenterPoint(m_ptCenter);
- m_fLongAxis = tmEllipse.GetLongAxis();
- m_fShortAxis = tmEllipse.GetShortAxis();
- m_fStartAngleRad = tmEllipse.GetStartAngleRad();
- m_fEndAngleRad = tmEllipse.GetEndAngleRad();
- m_fRotateAngleRad = tmEllipse.GetRotateAngleRad();
- RecalculatePtlist();
- }
- //通过椭圆的参数, 重新计算椭圆显示,选择时需要的点阵
- void CQEllipseObj::RecalculatePtlist()
- {
- m_PtList.DeleteAll(); //在重新计算之前要把以前的点阵作废
- double fStart = m_fStartAngleRad - m_fRotateAngleRad; //有效的 起始角度
- double fEnd = m_fEndAngleRad - m_fRotateAngleRad; //有效的终止角度
- if(fEnd < fStart) fEnd = fEnd + 2*PI; //如果终止角度小于起始角度的话就旋转360度
- double fStep = fabs(fEnd - fStart)/360; //360个点绘制椭圆
- if(fStep == 0)return; //假如步距为0则返回
- double dx = 0,dy = 0;
- for(double fStartAngle = fStart;fStartAngle<=fEnd;fStartAngle+=fStep)
- {
- CalculatePointByAngleRad(fStartAngle,dx,dy);
- m_PtList.AddPoint(dx,dy);
- }
- CalculatePointByAngleRad(fEnd,dx,dy);
- m_PtList.AddPoint(dx,dy);
- }
- void CQEllipseObj::CalculatePointByAngleRad(double dAngleRad, CQPoint & pt)
- {
- double a = m_fLongAxis;
- double b = m_fShortAxis;
- double fAngle = dAngleRad; //角度
- double R = a*b / sqrt( b*b*cos(fAngle)*cos(fAngle) + a*a*sin(fAngle)*sin(fAngle));
- double fx = R*cos(fAngle);
- double fy = R*sin(fAngle);
- double xx = fx*cos(m_fRotateAngleRad) - fy*sin(m_fRotateAngleRad);
- double yy = fx*sin(m_fRotateAngleRad) + fy*cos(m_fRotateAngleRad);
- xx += m_ptCenter.GetX();
- yy += m_ptCenter.GetY();
- pt.SetPoint(xx,yy);
- }
- void CQEllipseObj::CalculatePointByAngleRad(double dAngleRad, double &x, double &y)
- {
- double a = m_fLongAxis;
- double b = m_fShortAxis;
- double fAngle = dAngleRad; //角度
- //这是个轴长
- double R = a*b / sqrt( b*b*cos(fAngle)*cos(fAngle) + a*a*sin(fAngle)*sin(fAngle));
- double fx = R*cos(fAngle);
- double fy = R*sin(fAngle);
- x = fx*cos(m_fRotateAngleRad) - fy*sin(m_fRotateAngleRad);
- y = fx*sin(m_fRotateAngleRad) + fy*cos(m_fRotateAngleRad);
- x += m_ptCenter.GetX();
- y += m_ptCenter.GetY();
- }
- CQEllipseObj::~CQEllipseObj()
- {
- m_PtList.DeleteAll(); //删除所有的点
- }
- double CQEllipseObj::GetLongAxis()
- {
- return m_fLongAxis;
- }
- double CQEllipseObj::GetShortAxis()
- {
- return m_fShortAxis;
- }
- void CQEllipseObj::SetLongAxis(double a)
- {
- if(a<=0) a = 0;
- m_fLongAxis = a;
- RecalculatePtlist();
- }
- void CQEllipseObj::SetShortAxis(double b)
- {
- if(b<=0) b = 0;
- m_fShortAxis = b;
- RecalculatePtlist();
- }
- double CQEllipseObj::GetStartAngleRad()
- {
- return m_fStartAngleRad;
- }
- double CQEllipseObj::GetEndAngleRad()
- {
- return m_fEndAngleRad;
- }
- void CQEllipseObj::SetStartAngleRad(double dAngDeg)
- {
- m_fStartAngleRad = dAngDeg;
- RecalculatePtlist();
- }
- void CQEllipseObj::SetEndAngleRad(double dAngDeg)
- {
- m_fEndAngleRad = dAngDeg;
- RecalculatePtlist();
- }
- double CQEllipseObj::GetRotateAngleRad()
- {
- return m_fRotateAngleRad;
- }
- void CQEllipseObj::SetRotateAngleRad(double dAngDeg)
- {
- m_fRotateAngleRad = dAngDeg;
- RecalculatePtlist();
- }
- //返回一个椭圆对象的指针
- CQEllipseObj * CQEllipseObj::CreateEllipse(CQPoint ptCenter,double fLongAxis,double fShortAxis,double fStartAngle, double fEndAngle,double fRotateAngle)
- {
- CQEllipseObj * pEllipse = new CQEllipseObj;
- pEllipse->SetCenterPoint(ptCenter);
- pEllipse->SetLongAxis(fLongAxis);
- pEllipse->SetShortAxis(fShortAxis);
- pEllipse->SetRotateAngleRad(fRotateAngle);
- pEllipse->SetStartAngleRad(fStartAngle);
- pEllipse->SetEndAngleRad(fEndAngle);
- pEllipse->RecalculatePtlist();
- return pEllipse;
- }
- void CQEllipseObj::Display(CQCoordSys * pSys,CDC * pDC,int nDrawMode,int nSpecialMode,COLORREF * pColor)
- {
- //首先进行选择判断 如果当前椭圆对象的边界矩形不再视口范围内就不进行显示
- if(GetObjDeleted() || GetObjHided())return;
- if(m_bFill)
- {
- DisplayPolygon(pSys,pDC,nDrawMode,nSpecialMode,pColor);
- }
- else
- {
- DisplayPolyline(pSys,pDC,nDrawMode,nSpecialMode,pColor);
- }
- }
- //以区域的方式进行绘制,也就是要填充内部
- void CQEllipseObj::DisplayPolygon(CQCoordSys * pSys,CDC * pDC,int nDrawMode,int nSpecialMode,COLORREF * pColor)
- {
- CRect rectClient;
- pSys->GetWndport(rectClient.left,rectClient.top,rectClient.right,rectClient.bottom);
- CBoundaryRect bEllipseRect,bWndRect;
- CalculateBoundary(&bEllipseRect);
- pSys->LPtoWP(rectClient,&bWndRect);
- if(!bEllipseRect.IsCross(&bWndRect)) return;
- int nPtCount = m_PtList.GetSize();
- CPoint * pPoint = NULL;
- //保证能分配到空间
- while (pPoint == NULL)
- {
- pPoint = new CPoint[nPtCount];
- }
- for(int i=0;i<nPtCount;i++)
- {
- pSys->WPtoLP(*m_PtList.GetPoint(i),pPoint+i);
- }
- //获取线型
- long lPenStype = m_nLineType;
- //限制不能用特殊线型绘制
- if(lPenStype>5)
- lPenStype = 0;
- COLORREF crPen,crBrush;
- if(nSpecialMode == 1) //假如是选中
- {
- crPen = RGB(255,0,0); //红
- crBrush = RGB(0,255,0);//绿
- }
- else if(nSpecialMode == 2) // 指定颜色绘制
- {
- crPen = *pColor;
- crBrush = *pColor;
- }
- else
- {
- crPen = m_crPenColor;
- crBrush = m_crBrushColor;
- }
- CPen newPen(lPenStype,(int)m_fLineWidth,crPen);
- CPen * pOldPen = pDC->SelectObject(&newPen);
- CBrush newBrush(crBrush);
- CBrush * pOldBrush = pDC->SelectObject(&newBrush);
- pDC->SetMapMode(nDrawMode);
- pDC->Polygon(pPoint,nPtCount); //逼近
- pDC->SelectObject(&pOldPen);
- pDC->SelectObject(&pOldBrush);
- if(pPoint) delete []pPoint;
- }
- void CQEllipseObj::DisplayPolyline(CQCoordSys * pSys,CDC * pDC,int nDrawMode,int nSpecialMode,COLORREF * pColor)
- {
- CRect rectClient;
- pSys->GetWndport(rectClient.left,rectClient.top,rectClient.right,rectClient.bottom);
- CBoundaryRect bEllipseRect,bWndRect;
- CalculateBoundary(&bEllipseRect);
- pSys->LPtoWP(rectClient,&bWndRect);
- if(!bEllipseRect.IsCross(&bWndRect)) return;
- int nPtCount = m_PtList.GetSize();
- CPoint * pPoint = NULL;
- //保证能分配到空间
- while (pPoint == NULL)
- {
- pPoint = new CPoint[nPtCount];
- }
- for(int i=0;i<nPtCount;i++)
- {
- pSys->WPtoLP(*m_PtList.GetPoint(i),pPoint+i);
- }
- //获取线型
- long lPenStype = m_nLineType;
- //限制不能用特殊线型绘制
- if(lPenStype>5)
- lPenStype = 0;
- COLORREF crPen,crBrush;
- if(nSpecialMode == 1) //假如是选中
- {
- crPen = RGB(255,0,0); //红
- crBrush = RGB(0,255,0);//绿
- }
- else if(nSpecialMode == 2) // 指定颜色绘制
- {
- crPen = *pColor;
- crBrush = *pColor;
- }
- else
- {
- crPen = m_crPenColor;
- crBrush = m_crBrushColor;
- }
- CPen newPen(lPenStype,(int)m_fLineWidth,crPen);
- CPen * pOldPen = pDC->SelectObject(&newPen);
- pDC->SetMapMode(nDrawMode);
- pDC->Polyline(pPoint,nPtCount); //逼近
- pDC->SelectObject(&pOldPen);
- if(pPoint) delete []pPoint;
- }
- void CQEllipseObj::Move(double dx,double dy)
- {
- double fx = m_ptCenter.GetX();
- double fy = m_ptCenter.GetY();
- fx += dx;
- fy += dy;
- m_ptCenter.SetPoint(fx,fy);
- RecalculatePtlist();
- }
- //GIS中的旋转变换就是乘一个旋转矩阵
- //cosa sina 0
- //-sina cosa 0
- // 0 0 1
- void CQEllipseObj::Rotate(CQPoint & pt,double & fAngleDegree)
- {
- //对于圆这个东西 旋转中心就行了
- double dRedAng = CQGISAlgorithmLib::DegreeToRadian(fAngleDegree); //角度转换为弧度
- CQBaseObj::Rotate(&m_ptCenter,pt,fAngleDegree);
- m_fRotateAngleRad += dRedAng;
- m_fStartAngleRad += dRedAng;
- m_fEndAngleRad += dRedAng;
- RecalculatePtlist();
- }
- void CQEllipseObj::Mirror(int nMirrorType)
- {
- double fx,fy; //临时变量用于存放圆心坐标
- fx = m_ptCenter.GetX();
- fy = m_ptCenter.GetY();
- switch(nMirrorType)
- {
- case 2: //原点镜像
- {
- m_ptCenter.SetPoint(-fx,-fy);
- m_fStartAngleRad += PI;
- m_fEndAngleRad += PI;
- m_fRotateAngleRad += PI;
- break;
- }
- case 1://X轴镜像
- {
- m_ptCenter.SetPoint(fx,-fy);
- m_fStartAngleRad = -m_fStartAngleRad;
- m_fEndAngleRad = -m_fEndAngleRad;
- m_fRotateAngleRad = -m_fRotateAngleRad;
- break;
- }
- case 0://Y轴镜像
- {
- m_ptCenter.SetPoint(-fx,fy);
- m_fStartAngleRad = (PI - m_fStartAngleRad);
- m_fEndAngleRad = (PI - m_fEndAngleRad);
- m_fRotateAngleRad = (PI - m_fRotateAngleRad);
- break;
- }
- default:
- {
- m_ptCenter.SetPoint(-fx,fy);
- m_fStartAngleRad = (PI - m_fStartAngleRad);
- m_fEndAngleRad = (PI - m_fEndAngleRad);
- m_fRotateAngleRad = (PI - m_fRotateAngleRad);
- break;
- }
- }
- }
- //计算椭圆的边界矩形
- void CQEllipseObj::CalculateBoundary(CBoundaryRect * pRect /* = 0 */)//计算椭圆对象的边界矩形
- {
- double dx = m_ptCenter.GetX();
- double dy = m_ptCenter.GetY();
- double fMinX,fMinY,fMaxX,fMaxY;
- int nPtCount = m_PtList.GetSize();
- if(nPtCount <= 0)
- {
- fMinX = 0;
- fMinY = 0;
- fMaxX = 0;
- fMaxY = 0;
- }
- else
- {
- fMinX = m_PtList.GetPoint(0)->GetX();
- fMinY = m_PtList.GetPoint(0)->GetY();
- fMaxX = m_PtList.GetPoint(0)->GetX();
- fMaxY = m_PtList.GetPoint(0)->GetY();
- for(int i=1;i<nPtCount;i++)
- {
- fMinX = min(fMinX,m_PtList.GetPoint(i)->GetX());
- fMinY = min(fMinY,m_PtList.GetPoint(i)->GetY());
- fMaxX = max(fMaxX,m_PtList.GetPoint(i)->GetX());
- fMaxY = max(fMaxY,m_PtList.GetPoint(i)->GetY());
- }
- }
- m_Boundary.m_fMinX = fMinX;
- m_Boundary.m_fMinY = fMinY;
- m_Boundary.m_fMaxX = fMaxX;
- m_Boundary.m_fMaxY = fMaxY;
- if(pRect)
- {
- pRect->m_fMinX = fMinX;
- pRect->m_fMinY = fMinY;
- pRect->m_fMaxX = fMaxX;
- pRect->m_fMaxY = fMaxY;
- }
- }
- void CQEllipseObj::GetBoundingRect(CBoundaryRect * pRect)
- {
- if(!pRect)
- {
- pRect = NULL;
- return;
- }
- CalculateBoundary(pRect);
- }
- //框选择
- BOOL CQEllipseObj::Select(CQCoordSys * pSys,CBoundaryRect & rect)
- {
- CBoundaryRect bRect;
- CalculateBoundary(&bRect); //得到当前椭圆对象的边界
- if(!bRect.IsCross(&rect)) return FALSE;
- int nPtCount = m_PtList.GetSize();
- int nResult = 0;
- int i = 0;
- CQPoint ptLB,ptLT,ptRB,ptRT;
- //构造四个点
- ptLT.SetPoint(rect.m_fMinX,rect.m_fMaxY);
- ptLB.SetPoint(rect.m_fMinX,rect.m_fMinY);
- ptRB.SetPoint(rect.m_fMaxX,rect.m_fMinY);
- ptRT.SetPoint(rect.m_fMaxX,rect.m_fMaxY);
- for(;i<nPtCount-1;i++)
- {
- CQPoint * pt1 = NULL;
- pt1 = m_PtList.GetPoint(i);
- CQPoint * pt2 = NULL;
- pt2 = m_PtList.GetPoint(i+1);
- if(!pt1 || !pt2)continue;
- if(rect.PtInRect(*pt1)) return TRUE; //假如有点在矩形对象里
- if(CQGISAlgorithmLib::IsLineCross(*pt1,*pt2,ptLB,ptLT) == TRUE)
- return TRUE;
- if(CQGISAlgorithmLib::IsLineCross(*pt1,*pt2,ptLT,ptRT) == TRUE)
- return TRUE;
- if(CQGISAlgorithmLib::IsLineCross(*pt1,*pt2,ptRT,ptRB) == TRUE)
- return TRUE;
- if(CQGISAlgorithmLib::IsLineCross(*pt1,*pt2,ptRB,ptLB) == TRUE)
- return TRUE;
- }
- return FALSE;
- }
- //点选
- BOOL CQEllipseObj::Select(CQCoordSys * pSys,CQPoint & pt,double fEffectiveDistance)
- {
- if(!pSys)return FALSE; //没有坐标系统对象 无法实现
- CBoundaryRect bRect;
- CalculateBoundary(&bRect); //得到当前椭圆对象的边界
- if(bRect.PtInRect(pt) == FALSE)return FALSE;
- int nPtCount = m_PtList.GetSize();
- for(int i=0;i<nPtCount-1;i++)
- {
- CQPoint * pt1 = m_PtList.GetPoint(i);
- CQPoint * pt2 = m_PtList.GetPoint(i+1);
- double fDistance = CQPoint::Distance(pt,*pt1,*pt2);
- if(fDistance<=fEffectiveDistance)return TRUE;
- }
- return FALSE;
- }
- //串行化
- void CQEllipseObj::Serialize(CArchive& ar)
- {
- CQBaseObj::Serialize(ar);
- //调用基类的构造函数 串行化基类部分
- if (ar.IsStoring()) //写入硬盘
- {
- //写入椭圆的重点坐标
- m_ptCenter.Serialize(ar);
- float fLongAxis = static_cast<float>(m_fLongAxis);
- ar.Write(&fLongAxis,sizeof(float));
- float fShortAxis = static_cast<float>(m_fShortAxis);
- ar.Write(&fShortAxis,sizeof(float));
- float fStartAngle = static_cast<float>(m_fStartAngleRad);
- ar.Write(&fStartAngle,sizeof(float));
- float fEndAngle = static_cast<float>(m_fEndAngleRad);
- ar.Write(&fEndAngle,sizeof(float));
- float fRotateAngle = static_cast<float>(m_fRotateAngleRad);
- ar.Write(&fRotateAngle,sizeof(float));
- //m_PtList.Serialize(ar); 先 不写
- }
- else // 由磁盘读入
- {
- m_ptCenter.Serialize(ar);
- float fTemp = 0.0f;
- ar.Read(&fTemp,sizeof(float));
- m_fLongAxis = fTemp;
- ar.Read(&fTemp,sizeof(float));
- m_fShortAxis = fTemp;
- ar.Read(&fTemp,sizeof(float));
- m_fStartAngleRad = fTemp;
- ar.Read(&fTemp,sizeof(float));
- m_fEndAngleRad = fTemp;
- ar.Read(&fTemp,sizeof(float));
- m_fRotateAngleRad = fTemp;
- RecalculatePtlist(); //就是 不用写
- }
- }
- void CQEllipseObj::XFlex(double dcp_x,double dFlex)
- {
- int nPtNum = m_PtList.GetSize();
- for(int i=0;i<nPtNum;i++)
- {
- double dx = m_PtList.GetPoint(i)->GetX();
- dx = (dx-dcp_x)*dFlex;
- m_PtList.GetPoint(i)->SetX(dx);
- }
- }
- void CQEllipseObj::YFlex(double dcp_y,double dFlex)
- {
- int nPtNum = m_PtList.GetSize();
- for(int i=0;i<nPtNum;i++)
- {
- double dy = m_PtList.GetPoint(i)->GetY();
- dy = (dy-dcp_y)*dFlex;
- m_PtList.GetPoint(i)->SetX(dy);
- }
- }
- // 按标准椭圆方程:长半轴a,短半轴b。
- // 设 λ=(a-b)/(a+b),
- // 椭圆周长L:
- // L=π(a+b)(1 + λ^2/4 + λ^4/64 + λ^6/256 + 25λ^8/16384 + ......)
- double CQEllipseObj::GetPerimeter() //获取线条的周长,获取的是封闭的椭圆的周长
- {
- double lam = (m_fLongAxis-m_fShortAxis) / (m_fLongAxis+m_fShortAxis);
- double d = PI * (m_fLongAxis+m_fShortAxis) *
- ( 1 + lam*lam/4.0 + pow(lam,4)/64.0 + pow(lam,6)/256.0 + 25*pow(lam,8)/16384.0 );
- return d;
- }
- // 返 回:椭圆的面积
- double CQEllipseObj::GetArcLength() //获取线条的长度
- {
- double fEndAngle = m_fEndAngleRad;
- if(fEndAngle<m_fStartAngleRad) fEndAngle += 2*PI;
- double dx = (fEndAngle - m_fStartAngleRad)/2*PI;
- if(dx > 1.0)dx = 1.0;
- return dx*GetPerimeter();
- }
- //PI * a * b
- double CQEllipseObj::GetArea() //获取面积,获取的是封闭的椭圆的面积
- {
- return PI*m_fLongAxis*m_fShortAxis;
- }
- //返回点阵的指针
- CQPointArray * CQEllipseObj::GetPointList()
- {
- return & m_PtList;
- }
- //存入文件
- void CQEllipseObj::WriteToFile(CFile * pf)
- {
- if(pf == NULL)return;
- int nPtCount = m_PtList.GetSize();
- return;
- CQBaseObj::WriteToFile(pf);
- float fLongAxis = static_cast<float>(m_fLongAxis);
- pf->Write(&fLongAxis,sizeof(float));
- float fShortAxis = static_cast<float>(m_fShortAxis);
- pf->Write(&fLongAxis,sizeof(float));
- float fStartAngle = static_cast<float>(m_fStartAngleRad);
- pf->Write(&fStartAngle,sizeof(float));
- float fEndAngle = static_cast<float>(m_fEndAngleRad);
- pf->Write(&fEndAngle,sizeof(float));
- float fRotateAngle = static_cast<float>(m_fRotateAngleRad);
- pf->Write(&fRotateAngle,sizeof(float));
- }
- void CQEllipseObj::ReadFromFile(CFile * pf)
- {
- if(pf == NULL)
- pf = new CFile;
- CQBaseObj::ReadFromFile(pf);
- float fTemp = 0.0f;
- pf->Read(&fTemp,sizeof(float));
- m_fLongAxis = fTemp;
- pf->Read(&fTemp,sizeof(float));
- m_fShortAxis = fTemp;
- pf->Read(&fTemp,sizeof(float));
- m_fStartAngleRad = fTemp;
- pf->Read(&fTemp,sizeof(float));
- m_fEndAngleRad = fTemp;
- pf->Read(&fTemp,sizeof(float));
- m_fRotateAngleRad = fTemp;
- RecalculatePtlist();
- }
- CString CQEllipseObj::VarToStr() //将对象的成员信息转换成字符串信息
- {
- CString szFormBase;
- szFormBase.Empty();
- szFormBase = CQBaseObj::VarToStr();
- CString szEllipse,sztemp;
- szEllipse.Format("中心点X坐标:%f,中心点Y坐标:%f,椭圆长轴:%f,椭圆短轴:%f,起始角度:%f,终止角度:%f,旋转角度:%f",m_fLongAxis,m_fShortAxis,m_fStartAngleRad,m_fRotateAngleRad,m_fRotateAngleRad);
- szFormBase += szEllipse;
- return szFormBase;
- }
- inline void CQEllipseObj::GetCenterPoint(double &x, double &y) //获取椭圆中心点
- {
- x = m_ptCenter.GetX();
- y = m_ptCenter.GetY();
- }
- inline void CQEllipseObj::GetCenterPoint(CQPoint &pt) //获取椭圆中心点
- {
- pt.SetPoint(m_ptCenter.GetX(),m_ptCenter.GetY());
- }
- void CQEllipseObj::SetCenterPoint(double x, double y) //设置椭圆中心点
- {
- m_ptCenter.SetPoint(x,y);
- }
- void CQEllipseObj::SetCenterPoint(CQPoint pt) //设置椭圆中心点
- {
- m_ptCenter.SetPoint(pt.GetX(),pt.GetY());
- }
- //设定椭圆的参数,五个参数一起设置,这样只需计算一次点阵
- void CQEllipseObj::SetEllipseParams(double dCenterX,double dCenterY,double dMajorAxis,
- double dMinorAxis,double dStartAngleRad,double dEndAngleRad,double dRotateAngleRad)
- {
- m_ptCenter.SetPoint(dCenterX,dCenterY);
- m_fLongAxis = dMajorAxis;
- m_fShortAxis = dMinorAxis;
- m_fStartAngleRad = dStartAngleRad;
- m_fEndAngleRad = dEndAngleRad;
- m_fRotateAngleRad = dRotateAngleRad;
- RecalculatePtlist();
- }