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-2012 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 1:
262  return true;
263  // XXX color by stage
264  default:
265  return false;
266  }
267 }
268 
269 
270 SUMOReal
271 GUIPerson::getColorValue(size_t /* activeScheme */) const {
272  // XXX color by time spend waiting for a ride
273  /*
274  switch (activeScheme) {
275  case 7:
276  return getSpeed();
277  case 8:
278  return getWaitingSeconds();
279  case 9:
280  return getLastLaneChangeOffset();
281  case 10:
282  return getMaxSpeed();
283  case 11:
284  return getHBEFA_CO2Emissions();
285  case 12:
286  return getHBEFA_COEmissions();
287  case 13:
288  return getHBEFA_PMxEmissions();
289  case 14:
290  return getHBEFA_NOxEmissions();
291  case 15:
292  return getHBEFA_HCEmissions();
293  case 16:
294  return getHBEFA_FuelConsumption();
295  case 17:
296  return getHarmonoise_NoiseEmissions();
297  case 18:
298  if (getNumberReroutes() == 0) {
299  return -1;
300  }
301  return getNumberReroutes();
302  }
303  */
304  return 0;
305 }
306 
307 
308 Position
310  if ((*myStep)->getStageType() == DRIVING && !isWaiting4Vehicle()) {
311  return myPositionInVehicle;
312  }
313  return MSPerson::getPosition(now);
314 }
315 
316 
317 void
319  // draw triangle pointing down
320  glBegin(GL_TRIANGLES);
321  glVertex2d(0., 0.);
322  glVertex2d(-.5, 1.);
323  glVertex2d(.5, 1.);
324  glEnd();
325 }
326 
327 
328 void
330  // draw pedestrian shape
332  glRotated(getAngle(now), 0, 0, 1);
334  glTranslated(0, 0, .045);
336  glTranslated(0, 0, -.045);
337  glScaled(.7, 2, 1);
338  glTranslated(0, 0, .04);
339  GLHelper::setColor(lighter);
341  glTranslated(0, 0, -.04);
342 }
343 
344 
345 void
347  if (getVehicleType().getGuiShape() == SVS_PEDESTRIAN) {
349  glRotated(getAngle(now), 0, 0, 1);
350  }
351  const std::string& file = getVehicleType().getImgFile();
352  if (file != "") {
353  int textureID = GUITexturesHelper::getTextureID(file);
354  if (textureID > 0) {
355  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * s.vehicleExaggeration;
356  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
357  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
358  }
359  } else {
360  // fallback if no image is defined
362  }
363 }
364 /****************************************************************************/
365