SUMO - Simulation of Urban MObility
NIVissimSingleTypeParser_Verbindungsdefinition.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00008 //
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <iostream>
00033 #include <utils/geom/PositionVector.h>
00034 #include <utils/common/TplConvert.h>
00035 #include "../NIImporter_Vissim.h"
00036 #include "../tempstructs/NIVissimConnection.h"
00037 #include "NIVissimSingleTypeParser_Verbindungsdefinition.h"
00038 
00039 #ifdef CHECK_MEMORY_LEAKS
00040 #include <foreign/nvwa/debug_new.h>
00041 #endif // CHECK_MEMORY_LEAKS
00042 
00043 
00044 // ===========================================================================
00045 // method definitions
00046 // ===========================================================================
00047 NIVissimSingleTypeParser_Verbindungsdefinition::NIVissimSingleTypeParser_Verbindungsdefinition(NIImporter_Vissim& parent)
00048     : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
00049 
00050 
00051 NIVissimSingleTypeParser_Verbindungsdefinition::~NIVissimSingleTypeParser_Verbindungsdefinition() {}
00052 
00053 
00054 bool
00055 NIVissimSingleTypeParser_Verbindungsdefinition::parse(std::istream& from) {
00056     int id;
00057     from >> id; // type-checking is missing!
00058     std::string tag;
00059     // Read optional value "Name", skip optional value "Beschriftung"
00060     std::string name;
00061     while (tag != "von") {
00062         tag = overrideOptionalLabel(from);
00063         if (tag == "name") {
00064             name = readName(from);
00065         }
00066     }
00067     // Read the geometry information
00068     NIVissimExtendedEdgePoint from_def = readExtEdgePointDef(from);
00069     PositionVector geom;
00070     tag = myRead(from); // "ueber"
00071     while (tag != "nach") {
00072         std::string x = myRead(from);
00073         std::string y = myRead(from);
00074         if (y != "nach") {
00075             geom.push_back_noDoublePos(
00076                 Position(
00077                     TplConvert<char>::_2SUMOReal(x.c_str()),
00078                     TplConvert<char>::_2SUMOReal(y.c_str())
00079                 ));
00080             tag = myRead(from);
00081             try {
00082                 TplConvert<char>::_2SUMOReal(tag.c_str());
00083                 tag = myRead(from);
00084             } catch (NumberFormatException&) {}
00085         } else {
00086             tag = y;
00087         }
00088     }
00089     NIVissimExtendedEdgePoint to_def = readExtEdgePointDef(from);
00090     // read some optional values until mandatory "Fahrzeugklassen" occurs
00091     SUMOReal dxnothalt = 0;
00092     SUMOReal dxeinordnen = 0;
00093     SUMOReal zuschlag1, zuschlag2;
00094     zuschlag1 = zuschlag2 = 0;
00095     SUMOReal seglength = 0;
00096     tag = myRead(from);
00097     NIVissimConnection::Direction direction = NIVissimConnection::NIVC_DIR_ALL;
00098     while (tag != "fahrzeugklassen" && tag != "sperrung" && tag != "auswertung" && tag != "DATAEND") {
00099         if (tag == "rechts") {
00100             direction = NIVissimConnection::NIVC_DIR_RIGHT;
00101         } else if (tag == "links") {
00102             direction = NIVissimConnection::NIVC_DIR_LEFT;
00103         } else if (tag == "alle") {
00104             direction = NIVissimConnection::NIVC_DIR_ALL;
00105         } else if (tag == "dxnothalt") {
00106             from >> dxnothalt; // type-checking is missing!
00107         } else if (tag == "dxeinordnen") {
00108             from >> dxeinordnen; // type-checking is missing!
00109         } else if (tag == "segment") {
00110             from >> tag;
00111             from >> seglength;
00112         }
00113         if (tag == "zuschlag") {
00114             from >> zuschlag1; // type-checking is missing!
00115             tag = readEndSecure(from);
00116             if (tag == "zuschlag") {
00117                 from >> zuschlag2; // type-checking is missing!
00118                 tag = readEndSecure(from, "auswertung");
00119             }
00120         } else {
00121             tag = readEndSecure(from, "auswertung");
00122         }
00123     }
00124     // read in allowed vehicle classes
00125     std::vector<int> assignedVehicles;
00126     if (tag == "fahrzeugklassen") {
00127         tag = readEndSecure(from);
00128         while (tag != "DATAEND" && tag != "sperrung" && tag != "auswertung") {
00129             int classes = TplConvert<char>::_2int(tag.c_str());
00130             assignedVehicles.push_back(classes);
00131             tag = readEndSecure(from, "auswertung");
00132         }
00133     }
00134     // Read definitions of closed lanes
00135     NIVissimClosedLanesVector clv;
00136     if (tag != "DATAEND") {
00137         do {
00138             // check whether a next close lane definition can be found
00139             tag = readEndSecure(from);
00140             if (tag == "keinspurwechsel") {
00141                 while (tag != "DATAEND") {
00142                     tag = readEndSecure(from);
00143                 }
00144             } else if (tag == "spur") {
00145                 // get the lane number
00146 //                from >> tag;
00147                 int laneNo;
00148                 from >> laneNo; // type-checking is missing!
00149                 // get the list of assigned car classes
00150                 std::vector<int> assignedVehicles;
00151                 tag = myRead(from);
00152                 if (tag == "fahrzeugklassen") {
00153                     tag = myRead(from);
00154                 }
00155                 while (tag != "DATAEND" && tag != "spur" && tag != "keinspurwechsel") {
00156                     int classes = TplConvert<char>::_2int(tag.c_str());
00157                     assignedVehicles.push_back(classes);
00158                     tag = readEndSecure(from);
00159                 }
00160                 // build and add the definition
00161                 NIVissimClosedLaneDef* cld = new NIVissimClosedLaneDef(laneNo, assignedVehicles);
00162                 clv.push_back(cld);
00163             }
00164         } while (tag != "DATAEND");
00165     }
00166     NIVissimConnection* c = new NIVissimConnection(id, name, from_def, to_def, geom,
00167             direction, dxnothalt, dxeinordnen, zuschlag1, zuschlag2, seglength,
00168             assignedVehicles, clv);
00169 
00170     if (!NIVissimConnection::dictionary(id, c)) {
00171         return false;
00172     }
00173     return true;
00174     //return NIVissimAbstractEdge::dictionary(id, c);
00175 }
00176 
00177 
00178 
00179 /****************************************************************************/
00180 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines