SUMO - Simulation of Urban MObility
PCNetProjectionLoader.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
19 // A reader for a SUMO network's projection description
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <map>
34 #include <fstream>
36 #include <utils/options/Option.h>
37 #include <utils/common/StdDefs.h>
39 #include <utils/common/RGBColor.h>
40 #include <utils/geom/GeomHelper.h>
41 #include <utils/geom/Boundary.h>
42 #include <utils/geom/Position.h>
44 #include <utils/xml/XMLSubSys.h>
50 #include "PCNetProjectionLoader.h"
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 // ---------------------------------------------------------------------------
57 // static interface
58 // ---------------------------------------------------------------------------
59 void
60 PCNetProjectionLoader::load(const std::string& file, double scale) {
61  if (!FileHelpers::isReadable(file)) {
62  throw ProcessError("Could not open net-file '" + file + "'.");
63  }
64  // build handler and parser
65  PCNetProjectionLoader handler(scale);
66  handler.setFileName(file);
67  SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
68  PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'");
69  if (!parser->parseFirst(file)) {
70  delete parser;
71  throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'.");
72  }
73  // parse
74  while (parser->parseNext() && !handler.hasReadAll());
75  // clean up
77  if (!handler.hasReadAll()) {
78  throw ProcessError("Could not find projection parameter in net.");
79  }
80  delete parser;
81 }
82 
83 
84 
85 // ---------------------------------------------------------------------------
86 // handler methods
87 // ---------------------------------------------------------------------------
89  SUMOSAXHandler("sumo-network"),
90  myFoundLocation(false),
91  myScale(scale) {
92 }
93 
94 
96 
97 
98 void
100  const SUMOSAXAttributes& attrs) {
101  if (element != SUMO_TAG_LOCATION) {
102  return;
103  }
104  // @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader
105  myFoundLocation = true;
107  Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, 0, myFoundLocation);
108  Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, 0, myFoundLocation);
109  std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, 0, myFoundLocation);
110  if (myFoundLocation) {
112  Position networkOffset = s[0] + Position(oc.getFloat("offset.x"), oc.getFloat("offset.y"));
113  GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary, myScale);
114  }
115 }
116 
117 
118 bool
120  return myFoundLocation;
121 }
122 
123 
124 /****************************************************************************/
125 
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
static bool isReadable(std::string path)
Checks whether the given file is readable.
Definition: FileHelpers.cpp:53
double myScale
scaling of input coordinates (not given in the location element)
const std::string & getFileName() const
returns the current file name
static void load(const std::string &file, double scale)
Loads network projection if wished.
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:57
bool myFoundLocation
Information whether the parameter was read.
SAX-handler base for SUMO-files.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:47
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
void setFileName(const std::string &name)
Sets the current file name.
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:97
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:201
A reader for a SUMO network&#39;s projection description.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool parseFirst(std::string systemID)
A storage for options typed value containers)
Definition: OptionsCont.h:98
PCNetProjectionLoader(double scale)
Constructor.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:202
bool hasReadAll() const
Returns whether all needed values were read.