CStatDetectorDlg Class Reference

A class for the Detector Dialog. More...

#include <StatDetectorDlg.h>

List of all members.

Public Types

enum  { IDD = IDD_STATDETECTORS }

Public Member Functions

 CStatDetectorDlg (CWnd *pParent=NULL)
virtual void OnValidate (UINT &nID, CString &strMessage)

Public Attributes

int m_RoadLength
int m_nFixCols
int m_nFixRows
int m_nCols
int m_nRows
CObArray m_vStatDetectors
CGridCtrl m_Grid

Protected Member Functions

virtual void DoDataExchange (CDataExchange *pDX)
virtual BOOL OnInitDialog ()
afx_msg void OnBtnAdddet ()
afx_msg void OnBtnDeldet ()
void OnGridEndEdit (NMHDR *pNotifyStruct, LRESULT *pResult)

Private Member Functions

WORD MapStringToDetType (CString str)
WORD MapStringToVehType (CString str)
void SetParamData (int row, int col, int val)
void SetParamData (int row, int col, CString str)
CString MapDetTypeToString (WORD type)
CString MapVehTypeToString (WORD type)
void LoadStatDetectorsIntoGrid ()
void SetCells (bool bAddDelete)
void SetGridHeadings ()

Private Attributes

int m_NoStatDetectors
CStringArray m_sDirections
CStringArray m_sStatDetectorTypes
CStringArray m_sVehicleTypes
CStringArray m_sColumnHeaders


Detailed Description

A class for the Detector Dialog.

Definition at line 19 of file StatDetectorDlg.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
IDD 

Definition at line 28 of file StatDetectorDlg.h.

00028 { IDD = IDD_STATDETECTORS };


Constructor & Destructor Documentation

CStatDetectorDlg::CStatDetectorDlg ( CWnd *  pParent = NULL  ) 

Definition at line 23 of file StatDetectorDlg.cpp.

References FIXED_COLUMNS, FIXED_ROWS, m_nCols, m_nFixCols, m_nFixRows, m_sColumnHeaders, m_sDirections, m_sStatDetectorTypes, and m_sVehicleTypes.

00024         : CDialogExt(CStatDetectorDlg::IDD, pParent)
00025 {
00026         //{{AFX_DATA_INIT(CStatDetectorDlg)
00027                 // NOTE: the ClassWizard will add member initialization here
00028         //}}AFX_DATA_INIT
00029 
00030         m_sStatDetectorTypes.Add("Flow & Density");
00031         m_sStatDetectorTypes.Add("Headway");
00032         m_sStatDetectorTypes.Add("Composition");
00033         m_sStatDetectorTypes.Add("Lane Changes");
00034         
00035         m_sDirections.Add("Positive x");
00036         m_sDirections.Add("Negative x");
00037 
00038         m_sVehicleTypes.Add("All Vehicles");
00039         m_sVehicleTypes.Add("Cars");
00040         m_sVehicleTypes.Add("Small Trucks");
00041         m_sVehicleTypes.Add("Large Trucks");
00042         m_sVehicleTypes.Add("Cranes");
00043         m_sVehicleTypes.Add("Low-loaders");
00044 
00045         m_sColumnHeaders.Add("Type");
00046         m_sColumnHeaders.Add("Direction");
00047         m_sColumnHeaders.Add("Vehicle Types");
00048         m_sColumnHeaders.Add("Time Interval (s)");
00049         m_sColumnHeaders.Add("Location / Step (m)");
00050 
00051         m_nFixCols = FIXED_COLUMNS;
00052         m_nFixRows = FIXED_ROWS;        
00053         m_nCols = m_sColumnHeaders.GetSize() + m_nFixCols;
00054 }


Member Function Documentation

void CStatDetectorDlg::OnValidate ( UINT &  nID,
CString &  strMessage 
) [virtual]

Definition at line 107 of file StatDetectorDlg.cpp.

References CStatDetector::getDetectorType(), CStatDetector::getLocation(), CStatDetector::getTimeInterval(), IDC_GRID, m_RoadLength, m_vStatDetectors, and METRICS_TYPE_LANE_CHANGE.

