?? control.cpp
字號:
#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<POINT> vecpoint;
vector<int> vec;
CGA ga;
if( (MapObject->GetAllClickPoint( )).size( )<=2)
{ 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( )<=0)
{ return;}
if(LineObject.GetPointPosition( ).size( )<=2)
{
LineObject.DrawLine(hwnd,MapObject->GetAllClickPoint( ));
return;
}
LineObject.DrawLine(hwnd,LineObject.GetPointPosition( ));
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -