GeoFileParser.cpp 41.1 KB
Newer Older
GrgrLmml's avatar
GrgrLmml committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/**
 * \section License
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * JuPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 **/
//
// Created by laemmel on 30.03.16.
//

Mohcine Chraibi's avatar
Mohcine Chraibi committed
22
#include <filesystem>
GrgrLmml's avatar
GrgrLmml committed
23 24 25
#include "GeoFileParser.h"
#include "../tinyxml/tinyxml.h"
#include "../geometry/SubRoom.h"
26
#include "../geometry/WaitingArea.h"
Mohcine Chraibi's avatar
Mohcine Chraibi committed
27
namespace fs = std::filesystem;
28 29 30



Arne Graf's avatar
Arne Graf committed
31
GeoFileParser::GeoFileParser(Configuration* configuration)
GrgrLmml's avatar
GrgrLmml committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
          :_configuration(configuration)
{

}

void GeoFileParser::LoadBuilding(Building* building)
{
     //todo: what happens if any of these  methods failed (return false)? throw exception ?
     if (!LoadGeometry(building)) {
          Log->Write("ERROR:\t could not load the geometry!");
          exit(EXIT_FAILURE);
     }

     if (!LoadRoutingInfo(building)) {
          Log->Write("ERROR:\t could not load extra routing information!");
          exit(EXIT_FAILURE);
     }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
49
     if (!LoadTrafficInfo(building)) {
50 51
          Log->Write("ERROR:\t could not load extra traffic information!");
          exit(EXIT_FAILURE);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
52
     }
53 54 55 56 57
     if(!LoadTrainInfo(building))
     {
          Log->Write("ERROR:\t could not load train information!");
          exit(EXIT_FAILURE);
     }
GrgrLmml's avatar
GrgrLmml committed
58 59 60 61 62 63
}

bool GeoFileParser::LoadGeometry(Building* building)
{

     std::string geoFilenameWithPath = _configuration->GetProjectRootDir()+_configuration->GetGeometryFile();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
64
     std::cout << "\nLoadGeometry: file: " << geoFilenameWithPath << "\n";
Mohcine Chraibi's avatar
Mohcine Chraibi committed
65

GrgrLmml's avatar
GrgrLmml committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
     TiXmlDocument docGeo(geoFilenameWithPath);
     if (!docGeo.LoadFile()) {
          Log->Write("ERROR: \t%s", docGeo.ErrorDesc());
          Log->Write("\t could not parse the geometry file");
          return false;
     }

     TiXmlElement* xRootNode = docGeo.RootElement();
     if (!xRootNode) {
          Log->Write("ERROR:\tRoot element does not exist");
          return false;
     }

     if (xRootNode->ValueStr()!="geometry") {
          Log->Write("ERROR:\tRoot element value is not 'geometry'.");
          return false;
     }
     if (xRootNode->Attribute("unit")) if (std::string(xRootNode->Attribute("unit"))!="m") {
          Log->Write("ERROR:\tOnly the unit m (meters) is supported. \n\tYou supplied [%s]",
                    xRootNode->Attribute("unit"));
          return false;
     }

     double version = xmltof(xRootNode->Attribute("version"), -1);

91
     if (version<std::stod(JPS_OLD_VERSION)) {
GrgrLmml's avatar
GrgrLmml committed
92
          Log->Write(" \tWrong geometry version!");
93 94
          Log->Write(" \tOnly version >= %s supported", JPS_OLD_VERSION);
          Log->Write(" \tPlease update the version of your geometry file to %s", JPS_OLD_VERSION);
GrgrLmml's avatar
GrgrLmml committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
          return false;
     }

     building->SetCaption(xmltoa(xRootNode->Attribute("caption"), "virtual building"));

     //processing the rooms node
     TiXmlNode* xRoomsNode = xRootNode->FirstChild("rooms");
     if (!xRoomsNode) {
          Log->Write("ERROR: \tThe geometry should have at least one room and one subroom");
          return false;
     }

     for (TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom;
          xRoom = xRoom->NextSiblingElement("room")) {

          Room* room = new Room();
          //make_unique<Song>

          std::string room_id = xmltoa(xRoom->Attribute("id"), "-1");
          room->SetID(xmltoi(room_id.c_str(), -1));

          std::string caption = "room "+room_id;
          room->SetCaption(
                    xmltoa(xRoom->Attribute("caption"), caption.c_str()));

          double position = xmltof(xRoom->Attribute("zpos"), 0.0);

          //if(position>6.0) position+=50;
          room->SetZPos(position);

          //parsing the subrooms
          //processing the rooms node
          //TiXmlNode*  xSubroomsNode = xRoom->FirstChild("subroom");

          for (TiXmlElement* xSubRoom = xRoom->FirstChildElement("subroom"); xSubRoom;
               xSubRoom = xSubRoom->NextSiblingElement("subroom")) {

132 133 134
//               std::string subroom_id = xmltoa(xSubRoom->Attribute("id"), "-1");
               int subroom_id = xmltoi(xSubRoom->Attribute("id"), -1);

GrgrLmml's avatar
GrgrLmml committed
135 136 137 138 139 140 141 142 143 144 145
               std::string SubroomClosed = xmltoa(xSubRoom->Attribute("closed"), "0");
               std::string type = xmltoa(xSubRoom->Attribute("class"), "subroom");

               //get the equation of the plane if any
               double A_x = xmltof(xSubRoom->Attribute("A_x"), 0.0);
               double B_y = xmltof(xSubRoom->Attribute("B_y"), 0.0);

               // assume either the old "C_z" or the new "C"
               double C_z = xmltof(xSubRoom->Attribute("C_z"), 0.0);
               C_z = xmltof(xSubRoom->Attribute("C"), C_z);

146
               SubRoom* subroom = nullptr;
GrgrLmml's avatar
GrgrLmml committed
147 148

               if (type=="stair" || type=="escalator" || type=="idle_escalator") {
149
                    if (xSubRoom->FirstChildElement("up") == nullptr) {
150
                         Log->Write("ERROR:\t the attribute <up> and <down> are missing for the " + type);
GrgrLmml's avatar
GrgrLmml committed
151 152 153 154 155 156 157 158
                         Log->Write("ERROR:\t check your geometry file");
                         return false;
                    }
                    double up_x = xmltof(xSubRoom->FirstChildElement("up")->Attribute("px"), 0.0);
                    double up_y = xmltof(xSubRoom->FirstChildElement("up")->Attribute("py"), 0.0);
                    double down_x = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                    double down_y = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                    subroom = new Stair();
159 160 161
                    ((Stair *) subroom)->SetUp(Point(up_x, up_y));
                    ((Stair *) subroom)->SetDown(Point(down_x, down_y));
               } else if (type =="escalator_up") {
162
                    if (xSubRoom->FirstChildElement("up") == nullptr) {
163 164 165 166 167 168 169 170 171 172 173 174 175 176
                         Log->Write("ERROR:\t the attribute <up> and <down> are missing for the " + type);
                         Log->Write("ERROR:\t check your geometry file");
                         return false;
                    }
                    double up_x = xmltof(xSubRoom->FirstChildElement("up")->Attribute("px"), 0.0);
                    double up_y = xmltof(xSubRoom->FirstChildElement("up")->Attribute("py"), 0.0);
                    double down_x = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                    double down_y = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                    subroom = new Escalator();
                    ((Escalator *) subroom)->SetUp(Point(up_x, up_y));
                    ((Escalator *) subroom)->SetDown(Point(down_x, down_y));
                    ((Escalator*) subroom)->SetEscalatorUp();
                    _configuration->set_has_directional_escalators(true);
               } else if (type == "escalator_down") {
177
                    if (xSubRoom->FirstChildElement("up") ==nullptr) {
178 179 180 181 182 183 184 185 186 187 188 189 190 191
                         Log->Write("ERROR:\t the attribute <up> and <down> are missing for the " + type);
                         Log->Write("ERROR:\t check your geometry file");
                         return false;
                    }
                    double up_x = xmltof(xSubRoom->FirstChildElement("up")->Attribute("px"), 0.0);
                    double up_y = xmltof(xSubRoom->FirstChildElement("up")->Attribute("py"), 0.0);
                    double down_x = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                    double down_y = xmltof(xSubRoom->FirstChildElement("down")->Attribute("py"), 0.0);
                    subroom = new Escalator();
                    ((Escalator *) subroom)->SetUp(Point(up_x, up_y));
                    ((Escalator *) subroom)->SetDown(Point(down_x, down_y));
                    ((Escalator*) subroom)->SetEscalatorDown();
                    _configuration->set_has_directional_escalators(true);
               } else {
GrgrLmml's avatar
GrgrLmml committed
192 193 194 195 196 197 198
                    //normal subroom or corridor
                    subroom = new NormalSubRoom();
               }

               subroom->SetType(type);
               subroom->SetPlanEquation(A_x, B_y, C_z);
               subroom->SetRoomID(room->GetID());
199
               subroom->SetSubRoomID(subroom_id);
GrgrLmml's avatar
GrgrLmml committed
200 201 202 203 204 205 206

               //static int p_id=1;
               //cout<<endl<<"wall polygon: "<< p_id++<<endl;
               //looking for polygons (walls)
               for (TiXmlElement* xPolyVertices = xSubRoom->FirstChildElement("polygon"); xPolyVertices;
                    xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {

Mohcine Chraibi's avatar
Mohcine Chraibi committed
207
                    std::string wall_type = xmltoa(xPolyVertices->Attribute("type"), "wall");
GrgrLmml's avatar
GrgrLmml committed
208 209 210 211 212 213 214 215 216
                    for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
                              "vertex");
                         xVertex && xVertex!=xPolyVertices->LastChild("vertex");
                         xVertex = xVertex->NextSiblingElement("vertex")) {

                         double x1 = xmltof(xVertex->Attribute("px"));
                         double y1 = xmltof(xVertex->Attribute("py"));
                         double x2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("px"));
                         double y2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("py"));
Mohcine Chraibi's avatar
Mohcine Chraibi committed
217
                         subroom->AddWall(Wall(Point(x1, y1), Point(x2, y2), wall_type));
GrgrLmml's avatar
GrgrLmml committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
                         //printf("%0.2f %0.2f %0.2f %0.2f\n",x1,y1,x2,y2);
                    }

               }

               //looking for obstacles
               for (TiXmlElement* xObstacle = xSubRoom->FirstChildElement("obstacle"); xObstacle;
                    xObstacle = xObstacle->NextSiblingElement("obstacle")) {

                    int id = xmltoi(xObstacle->Attribute("id"), -1);
                    double height = xmltof(xObstacle->Attribute("height"), 0);
                    //double ObstClosed = xmltof(xObstacle->Attribute("closed"), 0);
                    std::string ObstCaption = xmltoa(xObstacle->Attribute("caption"), "-1");

                    Obstacle* obstacle = new Obstacle();
                    obstacle->SetId(id);
                    obstacle->SetCaption(ObstCaption);
                    //obstacle->SetClosed(ObstClosed);
                    obstacle->SetHeight(height);

                    //looking for polygons (walls)
                    for (TiXmlElement* xPolyVertices = xObstacle->FirstChildElement("polygon"); xPolyVertices;
                         xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {

                         for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
                                   "vertex");
                              xVertex && xVertex!=xPolyVertices->LastChild("vertex");
                              xVertex = xVertex->NextSiblingElement("vertex")) {

                              double x1 = xmltof(xVertex->Attribute("px"));
                              double y1 = xmltof(xVertex->Attribute("py"));
                              double x2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("px"));
                              double y2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("py"));
                              obstacle->AddWall(Wall(Point(x1, y1), Point(x2, y2)));
                         }
                    }
                    subroom->AddObstacle(obstacle);
               }
               room->AddSubRoom(subroom);
