#include "control.h"
////////////////////////// 提供提示和帮助信息 /////////////////////////////
void Control::welcome(HWND hwnd)
{
//创建一个对话框显示提示信息
MessageBox(hwnd, "点击鼠标左键设置点位置点\n 点击鼠标右键清空所有点\n点菜单开始或ENTER进行寻路\n详细信息请选菜单中帮助",
"遗传算法演示实验", MB_OK );
return;
}
void Control::help(HWND hwnd)
{
}
////////////////////////获得和设置地图类型 交叉率变异率种群大小最大世代数/////////////////////////////
UINT Control::GetMapStyle( ) //获得当前地图类型
{ return MapStyle; }
void Control::SetMapStyle(HWND hwnd, WPARAM wParam) //设置地图类型
{
HMENU hMenu ;
hMenu = GetMenu (hwnd) ;
switch (LOWORD (wParam))
{
case ID_DefaultMap :
{ MapObject= &DefaultMapObject;}break;
case ID_RoundMap :
{ MapObject=&RoundMapObject ;}break;
default :
break;
}
CheckMenuItem (hMenu, MapStyle, MF_UNCHECKED);
MapStyle=LOWORD (wParam);
CheckMenuItem (hMenu, MapStyle, MF_CHECKED );
return;
}
void Control::SetGaInformation(float fpcross ,float fpmutation , int fpopsize , int fmaxgen)
{ //依次交叉率变异率种群大小最大世代数
if( pcross!=0 ) { pcross=fpcross ;}
if(pmutation!=0) { pmutation=fpmutation;}
if( popsize!=0|| popsize!=1) { popsize=fpopsize ;}
if( maxgen!=0|| popsize!=1 ) { maxgen=fmaxgen ;}
return;
}
//////////////////////////// 清除所有点 /////////////////////////////////
void Control::CleanAllUpDate( )
{
MapObject->DelAllPoint();
return ;
}
/////////////////////////显示其它与鼠标位置 或地图相关信息//////////////////////////
void Control::DisPlay( HWND hwnd ,const POINT& point,bool bdrawline)
{
HDC hdc;
int n=0;
POINT temppoint;
char buffer[80]; // used to print strings
hdc=GetDC(hwnd);
SetBkMode(hdc,OPAQUE);
SetTextColor(hdc,RGB(0,0,0));
sprintf(buffer,"Point %d",(MapObject->GetAllClickPoint()).size() ); //显示点的个数
TextOut(hdc,0,n,buffer,strlen(buffer)); // print the message
if( bdrawline==1 ) // 当前未准备好所有的点
{ TextOut(hdc,60,0," Distance 0 ",15); } //连线总长为0
else
{
sprintf(buffer," Distance%d", LineObject.GetSumDistance( ) ); //显示连线总长
TextOut(hdc,60,0,buffer,strlen(buffer));
}
if(MapStyle==ID_DefaultMap ) //默认地图才显示坐标
{
temppoint=DefaultMapObject.GetMapPoint(point); //获得地图上的点位置700*400
if(-1!=temppoint.x ) //测试点再有效区没有
{ SetTextColor(hdc,RGB(0,0,0)); } //没在无效区域则为黑笔
else
{ SetTextColor(hdc,RGB(255,0,0));} //在无效区域则为红笔
sprintf(buffer,"cx%d", temppoint.x);
TextOut(hdc,0,20,buffer,strlen(buffer)); // print the message
sprintf(buffer,"cy%d", temppoint.y);
TextOut(hdc,0,40,buffer,strlen(buffer)); // print the message
}
ReleaseDC (hwnd, hdc);
return;
}
////////////////////////以下为画地图,画线,画单和所有点,涂点(擦除点)//////////////////////
void Control::DrawMap(HWND hwnd,HDC hdc )
{
MapObject->DrawMap( hwnd,hdc);
return;
}
void Control::DrawAllPoint(HWND hwnd) //画出所有在向量里的点
{
for( int n=(MapObject->GetAllClickPoint( )).size( );n>0;)
{ MapObject->DrawPonit(hwnd, (MapObject->GetAllClickPoint( ) )[--n] );}
return;
}
void Control::DrawTruePoint( HWND hwnd ,const POINT& point )
{
MapObject->DrawPonit( hwnd , point);
return;
}
void Control::DrawFalsePoint( HWND hwnd ,const POINT& point )
{
MapObject->SmearPonit( hwnd , point);
return;
}
////////////////////////////// 画线的准备和画线 //////////////
void Control::DrawLineWait( )
{
vector vecpoint;
vector vec;
CGA ga;
if( (MapObject->GetAllClickPoint( )).size( ) { return;}
LineObject.SetPointMatrix(MapObject->GetAllClickPoint( ) ); //将地图中所有点一位置作参数
//产生点的矩阵
ga.preSet(LineObject.GetPointMatrix(),pcross,pmutation,popsize,maxgen,power+1);//矩阵作参数
LineObject.GaInterface( ga.start() );
}
void Control::DrawLine(HWND hwnd)
{
if(LineObject.GetPointPosition( ).size( ) { return;}
if(LineObject.GetPointPosition( ).size( ) {
LineObject.DrawLine(hwnd,MapObject->GetAllClickPoint( ));
return;
}
LineObject.DrawLine(hwnd,LineObject.GetPointPosition( ));
}