Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/polyconvert/PCLoaderXML.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 PCLoaderXML.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Christoph Sommer
18
/// @author Michael Behrisch
19
/// @date Thu, 02.11.2006
20
///
21
// A reader for polygons and pois stored in XML-format
22
/****************************************************************************/
23
#include <config.h>
24
25
#include <string>
26
#include <map>
27
#include <fstream>
28
#include <utils/options/OptionsCont.h>
29
#include <utils/options/Option.h>
30
#include <utils/common/MsgHandler.h>
31
#include <utils/common/FileHelpers.h>
32
#include <utils/common/RGBColor.h>
33
#include <utils/common/StdDefs.h>
34
#include <utils/common/SysUtils.h>
35
#include <polyconvert/PCPolyContainer.h>
36
#include <utils/geom/GeomHelper.h>
37
#include <utils/geom/Boundary.h>
38
#include <utils/geom/Position.h>
39
#include <utils/geom/GeoConvHelper.h>
40
#include <utils/xml/XMLSubSys.h>
41
#include <utils/geom/GeomConvHelper.h>
42
#include <utils/xml/SUMOXMLDefinitions.h>
43
#include "PCLoaderXML.h"
44
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
// ---------------------------------------------------------------------------
50
// static interface
51
// ---------------------------------------------------------------------------
52
void
53
PCLoaderXML::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
54
PCTypeMap& tm) {
55
if (!oc.isSet("xml-files")) {
56
return;
57
}
58
PCLoaderXML handler(toFill, tm, oc);
59
// parse file(s)
60
std::vector<std::string> files = oc.getStringVector("xml");
61
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
62
if (!FileHelpers::isReadable(*file)) {
63
throw ProcessError(TLF("Could not open xml-file '%'.", *file));
64
}
65
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing XML from '" + *file + "'");
66
if (!XMLSubSys::runParser(handler, *file)) {
67
throw ProcessError();
68
}
69
PROGRESS_TIME_MESSAGE(before);
70
}
71
}
72
73
74
75
// ---------------------------------------------------------------------------
76
// handler methods
77
// ---------------------------------------------------------------------------
78
PCLoaderXML::PCLoaderXML(PCPolyContainer& toFill,
79
PCTypeMap& tm, OptionsCont& oc)
80
: ShapeHandler("xml-poi-definition", toFill),
81
myTypeMap(tm), myOptions(oc) {}
82
83
84
PCLoaderXML::~PCLoaderXML() {}
85
86
87
void
88
PCLoaderXML::myStartElement(int element,
89
const SUMOSAXAttributes& attrs) {
90
if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) {
91
return;
92
}
93
bool ok = true;
94
// get the id, report an error if not given or empty...
95
std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
96
std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, myOptions.getString("type"));
97
if (!ok) {
98
return;
99
}
100
// patch the values
101
bool discard = myOptions.getBool("discard");
102
if (myTypeMap.has(type)) {
103
const PCTypeMap::TypeDef& def = myTypeMap.get(type);
104
discard = def.discard;
105
setDefaults(def.prefix, def.color, def.icon, def.layer, def.allowFill != PCTypeMap::Filltype::NOFILL);
106
} else {
107
setDefaults(myOptions.getString("prefix"), RGBColor::parseColor(myOptions.getString("color")),
108
myOptions.getString("icon"), myOptions.getFloat("layer"), myOptions.getBool("fill"));
109
}
110
if (!discard) {
111
if (element == SUMO_TAG_POI) {
112
addPOI(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
113
}
114
if (element == SUMO_TAG_POLY) {
115
addPoly(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
116
}
117
}
118
}
119
120
121
Position
122
PCLoaderXML::getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat) {
123
static_cast<PCPolyContainer&>(myShapeContainer).addLanePos(poiID, laneID, lanePos, friendlyPos, lanePosLat);
124
return Position::INVALID;
125
}
126
127
128
/****************************************************************************/
129
130