257

GrgrLmml's avatar
GrgrLmml committed
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
          }
          //parsing the crossings
          TiXmlNode* xCrossingsNode = xRoom->FirstChild("crossings");
          if (xCrossingsNode)
               for (TiXmlElement* xCrossing = xCrossingsNode->FirstChildElement("crossing"); xCrossing;
                    xCrossing = xCrossing->NextSiblingElement("crossing")) {

                    int id = xmltoi(xCrossing->Attribute("id"), -1);
                    int sub1_id = xmltoi(xCrossing->Attribute("subroom1_id"), -1);
                    int sub2_id = xmltoi(xCrossing->Attribute("subroom2_id"), -1);

                    double x1 = xmltof(xCrossing->FirstChildElement("vertex")->Attribute("px"));
                    double y1 = xmltof(xCrossing->FirstChildElement("vertex")->Attribute("py"));
                    double x2 = xmltof(xCrossing->LastChild("vertex")->ToElement()->Attribute("px"));
                    double y2 = xmltof(xCrossing->LastChild("vertex")->ToElement()->Attribute("py"));

                    Crossing* c = new Crossing();
                    c->SetID(id);
                    c->SetPoint1(Point(x1, y1));
                    c->SetPoint2(Point(x2, y2));

                    c->SetSubRoom1(room->GetSubRoom(sub1_id));
                    c->SetSubRoom2(room->GetSubRoom(sub2_id));
                    c->SetRoom1(room);
                    building->AddCrossing(c);

                    room->GetSubRoom(sub1_id)->AddCrossing(c);
                    room->GetSubRoom(sub2_id)->AddCrossing(c);
               }

          building->AddRoom(room);
     }

     // all rooms are read, now proceed with transitions
     TiXmlNode* xTransNode = xRootNode->FirstChild("transitions");
     if (xTransNode)
294
     {
GrgrLmml's avatar
GrgrLmml committed
295 296
          for (TiXmlElement* xTrans = xTransNode->FirstChildElement("transition"); xTrans;
               xTrans = xTrans->NextSiblingElement("transition")) {
297 298 299 300 301 302
               Transition * t = parseTransitionNode(xTrans, building);
               building->AddTransition(t);
          }
          TiXmlNode * xNodeFile = xTransNode->FirstChild("file");
          if(xNodeFile)
          {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
303
               fs::path p(_configuration->GetProjectRootDir());
304
               std::string transFilename = xNodeFile->FirstChild()->ValueStr();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
305 306 307
               p /= transFilename;
               transFilename = p.string();

308 309 310 311 312 313
               Log->Write("INFO:\tParsing transition from file <%s>", transFilename.c_str());
               TiXmlDocument docTrans(transFilename);
               if (!docTrans.LoadFile()) {
                    Log->Write("ERROR: \t%s", docTrans.ErrorDesc());
                    Log->Write("ERROR: \t could not parse the transitions file.");
                    return false;
GrgrLmml's avatar
GrgrLmml committed
314
               }
315 316 317 318
               TiXmlElement* xRootNodeTrans = docTrans.RootElement();
               if (!xRootNodeTrans) {
                    Log->Write("ERROR:\tRoot element does not exist in transitions file.");
                    return false;
GrgrLmml's avatar
GrgrLmml committed
319
               }
320 321 322 323 324 325 326 327 328 329 330 331 332
               if (xRootNodeTrans->ValueStr() != "JPScore") {
                    Log->Write("ERROR:\tParsing transitions file. Root element value is not 'JPScore'.");
                    return false;
               }
               TiXmlNode* xTransNodeFile = xRootNodeTrans->FirstChild("transitions");
               if (!xTransNodeFile) {
                    Log->Write("ERROR:\tNo Transitions in file found.");
                    return false;
               }
               for (TiXmlElement* xTrans = xTransNodeFile->FirstChildElement("transition"); xTrans;
               xTrans = xTrans->NextSiblingElement("transition")) {
                    Transition * t = parseTransitionNode(xTrans, building);
                    building->AddTransition(t);
GrgrLmml's avatar
GrgrLmml committed
333 334
               }
          }
335
          else{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
336
               Log->Write("INFO:\tNot parsing transition from file");
GrgrLmml's avatar
GrgrLmml committed
337
          }
338
          Log->Write("INFO:\tGot %d transitions", building-> GetAllTransitions().size());
GrgrLmml's avatar
GrgrLmml committed
339

340
     }// xTransNode
GrgrLmml's avatar
GrgrLmml committed
341 342 343 344 345 346 347 348
     Log->Write("INFO: \tLoading building file successful!!!\n");

     //everything went fine
     return true;
}

