00001 // EvolveTrafficDoc.cpp : implementation of the CEvolveTrafficDoc class 00002 // 00003 00004 #include "stdafx.h" 00005 #include "EvolveTraffic.h" 00006 00007 #include "EvolveTrafficDoc.h" 00008 #include "RoadFeature.h" 00009 00010 #ifdef _DEBUG 00011 #define new DEBUG_NEW 00012 #undef THIS_FILE 00013 static char THIS_FILE[] = __FILE__; 00014 #endif 00015 00017 // CEvolveTrafficDoc 00018 00019 IMPLEMENT_DYNCREATE(CEvolveTrafficDoc, CDocument) 00020 00021 BEGIN_MESSAGE_MAP(CEvolveTrafficDoc, CDocument) 00022 //{{AFX_MSG_MAP(CEvolveTrafficDoc) 00023 // NOTE - the ClassWizard will add and remove mapping macros here. 00024 // DO NOT EDIT what you see in these blocks of generated code! 00025 //}}AFX_MSG_MAP 00026 END_MESSAGE_MAP() 00027 00029 // CEvolveTrafficDoc construction/destruction 00030 00031 CEvolveTrafficDoc::CEvolveTrafficDoc() 00032 { 00033 m_IDMParams_Car .setVehicleTypeID(VEH_ID_CAR); 00034 m_IDMParams_SmallTruck .setVehicleTypeID(VEH_ID_SMALLTRUCK); 00035 m_IDMParams_LargeTruck .setVehicleTypeID(VEH_ID_LARGETRUCK); 00036 m_IDMParams_Crane .setVehicleTypeID(VEH_ID_CRANE); 00037 m_IDMParams_Lowloader .setVehicleTypeID(VEH_ID_LOWLOADER); 00038 } 00039 00040 CEvolveTrafficDoc::~CEvolveTrafficDoc() 00041 { 00042 clear(); 00043 } 00044 00045 void CEvolveTrafficDoc::clear() 00046 { 00047 for(int i = 0; i < m_vRoadFeatures.GetSize(); i++) 00048 delete m_vRoadFeatures.GetAt(i); 00049 m_vRoadFeatures.RemoveAll(); 00050 00051 for(i = 0; i < m_vStatDetectors.GetSize(); i++) 00052 delete m_vStatDetectors.GetAt(i); 00053 m_vStatDetectors.RemoveAll(); 00054 00055 } 00056 00057 BOOL CEvolveTrafficDoc::OnNewDocument() 00058 { 00059 if (!CDocument::OnNewDocument()) 00060 return FALSE; 00061 00062 m_FileIn = _T(""); 00063 m_FileOut = _T(""); 00064 m_RoadLength = 3000; 00065 m_NoLanesDirPos = 2; 00066 m_NoLanesDirNeg = 1; 00067 m_FileType = CASTOR; 00068 m_SimTimeStep = 0.1; 00069 m_DriveOnRight = true; 00070 m_LocOutputDetectorDirPos = 2500; 00071 m_LocOutputDetectorDirNeg = 2500; 00072 00073 CRoadFeature* pFeat = new CRoadFeature; 00074 m_vRoadFeatures.Add(pFeat); 00075 00076 CStatDetector* pDet = new CStatDetector; 00077 m_vStatDetectors.Add(pDet); 00078 00079 UpdateDerivedMembers(false); // do not call SetModFlag 00080 00081 return TRUE; 00082 } 00083 00085 // CEvolveTrafficDoc serialization 00086 00087 void CEvolveTrafficDoc::Serialize(CArchive& ar) 00088 { 00089 m_vStatDetectors .Serialize(ar); 00090 m_vRoadFeatures .Serialize(ar); 00091 00092 m_IDMParams_Car .Serialize(ar); 00093 m_IDMParams_SmallTruck .Serialize(ar); 00094 m_IDMParams_LargeTruck .Serialize(ar); 00095 m_IDMParams_Crane .Serialize(ar); 00096 m_IDMParams_Lowloader .Serialize(ar); 00097 00098 if (ar.IsStoring()) 00099 { 00100 ar << m_FileIn 00101 << m_FileOut 00102 << m_MetricsDir 00103 << m_FileType 00104 << m_TrafFileNoLanesDirPos 00105 << m_TrafFileNoLanesDirNeg 00106 << m_NoDirections 00107 << m_NoLanes 00108 << m_NoLanesDirPos 00109 << m_NoLanesDirNeg 00110 << m_RoadLength 00111 << m_DriveOnRight 00112 << m_SimTimeStep 00113 << m_LocOutputDetectorDirPos 00114 << m_LocOutputDetectorDirNeg 00115 << m_AllowLaneChanging; 00116 } 00117 else 00118 { 00119 ar >> m_FileIn 00120 >> m_FileOut 00121 >> m_MetricsDir 00122 >> m_FileType 00123 >> m_TrafFileNoLanesDirPos 00124 >> m_TrafFileNoLanesDirNeg 00125 >> m_NoDirections 00126 >> m_NoLanes 00127 >> m_NoLanesDirPos 00128 >> m_NoLanesDirNeg 00129 >> m_RoadLength 00130 >> m_DriveOnRight 00131 >> m_SimTimeStep 00132 >> m_LocOutputDetectorDirPos 00133 >> m_LocOutputDetectorDirNeg 00134 >> m_AllowLaneChanging; 00135 } 00136 } 00137 00139 // CEvolveTrafficDoc diagnostics 00140 00141 #ifdef _DEBUG 00142 void CEvolveTrafficDoc::AssertValid() const 00143 { 00144 CDocument::AssertValid(); 00145 } 00146 00147 void CEvolveTrafficDoc::Dump(CDumpContext& dc) const 00148 { 00149 CDocument::Dump(dc); 00150 } 00151 #endif //_DEBUG 00152 00154 // CEvolveTrafficDoc commands 00155 00156 void CEvolveTrafficDoc::UpdateDerivedMembers(bool setMod) 00157 { 00158 m_NoLanes = m_NoLanesDirPos + m_NoLanesDirNeg; 00159 m_NoDirections = (m_NoLanesDirPos > 0 && m_NoLanesDirNeg > 0) ? 2 : 1; 00160 00161 if(setMod) 00162 SetModifiedFlag(); // To implement Save Changes prompts 00163 } 00164 00165 bool CEvolveTrafficDoc::initSim() 00166 { 00167 CFile FileIn; CFileStatus status; 00168 bool bFileExists = FileIn.GetStatus((LPCTSTR)m_FileIn,status); 00169 if(!bFileExists) 00170 { 00171 MessageBox(NULL, "The input traffic file does not exist","EvolveTraffic",MB_OK|MB_ICONWARNING); 00172 return false; 00173 } 00174 00175 m_Sim.setFileIn( (LPCTSTR)m_FileIn ); 00176 m_Sim.setFileOut( (LPCTSTR)m_FileOut ); 00177 m_Sim.setFileType(m_FileType); 00178 m_Sim.setNoDirections(m_NoDirections); 00179 m_Sim.setNoLanes(m_NoLanes); 00180 m_Sim.setNoLanesDirPos(m_NoLanesDirPos); 00181 m_Sim.setNoLanesDirNeg(m_NoLanesDirNeg); 00182 m_Sim.setRoadLength(m_RoadLength); 00183 m_Sim.setSimTimeStep(m_SimTimeStep); 00184 00185 m_Sim.getRoad()->setIDMParams_Car (&m_IDMParams_Car); 00186 m_Sim.getRoad()->setIDMParams_SmallTruck(&m_IDMParams_SmallTruck); 00187 m_Sim.getRoad()->setIDMParams_LargeTruck(&m_IDMParams_LargeTruck); 00188 m_Sim.getRoad()->setIDMParams_Crane (&m_IDMParams_Crane); 00189 m_Sim.getRoad()->setIDMParams_Lowloader (&m_IDMParams_Lowloader); 00190 00191 for(int i = 0; i < m_vRoadFeatures.GetSize(); i++) 00192 m_Sim.getRoad()->SetSegmentFromFeature( reinterpret_cast<CRoadFeature*>(m_vRoadFeatures.GetAt(i)) ); 00193 00194 for(i = 0; i < m_vStatDetectors.GetSize(); i++) 00195 { 00196 CStatDetector* pSD = reinterpret_cast<CStatDetector*>(m_vStatDetectors.GetAt(i)); 00197 pSD->setMetricsDir(m_MetricsDir); 00198 m_Sim.getRoad()->SetMetricDetFromStatDet( pSD, m_NoLanesDirPos, m_NoLanesDirNeg); 00199 } 00200 00201 m_Sim.getRoad()->setTrafFileNoLanesDirPos(m_TrafFileNoLanesDirPos); 00202 m_Sim.getRoad()->setTrafFileNoLanesDirNeg(m_TrafFileNoLanesDirNeg); 00203 m_Sim.getRoad()->setLocOuputDetectorDirPos(m_LocOutputDetectorDirPos); 00204 m_Sim.getRoad()->setLocOuputDetectorDirNeg(m_LocOutputDetectorDirNeg); 00205 m_Sim.getRoad()->setAllowLaneChanging(m_AllowLaneChanging); 00206 m_Sim.getRoad()->setDriveOnRight(m_DriveOnRight); 00207 00208 m_Sim.init(); // must be called last when all other params are set 00209 00210 return true; 00211 } 00212 00213 // Private Member Sets 00214 void CEvolveTrafficDoc::setRoadLength(int L) 00215 { 00216 m_RoadLength = L; 00217 SetModifiedFlag(); // To implement Save Changes prompts 00218 } 00219 00220 void CEvolveTrafficDoc::setNoLanes(int nl) 00221 { 00222 m_NoLanes = nl; 00223 SetModifiedFlag(); // To implement Save Changes prompts 00224 } 00225 00226 void CEvolveTrafficDoc::setNoDirections(int nd) 00227 { 00228 m_NoDirections = nd; 00229 SetModifiedFlag(); // To implement Save Changes prompts 00230 } 00231 00232 void CEvolveTrafficDoc::setSimTimeStep(double ts) 00233 { 00234 m_SimTimeStep = ts; 00235 SetModifiedFlag(); // To implement Save Changes prompts 00236 } 00237 00238 void CEvolveTrafficDoc::setNoLanesDirPos(int nlpos) 00239 { 00240 m_NoLanesDirPos = nlpos; 00241 SetModifiedFlag(); // To implement Save Changes prompts 00242 } 00243 00244 void CEvolveTrafficDoc::setNoLanesDirNeg(int nlneg) 00245 { 00246 m_NoLanesDirNeg = nlneg; 00247 SetModifiedFlag(); // To implement Save Changes prompts 00248 } 00249 00250 void CEvolveTrafficDoc::setFileIn(CString file) 00251 { 00252 m_FileIn = file; 00253 SetModifiedFlag(); // To implement Save Changes prompts 00254 } 00255 00256 void CEvolveTrafficDoc::setFileOut(CString file) 00257 { 00258 m_FileOut = file; 00259 SetModifiedFlag(); // To implement Save Changes prompts 00260 } 00261 00262 void CEvolveTrafficDoc::setMetricsDir(CString dir) 00263 { 00264 m_MetricsDir = dir; 00265 SetModifiedFlag(); // To implement Save Changes prompts 00266 } 00267 00268 void CEvolveTrafficDoc::setFileType(WORD fileType) 00269 { 00270 m_FileType = fileType; 00271 SetModifiedFlag(); // To implement Save Changes prompts 00272 } 00273 00274 void CEvolveTrafficDoc::setIDMParams_Car(CIDMParameterSet theSet) 00275 { 00276 m_IDMParams_Car = theSet; 00277 SetModifiedFlag(); // To implement Save Changes prompts 00278 } 00279 00280 void CEvolveTrafficDoc::setIDMParams_SmallTruck(CIDMParameterSet theSet) 00281 { 00282 m_IDMParams_SmallTruck = theSet; 00283 SetModifiedFlag(); // To implement Save Changes prompts 00284 } 00285 00286 void CEvolveTrafficDoc::setIDMParams_LargeTruck(CIDMParameterSet theSet) 00287 { 00288 m_IDMParams_LargeTruck = theSet; 00289 SetModifiedFlag(); // To implement Save Changes prompts 00290 } 00291 00292 void CEvolveTrafficDoc::setIDMParams_Crane(CIDMParameterSet theSet) 00293 { 00294 m_IDMParams_Crane = theSet; 00295 SetModifiedFlag(); // To implement Save Changes prompts 00296 } 00297 00298 void CEvolveTrafficDoc::setIDMParams_Lowloader(CIDMParameterSet theSet) 00299 { 00300 m_IDMParams_Lowloader = theSet; 00301 SetModifiedFlag(); // To implement Save Changes prompts 00302 } 00303 00304 void CEvolveTrafficDoc::setTrafFileNoLanesDirPos(int nl) 00305 { 00306 m_TrafFileNoLanesDirPos = nl; 00307 SetModifiedFlag(); 00308 } 00309 00310 void CEvolveTrafficDoc::setTrafFileNoLanesDirNeg(int nl) 00311 { 00312 m_TrafFileNoLanesDirNeg = nl; 00313 SetModifiedFlag(); 00314 } 00315 00316 void CEvolveTrafficDoc::setLocOutputDetectorDirPos(int loc) 00317 { 00318 m_LocOutputDetectorDirPos = loc; 00319 SetModifiedFlag(); 00320 } 00321 00322 void CEvolveTrafficDoc::setLocOutputDetectorDirNeg(int loc) 00323 { 00324 m_LocOutputDetectorDirNeg = loc; 00325 SetModifiedFlag(); 00326 } 00327 00328 void CEvolveTrafficDoc::setAllowLaneChanging(BOOL status) 00329 { 00330 m_AllowLaneChanging = status; 00331 SetModifiedFlag(); 00332 } 00333 00334 void CEvolveTrafficDoc::setRoadFeatures(CObArray* pRoadFeatures) 00335 { 00336 m_vRoadFeatures.Copy( *pRoadFeatures ); 00337 SetModifiedFlag(); 00338 } 00339 00340 void CEvolveTrafficDoc::setStatDetectors(CObArray* pStatDetectors) 00341 { 00342 m_vStatDetectors.Copy( *pStatDetectors ); 00343 SetModifiedFlag(); 00344 } 00345 00346 void CEvolveTrafficDoc::setDriveOnRight(bool OnRight) 00347 { 00348 m_DriveOnRight = OnRight; 00349 }