1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file NIVissimSingleTypeParser_Signalgruppendefinition.cpp
11 /// @author Daniel Krajzewicz
12 /// @author Jakob Erdmann
13 /// @author Michael Behrisch
14 /// @date Wed, 18 Dec 2002
15 /// @version $Id$
16 ///
17 //
18 /****************************************************************************/
19
20
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25
26 #include <cassert>
27 #include <iostream>
28 #include <utils/common/StringUtils.h>
29 #include <utils/common/ToString.h>
30 #include <utils/common/MsgHandler.h>
31 #include <utils/common/VectorHelper.h>
32 #include "../NIImporter_Vissim.h"
33 #include "../tempstructs/NIVissimTL.h"
34 #include "NIVissimSingleTypeParser_Signalgruppendefinition.h"
35
36
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
NIVissimSingleTypeParser_Signalgruppendefinition(NIImporter_Vissim & parent)40 NIVissimSingleTypeParser_Signalgruppendefinition::NIVissimSingleTypeParser_Signalgruppendefinition(NIImporter_Vissim& parent)
41 : NIImporter_Vissim::VissimSingleTypeParser(parent) {}
42
43
~NIVissimSingleTypeParser_Signalgruppendefinition()44 NIVissimSingleTypeParser_Signalgruppendefinition::~NIVissimSingleTypeParser_Signalgruppendefinition() {}
45
46
47 bool
parse(std::istream & from)48 NIVissimSingleTypeParser_Signalgruppendefinition::parse(std::istream& from) {
49 //
50 int id;
51 from >> id; // type-checking is missing!
52 //
53 std::string tag;
54 tag = myRead(from);
55 std::string name;
56 if (tag == "name") {
57 name = readName(from);
58 tag = myRead(from);
59 }
60 //
61 int lsaid;
62 from >> lsaid;
63 NIVissimTL* tl = NIVissimTL::dictionary(lsaid);
64 if (tl == nullptr) {
65 WRITE_ERROR("A traffic light group with an unknown traffic light occurred.\n Group-ID: " + toString<int>(id)
66 + "\n TrafficLight-ID: " + toString<int>(lsaid));
67 return false;
68 }
69 std::string type = tl->getType();
70 if (type == "festzeit") {
71 return parseFixedTime(id, name, lsaid, from);
72 }
73 if (type == "festzeit_fake") {
74 return parseFixedTime(id, name, lsaid, from);
75 // return parseExternFixedTime(id, name, lsaid, from);
76 }
77 if (type == "vas") {
78 return parseVAS(id, name, lsaid, from);
79 }
80 if (type == "vsplus") {
81 return parseVSPLUS(id, name, lsaid, from);
82 }
83 if (type == "trends") {
84 return parseTRENDS(id, name, lsaid, from);
85 }
86 if (type == "vap") {
87 return parseVAP(id, name, lsaid, from);
88 }
89 if (type == "tl") {
90 return parseTL(id, name, lsaid, from);
91 }
92 if (type == "pos") {
93 return parsePOS(id, name, lsaid, from);
94 }
95 WRITE_WARNING("Unsupported LSA-Type '" + type + "' occurred.");
96 return true;
97 }
98
99
100 bool
parseFixedTime(int id,const std::string & name,int lsaid,std::istream & from)101 NIVissimSingleTypeParser_Signalgruppendefinition::parseFixedTime(
102 int id, const std::string& name, int lsaid, std::istream& from) {
103 //
104 bool isGreenBegin;
105 std::vector<double> times;
106 std::string tag = myRead(from);
107 if (tag == "dauergruen") {
108 isGreenBegin = true;
109 from >> tag;
110 } else if (tag == "dauerrot") {
111 isGreenBegin = false;
112 from >> tag;
113 } else {
114 // the first phase will be green
115 isGreenBegin = true;
116 while (tag == "rotende" || tag == "gruenanfang") {
117 double point;
118 from >> point; // type-checking is missing!
119 times.push_back(point);
120 from >> tag;
121 from >> point; // type-checking is missing!
122 times.push_back(point);
123 tag = myRead(from);
124 }
125 }
126 //
127 double tredyellow, tyellow;
128 from >> tredyellow;
129 from >> tag;
130 from >> tyellow;
131 NIVissimTL::NIVissimTLSignalGroup* group =
132 new NIVissimTL::NIVissimTLSignalGroup(
133 id, name, isGreenBegin, times, (SUMOTime) tredyellow, (SUMOTime) tyellow);
134 if (!NIVissimTL::NIVissimTLSignalGroup::dictionary(lsaid, id, group)) {
135 throw 1; // !!!
136 }
137 return true;
138 }
139
140
141 bool
parseVAS(int,const std::string &,int lsaid,std::istream & from)142 NIVissimSingleTypeParser_Signalgruppendefinition::parseVAS(
143 int /*id*/, const std::string& /*name*/, int lsaid, std::istream& from) {
144 WRITE_WARNING("VAS traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
145 std::string tag;
146 while (tag != "detektoren") {
147 tag = myRead(from);
148 }
149 return true;
150 }
151
152
153 bool
parseVSPLUS(int,const std::string &,int lsaid,std::istream &)154 NIVissimSingleTypeParser_Signalgruppendefinition::parseVSPLUS(
155 int /*id*/, const std::string&, int lsaid, std::istream&) {
156 WRITE_WARNING("VSPLUS traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
157 return true;
158 }
159
160
161 bool
parseTRENDS(int,const std::string &,int lsaid,std::istream &)162 NIVissimSingleTypeParser_Signalgruppendefinition::parseTRENDS(
163 int /*id*/, const std::string&, int lsaid, std::istream&) {
164 WRITE_WARNING("TRENDS traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
165 return true;
166 }
167
168
169 bool
parseVAP(int,const std::string &,int lsaid,std::istream &)170 NIVissimSingleTypeParser_Signalgruppendefinition::parseVAP(
171 int /*id*/, const std::string&, int lsaid, std::istream&) {
172 WRITE_WARNING("VAS traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
173 return true;
174 }
175
176
177 bool
parseTL(int,const std::string &,int lsaid,std::istream &)178 NIVissimSingleTypeParser_Signalgruppendefinition::parseTL(
179 int /*id*/, const std::string&, int lsaid, std::istream&) {
180 WRITE_WARNING("TL traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
181 return true;
182 }
183
184
185 bool
parsePOS(int,const std::string &,int lsaid,std::istream &)186 NIVissimSingleTypeParser_Signalgruppendefinition::parsePOS(
187 int /*id*/, const std::string&, int lsaid, std::istream&) {
188 WRITE_WARNING("POS traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
189 return true;
190 }
191
192
193 bool
parseExternFixedTime(int,const std::string &,int lsaid,std::istream &)194 NIVissimSingleTypeParser_Signalgruppendefinition::parseExternFixedTime(
195 int /*id*/, const std::string&, int lsaid, std::istream&) {
196 WRITE_WARNING("externally defined traffic lights are not supported (lsa=" + toString<int>(lsaid) + ")");
197 return true;
198 }
199
200
201
202 /****************************************************************************/
203
204