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>
52 #include <utils/gui/div/GLHelper.h>
55 #include <gui/GUIGlobals.h>
56 #include "GUIPerson.h"
57 #include "GUINet.h"
58 #include "GUIEdge.h"
60 
61 #ifdef CHECK_MEMORY_LEAKS
62 #include <foreign/nvwa/debug_new.h>
63 #endif // CHECK_MEMORY_LEAKS
64 
65 //#define GUIPerson_DEBUG_DRAW_WALKING_AREA_SHAPE
66 
67 // ===========================================================================
68 // FOX callback mapping
69 // ===========================================================================
70 /*
71 FXDEFMAP(GUIPerson::GUIPersonPopupMenu) GUIPersonPopupMenuMap[] = {
72  FXMAPFUNC(SEL_COMMAND, MID_SHOW_ALLROUTES, GUIPerson::GUIPersonPopupMenu::onCmdShowAllRoutes),
73  FXMAPFUNC(SEL_COMMAND, MID_HIDE_ALLROUTES, GUIPerson::GUIPersonPopupMenu::onCmdHideAllRoutes),
74  FXMAPFUNC(SEL_COMMAND, MID_SHOW_CURRENTROUTE, GUIPerson::GUIPersonPopupMenu::onCmdShowCurrentRoute),
75  FXMAPFUNC(SEL_COMMAND, MID_HIDE_CURRENTROUTE, GUIPerson::GUIPersonPopupMenu::onCmdHideCurrentRoute),
76  FXMAPFUNC(SEL_COMMAND, MID_SHOW_BEST_LANES, GUIPerson::GUIPersonPopupMenu::onCmdShowBestLanes),
77  FXMAPFUNC(SEL_COMMAND, MID_HIDE_BEST_LANES, GUIPerson::GUIPersonPopupMenu::onCmdHideBestLanes),
78  FXMAPFUNC(SEL_COMMAND, MID_START_TRACK, GUIPerson::GUIPersonPopupMenu::onCmdStartTrack),
79  FXMAPFUNC(SEL_COMMAND, MID_STOP_TRACK, GUIPerson::GUIPersonPopupMenu::onCmdStopTrack),
80  FXMAPFUNC(SEL_COMMAND, MID_SHOW_LFLINKITEMS, GUIPerson::GUIPersonPopupMenu::onCmdShowLFLinkItems),
81  FXMAPFUNC(SEL_COMMAND, MID_HIDE_LFLINKITEMS, GUIPerson::GUIPersonPopupMenu::onCmdHideLFLinkItems),
82 };
83 
84 // Object implementation
85 FXIMPLEMENT(GUIPerson::GUIPersonPopupMenu, GUIGLObjectPopupMenu, GUIPersonPopupMenuMap, ARRAYNUMBER(GUIPersonPopupMenuMap))
86 */
87 
88 
89 
90 // ===========================================================================
91 // method definitions
92 // ===========================================================================
93 /* -------------------------------------------------------------------------
94  * GUIPerson::GUIPersonPopupMenu - methods
95  * ----------------------------------------------------------------------- */
97  GUIMainWindow& app, GUISUMOAbstractView& parent,
98  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
99  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
100 }
101 
102 
104 
105 
106 
107 /* -------------------------------------------------------------------------
108  * GUIPerson - methods
109  * ----------------------------------------------------------------------- */
111  MSPerson(pars, vtype, plan),
112  GUIGlObject(GLO_PERSON, pars->id),
114 { }
115 
116 
118 }
119 
120 
123  GUISUMOAbstractView& parent) {
125  buildPopupHeader(ret, app);
129  //
131  buildPositionCopyEntry(ret, false);
132  return ret;
133 }
134 
135 
140  new GUIParameterTableWindow(app, *this, 8);
141  // add items
142  //ret->mkItem("type [NAME]", false, myType->getID());
143  ret->mkItem("stage", false, getCurrentStageDescription());
144  ret->mkItem("start edge [id]", false, getFromEdge()->getID());
145  ret->mkItem("dest edge [id]", false, getDestination().getID());
146  ret->mkItem("edge [id]", false, getEdge()->getID());
147  ret->mkItem("position [m]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getEdgePos));
148  ret->mkItem("speed [m/s]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getSpeed));
149  ret->mkItem("angle [degree]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getAngle));
150  ret->mkItem("waiting time [s]", true, new FunctionBinding<GUIPerson, SUMOReal>(this, &GUIPerson::getWaitingSeconds));
151  // close building
152  ret->closeBuilding();
153  return ret;
154 }
155 
156 
157 Boundary
159  Boundary b;
160  b.add(getPosition());
161  b.grow(20);
162  return b;
163 }
164 
165 
166 void
168  glPushName(getGlID());
169  glPushMatrix();
170  Position p1 = getPosition();
171  glTranslated(p1.x(), p1.y(), getType());
172  glRotated(90, 0, 0, 1);
173  // XXX use person specific gui settings
174  // set person color
175  setColor(s);
176  // scale
177  SUMOReal upscale = s.personExaggeration;
178  glScaled(upscale, upscale, 1);
179  switch (s.personQuality) {
180  case 0:
181  case 1:
183  break;
184  case 2:
186  break;
187  case 3:
188  default:
190  break;
191  }
192  glPopMatrix();
193 
194 #ifdef GUIPerson_DEBUG_DRAW_WALKING_AREA_SHAPE
196  if (stage != 0) {
197  MSPModel_Striping::PState* stripingState = dynamic_cast<MSPModel_Striping::PState*>(stage->getPedestrianState());
198  if (stripingState != 0) {
199  MSPModel_Striping::WalkingAreaPath* waPath = stripingState->myWalkingAreaPath;
200  if (waPath != 0) {
201  glPushMatrix();
202  glTranslated(0, 0, getType());
203  GLHelper::drawBoxLines(waPath->shape, 0.05);
204  glPopMatrix();
205  }
206  }
207  }
208 #endif
209 
210  drawName(p1, s.scale, s.personName);
211  glPopName();
212 }
213 
214 
215 void
217  glPushName(getGlID());
218  glPushMatrix();
219  /*
220  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
221  if (hasActiveAddVisualisation(parent, VO_SHOW_BEST_LANES)) {
222  drawBestLanes();
223  }
224  if (hasActiveAddVisualisation(parent, VO_SHOW_ROUTE)) {
225  drawRoute(s, 0, 0.25);
226  }
227  if (hasActiveAddVisualisation(parent, VO_SHOW_ALL_ROUTES)) {
228  if (getNumberReroutes() > 0) {
229  const int noReroutePlus1 = getNumberReroutes() + 1;
230  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
231  SUMOReal darken = SUMOReal(0.4) / SUMOReal(noReroutePlus1) * SUMOReal(i);
232  drawRoute(s, i, darken);
233  }
234  } else {
235  drawRoute(s, 0, 0.25);
236  }
237  }
238  if (hasActiveAddVisualisation(parent, VO_SHOW_LFLINKITEMS)) {
239  for (DriveItemVector::const_iterator i = myLFLinkLanes.begin(); i != myLFLinkLanes.end(); ++i) {
240  if((*i).myLink==0) {
241  continue;
242  }
243  MSLink* link = (*i).myLink;
244  #ifdef HAVE_INTERNAL_LANES
245  MSLane *via = link->getViaLane();
246  if (via == 0) {
247  via = link->getLane();
248  }
249  #else
250  MSLane *via = link->getLane();
251  #endif
252  if (via != 0) {
253  Position p = via->getShape()[0];
254  if((*i).mySetRequest) {
255  glColor3f(0, 1, 0);
256  } else {
257  glColor3f(1, 0, 0);
258  }
259  glTranslated(p.x(), p.y(), -.1);
260  GLHelper::drawFilledCircle(1);
261  glTranslated(-p.x(), -p.y(), .1);
262  }
263  }
264  }
265  */
266  glPopMatrix();
267  glPopName();
268 }
269 
270 
271 
272 
273 void
275  const GUIColorer& c = s.personColorer;
276  if (!setFunctionalColor(c.getActive())) {
278  }
279 }
280 
281 
282 bool
283 GUIPerson::setFunctionalColor(size_t activeScheme) const {
284  switch (activeScheme) {
285  case 0: {
286  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
288  return true;
289  }
290  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
291  GLHelper::setColor(getVehicleType().getColor());
292  return true;
293  }
294  return false;
295  }
296  case 2: {
297  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
299  return true;
300  }
301  return false;
302  }
303  case 3: {
304  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
305  GLHelper::setColor(getVehicleType().getColor());
306  return true;
307  }
308  return false;
309  }
310  case 8: {
311  SUMOReal hue = getAngle() + 180; // [0-360]
313  return true;
314  }
315  default:
316  return false;
317  }
318 }
319 
320 
321 SUMOReal
322 GUIPerson::getColorValue(size_t activeScheme) const {
323  switch (activeScheme) {
324  case 4:
325  return getSpeed();
326  case 5:
327  if (isWaiting4Vehicle()) {
328  return 3;
329  } else {
330  return (SUMOReal)getCurrentStageType();
331  }
332  case 6:
333  return getWaitingSeconds();
334  case 7:
336  }
337  return 0;
338 }
339 
340 
341 SUMOReal
344  return MSPerson::getEdgePos();
345 }
346 
347 
348 Position
352  return myPositionInVehicle;
353  }
354  return MSPerson::getPosition();
355 }
356 
357 
358 SUMOReal
361  return MSPerson::getAngle();
362 }
363 
364 
365 SUMOReal
369 }
370 
371 
372 SUMOReal
375  return MSPerson::getSpeed();
376 }
377 
378 
379 void
381  // draw triangle pointing forward
382  glRotated(getAngle(), 0, 0, 1);
383  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
384  glBegin(GL_TRIANGLES);
385  glVertex2d(0., 0.);
386  glVertex2d(1, -0.5);
387  glVertex2d(1, 0.5);
388  glEnd();
389 }
390 
391 
392 void
394  // draw pedestrian shape
395  glRotated(getAngle(), 0, 0, 1);
396  glScaled(getVehicleType().getLength(), getVehicleType().getWidth(), 1);
398  glTranslated(0, 0, .045);
399  // head
400  glScaled(1, 0.5, 1.);
402  // nose
403  glBegin(GL_TRIANGLES);
404  glVertex2d(0.0, -0.2);
405  glVertex2d(0.0, 0.2);
406  glVertex2d(-0.6, 0.0);
407  glEnd();
408  glTranslated(0, 0, -.045);
409  // body
410  glScaled(0.9, 2.0, 1);
411  glTranslated(0, 0, .04);
412  GLHelper::setColor(lighter);
414  glTranslated(0, 0, -.04);
415 }
416 
417 
418 void
420  const std::string& file = getVehicleType().getImgFile();
421  if (file != "") {
422  if (getVehicleType().getGuiShape() == SVS_PEDESTRIAN) {
423  glRotated(getAngle(), 0, 0, 1);
424  }
425  int textureID = GUITexturesHelper::getTextureID(file);
426  if (textureID > 0) {
427  const SUMOReal halfLength = getVehicleType().getLength() / 2.0 * s.vehicleExaggeration;
428  const SUMOReal halfWidth = getVehicleType().getWidth() / 2.0 * s.vehicleExaggeration;
429  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, -halfLength, halfWidth, halfLength);
430  }
431  } else {
432  // fallback if no image is defined
434  }
435 }
436 /****************************************************************************/
437