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-2015 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 #ifdef CHECK_MEMORY_LEAKS
63 #include <foreign/nvwa/debug_new.h>
64 #endif // CHECK_MEMORY_LEAKS
65 
66 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
67 
68 // ===========================================================================
69 // FOX callback mapping
70 // ===========================================================================
71 /*
72 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
73  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdShowAllRoutes),
74  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdHideAllRoutes),
75  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdShowCurrentRoute),
76  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdHideCurrentRoute),
77  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdShowBestLanes),
78  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdHideBestLanes),
79  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStartTrack),
80  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStopTrack),
81  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdShowLFLinkItems),
82  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdHideLFLinkItems),
83 };
84 
85 // Object implementation
86 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
87 */
88 
89 #define WATER_WAY_OFFSET 6.0
90 
91 // ===========================================================================
92 // method definitions
93 // ===========================================================================
94 /* -------------------------------------------------------------------------
95  * GUIContainer::GUIContainerPopupMenu - methods
96  * ----------------------------------------------------------------------- */
98  GUIMainWindow& app, GUISUMOAbstractView& parent,
99  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
100  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
101 }
102 
103 
105 
106 
107 
108 /* -------------------------------------------------------------------------
109  * GUIContainer - methods
110  * ----------------------------------------------------------------------- */
112  MSContainer(pars, vtype, plan),
113  GUIGlObject(GLO_CONTAINER, pars->id)
114 { }
115 
116 
118 }
119 
120 
123  GUISUMOAbstractView& parent) {
125  buildPopupHeader(ret, app);
129  //
131  buildPositionCopyEntry(ret, false);
132  return ret;
133 }
134 
135 
140  new GUIParameterTableWindow(app, *this, 8);
141  // add items
142  //ret->mkItem("type [NAME]", false, myType->getID());
143  ret->mkItem("stage", false, getCurrentStageDescription());
144  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
145  ret->mkItem("dest edge [id]", false, getDestination().getID());
146  ret->mkItem("edge [id]", false, getEdge()->getID());
147  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getEdgePos));
148  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getSpeed));
149  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getAngle));
150  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getWaitingSeconds));
151  // close building
152  ret->closeBuilding();
153  return ret;
154 }
155 
156 
157 Boundary
159  Boundary b;
160  // ensure that the vehicle is drawn, otherwise myPositionInVehicle will not be updated
162  b.add(getVehicle()->getPosition());
163  } else {
164  b.add(getPosition());
165  }
166  b.grow(20);
167  return b;
168 }
169 
170 
171 void
173  glPushName(getGlID());
174  glPushMatrix();
175  Position p1 = getPosition();
176  glTranslated(p1.x(), p1.y(), getType());
177  glRotated(90, 0, 0, 1);
178  // XXX use container specific gui settings
179  // set container color
180  setColor(s);
181  // scale
182  const SUMOReal upscale = s.containerSize.getExaggeration(s);
183  glScaled(upscale, upscale, 1);
184  switch (s.containerQuality) {
185  case 0:
186  case 1:
187  case 2:
189  break;
190  case 3:
191  default:
193  break;
194  }
195  glPopMatrix();
196 
197  drawName(p1, s.scale, s.containerName);
198  glPopName();
199 }
200 
201 
202 void
204  glPushName(getGlID());
205  glPushMatrix();
206  /*
207  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
208  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
209  drawBestLanes();
210  }
211  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
212  drawRoute(s, 0, 0.25);
213  }
214  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
215  if (getNumberReroutes() > 0) {
216  const int noReroutePlus1 = getNumberReroutes() + 1;
217  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
218  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
219  drawRoute(s, i, darken);
220  }
221  } else {
222  drawRoute(s, 0, 0.25);
223  }
224  }
225  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
226  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
227  if((*i).myLink==0) {
228  continue;
229  }
230  MSLink* link = (*i).myLink;
231  #ifdef HAVE_INTERNAL_LANES
232  MSLane *via = link->getViaLane();
233  if (via == 0) {
234  via = link->getLane();
235  }
236  #else
237  MSLane *via = link->getLane();
238  #endif
239  if (via != 0) {
240  Position p = via->getShape()[0];
241  if((*i).mySetRequest) {
242  glColor3f(0, 1, 0);
243  } else {
244  glColor3f(1, 0, 0);
245  }
246  glTranslated(p.x(), p.y(), -.1);
247  GLHelper::drawFilledCircle(1);
248  glTranslated(-p.x(), -p.y(), .1);
249  }
250  }
251  }
252  */
253  glPopMatrix();
254  glPopName();
255 }
256 
257 
258 
259 
260 void
262  const GUIColorer& c = s.containerColorer;
263  if (!setFunctionalColor(c.getActive())) {
265  }
266 }
267 
268 
269 bool
270 GUIContainer::setFunctionalColor(size_t activeScheme) const {
271  switch (activeScheme) {
272  case 0: {
273  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
275  return true;
276  }
277  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
278  GLHelper::setColor(getVehicleType().getColor());
279  return true;
280  }
281  return false;
282  }
283  case 2: {
284  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
286  return true;
287  }
288  return false;
289  }
290  case 3: {
291  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
292  GLHelper::setColor(getVehicleType().getColor());
293  return true;
294  }
295  return false;
296  }
297  case 8: {
300  return true;
301  }
302  default:
303  return false;
304  }
305 }
306 
307 
308 SUMOReal
309 GUIContainer::getColorValue(size_t activeScheme) const {
310  switch (activeScheme) {
311  case 4:
312  return getSpeed();
313  case 5:
314  if (isWaiting4Vehicle()) {
315  return 3;
316  } else {
317  return (SUMOReal)getCurrentStageType();
318  }
319  case 6:
320  return getWaitingSeconds();
321  case 7:
323  }
324  return 0;
325 }
326 
327 
328 SUMOReal
331  return MSContainer::getEdgePos();
332 }
333 
334 
335 Position
339  return myPositionInVehicle;
340  }
341  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
342  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
343  PositionVector laneShape = lane->getShape();
344  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
345  }
346  return MSContainer::getPosition();
347 }
348 
349 
350 SUMOReal
353  return MSContainer::getAngle();
354 }
355 
356 
357 SUMOReal
361 }
362 
363 
364 SUMOReal
367  return MSContainer::getSpeed();
368 }
369 
370 
371 void
373  // draw pedestrian shape
374  glRotated(RAD2DEG(getAngle() + PI / 2.), 0, 0, 1);
375  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
376  glBegin(GL_QUADS);
377  glVertex2d(0, 0.5);
378  glVertex2d(0, -0.5);
379  glVertex2d(-1, -0.5);
380  glVertex2d(-1, 0.5);
381  glEnd();
382  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
383  glTranslated(0, 0, .045);
384  glBegin(GL_QUADS);
385  glVertex2d(-0.1, 0.4);
386  glVertex2d(-0.1, -0.4);
387  glVertex2d(-0.9, -0.4);
388  glVertex2d(-0.9, 0.4);
389  glEnd();
390 }
391 
392 
393 void
395  const std::string& file = getVehicleType().getImgFile();
396  if (file != "") {
397  // @todo invent an option for controlling whether images should be rotated or not
398  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
399  // glRotated(RAD2DEG(getAngle() + PI / 2.), 0, 0, 1);
400  //}
401  int textureID = GUITexturesHelper::getTextureID(file);
402  if (textureID > 0) {
403  const SUMOReal exaggeration = s.personSize.getExaggeration(s);
404  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
405  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
406  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
407  }
408  } else {
409  // fallback if no image is defined
411  }
412 }
413 /****************************************************************************/
414 
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:294
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:186
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
GUIContainerPopupMenu()
default constructor needed by FOX
Definition: GUIContainer.h:174
const SUMOVehicleParameter & getParameter() const
GUIColorer containerColorer
The container colorer.
virtual SUMOReal getWaitingSeconds() const
the time this transportable spent waiting in seconds
Stores the information about how to visualize structures.
SUMOVehicle * getVehicle() const
The vehicle associated with this transportable.
SUMOReal getLength() const
Get vehicle&#39;s length [m].
SUMOReal getAngle() const
return the current angle of the container
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
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 std::string & getID() const
returns the id of the transportable
#define RAD2DEG(x)
Definition: GeomHelper.h:46
virtual SUMOReal getEdgePos() const
Return the position on the edge.
SUMOReal getColorValue(size_t activeScheme) const
gets the color value according to the current scheme index
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual SUMOReal getAngle() const
return the current angle of the transportable
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
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.
Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:123
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool setFunctionalColor(size_t activeScheme) const
sets the color according to the current scheme index and some vehicle function
The car-following model and parameter.
Definition: MSVehicleType.h:74
SUMOReal getSpeed() const
the current speed of the container
SUMOReal scale
information about a lane&#39;s width (temporary, used for a single view)
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIContainer.h:181
GUIContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan)
Constructor.
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:167
a container
const MSVehicleType & getVehicleType() const
#define PI
Definition: polyfonts.c:61
static void drawTexturedBox(unsigned int which, SUMOReal size)
Draws a named texture as a box with the given size.
const MSEdge * getEdge() const
Returns the current edge.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:443
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
StageType getCurrentStageType() const
the current stage type 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)
const T getColor(const SUMOReal value) const
Position getPosition() const
return the Network coordinate of the container
SUMOReal getEdgePos() const
return the offset from the start of the current edge
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
const int VEHPARS_COLOR_SET
static SUMOReal naviDegree(const SUMOReal angle)
Definition: GeomHelper.cpp:191
int containerQuality
The quality of container drawing.
const MSEdge & getDestination() const
Returns the current destination.
is an arbitrary ship
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
const MSEdge * getFromEdge() const
Returns the departure edge.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
virtual SUMOReal getSpeed() const
the current speed of the transportable
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:201
Structure representing possible vehicle parameter.
Position myPositionInVehicle
The position of a container while riding a vehicle.
Definition: GUIContainer.h:191
GUIVisualizationSizeSettings containerSize
A mutex encapsulator which locks/unlocks the given mutex on construction/destruction, respectively.
Definition: AbstractMutex.h:71
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
void drawAction_drawAsPoly(const GUIVisualizationSettings &s) const
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIVisualizationSizeSettings personSize
virtual Position getPosition() const
Return the Network coordinate of the transportable.
SUMOReal getWaitingSeconds() const
the time this container spent waiting in seconds
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:323
#define SUMOReal
Definition: config.h:214
std::string getImgFile() const
Get this vehicle type&#39;s raster model file name.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
#define WATER_WAY_OFFSET
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
~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:77
A window containing a gl-object&#39;s parameter.
const int VTYPEPARS_COLOR_SET
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
SUMOReal getExaggeration(const GUIVisualizationSettings &s) const
return the drawing size including exaggeration and constantSize values
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:449
GUIVisualizationTextSettings containerName