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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
19 // A MSContainer extended by some values for usage within the gui
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <cmath>
24 #include <vector>
25 #include <string>
33 #include <utils/geom/GeomHelper.h>
39 #include <utils/gui/div/GLHelper.h>
43 #include <gui/GUIGlobals.h>
46 
47 #include "GUIContainer.h"
48 #include "GUINet.h"
49 #include "GUIEdge.h"
50 
51 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
52 
53 // ===========================================================================
54 // FOX callback mapping
55 // ===========================================================================
56 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
60 };
61 
62 // Object implementation
63 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
64 
65 #define WATER_WAY_OFFSET 6.0
66 
67 // ===========================================================================
68 // method definitions
69 // ===========================================================================
70 /* -------------------------------------------------------------------------
71  * GUIContainer::GUIContainerPopupMenu - methods
72  * ----------------------------------------------------------------------- */
75  : GUIGLObjectPopupMenu(app, parent, o) {
76 }
77 
78 
80 
81 
82 long
84  GUIContainer* p = dynamic_cast<GUIContainer*>(myObject);
85  if (p == nullptr) {
86  return 1;
87  }
88  GUIParameterTableWindow* ret = new GUIParameterTableWindow(*myApplication, *p);
89  // add items
90  for (int stage = 1; stage < p->getNumStages(); stage++) {
91  ret->mkItem(toString(stage).c_str(), false, p->getStageSummary(stage));
92  }
93  // close building (use an object that is not Parameterised as argument)
94  Parameterised dummy;
95  ret->closeBuilding(&dummy);
96  return 1;
97 }
98 
99 
100 long
102  assert(myObject->getType() == GLO_PERSON);
103  if (myParent->getTrackedID() != static_cast<GUIContainer*>(myObject)->getGlID()) {
104  myParent->startTrack(static_cast<GUIContainer*>(myObject)->getGlID());
105  }
106  return 1;
107 }
108 
109 long
111  assert(myObject->getType() == GLO_PERSON);
112  myParent->stopTrack();
113  return 1;
114 }
115 
116 
117 
118 
119 /* -------------------------------------------------------------------------
120  * GUIContainer - methods
121  * ----------------------------------------------------------------------- */
123  MSTransportable(pars, vtype, plan, false),
124  GUIGlObject(GLO_CONTAINER, pars->id) {
125 }
126 
127 
129 }
130 
131 
134  GUISUMOAbstractView& parent) {
135  GUIGLObjectPopupMenu* ret = new GUIContainerPopupMenu(app, parent, *this);
136  buildPopupHeader(ret, app);
140  new FXMenuSeparator(ret);
141  if (parent.getTrackedID() != getGlID()) {
142  GUIDesigns::buildFXMenuCommand(ret, "Start Tracking", nullptr, ret, MID_START_TRACK);
143  } else {
144  GUIDesigns::buildFXMenuCommand(ret, "Stop Tracking", nullptr, ret, MID_STOP_TRACK);
145  }
146  //
147 
151  new FXMenuSeparator(ret);
152  buildPositionCopyEntry(ret, false);
153  return ret;
154 }
155 
156 
160  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
161  // add items
162  ret->mkItem("stage", false, getCurrentStageDescription());
163  // there is always the "start" stage which we do not count here because it is not strictly part of the plan
164  ret->mkItem("stage index", false, toString(getNumStages() - getNumRemainingStages()) + " of " + toString(getNumStages() - 1));
165  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
166  ret->mkItem("dest edge [id]", false, getDestination()->getID());
167  ret->mkItem("arrivalPos [m]", false, toString(getCurrentStage()->getArrivalPos()));
168  ret->mkItem("edge [id]", false, getEdge()->getID());
169  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getEdgePos));
170  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getSpeed));
171  ret->mkItem("speed factor", false, getSpeedFactor());
172  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getAngle));
173  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getWaitingSeconds));
174  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
175  // close building
176  ret->closeBuilding(&getParameter());
177  return ret;
178 }
179 
180 
184  GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
185  // add items
186  ret->mkItem("Type Information:", false, "");
187  ret->mkItem("type [id]", false, myVType->getID());
188  ret->mkItem("length", false, myVType->getLength());
189  ret->mkItem("width", false, myVType->getWidth());
190  ret->mkItem("height", false, myVType->getHeight());
191  ret->mkItem("minGap", false, myVType->getMinGap());
192  ret->mkItem("maximum speed [m/s]", false, myVType->getMaxSpeed());
193  // close building
194  ret->closeBuilding(&(myVType->getParameter()));
195  return ret;
196 }
197 
198 
199 Boundary
201  Boundary b;
202  // ensure that the vehicle is drawn, otherwise myPositionInVehicle will not be updated
203  b.add(getPosition());
204  b.grow(20);
205  return b;
206 }
207 
208 
209 void
211  glPushName(getGlID());
212  glPushMatrix();
213  Position p1 = getPosition();
214  double angle = getAngle();
217  angle = myPositionInVehicle.angle;
218  }
219  glTranslated(p1.x(), p1.y(), getType());
220  glRotated(RAD2DEG(angle), 0, 0, 1);
221  // set container color
222  setColor(s);
223  // scale
224  const double upscale = s.containerSize.getExaggeration(s, this);
225  glScaled(upscale, upscale, 1);
226  switch (s.containerQuality) {
227  case 0:
228  case 1:
229  case 2:
231  break;
232  case 3:
233  default:
235  break;
236  }
237  glPopMatrix();
238 
239  drawName(p1, s.scale, s.containerName, s.angle);
240  glPopName();
241 }
242 
243 
244 void
246  glPushName(getGlID());
247  glPushMatrix();
248  /*
249  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
250  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
251  drawBestLanes();
252  }
253  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
254  drawRoute(s, 0, 0.25);
255  }
256  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
257  if (getNumberReroutes() > 0) {
258  const int noReroutePlus1 = getNumberReroutes() + 1;
259  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
260  double darken = double(0.4) / double(noReroutePlus1) * double(i);
261  drawRoute(s, i, darken);
262  }
263  } else {
264  drawRoute(s, 0, 0.25);
265  }
266  }
267  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
268  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
269  if((*i).myLink==0) {
270  continue;
271  }
272  MSLink* link = (*i).myLink;
273  MSLane *via = link->getViaLane();
274  if (via == 0) {
275  via = link->getLane();
276  }
277  if (via != 0) {
278  Position p = via->getShape()[0];
279  if((*i).mySetRequest) {
280  glColor3f(0, 1, 0);
281  } else {
282  glColor3f(1, 0, 0);
283  }
284  glTranslated(p.x(), p.y(), -.1);
285  GLHelper::drawFilledCircle(1);
286  glTranslated(-p.x(), -p.y(), .1);
287  }
288  }
289  }
290  */
291  glPopMatrix();
292  glPopName();
293 }
294 
295 
296 
297 
298 void
300  const GUIColorer& c = s.containerColorer;
301  if (!setFunctionalColor(c.getActive())) {
303  }
304 }
305 
306 
307 bool
308 GUIContainer::setFunctionalColor(int activeScheme) const {
309  switch (activeScheme) {
310  case 0: {
311  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
313  return true;
314  }
315  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
316  GLHelper::setColor(getVehicleType().getColor());
317  return true;
318  }
319  return false;
320  }
321  case 2: {
322  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
324  return true;
325  }
326  return false;
327  }
328  case 3: {
329  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
330  GLHelper::setColor(getVehicleType().getColor());
331  return true;
332  }
333  return false;
334  }
335  case 8: {
336  double hue = GeomHelper::naviDegree(getAngle());
338  return true;
339  }
340  default:
341  return false;
342  }
343 }
344 
345 
346 double
347 GUIContainer::getColorValue(const GUIVisualizationSettings& /* s */, int activeScheme) const {
348  switch (activeScheme) {
349  case 4:
350  return getSpeed();
351  case 5:
352  if (isWaiting4Vehicle()) {
353  return 5;
354  } else {
355  return (double)getCurrentStageType();
356  }
357  case 6:
358  return getWaitingSeconds();
359  case 7:
361  }
362  return 0;
363 }
364 
365 
366 double
368  FXMutexLock locker(myLock);
370 }
371 
372 
373 Position
375  FXMutexLock locker(myLock);
376  if (getCurrentStageType() == MSStageType::WAITING && getEdge()->getPermissions() == SVC_SHIP) {
377  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
378  PositionVector laneShape = lane->getShape();
379  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
380  }
382 }
383 
384 
385 double
387  FXMutexLock locker(myLock);
388  return MSTransportable::getAngle();
389 }
390 
391 
392 double
394  FXMutexLock locker(myLock);
396 }
397 
398 
399 double
401  FXMutexLock locker(myLock);
402  return MSTransportable::getSpeed();
403 }
404 
405 
406 void
408  // draw pedestrian shape
409  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
410  glBegin(GL_QUADS);
411  glVertex2d(0, 0.5);
412  glVertex2d(0, -0.5);
413  glVertex2d(-1, -0.5);
414  glVertex2d(-1, 0.5);
415  glEnd();
416  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
417  glTranslated(0, 0, .045);
418  glBegin(GL_QUADS);
419  glVertex2d(-0.1, 0.4);
420  glVertex2d(-0.1, -0.4);
421  glVertex2d(-0.9, -0.4);
422  glVertex2d(-0.9, 0.4);
423  glEnd();
424 }
425 
426 
427 void
429  const std::string& file = getVehicleType().getImgFile();
430  if (file != "") {
431  // @todo invent an option for controlling whether images should be rotated or not
432  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
433  // glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
434  //}
435  int textureID = GUITexturesHelper::getTextureID(file);
436  if (textureID > 0) {
437  const double exaggeration = s.personSize.getExaggeration(s, this);
438  const double halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
439  const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
440  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
441  }
442  } else {
443  // fallback if no image is defined
445  }
446 }
447 
448 
449 /****************************************************************************/
@ MID_SHOWPLAN
Show transportable plan.
Definition: GUIAppEnum.h:417
@ MID_START_TRACK
Start to track a vehicle.
Definition: GUIAppEnum.h:455
@ MID_STOP_TRACK
Stop to track a vehicle.
Definition: GUIAppEnum.h:457
FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[]
#define WATER_WAY_OFFSET
@ GLO_CONTAINER
a container
@ GLO_PERSON
a person
GUISelectedStorage gSelected
A global holder of selected objects.
#define RAD2DEG(x)
Definition: GeomHelper.h:36
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
const int VTYPEPARS_COLOR_SET
@ SVC_SHIP
is an arbitrary ship
const int VEHPARS_COLOR_SET
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:452
long onCmdStartTrack(FXObject *, FXSelector, void *)
Called if the person shall be tracked.
long onCmdShowPlan(FXObject *, FXSelector, void *)
Called if the plan shall be shown.
long onCmdStopTrack(FXObject *, FXSelector, void *)
Called if the person shall not be tracked any longer.
GUIContainerPopupMenu(GUIMainWindow &app, GUISUMOAbstractView &parent, GUIGlObject &o)
Constructor.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double getAngle() const
return the current angle of the container
bool setFunctionalColor(int activeScheme) const
sets the color according to the current scheme index and some vehicle function
void drawAction_drawAsPoly(const GUIVisualizationSettings &s) const
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
double getSpeed() const
the current speed of the container
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
Position getPosition() const
return the Network coordinate of the container
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
GUIContainer(const SUMOVehicleParameter *pars, MSVehicleType *vtype, MSTransportable::MSTransportablePlan *plan)
Constructor.
GUIParameterTableWindow * getTypeParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own type parameter window.
double getEdgePos() const
return the offset from the start of the current edge
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
Definition: GUIContainer.h:184
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
GUIBaseVehicle::Seat myPositionInVehicle
The position of a container while riding a vehicle.
Definition: GUIContainer.h:187
double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the color value according to the current scheme index
double getWaitingSeconds() const
the time this container spent waiting in seconds
~GUIContainer()
destructor
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:40
The popup menu of a globject.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the type parameter window.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
const T getColor(const double value) const
virtual GUIGlID getTrackedID() const
get tracked id
bool isSelected(GUIGlObjectType type, GUIGlID id)
Returns the information whether the object with the given type and id is selected.
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings containerSize
int containerQuality
The quality of container drawing.
GUIVisualizationSizeSettings personSize
double scale
information about a lane's width (temporary, used for a single view)
GUIVisualizationTextSettings containerName
GUIColorer containerColorer
The container colorer.
double angle
The current view rotation angle.
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:192
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:166
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:476
virtual double getEdgePos() const
Return the position on the edge.
std::string getCurrentStageDescription() const
Returns the current stage description as a string.
virtual double getAngle() const
return the current angle of the transportable
bool isWaiting4Vehicle() const
Whether the transportable waits for a vehicle.
int getNumRemainingStages() const
Return the number of remaining stages (including the current)
virtual double getSpeed() const
the current speed of the transportable
std::string getStageSummary(int stageIndex) const
return textual summary for the given stage
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
MSVehicleType * myVType
This transportable's type. (mainly used for drawing related information Note sure if it is really nec...
const MSVehicleType & getVehicleType() const
Returns the object's "vehicle" type.
virtual Position getPosition() const
Return the Network coordinate of the transportable.
double getArrivalPos() const
returns the final arrival pos
const MSEdge * getFromEdge() const
Returns the departure edge.
int getNumStages() const
Return the total number stages in this persons plan.
MSStageType getCurrentStageType() const
the current stage type of the transportable
const MSEdge * getEdge() const
Returns the current edge.
MSStage * getCurrentStage() const
Return the current stage.
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
std::vector< MSStage * > MSTransportablePlan
the structure holding the plan of a transportable
const MSEdge * getDestination() const
Returns the current destination.
virtual double getSpeedFactor() const
the current speed factor of the transportable (where applicable)
The car-following model and parameter.
Definition: MSVehicleType.h:62
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getMaxSpeed() const
Get vehicle's maximum speed [m/s].
double getMinGap() const
Get the free space in front of vehicles of this class.
double getHeight() const
Get the height which vehicles of this class shall have when being drawn.
const std::string & getID() const
Returns the name of the vehicle type.
Definition: MSVehicleType.h:90
double getLength() const
Get vehicle's length [m].
std::string getImgFile() const
Get this vehicle type's raster model file name.
const SUMOVTypeParameter & getParameter() const
const std::string & getID() const
Returns the id.
Definition: Named.h:73
An upper class for objects with additional parameters.
Definition: Parameterised.h:39
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
A list of positions.
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb....
Definition: RGBColor.cpp:300
Structure representing possible vehicle parameter.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values