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-sim.org/
13 // Copyright (C) 2001-2013 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 <utils/xml/XMLSubSys.h>
45 #include "GUISettingsHandler.h"
46 
47 #ifdef CHECK_MEMORY_LEAKS
48 #include <foreign/nvwa/debug_new.h>
49 #endif // CHECK_MEMORY_LEAKS
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 GUISettingsHandler::GUISettingsHandler(const std::string& content, bool isFile)
56  : SUMOSAXHandler(content), myDelay(-1), myLookFrom(-1, -1, -1), myLookAt(-1, -1, -1),
57  myCurrentColorer(SUMO_TAG_NOTHING), myCurrentScheme(0) {
58  if (isFile) {
59  XMLSubSys::runParser(*this, content);
60  } else {
61  setFileName("registrySettings");
62  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*this);
63  reader->parseString(content);
64  delete reader;
65  }
66 }
67 
68 
70 }
71 
72 
73 void
75  const SUMOSAXAttributes& attrs) {
76  bool ok = true;
77  switch (element) {
79  std::string file = attrs.get<std::string>(SUMO_ATTR_VALUE, 0, ok);
81  }
82  break;
84  myViewType = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, 0, ok, "default");
85  std::transform(myViewType.begin(), myViewType.end(), myViewType.begin(), tolower);
86  break;
87  case SUMO_TAG_DELAY:
88  myDelay = attrs.getOpt<SUMOReal>(SUMO_ATTR_VALUE, 0, ok, myDelay);
89  break;
90  case SUMO_TAG_VIEWPORT: {
91  const SUMOReal x = attrs.getOpt<SUMOReal>(SUMO_ATTR_X, 0, ok, myLookFrom.x());
92  const SUMOReal y = attrs.getOpt<SUMOReal>(SUMO_ATTR_Y, 0, ok, myLookFrom.y());
93  const SUMOReal z = attrs.getOpt<SUMOReal>(SUMO_ATTR_ZOOM, 0, ok, myLookFrom.z());
94  myLookFrom.set(x, y, z);
95  const SUMOReal cx = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_X, 0, ok, myLookAt.x());
96  const SUMOReal cy = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Y, 0, ok, myLookAt.y());
97  const SUMOReal cz = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Z, 0, ok, myLookAt.z());
98  myLookAt.set(cx, cy, cz);
99  break;
100  }
101  case SUMO_TAG_SNAPSHOT: {
102  bool ok = true;
103  std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, 0, ok);
104  if (file != "" && !FileHelpers::isAbsolute(file)) {
106  }
107  mySnapshots[attrs.getOptSUMOTimeReporting(SUMO_ATTR_TIME, file.c_str(), ok, 0)] = file;
108  }
109  break;
111  bool ok = true;
112  mySettings.name = attrs.getOpt<std::string>(SUMO_ATTR_NAME, 0, ok, mySettings.name);
115  }
116  }
117  break;
121  break;
123  bool ok = true;
124  mySettings.backgroundColor = RGBColor::parseColorReporting(attrs.getStringSecure("backgroundColor", toString(mySettings.backgroundColor)), "background", 0, true, ok);
128  }
129  break;
131  int laneEdgeMode = TplConvert::_2int(attrs.getStringSecure("laneEdgeMode", "0").c_str());
139  myCurrentColorer = element;
140 #ifdef HAVE_INTERNAL
141  mySettings.edgeColorer.setActive(laneEdgeMode);
142 #endif
143  mySettings.laneColorer.setActive(laneEdgeMode);
144  }
145  break;
147  myCurrentScheme = 0;
150 #ifdef HAVE_INTERNAL
151  if (myCurrentScheme == 0) {
152  myCurrentScheme = mySettings.edgeColorer.getSchemeByName(attrs.getStringSecure(SUMO_ATTR_NAME, ""));
153  }
154 #endif
155  }
158  }
161  }
163  bool ok = true;
164  myCurrentScheme->setInterpolated(attrs.getOpt<bool>(SUMO_ATTR_INTERPOLATED, 0, ok, false));
166  }
167  break;
168  case SUMO_TAG_ENTRY:
169  if (myCurrentScheme) {
170  bool ok = true;
171  RGBColor color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, 0, ok);
172  if (myCurrentScheme->isFixed()) {
174  } else {
175  myCurrentScheme->addColor(color,
176  attrs.get<SUMOReal>(SUMO_ATTR_THRESHOLD, 0, ok));
177  }
178  }
179  break;
181  mySettings.vehicleColorer.setActive(TplConvert::_2int(attrs.getStringSecure("vehicleMode", "0").c_str()));
187  myCurrentColorer = element;
188  break;
190  mySettings.personColorer.setActive(TplConvert::_2int(attrs.getStringSecure("personMode", "0").c_str()));
195  myCurrentColorer = element;
196  break;
198  mySettings.junctionColorer.setActive(TplConvert::_2int(attrs.getStringSecure("junctionMode", "0").c_str()));
204  myCurrentColorer = element;
205  break;
211  break;
216  break;
221  break;
224  break;
227  d.filename = attrs.getStringSecure("filename", d.filename);
228  if (d.filename != "" && !FileHelpers::isAbsolute(d.filename)) {
230  }
231  d.centerX = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_X, 0, ok, d.centerX);
232  d.centerY = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Y, 0, ok, d.centerY);
233  d.centerZ = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Z, 0, ok, d.centerZ);
234  d.width = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, 0, ok, d.width);
235  d.height = attrs.getOpt<SUMOReal>(SUMO_ATTR_HEIGHT, 0, ok, d.height);
236  d.altitude = TplConvert::_2SUMOReal(attrs.getStringSecure("altitude", toString(d.height)).c_str());
237  d.rot = TplConvert::_2SUMOReal(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
238  d.tilt = TplConvert::_2SUMOReal(attrs.getStringSecure("tilt", toString(d.tilt)).c_str());
239  d.roll = TplConvert::_2SUMOReal(attrs.getStringSecure("roll", toString(d.roll)).c_str());
240  d.layer = attrs.getOpt<SUMOReal>(SUMO_ATTR_LAYER, 0, ok, d.layer);
241  d.initialised = false;
242  myDecals.push_back(d);
243  }
244  break;
245  default:
246  break;
247  }
248 }
249 
250 
253  const std::string& prefix, const SUMOSAXAttributes& attrs,
254  GUIVisualizationTextSettings defaults) {
255  bool ok = true;
257  TplConvert::_2bool(attrs.getStringSecure(prefix + "_show", toString(defaults.show)).c_str()),
258  TplConvert::_2SUMOReal(attrs.getStringSecure(prefix + "_size", toString(defaults.size)).c_str()),
259  RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_color", toString(defaults.color)), "edges", 0, true, ok));
260 }
261 
262 
263 std::string
265  if (mySettings.name != "") {
267  if (view) {
268  FXint index = view->getColoringSchemesCombo().appendItem(mySettings.name.c_str());
269  view->getColoringSchemesCombo().setCurrentItem(index);
271  }
272  }
273  return mySettings.name;
274 }
275 
276 
277 void
279  if (myLookFrom.z() > 0) {
281  }
282 }
283 
284 
285 void
287  lookFrom = myLookFrom;
288  lookAt = myLookAt;
289 }
290 
291 
292 void
294  if (!mySnapshots.empty()) {
295  view->setSnapshots(mySnapshots);
296  }
297 }
298 
299 
300 bool
302  return !myDecals.empty();
303 }
304 
305 
306 const std::vector<GUISUMOAbstractView::Decal>&
308  return myDecals;
309 }
310 
311 
312 SUMOReal
314  return myDelay;
315 }
316 
317 
318 std::vector<SUMOTime>
319 GUISettingsHandler::loadBreakpoints(const std::string& file) {
320  std::vector<SUMOTime> result;
321  std::ifstream strm(file.c_str());
322  while (strm.good()) {
323  std::string val;
324  strm >> val;
325  if (val.length() == 0) {
326  continue;
327  }
328  try {
329  SUMOTime value = string2time(val);
330  result.push_back(value);
331  } catch (NumberFormatException&) {
332  WRITE_ERROR(" A breakpoint-value must be an int, is:" + val);
333  } catch (ProcessError&) {
334  WRITE_ERROR(" Could not decode breakpoint '" + val + "'");
335  } catch (EmptyData&) {}
336  }
337  return result;
338 }
339 
340 /****************************************************************************/
341 
float vehicleExaggeration
The vehicle exaggeration (upscale)
GUIVisualizationTextSettings junctionName
A decal (an image) that can be shown.
GUISettingsHandler(const std::string &content, bool isFile=true)
Constructor.
GUICompleteSchemeStorage gSchemeStorage
bool showSizeLegend
Information whether the size legend shall be drawn.
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
Definition: FileHelpers.cpp:85
GUIVisualizationTextSettings streetName
bool isFixed() const
SUMOReal roll
The roll of the image to the ground plane (in degrees)
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag.
std::string addSettings(GUISUMOAbstractView *view=0) const
Adds the parsed settings to the global list of settings.
virtual void setViewport(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
bool showBlinker
Information whether vehicle blinkers shall be drawn.
GUIVisualizationTextSettings addName
int myCurrentColorer
The last color scheme category (edges or vehicles)
GUIVisualizationTextSettings personName
float minAddSize
The minimum size of additional structures to let them be drawn.
GUIColorScheme * myCurrentScheme
The current color scheme.
bool drawLinkTLIndex
Information whether a link&#39;s tls index shall be drawn.
static SUMOReal _2SUMOReal(const E *const data)
Definition: TplConvert.h:223
GUIVisualizationTextSettings poiName
static bool _2bool(const E *const data)
Definition: TplConvert.h:282
float polyExaggeration
The additional shapes (upscale)
static RGBColor parseColorReporting(const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
Parses a color information.
Definition: RGBColor.cpp:231
GUIColorer laneColorer
The lane colorer.
A layer number.
float poiExaggeration
The additional shapes (upscale)
bool showRails
Information whether rails shall be drawn.
GUIColorScheme * getSchemeByName(std::string name)
Definition: GUIColorer.h:84
void setInterpolated(const bool interpolate, SUMOReal interpolationStart=0.f)
std::vector< GUISUMOAbstractView::Decal > myDecals
The decals list to fill.
GUIVisualizationTextSettings vehicleName
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:54
Position myLookAt
The point to look at, only needed for osg view.
SUMOReal myDelay
The delay loaded.
bool hasDecals() const
Returns whether any decals have been parsed.
bool laneShowBorders
Information whether lane borders shall be drawn.
SUMOReal centerZ
The center of the image in z-direction (net coordinates, in m)
void setSnapshots(std::map< SUMOTime, std::string > snaps)
Sets the snapshot time to file map.
SUMOReal width
The width of the image (net coordinates in x-direction, in m)
static std::vector< SUMOTime > loadBreakpoints(const std::string &file)
loads breakpoints from the specified file
static bool runParser(GenericSAXHandler &handler, const std::string &file)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:96
void parseString(std::string content)
SAX-handler base for SUMO-files.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
bool dither
Information whether dithering shall be enabled.
const std::vector< GUISUMOAbstractView::Decal > & getDecals() const
Returns the parsed decals.
void setViewport(GUISUMOAbstractView *view) const
Sets the viewport which has been parsed.
float personExaggeration
The person exaggeration (upscale)
GUIVisualizationSettings mySettings
The settings to fill.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
GUIColorer vehicleColorer
The vehicle colorer.
SUMOReal getDelay() const
Returns the parsed delay.
GUIVisualizationTextSettings edgeName
std::map< SUMOTime, std::string > mySnapshots
mappig of time steps to filenames for potential snapshots
void setActive(size_t scheme)
Definition: GUIColorer.h:66
const std::string & getFileName() const
returns the current file name
void setFileName(const std::string &name)
Sets the current file name.
std::string name
The name of this setting.
float addExaggeration
The additional structures exaggeration (upscale)
SUMOReal altitude
The altitude of the image (net coordinates in z-direction, in m)
Encapsulated SAX-Attributes.
GUIVisualizationTextSettings internalEdgeName
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
SUMOReal centerY
The center of the image in y-direction (net coordinates, in m)
GUIVisualizationTextSettings parseTextSettings(const std::string &prefix, const SUMOSAXAttributes &attrs, GUIVisualizationTextSettings defaults)
parse combined settings of bool, size and color
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
int addMode
The additional structures visualization scheme.
void setSnapshots(GUISUMOAbstractView *view) const
Makes a snapshot if it has been parsed.
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
FXComboBox & getColoringSchemesCombo()
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:84
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:48
bool initialised
Whether this image was initialised (inserted as a texture)
GUIColorer personColorer
The person colorer.
GUIVisualizationTextSettings internalJunctionName
GUIColorer junctionColorer
The junction colorer.
~GUISettingsHandler()
Destructor.
std::string filename
The path to the file the image is located at.
SUMOReal gridXSize
Information about the grid spacings.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:51
std::string myViewType
The view type (osg, opengl, default) loaded.
RGBColor backgroundColor
The background color to use.
bool antialiase
Information whether antialiase shall be enabled.
float minPOISize
The minimum size of shapes to let them be drawn.
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
SUMOReal height
The height of the image (net coordinates in y-direction, in m)
SUMOReal centerX
The center of the image in x-direction (net coordinates, in m)
static int _2int(const E *const data)
Definition: TplConvert.h:114
float minPersonSize
The minimum size of persons to let them be drawn.
bool showLinkDecals
Information whether link textures (arrows) shall be drawn.
unsigned int addColor(const RGBColor &color, const SUMOReal threshold, const std::string &name="")
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
void set(SUMOReal x, SUMOReal y)
Definition: Position.h:78
bool drawLinkJunctionIndex
Information whether a link&#39;s junction index shall be drawn.
virtual bool setColorScheme(const std::string &)
int personQuality
The quality of person drawing.
bool showGrid
Information whether a grid shall be shown.
SUMOReal layer
The layer of the image.
void setColor(const size_t pos, const RGBColor &color)
float minVehicleSize
The minimum size of vehicles to let them be drawn.
bool showLane2Lane
Information whether lane-to-lane arrows shall be drawn.
#define SUMOReal
Definition: config.h:215
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
SUMOReal tilt
The tilt of the image to the ground plane (in degrees)
int vehicleQuality
The quality of vehicle drawing.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
std::vector< SUMOTime > myBreakpoints
The parsed breakpoints.
A color information.
Position myLookFrom
The viewport loaded, zoom is stored in z coordinate.
float minPolySize
The minimum size of shapes to let them be drawn.
SUMOReal rot
The rotation of the image in the ground plane (in degrees)
void add(const GUIVisualizationSettings &scheme)
Adds a visualization scheme.
GUIVisualizationTextSettings polyName