Eclipse SUMO - Simulation of Urban MObility
PCTypeDefHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 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>
28 #include <utils/common/RGBColor.h>
32 #include <utils/shapes/Shape.h>
33 #include "PCTypeMap.h"
34 #include "PCTypeDefHandler.h"
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
41  : SUMOSAXHandler("Detector-Defintion"),
42  myOptions(oc), myContainer(con) {}
43 
44 
46 
47 
48 void
50  const SUMOSAXAttributes& attrs) {
51  if (element == SUMO_TAG_POLYTYPE) {
52  bool ok = true;
53  // get the id, report an error if not given or empty...
54  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
55  if (!ok) {
56  return;
57  }
58  const double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
59  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
60  const bool allowFill = attrs.getOpt<bool>(SUMO_ATTR_FILL, id.c_str(), ok, myOptions.getBool("fill"));
61  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOptions.getString("type"));
62  const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
63  const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
64  const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE);
65  const std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE);
66  // !!! what about error handling?
67  if (!myContainer.add(id, type, color, prefix, layer, angle, imgFile, discard, allowFill)) {
68  WRITE_ERROR("Could not add polygon type '" + id + "' (probably the id is already used).");
69  }
70  }
71 }
72 
73 
74 /****************************************************************************/
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:284
@ 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;.
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, 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:45
static const double DEFAULT_ANGLE
Definition: Shape.h:44