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 MSVehicle extended by some values for usage within the gui
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12 // Copyright (C) 2001-2013 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.vehicleExaggeration;
170  glScaled(upscale, upscale, 1);
171  switch (s.vehicleQuality) {
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.vehicleName);
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.vehicleColorer;
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  // XXX color by time spend waiting for a ride
294  /*
295  switch (activeScheme) {
296  case 7:
297  return getSpeed();
298  case 8:
299  return getWaitingSeconds();
300  case 9:
301  return getLastLaneChangeOffset();
302  case 10:
303  return getMaxSpeed();
304  case 11:
305  return getHBEFA_CO2Emissions();
306  case 12:
307  return getHBEFA_COEmissions();
308  case 13:
309  return getHBEFA_PMxEmissions();
310  case 14:
311  return getHBEFA_NOxEmissions();
312  case 15:
313  return getHBEFA_HCEmissions();
314  case 16:
315  return getHBEFA_FuelConsumption();
316  case 17:
317  return getHarmonoise_NoiseEmissions();
318  case 18:
319  if (getNumberReroutes() == 0) {
320  return -1;
321  }
322  return getNumberReroutes();
323  }
324  */
325  return 0;
326 }
327 
328 
329 Position
331  if ((*myStep)->getStageType() == DRIVING && !isWaiting4Vehicle()) {
332  return myPositionInVehicle;
333  }
334  return MSPerson::getPosition(now);
335 }
336 
337 
338 void
340  // draw triangle pointing down
341  glBegin(GL_TRIANGLES);
342  glVertex2d(0., 0.);
343  glVertex2d(-.5, 1.);
344  glVertex2d(.5, 1.);
345  glEnd();
346 }
347 
348 
349 void
351  // draw pedestrian shape
353  glRotated(getAngle(now), 0, 0, 1);
355  glTranslated(0, 0, .045);
357  glTranslated(0, 0, -.045);
358  glScaled(.7, 2, 1);
359  glTranslated(0, 0, .04);
360  GLHelper::setColor(lighter);
362  glTranslated(0, 0, -.04);
363 }
364 
365 
366 void
368  if (getVehicleType().getGuiShape() == SVS_PEDESTRIAN) {
370  glRotated(getAngle(now), 0, 0, 1);
371  }
372  const std::string& file = getVehicleType().getImgFile();
373  if (file != "") {
374  int textureID = GUITexturesHelper::getTextureID(file);
375  if (textureID > 0) {
376  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * s.vehicleExaggeration;
377  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
378  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
379  }
380  } else {
381  // fallback if no image is defined
383  }
384 }
385 /****************************************************************************/
386