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-2018 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>
38 #include <utils/geom/GeomHelper.h>
44 #include <utils/gui/div/GLHelper.h>
48 #include <gui/GUIGlobals.h>
49 #include "GUIContainer.h"
50 #include "GUINet.h"
51 #include "GUIEdge.h"
53 
54 //#define GUIContainer_DEBUG_DRAW_WALKING_AREA_SHAPE
55 
56 // ===========================================================================
57 // FOX callback mapping
58 // ===========================================================================
59 /*
60 FXDEFMAP(GUIContainer::GUIContainerPopupMenu) GUIContainerPopupMenuMap[] = {
61  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdShowAllRoutes),
62  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIContainer::GUIContainerPopupMenu::onCmdHideAllRoutes),
63  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdShowCurrentRoute),
64  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIContainer::GUIContainerPopupMenu::onCmdHideCurrentRoute),
65  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdShowBestLanes),
66  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIContainer::GUIContainerPopupMenu::onCmdHideBestLanes),
67  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStartTrack),
68  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIContainer::GUIContainerPopupMenu::onCmdStopTrack),
69  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdShowLFLinkItems),
70  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIContainer::GUIContainerPopupMenu::onCmdHideLFLinkItems),
71 };
72 
73 // Object implementation
74 FXIMPLEMENT(GUIContainer::GUIContainerPopupMenu, GUIGLObjectPopupMenu, GUIContainerPopupMenuMap, ARRAYNUMBER(GUIContainerPopupMenuMap))
75 */
76 
77 #define WATER_WAY_OFFSET 6.0
78 
79 // ===========================================================================
80 // method definitions
81 // ===========================================================================
82 /* -------------------------------------------------------------------------
83  * GUIContainer::GUIContainerPopupMenu - methods
84  * ----------------------------------------------------------------------- */
86  GUIMainWindow& app, GUISUMOAbstractView& parent,
87  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
88  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
89 }
90 
91 
93 
94 
95 
96 /* -------------------------------------------------------------------------
97  * GUIContainer - methods
98  * ----------------------------------------------------------------------- */
100  MSContainer(pars, vtype, plan),
101  GUIGlObject(GLO_CONTAINER, pars->id) {
102 }
103 
104 
106 }
107 
108 
111  GUISUMOAbstractView& parent) {
113  buildPopupHeader(ret, app);
117  //
119  buildPositionCopyEntry(ret, false);
120  return ret;
121 }
122 
123 
128  new GUIParameterTableWindow(app, *this, 12 + (int)getParameter().getParametersMap().size());
129  // add items
130  ret->mkItem("stage", false, getCurrentStageDescription());
131  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
132  ret->mkItem("dest edge [id]", false, getDestination()->getID());
133  ret->mkItem("edge [id]", false, getEdge()->getID());
134  ret->mkItem("position [m]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getEdgePos));
135  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getSpeed));
136  ret->mkItem("speed factor", false, getSpeedFactor());
137  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getAngle));
138  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIContainer, double>(this, &GUIContainer::getWaitingSeconds));
139  ret->mkItem("desired depart [s]", false, time2string(getParameter().depart));
140  // close building
141  ret->closeBuilding(&getParameter());
142  return ret;
143 }
144 
145 
150  new GUIParameterTableWindow(app, *this, 8 + (int)myVType->getParameter().getParametersMap().size());
151  // add items
152  ret->mkItem("Type Information:", false, "");
153  ret->mkItem("type [id]", false, myVType->getID());
154  ret->mkItem("length", false, myVType->getLength());
155  ret->mkItem("width", false, myVType->getWidth());
156  ret->mkItem("height", false, myVType->getHeight());
157  ret->mkItem("minGap", false, myVType->getMinGap());
158  ret->mkItem("maximum speed [m/s]", false, myVType->getMaxSpeed());
159  // close building
160  ret->closeBuilding(&(myVType->getParameter()));
161  return ret;
162 }
163 
164 
165 Boundary
167  Boundary b;
168  // ensure that the vehicle is drawn, otherwise myPositionInVehicle will not be updated
169  b.add(getPosition());
170  b.grow(20);
171  return b;
172 }
173 
174 
175 void
177  glPushName(getGlID());
178  glPushMatrix();
179  Position p1 = getPosition();
181  p1 = myPositionInVehicle;
182  }
183  glTranslated(p1.x(), p1.y(), getType());
184  glRotated(90, 0, 0, 1);
185  // XXX use container specific gui settings
186  // set container color
187  setColor(s);
188  // scale
189  const double upscale = s.containerSize.getExaggeration(s, this);
190  glScaled(upscale, upscale, 1);
191  switch (s.containerQuality) {
192  case 0:
193  case 1:
194  case 2:
196  break;
197  case 3:
198  default:
200  break;
201  }
202  glPopMatrix();
203 
204  drawName(p1, s.scale, s.containerName, s.angle);
205  glPopName();
206 }
207 
208 
209 void
211  glPushName(getGlID());
212  glPushMatrix();
213  /*
214  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
215  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
216  drawBestLanes();
217  }
218  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
219  drawRoute(s, 0, 0.25);
220  }
221  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
222  if (getNumberReroutes() > 0) {
223  const int noReroutePlus1 = getNumberReroutes() + 1;
224  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
225  double darken = double(0.4) / double(noReroutePlus1) * double(i);
226  drawRoute(s, i, darken);
227  }
228  } else {
229  drawRoute(s, 0, 0.25);
230  }
231  }
232  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
233  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
234  if((*i).myLink==0) {
235  continue;
236  }
237  MSLink* link = (*i).myLink;
238  MSLane *via = link->getViaLane();
239  if (via == 0) {
240  via = link->getLane();
241  }
242  if (via != 0) {
243  Position p = via->getShape()[0];
244  if((*i).mySetRequest) {
245  glColor3f(0, 1, 0);
246  } else {
247  glColor3f(1, 0, 0);
248  }
249  glTranslated(p.x(), p.y(), -.1);
250  GLHelper::drawFilledCircle(1);
251  glTranslated(-p.x(), -p.y(), .1);
252  }
253  }
254  }
255  */
256  glPopMatrix();
257  glPopName();
258 }
259 
260 
261 
262 
263 void
265  const GUIColorer& c = s.containerColorer;
266  if (!setFunctionalColor(c.getActive())) {
268  }
269 }
270 
271 
272 bool
273 GUIContainer::setFunctionalColor(int activeScheme) const {
274  switch (activeScheme) {
275  case 0: {
276  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
278  return true;
279  }
280  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
281  GLHelper::setColor(getVehicleType().getColor());
282  return true;
283  }
284  return false;
285  }
286  case 2: {
287  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
289  return true;
290  }
291  return false;
292  }
293  case 3: {
294  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
295  GLHelper::setColor(getVehicleType().getColor());
296  return true;
297  }
298  return false;
299  }
300  case 8: {
301  double hue = GeomHelper::naviDegree(getAngle());
303  return true;
304  }
305  default:
306  return false;
307  }
308 }
309 
310 
311 double
312 GUIContainer::getColorValue(int activeScheme) const {
313  switch (activeScheme) {
314  case 4:
315  return getSpeed();
316  case 5:
317  if (isWaiting4Vehicle()) {
318  return 5;
319  } else {
320  return (double)getCurrentStageType();
321  }
322  case 6:
323  return getWaitingSeconds();
324  case 7:
326  }
327  return 0;
328 }
329 
330 
331 double
334  return MSContainer::getEdgePos();
335 }
336 
337 
338 Position
341  if (getCurrentStageType() == WAITING && getEdge()->getPermissions() == SVC_SHIP) {
342  MSLane* lane = getEdge()->getLanes().front(); //the most right lane of the water way
343  PositionVector laneShape = lane->getShape();
344  return laneShape.positionAtOffset2D(getEdgePos(), WATER_WAY_OFFSET);
345  }
346  return MSContainer::getPosition();
347 }
348 
349 
350 double
353  return MSContainer::getAngle();
354 }
355 
356 
357 double
361 }
362 
363 
364 double
367  return MSContainer::getSpeed();
368 }
369 
370 
371 void
373  // draw pedestrian shape
374  glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
375  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
376  glBegin(GL_QUADS);
377  glVertex2d(0, 0.5);
378  glVertex2d(0, -0.5);
379  glVertex2d(-1, -0.5);
380  glVertex2d(-1, 0.5);
381  glEnd();
382  GLHelper::setColor(GLHelper::getColor().changedBrightness(-30));
383  glTranslated(0, 0, .045);
384  glBegin(GL_QUADS);
385  glVertex2d(-0.1, 0.4);
386  glVertex2d(-0.1, -0.4);
387  glVertex2d(-0.9, -0.4);
388  glVertex2d(-0.9, 0.4);
389  glEnd();
390 }
391 
392 
393 void
395  const std::string& file = getVehicleType().getImgFile();
396  if (file != "") {
397  // @todo invent an option for controlling whether images should be rotated or not
398  //if (getVehicleType().getGuiShape() == SVS_CONTAINER) {
399  // glRotated(RAD2DEG(getAngle() + M_PI / 2.), 0, 0, 1);
400  //}
401  int textureID = GUITexturesHelper::getTextureID(file);
402  if (textureID > 0) {
403  const double exaggeration = s.personSize.getExaggeration(s, this);
404  const double halfLength = getVehicleType().getLength() / 2.0 * exaggeration;
405  const double halfWidth = getVehicleType().getWidth() / 2.0 * exaggeration;
406  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
407  }
408  } else {
409  // fallback if no image is defined
411  }
412 }
413 /****************************************************************************/
414 
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.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:299
virtual double getEdgePos() const
Return the position on the edge.
GUIContainerPopupMenu()
default constructor needed by FOX
Definition: GUIContainer.h:174
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:162
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 PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
#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
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:42
The car-following model and parameter.
Definition: MSVehicleType.h:66
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIContainer.h:181
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:180
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:573
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
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:191
#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:59
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
virtual double getWaitingSeconds() const
the time this transportable spent waiting in seconds
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
double getColorValue(int activeScheme) const
gets the color value according to the current scheme index
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:78
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:579
GUIVisualizationTextSettings containerName