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>
51 #include <utils/gui/div/GLHelper.h>
55 #include <gui/GUIGlobals.h>
56 #include "GUIContainer.h"
57 #include "GUINet.h"
58 #include "GUIEdge.h"
60 
61 #ifdef CHECK_MEMORY_LEAKS
62 #include <foreign/nvwa/debug_new.h>
63 #endif // CHECK_MEMORY_LEAKS
64 
65 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
66 
67 // ===========================================================================
68 // FOX callback mapping
69 // ===========================================================================
70 /*
71 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
72  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdShowAllRoutes),
73  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdHideAllRoutes),
74  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdShowCurrentRoute),
75  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdHideCurrentRoute),
76  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdShowBestLanes),
77  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdHideBestLanes),
78  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStartTrack),
79  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStopTrack),
80  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdShowLFLinkItems),
81  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdHideLFLinkItems),
82 };
83 
84 // Object implementation
85 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
86 */
87 
88 #define WATER_WAY_OFFSET 6.0
89 
90 // ===========================================================================
91 // method definitions
92 // ===========================================================================
93 /* -------------------------------------------------------------------------
94  * GUIContainer::GUIContainerPopupMenu - methods
95  * ----------------------------------------------------------------------- */
97  GUIMainWindow& app, GUISUMOAbstractView& parent,
98  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
99  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
100 }
101 
102 
104 
105 
106 
107 /* -------------------------------------------------------------------------
108  * GUIContainer - methods
109  * ----------------------------------------------------------------------- */
111  MSContainer(pars, vtype, plan),
112  GUIGlObject(GLO_CONTAINER, pars->id)
113 { }
114 
115 
117 }
118 
119 
122  GUISUMOAbstractView& parent) {
124  buildPopupHeader(ret, app);
128  //
130  buildPositionCopyEntry(ret, false);
131  return ret;
132 }
133 
134 
139  new GUIParameterTableWindow(app, *this, 8);
140  // add items
141  //ret->mkItem("type [NAME]", false, myType->getID());
142  ret->mkItem("stage", false, getCurrentStageDescription());
143  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
144  ret->mkItem("dest edge [id]", false, getDestination().getID());
145  ret->mkItem("edge [id]", false, getEdge()->getID());
146  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getEdgePos));
147  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getSpeed));
148  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getAngle));
149  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, SUMOReal>(this, &GUIContainer::getWaitingSeconds));
150  // close building
151  ret->closeBuilding();
152  return ret;
153 }
154 
155 
156 Boundary
158  Boundary b;
159  b.add(getPosition());
160  b.grow(20);
161  return b;
162 }
163 
164 
165 void
167  glPushName(getGlID());
168  glPushMatrix();
169  Position p1 = getPosition();
170  glTranslated(p1.x(), p1.y(), getType());
171  glRotated(90, 0, 0, 1);
172  // XXX use container specific gui settings
173  // set container color
174  setColor(s);
175  // scale
176  const SUMOReal upscale = s.containerSize.getExaggeration(s);
177  glScaled(upscale, upscale, 1);
178  switch (s.containerQuality) {
179  case 0:
180  case 1:
181  case 2:
183  break;
184  case 3:
185  default:
187  break;
188  }
189  glPopMatrix();
190 
191  drawName(p1, s.scale, s.containerName);
192  glPopName();
193 }
194 
195 
196 void
198  glPushName(getGlID());
199  glPushMatrix();
200  /*
201  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
202  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
203  drawBestLanes();
204  }
205  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
206  drawRoute(s, 0, 0.25);
207  }
208  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
209  if (getNumberReroutes() > 0) {
210  const int noReroutePlus1 = getNumberReroutes() + 1;
211  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
212  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
213  drawRoute(s, i, darken);
214  }
215  } else {
216  drawRoute(s, 0, 0.25);
217  }
218  }
219  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
220  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
221  if((*i).myLink==0) {
222  continue;
223  }
224  MSLink* link = (*i).myLink;
225  #ifdef HAVE_INTERNAL_LANES
226  MSLane *via = link->getViaLane();
227  if (via == 0) {
228  via = link->getLane();
229  }
230  #else
231  MSLane *via = link->getLane();
232  #endif
233  if (via != 0) {
234  Position p = via->getShape()[0];
235  if((*i).mySetRequest) {
236  glColor3f(0, 1, 0);
237  } else {
238  glColor3f(1, 0, 0);
239  }
240  glTranslated(p.x(), p.y(), -.1);
241  GLHelper::drawFilledCircle(1);
242  glTranslated(-p.x(), -p.y(), .1);
243  }
244  }
245  }
246  */
247  glPopMatrix();
248  glPopName();
249 }
250 
251 
252 
253 
254 void
256  const GUIColorer& c = s.containerColorer;
257  if (!setFunctionalColor(c.getActive())) {
259  }
260 }
261 
262 
263 bool
264 GUIContainer::setFunctionalColor(size_t activeScheme) const {
265  switch (activeScheme) {
266  case 0: {
267  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
269  return true;
270  }
271  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
272  GLHelper::setColor(getVehicleType().getColor());
273  return true;
274  }
275  return false;
276  }
277  case 2: {
278  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
280  return true;
281  }
282  return false;
283  }
284  case 3: {
285  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
286  GLHelper::setColor(getVehicleType().getColor());
287  return true;
288  }
289  return false;
290  }
291  case 8: {
292  SUMOReal hue = getAngle() + 180; // [0-360]
294  return true;
295  }
296  default:
297  return false;
298  }
299 }
300 
301 
302 SUMOReal
303 GUIContainer::getColorValue(size_t activeScheme) const {
304  switch (activeScheme) {
305  case 4:
306  return getSpeed();
307  case 5:
308  if (isWaiting4Vehicle()) {
309  return 3;
310  } else {
311  return (SUMOReal)getCurrentStageType();
312  }
313  case 6:
314  return getWaitingSeconds();
315  case 7:
317  }
318  return 0;
319 }
320 
321 
322 SUMOReal
325  return MSContainer::getEdgePos();
326 }
327 
328 
329 Position
333  return myPositionInVehicle;
334  }
335  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
336  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
337  PositionVector laneShape = lane->getShape();
338  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
339  }
340  return MSContainer::getPosition();
341 }
342 
343 
344 SUMOReal
347  return MSContainer::getAngle();
348 }
349 
350 
351 SUMOReal
355 }
356 
357 
358 SUMOReal
361  return MSContainer::getSpeed();
362 }
363 
364 
365 void
367  // draw pedestrian shape
368  glRotated(getAngle(), 0, 0, 1);
369  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
370  glBegin(GL_QUADS);
371  glVertex2d(0, 0.5);
372  glVertex2d(0, -0.5);
373  glVertex2d(-1, -0.5);
374  glVertex2d(-1, 0.5);
375  glEnd();
376  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
377  glTranslated(0, 0, .045);
378  glBegin(GL_QUADS);
379  glVertex2d(-0.1, 0.4);
380  glVertex2d(-0.1, -0.4);
381  glVertex2d(-0.9, -0.4);
382  glVertex2d(-0.9, 0.4);
383  glEnd();
384 }
385 
386 
387 void
389  const std::string& file = getVehicleType().getImgFile();
390  if (file != "") {
391  // @todo invent an option for controlling whether images should be rotated or not
392  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
393  // glRotated(getAngle(), 0, 0, 1);
394  //}
395  int textureID = GUITexturesHelper::getTextureID(file);
396  if (textureID > 0) {
397  const SUMOReal exaggeration = s.personSize.getExaggeration(s);
398  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
399  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
400  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
401  }
402  } else {
403  // fallback if no image is defined
405  }
406 }
407 /****************************************************************************/
408 
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
Definition: MSContainer.h:636
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSContainer.h:606
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's lanes.
Definition: MSEdge.h:186
GUIContainerPopupMenu()
default constructor needed by FOX
Definition: GUIContainer.h:174
GUIColorer containerColorer
The container colorer.
Stores the information about how to visualize structures.
SUMOReal getLength() const
Get vehicle'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 SUMOVehicleParameter & getParameter() const
Definition: MSContainer.h:677
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.
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:115
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's width (temporary, used for a single view)
const MSVehicleType & getVehicleType() const
Definition: MSContainer.h:681
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIContainer.h:181
virtual SUMOReal getAngle() const
return the current angle of the container
const MSEdge * getFromEdge() const
Returns the departure edge.
Definition: MSContainer.h:611
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
a container
static void drawTexturedBox(unsigned int which, SUMOReal size)
Draws a named texture as a box with the given size.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:442
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.
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
virtual Position getPosition() const
Return the Network coordinate of the container.
int containerQuality
The quality of container drawing.
std::vector< MSContainerStage * > MSContainerPlan
the structure holding the plan of a container
Definition: MSContainer.h:553
is an arbitrary ship
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
bool isWaiting4Vehicle() const
Whether the container waits for a vehicle.
Definition: MSContainer.h:673
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:76
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
Definition: Boundary.cpp:200
Structure representing possible vehicle parameter.
Position myPositionInVehicle
The position of a container while riding a vehicle.
Definition: GUIContainer.h:191
virtual SUMOReal getEdgePos() const
Return the position on the edge.
virtual SUMOReal getWaitingSeconds() const
the time this container spent waiting in seconds
StageType getCurrentStageType() const
the current stage type of the container
Definition: MSContainer.h:631
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.
const std::string & getID() const
returns the container id
GUIVisualizationSizeSettings personSize
GUIContainer(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSContainer::MSContainerPlan *plan)
Constructor.
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's shape.
Definition: MSLane.h:323
#define SUMOReal
Definition: config.h:218
std::string getImgFile() const
Get this vehicle type's raster model file name.
#define WATER_WAY_OFFSET
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
virtual SUMOReal getSpeed() const
the current speed of the container
const MSEdge & getDestination() const
Returns the current destination.
Definition: MSContainer.h:596
~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'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:448
static int getTextureID(const std::string &filename)
return texture id for the given filename (initialize on first use)
GUIVisualizationTextSettings containerName