SUMO - Simulation of Urban MObility
GUIContainer.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A MSContainer extended by some values for usage within the gui
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <cmath>
33 #include <vector>
34 #include <string>
36 #include <microsim/MSContainer.h>
46 #include <utils/geom/GeomHelper.h>
52 #include <utils/gui/div/GLHelper.h>
56 #include <gui/GUIGlobals.h>
57 #include "GUIContainer.h"
58 #include "GUINet.h"
59 #include "GUIEdge.h"
61 
62 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
63 
64 // ===========================================================================
65 // FOX callback mapping
66 // ===========================================================================
67 /*
68 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
69  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdShowAllRoutes),
70  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdHideAllRoutes),
71  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdShowCurrentRoute),
72  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdHideCurrentRoute),
73  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdShowBestLanes),
74  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdHideBestLanes),
75  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStartTrack),
76  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStopTrack),
77  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdShowLFLinkItems),
78  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdHideLFLinkItems),
79 };
80 
81 // Object implementation
82 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
83 */
84 
85 #define WATER_WAY_OFFSET 6.0
86 
87 // ===========================================================================
88 // method definitions
89 // ===========================================================================
90 /* -------------------------------------------------------------------------
91  * GUIContainer::GUIContainerPopupMenu - methods
92  * ----------------------------------------------------------------------- */
94  GUIMainWindow& app, GUISUMOAbstractView& parent,
95  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
96  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
97 }
98 
99 
101 
102 
103 
104 /* -------------------------------------------------------------------------
105  * GUIContainer - methods
106  * ----------------------------------------------------------------------- */
108  MSContainer(pars, vtype, plan),
109  GUIGlObject(GLO_CONTAINER, pars->id) {
110 }
111 
112 
114 }
115 
116 
119  GUISUMOAbstractView& parent) {
121  buildPopupHeader(ret, app);
125  //
127  buildPositionCopyEntry(ret, false);
128  return ret;
129 }
130 
131 
136  new GUIParameterTableWindow(app, *this, 8);
137  // add items
138  //ret->mkItem("type [NAME]", false, myType->getID());
139  ret->mkItem("stage", false, getCurrentStageDescription());
140  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
141  ret->mkItem("dest edge [id]", false, getDestination().getID());
142  ret->mkItem("edge [id]", false, getEdge()->getID());
143  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getEdgePos));
144  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getSpeed));
145  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getAngle));
146  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getWaitingSeconds));
147  // close building
148  ret->closeBuilding();
149  return ret;
150 }
151 
152 
153 Boundary
155  Boundary b;
156  // ensure that the vehicle is drawn, otherwise myPositionInVehicle will not be updated
157  b.add(getPosition());
158  b.grow(20);
159  return b;
160 }
161 
162 
163 void
165  glPushName(getGlID());
166  glPushMatrix();
167  Position p1 = getPosition();
169  p1 = myPositionInVehicle;
170  }
171  glTranslated(p1.x(), p1.y(), getType());
172  glRotated(90, 0, 0, 1);
173  // XXX use container specific gui settings
174  // set container color
175  setColor(s);
176  // scale
177  const double upscale = s.containerSize.getExaggeration(s);
178  glScaled(upscale, upscale, 1);
179  switch (s.containerQuality) {
180  case 0:
181  case 1:
182  case 2:
184  break;
185  case 3:
186  default:
188  break;
189  }
190  glPopMatrix();
191 
192  drawName(p1, s.scale, s.containerName);
193  glPopName();
194 }
195 
196 
197 void
199  glPushName(getGlID());
200  glPushMatrix();
201  /*
202  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
203  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
204  drawBestLanes();
205  }
206  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
207  drawRoute(s, 0, 0.25);
208  }
209  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
210  if (getNumberReroutes() > 0) {
211  const int noReroutePlus1 = getNumberReroutes() + 1;
212  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
213  double darken = double(0.4) / double(noReroutePlus1) * double(i);
214  drawRoute(s, i, darken);
215  }
216  } else {
217  drawRoute(s, 0, 0.25);
218  }
219  }
220  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
221  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
222  if((*i).myLink==0) {
223  continue;
224  }
225  MSLink* link = (*i).myLink;
226  MSLane *via = link->getViaLane();
227  if (via == 0) {
228  via = link->getLane();
229  }
230  if (via != 0) {
231  Position p = via->getShape()[0];
232  if((*i).mySetRequest) {
233  glColor3f(0, 1, 0);
234  } else {
235  glColor3f(1, 0, 0);
236  }
237  glTranslated(p.x(), p.y(), -.1);
238  GLHelper::drawFilledCircle(1);
239  glTranslated(-p.x(), -p.y(), .1);
240  }
241  }
242  }
243  */
244  glPopMatrix();
245  glPopName();
246 }
247 
248 
249 
250 
251 void
253  const GUIColorer& c = s.containerColorer;
254  if (!setFunctionalColor(c.getActive())) {
256  }
257 }
258 
259 
260 bool
261 GUIContainer::setFunctionalColor(int activeScheme) const {
262  switch (activeScheme) {
263  case 0: {
264  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
266  return true;
267  }
268  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
269  GLHelper::setColor(getVehicleType().getColor());
270  return true;
271  }
272  return false;
273  }
274  case 2: {
275  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
277  return true;
278  }
279  return false;
280  }
281  case 3: {
282  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
283  GLHelper::setColor(getVehicleType().getColor());
284  return true;
285  }
286  return false;
287  }
288  case 8: {
289  double hue = GeomHelper::naviDegree(getAngle());
291  return true;
292  }
293  default:
294  return false;
295  }
296 }
297 
298 
299 double
300 GUIContainer::getColorValue(int activeScheme) const {
301  switch (activeScheme) {
302  case 4:
303  return getSpeed();
304  case 5:
305  if (isWaiting4Vehicle()) {
306  return 3;
307  } else {
308  return (double)getCurrentStageType();
309  }
310  case 6:
311  return getWaitingSeconds();
312  case 7:
314  }
315  return 0;
316 }
317 
318 
319 double
322  return MSContainer::getEdgePos();
323 }
324 
325 
326 Position
329  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
330  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
331  PositionVector laneShape = lane->getShape();
332  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
333  }
334  return MSContainer::getPosition();
335 }
336 
337 
338 double
341  return MSContainer::getAngle();
342 }
343 
344 
345 double
349 }
350 
351 
352 double
355  return MSContainer::getSpeed();
356 }
357 
358 
359 void
361  // draw pedestrian shape
362  glRotated(RAD2DEG(getAngle() + PI / 2.), 0, 0, 1);
363  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
364  glBegin(GL_QUADS);
365  glVertex2d(0, 0.5);
366  glVertex2d(0, -0.5);
367  glVertex2d(-1, -0.5);
368  glVertex2d(-1, 0.5);
369  glEnd();
370  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
371  glTranslated(0, 0, .045);
372  glBegin(GL_QUADS);
373  glVertex2d(-0.1, 0.4);
374  glVertex2d(-0.1, -0.4);
375  glVertex2d(-0.9, -0.4);
376  glVertex2d(-0.9, 0.4);
377  glEnd();
378 }
379 
380 
381 void
383  const std::string& file = getVehicleType().getImgFile();
384  if (file != "") {
385  // @todo invent an option for controlling whether images should be rotated or not
386  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
387  // glRotated(RAD2DEG(getAngle() + PI / 2.), 0, 0, 1);
388  //}
389  int textureID = GUITexturesHelper::getTextureID(file);
390  if (textureID > 0) {
391  const double exaggeration = s.personSize.getExaggeration(s);
392  const double halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
393  const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
394  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
395  }
396  } else {
397  // fallback if no image is defined
399  }
400 }
401 /****************************************************************************/
402 
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double getAngle() const
return the current angle of the container
double scale
information about a lane&#39;s width (temporary, used for a single view)
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
double getWaitingSeconds() const
the time this container spent waiting in seconds
const MSEdge * getEdge() const
Returns the current edge.
const MSEdge & getDestination() const
Returns the current destination.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:290
virtual double getEdgePos() const
Return the position on the edge.
GUIContainerPopupMenu()
default constructor needed by FOX
Definition: GUIContainer.h:174
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
GUIColorer containerColorer
The container colorer.
Stores the information about how to visualize structures.
double y() const
Returns the y-position.
Definition: Position.h:68
double x() const
Returns the x-position.
Definition: Position.h:63
std::string getImgFile() const
Get this vehicle type&#39;s raster model file name.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:192
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIContainer.h:188
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:426
#define RAD2DEG(x)
Definition: GeomHelper.h:46
double getEdgePos() const
return the offset from the start of the current edge
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual double getSpeed() const
the current speed of the transportable
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
const SUMOVehicleParameter & getParameter() const
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used, also builds an entry for copying the geo-position.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
The car-following model and parameter.
Definition: MSVehicleType.h:74
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIContainer.h:181
const MSEdge * getFromEdge() const
Returns the departure edge.
GUIContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan)
Constructor.
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
a container
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:187
#define PI
Definition: polyfonts.c:61
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:439
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
virtual double getAngle() const
return the current angle of the transportable
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
const std::string & getID() const
returns the id of the transportable
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:234
Position getPosition() const
return the Network coordinate of the container
const T getColor(const double value) const
bool setFunctionalColor(int activeScheme) const
sets the color according to the current scheme index and some vehicle function
const int VEHPARS_COLOR_SET
int containerQuality
The quality of container drawing.
is an arbitrary ship
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
Structure representing possible vehicle parameter.
Position myPositionInVehicle
The position of a container while riding a vehicle.
Definition: GUIContainer.h:191
virtual Position getPosition() const
Return the Network coordinate of the transportable.
GUIVisualizationSizeSettings containerSize
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
void drawAction_drawAsPoly(const GUIVisualizationSettings &s) const
GUIVisualizationSizeSettings personSize
double getLength() const
Get vehicle&#39;s length [m].
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
const MSVehicleType & getVehicleType() const
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
#define WATER_WAY_OFFSET
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:86
double getColorValue(int activeScheme) const
gets the color value according to the current scheme index
~GUIContainer()
destructor
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
GUISelectedStorage gSelected
A global holder of selected objects.
void closeBuilding()
Closes the building of the table.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
A window containing a gl-object&#39;s parameter.
const int VTYPEPARS_COLOR_SET
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
double getSpeed() const
the current speed of the container
StageType getCurrentStageType() const
the current stage type of the transportable
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:445
GUIVisualizationTextSettings containerName