00108 {
00109         int nSD = m_vStatDetectors.GetSize();
00110         
00111         for(int i = 0; i < nSD;  i++)
00112         {
00113                 CStatDetector* pSD = reinterpret_cast<CStatDetector*>(m_vStatDetectors.GetAt(i));
00114 
00115                 int location = pSD->getLocation();
00116                 if(location > m_RoadLength)     // since negative numbers can't occur - only check the end
00117                 {
00118                         strMessage.Format("Detector %d: must be located on the road.\nPlease check its location.", i+1);
00119                         nID = IDC_GRID;
00120                         return;
00121                 }
00122 
00123                 int time = pSD->getTimeInterval();
00124                 if(time < 10 && time > 0)
00125                 {
00126                         CString str; str.Format("Detector %d: The time interval is very small and may cause problems.", i+1);
00127                         int result = MessageBox(str + "\nAre you sure you want to keep this value?","EvolveTraffic", MB_YESNO | MB_ICONWARNING);
00128                         if(result == IDNO)
00129                         {
00130                                 strMessage.Format("Detector %d: Change the time interval.", i+1);
00131                                 nID = IDC_GRID;
00132                                 return;
00133                         }
00134                 }
00135                 else if(time == 0)
00136                 {
00137                         strMessage.Format("Detector %d: The time interval must not be zero.", i+1);
00138                         nID = IDC_GRID;
00139                         return;
00140                 }
00141 
00142                 WORD DetType = pSD->getDetectorType();
00143                 int dist_interval = location;
00144                 if(DetType == METRICS_TYPE_LANE_CHANGE && dist_interval > 1000)
00145                 {
00146                         CString str; str.Format("Detector %d: The lane change detector step is very large and may cause problems.", i+1);
00147                         MessageBox(str,"EvolveTraffic", MB_OK | MB_ICONWARNING);
00148                 }
00149         }
00150 }

Here is the call graph for this function:

void CStatDetectorDlg::DoDataExchange ( CDataExchange *  pDX  )  [protected, virtual]

Definition at line 57 of file StatDetectorDlg.cpp.

References IDC_GRID, and m_Grid.

00058 {
00059         CDialogExt::DoDataExchange(pDX);
00060         //{{AFX_DATA_MAP(CStatDetectorDlg)
00061         DDX_Control(pDX, IDC_GRID, m_Grid);             // associate the grid window with a C++ object
00062         //}}AFX_DATA_MAP
00063 }

BOOL CStatDetectorDlg::OnInitDialog (  )  [protected, virtual]

Definition at line 77 of file StatDetectorDlg.cpp.

References LoadStatDetectorsIntoGrid(), m_Grid, m_nCols, m_nFixCols, m_nFixRows, m_NoStatDetectors, m_nRows, m_vStatDetectors, SetCells(), and SetGridHeadings().

00078 {
00079         CDialogExt::OnInitDialog();
00080 
00081         // init rows
00082         m_NoStatDetectors = m_vStatDetectors.GetSize();
00083         m_nRows = m_nFixRows + m_NoStatDetectors;
00084 
00085         TRY {
00086                 m_Grid.SetRowCount(m_nRows);
00087                 m_Grid.SetColumnCount(m_nCols);
00088                 m_Grid.SetFixedRowCount(m_nFixRows);
00089                 m_Grid.SetFixedColumnCount(m_nFixCols);
00090         }
00091         CATCH (CMemoryException, e)
00092         {
00093                 e->ReportError();
00094                 return FALSE;
00095         }
00096         END_CATCH
00097         
00098         SetGridHeadings();
00099         SetCells(false);        // false because not addition or detletion
00100         m_Grid.ExpandColumnsToFit();    
00101         
00102         LoadStatDetectorsIntoGrid();
00103 
00104         return TRUE;  // return TRUE  unless you set the focus to a control
00105 }

Here is the call graph for this function:

void CStatDetectorDlg::OnBtnAdddet (  )  [protected]

