ModelCurve3Param.cpp
资源名称:44757463.rar [点击查看]
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:19k
源码类别:
绘图程序
开发平台:
Visual C++
- // ModelCurve3Param.cpp: implementation of the CModelCurve3Param class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GraphSoft.h"
- #include "ModelCurve3Param.h"
- #include "math.h"
- #include "GlobalFunction.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- ///////////////////////////////////
- IMPLEMENT_SERIAL( CModelCurve3Param, CShape, 0 )
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////
- CModelCurve3Param::CModelCurve3Param():CShape()
- {
- }
- CModelCurve3Param::CModelCurve3Param(COLORREF color,int penWidth,float angle):CShape(color,penWidth,angle)
- {
- }
- CModelCurve3Param::CModelCurve3Param(CModelCurve3Param * const pModelCurve3Param):CShape(pModelCurve3Param)
- {
- int i=pModelCurve3Param->m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- fx=pModelCurve3Param->m_flArrayxTemp.GetAt(j-1);
- fy=pModelCurve3Param->m_flArrayyTemp.GetAt(j-1);
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- i=pModelCurve3Param->m_flArrayx.GetSize();
- j=0;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- while(j++<i){
- fx=pModelCurve3Param->m_flArrayx.GetAt(j-1);
- fy=pModelCurve3Param->m_flArrayy.GetAt(j-1);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- }
- }
- CModelCurve3Param::~CModelCurve3Param()
- {
- }
- //////////////////////////////////////////////////////////////////////////
- void CModelCurve3Param::Serialize( CArchive& ar)
- {
- CShape::Serialize( ar ) ;
- int i=0,j;
- if ( ar.IsLoading() ){
- float fx,fy;
- ar>>i;
- j=0;
- while(j++ < i){
- ar>>fx;
- ar>>fy;
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- //temp
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- } else {
- RefreshData(m_bModified);
- i=m_flArrayx.GetSize();
- j=0;
- ar<<i;
- while(j++ < i){
- ar<<((float)m_flArrayx.GetAt(j-1));
- ar<<((float)m_flArrayy.GetAt(j-1));
- }
- }
- return ;
- }
- ////////////////////////////////////////////////////////////////////////
- void CModelCurve3Param::Draw(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth)
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,penWidth, color);
- poldPen=pDC->SelectObject(&pen);
- SanCiCanShu(pDC,1,1,m_flArrayxTemp,m_flArrayyTemp);
- if(GetDrawPointsFlag()==1){
- DrawPoints(pDC,color);
- }
- pDC->SelectObject(poldPen);
- }
- ///////////////////////////////////////////
- void CModelCurve3Param::DrawPointsCutTo(CDC *pDC,COLORREF color,CFlRect m_rectFrom,CRect m_rectTo)
- {
- // if(!IsInRect(m_rectFrom)){
- // return;
- // }
- //得到移动扩缩后的关键数据
- CArray<float,float> flArrayx;
- CArray<float,float> flArrayy;;
- //移动
- int i=m_flArrayxTemp.GetSize(),j;
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- for(j=0;j<i;j++){
- flArrayx.Add(m_flArrayxTemp.GetAt(j)+stepx);
- flArrayy.Add(m_flArrayyTemp.GetAt(j)+stepy);
- }
- //扩缩
- 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());
- i=flArrayx.GetSize();
- for(j=0;j<i;j++){
- flArrayx.SetAt(j,(flArrayx.GetAt(j)-cx)*flScale+cx);
- flArrayy.SetAt(j,(flArrayy.GetAt(j)-cy)*flScale+cy);
- }
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- i=flArrayx.GetSize();
- int nSX,nSY;
- nSX=flArrayx.GetAt(0);
- nSY=flArrayy.GetAt(0);
- for(j=0;j<i;j++){
- //画点
- pDC->MoveTo(flArrayx.GetAt(j),flArrayy.GetAt(j)-1-GetPenWidth());
- pDC->LineTo(flArrayx.GetAt(j),flArrayy.GetAt(j)+2+GetPenWidth());
- pDC->MoveTo(flArrayx.GetAt(j)-1-GetPenWidth(),flArrayy.GetAt(j));
- pDC->LineTo(flArrayx.GetAt(j)+2+GetPenWidth(),flArrayy.GetAt(j));
- //画线
- pen.DeleteObject();
- CShape::DotLine(pDC,nSX,nSY,flArrayx.GetAt(j),flArrayy.GetAt(j),color);
- nSX=flArrayx.GetAt(j);
- nSY=flArrayy.GetAt(j);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- void CModelCurve3Param::DrawPoints(CDC *pDC,COLORREF color)
- {
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,1, color);
- poldPen=pDC->SelectObject(&pen);
- int i=m_flArrayxTemp.GetSize();
- int nSX,nSY;
- nSX=m_flArrayxTemp.GetAt(0);
- nSY=m_flArrayyTemp.GetAt(0);
- for(int j=0;j<i;j++){
- //画点
- pDC->MoveTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j)-1-GetPenWidth());
- pDC->LineTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j)+2+GetPenWidth());
- pDC->MoveTo(m_flArrayxTemp.GetAt(j)-1-GetPenWidth(),m_flArrayyTemp.GetAt(j));
- pDC->LineTo(m_flArrayxTemp.GetAt(j)+2+GetPenWidth(),m_flArrayyTemp.GetAt(j));
- //画线
- pen.DeleteObject();
- // pen.CreatePen(PS_DOT,1,color);
- // pDC->SelectObject(&pen);
- //pDC->MoveTo(nSX,nSY);
- //pDC->LineTo(m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j));
- CShape::DotLine(pDC,nSX,nSY,m_flArrayxTemp.GetAt(j),m_flArrayyTemp.GetAt(j),color);
- nSX=m_flArrayxTemp.GetAt(j);
- nSY=m_flArrayyTemp.GetAt(j);
- }
- pDC->SelectObject(poldPen);
- return;
- }
- ////////////////////////
- void CModelCurve3Param::DrawCutToRect(CDC *pDC,COLORREF color,COLORREF fillColor,int penWidth,CFlRect m_rectFrom,CRect m_rectTo)
- {
- // if(!IsInRect(m_rectFrom)){
- // return;
- // }
- //得到移动扩缩后的关键数据
- CArray<float,float> flArrayx;
- CArray<float,float> flArrayy;
- //移动
- int i=m_flArrayxTemp.GetSize(),j;
- float stepx=m_rectTo.left-m_rectFrom.left;
- float stepy=m_rectTo.top-m_rectFrom.top;
- for(j=0;j<i;j++){
- flArrayx.Add(m_flArrayxTemp.GetAt(j)+stepx);
- flArrayy.Add(m_flArrayyTemp.GetAt(j)+stepy);
- }
- //扩缩
- 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());
- i=flArrayx.GetSize();
- for(j=0;j<i;j++){
- flArrayx.SetAt(j,(flArrayx.GetAt(j)-cx)*flScale+cx);
- flArrayy.SetAt(j,(flArrayy.GetAt(j)-cy)*flScale+cy);
- }
- CPen pen,*poldPen;
- pen.CreatePen(PS_SOLID,penWidth, color);
- poldPen=pDC->SelectObject(&pen);
- SanCiCanShu(pDC,1,1,flArrayx,flArrayy);
- if(GetDrawPointsFlag()==1){
- DrawPointsCutTo(pDC,color,m_rectFrom,m_rectTo);
- }
- pDC->SelectObject(poldPen);
- }
- //
- int CModelCurve3Param::SanCiCanShu(CDC *pDC,float b1,float bn,CArray<float,float>& flArrayx,CArray<float,float>& flArrayy)
- {
- if(flArrayx.GetSize()!=flArrayy.GetSize())
- return 0;
- CArray<float,float> x,y,alfa,alfay,batax,batay,L,Ly;
- int i,t,m;
- float k,a11,a21,a31,a41,b11,b21,b31,b41,t1,t2,t3,x0,x1,y0,y1,flTemp;
- int n=flArrayx.GetSize();
- if(n<2) return 0;
- for(i=0;i<n;i++)
- {
- flTemp=flArrayx.GetAt(i);
- x.Add(flTemp);
- flTemp=flArrayy.GetAt(i);
- y.Add(flTemp);
- alfa.Add(0);
- alfay.Add(0);
- batax.Add(0);
- batay.Add(0);
- L.Add(0);
- Ly.Add(0);
- }
- for(i=1;i<n;i++)
- {
- flTemp=sqrt(pow(x.GetAt(i)-x.GetAt(i-1),2)+pow(y.GetAt(i)-y.GetAt(i-1),2));
- if(fabs(flTemp)<1){//如果=0,会抛出异常------除零异常
- flTemp=1;
- }
- L.SetAt(i,flTemp);
- }
- for(i=1;i<n-1;i++)
- {
- alfa.SetAt(i,L.GetAt(i+1)/(L.GetAt(i)+L.GetAt(i+1)));
- batay.SetAt(i,6*((y.GetAt(i+1)-y.GetAt(i))/L.GetAt(i+1)-(y.GetAt(i)-y.GetAt(i-1))/L.GetAt(i))/(L.GetAt(i)+L.GetAt(i+1)));
- batax.SetAt(i,6*((x.GetAt(i+1)-x.GetAt(i))/L.GetAt(i+1)-(x.GetAt(i)-x.GetAt(i-1))/L.GetAt(i))/(L.GetAt(i)+L.GetAt(i+1)));
- //TRACE("batay= %f,batax=%f,alfa=%fn",batay.GetAt(i),batax.GetAt(i),alfa.GetAt(i));
- }
- batax.SetAt(0,6*((x.GetAt(1)-x.GetAt(0))/L.GetAt(1)-b1)/L.GetAt(1));
- batax.SetAt(n-1,6*(bn-(x.GetAt(n-1)-x.GetAt(n-2))/L.GetAt(n-1))/L.GetAt(n-1));
- batay.SetAt(0,6*((y.GetAt(1)-y.GetAt(0))/L.GetAt(1)-b1)/L.GetAt(1));
- batay.SetAt(n-1,6*(bn-(y.GetAt(n-1)-y.GetAt(n-2))/L.GetAt(n-1))/L.GetAt(n-1));;
- alfa.SetAt(n-1,0);
- alfa.SetAt(0,1);
- batax.SetAt(0,batax.GetAt(0)/2);
- batay.SetAt(0,batay.GetAt(0)/2);
- k=2;//追赶法
- for(m=0;m<n-1;m++)
- {
- alfa.SetAt(m,alfa.GetAt(m)/k);
- k=2-(1-alfa.GetAt(m+1))*alfa.GetAt(m);
- batax.SetAt(m+1,(batax.GetAt(m+1)-(1-alfa.GetAt(m+1))*batax.GetAt(m))/k);
- batay.SetAt(m+1,(batay.GetAt(m+1)-(1-alfa.GetAt(m+1))*batay.GetAt(m))/k);
- }
- for(m=n-2;m>=0;m--)
- {
- batax.SetAt(m,batax.GetAt(m)-batax.GetAt(m+1)*alfa.GetAt(m));
- batay.SetAt(m,batay.GetAt(m)-batay.GetAt(m+1)*alfa.GetAt(m));
- }
- for(i=0;i<n-1;i++)
- {
- alfa.SetAt(i,(x.GetAt(i+1)-x.GetAt(i))/L.GetAt(i+1)-L.GetAt(i+1)*(batax.GetAt(i)/3+batax.GetAt(i+1)/6));
- alfay.SetAt(i,(y.GetAt(i+1)-y.GetAt(i))/L.GetAt(i+1)-L.GetAt(i+1)*(batay.GetAt(i)/3+batay.GetAt(i+1)/6));
- L.SetAt(i,(batax.GetAt(i+1)-batax.GetAt(i))/(6*L.GetAt(i+1)));
- Ly.SetAt(i,(batay.GetAt(i+1)-batay.GetAt(i))/(6*L.GetAt(i+1)));
- batax.SetAt(i,batax.GetAt(i)/2);
- batay.SetAt(i,batay.GetAt(i)/2);
- }
- for(i=0;i<n-1;i++)
- {
- a11=x.GetAt(i);
- a21=alfa.GetAt(i);
- a31=batax.GetAt(i);
- a41=L.GetAt(i);
- b11=y.GetAt(i);
- b21=alfay.GetAt(i);
- b31=batay.GetAt(i);
- b41=Ly.GetAt(i);
- x0=x.GetAt(i);
- y0=y.GetAt(i);
- //TRACE("x0=%f,y0=%fn",x0,y0);
- k=2;//递增步调
- t1=0;
- m=sqrt(pow((x.GetAt(i+1)-x.GetAt(i)),2)+pow((y.GetAt(i+1)-y.GetAt(i)),2))/k;
- for(t=0;t<=m;t++)
- {
- t1+=k;
- t2=t1*t1;
- t3=t1*t2;
- x1=a11+a21*t1+a31*t2+a41*t3;
- y1=b11+b21*t1+b31*t2+b41*t3;
- pDC->MoveTo(x0,y0);
- pDC->LineTo(x1,y1);
- x0=x1;
- y0=y1;
- //TRACE("a11= %f,a21=%f,a31=%f,a41y1=%fn",a11,a21,a31,a41);
- }
- }
- return 1;
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void CModelCurve3Param::RefreshData(bool bRefresh)
- {
- if(bRefresh){
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- while(j++<i){
- fx=m_flArrayxTemp.GetAt(j-1);
- fy=m_flArrayyTemp.GetAt(j-1);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- }
- m_bModified=FALSE;
- m_ptMagnifyCenterTemp=CPoint(0,0);
- m_flScaleTemp=1;
- m_ptRotateCenterTemp=CPoint(0,0);
- m_flAngleTemp=0;
- }
- }
- void CModelCurve3Param::CreatGraph(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- //if(ptArray.GetSize()<2){
- // return;
- //}
- CShape::CreatGraph(flArrayX,flArrayY,nPenWidth,color,fillColor,nStyle);
- int i=flArrayX.GetSize();
- int j=0;
- float flx,fly;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- flx=flArrayX.GetAt(j-1);
- fly=flArrayY.GetAt(j-1);
- m_flArrayx.Add(flx);
- m_flArrayy.Add(fly);
- //temp
- m_flArrayxTemp.Add(flx);
- m_flArrayyTemp.Add(fly);
- }
- }
- void CModelCurve3Param::CreatGraph(CArray<CPoint,CPoint>& ptArray,int nPenWidth,COLORREF color,COLORREF fillColor,SHAPE_FILLSTYLE nStyle)
- {
- //if(ptArray.GetSize()<2){
- // return;
- //}
- CShape::CreatGraph(ptArray,nPenWidth,color,fillColor,nStyle);
- int i=ptArray.GetSize();
- int j=0;
- CPoint pt;
- m_flArrayx.RemoveAll();
- m_flArrayy.RemoveAll();
- m_flArrayxTemp.RemoveAll();
- m_flArrayyTemp.RemoveAll();
- while(j++<i){
- pt=ptArray.GetAt(j-1);
- m_flArrayx.Add(pt.x);
- m_flArrayy.Add(pt.y);
- //temp
- m_flArrayxTemp.Add(pt.x);
- m_flArrayyTemp.Add(pt.y);
- }
- }
- void CModelCurve3Param::SetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- m_flArrayx.Copy(flArrayX);
- m_flArrayxTemp.Copy(flArrayX);
- m_flArrayy.Copy(flArrayY);
- m_flArrayyTemp.Copy(flArrayY);
- }
- void CModelCurve3Param::GetPtData(CArray<float,float>& flArrayX,CArray<float,float>& flArrayY)
- {
- flArrayX.Copy(m_flArrayxTemp);
- flArrayY.Copy(m_flArrayyTemp);
- }
- CShape* CModelCurve3Param::GetCopy()
- {
- CShape* pGraph=new CModelCurve3Param(this);
- return pGraph;
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void CModelCurve3Param::Move(CDC *pDC,float stepx,float stepy)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- while(j++<i){
- fx=m_flArrayxTemp.GetAt(j-1);
- fy=m_flArrayyTemp.GetAt(j-1);
- m_flArrayx.SetAt(j-1,fx+stepx);
- m_flArrayy.SetAt(j-1,fy+stepy);
- m_flArrayxTemp.SetAt(j-1,fx+stepx);
- m_flArrayyTemp.SetAt(j-1,fy+stepy);
- }
- }
- void CModelCurve3Param::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));
- m_flArrayxTemp.SetAt(m_nSelectPtNum,CurX);
- m_flArrayyTemp.SetAt(m_nSelectPtNum,CurY);
- m_flArrayx.SetAt(m_nSelectPtNum,CurX);
- m_flArrayy.SetAt(m_nSelectPtNum,CurY);
- //CShape::Draw(pDC);
- }
- }
- void CModelCurve3Param::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;
- int i=m_flArrayx.GetSize();
- int j=0;
- float fx,fy,fxTemp,fyTemp;
- while(j++<i){
- fx=m_flArrayx.GetAt(j-1);
- fy=m_flArrayy.GetAt(j-1);
- fxTemp=((fx-CX)*cos(flAngle)-(fy-CY)*sin(flAngle))+CX;
- fyTemp=((fy-CY)*cos(flAngle)+(fx-CX)*sin(flAngle))+CY;
- m_flArrayxTemp.SetAt(j-1,fxTemp);
- m_flArrayyTemp.SetAt(j-1,fyTemp);
- }
- }
- void CModelCurve3Param::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;
- int i=m_flArrayx.GetSize();
- int j=0;
- float fx,fy;
- while(j++<i){
- fx=m_flArrayx.GetAt(j-1);
- fy=m_flArrayy.GetAt(j-1);
- fx=(fx-CX)*flScale+CX;
- fy=(fy-CY)*flScale+CY;
- m_flArrayxTemp.SetAt(j-1,fx);
- m_flArrayyTemp.SetAt(j-1,fy);
- }
- }
- ////////////////////
- void CModelCurve3Param::LeftToRight(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- int i=m_flArrayx.GetSize();
- for(int j=0;j<i;j++){
- m_flArrayx.SetAt(j,rect.left/1000.0+rect.right/1000.0-m_flArrayx.GetAt(j));
- m_flArrayxTemp.SetAt(j,rect.left/1000.0+rect.right/1000.0-m_flArrayxTemp.GetAt(j));
- }
- // CShape::Draw(pDC);
- }
- void CModelCurve3Param::TopToBottom(CDC* pDC,CRect rect)
- {
- RefreshData(m_bModified);
- // CShape::Draw(pDC,RGB(255,255,255),RGB(255,255,255));
- int i=m_flArrayx.GetSize();
- for(int j=0;j<i;j++){
- m_flArrayy.SetAt(j,rect.top/1000.0+rect.bottom/1000.0-m_flArrayy.GetAt(j));
- m_flArrayyTemp.SetAt(j,rect.top/1000.0+rect.bottom/1000.0-m_flArrayyTemp.GetAt(j));
- }
- // CShape::Draw(pDC);
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- int CModelCurve3Param::IsInRect(CRect rect)
- {
- int nRltVal=0,nTemp;
- int i=m_flArrayx.GetSize();
- int j=0;
- float fx1,fy1,fx2,fy2;
- while(++j < i){
- fx1=m_flArrayxTemp.GetAt(j-1);
- fy1=m_flArrayyTemp.GetAt(j-1);
- fx2=m_flArrayxTemp.GetAt(j);
- fy2=m_flArrayyTemp.GetAt(j);
- nTemp=GetLineStateToRect(fx1,fy1,fx2,fy2,rect);
- nRltVal=nRltVal | nTemp;
- }
- if(nRltVal==3){
- nRltVal=1;
- }
- return nRltVal;
- }
- CRect CModelCurve3Param::GetBoundaryRect()
- {
- if(m_flArrayxTemp.GetSize()==0){
- return CRect(0,0,0,0);
- }
- CRect rect(1000*m_flArrayxTemp.GetAt(0),1000*m_flArrayyTemp.GetAt(0),1000*m_flArrayxTemp.GetAt(0),1000*m_flArrayyTemp.GetAt(0));
- int i=m_flArrayxTemp.GetSize();
- int j=0;
- float fx,fy;
- while(j++<i){
- fx=1000*m_flArrayxTemp.GetAt(j-1);
- fy=1000*m_flArrayyTemp.GetAt(j-1);
- if(fx<rect.left){
- rect.left=fx;
- }else if(fx>rect.right){
- rect.right=fx;
- }
- if(fy<rect.top){
- rect.top=fy;
- }else if(fy>rect.bottom){
- rect.bottom=fy;
- }
- }
- return rect;
- }
- CPoint CModelCurve3Param::GetCenterPoint()
- {
- CRect rect=GetBoundaryRect();
- return rect.CenterPoint();
- }
- int CModelCurve3Param::IsPointinRegion(POINT point)
- {
- int nRltVal=0;
- int i=m_flArrayx.GetSize();
- int j=0;
- CPoint pt1,pt2;
- CRect rect;
- while(++j < i){
- pt1.x=m_flArrayxTemp.GetAt(j-1);
- pt1.y=m_flArrayyTemp.GetAt(j-1);
- pt2.x=m_flArrayxTemp.GetAt(j);
- pt2.y=m_flArrayyTemp.GetAt(j);
- rect=GetRectFromPoint(pt1,pt2);
- if(rect.PtInRect(point)){
- nRltVal|=1;
- break;
- }
- }
- return nRltVal;
- }
- //////
- int CModelCurve3Param::GetPtState(float flx,float fly,float flRate)
- {
- int nRltVal=0;
- int i=m_flArrayx.GetSize();
- int j=0;
- CRect rect;
- float tmpx,tmpy;
- while(j++<i){
- tmpx=m_flArrayxTemp.GetAt(j-1);
- tmpy=m_flArrayyTemp.GetAt(j-1);
- if(IsPtInRect(tmpx-3*flRate,tmpy-3*flRate,tmpx+3*flRate,tmpy+3*flRate,flx,fly)){
- nRltVal|=1;
- m_nSelectPtNum=j-1;
- m_nSelectLineNum=-1;
- break;
- }
- }
- if(nRltVal==0){
- m_nSelectPtNum=-1;
- m_nSelectLineNum=-1;
- }
- return nRltVal;
- }
- //////////////////////////////////////////////////////////////////////
- // MODULE :ExPort
- // ABSTRACT :Export to a txt file
- // FUNCTION :File->Export...
- // NOTE :
- // RETURN :
- // ARGUMENTS:
- // I/O TYPE NAME EXPLANATION
- // O FILE* outStream Out put File
- // CREATE : FNST)handwolf 2004-4-14
- // UPDATE :
- // :
- //////////////////////////////////////////////////////////////////////
- void CModelCurve3Param::ExPort(FILE* outStream)//增加导出txt功能时用
- {
- fprintf(outStream, " CModelCurve3Param n");
- CShape::ExPort(outStream);
- int n=m_flArrayxTemp.GetSize();
- int i=0;
- fprintf(outStream, " %d ",n);
- while(i++ < n){
- fprintf( outStream, " %f %f",(float)m_flArrayxTemp.GetAt(i-1),(float)m_flArrayyTemp.GetAt(i-1));
- }
- fprintf( outStream, "n");
- }
- //////////////////////////////////////////////////////////////////////
- // 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 CModelCurve3Param::ImPort(FILE* inStream)
- {
- CShape::ImPort(inStream);
- float fx,fy;
- int n;
- fscanf(inStream, "%d",&n);
- int i=0;
- while(i++ < n){
- fscanf(inStream, "%f%f",&fx,&fy);
- m_flArrayx.Add(fx);
- m_flArrayy.Add(fy);
- //temp
- m_flArrayxTemp.Add(fx);
- m_flArrayyTemp.Add(fy);
- }
- }
- CString CModelCurve3Param::GetNameString()
- {
- CString str;
- str.LoadString(IDS_MODELCURVE3PARAM);
- return str;
- }
- //////////////////////////////////////////////////////////////////////
- //End of File////////////////
- ////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////