SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUISettingsHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // The dialog to change the view (gui) settings.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include <vector>
36 #include <utils/common/ToString.h>
37 #include <utils/common/RGBColor.h>
43 #include <xercesc/framework/MemBufInputSource.hpp>
44 #include "GUISettingsHandler.h"
45 
46 #ifdef CHECK_MEMORY_LEAKS
47 #include <foreign/nvwa/debug_new.h>
48 #endif // CHECK_MEMORY_LEAKS
49 
50 
51 // ===========================================================================
52 // method definitions
53 // ===========================================================================
54 GUISettingsHandler::GUISettingsHandler(const std::string& content, bool isFile)
55  : SUMOSAXHandler(content), myDelay(-1), myZoom(-1), myXPos(-1), myYPos(-1), myCurrentColorer(SUMO_TAG_NOTHING), myCurrentScheme(0) {
56  if (isFile) {
57  XMLSubSys::runParser(*this, content);
58  } else {
59  setFileName("registrySettings");
60  SAX2XMLReader* reader = XMLSubSys::getSAXReader(*this);
61  MemBufInputSource memBufIS((const XMLByte*)content.c_str(), content.size(), "registrySettings");
62  reader->parse(memBufIS);
63  delete reader;
64  }
65 }
66 
67 
69 }
70 
71 
72 void
74  const SUMOSAXAttributes& attrs) {
75  bool ok = true;
76  switch (element) {
77  case SUMO_TAG_DELAY:
79  break;
80  case SUMO_TAG_VIEWPORT:
84  break;
85  case SUMO_TAG_SNAPSHOT: {
86  bool ok = true;
87  std::string file = attrs.getStringReporting(SUMO_ATTR_FILE, 0, ok);
88  if (file != "" && !FileHelpers::isAbsolute(file)) {
90  }
91  mySnapshots[attrs.getOptSUMOTimeReporting(SUMO_ATTR_TIME, file.c_str(), ok, 0)] = file;
92  }
93  break;
95  bool ok = true;
99  }
100  }
101  break;
105  break;
107  bool ok = true;
108  mySettings.backgroundColor = RGBColor::parseColorReporting(attrs.getStringSecure("backgroundColor", toString(mySettings.backgroundColor)), "background", 0, true, ok);
112  }
113  break;
115  bool ok = true;
116  int laneEdgeMode = TplConvert<char>::_2int(attrs.getStringSecure("laneEdgeMode", "0").c_str());
124  myCurrentColorer = element;
125 #ifdef HAVE_MESOSIM
126  mySettings.edgeColorer.setActive(laneEdgeMode);
127 #endif
128  mySettings.laneColorer.setActive(laneEdgeMode);
129  }
130  break;
132  myCurrentScheme = 0;
135 #ifdef HAVE_MESOSIM
136  if (myCurrentScheme == 0) {
137  myCurrentScheme = mySettings.edgeColorer.getSchemeByName(attrs.getStringSecure(SUMO_ATTR_NAME, ""));
138  }
139 #endif
140  }
143  }
145  bool ok = true;
148  }
149  break;
150  case SUMO_TAG_ENTRY:
151  if (myCurrentScheme) {
152  bool ok = true;
153  std::string colorStr = attrs.getStringReporting(SUMO_ATTR_COLOR, 0, ok);
154  RGBColor color = RGBColor::parseColorReporting(colorStr, attrs.getObjectType(), 0, true, ok);
155  if (myCurrentScheme->isFixed()) {
157  } else {
158  myCurrentScheme->addColor(color,
160  }
161  }
162  break;
164  mySettings.vehicleColorer.setActive(TplConvert<char>::_2int(attrs.getStringSecure("vehicleMode", "0").c_str()));
170  myCurrentColorer = element;
171  break;
179  break;
185  break;
190  break;
193  break;
196  d.filename = attrs.getStringSecure("filename", d.filename);
197  if (d.filename != "" && !FileHelpers::isAbsolute(d.filename)) {
199  }
200  d.centerX = TplConvert<char>::_2SUMOReal(attrs.getStringSecure("centerX", toString(d.centerX)).c_str());
201  d.centerY = TplConvert<char>::_2SUMOReal(attrs.getStringSecure("centerY", toString(d.centerY)).c_str());
202  d.width = TplConvert<char>::_2SUMOReal(attrs.getStringSecure("width", toString(d.width)).c_str());
203  d.height = TplConvert<char>::_2SUMOReal(attrs.getStringSecure("height", toString(d.height)).c_str());
204  d.rot = TplConvert<char>::_2SUMOReal(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
205  d.initialised = false;
206  myDecals.push_back(d);
207  }
208  break;
209  default:
210  break;
211  }
212 }
213 
214 
217  const std::string& prefix, const SUMOSAXAttributes& attrs,
218  GUIVisualizationTextSettings defaults) {
219  bool ok = true;
221  TplConvert<char>::_2bool(attrs.getStringSecure(prefix + "_show", toString(defaults.show)).c_str()),
222  TplConvert<char>::_2SUMOReal(attrs.getStringSecure(prefix + "_size", toString(defaults.size)).c_str()),
223  RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_color", toString(defaults.color)), "edges", 0, true, ok));
224 }
225 
226 
227 std::string
229  if (mySettings.name != "") {
231  if (view) {
232  FXint index = view->getColoringSchemesCombo().appendItem(mySettings.name.c_str());
233  view->getColoringSchemesCombo().setCurrentItem(index);
235  }
236  }
237  return mySettings.name;
238 }
239 
240 
241 void
243  if (myZoom > 0) {
244  view->setViewport(myZoom, myXPos, myYPos);
245  }
246 }
247 
248 
249 void
251  zoom = myZoom;
252  xoff = myXPos;
253  yoff = myYPos;
254 }
255 
256 
257 void
259  if (!mySnapshots.empty()) {
260  view->setSnapshots(mySnapshots);
261  }
262 }
263 
264 
265 bool
267  return !myDecals.empty();
268 }
269 
270 
271 const std::vector<GUISUMOAbstractView::Decal>&
273  return myDecals;
274 }
275 
276 
277 SUMOReal
279  return myDelay;
280 }
281 
282 
283 /****************************************************************************/
284