SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIPerson.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A MSPerson extended by some values for usage within the gui
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <cmath>
34 #include <vector>
35 #include <string>
37 #include <microsim/MSPerson.h>
50 #include <utils/gui/div/GLHelper.h>
53 #include <gui/GUIGlobals.h>
54 #include "GUIPerson.h"
55 #include "GUINet.h"
56 #include "GUIEdge.h"
58 
59 #ifdef CHECK_MEMORY_LEAKS
60 #include <foreign/nvwa/debug_new.h>
61 #endif // CHECK_MEMORY_LEAKS
62 
63 
64 // ===========================================================================
65 // FOX callback mapping
66 // ===========================================================================
67 /*
68 FXDEFMAP(GUIPerson::GUIPersonPopupMenu) GUIPersonPopupMenuMap[] = {
69  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIPerson::GUIPersonPopupMenu::onCmdShowAllRoutes),
70  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIPerson::GUIPersonPopupMenu::onCmdHideAllRoutes),
71  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIPerson::GUIPersonPopupMenu::onCmdShowCurrentRoute),
72  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIPerson::GUIPersonPopupMenu::onCmdHideCurrentRoute),
73  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIPerson::GUIPersonPopupMenu::onCmdShowBestLanes),
74  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIPerson::GUIPersonPopupMenu::onCmdHideBestLanes),
75  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIPerson::GUIPersonPopupMenu::onCmdStartTrack),
76  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIPerson::GUIPersonPopupMenu::onCmdStopTrack),
77  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIPerson::GUIPersonPopupMenu::onCmdShowLFLinkItems),
78  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIPerson::GUIPersonPopupMenu::onCmdHideLFLinkItems),
79 };
80 
81 // Object implementation
82 FXIMPLEMENT(GUIPerson::GUIPersonPopupMenu, GUIGLObjectPopupMenu, GUIPersonPopupMenuMap, ARRAYNUMBER(GUIPersonPopupMenuMap))
83 */
84 
85 
86 
87 // ===========================================================================
88 // method definitions
89 // ===========================================================================
90 /* -------------------------------------------------------------------------
91  * GUIPerson::GUIPersonPopupMenu - methods
92  * ----------------------------------------------------------------------- */
94  GUIMainWindow& app, GUISUMOAbstractView& parent,
95  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
96  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
97 }
98 
99 
101 
102 
103 
104 /* -------------------------------------------------------------------------
105  * GUIPerson - methods
106  * ----------------------------------------------------------------------- */
108  MSPerson(pars, vtype, plan),
109  GUIGlObject(GLO_PERSON, pars->id),
111 { }
112 
113 
115 }
116 
117 
120  GUISUMOAbstractView& parent) {
122  buildPopupHeader(ret, app);
126  //
128  buildPositionCopyEntry(ret, false);
129  return ret;
130 }
131 
132 
137  new GUIParameterTableWindow(app, *this, 3);
138  // add items
139  //ret->mkItem("type [NAME]", false, myType->getID());
140  ret->mkItem("stage", false, getCurrentStageTypeName());
141  ret->mkItem("from", false, getFromEdge()->getID());
142  ret->mkItem("to", false, getDestination().getID());
143  // close building
144  ret->closeBuilding();
145  return ret;
146 }
147 
148 
149 Boundary
151  Boundary b;
152  b.add(getPosition(MSNet::getInstance()->getCurrentTimeStep()));
153  b.grow(20);
154  return b;
155 }
156 
157 
158 void
160  glPushName(getGlID());
161  glPushMatrix();
163  Position p1 = getPosition(now);
164  glTranslated(p1.x(), p1.y(), getType());
165  // XXX use person specific gui settings
166  // set person color
167  setColor(s);
168  // scale
169  SUMOReal upscale = s.personExaggeration;
170  glScaled(upscale, upscale, 1);
171  switch (s.personQuality) {
172  case 0:
173  case 1:
175  break;
176  case 2:
178  break;
179  case 3:
180  default:
182  break;
183  }
184  glPopMatrix();
185  drawName(p1, s.scale, s.personName);
186  glPopName();
187 }
188 
189 
190 void
192  glPushName(getGlID());
193  glPushMatrix();
194  /*
195  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
196  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
197  drawBestLanes();
198  }
199  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
200  drawRoute(s, 0, 0.25);
201  }
202  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
203  if (getNumberReroutes() > 0) {
204  const int noReroutePlus1 = getNumberReroutes() + 1;
205  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
206  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
207  drawRoute(s, i, darken);
208  }
209  } else {
210  drawRoute(s, 0, 0.25);
211  }
212  }
213  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
214  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
215  if((*i).myLink==0) {
216  continue;
217  }
218  MSLink* link = (*i).myLink;
219  #ifdef HAVE_INTERNAL_LANES
220  MSLane *via = link->getViaLane();
221  if (via == 0) {
222  via = link->getLane();
223  }
224  #else
225  MSLane *via = link->getLane();
226  #endif
227  if (via != 0) {
228  Position p = via->getShape()[0];
229  if((*i).mySetRequest) {
230  glColor3f(0, 1, 0);
231  } else {
232  glColor3f(1, 0, 0);
233  }
234  glTranslated(p.x(), p.y(), -.1);
235  GLHelper::drawFilledCircle(1);
236  glTranslated(-p.x(), -p.y(), .1);
237  }
238  }
239  }
240  */
241  glPopMatrix();
242  glPopName();
243 }
244 
245 
246 
247 
248 void
250  const GUIColorer& c = s.personColorer;
251  if (!setFunctionalColor(c.getActive())) {
253  }
254 }
255 
256 
257 bool
258 GUIPerson::setFunctionalColor(size_t activeScheme) const {
259  switch (activeScheme) {
260  case 0: {
261  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
263  return true;
264  }
265  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
266  GLHelper::setColor(getVehicleType().getColor());
267  return true;
268  }
269  return false;
270  }
271  case 2: {
272  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
274  return true;
275  }
276  return false;
277  }
278  case 3: {
279  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
280  GLHelper::setColor(getVehicleType().getColor());
281  return true;
282  }
283  return false;
284  }
285  default:
286  return false;
287  }
288 }
289 
290 
291 SUMOReal
292 GUIPerson::getColorValue(size_t activeScheme) const {
293  switch (activeScheme) {
294  case 4:
295  if (isWaiting4Vehicle()) {
296  return 3;
297  } else {
298  return (SUMOReal)getCurrentStageType();
299  }
300  case 5:
301  return STEPS2TIME(timeWaiting4Vehicle(MSNet::getInstance()->getCurrentTimeStep()));
302  }
303  return 0;
304 }
305 
306 
307 Position
310  return myPositionInVehicle;
311  }
312  return MSPerson::getPosition(now);
313 }
314 
315 
316 void
318  // draw triangle pointing down
319  glBegin(GL_TRIANGLES);
320  glVertex2d(0., 0.);
321  glVertex2d(-.5, 1.);
322  glVertex2d(.5, 1.);
323  glEnd();
324 }
325 
326 
327 void
329  // draw pedestrian shape
331  glRotated(getAngle(now), 0, 0, 1);
333  glTranslated(0, 0, .045);
335  glTranslated(0, 0, -.045);
336  glScaled(.7, 2, 1);
337  glTranslated(0, 0, .04);
338  GLHelper::setColor(lighter);
340  glTranslated(0, 0, -.04);
341 }
342 
343 
344 void
346  if (getVehicleType().getGuiShape() == SVS_PEDESTRIAN) {
348  glRotated(getAngle(now), 0, 0, 1);
349  }
350  const std::string& file = getVehicleType().getImgFile();
351  if (file != "") {
352  int textureID = GUITexturesHelper::getTextureID(file);
353  if (textureID > 0) {
354  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * s.vehicleExaggeration;
355  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
356  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
357  }
358  } else {
359  // fallback if no image is defined
361  }
362 }
363 /****************************************************************************/
364 
float vehicleExaggeration
The vehicle exaggeration (upscale)
const std::string & getID() const
returns the person id
Definition: MSPerson.cpp:524
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
Definition: GUIPerson.h:165
bool myAmVisualizedAsStopped
whether the person is visualized as stopped
Definition: GUIPerson.h:187
const RGBColor getColor(const SUMOReal value) const
const MSVehicleType & getVehicleType() const
Definition: MSPerson.h:591
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
GUIVisualizationTextSettings personName
void drawAction_drawAsImage(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:345
bool isWaiting4Vehicle() const
Whether the person waits for a vehicle.
Definition: MSPerson.h:576
const MSEdge * getFromEdge() const
Returns the departure edge.
Definition: MSPerson.h:524
Stores the information about how to visualize structures.
StageType getCurrentStageType() const
Definition: MSPerson.h:543
SUMOReal getLength() const
Get vehicle's length [m].
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
GUIPersonPopupMenu()
default constructor needed by FOX
Definition: GUIPerson.h:158
SUMOReal getColorValue(size_t activeScheme) const
gets the color value according to the current scheme index
Definition: GUIPerson.cpp:292
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
Definition: GUIPerson.cpp:249
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
Definition: MSNet.h:210
void drawAction_drawAsPoly(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:328
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.
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
The car-following model and parameter.
Definition: MSVehicleType.h:74
const MSEdge & getDestination() const
Returns the current destination.
Definition: MSPerson.h:514
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GUIPerson.cpp:134
SUMOReal scale
information about a lane's width (temporary, used for a single view)
const SUMOVehicleParameter & getParameter() const
Definition: MSPerson.h:586
float personExaggeration
The person exaggeration (upscale)
size_t getActive() const
Definition: GUIColorer.h:72
~GUIPersonPopupMenu()
Destructor.
Definition: GUIPerson.cpp:100
std::string getCurrentStageTypeName() const
Definition: MSPerson.h:548
static void drawFilledCircle(SUMOReal width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:247
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GUIPerson.cpp:119
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.h:159
virtual Position getPosition(SUMOTime now) const
Definition: MSPerson.h:533
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GUIPerson.cpp:150
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
Definition: GUIPerson.cpp:191
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:352
bool setFunctionalColor(size_t activeScheme) const
sets the color according to the current scheme index and some vehicle function
Definition: GUIPerson.cpp:258
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
a person
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
GUIColorer personColorer
The person colorer.
void drawAction_drawAsTriangle(const GUIVisualizationSettings &s) const
Definition: GUIPerson.cpp:317
void drawName(const Position &pos, const SUMOReal scale, const GUIVisualizationTextSettings &settings, const SUMOReal angle=0) const
const int VEHPARS_COLOR_SET
SUMOReal getAngle(SUMOTime now) const
Definition: MSPerson.h:538
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPerson.cpp:159
SUMOReal getWidth() const
Get the width which vehicles of this class shall have when being drawn.
render as a pedestrian
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
SUMOTime timeWaiting4Vehicle(SUMOTime now) const
the time this person spent waiting for a vehicle
Definition: MSPerson.h:582
Structure representing possible vehicle parameter.
GUIColorScheme & getScheme()
Definition: GUIColorer.h:76
RGBColor changedBrightness(const char change)
Returns a new color with altered brightness.
Definition: RGBColor.cpp:145
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
The popup menu of a globject.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
int personQuality
The quality of person drawing.
~GUIPerson()
destructor
Definition: GUIPerson.cpp:114
Base class for coloring. Allows changing the used colors and sets the used color in dependence to a v...
Definition: GUIColorer.h:50
Position getPosition(SUMOTime now) const
overrides the base method and returns myPositionInVehicle while in driving stage
Definition: GUIPerson.cpp:308
GUIPerson(const SUMOVehicleParameter *pars, const MSVehicleType *vtype, MSPerson::MSPersonPlan *plan)
Constructor.
Definition: GUIPerson.cpp:107
#define SUMOReal
Definition: config.h:215
std::string getImgFile() const
Get this vehicle type's raster model file name.
void mkItem(const char *name, bool dynamic, ValueSource< unsigned > *src)
Adds a row which obtains its value from an unsigned-ValueSource.
void closeBuilding()
Closes the building of the table.
Position myPositionInVehicle
The position of a person while riding a vehicle.
Definition: GUIPerson.h:175
std::vector< MSPersonStage * > MSPersonPlan
the structure holding the plan of a person
Definition: MSPerson.h:475
A window containing a gl-object's parameter.
const int VTYPEPARS_COLOR_SET
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:358
static int getTextureID(const std::string &filename)
return texture id for the given filename (initialize on first use)