Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/dfrouter/RODFDetectorHandler.cpp
169665 views
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 RODFDetectorHandler.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Eric Nicolay
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @date Thu, 16.03.2006
20
///
21
// A handler for loading detector descriptions
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <string>
26
#include <utils/options/OptionsCont.h>
27
#include <utils/common/MsgHandler.h>
28
#include <utils/common/StringTokenizer.h>
29
#include <utils/common/UtilExceptions.h>
30
#include <utils/common/StringUtils.h>
31
#include <utils/common/ToString.h>
32
#include <utils/xml/SUMOSAXHandler.h>
33
#include <utils/xml/SUMOXMLDefinitions.h>
34
#include "RODFDetectorHandler.h"
35
#include "RODFNet.h"
36
37
38
// ===========================================================================
39
// method definitions
40
// ===========================================================================
41
RODFDetectorHandler::RODFDetectorHandler(RODFNet* optNet, bool ignoreErrors, RODFDetectorCon& con,
42
const std::string& file)
43
: SUMOSAXHandler(file),
44
myNet(optNet), myIgnoreErrors(ignoreErrors), myContainer(con) {}
45
46
47
RODFDetectorHandler::~RODFDetectorHandler() {}
48
49
50
void
51
RODFDetectorHandler::myStartElement(int element,
52
const SUMOSAXAttributes& attrs) {
53
if (element == SUMO_TAG_DETECTOR_DEFINITION || element == SUMO_TAG_E1DETECTOR || element == SUMO_TAG_INDUCTION_LOOP) {
54
try {
55
bool ok = true;
56
// get the id, report an error if not given or empty...
57
std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
58
if (!ok) {
59
throw ProcessError();
60
}
61
std::string lane = attrs.get<std::string>(SUMO_ATTR_LANE, id.c_str(), ok);
62
if (!ok) {
63
throw ProcessError();
64
}
65
ROEdge* edge = myNet->getEdge(SUMOXMLDefinitions::getEdgeIDFromLane(lane));
66
int laneIndex = SUMOXMLDefinitions::getIndexFromLane(lane);
67
if (edge == nullptr || laneIndex >= edge->getNumLanes()) {
68
throw ProcessError("Unknown lane '" + lane + "' for detector '" + id + "' in '" + getFileName() + "'.");
69
}
70
double pos = attrs.get<double>(SUMO_ATTR_POSITION, id.c_str(), ok);
71
std::string mml_type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, "");
72
if (!ok) {
73
throw ProcessError();
74
}
75
RODFDetectorType type = TYPE_NOT_DEFINED;
76
if (mml_type == "between") {
77
type = BETWEEN_DETECTOR;
78
} else if (mml_type == "source" || mml_type == "highway_source") { // !!! highway-source is legacy (removed accoring output on 06.08.2007)
79
type = SOURCE_DETECTOR;
80
} else if (mml_type == "sink") {
81
type = SINK_DETECTOR;
82
}
83
RODFDetector* detector = new RODFDetector(id, lane, pos, type);
84
if (!myContainer.addDetector(detector)) {
85
delete detector;
86
throw ProcessError(TLF("Could not add detector '%' (probably the id is already used).", id));
87
}
88
} catch (ProcessError& e) {
89
if (myIgnoreErrors) {
90
WRITE_WARNING(e.what());
91
} else {
92
throw;
93
}
94
}
95
}
96
}
97
98
99
/****************************************************************************/
100
101