Definition at line 253 of file StatDetectorDlg.cpp.

References LoadStatDetectorsIntoGrid(), m_NoStatDetectors, m_vStatDetectors, and SetCells().

00254 {
00255         // Add the feature to the vector
00256         m_NoStatDetectors++;
00257         CStatDetector* pStatDet = new CStatDetector;    // create one to use
00258         m_vStatDetectors.Add(pStatDet);
00259 
00260         // add a row to the table
00261         SetCells(true);
00262         LoadStatDetectorsIntoGrid();            
00263 }

Here is the call graph for this function:

void CStatDetectorDlg::OnBtnDeldet (  )  [protected]

Definition at line 265 of file StatDetectorDlg.cpp.

References LoadStatDetectorsIntoGrid(), m_NoStatDetectors, m_vStatDetectors, and SetCells().

00266 {
00267         if(m_NoStatDetectors != 0)
00268         {
00269                 // Get the ptr and remove from the vector
00270                 CStatDetector* pStatDet = reinterpret_cast<CStatDetector*>(m_vStatDetectors.GetAt(m_NoStatDetectors-1));
00271                 m_vStatDetectors.RemoveAt( m_NoStatDetectors-1 );
00272 
00273                 delete pStatDet;        // remove feature from heap
00274                 m_NoStatDetectors--;    // decrement only now
00275 
00276                 // update the table
00277                 SetCells(true);
00278                 LoadStatDetectorsIntoGrid();
00279         }
00280         else
00281                 MessageBox("No statistics detector to delete.", "EvolveTraffic", MB_OK|MB_ICONWARNING);
00282 }

Here is the call graph for this function:

void CStatDetectorDlg::OnGridEndEdit ( NMHDR *  pNotifyStruct,
LRESULT *  pResult 
) [protected]

Definition at line 285 of file StatDetectorDlg.cpp.

References m_Grid, m_nFixRows, and SetParamData().

00286 {
00287         // if change is ok, then *pResult 0, else *pResult -1
00288         
00289         // pItem is the cell that has just been edited
00290     NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
00291     
00292     int row = pItem->iRow;      int col = pItem->iColumn;
00293 
00294         if(col < 3 + m_nFixRows )       // is the type, direction, or vehicle column
00295         {
00296                 CString strCell = m_Grid.GetCell(row,col)->GetText();
00297                 if(strCell != "")
00298                 {
00299                         // data is ok
00300                         SetParamData(row,col,strCell);
00301                         *pResult = 0;
00302                 }       
00303                 else
00304                         *pResult = -1;
00305         }
00306         else
00307         {
00308                 int val = (int)((CGridCellNumeric *)(m_Grid.GetCell(row,col)))->GetNumber();
00309                 SetParamData(row,col,val);
00310                 *pResult = 0;
00311         }
00312 
00313 }

Here is the call graph for this function:

WORD CStatDetectorDlg::MapStringToDetType ( CString  str  )  [private]

Definition at line 401 of file StatDetectorDlg.cpp.

References m_sStatDetectorTypes, METRICS_TYPE_COMPOSITION, METRICS_TYPE_FLOWDENSITY, METRICS_TYPE_HEADWAY, and METRICS_TYPE_LANE_CHANGE.

Referenced by SetParamData().

00402 {
00403         // Note this function reqires the order of the types 
00404         // to not change
00405         int i = 0;
00406         while(str != m_sStatDetectorTypes.GetAt(i))
00407                 i++;
00408 
00409         switch(i)
00410         {
00411                 case 0:         return METRICS_TYPE_FLOWDENSITY;
00412                 case 1:         return METRICS_TYPE_HEADWAY;
00413                 case 2:         return METRICS_TYPE_COMPOSITION;
00414                 case 3:         return METRICS_TYPE_LANE_CHANGE;
00415                 default:        return METRICS_TYPE_FLOWDENSITY;
00416         }
00417 }

WORD CStatDetectorDlg::MapStringToVehType ( CString  str  )  [private]

Definition at line 381 of file StatDetectorDlg.cpp.

