00001
00002
00003
00004 #include "stdafx.h"
00005 #include "EvolveTraffic.h"
00006 #include "TrafficConfigDlg.h"
00007
00008 #include "GridCtrl_src/GridCellCombo.h"
00009 #include "GridCtrl_src/GridCellNumeric.h"
00010
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016
00018
00019
00020
00021 CTrafficConfigDlg::CTrafficConfigDlg(CWnd* pParent )
00022 : CDialog(CTrafficConfigDlg::IDD, pParent)
00023 {
00024 m_sDistributions.Add("Exponential");
00025 m_sDistributions.Add("Log-Normal");
00026 m_sDistributions.Add("Gamma");
00027 m_sDistributions.Add("Gumbel");
00028 m_sDistributions.Add("Poisson");
00029 m_sDistributions.Add("GEV");
00030 m_sDistributions.Add("Normal");
00031 m_sDistributions.Add("Constant");
00032
00033 m_sColumnHeaders.Add("Distribution");
00034 m_sColumnHeaders.Add("Location");
00035 m_sColumnHeaders.Add("Scale");
00036 m_sColumnHeaders.Add("Shape");
00037
00038 m_sRowHeaders.Add("Safe time headway, T (s)");
00039 m_sRowHeaders.Add("Maximum acceleration, a (m/s^2)");
00040 m_sRowHeaders.Add("Comfortable decceleration, b (m/s^2)");
00041 m_sRowHeaders.Add("Minimum jam distance, s0 (m)");
00042 m_sRowHeaders.Add("Elastic jam distance, s1 (m)");
00043 m_sRowHeaders.Add("Desired velocity, v0 (km/h)");
00044 m_sRowHeaders.Add("Acceleration exponent, delta");
00045 m_sRowHeaders.Add("Lane change politeness factor, p");
00046 m_sRowHeaders.Add("Outside lane bias factor, deltaAbias");
00047 m_sRowHeaders.Add("Lane change threshold, deltaAth (m/s^2)");
00048
00049 m_sCmbOptions.Add("Class 0 - Cars");
00050 m_sCmbOptions.Add("Class 1 - Small Truck");
00051 m_sCmbOptions.Add("Class 2 - Large Truck");
00052 m_sCmbOptions.Add("Class 3 - Crane");
00053 m_sCmbOptions.Add("Class 4 - Low-loader");
00054
00055 m_nFixCols = FIXED_COLUMNS;
00056 m_nFixRows = FIXED_ROWS;
00057 m_nCols = m_sColumnHeaders.GetSize() + m_nFixCols;
00058 m_nRows = m_sRowHeaders.GetSize() + m_nFixRows;
00059
00060
00061
00062
00063 }
00064
00065
00066 void CTrafficConfigDlg::DoDataExchange(CDataExchange* pDX)
00067 {
00068 CDialog::DoDataExchange(pDX);
00069
00070 DDX_Control(pDX, IDC_CMB_CLASSCOPY, m_cmbVehicleClassCopy);
00071 DDX_Control(pDX, IDC_CMB_CLASSDEFINE, m_cmbVehicleClassDefine);
00072 DDX_Control(pDX, IDC_GRID, m_Grid);
00073
00074 }
00075
00076
00077 BEGIN_MESSAGE_MAP(CTrafficConfigDlg, CDialog)
00078
00079 ON_BN_CLICKED(IDC_BTN_COPY, OnBtnCopy)
00080 ON_CBN_SELCHANGE(IDC_CMB_CLASSCOPY, OnSelchangeCmbClassCopy)
00081 ON_CBN_SELCHANGE(IDC_CMB_CLASSDEFINE, OnSelchangeCmbClassDefine)
00082 ON_NOTIFY(GVN_ENDLABELEDIT, IDC_GRID, OnGridEndEdit)
00083
00084 END_MESSAGE_MAP()
00085
00087
00088
00089 BOOL CTrafficConfigDlg::OnInitDialog()
00090 {
00091 CDialog::OnInitDialog();
00092
00093 TRY {
00094 m_Grid.SetRowCount(m_nRows);
00095 m_Grid.SetColumnCount(m_nCols);
00096 m_Grid.SetFixedRowCount(m_nFixRows);
00097 m_Grid.SetFixedColumnCount(m_nFixCols);
00098 }
00099 CATCH (CMemoryException, e)
00100 {
00101 e->ReportError();
00102 return FALSE;
00103 }
00104 END_CATCH
00105
00106 SetGridHeadings();
00107 SetCells();
00108 m_Grid.AutoSizeColumn(0);
00109 m_Grid.ExpandToFit();
00110
00111 m_pCurrentIDMParamSet = &m_IDMParams_Car;
00112 LoadParamsIntoGrid();
00113
00114
00115 for(int i = 0; i < m_sCmbOptions.GetSize(); i++)
00116 {
00117 m_cmbVehicleClassDefine.AddString(m_sCmbOptions.GetAt(i));
00118 m_cmbVehicleClassCopy.AddString(m_sCmbOptions.GetAt(i));
00119 }
00120
00121 m_cmbVehicleClassDefine.SelectString(0,m_sCmbOptions.GetAt(0));
00122
00123 return TRUE;
00124 }
00125
00126 void CTrafficConfigDlg::SetGridHeadings()
00127 {
00128 int row = 0;
00129 int col = 0;
00130
00131
00132 for (col = 1; col < m_nCols; col++)
00133 m_Grid.SetItemText(row,col,m_sColumnHeaders.GetAt(col-1));
00134
00135
00136 col = 0;
00137 for (row = 1; row < m_nRows; row++)
00138 m_Grid.SetItemText(row,col,m_sRowHeaders.GetAt(row-1));
00139 }
00140
00141 void CTrafficConfigDlg::SetCells()
00142 {
00143 for (int row = 1; row < m_nRows; row++)
00144 {
00145 int col = 1;
00146 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellCombo));
00147 CGridCellCombo *pCell = (CGridCellCombo*) m_Grid.GetCell(row,col);
00148 pCell->SetOptions(m_sDistributions);
00149 pCell->SetStyle(CBS_DROPDOWNLIST);
00150 }
00151
00152 for (row = 1; row < m_nRows; row++)
00153 {
00154 for (int col = 2; col < m_nCols; col++)
00155 {
00156 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellNumeric));
00157 m_Grid.GetCell(row,col)->SetFormat(DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
00158 CGridCellNumeric *pCell = (CGridCellNumeric*)m_Grid.GetCell(row,col);
00159 pCell->SetFlags(CGridCellNumeric::Real | CGridCellNumeric::Negative);
00160 }
00161 }
00162 }
00163
00164 void CTrafficConfigDlg::LoadParamsIntoGrid()
00165 {
00166
00167
00168
00169
00170 LoadRow(m_nFixRows);
00171 LoadRow(m_nFixRows+1);
00172 LoadRow(m_nFixRows+2);
00173 LoadRow(m_nFixRows+3);
00174 LoadRow(m_nFixRows+4);
00175 LoadRow(m_nFixRows+5);
00176 LoadRow(m_nFixRows+6);
00177 LoadRow(m_nFixRows+7);
00178 LoadRow(m_nFixRows+8);
00179 LoadRow(m_nFixRows+9);
00180
00181 m_Grid.Refresh();
00182 }
00183
00184 void CTrafficConfigDlg::LoadRow(int row)
00185 {
00186 CParameter* pParam = MapRowToParameter(row);
00187
00188 int col = m_nFixCols;
00189 CString txt = MapDistributionID( pParam->getDistribution()->getDistributionID() );
00190 m_Grid.SetItemText(row,col,txt);
00191
00192 CGridCellNumeric* pCell1 = (CGridCellNumeric *)(m_Grid.GetCell(row,col+1));
00193 CGridCellNumeric* pCell2 = (CGridCellNumeric *)(m_Grid.GetCell(row,col+2));
00194 CGridCellNumeric* pCell3 = (CGridCellNumeric *)(m_Grid.GetCell(row,col+3));
00195 pCell1->SetNumber(pParam->getDistribution()->getLocation());
00196 pCell2->SetNumber(pParam->getDistribution()->getScale());
00197 pCell3->SetNumber(pParam->getDistribution()->getShape());
00198 }
00199
00200 void CTrafficConfigDlg::OnBtnCopy()
00201 {
00202
00203 if( m_pCurrentIDMParamSet != NULL && m_pCopyIDMParamSet != NULL)
00204 {
00205
00206 if( m_pCurrentIDMParamSet != m_pCopyIDMParamSet )
00207 {
00208
00209 *m_pCurrentIDMParamSet = *m_pCopyIDMParamSet;
00210 LoadParamsIntoGrid();
00211 }
00212 }
00213 }
00214
00215 void CTrafficConfigDlg::OnSelchangeCmbClassCopy()
00216 {
00217 int iSelect = m_cmbVehicleClassCopy.GetCurSel();
00218 m_pCopyIDMParamSet = MapIDMParamSet(iSelect);
00219 }
00220
00221 void CTrafficConfigDlg::OnSelchangeCmbClassDefine()
00222 {
00223
00224 int iSelect = m_cmbVehicleClassDefine.GetCurSel();
00225 m_pCurrentIDMParamSet = MapIDMParamSet(iSelect);
00226
00227 LoadParamsIntoGrid();
00228 }
00229
00230
00231 void CTrafficConfigDlg::OnGridEndEdit(NMHDR *pNotifyStruct, LRESULT* pResult)
00232 {
00233
00234
00235
00236 NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
00237
00238 int row = pItem->iRow;
00239 int col = pItem->iColumn;
00240
00241 if(col == m_nFixCols)
00242 {
00243 CString strCell = m_Grid.GetCell(row,col)->GetText();
00244 if(strCell != "")
00245 {
00246
00247 SetParamData(row,col,strCell);
00248 *pResult = 0;
00249 }
00250 else
00251 *pResult = -1;
00252 }
00253 else
00254 {
00255
00256
00257 double val = ((CGridCellNumeric *)(m_Grid.GetCell(row,col)))->GetNumber();
00258 SetParamData(row,col,val);
00259 *pResult = 0;
00260 }
00261 }
00262
00263 void CTrafficConfigDlg::SetParamData(int row, int col, CString str)
00264 {
00265 CParameter* currentParam = MapRowToParameter(row);
00266 WORD dist = MapDistributionString(str);
00267 currentParam->getDistribution()->setDistributionID(dist);
00268 }
00269
00270 void CTrafficConfigDlg::SetParamData(int row, int col, double val)
00271 {
00272 CParameter* currentParam = MapRowToParameter(row);
00273
00274
00275 col = col - m_nFixCols;
00276 switch(col)
00277 {
00278 case 1:
00279 currentParam->getDistribution()->setLocation(val);
00280 break;
00281 case 2:
00282 currentParam->getDistribution()->setScale(val);
00283 break;
00284 case 3:
00285 currentParam->getDistribution()->setShape(val);
00286 break;
00287 default:
00288 currentParam->getDistribution()->setLocation(val);
00289 }
00290 }
00291
00294
00295 CParameter* CTrafficConfigDlg::MapRowToParameter(int row)
00296 {
00297
00298
00299
00300
00301 row = row - m_nFixRows;
00302 switch(row)
00303 {
00304 case 0: return m_pCurrentIDMParamSet->get_T();
00305 case 1: return m_pCurrentIDMParamSet->get_A();
00306 case 2: return m_pCurrentIDMParamSet->get_B();
00307 case 3: return m_pCurrentIDMParamSet->get_S0();
00308 case 4: return m_pCurrentIDMParamSet->get_S1();
00309 case 5: return m_pCurrentIDMParamSet->get_V0();
00310 case 6: return m_pCurrentIDMParamSet->get_Delta();
00311 case 7: return m_pCurrentIDMParamSet->get_Polite();
00312 case 8: return m_pCurrentIDMParamSet->get_Bias();
00313 case 9: return m_pCurrentIDMParamSet->get_DeltaAth();
00314 default: return m_pCurrentIDMParamSet->get_T();
00315 }
00316 }
00317
00318 CIDMParameterSet* CTrafficConfigDlg::MapIDMParamSet(int iSelect)
00319 {
00320
00321
00322
00323
00324
00325 switch(iSelect)
00326 {
00327 case 0: return &m_IDMParams_Car;
00328 case 1: return &m_IDMParams_SmallTruck;
00329 case 2: return &m_IDMParams_LargeTruck;
00330 case 3: return &m_IDMParams_Crane;
00331 case 4: return &m_IDMParams_Lowloader;
00332 default: return &m_IDMParams_Car;
00333 }
00334 }
00335
00336 CString CTrafficConfigDlg::MapDistributionID(WORD distID)
00337 {
00338
00339
00340 switch(distID)
00341 {
00342 case DIST_EXPONENTIAL: return m_sDistributions.GetAt(0);
00343 case DIST_LOGNORMAL: return m_sDistributions.GetAt(1);
00344 case DIST_GAMMA: return m_sDistributions.GetAt(2);
00345 case DIST_GUMBEL: return m_sDistributions.GetAt(3);
00346 case DIST_POISSON: return m_sDistributions.GetAt(4);
00347 case DIST_GEV: return m_sDistributions.GetAt(5);
00348 case DIST_NORMAL: return m_sDistributions.GetAt(6);
00349 case DIST_CONST: return m_sDistributions.GetAt(7);
00350 default: return m_sDistributions.GetAt(7);
00351 }
00352 }
00353
00354 WORD CTrafficConfigDlg::MapDistributionString(CString dist)
00355 {
00356
00357
00358 int i = 0;
00359 while(dist != m_sDistributions.GetAt(i))
00360 i++;
00361
00362 switch(i)
00363 {
00364 case 0: return DIST_EXPONENTIAL;
00365 case 1: return DIST_LOGNORMAL;
00366 case 2: return DIST_GAMMA;
00367 case 3: return DIST_GUMBEL;
00368 case 4: return DIST_POISSON;
00369 case 5: return DIST_GEV;
00370 case 6: return DIST_NORMAL;
00371 case 7: return DIST_CONST;
00372 default: return DIST_CONST;
00373 }
00374 }