00001
00002
00003
00004 #include "stdafx.h"
00005 #include "EvolveTraffic.h"
00006 #include "SimConfigDlg.h"
00007
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013
00015
00016
00017
00018 CSimConfigDlg::CSimConfigDlg(CWnd* pParent )
00019 : CDialogExt(CSimConfigDlg::IDD, pParent)
00020 {
00021
00022 m_FileIn = _T("");
00023 m_RoadLength = 5000;
00024 m_NoLanesDirPos = 1;
00025 m_NoLanesDirNeg = 1;
00026 m_FileType = CASTOR;
00027 m_SimTimeStep = 100;
00028 m_TrafFileNoLanesDirPos = -1;
00029 m_TrafFileNoLanesDirNeg = -1;
00030 m_FileOut = _T("");
00031 m_DriveOnRight = true;
00032 m_LocOutputDetectorDirPos = 0;
00033 m_LocOutputDetectorDirNeg = 0;
00034 m_AllowLaneChanging = true;
00035 m_intDriveSide = -1;
00036 m_MetricsDir = _T("");
00037
00038 }
00039
00040
00041 void CSimConfigDlg::DoDataExchange(CDataExchange* pDX)
00042 {
00043 CDialogExt::DoDataExchange(pDX);
00044
00045 DDX_Text(pDX, IDC_EDT_FILE_IN, m_FileIn);
00046 DDX_Text(pDX, IDC_EDT_ROADLENGTH, m_RoadLength);
00047 DDV_MinMaxInt(pDX, m_RoadLength, 500, 100000);
00048 DDX_CBIndex(pDX, IDC_CMB_LANESDIRPOS, m_NoLanesDirPos);
00049 DDX_CBIndex(pDX, IDC_CMB_LANESDIRNEG, m_NoLanesDirNeg);
00050 DDX_Text(pDX, IDC_EDT_SIMTIMESTEP, m_SimTimeStep);
00051 DDV_MinMaxInt(pDX, m_SimTimeStep, 10, 2000);
00052 DDX_CBIndex(pDX, IDC_CMB_TRAFFILE_LANESDIR1, m_TrafFileNoLanesDirPos);
00053 DDX_CBIndex(pDX, IDC_CMB_TRAFFILE_LANESDIR2, m_TrafFileNoLanesDirNeg);
00054 DDX_Text(pDX, IDC_EDT_FILE_OUT, m_FileOut);
00055 DDX_Text(pDX, IDC_EDT_DIRPOSDETECTOR, m_LocOutputDetectorDirPos);
00056 DDX_Text(pDX, IDC_EDT_DIRNEGDETECTOR, m_LocOutputDetectorDirNeg);
00057 DDX_Check(pDX, IDC_CHECK_LANECHNG, m_AllowLaneChanging);
00058 DDX_CBIndex(pDX, IDC_CMB_DRIVESIDE, m_intDriveSide);
00059 DDX_Text(pDX, IDC_EDT_METRICSOUT, m_MetricsDir);
00060
00061 }
00062
00063
00064 BEGIN_MESSAGE_MAP(CSimConfigDlg, CDialogExt)
00065
00066 ON_BN_CLICKED(IDC_BTN_FILEINPICK, OnBtnFileInPick)
00067 ON_BN_CLICKED(IDC_BTN_FILEOUTPICK, OnBtnFileOutPick)
00068 ON_BN_CLICKED(IDC_RAD_CASTOR, OnRadCastor)
00069 ON_BN_CLICKED(IDC_RAD_SAFT, OnRadSaft)
00070 ON_CBN_SELCHANGE(IDC_CMB_DRIVESIDE, OnSelchangeCmbDriveside)
00071 ON_BN_CLICKED(IDC_BTN_METRICSOUT, OnBtnMetricsout)
00072
00073 END_MESSAGE_MAP()
00074
00076
00077
00078 void CSimConfigDlg::OnValidate(UINT &nID, CString &strMessage)
00079 {
00080 UpdateData();
00081
00082 CString strFileIn, strFileOut, strNoLanesDirPos, strNoLanesDirNeg;
00083 CString strSimTimeStep, strTrafFileNoLanesDirPos, strTrafFileNoLanesDirNeg;
00084 CString strDriveSide, strLocOutputDetectorDirPos, strLocOutputDetectorDirNeg;
00085
00086 GetDlgItemText(IDC_EDT_FILE_IN, strFileIn);
00087 GetDlgItemText(IDC_EDT_FILE_OUT, strFileOut);
00088 GetDlgItemText(IDC_CMB_LANESDIRPOS, strNoLanesDirPos);
00089 GetDlgItemText(IDC_CMB_LANESDIRNEG, strNoLanesDirNeg);
00090 GetDlgItemText(IDC_CMB_TRAFFILE_LANESDIR1, strTrafFileNoLanesDirPos);
00091 GetDlgItemText(IDC_CMB_TRAFFILE_LANESDIR2, strTrafFileNoLanesDirNeg);
00092
00093 if(strFileIn.IsEmpty())
00094 {
00095 strMessage = "Please select a file.";
00096 nID = IDC_EDT_FILE_IN;
00097 return;
00098 }
00099
00100 if(strFileOut.IsEmpty())
00101 {
00102 strMessage = "Please specify a filename.";
00103 nID = IDC_EDT_FILE_OUT;
00104 return;
00105 }
00106
00107 if(strNoLanesDirPos.IsEmpty())
00108 {
00109 strMessage = "Please specify the number of lanes.";
00110 nID = IDC_CMB_LANESDIRPOS;
00111 return;
00112 }
00113
00114 if(strNoLanesDirNeg.IsEmpty())
00115 {
00116 strMessage = "Please specify the number of lanes.";
00117 nID = IDC_CMB_LANESDIRNEG;
00118 return;
00119 }
00120
00121 if(strTrafFileNoLanesDirPos.IsEmpty())
00122 {
00123 strMessage = "Please specify the number of lanes.";
00124 nID = IDC_CMB_TRAFFILE_LANESDIR1;
00125 return;
00126 }
00127
00128 if(strTrafFileNoLanesDirNeg.IsEmpty())
00129 {
00130 strMessage = "Please specify the number of lanes.";
00131 nID = IDC_CMB_TRAFFILE_LANESDIR2;
00132 return;
00133 }
00134
00135 if(m_TrafFileNoLanesDirPos == 0 && m_TrafFileNoLanesDirNeg == 0)
00136 {
00137 strMessage = "There cannot be zero lanes in both directions";
00138 nID = IDC_CMB_TRAFFILE_LANESDIR1;
00139 return;
00140 }
00141
00142 if(m_TrafFileNoLanesDirPos > m_NoLanesDirPos)
00143 {
00144 strMessage = "The number of simulation lanes must not \nbe less than that of the traffic file.";
00145 nID = IDC_CMB_LANESDIRPOS;
00146 return;
00147 }
00148
00149 if(m_TrafFileNoLanesDirNeg > m_NoLanesDirNeg)
00150 {
00151 strMessage = "The number of simulation lanes must not \nbe less than that of the traffic file.";
00152 nID = IDC_CMB_LANESDIRNEG;
00153 return;
00154 }
00155
00156 if(m_LocOutputDetectorDirPos > m_RoadLength)
00157 {
00158 strMessage = "The output dector must be located on the road \n- please check the road length";
00159 nID = IDC_EDT_DIRPOSDETECTOR;
00160 return;
00161 }
00162
00163 if(m_LocOutputDetectorDirNeg > m_RoadLength)
00164 {
00165 strMessage = "The output dector must be located on the road \n- please check the road length";
00166 nID = IDC_EDT_DIRNEGDETECTOR;
00167 return;
00168 }
00169
00170 if(m_TrafFileNoLanesDirPos == 0 && m_NoLanesDirPos > 0)
00171 {
00172 strMessage = "For this direction, there will be no vehicles \nsince there are no lanes in the traffic file";
00173 nID = IDC_CMB_LANESDIRPOS;
00174 return;
00175 }
00176
00177 if(m_TrafFileNoLanesDirNeg == 0 && m_NoLanesDirNeg > 0)
00178 {
00179 strMessage = "For this direction, there will be no vehicles \nsince there are no lanes in the traffic file";
00180 nID = IDC_CMB_LANESDIRNEG;
00181 return;
00182 }
00183 }
00184
00185 BOOL CSimConfigDlg::OnInitDialog()
00186 {
00187 CDialogExt::OnInitDialog();
00188
00189 switch (m_FileType)
00190 {
00191 case SAFT:
00192 CheckDlgButton(IDC_RAD_SAFT,1);
00193 break;
00194 case CASTOR:
00195 CheckDlgButton(IDC_RAD_CASTOR,1);
00196 break;
00197 default:
00198 CheckDlgButton(IDC_RAD_CASTOR,1);
00199 }
00200
00201 m_intDriveSide = 1;
00202 if(!m_DriveOnRight)
00203 m_intDriveSide = 0;
00204 CComboBox * pCmb = (CComboBox*)GetDlgItem(IDC_CMB_DRIVESIDE);
00205 pCmb->SetCurSel(m_intDriveSide);
00206
00207 return TRUE;
00208 }
00209
00210 void CSimConfigDlg::OnBtnFileInPick()
00211 {
00212
00213
00214
00215
00216 CFileDialog FileDlg(
00217 TRUE,
00218 NULL,
00219 NULL,
00220 OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY,
00221 "All Files (*.*)|*.*||",
00222 this);
00223
00224 if(FileDlg.DoModal() == IDOK)
00225 {
00226 m_FileIn = FileDlg.GetPathName();
00227 UpdateData(FALSE);
00228 }
00229 }
00230
00231 void CSimConfigDlg::OnBtnFileOutPick()
00232 {
00233 CFileDialog FileDlg(
00234 FALSE,
00235 _T("*.txt"),
00236 NULL,
00237 OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
00238 "text files (*.txt) |*.txt|All Files (*.*)|*.*||",
00239 this);
00240
00241 if(FileDlg.DoModal() == IDOK)
00242 {
00243 m_FileOut = FileDlg.GetPathName();
00244 UpdateData(FALSE);
00245 }
00246 }
00247
00248 void CSimConfigDlg::OnBtnMetricsout()
00249 {
00250 BROWSEINFO bi = { 0 };
00251 bi.lpszTitle = _T("Pick a Directory");
00252 LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
00253 if ( pidl != 0 )
00254 {
00255
00256 TCHAR path[MAX_PATH];
00257 if ( SHGetPathFromIDList ( pidl, path ) )
00258 {
00259
00260 m_MetricsDir = path;
00261 m_MetricsDir += "\\";
00262 UpdateData(FALSE);
00263 }
00264 else
00265 MessageBox("Error in selecting folder - please type the name","EvolveTraffic",MB_OK | MB_ICONWARNING);
00266
00267
00268 IMalloc * imalloc = 0;
00269 if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
00270 {
00271 imalloc->Free ( pidl );
00272 imalloc->Release ( );
00273 }
00274 }
00275 }
00276
00277 void CSimConfigDlg::OnRadCastor()
00278 {
00279 m_FileType = CASTOR;
00280 }
00281
00282 void CSimConfigDlg::OnRadSaft()
00283 {
00284 m_FileType = SAFT;
00285 }
00286
00287 void CSimConfigDlg::OnSelchangeCmbDriveside()
00288 {
00289 CString str;
00290 GetDlgItemText(IDC_CMB_DRIVESIDE, str);
00291
00292 if(str == "Left")
00293 m_DriveOnRight = false;
00294 else
00295 m_DriveOnRight = true;
00296 }