www.pudn.com > Daoli2.zip > DAOLI2View.cpp


// DAOLI2View.cpp : implementation of the CDAOLI2View class 
// 
 
#include "stdafx.h" 
#include "DAOLI2.h" 
 
#include "DAOLI2Doc.h" 
#include "DAOLI2View.h" 
 
#include "SETUP.h" 
#include "math.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
extern  bool DeListRules[RulesCounter]; 
extern int poleangle; 
extern int polespeed; 
///////////////////////////////////////////////////////////////////////////// 
// CDAOLI2View 
 
IMPLEMENT_DYNCREATE(CDAOLI2View, CView) 
 
BEGIN_MESSAGE_MAP(CDAOLI2View, CView) 
	//{{AFX_MSG_MAP(CDAOLI2View) 
	ON_WM_CREATE() 
	ON_WM_TIMER() 
	ON_WM_LBUTTONDBLCLK() 
	ON_WM_PAINT() 
	ON_WM_RBUTTONDOWN() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDAOLI2View construction/destruction 
 
CDAOLI2View::CDAOLI2View():nCarx(0),dcarF(0.0),bsettimer(false) 
{ 
    
	// TODO: add construction code here 
	blackBrush.CreateSolidBrush(RGB(0,0,0)); 
	dkgrayBrush.CreateSolidBrush(RGB(128,128,128)); 
    ltgrayBrush.CreateSolidBrush(RGB(192,192,192)); 
 
	blackPen.CreatePen(PS_SOLID,1,RGB(0,0,0)); 
	grayPen.CreatePen(PS_SOLID,4,RGB(192,192,192)); 
 
	 
} 
 
CDAOLI2View::~CDAOLI2View() 
{ 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CDAOLI2View drawing 
 
void CDAOLI2View::OnDraw(CDC* pDC) 
{ 
	//CDAOLI2Doc* pDoc = GetDocument(); 
	//ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here	 
} 
 
void CDAOLI2View::OnInitialUpdate() 
{ 
	CView::OnInitialUpdate(); 
    
 
	// TODO: This code navigates to a popular spot on the web. 
	//  change the code to go where you'd like. 
	//Navigate2(_T("http://www.sdu.edu.cn"),NULL,NULL); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CDAOLI2View diagnostics 
 
#ifdef _DEBUG 
void CDAOLI2View::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CDAOLI2View::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
/*CDAOLI2Doc* CDAOLI2View::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDAOLI2Doc))); 
	return (CDAOLI2Doc*)m_pDocument; 
}*/ 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CDAOLI2View message handlers 
 
 
BOOL CDAOLI2View::PreCreateWindow(CREATESTRUCT& cs)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	 
	return CView::PreCreateWindow(cs); 
} 
 
 
int CDAOLI2View::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
 
	for(int i=0;i-90)&&(dVpoleangle<90)) 
		{ 
			// TODO: Add your message handler code here and/or call default 
			GetcarF(); 
			CRect rect; 
			GetClientRect(rect); 
 
			nCarx=nCarx+(int)(dcarF*(double)rect.right/1000.0); 
			 
         
			 
			//mypDC 
 
			 
			 
			 
		    bool t1=(abs((int)dVpoleangle)<1),t2=(abs((int)dVpolespeed)<1),t4=(dVpoleangle>=90),t5=(dVpoleangle<=-90); 
			if(t4) 
			{ 
				dVpoleangle=90.0; 
			} 
			if(t5) 
			{ 
				dVpoleangle=-90.0; 
			} 
			poleangle=(int)dVpoleangle; 
			polespeed=(int)dVpolespeed; 
			bool t3; 
			t3=t1&&t2; 
			if(t3||t4||t5) 
			{ 
				bsettimer=false; 
				KillTimer(1); 
			} 
			else 
			{ 
				Invalidate(); 
			} 
		} 
	} 
	//CView::OnTimer(nIDEvent); 
} 
 
void CDAOLI2View::OnLButtonDblClk(UINT nFlags, CPoint point)  
{ 
	 
	if((dVpoleangle>-90)&&(dVpoleangle<90)) 
	{ 
		// TODO: Add your message handler code here and/or call default 
		GetcarF(); 
		CRect rect; 
		GetClientRect(rect); 
 
		nCarx=nCarx+(int)(dcarF*(double)rect.right/1000.0); 
 
		if(dVpoleangle>90) 
		{ 
			dVpoleangle=90; 
		} 
		else if(dVpoleangle<-90) 
		{ 
			dVpoleangle=-90; 
		} 
	 
		//mypDC 
 
		poleangle=(int)dVpoleangle; 
		polespeed=(int)dVpolespeed; 
		 
	 
		Invalidate(); 
	} 
		//CView::OnLButtonDblClk(nFlags, point); 
} 
 
 
void CDAOLI2View::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
 
	OnPrepareDC(&dc); 
 
 
	 
	// TODO: Add your message handler code here 
 
	for(int i=0;iGetSafeHwnd(); 
		 KillTimer(1); 
		 cwnd->SetTimer(1,20,NULL); 
		 bsettimer=true; 
	 } 
 
	  
	//CView::OnRButtonDown(nFlags, point); 
} 
 
 
void CDAOLI2View::GetcarF() 
{ 
	    double newangle=dVpoleangle;           //用到的中间变量 
		double newspeed=dVpolespeed; 
			 
		double ax=dVpoleangle/15.0,bx=dVpolespeed/60.0; 
		double ya1=0.0,ya2=0.0; 
		double yb1=0.0,yb2=0.0; 
		double yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		double cx0=0.0; 
 
		dcarF=0.0; 
 
		//state (1) 
		if((newangle<-15)&&(newspeed>=-30)&&(newspeed<30)) 
		{ 
			if(bx<0)               //输入隶属度函数的确定 
			{ 
				yb1=1+2.0*bx; 
			} 
			else 
			{ 
				yb1=1-2.0*bx; 
			} 
 
			//R[0] 
			if(bViewRules[0])       //推理 
			{	 
				yc1=yb1;		 
			} 
			else 
			{ 
				yc1=0.0; 
			} 
			 
			if(bViewRules[0])       //解模糊 
			{ 
				cx0=-0.25*yc1-0.75; 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (2) 
		else if((newangle>=-15)&&(newangle<-7.5)&&(newspeed>=0.0)&&(newspeed<30)) 
		{ 
			ya1=-2.0*ax-1,ya2=2*ax+2;   //输入隶属度函数的确定 
			yb1=1-2.0*bx,yb2=2*bx; 
 
			//R[0],R[1],R[2]并行推理 
 
			if(bViewRules[0])   //R[0]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)) 
				{ 
					cx0=-0.25*yc1-0.75; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)) 
				{ 
					cx0=0.25*yc2-0.75; 
				} 
				else 
				{ 
					cx0=0.25*yc3-0.25; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (3) 
		else if((newangle>=-15)&&(newangle<-7.5)&&(newspeed>=-30.0)&&(newspeed<0)) 
		{ 
			ya1=-2.0*ax-1,ya2=2*ax+2;   //输入隶属度函数的确定 
			yb1=2.0*bx+1.0,yb2=-2*bx; 
 
			//R[0],R[1]并行推理 
 
			if(bViewRules[0])   //R[0]推理 
			{ 
				if(ya1yc2) 
				{ 
					cx0=-0.25*yc1-0.75; 
				} 
				else 
				{ 
					cx0=0.25*yc2-0.75; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
 
		} 
		//state (4) 
		else if((newangle>=-7.5)&&(newangle<0)&&(newspeed>=-30.0)&&(newspeed<0)) 
		{ 
			ya1=2.0*ax+1,ya2=-2*ax;   //输入隶属度函数的确定 
			yb1=2.0*bx+1,yb2=-2*bx; 
 
			//R[5],R[4],R[1]并行推理 
 
			if(bViewRules[5])   //R[5]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)) 
				{ 
					cx0=0.25*yc1-0.25; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)) 
				{ 
					cx0=-0.25*yc2-0.25; 
				} 
				else 
				{ 
					cx0=-0.25*yc3-0.25; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (5) 
		else if((newangle>=-7.5)&&(newangle<0)&&(newspeed>=0.0)&&(newspeed<30.0)) 
		{ 
			ya1=2.0*ax+1,ya2=-2*ax;   //输入隶属度函数的确定 
			yb1=2.0*bx,yb2=1-2*bx; 
 
			//R[6],R[5],R[2],R[1]并行推理 
 
			if(bViewRules[6])   //R[6]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)&&(yc1>=yc4)) 
				{ 
					cx0=0.25*yc1+0.25; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)&&(yc2>=yc4)) 
				{ 
					if(ya1=yc1)&&(yc3>=yc2)&&(yc3>=yc4)) 
				{ 
					if(ya2=-7.5)&&(newangle<0)&&(newspeed>=30.0)&&(newspeed<60.0)) 
		{ 
			ya1=2.0*ax+1,ya2=-2*ax;   //输入隶属度函数的确定 
			yb1=-2.0*bx+2,yb2=2*bx-1; 
 
			//R[6],R[7],R[2]并行推理 
 
			if(bViewRules[6])   //R[6]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)) 
				{ 
					cx0=-0.25*yc1+0.75; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)) 
				{ 
					cx0=0.25*yc2+0.75; 
				} 
				else 
				{ 
					cx0=-0.25*yc3+0.25; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (7) 
		else if((newangle>=-7.5)&&(newangle<0)&&(newspeed>=-60.0)&&(newspeed<-30)) 
		{ 
			ya1=-2.0*ax+1,ya2=-2*ax;   //输入隶属度函数的确定 
			yb1=2.0*bx+2.0,yb2=-2*bx-1; 
 
			//R[4],R[3]并行推理 
 
			if(bViewRules[4])   //R[4]推理 
			{ 
				if(ya1yc2) 
				{ 
					cx0=0.25*yc1-0.75; 
				} 
				else 
				{ 
					cx0=-0.25*yc2-0.75; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
 
		} 
		//state (8) 
		else if((newangle>=0)&&(newangle<7.5)&&(newspeed>=0.0)&&(newspeed<30)) 
		{ 
			ya1=-2.0*ax+1,ya2=2*ax;   //输入隶属度函数的确定 
			yb1=-2.0*bx+1,yb2=2*bx; 
 
			//R[5],R[6],R[9]并行推理 
 
			if(bViewRules[5])   //R[5]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)) 
				{ 
					cx0=-0.25*yc1+0.25; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)) 
				{ 
					cx0=0.25*yc2+0.25; 
				} 
				else 
				{ 
					cx0=0.25*yc3+0.25; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (9) 
		else if((newangle>=0)&&(newangle<7.5)&&(newspeed>=-30.0)&&(newspeed<0.0)) 
		{ 
			ya1=-2.0*ax+1,ya2=2*ax;   //输入隶属度函数的确定 
			yb1=2.0*bx+1,yb2=-2*bx; 
 
			//R[5],R[4],R[9],R[8]并行推理 
 
			if(bViewRules[5])   //R[5]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)&&(yc1>=yc4)) 
				{ 
					if(ya1=yc1)&&(yc2>=yc3)&&(yc2>=yc4)) 
				{ 
					cx0=-0.25*yc2-0.25;			 
				} 
				else if((yc3>=yc1)&&(yc3>=yc2)&&(yc3>=yc4)) 
				{ 
					cx0=0.25*yc3+0.25;				 
				} 
				else 
				{ 
					if(ya2=0)&&(newangle<7.5)&&(newspeed>=-60.0)&&(newspeed<-30.0)) 
		{ 
			ya1=-2.0*ax+1,ya2=2*ax;   //输入隶属度函数的确定 
			yb1=2.0*bx+2,yb2=-2*bx-1; 
 
			//R[4],R[3],R[8]并行推理 
 
			if(bViewRules[4])   //R[4]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)) 
				{ 
					cx0=0.25*yc1-0.75; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)) 
				{ 
					cx0=-0.25*yc2-0.75; 
				} 
				else 
				{ 
					cx0=0.25*yc3-0.25; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (11) 
		else if((newangle>=0)&&(newangle<7.5)&&(newspeed>=30.0)&&(newspeed<60)) 
		{ 
			ya1=-2.0*ax+1,ya2=2*ax;   //输入隶属度函数的确定 
			yb1=-2.0*bx+2.0,yb2=2*bx-1; 
 
			//R[6],R[7]并行推理 
 
			if(bViewRules[6])   //R[6]推理 
			{ 
				if(ya1yc2) 
				{ 
					cx0=-0.25*yc1+0.75; 
				} 
				else 
				{ 
					cx0=0.25*yc2+0.75; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
 
		} 
		//state (12) 
		else if((newangle>=7.5)&&(newangle<15)&&(newspeed>=0.0)&&(newspeed<30)) 
		{ 
			ya1=-2.0*ax+2,ya2=2*ax-1;   //输入隶属度函数的确定 
			yb1=-2.0*bx+1.0,yb2=2*bx; 
 
			//R[9],R[10]并行推理 
 
			if(bViewRules[9])   //R[9]推理 
			{ 
				if(ya1yc2) 
				{ 
					cx0=-0.25*yc1+0.75; 
				} 
				else 
				{ 
					cx0=0.25*yc2+0.75; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
 
		} 
		//state (13) 
		else if((newangle>=7.5)&&(newangle<15)&&(newspeed>=-30.0)&&(newspeed<0)) 
		{ 
			ya1=-2.0*ax+2,ya2=2*ax-1;   //输入隶属度函数的确定 
			yb1=2.0*bx+1,yb2=-2*bx; 
 
			//R[9],R[8],R[10]并行推理 
 
			if(bViewRules[9])   //R[9]推理 
			{ 
				if(ya1=yc2)&&(yc1>=yc3)) 
				{ 
					cx0=-0.25*yc1+0.75; 
				} 
				else if((yc2>=yc1)&&(yc2>=yc3)) 
				{ 
					cx0=-0.25*yc2+0.25; 
				} 
				else 
				{ 
					cx0=0.25*yc3+0.75; 
				} 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (14) 
		else if((newangle>15)&&(newspeed>=-30)&&(newspeed<30)) 
		{ 
			if(bx<0)               //输入隶属度函数的确定 
			{ 
				yb1=1+2.0*bx; 
			} 
			else 
			{ 
				yb1=1-2.0*bx; 
			} 
 
			//R[10] 
			if(bViewRules[10])       //推理 
			{	 
				yc1=yb1;		 
			} 
			else 
			{ 
				yc1=0.0; 
			} 
			 
			if(bViewRules[10])       //解模糊 
			{ 
				cx0=0.25*yc1+0.75; 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (15) 
		else if((newangle>=-7.5)&&(newangle<7.5)&&(newspeed<-60)) 
		{ 
			if(ax<0)               //输入隶属度函数的确定 
			{ 
				ya1=1+2.0*ax; 
			} 
			else 
			{ 
				ya1=1-2.0*ax; 
			} 
 
			//R[3] 
			if(bViewRules[3])       //推理 
			{	 
				yc1=ya1;		 
			} 
			else 
			{ 
				yc1=0.0; 
			} 
			 
			if(bViewRules[3])       //解模糊 
			{ 
				cx0=-0.25*yc1-0.75; 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (16) 
		else if((newangle>=-7.5)&&(newangle<7.5)&&(newspeed>=60)) 
		{ 
			if(ax<0)               //输入隶属度函数的确定 
			{ 
				ya1=1+2.0*ax; 
			} 
			else 
			{ 
				ya1=1-2.0*ax; 
			} 
 
			//R[7] 
			if(bViewRules[7])       //推理 
			{	 
				yc1=ya1;		 
			} 
			else 
			{ 
				yc1=0.0; 
			} 
			 
			if(bViewRules[7])       //解模糊 
			{ 
				cx0=0.25*yc1+0.75; 
			} 
			else 
			{ 
				cx0=0.0; 
			} 
 
			ya1=0.0,ya2=0.0;        //还原输入中间变量 
			yb1=0.0,yb2=0.0; 
			yc1=0.0,yc2=0.0,yc3=0.0,yc4=0.0; 
		} 
		//state (17) 
		else if((newangle>=-15)&&(newangle<-7.5)&&(newspeed>=30)&&(newspeed<60)) 
		{ 
			 //输入隶属度函数的确定 
			ya1=-2.0*ax-1.0,ya2=2.0*ax+2; 
			yb1=-2.0*bx+2.0,yb2=2.0*bx-1; 
			 
			//R[2] 
			if(bViewRules[2])       //推理 
			{	 
				if(ya2=7.5)&&(newangle<15)&&(newspeed>=-60)&&(newspeed<30)) 
		{ 
			 //输入隶属度函数的确定 
			ya1=-2.0*ax+2.0,ya2=2.0*ax-1; 
			yb1=2.0*bx+2.0,yb2=-2.0*bx-1; 
			 
			//R[8] 
			if(bViewRules[8])       //推理 
			{	 
				if(ya1