SUMO - Simulation of Urban MObility
GUIContainer.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 /****************************************************************************/
18 // A MSContainer extended by some values for usage within the gui
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <cmath>
32 #include <vector>
33 #include <string>
34 #include <microsim/MSContainer.h>
44 #include <utils/geom/GeomHelper.h>
50 #include <utils/gui/div/GLHelper.h>
54 #include <gui/GUIGlobals.h>
55 #include "GUIContainer.h"
56 #include "GUINet.h"
57 #include "GUIEdge.h"
59 
60 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
61 
62 // ===========================================================================
63 // FOX callback mapping
64 // ===========================================================================
65 /*
66 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
67  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdShowAllRoutes),
68  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdHideAllRoutes),
69  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdShowCurrentRoute),
70  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdHideCurrentRoute),
71  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdShowBestLanes),
72  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdHideBestLanes),
73  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStartTrack),
74  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStopTrack),
75  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdShowLFLinkItems),
76  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdHideLFLinkItems),
77 };
78 
79 // Object implementation
80 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
81 */
82 
83 #define WATER_WAY_OFFSET 6.0
84 
85 // ===========================================================================
86 // method definitions
87 // ===========================================================================
88 /* -------------------------------------------------------------------------
89  * GUIContainer::GUIContainerPopupMenu - methods
90  * ----------------------------------------------------------------------- */
92  GUIMainWindow& app, GUISUMOAbstractView& parent,
93  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
94  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
95 }
96 
97 
99 
100 
101 
102 /* -------------------------------------------------------------------------
103  * GUIContainer - methods
104  * ----------------------------------------------------------------------- */
106  MSContainer(pars, vtype, plan),
107  GUIGlObject(GLO_CONTAINER, pars->id) {
108 }
109 
110 
112 }
113 
114 
117  GUISUMOAbstractView& parent) {
119  buildPopupHeader(ret, app);
123  //
125  buildPositionCopyEntry(ret, false);
126  return ret;
127 }
128 
129 
134  new GUIParameterTableWindow(app, *this, 12 + (int)getParameter().getMap().size());
135  // add items
136  ret->mkItem("stage", false, getCurrentStageDescription());
137  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
138  ret->mkItem("dest edge [id]", false, getDestination().getID());
139  ret->mkItem("edge [id]", false, getEdge()->getID());
140  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getEdgePos));
141  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getSpeed));
142  ret->mkItem("speed factor", false, getSpeedFactor());
143  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getAngle));
144  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getWaitingSeconds));
145  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
146  // close building
147  ret->closeBuilding(&getParameter());
148  return ret;
149 }
150 
151 
156  new GUIParameterTableWindow(app, *this, 8 + (int)myVType->getParameter().getMap().size());
157  // add items
158  ret->mkItem("Type Information:", false, "");
159  ret->mkItem("type [id]", false, myVType->getID());
160  ret->mkItem("length", false, myVType->getLength());
161  ret->mkItem("width", false, myVType->getWidth());
162  ret->mkItem("height", false, myVType->getHeight());
163  ret->mkItem("minGap", false, myVType->getMinGap());
164  ret->mkItem("maximum speed [m/s]", false, myVType->getMaxSpeed());
165  // close building
166  ret->closeBuilding(&(myVType->getParameter()));
167  return ret;
168 }
169 
170 
171 Boundary
173  Boundary b;
174  // ensure that the vehicle is drawn, otherwise myPositionInVehicle will not be updated
175  b.add(getPosition());
176  b.grow(20);
177  return b;
178 }
179 
180 
181 void
183  glPushName(getGlID());
184  glPushMatrix();
185  Position p1 = getPosition();
187  p1 = myPositionInVehicle;
188  }
189  glTranslated(p1.x(), p1.y(), getType());
190  glRotated(90, 0, 0, 1);
191  // XXX use container specific gui settings
192  // set container color
193  setColor(s);
194  // scale
195  const double upscale = s.containerSize.getExaggeration(s);
196  glScaled(upscale, upscale, 1);
197  switch (s.containerQuality) {
198  case 0:
199  case 1:
200  case 2:
202  break;
203  case 3:
204  default:
206  break;
207  }
208  glPopMatrix();
209 
210  drawName(p1, s.scale, s.containerName);
211  glPopName();
212 }
213 
214 
215 void
217  glPushName(getGlID());
218  glPushMatrix();
219  /*
220  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
221  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
222  drawBestLanes();
223  }
224  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
225  drawRoute(s, 0, 0.25);
226  }
227  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
228  if (getNumberReroutes() > 0) {
229  const int noReroutePlus1 = getNumberReroutes() + 1;
230  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
231  double darken = double(0.4) / double(noReroutePlus1) * double(i);
232  drawRoute(s, i, darken);
233  }
234  } else {
235  drawRoute(s, 0, 0.25);
236  }
237  }
238  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
239  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
240  if((*i).myLink==0) {
241  continue;
242  }
243  MSLink* link = (*i).myLink;
244  MSLane *via = link->getViaLane();
245  if (via == 0) {
246  via = link->getLane();
247  }
248  if (via != 0) {
249  Position p = via->getShape()[0];
250  if((*i).mySetRequest) {
251  glColor3f(0, 1, 0);
252  } else {
253  glColor3f(1, 0, 0);
254  }
255  glTranslated(p.x(), p.y(), -.1);
256  GLHelper::drawFilledCircle(1);
257  glTranslated(-p.x(), -p.y(), .1);
258  }
259  }
260  }
261  */
262  glPopMatrix();
263  glPopName();
264 }
265 
266 
267 
268 
269 void
271  const GUIColorer& c = s.containerColorer;
272  if (!setFunctionalColor(c.getActive())) {
274  }
275 }
276 
277 
278 bool
279 GUIContainer::setFunctionalColor(int activeScheme) const {
280  switch (activeScheme) {
281  case 0: {
282  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
284  return true;
285  }
286  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
287  GLHelper::setColor(getVehicleType().getColor());
288  return true;
289  }
290  return false;
291  }
292  case 2: {
293  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
295  return true;
296  }
297  return false;
298  }
299  case 3: {
300  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
301  GLHelper::setColor(getVehicleType().getColor());
302  return true;
303  }
304  return false;
305  }
306  case 8: {
307  double hue = GeomHelper::naviDegree(getAngle());
309  return true;
310  }
311  default:
312  return false;
313  }
314 }
315 
316 
317 double
318 GUIContainer::getColorValue(int activeScheme) const {
319  switch (activeScheme) {
320  case 4:
321  return getSpeed();
322  case 5:
323  if (isWaiting4Vehicle()) {
324  return 3;
325  } else {
326  return (double)getCurrentStageType();
327  }
328  case 6:
329  return getWaitingSeconds();
330  case 7:
332  }
333  return 0;
334 }
335 
336 
337 double
340  return MSContainer::getEdgePos();
341 }
342 
343 
344 Position
347  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
348  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
349  PositionVector laneShape = lane->getShape();
350  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
351  }
352  return MSContainer::getPosition();
353 }
354 
355 
356 double
359  return MSContainer::getAngle();
360 }
361 
362 
363 double
367 }
368 
369 
370 double
373  return MSContainer::getSpeed();
374 }
375 
376 
377 void
379  // draw pedestrian shape
380  glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
381  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
382  glBegin(GL_QUADS);
383  glVertex2d(0, 0.5);
384  glVertex2d(0, -0.5);
385  glVertex2d(-1, -0.5);
386  glVertex2d(-1, 0.5);
387  glEnd();
388  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
389  glTranslated(0, 0, .045);
390  glBegin(GL_QUADS);
391  glVertex2d(-0.1, 0.4);
392  glVertex2d(-0.1, -0.4);
393  glVertex2d(-0.9, -0.4);
394  glVertex2d(-0.9, 0.4);
395  glEnd();
396 }
397 
398 
399 void
401  const std::string& file = getVehicleType().getImgFile();
402  if (file != "") {
403  // @todo invent an option for controlling whether images should be rotated or not
404  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
405  // glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
406  //}
407  int textureID = GUITexturesHelper::getTextureID(file);
408  if (textureID > 0) {
409  const double exaggeration = s.personSize.getExaggeration(s);
410  const double halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
411  const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
412  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
413  }
414  } else {
415  // fallback if no image is defined
417  }
418 }
419 /****************************************************************************/
420 
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)
GUIContainer(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan)
Constructor.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
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:301
virtual double getEdgePos() const
Return the position on the edge.
GUIContainerPopupMenu()
default constructor needed by FOX
Definition: GUIContainer.h:180
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:67
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:59
double x() const
Returns the x-position.
Definition: Position.h:62
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:167
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:194
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:439
#define RAD2DEG(x)
Definition: GeomHelper.h:45
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:47
The car-following model and parameter.
Definition: MSVehicleType.h:72
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIContainer.h:187
const MSEdge * getFromEdge() const
Returns the departure edge.
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
a container
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:186
MSVehicleType * myVType
This transportable&#39;s type. (mainly used for drawing related information Note sure if it is really nec...
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:449
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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.
double getMaxSpeed() const
Get vehicle&#39;s maximum speed [m/s].
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:301
double getMinGap() const
Get the free space in front of vehicles of this class.
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
const SUMOVTypeParameter & getParameter() const
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.
virtual double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getHeight() const
Get the height 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:197
#define M_PI
Definition: odrSpiral.cpp:40
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:70
const std::map< std::string, std::string > & getMap() const
Returns the inner key/value map.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
const std::string & getID() const
Returns the name of the vehicle type.
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:85
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.
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 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:455
GUIVisualizationTextSettings containerName