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.sourceforge.net/
12 // Copyright (C) 2001-2012 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
66  Position& netOffset, Boundary& origNetBoundary,
67  Boundary& convNetBoundary,
68  std::string& projParameter) {
69  if (!oc.isSet("net")) {
70  return;
71  }
72  // check file
73  std::string file = oc.getString("net");
74  if (!FileHelpers::exists(file)) {
75  throw ProcessError("Could not open net-file '" + file + "'.");
76  }
77  // build handler and parser
78  PCNetProjectionLoader handler(netOffset, origNetBoundary, convNetBoundary, projParameter);
79  handler.setFileName(file);
80  SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler);
81  PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'");
82  if (!parser->parseFirst(file)) {
83  delete parser;
84  throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'.");
85  }
86  // parse
87  while (parser->parseNext() && !handler.hasReadAll());
88  // clean up
90  if (!handler.hasReadAll()) {
91  throw ProcessError("Could not find projection parameter in net.");
92  }
93  delete parser;
94 }
95 
96 
97 
98 // ---------------------------------------------------------------------------
99 // handler methods
100 // ---------------------------------------------------------------------------
102  Boundary& origNetBoundary, Boundary& convNetBoundary,
103  std::string& projParameter)
104  : SUMOSAXHandler("sumo-network"), myNetOffset(netOffset),
105  myOrigNetBoundary(origNetBoundary), myConvNetBoundary(convNetBoundary),
106  myProjParameter(projParameter),
107  myFoundOffset(false), myFoundOrigNetBoundary(false),
108  myFoundConvNetBoundary(false), myFoundProj(false) {}
109 
110 
112 
113 
114 void
116  const SUMOSAXAttributes& attrs) {
117  if (element != SUMO_TAG_LOCATION) {
118  return;
119  }
120  bool ok = true;
121  PositionVector tmp = attrs.getShapeReporting(SUMO_ATTR_NET_OFFSET, 0, ok, false);
122  if (ok) {
123  myNetOffset = tmp[0];
124  }
129 }
130 
131 
132 bool
135 }
136 
137 
138 /****************************************************************************/
139