bool GeoFileParser::LoadRoutingInfo(Building* building)
{
tobias schroedter's avatar
tobias schroedter committed
349 350
     //TODO read schedule

GrgrLmml's avatar
GrgrLmml committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
     TiXmlDocument docRouting(_configuration->GetProjectFile());
     if (!docRouting.LoadFile()) {
          Log->Write("ERROR: \t%s", docRouting.ErrorDesc());
          Log->Write("ERROR: \t could not parse the routing file");
          return false;
     }

     TiXmlElement* xRootNode = docRouting.RootElement();
     if (!xRootNode) {
          Log->Write("ERROR:\tRoot element does not exist");
          return false;
     }

     if (!xRootNode->FirstChild("routing")) {
          return true; // no extra routing information
     }

368

GrgrLmml's avatar
GrgrLmml committed
369 370
     //load goals and routes
     TiXmlNode* xGoalsNode = xRootNode->FirstChild("routing")->FirstChild("goals");
371
     if (xGoalsNode) {
372
          // ---- parse goals from inifile
GrgrLmml's avatar
GrgrLmml committed
373 374
          for (TiXmlElement* e = xGoalsNode->FirstChildElement("goal"); e;
               e = e->NextSiblingElement("goal")) {
375
               Goal * goal = parseGoalNode(e);
376 377 378
               if (goal) {
                    building->AddGoal(goal);
                    _configuration->GetRoutingEngine()->AddFinalDestinationID(goal->GetId());
GrgrLmml's avatar
GrgrLmml committed
379 380 381 382
               }

          }

383
          // ---- parse waiting areas from inifile
384 385
          for (TiXmlElement* e = xGoalsNode->FirstChildElement("waiting_area"); e;
               e = e->NextSiblingElement("waiting_area")) {
386
               Goal * goal = parseWaitingAreaNode(e);
387 388 389
               if (goal) {
                    building->AddGoal(goal);
                    _configuration->GetRoutingEngine()->AddFinalDestinationID(goal->GetId());
390
               }
391

392 393
          }
          // ---- parse goals/waiting areas from external file
394 395 396
          TiXmlNode* xGoalsNodeFile = xGoalsNode->FirstChild("file");
          if(xGoalsNodeFile)
          {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
397
               fs::path p(_configuration->GetProjectRootDir());
398
               std::string goalFilename = xGoalsNodeFile->FirstChild()->ValueStr();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
399 400
               p /= goalFilename;
               goalFilename = p.string();
401 402 403 404 405
               Log->Write("INFO:\tGoal file <%s> will be parsed", goalFilename.c_str());
               TiXmlDocument docGoal(goalFilename);
               if (!docGoal.LoadFile()) {
                    Log->Write("ERROR: \t%s", docGoal.ErrorDesc());
                    Log->Write("ERROR: \t could not parse the goal file.");
406 407
                    return false;
               }
408 409 410
               TiXmlElement* xRootNodeGoal = docGoal.RootElement();
               if (!xRootNodeGoal) {
                    Log->Write("ERROR:\tRoot element does not exist in goal file.");
411
                    return false;
412 413 414 415 416 417 418 419 420 421 422 423 424
               }
               if (xRootNodeGoal->ValueStr() != "JPScore") {
                    Log->Write("ERROR:\tParsing goal file. Root element value is not 'JPScore'.");
                    return false;
               }
               TiXmlNode* xGoal = xRootNodeGoal->FirstChild("goals");
               if (!xGoal) {
                    Log->Write("ERROR:\tNo Goals in file found.");
                    return false;
               }
               for (TiXmlElement* e = xGoal->FirstChildElement("goal"); e;
                    e = e->NextSiblingElement("goal")) {
                    Goal * goal = parseGoalNode(e);
425 426 427
                    if (goal) {
                         building->AddGoal(goal);
                         _configuration->GetRoutingEngine()->AddFinalDestinationID(goal->GetId());
428 429 430
                    }
               }

431 432 433
               for (TiXmlElement* e = xGoal->FirstChildElement("waiting_area"); e;
                    e = e->NextSiblingElement("waiting_area")) {
                    Goal * goal = parseWaitingAreaNode(e);
434 435 436 437
                    if (goal) {
                         building->AddGoal(goal);
                         _configuration->GetRoutingEngine()->AddFinalDestinationID(goal->GetId());
                    }
438 439
               }

440

tobias schroedter's avatar
tobias schroedter committed
441
          }
442 443 444
          else
               Log->Write("INFO:\tGoal file not parsed");
     } //xgoalsNode
445

GrgrLmml's avatar
GrgrLmml committed
446 447 448
     Log->Write("INFO:\tdone with loading extra routing information");
     return true;
}
449

450 451 452 453 454 455 456 457 458
bool GeoFileParser::parseDoorNode(TiXmlElement * xDoor, int id, Building* building)
{
     bool result = false;// this return value is not needed.
                         // maybe in the future it might be...
     std::string str("INFO:\tParsed Door: \n");
     char tmp[100];
     sprintf(tmp, "\t>> ID: %d\n", id);
     str.append(tmp);
     //------------------ state
tobias schroedter's avatar
tobias schroedter committed
459 460 461 462 463
     std::string stateStr = xmltoa(xDoor->Attribute("state"), "open");
     DoorState state = StringToDoorState(stateStr);
     //store transition in a map and call getTransition/getCrossing
     switch (state) {
     case DoorState::OPEN:
464
          building->GetTransition(id)->Open();
tobias schroedter's avatar
tobias schroedter committed
465 466
          break;
     case DoorState::CLOSE:
467
          building->GetTransition(id)->Close();
tobias schroedter's avatar
tobias schroedter committed
468 469 470 471
          break;
     case DoorState::TEMP_CLOSE:
          building->GetTransition(id)->TempClose();
          break;
qiancheng xu's avatar
qiancheng xu committed
472
     case DoorState::Error:
Mohcine Chraibi's avatar
Mohcine Chraibi committed
473
          Log->Write("WARNING:\t Unknown door state: <%s>. open, close or temp_close. Default: open",
tobias schroedter's avatar
tobias schroedter committed
474 475 476
                    stateStr.c_str());
          building->GetTransition(id)->Open();
          break;
477
     }
tobias schroedter's avatar
tobias schroedter committed
478

tobias schroedter's avatar
tobias schroedter committed
479
     sprintf(tmp, "\t>> state: %s\n", stateStr.c_str());
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
     str.append(tmp);
     //------------------ outflow
     double outflow = xmltof(xDoor->Attribute("outflow"), -1.0);
     if(outflow >= 0)
     {
          building->GetTransition(id)->SetOutflowRate(outflow);
          sprintf(tmp, "\t>> ouflow: %.2f\n", outflow);
          str.append(tmp);
     }
     //----------------- dt
     double DT = xmltof(xDoor->Attribute("dt"), -1.0);
     if(DT >= 0)
     {
          building->GetTransition(id)->SetDT(DT);
     }
     //----------------- dn
     int DN = xmltof(xDoor->Attribute("dn"), -1.0);
     if(DN >= 0)
     {
          building->GetTransition(id)->SetDN(DN);
          sprintf(tmp, "\t>> dn: %d\n", DN);
          str.append(tmp);
502 503
     }

504 505 506 507 508 509 510 511 512 513 514 515
     //------------------ max door usage
     int mdu = xmltof(xDoor->Attribute("max_agents"), -1);
     if(mdu >= 0)
     {
          building->GetTransition(id)->SetMaxDoorUsage(mdu);
          sprintf(tmp, "\t>> max_agents: %d\n", mdu);
          str.append(tmp);
     }
     //-----------------
     Log->Write(str);
     result = true;
     return result;
GrgrLmml's avatar
GrgrLmml committed
516 517 518 519 520
}

bool GeoFileParser::LoadTrafficInfo(Building* building)
{

521
     Log->Write("INFO:\tLoading the traffic info");
GrgrLmml's avatar
GrgrLmml committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

     TiXmlDocument doc(_configuration->GetProjectFile());
     if (!doc.LoadFile()) {
          Log->Write("ERROR: \t%s", doc.ErrorDesc());
          Log->Write("ERROR: \t could not parse the project file");
          return false;
     }

     TiXmlNode* xRootNode = doc.RootElement()->FirstChild("traffic_constraints");
     if (!xRootNode) {
          Log->Write("WARNING:\tcould not find any traffic information");
          return true;
     }

     //processing the rooms node
     TiXmlNode* xRoomsNode = xRootNode->FirstChild("rooms");
     if (xRoomsNode)
          for (TiXmlElement* xRoom = xRoomsNode->FirstChildElement("room"); xRoom;
               xRoom = xRoom->NextSiblingElement("room")) {

               double id = xmltof(xRoom->Attribute("room_id"), -1);
               std::string state = xmltoa(xRoom->Attribute("state"), "good");
               RoomState status = (state=="good") ? ROOM_CLEAN : ROOM_SMOKED;
               building->GetRoom(id)->SetState(status);
          }
547 548
     else
          Log->Write("Info:\t  no room info found in inifile");
GrgrLmml's avatar
GrgrLmml committed
549 550 551

     //processing the doors node
     TiXmlNode* xDoorsNode = xRootNode->FirstChild("doors");
552 553 554
     if(xDoorsNode)
     {
          bool res_parseDoor;
GrgrLmml's avatar
GrgrLmml committed
555 556 557
          for (TiXmlElement* xDoor = xDoorsNode->FirstChildElement("door"); xDoor;
               xDoor = xDoor->NextSiblingElement("door")) {
               int id = xmltoi(xDoor->Attribute("trans_id"), -1);
558
               if (id!=-1 && building->GetTransition(id)) {
559 560 561
                    res_parseDoor = parseDoorNode(xDoor, id, building);
                    if(!res_parseDoor)
                         return false;
GrgrLmml's avatar
GrgrLmml committed
562
               }
563 564
          }//for xDoor
     }
565 566 567 568 569 570
     else
          Log->Write("Info:\t  no door info found in inifile");
     // processing file node
     TiXmlNode* xFileNode = xRootNode->FirstChild("file");
     if(xFileNode)
     {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
571
          fs::path p(_configuration->GetProjectRootDir());
572
          std::string trafficFilename = xFileNode->FirstChild()->ValueStr();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
573 574
          p /= trafficFilename;
          trafficFilename = p.string();
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
          Log->Write("Info:\t  traffic file found <%s>", trafficFilename.c_str());
          TiXmlDocument docTraffic(trafficFilename);
          if (!docTraffic.LoadFile()) {
               Log->Write("ERROR: \t%s", docTraffic.ErrorDesc());
               Log->Write("ERROR: \t could not parse the traffic file.");
               return false;
          }
          TiXmlElement* xRootNodeTraffic = docTraffic.RootElement();
          if (!xRootNodeTraffic) {
               Log->Write("ERROR:\tRoot element does not exist.");
               return false;
          }

          if (xRootNodeTraffic->ValueStr() != "JPScore") {
               Log->Write("ERROR:\tRoot element value is not 'JPScore'.");
               return false;
          }
          TiXmlNode* xTraffic = xRootNodeTraffic->FirstChild("traffic_constraints");
          if (!xTraffic) {
               Log->Write("ERROR:\tNo traffic constraints in file found.");
               return false;
          }
          TiXmlNode* xDoorsNodeF = xTraffic->FirstChild("doors");
          if(xDoorsNodeF)
          {
               bool res_parseDoor;
               for (TiXmlElement* xDoor = xDoorsNodeF->FirstChildElement("door"); xDoor;
                    xDoor = xDoor->NextSiblingElement("door")) {
                    int id = xmltoi(xDoor->Attribute("trans_id"), -1);
                    if (id!=-1 && building->GetTransition(id)) {
                         res_parseDoor = parseDoorNode(xDoor, id, building);
                         if(!res_parseDoor)
                              return false;
GrgrLmml's avatar
GrgrLmml committed
608
                    }
609
               }//for xDoor
GrgrLmml's avatar
GrgrLmml committed
610
          }
611 612 613 614 615 616
          else
               Log->Write("Info:\t  no door info found in traffic file");
     }
     else
          Log->Write("Info:\t  no traffic file found.");

GrgrLmml's avatar
GrgrLmml committed
617 618 619 620
     Log->Write("INFO:\tDone with loading traffic info file");
     return true;
}

