00001
00002
00003
00004 #include "stdafx.h"
00005 #include "EvolveTraffic.h"
00006
00007 #include "EvolveTrafficDoc.h"
00008 #include "EvolveTrafficView.h"
00009 #include "SimConfigDlg.h"
00010 #include "TrafficConfigDlg.h"
00011 #include "PreferencesDlg.h"
00012 #include "RoadFeaturesDlg.h"
00013 #include "RoadFeature.h"
00014 #include "StatDetectorDlg.h"
00015 #include "StatDetector.h"
00016
00017 #include "WindowToBMP.h"
00018
00019 #include <Mmsystem.h>
00020
00021 extern CConfigData g_ConfigData;
00022
00023 #ifdef _DEBUG
00024 #define new DEBUG_NEW
00025 #undef THIS_FILE
00026 static char THIS_FILE[] = __FILE__;
00027 #endif
00028
00030
00031
00032 IMPLEMENT_DYNCREATE(CEvolveTrafficView, CScrollView)
00033
00034 BEGIN_MESSAGE_MAP(CEvolveTrafficView, CScrollView)
00035
00036 ON_COMMAND(ID_CONFIG_SIM, OnConfigSim)
00037 ON_COMMAND(ID_RUN_VISIBLE, OnRunVisible)
00038 ON_WM_SIZE()
00039 ON_COMMAND(ID_CONFIG_TRAF, OnConfigTraf)
00040 ON_COMMAND(ID_TOOLS_PREFS, OnToolsPrefs)
00041 ON_COMMAND(ID_TOOLS_PAUSE, OnToolsPause)
00042 ON_COMMAND(ID_TOOLS_ZOOMIN, OnToolsZoomin)
00043 ON_COMMAND(ID_TOOLS_ZOOMOUT, OnToolsZoomout)
00044 ON_COMMAND(ID_TOOLS_SPEEDUP, OnToolsSpeedup)
00045 ON_COMMAND(ID_TOOLS_SLOWDOWN, OnToolsSlowdown)
00046 ON_WM_KEYDOWN()
00047 ON_COMMAND(ID_RUN_INVISIBLE, OnRunInvisible)
00048 ON_COMMAND(ID_CONFIG_FEATURES, OnConfigFeatures)
00049 ON_COMMAND(ID_CONFIG_METRICS, OnConfigMetrics)
00050 ON_UPDATE_COMMAND_UI(ID_TOOLS_PAUSE, OnUpdateToolsPause)
00051 ON_UPDATE_COMMAND_UI(ID_TOOLS_SPEEDUP, OnUpdateToolsSpeedup)
00052 ON_UPDATE_COMMAND_UI(ID_TOOLS_SLOWDOWN, OnUpdateToolsSlowdown)
00053 ON_COMMAND(ID_TOOLS_STOP, OnToolsStop)
00054 ON_UPDATE_COMMAND_UI(ID_TOOLS_STOP, OnUpdateToolsStop)
00055 ON_WM_LBUTTONDOWN()
00056 ON_COMMAND(ID_FILE_SAVEIMAGE, OnFileSaveImage)
00057
00058
00059 ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
00060 ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
00061 ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
00062 END_MESSAGE_MAP()
00063
00065
00066
00067 CEvolveTrafficView::CEvolveTrafficView()
00068 {
00069
00070 MIN_VIEW_SCALE = g_ConfigData.View.MIN_VIEW_SCALE;
00071 DATATIP_DELAY = g_ConfigData.View.DATATIP_DELAY;
00072
00073 CLR_BACKGRND = g_ConfigData.View.Colours.DrawElements.CLR_BACKGRND;
00074 CLR_DET_COMPOSITION = g_ConfigData.View.Colours.DrawElements.CLR_DET_COMPOSITION;
00075 CLR_DET_FLOWDENSITY = g_ConfigData.View.Colours.DrawElements.CLR_DET_FLOWDENSITY;
00076 CLR_DET_HEADWAY = g_ConfigData.View.Colours.DrawElements.CLR_DET_HEADWAY;
00077 CLR_DET_OUTPUT = g_ConfigData.View.Colours.DrawElements.CLR_DET_OUTPUT;
00078 CLR_FEAT_GRADIENT = g_ConfigData.View.Colours.DrawElements.CLR_FEAT_GRADIENT;
00079 CLR_FEAT_SPEEDLIMIT = g_ConfigData.View.Colours.DrawElements.CLR_FEAT_SPEEDLIMIT;
00080 CLR_LEGEND_TEXT = g_ConfigData.View.Colours.DrawElements.CLR_LEGEND_TEXT;
00081 CLR_ROAD_LINES = g_ConfigData.View.Colours.DrawElements.CLR_ROAD_LINES;
00082 CLR_ROAD_SURFACE = g_ConfigData.View.Colours.DrawElements.CLR_ROAD_SURFACE;
00083 CLR_RULER_LINES = g_ConfigData.View.Colours.DrawElements.CLR_RULER_LINES;
00084 CLR_RULER_TEXT = g_ConfigData.View.Colours.DrawElements.CLR_RULER_TEXT;
00085
00086 VEH_COLOR_CAR = g_ConfigData.View.Colours.Vehicles.VEH_COLOR_CAR;
00087 VEH_COLOR_SMALLTRUCK = g_ConfigData.View.Colours.Vehicles.VEH_COLOR_SMALLTRUCK;
00088 VEH_COLOR_LARGETRUCK = g_ConfigData.View.Colours.Vehicles.VEH_COLOR_LARGETRUCK;
00089 VEH_COLOR_CRANE = g_ConfigData.View.Colours.Vehicles.VEH_COLOR_CRANE;
00090 VEH_COLOR_LOWLOADER = g_ConfigData.View.Colours.Vehicles.VEH_COLOR_LOWLOADER;
00091
00092
00093 m_Scale = 1.0;
00094 m_ExaggerateWidths = 10.0;
00095
00096 m_Border_Top = 20;
00097 m_Border_Btm = 40;
00098 m_Border_Lhs = 20;
00099 m_Border_Rhs = 100;
00100 m_TickStep = 500;
00101 m_VehicleLengthScale = 2.0;
00102 m_bShowVelocity = true;
00103 m_bShowLegend = true;
00104 m_TickLength = 1.0 * m_ExaggerateWidths;
00105 m_LaneWidth = 4.0 * m_ExaggerateWidths;
00106 m_VehicleWidth = 3.0 * m_ExaggerateWidths;
00107
00108 m_bInSimulation = false;
00109 m_bPause = false;
00110 m_TimeWarp = 1;
00111
00112 m_TimerSpeed = Round(1000/DRAW_FRAMES_PER_SEC);
00113 m_CurentRealTime = 0;
00114 m_CurentSimTime = 0;
00115 m_PauseTime = 0;
00116 m_MaxTimeWarp = 1000;
00117
00118 m_LastPercentComplete = 0;
00119 m_PercentComplete = 0;
00120
00121 m_YCoordTop = 0;
00122 }
00123
00124 CEvolveTrafficView::~CEvolveTrafficView()
00125 {
00126
00127 }
00128
00129 BOOL CEvolveTrafficView::PreCreateWindow(CREATESTRUCT& cs)
00130 {
00131
00132
00133
00134 return CScrollView::PreCreateWindow(cs);
00135 }
00136
00138
00139
00140 void CEvolveTrafficView::OnInitialUpdate()
00141 {
00142 m_DrawArea.cx = 5000;
00143 m_DrawArea.cy = 100;
00144
00145 CScrollView::OnInitialUpdate();
00146
00147 m_pDoc = GetDocument();
00148 ASSERT_VALID(m_pDoc);
00149
00150 initRoad();
00151 if(m_DataTip.m_hWnd == NULL)
00152 {
00153 m_DataTip.Create(this);
00154 m_DataTip.SetDisplayTime( Round(DATATIP_DELAY*1000) );
00155 }
00156
00157 }
00158
00159 void CEvolveTrafficView::OnPrepareDC(CDC *pDC, CPrintInfo *pInfo)
00160 {
00161 CScrollView::OnPrepareDC(pDC, pInfo);
00162
00163 pDC->SetMapMode(MM_ANISOTROPIC);
00164 pDC->SetWindowExt(m_DrawArea);
00165
00166 int xExtent = m_Scale * m_DrawArea.cx;
00167 int yExtent = m_Scale * m_DrawArea.cy;
00168 pDC->SetViewportExt(xExtent, yExtent);
00169
00170
00171
00172 GetClientRect(&m_ClientRect);
00173 CPoint viewOrg;
00174 viewOrg.y = m_ClientRect.Height()/2;
00175 viewOrg.x = m_Border_Lhs*m_Scale;
00176
00177 viewOrg -= GetDeviceScrollPosition();
00178 pDC->SetViewportOrg(viewOrg);
00179 }
00180
00181 void CEvolveTrafficView::SetZoomScale(double newScale)
00182 {
00183 if(newScale > MIN_VIEW_SCALE)
00184 {
00185 double oldZoomFactor = m_Scale;
00186
00187 CPoint centerScrollPosition = GetScrollPosition();
00188 CRect ClientRect(0,0,0,0);
00189 centerScrollPosition.x += m_ClientRect.right/2;
00190 centerScrollPosition.y += m_ClientRect.bottom/2;
00191
00192 m_Scale = newScale;
00193
00194 CSize displaySize;
00195 displaySize.cx = Round(m_DrawArea.cx * m_Scale);
00196 displaySize.cy = Round(m_DrawArea.cy * m_Scale);
00197 SetScrollSizes(MM_TEXT,displaySize);
00198
00199 int newXScrollPosition = Round((centerScrollPosition.x / oldZoomFactor) * m_Scale);
00200 int newYScrollPosition = Round((centerScrollPosition.y / oldZoomFactor) * m_Scale);
00201
00202 newXScrollPosition -= m_ClientRect.right/2;
00203 newYScrollPosition -= m_ClientRect.bottom/2;
00204 ScrollToPosition(CPoint(newXScrollPosition,newYScrollPosition));
00205 }
00206 else
00207 {
00208 CString str; str.Format("You cannot zoom out any further - minimum view scale is 0.1.", MIN_VIEW_SCALE);
00209 MessageBox(str, "EvolveTraffic", MB_OK|MB_ICONWARNING);
00210 }
00211
00212 Invalidate(FALSE);
00213 }
00214
00215 void CEvolveTrafficView::initRoad()
00216 {
00217 m_DriveOnRight = m_pDoc->getDriveOnRight();
00218 m_RoadLength = m_pDoc->getRoadLength();
00219 m_NoLanes = m_pDoc->getNoLanes();
00220 m_NoLanesDirPos = m_pDoc->getNoLanesDirPos();
00221 m_NoLanesDirNeg = m_pDoc->getNoLanesDirNeg();
00222 m_NoDirections = m_pDoc->getNoDirections();
00223 m_RoadWidth = m_NoLanes * m_LaneWidth;
00224 m_NoTicks = (int)(m_RoadLength/m_TickStep)+1;
00225
00226 m_nLanesOnTop = m_DriveOnRight ? m_NoLanesDirNeg : m_NoLanesDirPos;
00227 m_nLanesOnBtm = m_DriveOnRight ? m_NoLanesDirPos : m_NoLanesDirNeg;
00228 m_TopEdge = -m_nLanesOnTop*m_LaneWidth;
00229 m_BtmEdge = m_nLanesOnBtm*m_LaneWidth;
00230
00231 m_SimTimeStep = Round(1000 * m_pDoc->getSimTimeStep());
00232
00233 m_DrawArea.cy = m_Border_Top + m_Border_Btm + m_RoadWidth;
00234 m_DrawArea.cx = m_Border_Lhs + m_Border_Rhs + m_RoadLength;
00235
00236 CSize scrolls;
00237 scrolls.cx = m_DrawArea.cx*m_Scale;
00238 scrolls.cy = m_DrawArea.cy*m_Scale;
00239 CScrollView::SetScrollSizes(MM_TEXT, scrolls);
00240 }
00241
00242 void CEvolveTrafficView::doLoop(int curTime)
00243 {
00244 int StepTime = Round( (double)m_SimTimeStep/m_TimeWarp );
00245 static int TimeNextSimStep = m_StartRealTime + StepTime;
00246 static int TimeNextDraw = m_StartRealTime + m_TimerSpeed;
00247
00248 if(m_bInSimulation && !m_bPause)
00249 {
00250 if(curTime > TimeNextSimStep)
00251 {
00252
00253 m_VehiclePositions = m_pDoc->m_Sim.doOneTimeStep(&m_bInSimulation);
00254 UpdateProgressBar();
00255
00256 if(!m_bInSimulation)
00257 doSimFinished(true);
00258
00259 while(TimeNextSimStep < curTime)
00260 TimeNextSimStep += StepTime;
00261 }
00262 }
00263
00264 if(curTime > TimeNextDraw)
00265 {
00266 InvalidateRect(NULL,FALSE);
00267 while(TimeNextDraw < curTime)
00268 TimeNextDraw += m_TimerSpeed;
00269 }
00270 }
00271
00272 void CEvolveTrafficView::UpdateProgressBar()
00273 {
00274 m_PercentComplete = m_pDoc->m_Sim.getPercentComplete();
00275
00276 if(m_PercentComplete > m_LastPercentComplete)
00277 {
00278 CString str;
00279 str.Format("%d%% complete", m_PercentComplete);
00280 m_pProgBar->SetText(str);
00281 m_pProgBar->StepIt();
00282 m_LastPercentComplete = m_PercentComplete;
00283 Invalidate(FALSE);
00284 }
00285 }
00286
00287 void CEvolveTrafficView::OnDraw(CDC* dc)
00288 {
00289 CMemDC pDC(dc);
00290
00291 DrawRoad(pDC);
00292 DrawRuler(pDC);
00293
00294 if(m_bShowLegend)
00295 DrawLegend(pDC);
00296
00297 if(m_bInSimulation)
00298 {
00299
00300 for (int i = 0; i < m_VehiclePositions.size(); i++)
00301 {
00302 for (int j = 0; j < m_VehiclePositions[i].size(); j++)
00303 DrawVehicle(pDC, m_VehiclePositions[i][j]);
00304 }
00305 }
00306
00307 DrawTimer(pDC);
00308
00309 }
00310
00312
00313
00314 BOOL CEvolveTrafficView::OnPreparePrinting(CPrintInfo* pInfo)
00315 {
00316
00317 return DoPreparePrinting(pInfo);
00318 }
00319
00320 void CEvolveTrafficView::OnBeginPrinting(CDC* , CPrintInfo* )
00321 {
00322
00323 }
00324
00325 void CEvolveTrafficView::OnEndPrinting(CDC* , CPrintInfo* )
00326 {
00327
00328 }
00329
00331
00332
00333 #ifdef _DEBUG
00334 void CEvolveTrafficView::AssertValid() const
00335 {
00336 CScrollView::AssertValid();
00337 }
00338
00339 void CEvolveTrafficView::Dump(CDumpContext& dc) const
00340 {
00341 CScrollView::Dump(dc);
00342 }
00343
00344 CEvolveTrafficDoc* CEvolveTrafficView::GetDocument()
00345 {
00346 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEvolveTrafficDoc)));
00347 return (CEvolveTrafficDoc*)m_pDocument;
00348 }
00349 #endif //_DEBUG
00350
00352
00353
00354 void CEvolveTrafficView::OnRunVisible()
00355 {
00356 if( !m_bInSimulation )
00357 doSimStart();
00358 else
00359 {
00360 if(m_bPause)
00361 OnToolsPause();
00362 else
00363 MessageBox("Simulation already running", "EvolveTraffic", MB_OK|MB_ICONWARNING);
00364 }
00365 }
00366
00367 void CEvolveTrafficView::OnRunInvisible()
00368 {
00369 if( !m_bInSimulation )
00370 {
00371 int result = MessageBox("Running EvolveTraffic in this mode means:\n"
00372 "- only the progress bar is updated;\n"
00373 "- the program will appear to be unresponsive until the simulation is complete.\n"
00374 "Are you sure that you want to proceed in this mode?",
00375 "EvolveTraffic", MB_YESNO|MB_ICONWARNING);
00376
00377 if(result == IDYES)
00378 {
00379 doSimStart();
00380 bool bInSim = true;
00381 while(bInSim)
00382 {
00383 m_pDoc->m_Sim.doOneTimeStep(&bInSim);
00384 UpdateProgressBar();
00385 }
00386 m_CurentSimTime = m_pDoc->m_Sim.getCurrentSimTime();
00387 m_CurentRealTime = timeGetTime() - m_StartRealTime;
00388 doSimFinished(true);
00389 }
00390 }
00391 else
00392 MessageBox("Simulation already running", "EvolveTraffic", MB_OK|MB_ICONWARNING);
00393
00394 }
00395
00396 void CEvolveTrafficView::doSimStart()
00397 {
00398 bool statusOK = m_pDoc->initSim();
00399 if(statusOK)
00400 {
00401 ((CEvolveTrafficApp*)AfxGetApp())->setInSimulation(true);
00402 m_StartRealTime = timeGetTime();
00403 m_bInSimulation = true;
00404 m_CurentSimTime = 0.0;
00405 m_pProgBar = new CProgressBar;
00406 m_pProgBar->Create("Percent Complete 0%");
00407 Invalidate();
00408 }
00409 }
00410
00411 void CEvolveTrafficView::doSimFinished(bool bCompleted)
00412 {
00413 Invalidate();
00414 m_bInSimulation = false;
00415 ((CEvolveTrafficApp*)AfxGetApp())->setInSimulation(false);
00416 m_pProgBar->Clear();
00417 delete m_pProgBar;
00418 m_pDoc->m_Sim.clear();
00419 m_LastPercentComplete = 0;
00420 m_VehiclePositions.clear();
00421
00422 if(bCompleted)
00423 MessageBox("The simulation has finished.","EvolveTraffic",MB_OK|MB_ICONINFORMATION);
00424 }
00425
00426
00427
00428 void CEvolveTrafficView::setMaxTimeWarp()
00429 {
00430 m_MaxTimeWarp = m_TimeWarp;
00431 }
00432
00433 void CEvolveTrafficView::OnSize(UINT nType, int cx, int cy)
00434 {
00435 CScrollView::OnSize(nType, cx, cy);
00436 }
00437
00438 void CEvolveTrafficView::OnToolsPause()
00439 {
00440 if(m_bPause)
00441 {
00442 m_PauseTime = timeGetTime() - m_PauseTime;
00443 m_StartRealTime += m_PauseTime;
00444 }
00445 else
00446 m_PauseTime = timeGetTime();
00447
00448 m_bPause = !m_bPause;
00449
00450 }
00451
00452 void CEvolveTrafficView::OnToolsStop()
00453 {
00454 doSimFinished(false);
00455 }
00456
00457 void CEvolveTrafficView::OnUpdateToolsStop(CCmdUI* pCmdUI)
00458 {
00459 if(m_bInSimulation)
00460 pCmdUI->Enable(true);
00461 else
00462 pCmdUI->Enable(false);
00463 }
00464
00465 void CEvolveTrafficView::OnUpdateToolsPause(CCmdUI* pCmdUI)
00466 {
00467 if(m_bInSimulation)
00468 {
00469 pCmdUI->Enable(true);
00470 if(m_bPause)
00471 pCmdUI->SetText("&Resume\tF9");
00472 else
00473 pCmdUI->SetText("&Pause\tF9");
00474 }
00475 else
00476 pCmdUI->Enable(false);
00477
00478 }
00479
00480 void CEvolveTrafficView::OnUpdateToolsSpeedup(CCmdUI* pCmdUI)
00481 {
00482 if(m_bInSimulation)
00483 pCmdUI->Enable(true);
00484 else
00485 pCmdUI->Enable(false);
00486 }
00487
00488 void CEvolveTrafficView::OnUpdateToolsSlowdown(CCmdUI* pCmdUI)
00489 {
00490 if(m_bInSimulation)
00491 pCmdUI->Enable(true);
00492 else
00493 pCmdUI->Enable(false);
00494 }
00495
00496 void CEvolveTrafficView::SettingUpdateRedraw()
00497 {
00498 initRoad();
00499 Invalidate();
00500 }
00501
00502 void CEvolveTrafficView::ValidateTimeWarp()
00503 {
00504 if(m_TimeWarp > m_MaxTimeWarp)
00505 {
00506 m_TimeWarp = m_MaxTimeWarp;
00507 CString str; str.Format("Maximum time warp reached (%.2f) for this simulation.",m_TimeWarp);
00508 MessageBox(str,"EvolveTraffic",MB_OK|MB_ICONINFORMATION);
00509 }
00510 if(m_TimeWarp < 0.5)
00511 {
00512 m_TimeWarp = 1.0;
00513 MessageBox("Half of real-time speed is the minimum time warp.","EvolveTraffic",MB_OK|MB_ICONINFORMATION);
00514 }
00515 }
00516
00517 void CEvolveTrafficView::OnToolsZoomin()
00518 {
00519 SetZoomScale(m_Scale + 0.2);
00520 }
00521
00522 void CEvolveTrafficView::OnToolsZoomout()
00523 {
00524 SetZoomScale(m_Scale - 0.2);
00525 }
00526
00527 void CEvolveTrafficView::OnToolsSpeedup()
00528 {
00529 m_TimeWarp += 1.0;
00530
00531 ValidateTimeWarp();
00532 }
00533
00534 void CEvolveTrafficView::OnToolsSlowdown()
00535 {
00536 m_TimeWarp -= 1.0;
00537
00538 ValidateTimeWarp();
00539 }
00540
00541 void CEvolveTrafficView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
00542 {
00543 CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
00544
00545 POINT curPoint = GetScrollPosition();
00546 int deltaX = Round(m_RoadLength/10);
00547
00548 switch(nChar)
00549 {
00550 case VK_RIGHT:
00551 curPoint.x += deltaX;
00552 break;
00553 case VK_LEFT:
00554 curPoint.x -= deltaX;
00555 break;
00556 case VK_HOME:
00557 curPoint.x = 0;
00558 break;
00559 case VK_END:
00560 CSize temp = GetTotalSize();
00561 curPoint.x = temp.cx;
00562 break;
00563 }
00564 ScrollToPosition(curPoint);
00565 Invalidate(FALSE);
00566 }
00567
00571
00572 void CEvolveTrafficView::OnFileSaveImage()
00573 {
00574 CFileDialog FileDlg(
00575 FALSE,
00576 _T("*.bmp"),
00577 NULL,
00578 OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
00579 "Bitmap files (*.bmp) |*.bmp||",
00580 this);
00581
00582 if(FileDlg.DoModal() == IDOK)
00583 {
00584 CString file = FileDlg.GetPathName();
00585 UpdateWindow();
00586 CWindowToBMP convert;
00587 if( convert.Write(file, this) )
00588 MessageBox("Image saved.","EvolveTraffic", MB_OK|MB_ICONINFORMATION);
00589 else
00590 MessageBox("Image saving failed.","EvolveTraffic", MB_OK|MB_ICONWARNING);
00591 }
00592 }
00593
00594 void CEvolveTrafficView::OnConfigSim()
00595 {
00596 CSimConfigDlg SimDlg;
00597
00598 SimDlg.m_FileIn = m_pDoc->getFileIn();
00599 SimDlg.m_FileOut = m_pDoc->getFileOut();
00600 SimDlg.m_MetricsDir = m_pDoc->getMetricsDir();
00601 SimDlg.m_FileType = m_pDoc->getFileType();
00602 SimDlg.m_RoadLength = m_pDoc->getRoadLength();
00603 SimDlg.m_DriveOnRight = m_pDoc->getDriveOnRight();
00604 SimDlg.m_NoLanesDirPos = m_pDoc->getNoLanesDirPos();
00605 SimDlg.m_NoLanesDirNeg = m_pDoc->getNoLanesDirNeg();
00606 SimDlg.m_SimTimeStep = (int)(m_pDoc->getSimTimeStep() * 1000);
00607
00608 SimDlg.m_AllowLaneChanging = m_pDoc->getAllowLaneChanging();
00609 SimDlg.m_TrafFileNoLanesDirPos = m_pDoc->getTrafFileNoLanesDirPos();
00610 SimDlg.m_TrafFileNoLanesDirNeg = m_pDoc->getTrafFileNoLanesDirNeg();
00611 SimDlg.m_LocOutputDetectorDirPos = m_pDoc->getLocOutputDetectorDirPos();
00612 SimDlg.m_LocOutputDetectorDirNeg = m_pDoc->getLocOutputDetectorDirNeg();
00613
00614 if(SimDlg.DoModal() == IDOK)
00615 {
00616 m_pDoc->setFileIn( SimDlg.m_FileIn );
00617 m_pDoc->setFileOut( SimDlg.m_FileOut );
00618 m_pDoc->setMetricsDir( SimDlg.m_MetricsDir );
00619 m_pDoc->setFileType( SimDlg.m_FileType );
00620 m_pDoc->setRoadLength( SimDlg.m_RoadLength );
00621 m_pDoc->setDriveOnRight( SimDlg.m_DriveOnRight );
00622 m_pDoc->setNoLanesDirPos( SimDlg.m_NoLanesDirPos);
00623 m_pDoc->setNoLanesDirNeg( SimDlg.m_NoLanesDirNeg);
00624 m_pDoc->setSimTimeStep( (double)SimDlg.m_SimTimeStep / 1000 );
00625
00626 m_pDoc->setAllowLaneChanging( SimDlg.m_AllowLaneChanging );
00627 m_pDoc->setTrafFileNoLanesDirPos( SimDlg.m_TrafFileNoLanesDirPos );
00628 m_pDoc->setTrafFileNoLanesDirNeg( SimDlg.m_TrafFileNoLanesDirNeg );
00629 m_pDoc->setLocOutputDetectorDirPos( SimDlg.m_LocOutputDetectorDirPos );
00630 m_pDoc->setLocOutputDetectorDirNeg( SimDlg.m_LocOutputDetectorDirNeg );
00631
00632 m_pDoc->UpdateDerivedMembers(true);
00633
00634 SettingUpdateRedraw();
00635 };
00636 }
00637
00638 void CEvolveTrafficView::OnConfigTraf()
00639 {
00640 CTrafficConfigDlg TrafDlg;
00641
00642 TrafDlg.m_IDMParams_Car = m_pDoc->getIDMParams_Car();
00643 TrafDlg.m_IDMParams_SmallTruck = m_pDoc->getIDMParams_SmallTruck();
00644 TrafDlg.m_IDMParams_LargeTruck = m_pDoc->getIDMParams_LargeTruck();
00645 TrafDlg.m_IDMParams_Crane = m_pDoc->getIDMParams_Crane();
00646 TrafDlg.m_IDMParams_Lowloader = m_pDoc->getIDMParams_Lowloader();
00647
00648 if(TrafDlg.DoModal() == IDOK)
00649 {
00650 m_pDoc->setIDMParams_Car (TrafDlg.m_IDMParams_Car);
00651 m_pDoc->setIDMParams_SmallTruck (TrafDlg.m_IDMParams_SmallTruck);
00652 m_pDoc->setIDMParams_LargeTruck (TrafDlg.m_IDMParams_LargeTruck);
00653 m_pDoc->setIDMParams_Crane (TrafDlg.m_IDMParams_Crane);
00654 m_pDoc->setIDMParams_Lowloader (TrafDlg.m_IDMParams_Lowloader);
00655
00656 Invalidate();
00657 }
00658 }
00659
00660 void CEvolveTrafficView::OnToolsPrefs()
00661 {
00662 CPreferencesDlg PrefsDlg;
00663
00664 PrefsDlg.m_Scale = m_Scale;
00665 PrefsDlg.m_ExaggerateWidths = m_ExaggerateWidths;
00666 PrefsDlg.m_TimeWarp = m_TimeWarp;
00667 PrefsDlg.m_TickStep = m_TickStep;
00668
00669 PrefsDlg.m_LaneWidth = m_LaneWidth / m_ExaggerateWidths;
00670 PrefsDlg.m_VehicleWidth = m_VehicleWidth/ m_ExaggerateWidths;
00671 PrefsDlg.m_TickLength = m_TickLength / m_ExaggerateWidths;
00672
00673 PrefsDlg.m_VehicleLengthScale = m_VehicleLengthScale;
00674 PrefsDlg.m_ShowVelocity = m_bShowVelocity ? 1 : 0;
00675 PrefsDlg.m_ShowLegend = m_bShowLegend ? 1 : 0;
00676 PrefsDlg.m_Border_Top = m_Border_Top;
00677 PrefsDlg.m_Border_Btm = m_Border_Btm;
00678 PrefsDlg.m_Border_Lhs = m_Border_Lhs;
00679 PrefsDlg.m_Border_Rhs = m_Border_Rhs;
00680
00681 if(PrefsDlg.DoModal() == IDOK)
00682 {
00683 m_Scale = PrefsDlg.m_Scale;
00684 m_ExaggerateWidths = PrefsDlg.m_ExaggerateWidths;
00685 m_TimeWarp = PrefsDlg.m_TimeWarp;
00686 m_TickStep = PrefsDlg.m_TickStep;
00687
00688 m_LaneWidth = PrefsDlg.m_LaneWidth * m_ExaggerateWidths;
00689 m_VehicleWidth = PrefsDlg.m_VehicleWidth * m_ExaggerateWidths;
00690 m_TickLength = PrefsDlg.m_TickLength * m_ExaggerateWidths;
00691
00692 m_VehicleLengthScale = PrefsDlg.m_VehicleLengthScale;
00693 m_bShowVelocity = PrefsDlg.m_ShowVelocity == 0 ? false : true;
00694 m_bShowLegend = PrefsDlg.m_ShowLegend == 0 ? false : true;
00695 m_Border_Top = PrefsDlg.m_Border_Top;
00696 m_Border_Btm = PrefsDlg.m_Border_Btm;
00697 m_Border_Lhs = PrefsDlg.m_Border_Lhs;
00698 m_Border_Rhs = PrefsDlg.m_Border_Rhs;
00699
00700 SettingUpdateRedraw();
00701 }
00702 }
00703
00704 void CEvolveTrafficView::OnConfigFeatures()
00705 {
00706 CRoadFeaturesDlg FeaturesDlg;
00707
00708 FeaturesDlg.m_RoadLength = m_RoadLength;
00709 FeaturesDlg.m_vRoadFeatures.Copy( *(m_pDoc->getRoadFeatures()) );
00710
00711 if( FeaturesDlg.DoModal() == IDOK )
00712 m_pDoc->setRoadFeatures( &(FeaturesDlg.m_vRoadFeatures) );
00713
00714 Invalidate();
00715 }
00716
00717 void CEvolveTrafficView::OnConfigMetrics()
00718 {
00719 CStatDetectorDlg StatDetDlg;
00720
00721 StatDetDlg.m_RoadLength = m_RoadLength;
00722 StatDetDlg.m_vStatDetectors.Copy( *(m_pDoc->getStatDetectors()) );
00723
00724 if( StatDetDlg.DoModal() == IDOK )
00725 m_pDoc->setStatDetectors( &(StatDetDlg.m_vStatDetectors) );
00726
00727 Invalidate();
00728 }
00729
00733
00734 void CEvolveTrafficView::OnLButtonDown(UINT nFlags, CPoint point)
00735 {
00736 if(m_bPause)
00737 {
00738
00739 CClientDC aDC(this);
00740 OnPrepareDC(&aDC);
00741 CPoint ptRoad = point;
00742 aDC.DPtoLP(&ptRoad);
00743 ptRoad.x -= m_Border_Lhs;
00744
00745 if(ptRoad.y < m_BtmEdge && ptRoad.y > m_TopEdge)
00746 {
00747
00748 int iLane = 1;
00749 int TopOfLane = m_BtmEdge;
00750
00751 while(ptRoad.y < TopOfLane)
00752 {
00753 TopOfLane = m_BtmEdge - iLane*m_LaneWidth;
00754 iLane++;
00755 }
00756
00757 iLane -= 2;
00758 if(!m_DriveOnRight)
00759 iLane = m_NoLanes - iLane -1;
00760
00761
00762 Vehicle* pVeh = FindVehicle(iLane, ptRoad.x);
00763
00764 if(pVeh != NULL)
00765 {
00766 CRect rect(point.x,point.y,point.x+100, point.y+100);
00767 m_DataTip.Show(rect,pVeh->getDataString());
00768 }
00769 }
00770 }
00771
00772 CScrollView::OnLButtonDown(nFlags, point);
00773 }
00774
00775 Vehicle* CEvolveTrafficView::FindVehicle(int iLane, int location)
00776 {
00777 Vehicle* pVeh = NULL;
00778 std::vector<Vehicle*> vLaneVehs = m_VehiclePositions.at(iLane);
00779
00780 for(int i = 0; i < vLaneVehs.size(); i++)
00781 {
00782 pVeh = vLaneVehs.at(i);
00783 int front = pVeh->getRoadPos();
00784 int length = pVeh->getLength() * m_VehicleLengthScale;
00785
00786 bool bOnVehicle = false;
00787 if(pVeh->getDirection())
00788 {
00789 if( location < front && location > front - length )
00790 bOnVehicle = true;
00791 }
00792 else
00793 {
00794 if( location > front && location < front + length )
00795 bOnVehicle = true;
00796 }
00797
00798 if( bOnVehicle )
00799 return pVeh;
00800 }
00801
00802 return NULL;
00803 }
00804
00808
00809 void CEvolveTrafficView::DrawRoad(CMemDC *pDC)
00810 {
00811
00812 CPen BlackPen(PS_SOLID, 0, CLR_ROAD_LINES);
00813 CPen BlackDashPen(PS_DASH, 0, CLR_ROAD_LINES);
00814
00815
00816 pDC->FillSolidRect(m_Border_Lhs,m_TopEdge,m_RoadLength,m_RoadWidth, CLR_ROAD_SURFACE);
00817
00818 DrawRoadSegments(pDC);
00819
00820 pDC->SelectObject(&BlackPen);
00821
00822 pDC->MoveTo(m_Border_Lhs,m_TopEdge);
00823 pDC->LineTo(m_Border_Lhs+m_RoadLength,m_TopEdge);
00824
00825 pDC->MoveTo(m_Border_Lhs,m_BtmEdge);
00826 pDC->LineTo(m_Border_Lhs+m_RoadLength,m_BtmEdge);
00827
00828 pDC->SelectObject(&BlackDashPen);
00829 int LaneEdge = m_BtmEdge;
00830 for (int i = 0; i < m_NoLanes-1; i++)
00831 {
00832 LaneEdge -= m_LaneWidth;
00833 pDC->MoveTo(m_Border_Lhs,LaneEdge);
00834 pDC->LineTo(m_Border_Lhs+m_RoadLength,LaneEdge);
00835 }
00836
00837 pDC->SelectObject(&BlackPen);
00838 if(m_NoDirections == 2)
00839 {
00840 pDC->MoveTo(m_Border_Lhs,0);
00841 pDC->LineTo(m_Border_Lhs+m_RoadLength,0);
00842 }
00843
00844 DrawDetectors(pDC);
00845 }
00846
00847 void CEvolveTrafficView::DrawVehicle(CMemDC *pDC, Vehicle* pVeh)
00848 {
00849 bool DirPointsRight = pVeh->getDirection();
00850 int lane = pVeh->getLane();
00851 int x = pVeh->getRoadPos() + m_Border_Lhs;
00852 int y = 0;
00853
00854 y = m_DriveOnRight ? m_BtmEdge - (lane-0.5)*m_LaneWidth : m_TopEdge + (lane-0.5)*m_LaneWidth;
00855
00856 y = y - m_VehicleWidth/2;
00857
00858
00859 int DirectionFactor = DirPointsRight == true ? -1 : +1;
00860 int cx = DirectionFactor * m_VehicleLengthScale * pVeh->getLength();
00861 CRect VehRect(x,y,x+cx,y+m_VehicleWidth);
00862
00863 DrawVehicleAt(pDC, pVeh->getID(), VehRect);
00864
00865
00866 double velocity = pVeh->getVelocity()*M_PER_S_TO_KM_PER_H;
00867
00868 if(m_bShowVelocity)
00869 {
00870 CString SpeedStr; SpeedStr.Format("%3.1f", velocity);
00871 CSize strSize = pDC->GetTextExtent(SpeedStr);
00872 x = x + cx/2 - strSize.cx/2;
00873 y = y + m_VehicleWidth/2 - strSize.cy/2;
00874 pDC->TextOut(x,y,SpeedStr);
00875 }
00876 }
00877
00878 void CEvolveTrafficView::DrawVehicleAt(CMemDC *pDC, WORD VEH_ID, CRect VehRect)
00879 {
00880 switch(VEH_ID)
00881 {
00882 case VEH_ID_CAR:
00883 pDC->FillSolidRect(VehRect, VEH_COLOR_CAR);
00884 break;
00885 case VEH_ID_SMALLTRUCK:
00886 pDC->FillSolidRect(VehRect, VEH_COLOR_SMALLTRUCK);
00887 break;
00888 case VEH_ID_LARGETRUCK:
00889 pDC->FillSolidRect(VehRect, VEH_COLOR_LARGETRUCK);
00890 break;
00891 case VEH_ID_CRANE:
00892 pDC->FillSolidRect(VehRect, VEH_COLOR_CRANE);
00893 break;
00894 case VEH_ID_LOWLOADER:
00895 pDC->FillSolidRect(VehRect, VEH_COLOR_LOWLOADER);
00896 break;
00897 default:
00898 pDC->FillSolidRect(VehRect, VEH_COLOR_CAR);
00899 }
00900 }
00901
00902 void CEvolveTrafficView::DrawTimer(CMemDC *pDC)
00903 {
00904 pDC->SetTextColor(CLR_LEGEND_TEXT);
00905 pDC->SetBkColor(CLR_BACKGRND);
00906
00907
00908 int ypos = Round(-(m_ClientRect.Height()/2)/m_Scale)+m_Border_Top;
00909 int xpos = m_Border_Lhs;
00910
00911 if(m_bInSimulation)
00912 m_CurentSimTime = m_pDoc->m_Sim.getCurrentSimTime();
00913
00914 double temp = m_CurentSimTime; int day = (int)(temp/(HOURS_PER_DAY * SECS_PER_HOUR));
00915 temp = temp - day * HOURS_PER_DAY * SECS_PER_HOUR; int hr = (int)(temp/(SECS_PER_HOUR));
00916 temp = temp - hr * SECS_PER_HOUR; int min = (int)(temp/(MINS_PER_HOUR));
00917 temp = temp - min * SECS_PER_MIN; double sec = temp;
00918
00919 CString SimStr; SimStr.Format("Sim. Time - Day: %d - %d:%02d:%05.2f",day,hr,min,sec);
00920 CSize strSimSize = pDC->GetTextExtent(SimStr);
00921 pDC->TextOut(xpos,ypos,SimStr);
00922
00923
00924 if(m_bInSimulation && !m_bPause)
00925 m_CurentRealTime = timeGetTime() - m_StartRealTime;
00926
00927 temp = (double)m_CurentRealTime/1000; day = (int)(temp/(HOURS_PER_DAY * SECS_PER_HOUR));
00928 temp = temp - day * HOURS_PER_DAY * SECS_PER_HOUR; hr = (int)(temp/(SECS_PER_HOUR));
00929 temp = temp - hr * SECS_PER_HOUR; min = (int)(temp/(MINS_PER_HOUR));
00930 temp = temp - min * SECS_PER_MIN; sec = temp;
00931
00932 CString RealStr; RealStr.Format("Real Time - Day: %d - %d:%02d:%05.2f",day,hr,min,sec);
00933 CSize strRealSize = pDC->GetTextExtent(RealStr);
00934 pDC->TextOut(xpos,ypos + strRealSize.cy*1.2 ,RealStr);
00935
00936 }
00937
00938 void CEvolveTrafficView::DrawLegend(CMemDC *pDC)
00939 {
00940 pDC->SetTextColor(CLR_LEGEND_TEXT);
00941 pDC->SetBkColor(CLR_BACKGRND);
00942
00943 CString strTime = "Real Time - Day: 00 - 00:00:00.00";
00944 CSize timeSize = pDC->GetTextExtent(strTime);
00945
00946
00947 int ypos = Round(-(m_ClientRect.Height()/2)/m_Scale) + m_Border_Top;
00948 int xpos = m_Border_Lhs + timeSize.cx + m_Border_Lhs;
00949 int ygap = 20/m_Scale;
00950 int LineLength = m_Border_Lhs/m_Scale;
00951 int LineToText = 20/m_Scale;
00952
00953 DrawLegendVehicle(pDC, VEH_ID_CAR, "Car", LineToText, xpos, ypos); ypos += ygap;
00954 DrawLegendVehicle(pDC, VEH_ID_SMALLTRUCK, "Small Truck", LineToText, xpos, ypos); ypos += ygap;
00955 DrawLegendVehicle(pDC, VEH_ID_LARGETRUCK, "Large Truck", LineToText, xpos, ypos); ypos += ygap;
00956 DrawLegendVehicle(pDC, VEH_ID_CRANE, "Crane", LineToText, xpos, ypos); ypos += ygap;
00957 DrawLegendVehicle(pDC, VEH_ID_LOWLOADER, "Low-loader", LineToText, xpos, ypos); ypos += ygap;
00958
00959 ypos -= 5*ygap;
00960 CSize strSize = pDC->GetTextExtent("Large Truck");
00961 xpos += LineLength+LineToText+strSize.cx+2*m_Border_Lhs;
00962
00963 DrawLegendElement(pDC, LineLength, LineToText, xpos, ypos, "Output Detector", CLR_DET_OUTPUT); ypos += ygap;
00964 DrawLegendElement(pDC, LineLength, LineToText, xpos, ypos, "Flow-Density Detector", CLR_DET_FLOWDENSITY); ypos += ygap;
00965 DrawLegendElement(pDC, LineLength, LineToText, xpos, ypos, "Headway Detector", CLR_DET_HEADWAY); ypos += ygap;
00966 DrawLegendElement(pDC, LineLength, LineToText, xpos, ypos, "Composition Detector", CLR_DET_COMPOSITION); ypos += ygap;
00967
00968 pDC->TextOut(xpos,ypos,"LC");
00969 pDC->TextOut(xpos+LineLength+LineToText,ypos,"Lane Change Detector");
00970
00971 ypos -= 4*ygap;
00972 strSize = pDC->GetTextExtent("Lane Change Detector");
00973 xpos += LineLength+LineToText+strSize.cx+2*m_Border_Lhs;
00974
00975 DrawLegendSegment(pDC, CLR_FEAT_SPEEDLIMIT, HS_DIAGCROSS, FEAT_SPEEDLIMIT,
00976 "Speed limit section", 50, LineToText, xpos, ypos);
00977 ypos += 2*ygap+5;
00978 DrawLegendSegment(pDC, CLR_FEAT_GRADIENT, HS_VERTICAL, FEAT_GRADIENT,
00979 "Gradient section", 5, LineToText, xpos, ypos);
00980
00981 }
00982
00983 void CEvolveTrafficView::DrawLegendVehicle(CMemDC *pDC, WORD VehType, CString str, int LineToText, int xpos, int ypos)
00984 {
00985 int rectWidth = 20/m_Scale;
00986 int rectHeight = 10/m_Scale;
00987
00988 CSize strSize = pDC->GetTextExtent(str);
00989 pDC->TextOut(xpos+rectWidth+LineToText, ypos,str);
00990 ypos += strSize.cy/2 - rectHeight/2;
00991 CRect VehRect(xpos,ypos,xpos+rectWidth, ypos+rectHeight);
00992 DrawVehicleAt(pDC, VehType, VehRect);
00993 }
00994
00995 void CEvolveTrafficView::DrawLegendSegment(CMemDC *pDC, COLORREF COL, WORD HATCH,
00996 WORD FeatType, CString str, int value, int LineToText, int xpos, int ypos)
00997 {
00998 int rectWidth = 80/m_Scale;
00999 int rectHeight = 30/m_Scale;
01000
01001 CRect segRect(xpos,ypos,xpos+rectWidth, ypos+rectHeight);
01002 DrawSingleSegment(pDC, COL, HATCH, FeatType, value, segRect, 0);
01003
01004 CSize strSize = pDC->GetTextExtent(str);
01005 pDC->TextOut(xpos+rectWidth+LineToText, ypos+rectHeight/2-strSize.cy/2,str);
01006 }
01007
01008 void CEvolveTrafficView::DrawLegendElement(CMemDC *pDC, int LineLength, int LineToText,
01009 int xpos, int ypos, CString str, COLORREF COL)
01010 {
01011 CPen DetPen;
01012
01013 DetPen.CreatePen(PS_SOLID, 3, COL);
01014 pDC->SelectObject(&DetPen);
01015 CSize strSize = pDC->GetTextExtent(str);
01016 pDC->TextOut(xpos+LineLength+LineToText,ypos,str);
01017 ypos += strSize.cy/2;
01018 pDC->MoveTo(xpos,ypos);
01019 pDC->LineTo(xpos+LineLength,ypos);
01020 }
01021
01022 void CEvolveTrafficView::DrawRoadSegments(CMemDC *pDC)
01023 {
01024 CObArray vSeg; vSeg.Copy( *(m_pDoc->getRoadFeatures()) );
01025 for(int i = 0; i < vSeg.GetSize(); i++)
01026 {
01027 CRoadFeature* pFeat = reinterpret_cast<CRoadFeature*>(vSeg.GetAt(i));
01028 WORD FeatType = pFeat->getType();
01029 int FeatValue = 0;
01030 COLORREF COL;
01031 WORD HATCH;
01032 switch(FeatType)
01033 {
01034 case FEAT_SPEEDLIMIT:
01035 COL = CLR_FEAT_SPEEDLIMIT;
01036 HATCH = HS_DIAGCROSS;
01037 FeatValue = Round(pFeat->getValue()*M_PER_S_TO_KM_PER_H);
01038 break;
01039 case FEAT_GRADIENT:
01040 COL = CLR_FEAT_GRADIENT;
01041 HATCH = HS_VERTICAL;
01042 FeatValue = Round(pFeat->getValue());
01043 break;
01044 default:
01045 COL = CLR_FEAT_SPEEDLIMIT;
01046 }
01047
01048 bool DirPos = pFeat->getDirPos();
01049 int DriveSide = m_DriveOnRight ? +1 : -1;
01050 int DirFactor = DirPos ? +1 : -1;
01051 int nLanes = DirPos ? m_NoLanesDirPos : m_NoLanesDirNeg;
01052
01053 int x1 = pFeat->getStart() + m_Border_Lhs;
01054 int x2 = pFeat->getEnd() + m_Border_Lhs;
01055 int y1 = 0;
01056 int y2 = DirFactor * DriveSide * nLanes * m_LaneWidth;
01057 CRect segRect(x1,y1,x2,y2);
01058 DrawSingleSegment(pDC, COL, HATCH, FeatType, FeatValue, segRect,m_LaneWidth/2);
01059 }
01060 }
01061
01062 void CEvolveTrafficView::DrawSingleSegment(CMemDC *pDC, COLORREF COL, WORD HATCH,
01063 WORD FeatType, int val, CRect rect, int yTextOffset)
01064 {
01065 int x1 = rect.left;
01066 int x2 = rect.right;
01067 int y1 = rect.top;
01068 int y2 = rect.bottom;
01069
01070 CPen SegEdgePen(PS_SOLID, 1, COL);
01071 CPen* pOldPen = pDC->SelectObject(&SegEdgePen);
01072 CBrush SegBrush(HATCH,COL);
01073 CRect SegRect(x1,y1,x2,y2);
01074 CBrush* pOldBrush = pDC->SelectObject(&SegBrush);
01075 pDC->SetBkMode(TRANSPARENT);
01076 pDC->Rectangle(SegRect);
01077 pDC->SelectObject(pOldBrush);
01078
01079 CPen SegEndsPen(PS_SOLID, 3, COL);
01080 pDC->SelectObject(&SegEndsPen);
01081 pDC->MoveTo(x1,y1); pDC->LineTo(x1,y2);
01082 pDC->MoveTo(x2,y1); pDC->LineTo(x2,y2);
01083
01084 pDC->SelectObject(pOldPen);
01085
01086 CString str;
01087 switch(FeatType)
01088 {
01089 case FEAT_SPEEDLIMIT:
01090 str.Format("%d km/h",val);
01091 break;
01092 case FEAT_GRADIENT:
01093 str.Format("%d%%",val);
01094 break;
01095 default:
01096 str.Format("%d km/h",val);
01097 }
01098 CSize strSize = pDC->GetTextExtent(str);
01099 pDC->TextOut((x1+x2)/2-strSize.cx/2,(y1+y2)/2-strSize.cy/2+yTextOffset,str);
01100 }
01101
01102 void CEvolveTrafficView::DrawDetectors(CMemDC *pDC)
01103 {
01104
01105 double LocDetDirPos = m_pDoc->getLocOutputDetectorDirPos();
01106 double LocDetDirNeg = m_pDoc->getLocOutputDetectorDirNeg();
01107 DrawSingleDetector(pDC, CLR_DET_OUTPUT, LocDetDirPos, true);
01108 DrawSingleDetector(pDC, CLR_DET_OUTPUT, LocDetDirNeg, false);
01109
01110
01111 CObArray vSD; vSD.Copy( *(m_pDoc->getStatDetectors()) );
01112 for(int i = 0; i < vSD.GetSize(); i++)
01113 {
01114 CStatDetector* pSD = reinterpret_cast<CStatDetector*>(vSD.GetAt(i));
01115 WORD SDtype = pSD->getDetectorType();
01116 bool bDraw = true;
01117 COLORREF COL;
01118 switch(SDtype)
01119 {
01120 case METRICS_TYPE_FLOWDENSITY:
01121 COL = CLR_DET_FLOWDENSITY;
01122 break;
01123 case METRICS_TYPE_HEADWAY:
01124 COL = CLR_DET_HEADWAY;
01125 break;
01126 case METRICS_TYPE_COMPOSITION:
01127 COL = CLR_DET_COMPOSITION;
01128 break;
01129 case METRICS_TYPE_LANE_CHANGE:
01130 DrawLaneChangeDetectors(pDC, pSD->getDirPos());
01131 bDraw = false;
01132 break;
01133 default:
01134 COL = CLR_DET_FLOWDENSITY;
01135 }
01136 if(bDraw)
01137 DrawSingleDetector(pDC, COL, pSD->getLocation(), pSD->getDirPos());
01138 }
01139 }
01140
01141 void CEvolveTrafficView::DrawLaneChangeDetectors(CMemDC *pDC, bool DirPos)
01142 {
01143 CString str = "LC";
01144 CSize strSize = pDC->GetTextExtent(str);
01145
01146 int DriveSide = m_DriveOnRight ? +1 : -1;
01147 int DirFactor = DirPos ? +1 : -1;
01148 int nLanes = DirPos ? m_NoLanesDirPos : m_NoLanesDirNeg;
01149
01150 int xScrnLoc = m_Border_Lhs - strSize.cx - 2;
01151 int ypos = DirFactor* DriveSide * nLanes * m_LaneWidth /2;
01152
01153 pDC->TextOut(xScrnLoc,ypos-strSize.cy/2,str);
01154 }
01155
01156 void CEvolveTrafficView::DrawSingleDetector(CMemDC *pDC, COLORREF COL, int Loc, bool DirPos)
01157 {
01158
01159 CPen DetectorPen(PS_SOLID, 3, COL);
01160 pDC->SelectObject(&DetectorPen);
01161
01162 int ScrnLoc = Loc + m_Border_Lhs;
01163
01164 int DriveSide = m_DriveOnRight ? +1 : -1;
01165 int DirFactor = DirPos ? +1 : -1;
01166 int nLanes = DirPos ? m_NoLanesDirPos : m_NoLanesDirNeg;
01167
01168 int ypos = 0;
01169 pDC->MoveTo(ScrnLoc,ypos);
01170
01171 ypos = DirFactor* DriveSide * nLanes * m_LaneWidth;
01172 pDC->LineTo(ScrnLoc,ypos);
01173 }
01174
01175 void CEvolveTrafficView::DrawRuler(CMemDC *pDC)
01176 {
01177 int ypos = m_BtmEdge;
01178
01179
01180 CPen RulerLinesPen(PS_SOLID, 0, CLR_RULER_LINES);
01181 pDC->SelectObject(&RulerLinesPen);
01182 pDC->SetTextColor(CLR_RULER_TEXT);
01183 pDC->SetBkColor(CLR_BACKGRND);
01184
01185 for(int i = 0; i < m_NoTicks; i++)
01186 {
01187 int xpos = m_Border_Lhs+i*m_TickStep;
01188 pDC->MoveTo(xpos,ypos);
01189 pDC->LineTo(xpos,ypos+m_TickLength);
01190 CString str; str.Format("%d m",i*m_TickStep);
01191 pDC->TextOut(xpos+5,ypos+10,str);
01192 }
01193 }