Commit 78cc48e0 authored by a.zitz's avatar a.zitz

Testausgaben wurden entfernt; Die Datei events.txt wird als fstream...

Testausgaben wurden entfernt; Die Datei events.txt wird als fstream eingelesen; Das Einlesen erfolgt in jedem Zeitschritt, aber nur wenn eine neue Zeile hinzugekommen ist, reagiert das Programm. Im Moment gibt das Programm einfach nur den Inhalt der Zeile wieder aus.; Es gibt eine boolsche Variable, die beim Erzeugen des EventManager gesetzt wird. Sie bestimmt, ob ein dynamisches Eventhandling moeglich ist, abhaengig davon ob die Datei events.txt existiert.
parent 6336ce5a
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <math.h>
#include "EventManager.h"
#include "../tinyxml/tinyxml.h"
#include "../IO/OutputHandler.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
using namespace std;
......@@ -23,6 +14,17 @@ EventManager::EventManager(Building *_b){
_projectFilename = "";
_building = _b;
_deltaT=NULL;
_eventCounter=0;
_dynamic=false;
_file.open("../events/events.txt", ios::in);
if(!_file){
cout << "INFO:\tDatei events.txt nicht gefunden. Dynamisches Eventhandling nicht moeglich." << endl;
}
else{
cout << "INFO:\tDatei events.txt gefunden. Dynamisches Eventhandling moeglich." << endl;
_dynamic=true;
}
_file.close();
}
/*******************
......@@ -110,6 +112,21 @@ void EventManager::listEvents(){
}
void EventManager::readEventsTxt(double time){
_file.open("../events/events.txt", ios::in);
char cstring[256];
int lines=0;
do {
lines++;
_file.getline(cstring, sizeof(cstring));
if(lines>_eventCounter){
cout << time << ": " << cstring << endl;
_eventCounter++;
}
} while (!_file.eof());
_file.close();
}
/***********
Update
**********/
......@@ -125,8 +142,7 @@ void EventManager::Update_Events(double time, double d){
for(i=0;i<_event_times.size();i++){
if(fabs(_event_times[i]-time)<0.0000001){
//Event findet statt
printf("%f: Event zum Zeitpunkt %f findet statt: ",time,_event_times[i]);
cout << _event_types[i] << " " << _event_ids[i] << " " << _event_states[i] << endl;
printf("INFO:\t%f: Event zum Zeitpunkt %f findet statt: \n",time,_event_times[i]);
if(_event_states[i].compare("close")==0){
closeDoor(_event_ids[i]);
}
......@@ -135,6 +151,8 @@ void EventManager::Update_Events(double time, double d){
}
}
}
if(_dynamic)
readEventsTxt(time);
}
/***************
......@@ -148,6 +166,9 @@ void EventManager::closeDoor(int id){
cout << "Door " << id << " closed." << endl;
changeRouting(id,"close");
}
else{
cout << "Door " << id << " is already close yet." << endl;
}
}
......@@ -169,14 +190,9 @@ void EventManager::changeRouting(int id, string state){
routingEngine->Init(_building);
_building->InitPhiAllPeds(_deltaT);
vector<Pedestrian*> _allPedestrians=_building->GetAllPedestrians();
cout << "alle Pedestrians" <<endl;
unsigned int nSize = _allPedestrians.size();
cout << nSize << endl;
//cout << nSize << endl;
for (int p = 0; p < nSize; ++p) {
_allPedestrians[p]->ClearMentalMap();
cout << p << ": " << _allPedestrians[p]->FindRoute() << endl;
}
cout << "fertig" << endl;
}
......@@ -2,9 +2,15 @@
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <vector>
#include <math.h>
#include "../geometry/Building.h"
#include "../geometry/Transition.h"
#include "../tinyxml/tinyxml.h"
#include "../IO/OutputHandler.h"
#include "../routing/RoutingEngine.h"
#include "../pedestrian/Pedestrian.h"
class EventManager {
private:
......@@ -16,6 +22,9 @@ private:
std::string _projectRootDir;
Building *_building;
double _deltaT;
std::fstream _file;
bool _dynamic;
int _eventCounter;
public:
//Konstruktor
......@@ -25,7 +34,7 @@ public:
void SetProjectRootDir(const std::string &filename);
void readEventsXml();
void listEvents();
void readEventsTxt(std::string eventfile);
void readEventsTxt(double time);
//Update
void Update_Events(double time, double d);
//Eventhandling
......
door 5 close
door 5 open
\ No newline at end of file
......@@ -1292,10 +1292,8 @@ void Building::LoadTrafficInfo() {
//store transition in a map and call getTransition/getCrossin
if (state == "open") {
GetTransition(id)->Open();
cout << "Door" << id << "is " << state <<endl;
} else if (state == "close") {
GetTransition(id)->Close();
cout << "Door" << id << "is " << state <<endl;
} else {
Log->Write("WARNING:\t Unknown door state: %s", state.c_str());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment