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>
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  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*this);
61  reader->parseString(content);
62  delete reader;
63  }
64 }
65 
66 
68 }
69 
70 
71 void
73  const SUMOSAXAttributes& attrs) {
74  bool ok = true;
75  switch (element) {
76  case SUMO_TAG_DELAY:
78  break;
79  case SUMO_TAG_VIEWPORT:
83  break;
84  case SUMO_TAG_SNAPSHOT: {
85  bool ok = true;
86  std::string file = attrs.getStringReporting(SUMO_ATTR_FILE, 0, ok);
87  if (file != "" && !FileHelpers::isAbsolute(file)) {
89  }
90  mySnapshots[attrs.getOptSUMOTimeReporting(SUMO_ATTR_TIME, file.c_str(), ok, 0)] = file;
91  }
92  break;
94  bool ok = true;
98  }
99  }
100  break;
104  break;
106  bool ok = true;
107  mySettings.backgroundColor = RGBColor::parseColorReporting(attrs.getStringSecure("backgroundColor", toString(mySettings.backgroundColor)), "background", 0, true, ok);
111  }
112  break;
114  int laneEdgeMode = TplConvert::_2int(attrs.getStringSecure("laneEdgeMode", "0").c_str());
122  myCurrentColorer = element;
123 #ifdef HAVE_INTERNAL
124  mySettings.edgeColorer.setActive(laneEdgeMode);
125 #endif
126  mySettings.laneColorer.setActive(laneEdgeMode);
127  }
128  break;
130  myCurrentScheme = 0;
133 #ifdef HAVE_INTERNAL
134  if (myCurrentScheme == 0) {
135  myCurrentScheme = mySettings.edgeColorer.getSchemeByName(attrs.getStringSecure(SUMO_ATTR_NAME, ""));
136  }
137 #endif
138  }
141  }
143  bool ok = true;
146  }
147  break;
148  case SUMO_TAG_ENTRY:
149  if (myCurrentScheme) {
150  bool ok = true;
151  RGBColor color = attrs.getColorReporting(0, ok);
152  if (myCurrentScheme->isFixed()) {
154  } else {
155  myCurrentScheme->addColor(color,
157  }
158  }
159  break;
161  mySettings.vehicleColorer.setActive(TplConvert::_2int(attrs.getStringSecure("vehicleMode", "0").c_str()));
167  myCurrentColorer = element;
168  break;
176  break;
182  break;
187  break;
190  break;
193  d.filename = attrs.getStringSecure("filename", d.filename);
194  if (d.filename != "" && !FileHelpers::isAbsolute(d.filename)) {
196  }
197  d.centerX = TplConvert::_2SUMOReal(attrs.getStringSecure("centerX", toString(d.centerX)).c_str());
198  d.centerY = TplConvert::_2SUMOReal(attrs.getStringSecure("centerY", toString(d.centerY)).c_str());
199  d.width = TplConvert::_2SUMOReal(attrs.getStringSecure("width", toString(d.width)).c_str());
200  d.height = TplConvert::_2SUMOReal(attrs.getStringSecure("height", toString(d.height)).c_str());
201  d.rot = TplConvert::_2SUMOReal(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
202  d.layer = TplConvert::_2SUMOReal(attrs.getStringSecure("layer", toString(d.layer)).c_str());
203  d.initialised = false;
204  myDecals.push_back(d);
205  }
206  break;
207  default:
208  break;
209  }
210 }
211 
212 
215  const std::string& prefix, const SUMOSAXAttributes& attrs,
216  GUIVisualizationTextSettings defaults) {
217  bool ok = true;
219  TplConvert::_2bool(attrs.getStringSecure(prefix + "_show", toString(defaults.show)).c_str()),
220  TplConvert::_2SUMOReal(attrs.getStringSecure(prefix + "_size", toString(defaults.size)).c_str()),
221  RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_color", toString(defaults.color)), "edges", 0, true, ok));
222 }
223 
224 
225 std::string
227  if (mySettings.name != "") {
229  if (view) {
230  FXint index = view->getColoringSchemesCombo().appendItem(mySettings.name.c_str());
231  view->getColoringSchemesCombo().setCurrentItem(index);
233  }
234  }
235  return mySettings.name;
236 }
237 
238 
239 void
241  if (myZoom > 0) {
242  view->setViewport(myZoom, myXPos, myYPos);
243  }
244 }
245 
246 
247 void
249  zoom = myZoom;
250  xoff = myXPos;
251  yoff = myYPos;
252 }
253 
254 
255 void
257  if (!mySnapshots.empty()) {
258  view->setSnapshots(mySnapshots);
259  }
260 }
261 
262 
263 bool
265  return !myDecals.empty();
266 }
267 
268 
269 const std::vector<GUISUMOAbstractView::Decal>&
271  return myDecals;
272 }
273 
274 
275 SUMOReal
277  return myDelay;
278 }
279 
280 
281 /****************************************************************************/
282