621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
Transition* GeoFileParser::parseTransitionNode(TiXmlElement * xTrans, Building * building)
{
     int id = xmltoi(xTrans->Attribute("id"), -1);
     // string caption = "door " + id;
     std::string caption = "door ";
     caption += std::to_string(id);
     caption = xmltoa(xTrans->Attribute("caption"), caption.c_str());
     int room1_id = xmltoi(xTrans->Attribute("room1_id"), -1);
     int room2_id = xmltoi(xTrans->Attribute("room2_id"), -1);
     int subroom1_id = xmltoi(xTrans->Attribute("subroom1_id"), -1);
     int subroom2_id = xmltoi(xTrans->Attribute("subroom2_id"), -1);
     std::string type = xmltoa(xTrans->Attribute("type"), "normal");

     double x1 = xmltof(xTrans->FirstChildElement("vertex")->Attribute("px"));
     double y1 = xmltof(xTrans->FirstChildElement("vertex")->Attribute("py"));

     double x2 = xmltof(xTrans->LastChild("vertex")->ToElement()->Attribute("px"));
     double y2 = xmltof(xTrans->LastChild("vertex")->ToElement()->Attribute("py"));

     Transition* t = new Transition();
     t->SetID(id);
     t->SetCaption(caption);
     t->SetPoint1(Point(x1, y1));
     t->SetPoint2(Point(x2, y2));
     t->SetType(type);
     //--- danger area
     if (room1_id!=-1 && subroom1_id!=-1) {
          //Room* room = _rooms[room1_id];
          Room* room = building->GetRoom(room1_id);
          SubRoom* subroom = room->GetSubRoom(subroom1_id);

          //subroom->AddGoalID(t->GetUniqueID());
          //MPI
          room->AddTransitionID(t->GetUniqueID());
          t->SetRoom1(room);
          t->SetSubRoom1(subroom);

          //new implementation
          subroom->AddTransition(t);
     }
     if (room2_id!=-1 && subroom2_id!=-1) {
          Room* room = building->GetRoom(room2_id);
          SubRoom* subroom = room->GetSubRoom(subroom2_id);
          //subroom->AddGoalID(t->GetUniqueID());
          //MPI
          room->AddTransitionID(t->GetUniqueID());
          t->SetRoom2(room);
          t->SetSubRoom2(subroom);

          //new implementation
          subroom->AddTransition(t);
     }
     return t;
}
675

676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
Goal* GeoFileParser::parseGoalNode(TiXmlElement * e)
{
     Log->Write("INFO:\tLoading goal");
     int id = xmltoi(e->Attribute("id"), -1);
     int isFinal = std::string(e->Attribute("final"))=="true" ? true : false;
     std::string caption = xmltoa(e->Attribute("caption"), "-1");
     int room_id = xmltoi(e->Attribute("room_id"), -1);
     int subroom_id = xmltoi(e->Attribute("subroom_id"), -1);
     Log->Write("INFO:\t  Goal id: %d", id);
     Log->Write("INFO:\t  Goal caption: %s", caption.c_str());
     Log->Write("INFO:\t  Goal room_id: %d", room_id);
     Log->Write("INFO:\t  Goal subroom_id: %d", subroom_id);
     Goal* goal = new Goal();
     goal->SetId(id);
     goal->SetCaption(caption);
     goal->SetIsFinalGoal(isFinal);
     goal->SetRoomID(room_id);
     goal->SetSubRoomID(subroom_id);

     //looking for polygons (walls)
     for (TiXmlElement* xPolyVertices = e->FirstChildElement("polygon"); xPolyVertices;
          xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {

          for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
                    "vertex");
               xVertex && xVertex!=xPolyVertices->LastChild("vertex");
               xVertex = xVertex->NextSiblingElement("vertex")) {

               double x1 = xmltof(xVertex->Attribute("px"));
               double y1 = xmltof(xVertex->Attribute("py"));
               double x2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("px"));
               double y2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("py"));
               goal->AddWall(Wall(Point(x1, y1), Point(x2, y2)));
          }
     }

     if (!goal->ConvertLineToPoly())
     {
          Log->Write("ERROR:\t parsing polygon of goal %d", id);
          return nullptr;
     }
     Log->Write("INFO:\t  finished parsing goal %d", id);
     return goal;
}

721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
Goal* GeoFileParser::parseWaitingAreaNode(TiXmlElement * e)
{
     Log->Write("INFO:\tLoading Waiting Area");
     int id = xmltoi(e->Attribute("id"), -1);
     int min_peds = xmltoi(e->Attribute("min_peds"), -1);
     int max_peds = xmltoi(e->Attribute("max_peds"), -1);
     int waiting_time = xmltoi(e->Attribute("waiting_time"), -1);
     int transition_id = xmltoi(e->Attribute("transition_id"), -1);
     int room_id = xmltoi(e->Attribute("room_id"), -1);
     int subroom_id = xmltoi(e->Attribute("subroom_id"), -1);
     bool open = strcmp(xmltoa(e->Attribute("is_open"), "false"), "true") == 0;
     bool global_timer = strcmp(xmltoa(e->Attribute("global_timer"), "false"), "true") == 0;

     std::string caption = xmltoa(e->Attribute("caption"), "-1");

     Log->Write("INFO:\t  Goal id: %d", id);
     Log->Write("INFO:\t  Goal caption: %s", caption.c_str());
     Log->Write("INFO:\t  Goal room_id: %d", room_id);
     Log->Write("INFO:\t  Goal subroom_id: %d", subroom_id);

     Goal* wa = new WaitingArea();
     WaitingArea* waitingArea = static_cast<WaitingArea*>(wa);
     waitingArea->SetIsFinalGoal(0);
     waitingArea->SetId(id);
     waitingArea->SetCaption(caption);
     waitingArea->setOpen(open);
     waitingArea->setGlobalTimer(global_timer);
     waitingArea->setMinNumPed(min_peds);
     waitingArea->setMaxNumPed(max_peds);
     waitingArea->setWaitingTime(waiting_time);
     waitingArea->setTransitionID(transition_id);
     waitingArea->SetRoomID(room_id);
     waitingArea->SetSubRoomID(subroom_id);

     std::map<int, double> nextGoals;


     //looking for next_wa
     for (TiXmlElement* nextWa = e->FirstChildElement("next_wa"); nextWa;
          nextWa = nextWa->NextSiblingElement("next_wa")) {
          int nextWaId = xmltoi(nextWa->Attribute("id"));
          double nextWaP = xmltof(nextWa->Attribute("p"));

          nextGoals.insert(std::pair<int, double>(nextWaId, nextWaP));
     }

     if (!waitingArea->setNextGoals(nextGoals)){
768 769
          Log->Write("ERROR:\t  check probabilties of next goal of WA  %d", id);
          return nullptr;
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
     };


     //looking for polygons (walls)
     for (TiXmlElement* xPolyVertices = e->FirstChildElement("polygon"); xPolyVertices;
          xPolyVertices = xPolyVertices->NextSiblingElement("polygon")) {

          for (TiXmlElement* xVertex = xPolyVertices->FirstChildElement(
                    "vertex");
               xVertex && xVertex!=xPolyVertices->LastChild("vertex");
               xVertex = xVertex->NextSiblingElement("vertex")) {

               double x1 = xmltof(xVertex->Attribute("px"));
               double y1 = xmltof(xVertex->Attribute("py"));
               double x2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("px"));
               double y2 = xmltof(xVertex->NextSiblingElement("vertex")->Attribute("py"));
               wa->AddWall(Wall(Point(x1, y1), Point(x2, y2)));
          }
     }

     if (!waitingArea->ConvertLineToPoly()){
791 792
          Log->Write("ERROR:\t   parsing polygon of waiting area %d", id);
          return nullptr;
793 794
     }

