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>
50 #include "PCNetProjectionLoader.h"
51 
52 #ifdef CHECK_MEMORY_LEAKS
53 #include <foreign/nvwa/debug_new.h>
54 #endif // CHECK_MEMORY_LEAKS
55 
56 
57 // ===========================================================================
58 // method definitions
59 // ===========================================================================
60 // ---------------------------------------------------------------------------
61 // static interface
62 // ---------------------------------------------------------------------------
63 void
65  Position& netOffset, Boundary& origNetBoundary,
66  Boundary& convNetBoundary,
67  std::string& projParameter) {
68  if (!oc.isSet("net")) {
69  return;
70  }
71  // check file
72  std::string file = oc.getString("net");
73  if (!FileHelpers::exists(file)) {
74  throw ProcessError("Could not open net-file '" + file + "'.");
75  }
76  // build handler and parser
77  PCNetProjectionLoader handler(netOffset, origNetBoundary, convNetBoundary, projParameter);
78  handler.setFileName(file);
79  XMLPScanToken token;
80  XERCES_CPP_NAMESPACE_QUALIFIER SAX2XMLReader* parser = XMLSubSys::getSAXReader(handler);
81  PROGRESS_BEGIN_MESSAGE("Parsing network projection from '" + file + "'");
82  if (!parser->parseFirst(file.c_str(), token)) {
83  delete parser;
84  throw ProcessError("Can not read XML-file '" + handler.getFileName() + "'.");
85  }
86  // parse
87  while (parser->parseNext(token) && !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;
123  attrs.getObjectType(), 0, ok, false);
124  if (ok) {
125  myNetOffset = tmp[0];
126  }
129  attrs.getObjectType(), 0, ok);
132  attrs.getObjectType(), 0, ok);
135 }
136 
137 
138 void
140  const std::string& chars) {
141  UNUSED_PARAMETER(element);
142  UNUSED_PARAMETER(chars);
143 }
144 
145 
146 bool
149 }
150 
151 
152 /****************************************************************************/
153