References m_sVehicleTypes, METRICS_VEH_ALL, METRICS_VEH_CAR, METRICS_VEH_CRANE, METRICS_VEH_LARGETRUCK, METRICS_VEH_LOWLOADER, and METRICS_VEH_SMALLTRUCK.

Referenced by SetParamData().

00382 {
00383         // Note this function reqires the order of the types 
00384         // to not change
00385         int i = 0;
00386         while(str != m_sVehicleTypes.GetAt(i))
00387                 i++;
00388 
00389         switch(i)
00390         {
00391                 case 0:         return METRICS_VEH_ALL;
00392                 case 1:         return METRICS_VEH_CAR;
00393                 case 2:         return METRICS_VEH_SMALLTRUCK;
00394                 case 3:         return METRICS_VEH_LARGETRUCK;
00395                 case 4:         return METRICS_VEH_CRANE;
00396                 case 5:         return METRICS_VEH_LOWLOADER;
00397                 default:        return METRICS_VEH_ALL;
00398         }
00399 }

void CStatDetectorDlg::SetParamData ( int  row,
int  col,
int  val 
) [private]

Definition at line 339 of file StatDetectorDlg.cpp.

References m_nFixCols, m_nFixRows, m_vStatDetectors, CStatDetector::setLocation(), and CStatDetector::setTimeInterval().

Referenced by OnGridEndEdit().

00340 {
00341         CStatDetector* pStatDet = reinterpret_cast<CStatDetector*>(m_vStatDetectors[row-m_nFixRows]);
00342 
00343         col = col - m_nFixCols;
00344 
00345         switch(col)
00346         {
00347                 case 3:         // time
00348                         pStatDet->setTimeInterval(val);
00349                         break;
00350                 default:        // location
00351                         pStatDet->setLocation(val);
00352         }
00353 }

Here is the call graph for this function:

void CStatDetectorDlg::SetParamData ( int  row,
int  col,
CString  str 
) [private]

Definition at line 315 of file StatDetectorDlg.cpp.

References m_nFixCols, m_nFixRows, m_sDirections, m_vStatDetectors, MapStringToDetType(), MapStringToVehType(), CStatDetector::setDetectorType(), CStatDetector::setDirPos(), and CStatDetector::setVehicleType().

00316 {
00317         // if it's a string it's either col 1 or 2
00318         CStatDetector* pStatDet = reinterpret_cast<CStatDetector*>(m_vStatDetectors[row-m_nFixRows]);
00319         
00320         col = col - m_nFixCols;
00321         
00322 
00323         switch(col)
00324         {
00325                 case 0:                 // detector type
00326                         pStatDet->setDetectorType( MapStringToDetType(str) );
00327                         break;
00328                 case 1:                 // direction
00329                         {
00330                                 bool DirPos = str == m_sDirections.GetAt(0) ? true : false;
00331                                 pStatDet->setDirPos(DirPos);
00332                                 break;
00333                         }
00334                 default:                // vehicle
00335                         pStatDet->setVehicleType( MapStringToVehType(str) );
00336         }
00337 }

Here is the call graph for this function:

CString CStatDetectorDlg::MapDetTypeToString ( WORD  type  )  [private]

Definition at line 369 of file StatDetectorDlg.cpp.

References m_sStatDetectorTypes, METRICS_TYPE_COMPOSITION, METRICS_TYPE_FLOWDENSITY, METRICS_TYPE_HEADWAY, and METRICS_TYPE_LANE_CHANGE.

Referenced by LoadStatDetectorsIntoGrid().

00370 {
00371         switch(type)
00372         {
00373                 case METRICS_TYPE_FLOWDENSITY:  return m_sStatDetectorTypes.GetAt(0);
00374                 case METRICS_TYPE_HEADWAY:              return m_sStatDetectorTypes.GetAt(1);
00375                 case METRICS_TYPE_COMPOSITION:  return m_sStatDetectorTypes.GetAt(2);
00376                 case METRICS_TYPE_LANE_CHANGE:  return m_sStatDetectorTypes.GetAt(3);
00377                 default:                                                return m_sStatDetectorTypes.GetAt(0);   // all vehicles
00378         }
00379 }

