Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/polyconvert/PCTypeDefHandler.cpp
169666 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 PCTypeDefHandler.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Thu, 16.03.2006
19
///
20
// A handler for loading polygon type maps
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <string>
25
#include <utils/options/OptionsCont.h>
26
#include <utils/common/MsgHandler.h>
27
#include <utils/common/StringTokenizer.h>
28
#include <utils/common/RGBColor.h>
29
#include <utils/common/UtilExceptions.h>
30
#include <utils/xml/SUMOSAXHandler.h>
31
#include <utils/xml/SUMOXMLDefinitions.h>
32
#include <utils/shapes/Shape.h>
33
#include "PCTypeMap.h"
34
#include "PCTypeDefHandler.h"
35
36
37
// ===========================================================================
38
// method definitions
39
// ===========================================================================
40
PCTypeDefHandler::PCTypeDefHandler(OptionsCont& oc, PCTypeMap& con) :
41
SUMOSAXHandler(),
42
myOptions(oc),
43
myContainer(con),
44
myOverwriteType(!oc.isDefault("type"))
45
{}
46
47
48
PCTypeDefHandler::~PCTypeDefHandler() {}
49
50
51
void
52
PCTypeDefHandler::myStartElement(int element,
53
const SUMOSAXAttributes& attrs) {
54
if (element == SUMO_TAG_POLYTYPE) {
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
return;
60
}
61
const std::string icon = attrs.getOpt<std::string>(SUMO_ATTR_ICON, id.c_str(), ok, myOptions.getString("icon"));
62
const double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
63
const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
64
PCTypeMap::Filltype allowFill = myOptions.getBool("fill") ? PCTypeMap::Filltype::FILL : PCTypeMap::Filltype::NOFILL;
65
if (attrs.hasAttribute(SUMO_ATTR_FILL)) {
66
const std::string allowFillS = attrs.get<std::string>(SUMO_ATTR_FILL, id.c_str(), ok);
67
if (allowFillS == "force") {
68
allowFill = PCTypeMap::Filltype::FORCE;
69
} else {
70
allowFill = StringUtils::toBool(allowFillS) ? PCTypeMap::Filltype::FILL : PCTypeMap::Filltype::NOFILL;
71
}
72
}
73
const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOverwriteType ? myOptions.getString("type") : id);
74
const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
75
const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
76
const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE);
77
const std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE);
78
// !!! what about error handling?
79
if (!myContainer.add(id, type, color, prefix, icon, layer, angle, imgFile, discard, allowFill)) {
80
WRITE_ERRORF(TL("Could not add polygon type '%' (probably the id is already used)."), id);
81
}
82
}
83
}
84
85
86
/****************************************************************************/
87
88