795 796
     Log->Write("INFO:\t  finished parsing waiting area %d", id);

797 798 799
     return wa;
}

800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
bool GeoFileParser::LoadTrainInfo(Building* building)
{
     Log->Write("--------\nINFO:\tLoading the train info");

     TiXmlDocument doc(_configuration->GetProjectFile());
     if (!doc.LoadFile()) {
          Log->Write("ERROR: \t%s", doc.ErrorDesc());
          Log->Write("ERROR: \t could not parse the project file");
          return false;
     }
     TiXmlElement* xRootNode = doc.RootElement();
     if (!xRootNode) {
          Log->Write("ERROR:\tRoot element does not exist");
          return false;
     }
     if (!xRootNode->FirstChild("train_constraints")) {
          Log->Write("WARNING:\tNo train constraints were found. Continue.");
     }
818 819 820 821 822 823 824
     bool resTTT = true;
     bool resType = true;
     if(xRootNode->FirstChild("train_constraints"))
     {
          resTTT = LoadTrainTimetable(building, xRootNode);
          resType = LoadTrainType(building, xRootNode);
     }
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
     return (resTTT && resType);
}
bool GeoFileParser::LoadTrainTimetable(Building* building, TiXmlElement * xRootNode)
{
     TiXmlNode* xTTTNode = xRootNode->FirstChild("train_constraints")->FirstChild("train_time_table");
     std::string TTTFilename;
     if(xTTTNode)
     {
          fs::path p(_configuration->GetProjectRootDir());
          TTTFilename = xTTTNode->FirstChild()->ValueStr();
          p /= TTTFilename;
          TTTFilename = p.string();
          Log->Write("INFO:\tTrain Timetable file <%s> will be parsed", TTTFilename.c_str());
     }
     else return true;


     TiXmlDocument docTTT(TTTFilename);
     if (!docTTT.LoadFile()) {
          Log->Write("ERROR: \t%s", docTTT.ErrorDesc());
          Log->Write("ERROR: \t could not parse the train timetable file.");
          return false;
     }
     TiXmlElement* xTTT = docTTT.RootElement();
     if (!xTTT) {
          Log->Write("ERROR:\tRoot element does not exist in TTT file.");
          return false;
     }
     if (xTTT->ValueStr() != "train_time_table") {
          Log->Write("ERROR:\tParsing train timetable file. Root element value is not 'train_time_table'.");
          return false;
     }
     for (TiXmlElement* e = xTTT->FirstChildElement("train"); e;
                    e = e->NextSiblingElement("train")) {
859
          std::shared_ptr<TrainTimeTable> TTT = parseTrainTimeTableNode(e);
860

861 862
          if (TTT) { // todo: maybe get pointer to train
               building->AddTrainTimeTable(TTT);
863 864
          }
     }
865
     return true;
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
}
bool GeoFileParser::LoadTrainType(Building* building, TiXmlElement * xRootNode)
{
     TiXmlNode* xTTNode = xRootNode->FirstChild("train_constraints")->FirstChild("train_types");
     std::string TTFilename;
     if(xTTNode)
     {
          fs::path p(_configuration->GetProjectRootDir());
          TTFilename = xTTNode->FirstChild()->ValueStr();
          p /= TTFilename;
          TTFilename = p.string();
          Log->Write("INFO:\tTrain Type file <%s> will be parsed", TTFilename.c_str());
     }
     else return true;


     TiXmlDocument docTT(TTFilename);
     if (!docTT.LoadFile()) {
          Log->Write("ERROR: \t%s", docTT.ErrorDesc());
          Log->Write("ERROR: \t could not parse the train type file.");
          return false;
     }
     TiXmlElement* xTT = docTT.RootElement();
     if (!xTT) {
          Log->Write("ERROR:\tRoot element does not exist in TT file.");
          return false;
     }
     if (xTT->ValueStr() != "train_type") {
          Log->Write("ERROR:\tParsing train type file. Root element value is not 'train_type'.");
          return false;
     }
     for (TiXmlElement* e = xTT->FirstChildElement("train"); e;
                    e = e->NextSiblingElement("train")) {
899 900 901
          std::shared_ptr<TrainType> TT = parseTrainTypeNode(e);
          if (TT) {
               building->AddTrainType(TT);
902 903 904 905 906
          }
     }
     return true;

}
907 908

