00001
00002
00003
00004 #include "stdafx.h"
00005 #include "EvolveTraffic.h"
00006 #include "PreferencesDlg.h"
00007
00008 #include "GridCtrl_src/GridCellNumeric.h"
00009
00010 #include "ConfigData.h"
00011 extern CConfigData g_ConfigData;
00012
00013 #ifdef _DEBUG
00014 #define new DEBUG_NEW
00015 #undef THIS_FILE
00016 static char THIS_FILE[] = __FILE__;
00017 #endif
00018
00020
00021
00022
00023 CPreferencesDlg::CPreferencesDlg(CWnd* pParent )
00024 : CDialog(CPreferencesDlg::IDD, pParent)
00025 {
00026 MIN_VIEW_SCALE = g_ConfigData.View.MIN_VIEW_SCALE;
00027
00028 m_sRowHeads.Add("Overall scale (meters/pixel)");
00029 m_sRowHeads.Add("Widths Scale");
00030 m_sRowHeads.Add("Time warp factor");
00031 m_sRowHeads.Add("Lane width (m)");
00032 m_sRowHeads.Add("Vehicle width (m)");
00033 m_sRowHeads.Add("Vehicle Length Scale");
00034 m_sRowHeads.Add("Show Velocities");
00035 m_sRowHeads.Add("Show Legend");
00036 m_sRowHeads.Add("Tick Length (m)");
00037 m_sRowHeads.Add("Tick Interval (m)");
00038 m_sRowHeads.Add("Border Top (m)");
00039 m_sRowHeads.Add("Border Bottom (m)");
00040 m_sRowHeads.Add("Border Left (m)");
00041 m_sRowHeads.Add("Border Right (m)");
00042
00043 m_sColHeads.Add("Setting");
00044 m_sColHeads.Add("Value");
00045
00046 m_nFixRows = FIXED_ROWS;
00047 m_nFixCols = FIXED_COLUMNS;
00048
00049 m_nCols = 1 + m_nFixCols;
00050 m_nRows = m_sRowHeads.GetSize() + m_nFixRows;
00051
00052
00053
00054
00055 }
00056
00057
00058 void CPreferencesDlg::DoDataExchange(CDataExchange* pDX)
00059 {
00060 CDialog::DoDataExchange(pDX);
00061
00062 DDX_Control(pDX, IDC_GRID, m_Grid);
00063
00064 }
00065
00066
00067 BEGIN_MESSAGE_MAP(CPreferencesDlg, CDialog)
00068
00069 ON_NOTIFY(GVN_ENDLABELEDIT, IDC_GRID, OnGridEndEdit)
00070
00071 END_MESSAGE_MAP()
00072
00074
00075
00076
00077 void CPreferencesDlg::OnOK()
00078 {
00079 CDialog::OnOK();
00080 if(m_Scale < MIN_VIEW_SCALE)
00081 {
00082 MessageBox("View scale cannot be less than minimum - default minimum set", "EvolveTraffic", MB_OK | MB_ICONWARNING);
00083 m_Scale = MIN_VIEW_SCALE;
00084 }
00085 if(m_ExaggerateWidths < 1.0)
00086 {
00087 MessageBox("Widths scale cannot be less than 1.0 - default set", "EvolveTraffic", MB_OK | MB_ICONWARNING);
00088 m_ExaggerateWidths = 1.0;
00089 }
00090 if(m_TimeWarp < 1.0)
00091 {
00092 MessageBox("Widths scale cannot be less than 1.0 - default set", "EvolveTraffic", MB_OK | MB_ICONWARNING);
00093 m_ExaggerateWidths = 1.0;
00094 }
00095 if(m_VehicleWidth > m_LaneWidth)
00096 {
00097 MessageBox("Vehicle width should be less than lane width - default of 80% of lane width set", "EvolveTraffic", MB_OK | MB_ICONWARNING);
00098 m_VehicleWidth = 0.8 * m_LaneWidth;
00099 }
00100 }
00101
00102 BOOL CPreferencesDlg::OnInitDialog()
00103 {
00104 CDialog::OnInitDialog();
00105
00106 TRY {
00107 m_Grid.SetRowCount(m_nRows);
00108 m_Grid.SetColumnCount(m_nCols);
00109 m_Grid.SetFixedRowCount(m_nFixRows);
00110 m_Grid.SetFixedColumnCount(m_nFixCols);
00111 }
00112 CATCH (CMemoryException, e)
00113 {
00114 e->ReportError();
00115 return FALSE;
00116 }
00117 END_CATCH
00118
00119 SetGridHeadings();
00120 SetCells();
00121 m_Grid.ExpandToFit();
00122
00123 LoadSettingsIntoGrid();
00124
00125 return TRUE;
00126 }
00127
00128 void CPreferencesDlg::SetGridHeadings()
00129 {
00130 int row = 0;
00131 int col = 0;
00132
00133
00134 m_Grid.SetItemText(row,m_nFixCols-1,m_sColHeads.GetAt(0));
00135 m_Grid.SetItemText(row,m_nFixCols,m_sColHeads.GetAt(1));
00136
00137
00138 col = 0;
00139 for (row = 1; row < m_Grid.GetRowCount(); row++)
00140 m_Grid.SetItemText(row,col,m_sRowHeads.GetAt(row-1));
00141 }
00142
00143 void CPreferencesDlg::SetCells()
00144 {
00145 for (int row = 1; row < m_nRows; row++)
00146 {
00147 int col = 1;
00148 m_Grid.SetCellType(row,col, RUNTIME_CLASS(CGridCellNumeric));
00149 m_Grid.GetCell(row,col)->SetFormat(DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX|DT_END_ELLIPSIS);
00150 CGridCellNumeric *pCell = (CGridCellNumeric*)m_Grid.GetCell(row,col);
00151 pCell->SetFlags(CGridCellNumeric::Real);
00152 }
00153 }
00154
00155 void CPreferencesDlg::LoadSettingsIntoGrid()
00156 {
00157 int col = 1;
00158 for (int row = 1; row < m_nRows; row++)
00159 {
00160 CGridCellNumeric* pCell = (CGridCellNumeric *)(m_Grid.GetCell(row,col));
00161 pCell->SetNumber( *(MapRowToValue(row)) );
00162 }
00163 }
00164
00165 void CPreferencesDlg::OnGridEndEdit(NMHDR *pNotifyStruct, LRESULT* pResult)
00166 {
00167
00168
00169
00170 NM_GRIDVIEW* pItem = (NM_GRIDVIEW*) pNotifyStruct;
00171
00172 int row = pItem->iRow;
00173 int col = pItem->iColumn;
00174
00175 double val = ((CGridCellNumeric *)(m_Grid.GetCell(row,col)))->GetNumber();
00176 *(MapRowToValue(row)) = val;
00177
00178 *pResult = 0;
00179 }
00180
00181 double* CPreferencesDlg::MapRowToValue(int row)
00182 {
00183
00184
00185 row = row - m_nFixRows;
00186 switch(row)
00187 {
00188 case 0:
00189 return &m_Scale;
00190 case 1:
00191 return &m_ExaggerateWidths;
00192 case 2:
00193 return &m_TimeWarp;
00194 case 3:
00195 return &m_LaneWidth;
00196 case 4:
00197 return &m_VehicleWidth;
00198 case 5:
00199 return &m_VehicleLengthScale;
00200 case 6:
00201 return &m_ShowVelocity;
00202 case 7:
00203 return &m_ShowLegend;
00204 case 8:
00205 return &m_TickLength;
00206 case 9:
00207 return &m_TickStep;
00208 case 10:
00209 return &m_Border_Top;
00210 case 11:
00211 return &m_Border_Btm;
00212 case 12:
00213 return &m_Border_Lhs;
00214 case 13:
00215 return &m_Border_Rhs;
00216 default:
00217 return &m_Border_Top;
00218 }
00219 }