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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A handler for loading polygon type maps
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
29 #include <utils/common/RGBColor.h>
33 #include <utils/shapes/Shape.h>
34 #include "PCTypeMap.h"
35 #include "PCTypeDefHandler.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  : SUMOSAXHandler("Detector-Defintion"),
43  myOptions(oc), myContainer(con) {}
44 
45 
47 
48 
49 void
51  const SUMOSAXAttributes& attrs) {
52  if (element == SUMO_TAG_POLYTYPE) {
53  bool ok = true;
54  // get the id, report an error if not given or empty...
55  std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
56  if (!ok) {
57  return;
58  }
59  const double layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getFloat("layer"));
60  const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, id.c_str(), ok, false);
61  const bool allowFill = attrs.getOpt<bool>(SUMO_ATTR_FILL, id.c_str(), ok, myOptions.getBool("fill"));
62  const std::string type = attrs.getOpt<std::string>(SUMO_ATTR_NAME, id.c_str(), ok, myOptions.getString("type"));
63  const std::string prefix = attrs.getOpt<std::string>(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix"));
64  const std::string color = attrs.getOpt<std::string>(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color"));
65  const double angle = attrs.getOpt<double>(SUMO_ATTR_ANGLE, id.c_str(), ok, Shape::DEFAULT_ANGLE);
66  const std::string imgFile = attrs.getOpt<std::string>(SUMO_ATTR_IMGFILE, id.c_str(), ok, Shape::DEFAULT_IMG_FILE);
67  // !!! what about error handling?
68  if (!myContainer.add(id, type, color, prefix, layer, angle, imgFile, discard, allowFill)) {
69  WRITE_ERROR("Could not add polygon type '" + id + "' (probably the id is already used).");
70  }
71  }
72 }
73 
74 
75 /****************************************************************************/
76 
PCTypeDefHandler::myContainer
PCTypeMap & myContainer
The type map to fill.
Definition: PCTypeDefHandler.h:81
SUMO_ATTR_ANGLE
Definition: SUMOXMLDefinitions.h:794
SUMO_ATTR_IMGFILE
Definition: SUMOXMLDefinitions.h:792
SUMO_TAG_POLYTYPE
type of polygon
Definition: SUMOXMLDefinitions.h:200
SUMOSAXHandler
SAX-handler base for SUMO-files.
Definition: SUMOSAXHandler.h:41
OptionsCont.h
SUMOSAXAttributes::get
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
Definition: SUMOSAXAttributes.h:492
MsgHandler.h
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
SUMOSAXHandler.h
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
SUMO_ATTR_COLOR
A color information.
Definition: SUMOXMLDefinitions.h:704
PCTypeMap.h
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
SUMO_ATTR_DISCARD
Definition: SUMOXMLDefinitions.h:717
SUMO_ATTR_PREFIX
Definition: SUMOXMLDefinitions.h:716
RGBColor.h
Shape.h
PCTypeDefHandler::myOptions
OptionsCont & myOptions
The options (program settings)
Definition: PCTypeDefHandler.h:78
SUMO_ATTR_LAYER
A layer number.
Definition: SUMOXMLDefinitions.h:712
UtilExceptions.h
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
SUMOSAXAttributes::getOpt
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.
Definition: SUMOSAXAttributes.h:518
PCTypeDefHandler::myStartElement
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
Definition: PCTypeDefHandler.cpp:50
SUMO_ATTR_FILL
Fill the polygon.
Definition: SUMOXMLDefinitions.h:714
PCTypeDefHandler.h
OptionsCont::getFloat
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
Definition: OptionsCont.cpp:208
PCTypeDefHandler::PCTypeDefHandler
PCTypeDefHandler(OptionsCont &oc, PCTypeMap &con)
Constructor.
Definition: PCTypeDefHandler.cpp:41
PCTypeMap::add
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:48
PCTypeDefHandler::~PCTypeDefHandler
virtual ~PCTypeDefHandler()
Destructor.
Definition: PCTypeDefHandler.cpp:46
Shape::DEFAULT_ANGLE
static const double DEFAULT_ANGLE
Definition: Shape.h:46
config.h
StringTokenizer.h
SUMO_ATTR_NAME
Definition: SUMOXMLDefinitions.h:380
Shape::DEFAULT_IMG_FILE
static const std::string DEFAULT_IMG_FILE
Definition: Shape.h:47
PCTypeMap
A storage for type mappings.
Definition: PCTypeMap.h:44
SUMOSAXAttributes
Encapsulated SAX-Attributes.
Definition: SUMOSAXAttributes.h:56
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
SUMOXMLDefinitions.h