std::shared_ptr<TrainTimeTable> GeoFileParser::parseTrainTimeTableNode(TiXmlElement * e)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
909
{
910
     Log->Write("INFO:\tLoading train time table NODE");
Mohcine Chraibi's avatar
Mohcine Chraibi committed
911 912 913 914
     std::string caption = xmltoa(e->Attribute("caption"), "-1");
     int id = xmltoi(e->Attribute("id"), -1);
     std::string type = xmltoa(e->Attribute("type"), "-1");
     int room_id = xmltoi(e->Attribute("room_id"), -1);
915
     int subroom_id = xmltoi(e->Attribute("subroom_id"), -1);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
916
     int platform_id = xmltoi(e->Attribute("platform_id"), -1);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
917 918 919 920 921 922 923 924 925 926 927 928
     float track_start_x = xmltof(e->Attribute("track_start_x"), -1);
     float track_start_y = xmltof(e->Attribute("track_start_y"), -1);
     float track_end_x = xmltof(e->Attribute("track_end_x"), -1);
     float track_end_y = xmltof(e->Attribute("track_end_y"), -1);

     float train_start_x = xmltof(e->Attribute("train_start_x"),-1);
     float train_start_y = xmltof(e->Attribute("train_start_y"), -1);
     float train_end_x = xmltof(e->Attribute("train_end_x"), -1);
     float train_end_y = xmltof(e->Attribute("train_end_y"), -1);

     float arrival_time = xmltof(e->Attribute("arrival_time"), -1);
     float departure_time = xmltof(e->Attribute("departure_time"), -1);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
929
     // @todo: check these values for correctness e.g. arrival < departure
Mohcine Chraibi's avatar
Mohcine Chraibi committed
930 931 932 933
     Log->Write("INFO:\tTrain time table:");
     Log->Write("INFO:\t   id: %d", id);
     Log->Write("INFO:\t   type: %s", type.c_str());
     Log->Write("INFO:\t   room_id: %d", room_id);
934
     Log->Write("INFO:\t   subroom_id: %d", subroom_id);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
935
     Log->Write("INFO:\t   platform_id: %d", platform_id);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
936 937
     Log->Write("INFO:\t   track_start: [%.2f, %.2f]", track_start_x, track_start_y);
     Log->Write("INFO:\t   track_end: [%.2f, %.2f]", track_end_x, track_end_y);
938 939
     Log->Write("INFO:\t   arrival_time: %.2f", arrival_time);
     Log->Write("INFO:\t   departure_time: %.2f", departure_time);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
940 941 942 943
     Point track_start(track_start_x, track_start_y);
     Point track_end(track_end_x, track_end_y);
     Point train_start(train_start_x, train_start_y);
     Point train_end(train_end_x, train_end_y);
944 945 946 947 948
     std::shared_ptr<TrainTimeTable> trainTimeTab = std::make_shared<TrainTimeTable>(
          TrainTimeTable{
                    id,
                    type,
                    room_id,
949
                    subroom_id,
950 951 952 953 954 955
                    arrival_time,
                    departure_time,
                    track_start,
                    track_end,
                    train_start,
                    train_end,
Mohcine Chraibi's avatar
Mohcine Chraibi committed
956
                    platform_id,
Mohcine Chraibi's avatar
Mohcine Chraibi committed
957 958
                    false,
                    false,
959 960 961
                    });

     return trainTimeTab;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
962 963
}

964
std::shared_ptr<TrainType> GeoFileParser::parseTrainTypeNode(TiXmlElement * e)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
965 966 967 968 969
{
     Log->Write("INFO:\tLoading train type");
     // int T_id = xmltoi(e->Attribute("id"), -1);
     std::string type = xmltoa(e->Attribute("type"), "-1");
     int agents_max = xmltoi(e->Attribute("agents_max"), -1);
970
     float length = xmltof(e->Attribute("length"), -1);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
971 972 973 974 975 976 977
     // std::shared_ptr<Transition> t = new Transition();
     // std::shared_ptr<Transition> doors;
     Transition t;
     std::vector<Transition> doors;

     for (TiXmlElement* xDoor = e->FirstChildElement("door"); xDoor;
          xDoor = xDoor->NextSiblingElement("door")) {
978 979 980 981 982
          int D_id = xmltoi(xDoor->Attribute("id"), -1);
          float x1 = xmltof(xDoor->FirstChildElement("vertex")->Attribute("px"), -1);
          float y1 = xmltof(xDoor->FirstChildElement("vertex")->Attribute("py"), -1);
          float x2 = xmltof(xDoor->LastChild("vertex")->ToElement()->Attribute("px"), -1);
          float y2 = xmltof(xDoor->LastChild("vertex")->ToElement()->Attribute("py"), -1);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
983 984
          Point start(x1, y1);
          Point end(x2, y2);
985 986
          float outflow = xmltof(xDoor->Attribute("outflow"), -1);
          float dn = xmltoi(xDoor->Attribute("dn"), -1);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
987 988 989 990
          t.SetID(D_id);
          t.SetCaption(type + std::to_string(D_id));
          t.SetPoint1(start);
          t.SetPoint2(end);
991 992
          t.SetOutflowRate(outflow);
          t.SetDN(dn);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
993 994 995
          doors.push_back(t);
     }
     Log->Write("INFO:\t   type: %s", type.c_str());
996 997
     Log->Write("INFO:\t   capacity: %d", agents_max);
     Log->Write("INFO:\t   number of doors: %d", doors.size());
998 999 1000 1001
     for(auto d: doors)
     {
          Log->Write("INFO\t      door (%d): %s | %s", d.GetID(), d.GetPoint1().toString().c_str(), d.GetPoint2().toString().c_str());
     }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1002

1003 1004 1005 1006
     std::shared_ptr<TrainType> Type = std::make_shared<TrainType>(
          TrainType{
                    type,
                    agents_max,
1007
                    length,
1008 1009
                    doors,
                    });
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1010 1011 1012
   return Type;

}
1013

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1014 1015 1016 1017
GeoFileParser::~GeoFileParser()
{

}