CString CStatDetectorDlg::MapVehTypeToString ( WORD  type  )  [private]

Definition at line 355 of file StatDetectorDlg.cpp.

References m_sVehicleTypes, METRICS_VEH_ALL, METRICS_VEH_CAR, METRICS_VEH_CRANE, METRICS_VEH_LARGETRUCK, METRICS_VEH_LOWLOADER, and METRICS_VEH_SMALLTRUCK.

Referenced by LoadStatDetectorsIntoGrid().

00356 {
00357         switch(type)
00358         {
00359                 case METRICS_VEH_ALL:                   return m_sVehicleTypes.GetAt(0);
00360                 case METRICS_VEH_CAR:                   return m_sVehicleTypes.GetAt(1);
00361                 case METRICS_VEH_SMALLTRUCK:    return m_sVehicleTypes.GetAt(2);
00362                 case METRICS_VEH_LARGETRUCK:    return m_sVehicleTypes.GetAt(3);
00363                 case METRICS_VEH_CRANE:                 return m_sVehicleTypes.GetAt(4);
00364                 case METRICS_VEH_LOWLOADER:             return m_sVehicleTypes.GetAt(5);
00365                 default:                                                return m_sVehicleTypes.GetAt(0);        // all vehicles
00366         }
00367 }

void CStatDetectorDlg::LoadStatDetectorsIntoGrid (  )  [private]

Definition at line 222 of file StatDetectorDlg.cpp.

References CStatDetector::getDetectorType(), CStatDetector::getDirPos(), CStatDetector::getLocation(), CStatDetector::getTimeInterval(), CStatDetector::getVehicleType(), m_Grid, m_nFixCols, m_nFixRows, m_NoStatDetectors, m_sDirections, m_vStatDetectors, MapDetTypeToString(), and MapVehTypeToString().

Referenced by OnBtnAdddet(), OnBtnDeldet(), and OnInitDialog().

00223 {
00224         for(int i = 0; i < m_NoStatDetectors; i++)
00225         {
00226                 int col = m_nFixCols;
00227                 int row = m_nFixRows + i;
00228                 CStatDetector* pStatDet = reinterpret_cast<CStatDetector*>(m_vStatDetectors[i]);
00229 
00230                 CString txt = MapDetTypeToString( pStatDet->getDetectorType() );
00231                 m_Grid.SetItemText(row,col,txt);
00232 
00233                 col++;  // next col - set direction text
00234                 txt = pStatDet->getDirPos() == true ? m_sDirections.GetAt(0) : m_sDirections.GetAt(1);
00235                 m_Grid.SetItemText(row,col,txt);
00236 
00237                 col++;  // next col - set vehicle text
00238                 txt = MapVehTypeToString( pStatDet->getVehicleType() );
00239                 m_Grid.SetItemText(row,col,txt);
00240 
00241                 col++;  // next col - set time interval
00242                 CGridCellNumeric* pCell = (CGridCellNumeric *)(m_Grid.GetCell(row,col));
00243                 pCell->SetNumber( pStatDet->getTimeInterval() );
00244 
00245                 col++;  // next col - set location
00246                 pCell = (CGridCellNumeric *)(m_Grid.GetCell(row,col));
00247                 pCell->SetNumber( pStatDet->getLocation() );
00248         }
00249         m_Grid.AutoSizeRows();
00250         m_Grid.Invalidate();
00251 }

Here is the call graph for this function:

void CStatDetectorDlg::SetCells ( bool  bAddDelete  )  [private]

Definition at line 171 of file StatDetectorDlg.cpp.

References m_Grid, m_nFixRows, m_NoStatDetectors, m_nRows, m_sDirections, m_sStatDetectorTypes, m_sVehicleTypes, and m_vStatDetectors.

Referenced by OnBtnAdddet(), OnBtnDeldet(), and OnInitDialog().

