Commit ddb8959b authored by a.zitz's avatar a.zitz

Einlesen der events.xml abgeschlossen, so dass man auf die Events zugreifen kann.

parent 71abf5ce
......@@ -226,6 +226,8 @@ file(
poly2tri/sweep/advancing_front.h
poly2tri/sweep/sweep.h
events/EventManager.cpp
)
#Target
......
......@@ -42,7 +42,7 @@ Simulation::Simulation() {
_solver = NULL;
_iod = new IODispatcher();
_fps=1;
_em = NULL;
_em=NULL;
}
Simulation::~Simulation() {
......@@ -52,7 +52,7 @@ Simulation::~Simulation() {
delete _model;
delete _solver;
delete _iod;
delete _em;
delete _em;
}
/************************************************
......@@ -381,6 +381,13 @@ void Simulation::InitArgs(ArgumentParser* args) {
// perform a general check to the .
_building->SanityCheck();
//read the events
_em = new EventManager();
_em->SetProjectFilename(args->GetProjectFile());
_em->SetProjectRootDir(args->GetProjectRootDir());
_em->readEventsXml();
_em->listEvents();
}
......
......@@ -75,7 +75,7 @@ private:
/// writing the trajectories to file
IODispatcher* _iod;
///new: EventManager
EventManager _em;
EventManager* _em;
public:
......
......@@ -13,37 +13,106 @@ using namespace std;
******************/
EventManager::EventManager(){
_event_times=vector<int>();
_event_times=vector<double>();
_event_values=vector<string>();
_projectFilename = "";
}
void readEventsXml(string eventfile){
Log->Write("INFO: \tLoading and parsing the event file <%s>",eventfile.c_str());
/*******************
Dateien einlesen
******************/
void EventManager::SetProjectFilename(const std::string &filename){
_projectFilename=filename;
}
TiXmlDocument doc(eventfile);
if(!doc.LoadFile()){
Log->Write("EROOR: \t%s",doc.ErrorDesc());
Log->Write("ERROR: \t could not parse the event file");
exit(EXIT_FAILURE);
void EventManager::SetProjectRootDir(const std::string &filename){
_projectRootDir= filename;
}
void EventManager::readEventsXml(){
printf("INFO: \tReading events\n ");
//get the geometry filename from the project file
TiXmlDocument doc(_projectFilename);
if (!doc.LoadFile()){
//Log->Write("ERROR: \t%s", doc.ErrorDesc());
//Log->Write("ERROR: \t could not parse the project file");
printf("ERROR: \t%s\nRROR: \t could not parse the project file\n",doc.ErrorDesc());
exit(EXIT_FAILURE);
}
TiXmlElement* xMainNdoe = doc.RootElement();
if(!xMainNode){
Log->Write("ERROR:\tRoot element does not exist.");
exit(EXIT_FAILURE);
//Log->Write("INFO: \tParsing the event file");
printf("INFO: \tParsing the event file\n");
TiXmlElement* xMainNode = doc.RootElement();
string eventfile="";
if(xMainNode->FirstChild("events")){
eventfile=_projectRootDir+xMainNode->FirstChild("events")->FirstChild()->Value();
//Log->Write("INFO: \tevents <"+eventfile+">");
//printf("INFO: \t events <%s>\n", eventfile);
}
TiXmlNode* xEvents = xMainNode->FirstChild("JPScore");
TiXmlDocument docEvent(eventfile);
if(!docEvent.LoadFile()){
//Log->Write("EROOR: \t%s",docEvent.ErrorDesc());
//Log->Write("ERROR: \t could not parse the event file");
printf("EROOR: \t%s\nERROR: \t could not parse the event file\n",docEvent.ErrorDesc());
exit(EXIT_FAILURE);
}
TiXmlElement* xRootNode = docEvent.RootElement();
if(!xRootNode){
//Log->Write("ERROR:\tRoot element does not exist.");
printf("ERROR:\tRoot element does not exist.\n");
exit(EXIT_FAILURE);
}
if( xRootNode->ValueStr () != "JPScore" ) {
//Log->Write("ERROR:\tRoot element value is not 'geometry'.");
printf("ERROR:\tRoot element value is not 'JPScore'.");
exit(EXIT_FAILURE);
}
TiXmlNode* xEvents = xRootNode->FirstChild("events");
if(!xEvents){
Log->Write("ERROR:\tNo events found.");
exit(EXIT_FAILURE);
//Log->Write("ERROR:\tNo events found.");
printf("ERROR:\tNo events found.\n");
exit(EXIT_FAILURE);
}
for(TiXmlElement* e = xEvents->FirstChildElement("event"); e; e= e->NextSiblingElement("event")){
_event_times.push_back(atoi(e->Attribute("time")));
string tmp=e->Attribute("type"))+"-");
tmp=tmp+e->Attribute("id"))+"-";
tmp=tmp+=e->Attribute("state"));
_event_values.push_back(tmp);
_event_times.push_back(atoi(e->Attribute("time")));
string tmp=e->Attribute("type");
tmp=tmp+"-";
tmp=tmp+e->Attribute("id")+"-";
tmp=tmp+=e->Attribute("state");
_event_values.push_back(tmp);
}
printf("INFO: \tEvents were read\n");
}
void EventManager::listEvents(){
if(_event_times.size()==0&&_event_values.size()==0){
//Log->Write("INFO: \tNo events in the events.xml");
printf("INFO: \tNo events in the events.xml\n");
}
else if(_event_times.size()!=_event_values.size()){
//Log->Write("ERROR: \tThe event.xml is irregular.");
printf("ERROR: \tThe event.xml is irregular.\n");
}
else{
int i;
for(i=0;i<_event_times.size();i++){
// Log->Write("INFO: \tEvent "+(i+1)+" after "+_event_times[i]+" sec.: "+_event_values[i]);
cout <<"INFO: \tEvent "<<i+1<<" after "<< _event_times[i] << "sec.: "<<_event_values[i] <<endl;
}
}
}
/***********
Update
**********/
void EventManager::Update_Events(double time){
}
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
class EventManager {
private:
std::vector<int> _event_times;
std::vector<string> _event_values;
std::vector<double> _event_times;
std::vector<std::string> _event_values;
std::string _projectFilename;
std::string _projectRootDir;
public:
EventManager();
readEventsXml(string eventfile);
};
\ No newline at end of file
void readEventsXml();
void listEvents();
void Update_Events(double time);
void readEventsTxt(std::string eventfile);
void SetProjectFilename(const std::string &filename) ;
void SetProjectRootDir(const std::string &filename);
};
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JPScore>
<events>
<event time="2" type="door" state="close" id="0" caption="exit" />
<event time="10" type="door" state="close" id="1" caption="roomdoor" />
<event time="15" type="door" state="open" id="0" caption="exit" />
</events>
</JPScore>
......@@ -6,6 +6,7 @@
<seed>12542</seed>
<!-- geometry file -->
<geometry>geo.xml</geometry>
<events>events.xml</events>
<!-- trajectories file and format -->
<trajectories format="xml-plain" embed_mesh="false" fps="8">
<file location="testTrajectories.xml" />
......
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