Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
PCTypeDefHandler.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2023 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/****************************************************************************/
20// A handler for loading polygon type maps
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
32#include <utils/shapes/Shape.h>
33#include "PCTypeMap.h"
34#include "PCTypeDefHandler.h"
35
36
37// ===========================================================================
38// method definitions
39// ===========================================================================
42 myOptions(oc),
43 myContainer(con),
44 myOverwriteType(!oc.isDefault("type"))
45{}
46
47
49
50
51void
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 double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
62 const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
63 const bool allowFill = attrs.getOpt<bool>(SUMO_ATTR_FILL, id.c_str(), ok, myOptions.getBool("fill"));
64 const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOverwriteType ? myOptions.getString("type") : id);
65 const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
66 const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
67 const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE);
68 const std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE);
69 // !!! what about error handling?
70 if (!myContainer.add(id, type, color, prefix, layer, angle, imgFile, discard, allowFill)) {
71 WRITE_ERRORF(TL("Could not add polygon type '%' (probably the id is already used)."), id);
72 }
73 }
74}
75
76
77/****************************************************************************/
#define WRITE_ERRORF(...)
Definition MsgHandler.h:280
#define TL(string)
Definition MsgHandler.h:287
@ SUMO_TAG_POLYTYPE
type of polygon
@ SUMO_ATTR_FILL
Fill the polygon.
@ SUMO_ATTR_NAME
@ SUMO_ATTR_LAYER
A layer number.
@ SUMO_ATTR_ANGLE
@ SUMO_ATTR_PREFIX
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_DISCARD
@ SUMO_ATTR_IMGFILE
A storage for options typed value containers)
Definition OptionsCont.h:89
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
virtual ~PCTypeDefHandler()
Destructor.
OptionsCont & myOptions
The options (program settings)
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
bool myOverwriteType
whether to replace the loaded type with a custom value
PCTypeDefHandler(OptionsCont &oc, PCTypeMap &con)
Constructor.
PCTypeMap & myContainer
The type map to fill.
A storage for type mappings.
Definition PCTypeMap.h:42
bool add(const std::string &id, const std::string &newid, const std::string &color, const std::string &prefix, double layer, double angle, const std::string &imgFile, bool discard, bool allowFill)
Adds a type definition.
Definition PCTypeMap.cpp:47
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue=T(), bool report=true) const
Tries to read given attribute assuming it is an int.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
SAX-handler base for SUMO-files.
static const std::string DEFAULT_IMG_FILE
Definition Shape.h:47
static const double DEFAULT_ANGLE
Definition Shape.h:46