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-2016 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
161  b.add(getPosition());
162  b.grow(20);
163  return b;
164 }
165 
166 
167 void
169  glPushName(getGlID());
170  glPushMatrix();
171  Position p1 = getPosition();
173  p1 = myPositionInVehicle;
174  }
175  glTranslated(p1.x(), p1.y(), getType());
176  glRotated(90, 0, 0, 1);
177  // XXX use container specific gui settings
178  // set container color
179  setColor(s);
180  // scale
181  const SUMOReal upscale = s.containerSize.getExaggeration(s);
182  glScaled(upscale, upscale, 1);
183  switch (s.containerQuality) {
184  case 0:
185  case 1:
186  case 2:
188  break;
189  case 3:
190  default:
192  break;
193  }
194  glPopMatrix();
195 
196  drawName(p1, s.scale, s.containerName);
197  glPopName();
198 }
199 
200 
201 void
203  glPushName(getGlID());
204  glPushMatrix();
205  /*
206  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
207  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
208  drawBestLanes();
209  }
210  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
211  drawRoute(s, 0, 0.25);
212  }
213  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
214  if (getNumberReroutes() > 0) {
215  const int noReroutePlus1 = getNumberReroutes() + 1;
216  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
217  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
218  drawRoute(s, i, darken);
219  }
220  } else {
221  drawRoute(s, 0, 0.25);
222  }
223  }
224  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
225  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
226  if((*i).myLink==0) {
227  continue;
228  }
229  MSLink* link = (*i).myLink;
230  #ifdef HAVE_INTERNAL_LANES
231  MSLane *via = link->getViaLane();
232  if (via == 0) {
233  via = link->getLane();
234  }
235  #else
236  MSLane *via = link->getLane();
237  #endif
238  if (via != 0) {
239  Position p = via->getShape()[0];
240  if((*i).mySetRequest) {
241  glColor3f(0, 1, 0);
242  } else {
243  glColor3f(1, 0, 0);
244  }
245  glTranslated(p.x(), p.y(), -.1);
246  GLHelper::drawFilledCircle(1);
247  glTranslated(-p.x(), -p.y(), .1);
248  }
249  }
250  }
251  */
252  glPopMatrix();
253  glPopName();
254 }
255 
256 
257 
258 
259 void
261  const GUIColorer& c = s.containerColorer;
262  if (!setFunctionalColor(c.getActive())) {
264  }
265 }
266 
267 
268 bool
269 GUIContainer::setFunctionalColor(size_t activeScheme) const {
270  switch (activeScheme) {
271  case 0: {
272  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
274  return true;
275  }
276  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
277  GLHelper::setColor(getVehicleType().getColor());
278  return true;
279  }
280  return false;
281  }
282  case 2: {
283  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
285  return true;
286  }
287  return false;
288  }
289  case 3: {
290  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
291  GLHelper::setColor(getVehicleType().getColor());
292  return true;
293  }
294  return false;
295  }
296  case 8: {
299  return true;
300  }
301  default:
302  return false;
303  }
304 }
305 
306 
307 SUMOReal
308 GUIContainer::getColorValue(size_t activeScheme) const {
309  switch (activeScheme) {
310  case 4:
311  return getSpeed();
312  case 5:
313  if (isWaiting4Vehicle()) {
314  return 3;
315  } else {
316  return (SUMOReal)getCurrentStageType();
317  }
318  case 6:
319  return getWaitingSeconds();
320  case 7:
322  }
323  return 0;
324 }
325 
326 
327 SUMOReal
330  return MSContainer::getEdgePos();
331 }
332 
333 
334 Position
337  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
338  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
339  PositionVector laneShape = lane->getShape();
340  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
341  }
342  return MSContainer::getPosition();
343 }
344 
345 
346 SUMOReal
349  return MSContainer::getAngle();
350 }
351 
352 
353 SUMOReal
357 }
358 
359 
360 SUMOReal
363  return MSContainer::getSpeed();
364 }
365 
366 
367 void
369  // draw pedestrian shape
370  glRotated(RAD2DEG(getAngle() + PI / 2.), 0, 0, 1);
371  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
372  glBegin(GL_QUADS);
373  glVertex2d(0, 0.5);
374  glVertex2d(0, -0.5);
375  glVertex2d(-1, -0.5);
376  glVertex2d(-1, 0.5);
377  glEnd();
378  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
379  glTranslated(0, 0, .045);
380  glBegin(GL_QUADS);
381  glVertex2d(-0.1, 0.4);
382  glVertex2d(-0.1, -0.4);
383  glVertex2d(-0.9, -0.4);
384  glVertex2d(-0.9, 0.4);
385  glEnd();
386 }
387 
388 
389 void
391  const std::string& file = getVehicleType().getImgFile();
392  if (file != "") {
393  // @todo invent an option for controlling whether images should be rotated or not
394  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
395  // glRotated(RAD2DEG(getAngle() + PI / 2.), 0, 0, 1);
396  //}
397  int textureID = GUITexturesHelper::getTextureID(file);
398  if (textureID > 0) {
399  const SUMOReal exaggeration = s.personSize.getExaggeration(s);
400  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
401  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
402  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
403  }
404  } else {
405  // fallback if no image is defined
407  }
408 }
409 /****************************************************************************/
410 
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:185
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.
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:180
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:322
#define SUMOReal
Definition: config.h:213
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