00172 {
00173         // these lines are for the resizing of the rows due to addtions/deletions
00174         if(bAddDelete)
00175         {
00176                 m_NoStatDetectors = m_vStatDetectors.GetSize();
00177                 m_nRows = m_nFixRows + m_NoStatDetectors;
00178                 m_Grid.SetRowCount(m_nRows);
00179                 // update row headings
00180                 for(int row = m_nFixRows; row < m_nRows; row++)
00181                 {
00182                         CString str;
00183                         str.Format("Detector %d", row);
00184                         m_Grid.SetItemText(row,0,str);
00185                 }
00186         }
00187 
00188         for (int row = m_nFixRows; row < m_nRows; row++)
00189         {
00190                 int col = 1;    // Do Detector-type drop down
00191                 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellCombo));     
00192             CGridCellCombo *pCell = (CGridCellCombo*) m_Grid.GetCell(row,col);
00193                 pCell->SetOptions(m_sStatDetectorTypes);
00194                 pCell->SetStyle(CBS_DROPDOWNLIST);
00195 
00196                 col = 2;                // Do directions drop down
00197                 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellCombo));     
00198             pCell = (CGridCellCombo*) m_Grid.GetCell(row,col);
00199                 pCell->SetOptions(m_sDirections);
00200                 pCell->SetStyle(CBS_DROPDOWNLIST);
00201 
00202                 col = 3;                // Do vehicles drop down
00203                 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellCombo));     
00204             pCell = (CGridCellCombo*) m_Grid.GetCell(row,col);
00205                 pCell->SetOptions(m_sVehicleTypes);
00206                 pCell->SetStyle(CBS_DROPDOWNLIST);
00207 
00208                 col = 4;                // Do time interval cells
00209                 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellNumeric));
00210                 m_Grid.GetCell(row,col)->SetFormat(DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
00211                 CGridCellNumeric *pCellN = (CGridCellNumeric*)m_Grid.GetCell(row,col);
00212                 pCellN->SetFlags(CGridCellNumeric::Integer);
00213 
00214                 col = 5;                // Do location cells
00215                 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellNumeric));
00216                 m_Grid.GetCell(row,col)->SetFormat(DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
00217                 pCellN = (CGridCellNumeric*)m_Grid.GetCell(row,col);
00218                 pCellN->SetFlags(CGridCellNumeric::Integer);
00219         }
00220 }

void CStatDetectorDlg::SetGridHeadings (  )  [private]

Definition at line 152 of file StatDetectorDlg.cpp.

References m_Grid, m_nCols, m_nFixRows, m_nRows, and m_sColumnHeaders.

Referenced by OnInitDialog().

00153 {
00154         int row = 0;
00155         int col = 0;
00156 
00157         // Set fixed column text
00158         for (col = 1; col < m_nCols; col++)
00159                 m_Grid.SetItemText(row,col,m_sColumnHeaders.GetAt(col-1));
00160 
00161         // Set fixed row text
00162         col = 0;
00163         for(row = m_nFixRows; row < m_nRows; row++)
00164         {
00165                 CString str;
00166                 str.Format("Detector %d", row);
00167                 m_Grid.SetItemText(row,col,str);
00168         }
00169 }


Member Data Documentation

Definition at line 23 of file StatDetectorDlg.h.

Referenced by CEvolveTrafficView::OnConfigMetrics(), and OnValidate().

Definition at line 31 of file StatDetectorDlg.h.

Referenced by CStatDetectorDlg(), OnInitDialog(), and SetGridHeadings().

Definition at line 32 of file StatDetectorDlg.h.

Referenced by OnInitDialog(), SetCells(), and SetGridHeadings().

CStringArray CStatDetectorDlg::m_sDirections [private]

CStringArray CStatDetectorDlg::m_sVehicleTypes [private]

CStringArray CStatDetectorDlg::m_sColumnHeaders [private]

Definition at line 72 of file StatDetectorDlg.h.

Referenced by CStatDetectorDlg(), and SetGridHeadings().


The documentation for this class was generated from the following files:

Generated on Wed Aug 20 00:48:46 2008 for EvolveTraffic by  doxygen 1.5.6