SUMO - Simulation of Urban MObility
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.dlr.de/
13 // Copyright (C) 2001-2016 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>
45 #include <utils/xml/XMLSubSys.h>
46 #include "GUISettingsHandler.h"
47 
48 #ifdef CHECK_MEMORY_LEAKS
49 #include <foreign/nvwa/debug_new.h>
50 #endif // CHECK_MEMORY_LEAKS
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 GUISettingsHandler::GUISettingsHandler(const std::string& content, bool isFile)
57  : SUMOSAXHandler(content), myDelay(-1), myLookFrom(-1, -1, -1), myLookAt(-1, -1, -1),
58  myCurrentColorer(SUMO_TAG_NOTHING), myCurrentScheme(0), myJamSoundTime(-1) {
59  if (isFile) {
60  XMLSubSys::runParser(*this, content);
61  } else {
62  setFileName("registrySettings");
63  SUMOSAXReader* reader = XMLSubSys::getSAXReader(*this);
64  reader->parseString(content);
65  delete reader;
66  }
67 }
68 
69 
71 }
72 
73 
74 void
76  const SUMOSAXAttributes& attrs) {
77  bool ok = true;
78  switch (element) {
80  std::string file = attrs.get<std::string>(SUMO_ATTR_VALUE, 0, ok);
82  }
83  break;
85  myViewType = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, 0, ok, "default");
86  std::transform(myViewType.begin(), myViewType.end(), myViewType.begin(), tolower);
87  break;
88  case SUMO_TAG_DELAY:
89  myDelay = attrs.getOpt<SUMOReal>(SUMO_ATTR_VALUE, 0, ok, myDelay);
90  break;
91  case SUMO_TAG_VIEWPORT: {
92  const SUMOReal x = attrs.getOpt<SUMOReal>(SUMO_ATTR_X, 0, ok, myLookFrom.x());
93  const SUMOReal y = attrs.getOpt<SUMOReal>(SUMO_ATTR_Y, 0, ok, myLookFrom.y());
94  const SUMOReal z = attrs.getOpt<SUMOReal>(SUMO_ATTR_ZOOM, 0, ok, myLookFrom.z());
95  myLookFrom.set(x, y, z);
96  const SUMOReal cx = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_X, 0, ok, myLookAt.x());
97  const SUMOReal cy = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Y, 0, ok, myLookAt.y());
98  const SUMOReal cz = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Z, 0, ok, myLookAt.z());
99  myLookAt.set(cx, cy, cz);
100  break;
101  }
102  case SUMO_TAG_SNAPSHOT: {
103  bool ok = true;
104  std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, 0, ok);
105  if (file != "" && !FileHelpers::isAbsolute(file)) {
107  }
108  mySnapshots[attrs.getOptSUMOTimeReporting(SUMO_ATTR_TIME, file.c_str(), ok, 0)] = file;
109  }
110  break;
112  bool ok = true;
113  mySettings.name = attrs.getOpt<std::string>(SUMO_ATTR_NAME, 0, ok, mySettings.name);
116  }
117  }
118  break;
122  break;
124  bool ok = true;
125  mySettings.backgroundColor = RGBColor::parseColorReporting(attrs.getStringSecure("backgroundColor", toString(mySettings.backgroundColor)), "background", 0, true, ok);
129  }
130  break;
132  int laneEdgeMode = TplConvert::_2int(attrs.getStringSecure("laneEdgeMode", "0").c_str());
133  int laneEdgeScaleMode = TplConvert::_2int(attrs.getStringSecure("scaleMode", "0").c_str());
146  myCurrentColorer = element;
147  mySettings.edgeColorer.setActive(laneEdgeMode);
148  mySettings.edgeScaler.setActive(laneEdgeScaleMode);
149  mySettings.laneColorer.setActive(laneEdgeMode);
150  mySettings.laneScaler.setActive(laneEdgeScaleMode);
151  }
152  break;
154  myCurrentScheme = 0;
158  if (myCurrentScheme == 0) {
160  }
161  }
164  }
167  }
170  }
172  bool ok = true;
173  myCurrentScheme->setInterpolated(attrs.getOpt<bool>(SUMO_ATTR_INTERPOLATED, 0, ok, false));
175  }
176  break;
178  myCurrentScheme = 0;
182  if (myCurrentScaleScheme == 0) {
184  }
185  }
187  bool ok = true;
190  }
191  break;
192 
193  case SUMO_TAG_ENTRY:
194  if (myCurrentScheme != 0) {
195  bool ok = true;
196  RGBColor color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, 0, ok);
197  if (myCurrentScheme->isFixed()) {
199  } else {
200  myCurrentScheme->addColor(color, attrs.getOpt<SUMOReal>(SUMO_ATTR_THRESHOLD, 0, ok, 0));
201  }
202  } else if (myCurrentScaleScheme != 0) {
203  bool ok = true;
204  SUMOReal scale = attrs.get<SUMOReal>(SUMO_ATTR_COLOR, 0, ok);
205  if (myCurrentScaleScheme->isFixed()) {
207  } else {
209  }
210  }
211  break;
213  mySettings.vehicleColorer.setActive(TplConvert::_2int(attrs.getStringSecure("vehicleMode", "0").c_str()));
218  myCurrentColorer = element;
219  break;
221  mySettings.personColorer.setActive(TplConvert::_2int(attrs.getStringSecure("personMode", "0").c_str()));
225  myCurrentColorer = element;
226  break;
228  mySettings.containerColorer.setActive(TplConvert::_2int(attrs.getStringSecure("containerMode", "0").c_str()));
232  myCurrentColorer = element;
233  break;
235  mySettings.junctionColorer.setActive(TplConvert::_2int(attrs.getStringSecure("junctionMode", "0").c_str()));
243  "drawCrossingsAndWalkingareas", toString(mySettings.drawCrossingsAndWalkingareas)).c_str());
245  myCurrentColorer = element;
246  break;
251  break;
255  break;
259  break;
262  break;
265  d.filename = attrs.getStringSecure("filename", d.filename);
266  if (d.filename != "" && !FileHelpers::isAbsolute(d.filename)) {
268  }
269  d.centerX = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_X, 0, ok, d.centerX);
270  d.centerY = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Y, 0, ok, d.centerY);
271  d.centerZ = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Z, 0, ok, d.centerZ);
272  d.width = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, 0, ok, d.width);
273  d.height = attrs.getOpt<SUMOReal>(SUMO_ATTR_HEIGHT, 0, ok, d.height);
274  d.altitude = TplConvert::_2SUMOReal(attrs.getStringSecure("altitude", toString(d.height)).c_str());
275  d.rot = TplConvert::_2SUMOReal(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
276  d.tilt = TplConvert::_2SUMOReal(attrs.getStringSecure("tilt", toString(d.tilt)).c_str());
277  d.roll = TplConvert::_2SUMOReal(attrs.getStringSecure("roll", toString(d.roll)).c_str());
278  d.layer = attrs.getOpt<SUMOReal>(SUMO_ATTR_LAYER, 0, ok, d.layer);
279  d.initialised = false;
280  myDecals.push_back(d);
281  }
282  break;
285  d.filename = "light" + attrs.getOpt<std::string>(SUMO_ATTR_INDEX, 0, ok, "0");
286  d.centerX = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_X, 0, ok, d.centerX);
287  d.centerY = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Y, 0, ok, d.centerY);
288  d.centerZ = attrs.getOpt<SUMOReal>(SUMO_ATTR_CENTER_Z, 0, ok, d.centerZ);
289  d.width = attrs.getOpt<SUMOReal>(SUMO_ATTR_WIDTH, 0, ok, d.width);
290  d.height = attrs.getOpt<SUMOReal>(SUMO_ATTR_HEIGHT, 0, ok, d.height);
291  d.altitude = TplConvert::_2SUMOReal(attrs.getStringSecure("altitude", toString(d.height)).c_str());
292  d.rot = TplConvert::_2SUMOReal(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
293  d.tilt = TplConvert::_2SUMOReal(attrs.getStringSecure("tilt", toString(d.tilt)).c_str());
294  d.roll = TplConvert::_2SUMOReal(attrs.getStringSecure("roll", toString(d.roll)).c_str());
295  d.layer = attrs.getOpt<SUMOReal>(SUMO_ATTR_LAYER, 0, ok, d.layer);
296  d.initialised = false;
297  myDecals.push_back(d);
298  }
299  break;
301  const std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
302  const std::string cmd = attrs.get<std::string>(SUMO_ATTR_COMMAND, 0, ok);
303  const SUMOReal prob = attrs.get<SUMOReal>(SUMO_ATTR_PROB, id.c_str(), ok);
304  myEventDistributions[id].add(prob, cmd);
305  }
306  break;
308  myJamSoundTime = attrs.get<SUMOReal>(SUMO_ATTR_VALUE, 0, ok);
309  break;
310  default:
311  break;
312  }
313 }
314 
315 
318  const std::string& prefix, const SUMOSAXAttributes& attrs,
319  GUIVisualizationTextSettings defaults) {
320  bool ok = true;
322  TplConvert::_2bool(attrs.getStringSecure(prefix + "_show", toString(defaults.show)).c_str()),
323  TplConvert::_2SUMOReal(attrs.getStringSecure(prefix + "_size", toString(defaults.size)).c_str()),
324  RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_color", toString(defaults.color)), "edges", 0, true, ok));
325 }
326 
327 
330  const std::string& prefix, const SUMOSAXAttributes& attrs,
331  GUIVisualizationSizeSettings defaults) {
333  TplConvert::_2SUMOReal(attrs.getStringSecure(prefix + "_minSize", toString(defaults.minSize)).c_str()),
334  TplConvert::_2SUMOReal(attrs.getStringSecure(prefix + "_exaggeration", toString(defaults.exaggeration)).c_str()),
335  TplConvert::_2bool(attrs.getStringSecure(prefix + "_constantSize", toString(defaults.constantSize)).c_str()));
336 }
337 
338 
339 std::string
341  if (mySettings.name != "") {
343  if (view) {
344  FXint index = view->getColoringSchemesCombo().appendItem(mySettings.name.c_str());
345  view->getColoringSchemesCombo().setCurrentItem(index);
347  }
348  }
349  return mySettings.name;
350 }
351 
352 
353 void
355  if (myLookFrom.z() > 0) {
356  // z value stores zoom so we must convert first
357  Position lookFrom(myLookFrom.x(), myLookFrom.y(), view->getChanger().zoom2ZPos(myLookFrom.z()));
358  view->setViewportFromTo(lookFrom, myLookAt);
359  }
360 }
361 
362 
363 void
365  if (!mySnapshots.empty()) {
366  view->setSnapshots(mySnapshots);
367  }
368 }
369 
370 
371 bool
373  return !myDecals.empty();
374 }
375 
376 
377 const std::vector<GUISUMOAbstractView::Decal>&
379  return myDecals;
380 }
381 
382 
383 SUMOReal
385  return myDelay;
386 }
387 
388 
389 std::vector<SUMOTime>
390 GUISettingsHandler::loadBreakpoints(const std::string& file) {
391  std::vector<SUMOTime> result;
392  std::ifstream strm(file.c_str());
393  while (strm.good()) {
394  std::string val;
395  strm >> val;
396  if (val.length() == 0) {
397  continue;
398  }
399  try {
400  SUMOTime value = string2time(val);
401  result.push_back(value);
402  } catch (NumberFormatException&) {
403  WRITE_ERROR(" A breakpoint-value must be an int, is:" + val);
404  } catch (ProcessError&) {
405  WRITE_ERROR(" Could not decode breakpoint '" + val + "'");
406  } catch (EmptyData&) {}
407  }
408  return result;
409 }
410 
411 
415  if (result.getOverallProb() > 0 && result.getOverallProb() < 1) {
416  // unscaled probabilities are assumed, fill up with dummy event
417  result.add(1 - result.getOverallProb(), "");
418  }
419  return result;
420 }
421 
422 
423 /****************************************************************************/
424 
GUIVisualizationSizeSettings junctionSize
GUIVisualizationTextSettings junctionName
A decal (an image) that can be shown.
GUIScaleScheme * myCurrentScaleScheme
The current scaling scheme.
GUISettingsHandler(const std::string &content, bool isFile=true)
Constructor.
GUICompleteSchemeStorage gSchemeStorage
bool showSizeLegend
Information whether the size legend shall be drawn.
long long int SUMOTime
Definition: SUMOTime.h:43
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:86
GUIVisualizationTextSettings streetName
float laneWidthExaggeration
The lane exaggeration (upscale thickness)
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.
bool showBlinker
Information whether vehicle blinkers shall be drawn.
virtual void setViewportFromTo(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
GUIVisualizationTextSettings addName
int myCurrentColorer
The last color scheme category (edges or vehicles)
GUIVisualizationTextSettings personName
GUIColorScheme * myCurrentScheme
The current color scheme.
static SUMOReal _2SUMOReal(const E *const data)
converts a char-type array into the SUMOReal value described by it
Definition: TplConvert.h:290
GUIVisualizationTextSettings poiName
static bool _2bool(const E *const data)
converts a 0-terminated char-type array into the boolean value described by it
Definition: TplConvert.h:364
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:252
GUIColorer laneColorer
The lane colorer.
GUIColorer containerColorer
The container colorer.
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
A layer number.
GUIColorer edgeColorer
The mesoscopic edge colorer.
bool showRails
Information whether rails shall be drawn.
std::vector< GUISUMOAbstractView::Decal > myDecals
The decals list to fill.
GUIVisualizationTextSettings vehicleName
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:58
Position myLookAt
The point to look at, only needed for osg view.
SUMOReal myDelay
The delay loaded.
T * getSchemeByName(std::string name)
bool hasDecals() const
Returns whether any decals have been parsed.
bool showLaneDirection
Whether to show direction indicators for lanes.
GUIVisualizationTextSettings cwaEdgeName
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
void parseString(std::string content)
SAX-handler base for SUMO-files.
static bool runParser(GenericSAXHandler &handler, const std::string &file, const bool isNet=false)
Runs the given handler on the given file; returns if everything&#39;s ok.
Definition: XMLSubSys.cpp:114
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.
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.
GUIVisualizationSizeSettings polySize
GUIColorer vehicleColorer
The vehicle colorer.
SUMOReal getDelay() const
Returns the parsed delay.
bool isFixed() const
RandomDistributor< std::string > getEventDistribution(const std::string &id)
GUIVisualizationTextSettings edgeName
void setInterpolated(const bool interpolate, SUMOReal interpolationStart=0.f)
GUIVisualizationSizeSettings addSize
std::map< SUMOTime, std::string > mySnapshots
mappig of time steps to filenames for potential snapshots
int addColor(const T &color, const SUMOReal threshold, const std::string &name="")
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.
void applyViewport(GUISUMOAbstractView *view) const
Sets the viewport which has been parsed.
float laneMinSize
The minimum visual lane width for drawing.
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 attributes for textSettings
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.
bool showSublanes
Whether to show sublane boundaries.
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()
get coloring schemes combo
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:102
SUMOTime string2time(const std::string &r)
Definition: SUMOTime.cpp:46
bool initialised
Whether this image was initialised (inserted as a texture)
GUIVisualizationTextSettings drawLinkTLIndex
GUIColorer personColorer
The person colorer.
GUIVisualizationTextSettings internalJunctionName
float minSize
The minimum size to draw this object.
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:55
GUIScaler edgeScaler
The mesoscopic edge scaler.
std::string myViewType
The view type (osg, opengl, default) loaded.
int containerQuality
The quality of container drawing.
RGBColor backgroundColor
The background color to use.
bool antialiase
Information whether antialiase shall be enabled.
void setColor(const int pos, const T &color)
virtual bool setColorScheme(const std::string &)
set color scheme
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
SUMOReal height
The height of the image (net coordinates in y-direction, in m)
GUIVisualizationSizeSettings poiSize
SUMOReal getOverallProb() const
Return the sum of the probabilites assigned to the members.
SUMOReal centerX
The center of the image in x-direction (net coordinates, in m)
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:149
float exaggeration
The size exaggeration (upscale)
bool showLinkDecals
Information whether link textures (arrows) shall be drawn.
GUIVisualizationSizeSettings containerSize
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
GUIVisualizationSizeSettings personSize
int personQuality
The quality of person drawing.
bool showGrid
Information whether a grid shall be shown.
bool drawCrossingsAndWalkingareas
whether crosings and walkingareas shall be drawn
GUIPerspectiveChanger & getChanger() const
get changer
SUMOReal layer
The layer of the image.
bool showLane2Lane
Information whether lane-to-lane arrows shall be drawn.
std::map< std::string, RandomDistributor< std::string > > myEventDistributions
The parsed event distributions.
#define SUMOReal
Definition: config.h:213
GUIVisualizationSizeSettings vehicleSize
bool drawJunctionShape
whether the shape of the junction should be drawn
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.
GUIScaler laneScaler
The lane scaler.
virtual SUMOReal zoom2ZPos(SUMOReal zoom) const =0
Returns the camera height at which the given zoom level is reached.
A color information.
GUIVisualizationTextSettings drawLinkJunctionIndex
GUIVisualizationSizeSettings parseSizeSettings(const std::string &prefix, const SUMOSAXAttributes &attrs, GUIVisualizationSizeSettings defaults)
parse attributes for sizeSettings
Position myLookFrom
The viewport loaded, zoom is stored in z coordinate.
SUMOReal rot
The rotation of the image in the ground plane (in degrees)
void add(const GUIVisualizationSettings &scheme)
Adds a visualization scheme.
GUIVisualizationTextSettings polyName
GUIVisualizationTextSettings containerName