Eclipse 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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // A MSContainer extended by some values for usage within the gui
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <cmath>
26 #include <vector>
27 #include <string>
28 #include <microsim/MSContainer.h>
37 #include <utils/geom/GeomHelper.h>
43 #include <utils/gui/div/GLHelper.h>
47 #include <gui/GUIGlobals.h>
48 #include "GUIContainer.h"
49 #include "GUINet.h"
50 #include "GUIEdge.h"
52 
53 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
54 
55 // ===========================================================================
56 // FOX callback mapping
57 // ===========================================================================
58 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
62 };
63 
64 // Object implementation
65 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
66 
67 #define WATER_WAY_OFFSET 6.0
68 
69 // ===========================================================================
70 // method definitions
71 // ===========================================================================
72 /* -------------------------------------------------------------------------
73  * GUIContainer::GUIContainerPopupMenu - methods
74  * ----------------------------------------------------------------------- */
76  GUIMainWindow& app, GUISUMOAbstractView& parent,
77  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
78  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
79 }
80 
81 
83 
84 
85 long
87  GUIContainer* p = dynamic_cast<GUIContainer*>(myObject);
88  if (p == nullptr) {
89  return 1;
90  }
92  // add items
93  for (int stage = 1; stage < p->getNumStages(); stage++) {
94  ret->mkItem(toString(stage).c_str(), false, p->getStageSummary(stage));
95  }
96  // close building (use an object that is not Parameterised as argument)
98  ret->closeBuilding(&dummy);
99  return 1;
100 }
101 
102 
103 long
105  assert(myObject->getType() == GLO_PERSON);
106  if (myParent->getTrackedID() != static_cast<GUIContainer*>(myObject)->getGlID()) {
107  myParent->startTrack(static_cast<GUIContainer*>(myObject)->getGlID());
108  }
109  return 1;
110 }
111 
112 long
114  assert(myObject->getType() == GLO_PERSON);
115  myParent->stopTrack();
116  return 1;
117 }
118 
119 
120 
121 
122 /* -------------------------------------------------------------------------
123  * GUIContainer - methods
124  * ----------------------------------------------------------------------- */
126  MSContainer(pars, vtype, plan),
127  GUIGlObject(GLO_CONTAINER, pars->id) {
128 }
129 
130 
132 }
133 
134 
137  GUISUMOAbstractView& parent) {
139  buildPopupHeader(ret, app);
143  new FXMenuSeparator(ret);
144  if (parent.getTrackedID() != getGlID()) {
145  new FXMenuCommand(ret, "Start Tracking", nullptr, ret, MID_START_TRACK);
146  } else {
147  new FXMenuCommand(ret, "Stop Tracking", nullptr, ret, MID_STOP_TRACK);
148  }
149  //
150 
153  new FXMenuCommand(ret, "Show Plan", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPLAN);
154  new FXMenuSeparator(ret);
155  buildPositionCopyEntry(ret, false);
156  return ret;
157 }
158 
159 
164  new GUIParameterTableWindow(app, *this, 12 + (int)getParameter().getParametersMap().size());
165  // add items
166  ret->mkItem("stage", false, getCurrentStageDescription());
167  // there is always the "start" stage which we do not count here because it is not strictly part of the plan
168  ret->mkItem("stage index", false, toString(getNumStages() - getNumRemainingStages()) + " of " + toString(getNumStages() - 1));
169  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
170  ret->mkItem("dest edge [id]", false, getDestination()->getID());
171  ret->mkItem("arrivalPos [m]", false, toString(getCurrentStage()->getArrivalPos()));
172  ret->mkItem("edge [id]", false, getEdge()->getID());
173  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getEdgePos));
174  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getSpeed));
175  ret->mkItem("speed factor", false, getSpeedFactor());
176  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getAngle));
177  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getWaitingSeconds));
178  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
179  // close building
180  ret->closeBuilding(&getParameter());
181  return ret;
182 }
183 
184 
189  new GUIParameterTableWindow(app, *this, 8 + (int)myVType->getParameter().getParametersMap().size());
190  // add items
191  ret->mkItem("Type Information:", false, "");
192  ret->mkItem("type [id]", false, myVType->getID());
193  ret->mkItem("length", false, myVType->getLength());
194  ret->mkItem("width", false, myVType->getWidth());
195  ret->mkItem("height", false, myVType->getHeight());
196  ret->mkItem("minGap", false, myVType->getMinGap());
197  ret->mkItem("maximum speed [m/s]", false, myVType->getMaxSpeed());
198  // close building
199  ret->closeBuilding(&(myVType->getParameter()));
200  return ret;
201 }
202 
203 
204 Boundary
206  Boundary b;
207  // ensure that the vehicle is drawn, otherwise myPositionInVehicle will not be updated
208  b.add(getPosition());
209  b.grow(20);
210  return b;
211 }
212 
213 
214 void
216  glPushName(getGlID());
217  glPushMatrix();
218  Position p1 = getPosition();
220  p1 = myPositionInVehicle;
221  }
222  glTranslated(p1.x(), p1.y(), getType());
223  glRotated(90, 0, 0, 1);
224  // set container color
225  setColor(s);
226  // scale
227  const double upscale = s.containerSize.getExaggeration(s, this);
228  glScaled(upscale, upscale, 1);
229  switch (s.containerQuality) {
230  case 0:
231  case 1:
232  case 2:
234  break;
235  case 3:
236  default:
238  break;
239  }
240  glPopMatrix();
241 
242  drawName(p1, s.scale, s.containerName, s.angle);
243  glPopName();
244 }
245 
246 
247 void
249  glPushName(getGlID());
250  glPushMatrix();
251  /*
252  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
253  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
254  drawBestLanes();
255  }
256  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
257  drawRoute(s, 0, 0.25);
258  }
259  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
260  if (getNumberReroutes() > 0) {
261  const int noReroutePlus1 = getNumberReroutes() + 1;
262  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
263  double darken = double(0.4) / double(noReroutePlus1) * double(i);
264  drawRoute(s, i, darken);
265  }
266  } else {
267  drawRoute(s, 0, 0.25);
268  }
269  }
270  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
271  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
272  if((*i).myLink==0) {
273  continue;
274  }
275  MSLink* link = (*i).myLink;
276  MSLane *via = link->getViaLane();
277  if (via == 0) {
278  via = link->getLane();
279  }
280  if (via != 0) {
281  Position p = via->getShape()[0];
282  if((*i).mySetRequest) {
283  glColor3f(0, 1, 0);
284  } else {
285  glColor3f(1, 0, 0);
286  }
287  glTranslated(p.x(), p.y(), -.1);
288  GLHelper::drawFilledCircle(1);
289  glTranslated(-p.x(), -p.y(), .1);
290  }
291  }
292  }
293  */
294  glPopMatrix();
295  glPopName();
296 }
297 
298 
299 
300 
301 void
303  const GUIColorer& c = s.containerColorer;
304  if (!setFunctionalColor(c.getActive())) {
306  }
307 }
308 
309 
310 bool
311 GUIContainer::setFunctionalColor(int activeScheme) const {
312  switch (activeScheme) {
313  case 0: {
314  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
316  return true;
317  }
318  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
319  GLHelper::setColor(getVehicleType().getColor());
320  return true;
321  }
322  return false;
323  }
324  case 2: {
325  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
327  return true;
328  }
329  return false;
330  }
331  case 3: {
332  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
333  GLHelper::setColor(getVehicleType().getColor());
334  return true;
335  }
336  return false;
337  }
338  case 8: {
339  double hue = GeomHelper::naviDegree(getAngle());
341  return true;
342  }
343  default:
344  return false;
345  }
346 }
347 
348 
349 double
350 GUIContainer::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
351  switch (activeScheme) {
352  case 4:
353  return getSpeed();
354  case 5:
355  if (isWaiting4Vehicle()) {
356  return 5;
357  } else {
358  return (double)getCurrentStageType();
359  }
360  case 6:
361  return getWaitingSeconds();
362  case 7:
364  }
365  return 0;
366 }
367 
368 
369 double
371  FXMutexLock locker(myLock);
372  return MSContainer::getEdgePos();
373 }
374 
375 
376 Position
378  FXMutexLock locker(myLock);
379  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
380  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
381  PositionVector laneShape = lane->getShape();
382  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
383  }
384  return MSContainer::getPosition();
385 }
386 
387 
388 double
390  FXMutexLock locker(myLock);
391  return MSContainer::getAngle();
392 }
393 
394 
395 double
397  FXMutexLock locker(myLock);
399 }
400 
401 
402 double
404  FXMutexLock locker(myLock);
405  return MSContainer::getSpeed();
406 }
407 
408 
409 void
411  // draw pedestrian shape
412  glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
413  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
414  glBegin(GL_QUADS);
415  glVertex2d(0, 0.5);
416  glVertex2d(0, -0.5);
417  glVertex2d(-1, -0.5);
418  glVertex2d(-1, 0.5);
419  glEnd();
420  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
421  glTranslated(0, 0, .045);
422  glBegin(GL_QUADS);
423  glVertex2d(-0.1, 0.4);
424  glVertex2d(-0.1, -0.4);
425  glVertex2d(-0.9, -0.4);
426  glVertex2d(-0.9, 0.4);
427  glEnd();
428 }
429 
430 
431 void
433  const std::string& file = getVehicleType().getImgFile();
434  if (file != "") {
435  // @todo invent an option for controlling whether images should be rotated or not
436  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
437  // glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
438  //}
439  int textureID = GUITexturesHelper::getTextureID(file);
440  if (textureID > 0) {
441  const double exaggeration = s.personSize.getExaggeration(s, this);
442  const double halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
443  const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
444  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
445  }
446  } else {
447  // fallback if no image is defined
449  }
450 }
451 /****************************************************************************/
452 
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.
long onCmdStartTrack(FXObject *, FXSelector, void *)
Called if the person shall be tracked.
double getArrivalPos() const
returns the final arrival pos
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.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb.htm.
Definition: RGBColor.cpp:299
virtual double getEdgePos() const
Return the position on the edge.
std::map< GUISUMOAbstractView *, int > dummy
Needed for parameterless instantiation.
Definition: GUIContainer.h:176
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:62
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
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:165
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:478
GUISUMOAbstractView * myParent
The parent window.
#define RAD2DEG(x)
Definition: GeomHelper.h:39
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
virtual void stopTrack()
stop track
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.
void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the type parameter window.
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
The car-following model and parameter.
Definition: MSVehicleType.h:66
Start to track a vehicle.
Definition: GUIAppEnum.h:419
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIContainer.h:187
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
const MSEdge * getFromEdge() const
Returns the departure edge.
long onCmdStopTrack(FXObject *, FXSelector, void *)
Called if the person shall not be tracked any longer.
std::vector< MSTransportable::Stage * > MSTransportablePlan
the structure holding the plan of a transportable
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:194
MSTransportable::Stage * getCurrentStage() const
Return the current stage.
virtual GUIGlID getTrackedID() const
get tracked id
virtual void startTrack(int)
star track
MSVehicleType * myVType
This transportable&#39;s type. (mainly used for drawing related information Note sure if it is really nec...
Stop to track a vehicle.
Definition: GUIAppEnum.h:421
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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
double angle
The current view rotation angle.
const T getColor(const double value) const
FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[]
bool setFunctionalColor(int activeScheme) const
sets the color according to the current scheme index and some vehicle function
std::string getStageSummary(int stageIndex) const
return textual summary for the given stage
An upper class for objects with additional parameters.
Definition: Parameterised.h:43
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
Show transportable plan.
Definition: GUIAppEnum.h:385
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:94
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].
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
GUIGlID getGlID() const
Returns the numerical id of the object.
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type.
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
GUIMainWindow * myApplication
The main application.
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIContainer.h:194
const MSEdge * getDestination() const
Returns the current destination.
#define WATER_WAY_OFFSET
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
long onCmdShowPlan(FXObject *, FXSelector, void *)
Called if the plan shall be shown.
GUIGlObject * myObject
The object that belongs to this popup-menu.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
~GUIContainer()
destructor
GUISelectedStorage gSelected
A global holder of selected objects.
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
A window containing a gl-object&#39;s parameter.
const int VTYPEPARS_COLOR_SET
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
int getNumStages() const
Return the total number stages in this persons plan.
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:622
GUIVisualizationTextSettings containerName