SUMO - Simulation of Urban MObility
GUISettingsHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // The dialog to change the view (gui) settings.
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 <vector>
35 #include <utils/common/ToString.h>
36 #include <utils/common/RGBColor.h>
44 #include <utils/xml/XMLSubSys.h>
45 #include "GUISettingsHandler.h"
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 GUISettingsHandler::GUISettingsHandler(const std::string& content, bool isFile, bool netedit) :
52  SUMOSAXHandler(content),
53  mySettings(netedit),
54  myDelay(-1), myLookFrom(-1, -1, -1), myLookAt(-1, -1, -1),
55  myCurrentColorer(SUMO_TAG_NOTHING),
56  myCurrentScheme(0),
57  myJamSoundTime(-1) {
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<double>(SUMO_ATTR_VALUE, 0, ok, myDelay);
89  break;
90  case SUMO_TAG_VIEWPORT: {
91  const double x = attrs.getOpt<double>(SUMO_ATTR_X, 0, ok, myLookFrom.x());
92  const double y = attrs.getOpt<double>(SUMO_ATTR_Y, 0, ok, myLookFrom.y());
93  const double z = attrs.getOpt<double>(SUMO_ATTR_ZOOM, 0, ok, myLookFrom.z());
94  myLookFrom.set(x, y, z);
95  const double cx = attrs.getOpt<double>(SUMO_ATTR_CENTER_X, 0, ok, myLookAt.x());
96  const double cy = attrs.getOpt<double>(SUMO_ATTR_CENTER_Y, 0, ok, myLookAt.y());
97  const double cz = attrs.getOpt<double>(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)].push_back(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;
120  break;
122  bool ok = true;
123  mySettings.backgroundColor = RGBColor::parseColorReporting(attrs.getStringSecure("backgroundColor", toString(mySettings.backgroundColor)), "background", 0, true, ok);
127  }
128  break;
130  int laneEdgeMode = TplConvert::_2int(attrs.getStringSecure("laneEdgeMode", "0").c_str());
131  int laneEdgeScaleMode = TplConvert::_2int(attrs.getStringSecure("scaleMode", "0").c_str());
145  myCurrentColorer = element;
146  mySettings.edgeColorer.setActive(laneEdgeMode);
147  mySettings.edgeScaler.setActive(laneEdgeScaleMode);
148  mySettings.laneColorer.setActive(laneEdgeMode);
149  mySettings.laneScaler.setActive(laneEdgeScaleMode);
150  }
151  break;
153  myCurrentScheme = 0;
157  if (myCurrentScheme == 0) {
159  }
160  }
163  }
166  }
169  }
171  bool ok = true;
172  myCurrentScheme->setInterpolated(attrs.getOpt<bool>(SUMO_ATTR_INTERPOLATED, 0, ok, false));
174  }
175  break;
177  myCurrentScheme = 0;
181  if (myCurrentScaleScheme == 0) {
183  }
184  }
186  bool ok = true;
189  }
190  break;
191 
192  case SUMO_TAG_ENTRY:
193  if (myCurrentScheme != 0) {
194  bool ok = true;
195  RGBColor color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, 0, ok);
196  if (myCurrentScheme->isFixed()) {
198  } else {
199  myCurrentScheme->addColor(color, attrs.getOpt<double>(SUMO_ATTR_THRESHOLD, 0, ok, 0));
200  }
201  } else if (myCurrentScaleScheme != 0) {
202  bool ok = true;
203  double scale = attrs.get<double>(SUMO_ATTR_COLOR, 0, ok);
204  if (myCurrentScaleScheme->isFixed()) {
206  } else {
207  myCurrentScaleScheme->addColor(scale, attrs.getOpt<double>(SUMO_ATTR_THRESHOLD, 0, ok, 0));
208  }
209  }
210  break;
212  mySettings.vehicleColorer.setActive(TplConvert::_2int(attrs.getStringSecure("vehicleMode", "0").c_str()));
217  myCurrentColorer = element;
218  break;
220  mySettings.personColorer.setActive(TplConvert::_2int(attrs.getStringSecure("personMode", "0").c_str()));
224  myCurrentColorer = element;
225  break;
227  mySettings.containerColorer.setActive(TplConvert::_2int(attrs.getStringSecure("containerMode", "0").c_str()));
231  myCurrentColorer = element;
232  break;
234  mySettings.junctionColorer.setActive(TplConvert::_2int(attrs.getStringSecure("junctionMode", "0").c_str()));
242  "drawCrossingsAndWalkingareas", toString(mySettings.drawCrossingsAndWalkingareas)).c_str());
244  myCurrentColorer = element;
245  break;
251  break;
256  break;
261  break;
264  break;
267  d.filename = attrs.getStringSecure("filename", d.filename);
268  if (d.filename != "" && !FileHelpers::isAbsolute(d.filename)) {
270  }
271  d.centerX = attrs.getOpt<double>(SUMO_ATTR_CENTER_X, 0, ok, d.centerX);
272  d.centerY = attrs.getOpt<double>(SUMO_ATTR_CENTER_Y, 0, ok, d.centerY);
273  d.centerZ = attrs.getOpt<double>(SUMO_ATTR_CENTER_Z, 0, ok, d.centerZ);
274  d.width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, 0, ok, d.width);
275  d.height = attrs.getOpt<double>(SUMO_ATTR_HEIGHT, 0, ok, d.height);
276  d.altitude = TplConvert::_2double(attrs.getStringSecure("altitude", toString(d.height)).c_str());
277  d.rot = TplConvert::_2double(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
278  d.tilt = TplConvert::_2double(attrs.getStringSecure("tilt", toString(d.tilt)).c_str());
279  d.roll = TplConvert::_2double(attrs.getStringSecure("roll", toString(d.roll)).c_str());
280  d.layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, 0, ok, d.layer);
281  d.screenRelative = TplConvert::_2bool(attrs.getStringSecure("screenRelative", toString(d.screenRelative)).c_str());
282  d.initialised = false;
283  myDecals.push_back(d);
284  }
285  break;
288  d.filename = "light" + attrs.getOpt<std::string>(SUMO_ATTR_INDEX, 0, ok, "0");
289  d.centerX = attrs.getOpt<double>(SUMO_ATTR_CENTER_X, 0, ok, d.centerX);
290  d.centerY = attrs.getOpt<double>(SUMO_ATTR_CENTER_Y, 0, ok, d.centerY);
291  d.centerZ = attrs.getOpt<double>(SUMO_ATTR_CENTER_Z, 0, ok, d.centerZ);
292  d.width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, 0, ok, d.width);
293  d.height = attrs.getOpt<double>(SUMO_ATTR_HEIGHT, 0, ok, d.height);
294  d.altitude = TplConvert::_2double(attrs.getStringSecure("altitude", toString(d.height)).c_str());
295  d.rot = TplConvert::_2double(attrs.getStringSecure("rotation", toString(d.rot)).c_str());
296  d.tilt = TplConvert::_2double(attrs.getStringSecure("tilt", toString(d.tilt)).c_str());
297  d.roll = TplConvert::_2double(attrs.getStringSecure("roll", toString(d.roll)).c_str());
298  d.layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, 0, ok, d.layer);
299  d.initialised = false;
300  myDecals.push_back(d);
301  }
302  break;
304  const std::string id = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
305  const std::string cmd = attrs.get<std::string>(SUMO_ATTR_COMMAND, 0, ok);
306  const double prob = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
307  myEventDistributions[id].add(cmd, prob);
308  }
309  break;
311  myJamSoundTime = attrs.get<double>(SUMO_ATTR_VALUE, 0, ok);
312  break;
313  default:
314  break;
315  }
316 }
317 
318 
321  const std::string& prefix, const SUMOSAXAttributes& attrs,
322  GUIVisualizationTextSettings defaults) {
323  bool ok = true;
325  TplConvert::_2bool(attrs.getStringSecure(prefix + "_show", toString(defaults.show)).c_str()),
326  TplConvert::_2double(attrs.getStringSecure(prefix + "_size", toString(defaults.size)).c_str()),
327  RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_color", toString(defaults.color)), "edges", 0, true, ok));
328 }
329 
330 
333  const std::string& prefix, const SUMOSAXAttributes& attrs,
334  GUIVisualizationSizeSettings defaults) {
336  TplConvert::_2double(attrs.getStringSecure(prefix + "_minSize", toString(defaults.minSize)).c_str()),
337  TplConvert::_2double(attrs.getStringSecure(prefix + "_exaggeration", toString(defaults.exaggeration)).c_str()),
338  TplConvert::_2bool(attrs.getStringSecure(prefix + "_constantSize", toString(defaults.constantSize)).c_str()));
339 }
340 
341 
342 std::string
344  if (mySettings.name != "") {
346  if (view) {
347  FXint index = view->getColoringSchemesCombo().appendItem(mySettings.name.c_str());
348  view->getColoringSchemesCombo().setCurrentItem(index);
350  }
351  }
352  return mySettings.name;
353 }
354 
355 
356 void
358  if (myLookFrom.z() > 0) {
359  // z value stores zoom so we must convert first
360  Position lookFrom(myLookFrom.x(), myLookFrom.y(), view->getChanger().zoom2ZPos(myLookFrom.z()));
361  view->setViewportFromTo(lookFrom, myLookAt);
362  }
363 }
364 
365 
366 void
368  if (!mySnapshots.empty()) {
369  for (auto item : mySnapshots) {
370  for (auto file : item.second) {
371  view->addSnapshot(item.first, file);
372  }
373  }
374  }
375 }
376 
377 
378 bool
380  return !myDecals.empty();
381 }
382 
383 
384 const std::vector<GUISUMOAbstractView::Decal>&
386  return myDecals;
387 }
388 
389 
390 double
392  return myDelay;
393 }
394 
395 
396 std::vector<SUMOTime>
397 GUISettingsHandler::loadBreakpoints(const std::string& file) {
398  std::vector<SUMOTime> result;
399  std::ifstream strm(file.c_str());
400  while (strm.good()) {
401  std::string val;
402  strm >> val;
403  if (val.length() == 0) {
404  continue;
405  }
406  try {
407  SUMOTime value = string2time(val);
408  result.push_back(value);
409  } catch (NumberFormatException&) {
410  WRITE_ERROR(" A breakpoint-value must be an int, is:" + val);
411  } catch (ProcessError&) {
412  WRITE_ERROR(" Could not decode breakpoint '" + val + "'");
413  } catch (EmptyData&) {}
414  }
415  return result;
416 }
417 
418 
422  if (result.getOverallProb() > 0 && result.getOverallProb() < 1) {
423  // unscaled probabilities are assumed, fill up with dummy event
424  result.add("", 1. - result.getOverallProb());
425  }
426  return result;
427 }
428 
429 
430 /****************************************************************************/
431 
GUIVisualizationSizeSettings junctionSize
const std::vector< GUISUMOAbstractView::Decal > & getDecals() const
Returns the parsed decals.
GUIVisualizationTextSettings junctionName
A decal (an image) that can be shown.
GUIScaleScheme * myCurrentScaleScheme
The current scaling scheme.
double altitude
The altitude of the image (net coordinates in z-direction, in m)
GUICompleteSchemeStorage gSchemeStorage
bool showSizeLegend
Information whether the size legend shall be drawn.
GUIVisualizationTextSettings poiType
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:81
GUIVisualizationTextSettings streetName
double laneWidthExaggeration
The lane exaggeration (upscale thickness)
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag.
bool showBlinker
Information whether vehicle blinkers shall be drawn.
double z() const
Returns the z-position.
Definition: Position.h:72
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.
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:388
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:259
virtual double zoom2ZPos(double zoom) const =0
Returns the camera height at which the given zoom level is reached.
double exaggeration
The size exaggeration (upscale)
GUIColorer laneColorer
The lane colorer.
GUIColorer containerColorer
The container colorer.
A layer number.
GUIColorer edgeColorer
The mesoscopic edge colorer.
const std::string & getFileName() const
returns the current file name
double y() const
Returns the y-position.
Definition: Position.h:67
bool showRails
Information whether rails shall be drawn.
std::vector< GUISUMOAbstractView::Decal > myDecals
The decals list to fill.
void addSnapshot(SUMOTime time, const std::string &file)
Sets the snapshot time to file map.
GUIVisualizationTextSettings vehicleName
double x() const
Returns the x-position.
Definition: Position.h:62
double centerX
The center of the image in x-direction (net coordinates, in m)
SAX-reader encapsulation containing binary reader.
Definition: SUMOSAXReader.h:57
Position myLookAt
The point to look at, only needed for osg view.
bool screenRelative
Whether this image should be skipped in 2D-views.
T * getSchemeByName(std::string name)
bool showLaneDirection
Whether to show direction indicators for lanes.
GUIVisualizationTextSettings cwaEdgeName
bool laneShowBorders
Information whether lane borders shall be drawn.
static std::vector< SUMOTime > loadBreakpoints(const std::string &file)
loads breakpoints from the specified file
bool hasDecals() const
Returns whether any decals have been parsed.
bool showLinkRules
Information whether link rules (colored bars) shall be drawn.
void parseString(std::string content)
void set(double x, double y)
set positions x and y
Definition: Position.h:92
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:109
bool dither
Information whether dithering shall be enabled.
double height
The height of the image (net coordinates in y-direction, in m)
double myDelay
The delay loaded.
double getDelay() const
Returns the parsed delay.
double layer
The layer of the image.
GUIVisualizationSettings mySettings
The settings to fill.
GUIVisualizationSizeSettings polySize
GUIColorer vehicleColorer
The vehicle colorer.
double roll
The roll of the image to the ground plane (in degrees)
RandomDistributor< std::string > getEventDistribution(const std::string &id)
GUIVisualizationTextSettings edgeName
GUIVisualizationSizeSettings addSize
GUISettingsHandler(const std::string &content, bool isFile=true, bool netedit=false)
Constructor.
void setFileName(const std::string &name)
Sets the current file name.
int addColor(const T &color, const double threshold, const std::string &name="")
std::string name
The name of this setting.
double gridXSize
Information about the grid spacings.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
double minSize
The minimum size to draw this object.
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
GUIVisualizationTextSettings internalEdgeName
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
Definition: FileHelpers.cpp:96
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
GUIVisualizationTextSettings parseTextSettings(const std::string &prefix, const SUMOSAXAttributes &attrs, GUIVisualizationTextSettings defaults)
parse attributes for textSettings
int addMode
The additional structures visualization scheme.
double rot
The rotation of the image in the ground plane (in degrees)
GUIVisualizationTextSettings polyType
bool showSublanes
Whether to show sublane boundaries.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
GUIPerspectiveChanger & getChanger() const
get changer
FXComboBox & getColoringSchemesCombo()
get coloring schemes combo
static SUMOSAXReader * getSAXReader(SUMOSAXHandler &handler)
Builds a reader and assigns the handler to it.
Definition: XMLSubSys.cpp:97
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
double centerY
The center of the image in y-direction (net coordinates, in m)
GUIColorer junctionColorer
The junction colorer.
~GUISettingsHandler()
Destructor.
std::string filename
The path to the file the image is located at.
double laneMinSize
The minimum visual lane width for drawing.
GUIScaler edgeScaler
The mesoscopic edge scaler.
void setSnapshots(GUISUMOAbstractView *view) const
Makes a snapshot if it has been parsed.
std::string myViewType
The view type (osg, opengl, default) loaded.
int containerQuality
The quality of container drawing.
RGBColor backgroundColor
The background color to use.
std::string addSettings(GUISUMOAbstractView *view=0) const
Adds the parsed settings to the global list of settings.
double width
The width of the image (net coordinates in x-direction, in m)
void setColor(const int pos, const T &color)
virtual bool setColorScheme(const std::string &)
set color scheme
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
GUIVisualizationSizeSettings poiSize
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
Definition: TplConvert.h:155
trigger: the time of the step
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.
bool showLinkDecals
Information whether link textures (arrows) shall be drawn.
GUIVisualizationSizeSettings containerSize
void applyViewport(GUISUMOAbstractView *view) const
Sets the viewport which has been parsed.
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
GUIVisualizationTextSettings addFullName
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.
virtual std::string getStringSecure(int id, const std::string &def) const =0
Returns the string-value of the named (by its enum-value) attribute.
double centerZ
The center of the image in z-direction (net coordinates, in m)
static double _2double(const E *const data)
converts a char-type array into the double value described by it
Definition: TplConvert.h:311
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
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
double tilt
The tilt of the image to the ground plane (in degrees)
std::map< SUMOTime, std::vector< std::string > > mySnapshots
mappig of time steps to filenames for potential snapshots
bool showLane2Lane
Information whether lane-to-lane arrows shall be drawn.
std::map< std::string, RandomDistributor< std::string > > myEventDistributions
The parsed event distributions.
GUIVisualizationSizeSettings vehicleSize
long long int SUMOTime
Definition: TraCIDefs.h:51
bool drawJunctionShape
whether the shape of the junction should be drawn
int vehicleQuality
The quality of vehicle drawing.
std::vector< SUMOTime > myBreakpoints
The parsed breakpoints.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
GUIScaler laneScaler
The lane scaler.
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.
void setInterpolated(const bool interpolate, double interpolationStart=0.f)
void add(const GUIVisualizationSettings &scheme)
Adds a visualization scheme.
GUIVisualizationTextSettings polyName
GUIVisualizationTextSettings containerName