SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-sim.org/
12 // Copyright (C) 2001-2014 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 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // method definitions
60 // ===========================================================================
61 // ---------------------------------------------------------------------------
62 // static interface
63 // ---------------------------------------------------------------------------
64 void
65 PCNetProjectionLoader::load(const std::string& file, int shift) {
66  if (!FileHelpers::isReadable(file)) {
67  throw ProcessError("Could not open net-file '" + file + "'.");
68  }
69  // build handler and parser
70  PCNetProjectionLoader handler(shift);
71  handler.setFileName(file);
72  SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
73  PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'");
74  if (!parser->parseFirst(file)) {
75  delete parser;
76  throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'.");
77  }
78  // parse
79  while (parser->parseNext() && !handler.hasReadAll());
80  // clean up
82  if (!handler.hasReadAll()) {
83  throw ProcessError("Could not find projection parameter in net.");
84  }
85  delete parser;
86 }
87 
88 
89 
90 // ---------------------------------------------------------------------------
91 // handler methods
92 // ---------------------------------------------------------------------------
94  SUMOSAXHandler("sumo-network"),
95  myFoundLocation(false),
96  myShift(shift)
97 {}
98 
99 
101 
102 
103 void
105  const SUMOSAXAttributes& attrs) {
106  if (element != SUMO_TAG_LOCATION) {
107  return;
108  }
109  // @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader
110  myFoundLocation = true;
112  Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, 0, myFoundLocation);
113  Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, 0, myFoundLocation);
114  std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, 0, myFoundLocation);
115  if (myFoundLocation) {
116  Position networkOffset = s[0];
117  GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary, myShift);
118  }
119 }
120 
121 
122 bool
124  return myFoundLocation;
125 }
126 
127 
128 /****************************************************************************/
129 
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:58
bool hasReadAll() const
Returns whether all needed values were read.
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
const std::string & getFileName() const
returns the current file name
void setFileName(const std::string &name)
Sets the current file name.
Encapsulated SAX-Attributes.
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:102
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's projection description.
static void load(const std::string &file, int shift)
Loads network projection if wished.
bool parseFirst(std::string systemID)
PCNetProjectionLoader(int shift)
Constructor.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
#define PROGRESS_DONE_MESSAGE()
Definition: MsgHandler.h:203