SUMO - Simulation of Urban MObility
PCNetProjectionLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A reader for a SUMO network's projection description
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include <map>
35 #include <fstream>
37 #include <utils/options/Option.h>
38 #include <utils/common/StdDefs.h>
40 #include <utils/common/RGBColor.h>
41 #include <utils/geom/GeomHelper.h>
42 #include <utils/geom/Boundary.h>
43 #include <utils/geom/Position.h>
45 #include <utils/xml/XMLSubSys.h>
51 #include "PCNetProjectionLoader.h"
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 // ---------------------------------------------------------------------------
58 // static interface
59 // ---------------------------------------------------------------------------
60 void
61 PCNetProjectionLoader::load(const std::string& file, int shift) {
62  if (!FileHelpers::isReadable(file)) {
63  throw ProcessError("Could not open net-file '" + file + "'.");
64  }
65  // build handler and parser
66  PCNetProjectionLoader handler(shift);
67  handler.setFileName(file);
68  SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
69  PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'");
70  if (!parser->parseFirst(file)) {
71  delete parser;
72  throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'.");
73  }
74  // parse
75  while (parser->parseNext() && !handler.hasReadAll());
76  // clean up
78  if (!handler.hasReadAll()) {
79  throw ProcessError("Could not find projection parameter in net.");
80  }
81  delete parser;
82 }
83 
84 
85 
86 // ---------------------------------------------------------------------------
87 // handler methods
88 // ---------------------------------------------------------------------------
90  SUMOSAXHandler("sumo-network"),
91  myFoundLocation(false),
92  myShift(shift) {
93 }
94 
95 
97 
98 
99 void
101  const SUMOSAXAttributes& attrs) {
102  if (element != SUMO_TAG_LOCATION) {
103  return;
104  }
105  // @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader
106  myFoundLocation = true;
108  Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, 0, myFoundLocation);
109  Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, 0, myFoundLocation);
110  std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, 0, myFoundLocation);
111  if (myFoundLocation) {
113  Position networkOffset = s[0] + Position(oc.getFloat("offset.x"), oc.getFloat("offset.y"));
114  GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary, myShift);
115  }
116 }
117 
118 
119 bool
121  return myFoundLocation;
122 }
123 
124 
125 /****************************************************************************/
126 
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:54
const std::string & getFileName() const
returns the current file name
int myShift
shift of input coordinates (not given in the location element)
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:58
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:48
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
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:46
A list of positions.
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:98
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
#define PROGRESS_BEGIN_MESSAGE(msg)
Definition: MsgHandler.h:202
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)
static void load(const std::string &file, int shift)
Loads network projection if wished.
bool parseFirst(std::string systemID)
PCNetProjectionLoader(int shift)
Constructor.
A storage for options typed value containers)
Definition: OptionsCont.h:99
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203
bool hasReadAll() const
Returns whether all needed values were read.