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