SUMO - Simulation of Urban MObility
GUIBaseVehicle.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 /****************************************************************************/
18 // A MSVehicle extended by some values for usage within the gui
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <cmath>
28 #include <vector>
29 #include <string>
30 #include <functional>
32 #include <utils/geom/GeomHelper.h>
40 #include <utils/gui/div/GLHelper.h>
42 #include <microsim/MSVehicle.h>
43 #include <microsim/MSLane.h>
52 #include <gui/GUIGlobals.h>
53 #include "GUIBaseVehicle.h"
54 #include "GUIPerson.h"
55 #include "GUIContainer.h"
56 #include "GUINet.h"
57 #include "GUIEdge.h"
58 #include "GUILane.h"
59 
60 //#define DRAW_BOUNDING_BOX
61 
62 // ===========================================================================
63 // FOX callback mapping
64 // ===========================================================================
65 FXDEFMAP(GUIBaseVehicle::GUIBaseVehiclePopupMenu) GUIBaseVehiclePopupMenuMap[] = {
77 };
78 
79 // Object implementation
80 FXIMPLEMENT(GUIBaseVehicle::GUIBaseVehiclePopupMenu, GUIGLObjectPopupMenu, GUIBaseVehiclePopupMenuMap, ARRAYNUMBER(GUIBaseVehiclePopupMenuMap))
81 
82 
83 
84 // ===========================================================================
85 // data definitions
86 // ===========================================================================
87 /* -------------------------------------------------------------------------
88  * drawed shapes
89  * ----------------------------------------------------------------------- */
90 double vehiclePoly_PassengerCarBody[] = { .5, 0, 0, 0, 0, .3, 0.08, .44, 0.25, .5, 0.95, .5, 1., .4, 1., -.4, 0.95, -.5, 0.25, -.5, 0.08, -.44, 0, -.3, 0, 0, -10000 };
91 double vehiclePoly_PassengerCarBodyFront[] = { 0.1, 0, 0.025, 0, 0.025, 0.25, 0.27, 0.4, 0.27, -.4, 0.025, -0.25, 0.025, 0, -10000 };
92 double vehiclePoly_PassengerFrontGlass[] = { 0.35, 0, 0.3, 0, 0.3, 0.4, 0.43, 0.3, 0.43, -0.3, 0.3, -0.4, 0.3, 0, -10000 };
93 double vehiclePoly_PassengerSedanRightGlass[] = { 0.36, -.43, 0.34, -.47, 0.77, -.47, 0.67, -.37, 0.45, -.37, 0.34, -.47, -10000 };
94 double vehiclePoly_PassengerSedanLeftGlass[] = { 0.36, .43, 0.34, .47, 0.77, .47, 0.67, .37, 0.45, .37, 0.34, .47, -10000 };
95 double vehiclePoly_PassengerSedanBackGlass[] = { 0.80, 0, 0.70, 0, 0.70, 0.3, 0.83, 0.4, 0.83, -.4, 0.70, -.3, 0.70, 0, -10000 };
96 double vehiclePoly_PassengerHatchbackRightGlass[] = { 0.36, -.43, 0.34, -.47, 0.94, -.47, 0.80, -.37, 0.45, -.37, 0.34, -.47, -10000 };
97 double vehiclePoly_PassengerHatchbackLeftGlass[] = { 0.36, .43, 0.34, .47, 0.94, .47, 0.80, .37, 0.45, .37, 0.34, .47, -10000 };
98 double vehiclePoly_PassengerHatchbackBackGlass[] = { 0.92, 0, 0.80, 0, 0.80, 0.3, 0.95, 0.4, 0.95, -.4, 0.80, -.3, 0.80, 0, -10000 };
99 double vehiclePoly_PassengerWagonRightGlass[] = { 0.36, -.43, 0.34, -.47, 0.94, -.47, 0.87, -.37, 0.45, -.37, 0.34, -.47, -10000 };
100 double vehiclePoly_PassengerWagonLeftGlass[] = { 0.36, .43, 0.34, .47, 0.94, .47, 0.87, .37, 0.45, .37, 0.34, .47, -10000 };
101 double vehiclePoly_PassengerWagonBackGlass[] = { 0.92, 0, 0.90, 0, 0.90, 0.3, 0.95, 0.4, 0.95, -.4, 0.90, -.3, 0.90, 0, -10000 };
102 
103 double vehiclePoly_PassengerVanBody[] = { .5, 0, 0, 0, 0, .4, 0.1, .5, 0.97, .5, 1., .47, 1., -.47, 0.97, -.5, 0.1, -.5, 0, -.4, 0, 0, -10000 };
104 double vehiclePoly_PassengerVanBodyFront[] = { 0.1, 0, 0.025, 0, 0.025, 0.25, 0.13, 0.4, 0.13, -.4, 0.025, -0.25, 0.025, 0, -10000 };
105 double vehiclePoly_PassengerVanFrontGlass[] = { 0.21, 0, 0.16, 0, 0.16, 0.4, 0.29, 0.3, 0.29, -0.3, 0.16, -0.4, 0.16, 0, -10000 };
106 double vehiclePoly_PassengerVanRightGlass[] = { 0.36, -.43, 0.20, -.47, 0.98, -.47, 0.91, -.37, 0.31, -.37, 0.20, -.47, -10000 };
107 double vehiclePoly_PassengerVanLeftGlass[] = { 0.36, .43, 0.20, .47, 0.98, .47, 0.91, .37, 0.31, .37, 0.20, .47, -10000 };
108 double vehiclePoly_PassengerVanBackGlass[] = { 0.95, 0, 0.94, 0, 0.94, 0.3, 0.98, 0.4, 0.98, -.4, 0.94, -.3, 0.94, 0, -10000 };
109 
110 double vehiclePoly_DeliveryMediumRightGlass[] = { 0.21, -.43, 0.20, -.47, 0.38, -.47, 0.38, -.37, 0.31, -.37, 0.20, -.47, -10000 };
111 double vehiclePoly_DeliveryMediumLeftGlass[] = { 0.21, .43, 0.20, .47, 0.38, .47, 0.38, .37, 0.31, .37, 0.20, .47, -10000 };
112 
113 double vehiclePoly_TransportBody[] = { .5, 0, 0, 0, 0, .45, 0.05, .5, 2.25, .5, 2.25, -.5, 0.05, -.5, 0, -.45, 0, 0, -10000 };
114 double vehiclePoly_TransportFrontGlass[] = { 0.1, 0, 0.05, 0, 0.05, 0.45, 0.25, 0.4, 0.25, -.4, 0.05, -0.45, 0.05, 0, -10000 };
115 double vehiclePoly_TransportRightGlass[] = { 0.36, -.47, 0.10, -.48, 1.25, -.48, 1.25, -.4, 0.3, -.4, 0.10, -.48, -10000 };
116 double vehiclePoly_TransportLeftGlass[] = { 0.36, .47, 0.10, .48, 1.25, .48, 1.25, .4, 0.3, .4, 0.10, .48, -10000 };
117 
118 double vehiclePoly_EVehicleBody[] = { .5, 0, 0, 0, 0, .3, 0.08, .44, 0.25, .5, 0.75, .5, .92, .44, 1, .3, 1, -.3, .92, -.44, .75, -.5, .25, -.5, 0.08, -.44, 0, -.3, 0, 0, -1000 };
119 double vehiclePoly_EVehicleFrontGlass[] = { .5, 0, 0.05, .05, 0.05, .25, 0.13, .39, 0.3, .45, 0.70, .45, .87, .39, .95, .25, .95, -.25, .87, -.39, .70, -.45, .3, -.45, 0.13, -.39, 0.05, -.25, 0.05, 0.05, -1000 };
120 //double vehiclePoly_EVehicleFrontGlass[] = { 0.35,0, 0.1,0, 0.1,0.4, 0.43,0.3, 0.43,-0.3, 0.1,-0.4, 0.1,0, -10000 };
121 double vehiclePoly_EVehicleBackGlass[] = { 0.65, 0, 0.9, 0, 0.9, 0.4, 0.57, 0.3, 0.57, -0.3, 0.9, -0.4, 0.9, 0, -10000 };
122 
123 double vehiclePoly_Ship[] = { 0.25, 0, 0, 0, 0.1, 0.25, 0.2, 0.45, 0.25, 0.5, 0.95, 0.5, 1.0, 0.45, 1.0, -0.45, 0.95, -0.5, 0.25, -0.5, 0.2, -0.45, 0.1, -0.25, 0, 0, -10000 };
124 double vehiclePoly_ShipDeck[] = { 0.5, 0, 0.25, 0.4, 0.95, 0.4, 0.95, -0.4, 0.25, -0.4, 0.25, 0.4, -10000 };
125 double vehiclePoly_ShipSuperStructure[] = { 0.8, 0, 0.5, 0.3, 0.85, 0.3, 0.85, -0.3, 0.5, -0.3, 0.5, 0.3, -10000 };
126 
127 double vehiclePoly_Cyclist[] = { 0.5, 0, 0.25, 0.45, 0.25, 0.5, 0.8, 0.15, 0.8, -0.15, 0.25, -0.5, 0.25, -0.45, -10000 };
128 
129 double vehiclePoly_EmergencySign[] = { .2, .5, -.2, .5, -.2, -.5, .2, -.5, -10000 };
130 double vehiclePoly_Emergency[] = { .1, .1, -.1, .1, -.1, -.1, .1, -.1, -10000 };
131 double vehiclePoly_Emergency2[] = { .04, .3, -.04, .3, -.04, -.3, .04, -.3, -10000 };
132 
133 double vehiclePoly_EmergencyLadder[] = { -.5, .3, .5, .3, .5, .2, -.5, .2, -10000 };
134 double vehiclePoly_EmergencyLadder2[] = { -.5, -.3, .5, -.3, .5, -.2, -.5, -.2, -10000 };
135 double vehiclePoly_EmergencyLadder3[] = { -.45, .3, -.4, .3, -.4, -.3, -.45, -.3, -10000 };
136 double vehiclePoly_EmergencyLadder4[] = { .45, .3, .4, .3, .4, -.3, .45, -.3, -10000 };
137 double vehiclePoly_EmergencyLadder5[] = { .05, .3, .0, .3, .0, -.3, .05, -.3, -10000 };
138 double vehiclePoly_EmergencyLadder6[] = { -.25, .3, -.2, .3, -.2, -.3, -.25, -.3, -10000 };
139 double vehiclePoly_EmergencyLadder7[] = { .25, .3, .2, .3, .2, -.3, .25, -.3, -10000 };
140 
141 double vehiclePoly_Rickshaw[] = { 0.5, 0, 0.25, 0.45, 0.25, 0.5, 0.8, 0.15, 0.8, -0.15, 0.25, -0.5, 0.25, -0.45, -10000 };
142 
143 // ===========================================================================
144 // method definitions
145 // ===========================================================================
146 /* -------------------------------------------------------------------------
147  * GUIBaseVehicle::GUIBaseVehiclePopupMenu - methods
148  * ----------------------------------------------------------------------- */
150  GUIMainWindow& app, GUISUMOAbstractView& parent,
151  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
152  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
153 }
154 
155 
157 
158 
159 long
161  assert(myObject->getType() == GLO_VEHICLE);
162  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES)) {
164  }
165  return 1;
166 }
167 
168 long
170  assert(myObject->getType() == GLO_VEHICLE);
172  return 1;
173 }
174 
175 
176 long
178  assert(myObject->getType() == GLO_VEHICLE);
179  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE)) {
181  }
182  return 1;
183 }
184 
185 long
187  assert(myObject->getType() == GLO_VEHICLE);
189  return 1;
190 }
191 
192 
193 long
195  assert(myObject->getType() == GLO_VEHICLE);
196  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES)) {
198  }
199  return 1;
200 }
201 
202 long
204  assert(myObject->getType() == GLO_VEHICLE);
206  return 1;
207 }
208 
209 
210 long
212  assert(myObject->getType() == GLO_VEHICLE);
213  if (myParent->getTrackedID() != static_cast<GUIBaseVehicle*>(myObject)->getGlID()) {
214  myParent->startTrack(static_cast<GUIBaseVehicle*>(myObject)->getGlID());
215  }
216  return 1;
217 }
218 
219 long
221  assert(myObject->getType() == GLO_VEHICLE);
222  myParent->stopTrack();
223  return 1;
224 }
225 
226 
227 long
229  assert(myObject->getType() == GLO_VEHICLE);
230  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS)) {
232  }
233  return 1;
234 }
235 
236 long
238  assert(myObject->getType() == GLO_VEHICLE);
240  return 1;
241 }
242 
243 long
245  assert(myObject->getType() == GLO_VEHICLE);
246  static_cast<GUIBaseVehicle*>(myObject)->selectBlockingFoes();
247  myParent->update();
248  return 1;
249 }
250 
251 
252 /* -------------------------------------------------------------------------
253  * GUIBaseVehicle - methods
254  * ----------------------------------------------------------------------- */
255 
257  GUIGlObject(GLO_VEHICLE, vehicle.getID()),
258  myVehicle(vehicle) {
259  // as it is possible to show all vehicle routes, we have to store them... (bug [ 2519761 ])
261  myVehicle.myMoveReminders.push_back(std::make_pair(myRoutes, 0.));
262  mySeatPositions.push_back(Position(0, 0)); // ensure length 1
263 }
264 
265 
267  myLock.lock();
268  for (std::map<GUISUMOAbstractView*, int>::iterator i = myAdditionalVisualizations.begin(); i != myAdditionalVisualizations.end(); ++i) {
269  if (i->first->getTrackedID() == getGlID()) {
270  i->first->stopTrack();
271  }
272  while (i->first->removeAdditionalGLVisualisation(this));
273  }
274  myLock.unlock();
275  delete myRoutes;
276 }
277 
278 
281  GUISUMOAbstractView& parent) {
283  buildPopupHeader(ret, app);
287  //
289  new FXMenuCommand(ret, "Hide Current Route", nullptr, ret, MID_HIDE_CURRENTROUTE);
290  } else {
291  new FXMenuCommand(ret, "Show Current Route", nullptr, ret, MID_SHOW_CURRENTROUTE);
292  }
294  new FXMenuCommand(ret, "Hide All Routes", nullptr, ret, MID_HIDE_ALLROUTES);
295  } else {
296  new FXMenuCommand(ret, "Show All Routes", nullptr, ret, MID_SHOW_ALLROUTES);
297  }
299  new FXMenuCommand(ret, "Hide Best Lanes", nullptr, ret, MID_HIDE_BEST_LANES);
300  } else {
301  new FXMenuCommand(ret, "Show Best Lanes", nullptr, ret, MID_SHOW_BEST_LANES);
302  }
304  new FXMenuCommand(ret, "Hide Link Items", nullptr, ret, MID_HIDE_LFLINKITEMS);
305  } else {
306  new FXMenuCommand(ret, "Show Link Items", nullptr, ret, MID_SHOW_LFLINKITEMS);
307  }
308  new FXMenuSeparator(ret);
309  if (parent.getTrackedID() != getGlID()) {
310  new FXMenuCommand(ret, "Start Tracking", nullptr, ret, MID_START_TRACK);
311  } else {
312  new FXMenuCommand(ret, "Stop Tracking", nullptr, ret, MID_STOP_TRACK);
313  }
314  new FXMenuCommand(ret, "Select Foes", nullptr, ret, MID_SHOW_FOES);
315 
316  new FXMenuSeparator(ret);
317  //
318  buildShowParamsPopupEntry(ret, false);
320  buildPositionCopyEntry(ret, false);
321  return ret;
322 }
323 
324 
325 Boundary
327  Boundary b;
328  b.add(getPosition());
330  return b;
331 }
332 
333 
334 void
336  glPushMatrix();
337  glScaled(getVType().getWidth(), getVType().getLength(), 1.);
338  glBegin(GL_TRIANGLE_STRIP);
339  glVertex2d(0., 0.);
340  glVertex2d(-.5, .15);
341  glVertex2d(.5, .15);
342  glVertex2d(-.5, 1.);
343  glVertex2d(.5, 1.);
344  glEnd();
345  glPopMatrix();
346 }
347 
348 
349 void
351  const double length = getVType().getLength();
352  if (length >= 8.) {
354  return;
355  }
356  glPushMatrix();
357  glScaled(getVType().getWidth(), length, 1.);
358  glBegin(GL_TRIANGLES);
359  glVertex2d(0., 0.);
360  glVertex2d(-.5, 1.);
361  glVertex2d(.5, 1.);
362  glEnd();
363  glPopMatrix();
364 }
365 
366 
367 void
368 GUIBaseVehicle::drawPoly(double* poses, double offset) {
369  glPushMatrix();
370  glTranslated(0, 0, offset * .1);
371  glPolygonOffset(0, (GLfloat) - offset);
372  glBegin(GL_TRIANGLE_FAN);
373  int i = 0;
374  while (poses[i] > -999) {
375  glVertex2d(poses[i], poses[i + 1]);
376  i = i + 2;
377  }
378  glEnd();
379  glPopMatrix();
380 }
381 
382 
383 bool
385  RGBColor current = GLHelper::getColor();
386  RGBColor lighter = current.changedBrightness(51);
387  RGBColor darker = current.changedBrightness(-51);
388 
389  const double length = getVType().getLength();
390  const double width = getVType().getWidth();
391  glPushMatrix();
392  glRotated(90, 0, 0, 1);
393  glScaled(length, width, 1.);
395  bool drawCarriages = false;
396 
397  // draw main body
398  switch (shape) {
399  case SVS_UNKNOWN:
401  GLHelper::setColor(lighter);
402  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
403  glColor3d(0, 0, 0);
404  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
405  break;
406  case SVS_PEDESTRIAN:
407  glTranslated(0, 0, .045);
409  glTranslated(0, 0, -.045);
410  glScaled(.7, 2, 1);
411  glTranslated(0, 0, .04);
412  GLHelper::setColor(lighter);
414  glTranslated(0, 0, -.04);
415  break;
416  case SVS_BICYCLE:
417  case SVS_MOPED:
418  case SVS_MOTORCYCLE: {
419  RGBColor darker = current.changedBrightness(-50);
420  // body
421  drawPoly(vehiclePoly_Cyclist, 4);
422  // head
423  glPushMatrix();
424  glTranslated(0.4, 0, .5);
425  glScaled(0.1, 0.2, 1);
426  GLHelper::setColor(darker);
428  glPopMatrix();
429  // bike frame
431  glPushMatrix();
432  glTranslated(0.5, 0, .3);
433  glScaled(0.5, 0.05, 1);
435  glPopMatrix();
436  // handle bar
437  glPushMatrix();
438  glTranslated(0.25, 0, .3);
439  glScaled(0.02, 0.5, 1);
441  glPopMatrix();
442  }
443  break;
444  case SVS_PASSENGER:
445  case SVS_PASSENGER_SEDAN:
447  case SVS_PASSENGER_WAGON:
449  GLHelper::setColor(lighter);
450  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
451  glColor3d(0, 0, 0);
452  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
453  break;
454  case SVS_PASSENGER_VAN:
455  drawPoly(vehiclePoly_PassengerVanBody, 4);
456  GLHelper::setColor(lighter);
457  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
458  glColor3d(0, 0, 0);
459  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
460  drawPoly(vehiclePoly_PassengerVanRightGlass, 4.5);
461  drawPoly(vehiclePoly_PassengerVanLeftGlass, 4.5);
462  drawPoly(vehiclePoly_PassengerVanBackGlass, 4.5);
463  break;
464  case SVS_DELIVERY:
465  drawPoly(vehiclePoly_PassengerVanBody, 4);
466  GLHelper::setColor(lighter);
467  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
468  glColor3d(0, 0, 0);
469  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
470  drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5);
471  drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5);
472  break;
473  case SVS_TRUCK:
475  case SVS_TRUCK_1TRAILER:
476  glScaled(1. / (length), 1, 1.);
477  drawPoly(vehiclePoly_TransportBody, 4);
478  glColor3d(0, 0, 0);
479  drawPoly(vehiclePoly_TransportFrontGlass, 4.5);
480  drawPoly(vehiclePoly_TransportRightGlass, 4.5);
481  drawPoly(vehiclePoly_TransportLeftGlass, 4.5);
482  break;
483  case SVS_BUS:
484  case SVS_BUS_COACH:
485  case SVS_BUS_TROLLEY: {
486  double ml = length;
487  glScaled(1. / (length), 1, 1.);
488  glTranslated(0, 0, .04);
489  glBegin(GL_TRIANGLE_FAN);
490  glVertex2d(ml / 2., 0);
491  glVertex2d(0, 0);
492  glVertex2d(0, -.45);
493  glVertex2d(0 + .05, -.5);
494  glVertex2d(ml - .05, -.5);
495  glVertex2d(ml, -.45);
496  glVertex2d(ml, .45);
497  glVertex2d(ml - .05, .5);
498  glVertex2d(0 + .05, .5);
499  glVertex2d(0, .45);
500  glVertex2d(0, 0);
501  glEnd();
502  glTranslated(0, 0, -.04);
503 
504  glTranslated(0, 0, .045);
505  glColor3d(0, 0, 0);
506  glBegin(GL_QUADS);
507  glVertex2d(0 + .05, .48);
508  glVertex2d(0 + .05, -.48);
509  glVertex2d(0 + .15, -.48);
510  glVertex2d(0 + .15, .48);
511 
512  glVertex2d(ml - .1, .45);
513  glVertex2d(ml - .1, -.45);
514  glVertex2d(ml - .05, -.45);
515  glVertex2d(ml - .05, .45);
516 
517  glVertex2d(0 + .20, .49);
518  glVertex2d(0 + .20, .45);
519  glVertex2d(ml - .20, .45);
520  glVertex2d(ml - .20, .49);
521 
522  glVertex2d(0 + .20, -.49);
523  glVertex2d(0 + .20, -.45);
524  glVertex2d(ml - .20, -.45);
525  glVertex2d(ml - .20, -.49);
526 
527  glEnd();
528  glTranslated(0, 0, -.045);
529  }
530  break;
531  case SVS_BUS_FLEXIBLE:
532  case SVS_RAIL:
533  case SVS_RAIL_CAR:
534  case SVS_RAIL_CARGO:
535  drawAction_drawCarriageClass(s, shape, false);
536  drawCarriages = true;
537  break;
538  case SVS_E_VEHICLE:
539  drawPoly(vehiclePoly_EVehicleBody, 4);
540  glColor3d(0, 0, 0);
541  drawPoly(vehiclePoly_EVehicleFrontGlass, 4.5);
542  glTranslated(0, 0, .048);
543  GLHelper::setColor(current);
544  glBegin(GL_QUADS);
545  glVertex2d(.3, .5);
546  glVertex2d(.35, .5);
547  glVertex2d(.35, -.5);
548  glVertex2d(.3, -.5);
549 
550  glVertex2d(.3, -.05);
551  glVertex2d(.7, -.05);
552  glVertex2d(.7, .05);
553  glVertex2d(.3, .05);
554 
555  glVertex2d(.7, .5);
556  glVertex2d(.65, .5);
557  glVertex2d(.65, -.5);
558  glVertex2d(.7, -.5);
559  glEnd();
560  glTranslated(0, 0, -.048);
561  //drawPoly(vehiclePoly_EVehicleBackGlass, 4.5);
562  break;
563  case SVS_ANT:
564  glPushMatrix();
565  // ant is stretched via vehicle length
566  GLHelper::setColor(darker);
567  // draw left side
568  GLHelper::drawBoxLine(Position(-0.2, -.10), 350, 0.5, .02);
569  GLHelper::drawBoxLine(Position(-0.3, -.50), 240, 0.4, .03);
570  GLHelper::drawBoxLine(Position(0.3, -.10), 340, 0.8, .03);
571  GLHelper::drawBoxLine(Position(0.05, -.80), 290, 0.6, .04);
572  GLHelper::drawBoxLine(Position(0.4, -.10), 20, 0.8, .03);
573  GLHelper::drawBoxLine(Position(0.65, -.80), 75, 0.6, .04);
574  GLHelper::drawBoxLine(Position(0.5, -.10), 55, 0.8, .04);
575  GLHelper::drawBoxLine(Position(1.1, -.55), 90, 0.6, .04);
576  // draw right side
577  GLHelper::drawBoxLine(Position(-0.2, .10), 190, 0.5, .02);
578  GLHelper::drawBoxLine(Position(-0.3, .50), 300, 0.4, .03);
579  GLHelper::drawBoxLine(Position(0.3, .10), 200, 0.8, .03);
580  GLHelper::drawBoxLine(Position(0.05, .80), 250, 0.6, .04);
581  GLHelper::drawBoxLine(Position(0.4, .10), 160, 0.8, .03);
582  GLHelper::drawBoxLine(Position(0.65, .80), 105, 0.6, .04);
583  GLHelper::drawBoxLine(Position(0.5, .10), 125, 0.8, .04);
584  GLHelper::drawBoxLine(Position(1.1, .55), 90, 0.6, .04);
585  // draw body
586  GLHelper::setColor(current);
587  glTranslated(0, 0, 0.1);
589  glTranslated(.4, 0, 0);
591  glTranslated(.4, 0, 0);
593  glPopMatrix();
594  break;
595  case SVS_SHIP: {
596  RGBColor darker = current.changedBrightness(-30);
597  RGBColor darker2 = current.changedBrightness(-70);
598  drawPoly(vehiclePoly_Ship, 4);
599  GLHelper::setColor(darker);
600  drawPoly(vehiclePoly_ShipDeck, 5);
601  GLHelper::setColor(darker2);
602  drawPoly(vehiclePoly_ShipSuperStructure, 6);
603  break;
604  }
605  case SVS_EMERGENCY: // similar to delivery
606  drawPoly(vehiclePoly_PassengerVanBody, 4);
607  GLHelper::setColor(darker);
608  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
609  glColor3d(0, 0, 0);
610  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
611  drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5);
612  drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5);
613  // first aid sign
614  glTranslated(0.7, 0, 0);
615  glColor3d(.18, .55, .34);
616  drawPoly(vehiclePoly_EmergencySign, 4.5);
617  glColor3d(1, 1, 1);
618  drawPoly(vehiclePoly_Emergency, 5);
619  drawPoly(vehiclePoly_Emergency2, 5);
620  break;
621  case SVS_FIREBRIGADE: // similar to delivery in red orange
622  drawPoly(vehiclePoly_PassengerVanBody, 4);
623  GLHelper::setColor(lighter);
624  drawPoly(vehiclePoly_PassengerVanBodyFront, 4.5);
625  glColor3d(0, 0, 0);
626  drawPoly(vehiclePoly_PassengerVanFrontGlass, 4.5);
627  drawPoly(vehiclePoly_DeliveryMediumRightGlass, 4.5);
628  drawPoly(vehiclePoly_DeliveryMediumLeftGlass, 4.5);
629  // draw ladder
630  glTranslated(0.7, 0, 0);
631  glColor3d(1, .5, 0);
632  drawPoly(vehiclePoly_EmergencySign, 4.5);
633  glColor3d(.5, .5, .5);
634  drawPoly(vehiclePoly_EmergencyLadder, 5);
635  drawPoly(vehiclePoly_EmergencyLadder2, 5);
636  drawPoly(vehiclePoly_EmergencyLadder3, 5);
637  drawPoly(vehiclePoly_EmergencyLadder4, 5);
638  drawPoly(vehiclePoly_EmergencyLadder5, 5);
639  drawPoly(vehiclePoly_EmergencyLadder6, 5);
640  drawPoly(vehiclePoly_EmergencyLadder7, 5);
641  break;
642  case SVS_POLICE: // similar to passenger grey with blue
644  GLHelper::setColor(lighter);
645  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
646  glColor3d(0, 0, 0);
647  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
648  // first aid sign
649  glTranslated(0.7, 0, 0);
650  glColor3d(.5, .5, .5);
651  drawPoly(vehiclePoly_EmergencySign, 4.5);
652  glColor3d(0, 0, 1);
653  drawPoly(vehiclePoly_Emergency, 5);
654  drawPoly(vehiclePoly_Emergency2, 5);
655  break;
656  case SVS_RICKSHAW: // Rickshaw
658  // wheels
659  GLHelper::setColor(darker);
660  glPushMatrix();
661  glTranslated(.5, .5, -0.1);
663  glPopMatrix();
664  //other wheel
665  glPushMatrix();
666  glTranslated(.5, -.5, -0.1);
668  glPopMatrix();
669  break;
670  default: // same as passenger
672  glColor3d(1, 1, 1);
673  drawPoly(vehiclePoly_PassengerCarBodyFront, 4.5);
674  glColor3d(0, 0, 0);
675  drawPoly(vehiclePoly_PassengerFrontGlass, 4.5);
676  break;
677  }
678 
679  // draw decorations
680  switch (shape) {
681  case SVS_PEDESTRIAN:
682  break;
683  case SVS_BICYCLE:
684  //glScaled(length, 1, 1.);
685  glBegin(GL_TRIANGLE_FAN);
686  glVertex2d(1 / 2., 0);
687  glVertex2d(0, 0);
688  glVertex2d(0, -.03);
689  glVertex2d(0 + .05, -.05);
690  glVertex2d(1 - .05, -.05);
691  glVertex2d(1, -.03);
692  glVertex2d(1, .03);
693  glVertex2d(1 - .05, .05);
694  glVertex2d(0 + .05, .05);
695  glVertex2d(0, .03);
696  glVertex2d(0, 0);
697  glEnd();
698  break;
699  case SVS_MOPED:
700  case SVS_MOTORCYCLE:
701  //glScaled(length, 1, 1.);
702  glBegin(GL_TRIANGLE_FAN);
703  glVertex2d(1 / 2., 0);
704  glVertex2d(0, 0);
705  glVertex2d(0, -.03);
706  glVertex2d(0 + .05, -.2);
707  glVertex2d(1 - .05, -.2);
708  glVertex2d(1, -.03);
709  glVertex2d(1, .03);
710  glVertex2d(1 - .05, .2);
711  glVertex2d(0 + .05, .2);
712  glVertex2d(0, .03);
713  glVertex2d(0, 0);
714  glEnd();
715  break;
716  case SVS_PASSENGER:
717  case SVS_PASSENGER_SEDAN:
718  drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
719  drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
720  drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
721  break;
723  drawPoly(vehiclePoly_PassengerHatchbackRightGlass, 4.5);
724  drawPoly(vehiclePoly_PassengerHatchbackLeftGlass, 4.5);
725  drawPoly(vehiclePoly_PassengerHatchbackBackGlass, 4.5);
726  break;
727  case SVS_PASSENGER_WAGON:
728  drawPoly(vehiclePoly_PassengerWagonRightGlass, 4.5);
729  drawPoly(vehiclePoly_PassengerWagonLeftGlass, 4.5);
730  drawPoly(vehiclePoly_PassengerWagonBackGlass, 4.5);
731  break;
732  case SVS_PASSENGER_VAN:
733  case SVS_DELIVERY:
734  break;
735  case SVS_TRUCK:
736  GLHelper::setColor(current);
737  GLHelper::drawBoxLine(Position(2.3, 0), 90., length - 2.3, .5);
738  break;
740  GLHelper::setColor(current);
741  GLHelper::drawBoxLine(Position(2.8, 0), 90., length - 2.8, .5);
742  break;
743  case SVS_TRUCK_1TRAILER: {
744  GLHelper::setColor(current);
745  double l = length - 2.3;
746  l = l / 2.;
747  GLHelper::drawBoxLine(Position(2.3, 0), 90., l, .5);
748  GLHelper::drawBoxLine(Position(2.3 + l + .5, 0), 90., l - .5, .5);
749  break;
750  }
751  case SVS_BUS_TROLLEY:
752  glPushMatrix();
753  glTranslated(0, 0, .1);
754  GLHelper::setColor(darker);
755  GLHelper::drawBoxLine(Position(3.8, 0), 90., 1, .3);
756  glTranslated(0, 0, .1);
757  glColor3d(0, 0, 0);
758  GLHelper::drawBoxLine(Position(4.3, .2), 90., 1, .06);
759  GLHelper::drawBoxLine(Position(4.3, -.2), 90., 1, .06);
760  GLHelper::drawBoxLine(Position(5.3, .2), 90., 3, .03);
761  GLHelper::drawBoxLine(Position(5.3, -.2), 90., 3, .03);
762  glPopMatrix();
763  break;
764  case SVS_BUS:
765  case SVS_BUS_COACH:
766  case SVS_BUS_FLEXIBLE:
767  case SVS_RAIL:
768  case SVS_RAIL_CAR:
769  case SVS_RAIL_CARGO:
770  case SVS_E_VEHICLE:
771  case SVS_ANT:
772  case SVS_SHIP:
773  case SVS_EMERGENCY:
774  case SVS_FIREBRIGADE:
775  case SVS_POLICE:
776  case SVS_RICKSHAW:
777  break;
778  default: // same as passenger/sedan
779  drawPoly(vehiclePoly_PassengerSedanRightGlass, 4.5);
780  drawPoly(vehiclePoly_PassengerSedanLeftGlass, 4.5);
781  drawPoly(vehiclePoly_PassengerSedanBackGlass, 4.5);
782  break;
783  }
784  /*
785  glBegin(GL_TRIANGLE_FAN);
786  glVertex2d(.5,.5); // center - strip begin
787  glVertex2d(0, .5); // center, front
788  glVertex2d(0, .8); // ... clockwise ... (vehicle right side)
789  glVertex2d(0.08, .94);
790  glVertex2d(0.25, 1.);
791  glVertex2d(0.95, 1.);
792  glVertex2d(1., .9);
793  glVertex2d(1., .1); // (vehicle left side)
794  glVertex2d(0.95, 0.);
795  glVertex2d(0.25, 0.);
796  glVertex2d(0.08, .06);
797  glVertex2d(0, .2); //
798  glVertex2d(0, .5); // center, front (close)
799  glEnd();
800 
801  glPolygonOffset(0, -4.5);
802  glColor3d(1, 1, 1); // front
803  glBegin(GL_TRIANGLE_FAN);
804  glVertex2d(0.1,0.5);
805  glVertex2d(0.025,0.5);
806  glVertex2d(0.025,0.75);
807  glVertex2d(0.27,0.9);
808  glVertex2d(0.27,0.1);
809  glVertex2d(0.025,0.25);
810  glVertex2d(0.025,0.5);
811  glEnd();
812 
813  glColor3d(0, 0, 0); // front glass
814  glBegin(GL_TRIANGLE_FAN);
815  glVertex2d(0.35,0.5);
816  glVertex2d(0.3,0.5);
817  glVertex2d(0.3,0.9);
818  glVertex2d(0.43,0.8);
819  glVertex2d(0.43,0.2);
820  glVertex2d(0.3,0.1);
821  glVertex2d(0.3,0.5);
822  glEnd();
823 
824  glBegin(GL_TRIANGLE_FAN); // back glass
825  glVertex2d(0.92,0.5);
826  glVertex2d(0.90,0.5);
827  glVertex2d(0.90,0.8);
828  glVertex2d(0.95,0.9);
829  glVertex2d(0.95,0.1);
830  glVertex2d(0.90,0.2);
831  glVertex2d(0.90,0.5);
832  glEnd();
833 
834  glBegin(GL_TRIANGLE_FAN); // right glass
835  glVertex2d(0.36,0.07);
836  glVertex2d(0.34,0.03);
837  glVertex2d(0.94,0.03);
838  glVertex2d(0.87,0.13);
839  glVertex2d(0.45,0.13);
840  glVertex2d(0.34,0.03);
841  glEnd();
842 
843  glBegin(GL_TRIANGLE_FAN); // left glass
844  glVertex2d(0.36,1.-0.07);
845  glVertex2d(0.34,1.-0.03);
846  glVertex2d(0.94,1.-0.03);
847  glVertex2d(0.87,1.-0.13);
848  glVertex2d(0.45,1.-0.13);
849  glVertex2d(0.34,1.-0.03);
850  glEnd();
851  */
852 
853  glPopMatrix();
854  return drawCarriages;
855 }
856 
857 
858 bool
860  const std::string& file = getVType().getImgFile();
861  if (file != "") {
862  int textureID = GUITexturesHelper::getTextureID(file);
863  if (textureID > 0) {
864  const double exaggeration = s.vehicleSize.getExaggeration(s, this);
865  if (length < 0) {
866  length = getVType().getLength() * exaggeration;
867  }
868  const double halfWidth = getVType().getWidth() / 2.0 * exaggeration;
869  GUITexturesHelper::drawTexturedBox(textureID, -halfWidth, 0, halfWidth, length);
870  return true;
871  }
872  }
873  return false;
874 }
875 
876 
877 void
878 GUIBaseVehicle::drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const {
879  glPushName(getGlID());
880  glPushMatrix();
881  Position p1 = pos;
882  const double degAngle = RAD2DEG(angle + M_PI / 2.);
883  const double length = getVType().getLength();
884  // one seat in the center of the vehicle by default
885  if (myVehicle.getLane() != nullptr) {
886  mySeatPositions[0] = myVehicle.getPosition(-length / 2);
887  } else {
888  mySeatPositions[0] = p1;
889  }
890  glTranslated(p1.x(), p1.y(), getType());
891  glRotated(degAngle, 0, 0, 1);
892  // set lane color
893  setColor(s);
894  // scale
895  const double upscale = s.vehicleSize.getExaggeration(s, this);
896  double upscaleLength = upscale;
897  if (upscale > 1 && length > 5) {
898  // reduce the length/width ratio because this is not usefull at high zoom
899  upscaleLength = MAX2(1.0, upscaleLength * (5 + sqrt(length - 5)) / length);
900  }
901  glScaled(upscale, upscaleLength, 1);
902  /*
903  MSLCM_DK2004 &m2 = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
904  if((m2.getState()&LCA_URGENT)!=0) {
905  glColor3d(1, .4, .4);
906  } else if((m2.getState()&LCA_SPEEDGAIN)!=0) {
907  glColor3d(.4, .4, 1);
908  } else {
909  glColor3d(.4, 1, .4);
910  }
911  */
912  // draw the vehicle
913  bool drawCarriages = false;
914  switch (s.vehicleQuality) {
915  case 0:
917  break;
918  case 1:
920  break;
921  case 2:
922  drawCarriages = drawAction_drawVehicleAsPoly(s);
923  // draw flashing blue light for emergency vehicles
924  if (getVType().getGuiShape() == SVS_EMERGENCY) {
925  glTranslated(0, 0, .1);
927  }
928  break;
929  case 3:
930  default:
931  // draw as image but take special care for drawing trains
932  // fallback to simple shapes
933  glPushMatrix(); // drawAction_drawRailCarriages assumes matrix stack depth of 2
934  if (!drawAction_drawCarriageClass(s, getVType().getGuiShape(), true)) {
936  drawCarriages = drawAction_drawVehicleAsPoly(s);
937  };
938  }
939  glPopMatrix();
940  break;
941  }
942  if (s.drawMinGap) {
943  const double minGap = -getVType().getMinGap();
944  glColor3d(0., 1., 0.);
945  glBegin(GL_LINES);
946  glVertex2d(0., 0);
947  glVertex2d(0., minGap);
948  glVertex2d(-.5, minGap);
949  glVertex2d(.5, minGap);
950  glEnd();
951  }
953  if (dev != nullptr && s.showBTRange) {
954  glColor3d(1., 0., 0.);
955  GLHelper::drawOutlineCircle(dev->getRange(), dev->getRange() - .2, 32);
956  }
957  // draw the blinker and brakelights if wished
958  if (s.showBlinker) {
959  glTranslated(0, 0, .1);
960  switch (getVType().getGuiShape()) {
961  case SVS_PEDESTRIAN:
962  case SVS_BICYCLE:
963  case SVS_ANT:
964  case SVS_SHIP:
965  case SVS_RAIL:
966  case SVS_RAIL_CARGO:
967  case SVS_RAIL_CAR:
968  break;
969  case SVS_MOTORCYCLE:
970  case SVS_MOPED:
972  drawAction_drawVehicleBrakeLight(length, true);
973  break;
974  default:
975  // only SVS_RAIL_CAR has blinkers and brake lights but they are drawn along with the carriages
976  if (!drawCarriages) {
979  }
980  break;
981  }
982  }
983  // draw the wish to change the lane
984  if (s.drawLaneChangePreference) {
985  /*
986  if(gSelected.isSelected(GLO_VEHICLE, veh->getGlID())) {
987  MSLCM_DK2004 &m = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
988  glColor3d(.5, .5, 1);
989  glBegin(GL_LINES);
990  glVertex2f(0, 0);
991  glVertex2f(m.getChangeProbability(), .5);
992  glEnd();
993 
994  glColor3d(1, 0, 0);
995  glBegin(GL_LINES);
996  glVertex2f(0.1, 0);
997  glVertex2f(0.1, m.myMaxJam1);
998  glEnd();
999 
1000  glColor3d(0, 1, 0);
1001  glBegin(GL_LINES);
1002  glVertex2f(-0.1, 0);
1003  glVertex2f(-0.1, m.myTDist);
1004  glEnd();
1005  }
1006  */
1007  }
1008  // draw best lanes
1009  /*
1010  if (true) {
1011  const MSLane &l = veh->getLane();
1012  double r1 = veh->allowedContinuationsLength(&l, 0);
1013  double r2 = l.getLeftLane()!=0 ? veh->allowedContinuationsLength(l.getLeftLane(), 0) : 0;
1014  double r3 = l.getRightLane()!=0 ? veh->allowedContinuationsLength(l.getRightLane(), 0) : 0;
1015  double mmax = MAX3(r1, r2, r3);
1016  glBegin(GL_LINES);
1017  glVertex2f(0, 0);
1018  glVertex2f(0, r1/mmax/2.);
1019  glEnd();
1020  glBegin(GL_LINES);
1021  glVertex2f(.4, 0);
1022  glVertex2f(.4, r2/mmax/2.);
1023  glEnd();
1024  glBegin(GL_LINES);
1025  glVertex2f(-.4, 0);
1026  glVertex2f(-.4, r3/mmax/2.);
1027  glEnd();
1028  }
1029  */
1030  glTranslated(0, MIN2(length / 2, double(5)), -getType()); // drawing name at GLO_MAX fails unless translating z
1031  glScaled(1 / upscale, 1 / upscaleLength, 1);
1032  glRotated(-degAngle, 0, 0, 1);
1033  drawName(Position(0, 0), s.scale,
1034  getVType().getGuiShape() == SVS_PEDESTRIAN ? s.personName : s.vehicleName, s.angle);
1035  if (s.vehicleName.show && myVehicle.getParameter().line != "") {
1036  glTranslated(0, 0.6 * s.vehicleName.scaledSize(s.scale), 0);
1038  }
1039  if (s.vehicleValue.show) {
1040  glTranslated(0, 0.6 * s.vehicleName.scaledSize(s.scale), 0);
1041  const double value = getColorValue(s.vehicleColorer.getActive());
1043  }
1044  glPopMatrix();
1045  glPopName();
1047 }
1048 
1049 
1050 void
1052  drawOnPos(s, getPosition(), getAngle());
1053 }
1054 
1055 
1056 void
1058  if (!myVehicle.isOnRoad()) {
1059  drawGL(s);
1060  }
1061  glPushName(getGlID());
1062  glPushMatrix();
1063  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
1065  drawBestLanes();
1066  }
1068  drawRoute(s, 0, 0.25);
1069  }
1071  if (myVehicle.getNumberReroutes() > 0) {
1072  const int noReroutePlus1 = myVehicle.getNumberReroutes() + 1;
1073  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
1074  double darken = double(0.4) / double(noReroutePlus1) * double(i);
1075  drawRoute(s, i, darken);
1076  }
1077  } else {
1078  drawRoute(s, 0, 0.25);
1079  }
1080  }
1083  }
1084  glPopMatrix();
1085  glPopName();
1086 }
1087 
1088 
1089 void
1090 GUIBaseVehicle::drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate) {
1091  glTranslated(pos.x(), pos.y(), -.1);
1093  std::string times = toString(STEPS2TIME(arrivalTime)) + "/" + toString(STEPS2TIME(leaveTime));
1094  GLHelper::drawText(times.c_str(), Position(), .1, 1.6 * exagerate, RGBColor::GREEN, 0);
1095  glTranslated(-pos.x(), -pos.y(), .1);
1096 }
1097 
1098 
1099 void
1101  const GUIColorer& c = s.vehicleColorer;
1102  if (!setFunctionalColor(c.getActive(), &myVehicle)) {
1104  }
1105 }
1106 
1107 
1108 bool
1109 GUIBaseVehicle::setFunctionalColor(int activeScheme, const MSBaseVehicle* veh) {
1110  switch (activeScheme) {
1111  case 0: {
1112  //test for emergency vehicle
1113  if (veh->getVehicleType().getGuiShape() == SVS_EMERGENCY) {
1115  return true;
1116  }
1117  //test for firebrigade
1118  if (veh->getVehicleType().getGuiShape() == SVS_FIREBRIGADE) {
1120  return true;
1121  }
1122  //test for police car
1123  if (veh->getVehicleType().getGuiShape() == SVS_POLICE) {
1125  return true;
1126  }
1127  if (veh->getParameter().wasSet(VEHPARS_COLOR_SET)) {
1129  return true;
1130  }
1133  return true;
1134  }
1135  if (&(veh->getRoute().getColor()) != &RGBColor::DEFAULT_COLOR) {
1137  return true;
1138  }
1139  return false;
1140  }
1141  case 2: {
1142  if (veh->getParameter().wasSet(VEHPARS_COLOR_SET)) {
1144  return true;
1145  }
1146  return false;
1147  }
1148  case 3: {
1151  return true;
1152  }
1153  return false;
1154  }
1155  case 4: {
1156  if (&(veh->getRoute().getColor()) != &RGBColor::DEFAULT_COLOR) {
1158  return true;
1159  }
1160  return false;
1161  }
1162  case 5: {
1163  Position p = veh->getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
1164  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1165  Position center = b.getCenter();
1166  double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
1167  double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
1168  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1169  return true;
1170  }
1171  case 6: {
1172  Position p = veh->getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
1173  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1174  Position center = b.getCenter();
1175  double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
1176  double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
1177  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1178  return true;
1179  }
1180  case 7: {
1181  Position pb = veh->getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
1182  Position pe = veh->getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
1183  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
1184  double hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / M_PI;
1185  Position minp(b.xmin(), b.ymin());
1186  Position maxp(b.xmax(), b.ymax());
1187  double sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
1188  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1189  return true;
1190  }
1191  case 29: { // color randomly (by pointer hash)
1192  std::hash<const MSBaseVehicle*> ptr_hash;
1193  const double hue = (double)(ptr_hash(veh) % 360); // [0-360]
1194  const double sat = ((ptr_hash(veh) / 360) % 67) / 100.0 + 0.33; // [0.33-1]
1195  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
1196  return true;
1197  }
1198  }
1199  return false;
1200 }
1201 
1202 
1203 // ------------ Additional visualisations
1204 bool
1206  return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
1207 }
1208 
1209 
1210 void
1212  if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
1213  myAdditionalVisualizations[parent] = 0;
1214  }
1215  myAdditionalVisualizations[parent] |= which;
1216  parent->addAdditionalGLVisualisation(this);
1217 }
1218 
1219 
1220 void
1222  myAdditionalVisualizations[parent] &= ~which;
1223  parent->removeAdditionalGLVisualisation(this);
1224 }
1225 
1226 
1227 void
1228 GUIBaseVehicle::drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken) const {
1229  setColor(s);
1230  GLdouble colors[4];
1231  glGetDoublev(GL_CURRENT_COLOR, colors);
1232  colors[0] -= darken;
1233  if (colors[0] < 0) {
1234  colors[0] = 0;
1235  }
1236  colors[1] -= darken;
1237  if (colors[1] < 0) {
1238  colors[1] = 0;
1239  }
1240  colors[2] -= darken;
1241  if (colors[2] < 0) {
1242  colors[2] = 0;
1243  }
1244  colors[3] -= darken;
1245  if (colors[3] < 0) {
1246  colors[3] = 0;
1247  }
1248  glColor3dv(colors);
1249  if (routeNo == 0) {
1251  return;
1252  }
1253  --routeNo; // only prior routes are stored
1254  const MSRoute* route = myRoutes->getRoute(routeNo);
1255  if (route != nullptr) {
1256  drawRouteHelper(s, *route);
1257  }
1258 }
1259 
1260 
1261 const Position&
1262 GUIBaseVehicle::getSeatPosition(int personIndex) const {
1264  return mySeatPositions[MIN2(personIndex, (int)mySeatPositions.size() - 1)];
1265 }
1266 
1267 
1268 void
1270  if (myVehicle.myPersonDevice != nullptr) {
1271  const std::vector<MSTransportable*>& ps = myVehicle.myPersonDevice->getTransportables();
1272  int personIndex = 0;
1273  for (std::vector<MSTransportable*>::const_iterator i = ps.begin(); i != ps.end(); ++i) {
1274  GUIPerson* person = dynamic_cast<GUIPerson*>(*i);
1275  assert(person != 0);
1276  person->setPositionInVehicle(getSeatPosition(personIndex++));
1277  person->drawGL(s);
1278  }
1279  }
1280  if (myVehicle.myContainerDevice != nullptr) {
1281  const std::vector<MSTransportable*>& cs = myVehicle.myContainerDevice->getTransportables();
1282  int containerIndex = 0;
1283  for (std::vector<MSTransportable*>::const_iterator i = cs.begin(); i != cs.end(); ++i) {
1284  GUIContainer* container = dynamic_cast<GUIContainer*>(*i);
1285  assert(container != 0);
1286  container->setPositionInVehicle(getSeatPosition(containerIndex++));
1287  container->drawGL(s);
1288  }
1289  }
1290 #ifdef DRAW_BOUNDING_BOX
1291  glPushName(getGlID());
1292  glPushMatrix();
1293  glTranslated(0, 0, getType());
1294  PositionVector boundingBox = getBoundingBox();
1295  boundingBox.push_back(boundingBox.front());
1296  PositionVector smallBB = getBoundingPoly();
1297  glColor3d(0, .8, 0);
1298  GLHelper::drawLine(boundingBox);
1299  glColor3d(0.5, .8, 0);
1300  GLHelper::drawLine(smallBB);
1301  //GLHelper::drawBoxLines(getBoundingBox(), 0.5);
1302  glPopMatrix();
1303  glPopName();
1304 #endif
1305 }
1306 
1307 
1308 
1309 /****************************************************************************/
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
const std::vector< MSTransportable * > & getTransportables() const
Returns the list of transportables using this vehicle.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
long onCmdStopTrack(FXObject *, FXSelector, void *)
Called if the current shall not be tracked any longer.
static const RGBColor BLUE
Definition: RGBColor.h:186
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:131
long onCmdHideCurrentRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be hidden.
double vehiclePoly_PassengerVanBody[]
SUMOVehicleShape getGuiShape() const
Get this vehicle type&#39;s shape.
render as a rail
double vehiclePoly_Emergency2[]
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
RGBColor color
The vehicle&#39;s color, TraCI may change this.
long long int SUMOTime
Definition: SUMOTime.h:36
double scale
information about a lane&#39;s width (temporary, used for a single view)
virtual void drawAction_drawVehicleBlueLight() const
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:154
double vehiclePoly_PassengerVanRightGlass[]
double vehiclePoly_EmergencyLadder4[]
MoveReminderCont myMoveReminders
Currently relevant move reminders.
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:121
bool showBlinker
Information whether vehicle blinkers shall be drawn.
double vehiclePoly_Rickshaw[]
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
double vehiclePoly_PassengerWagonLeftGlass[]
a vehicles
GUIVisualizationTextSettings personName
double vehiclePoly_EVehicleFrontGlass[]
double vehiclePoly_PassengerSedanRightGlass[]
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
MFXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
Definition: RGBColor.cpp:299
static const RGBColor WHITE
Definition: RGBColor.h:191
render as a motorcycle
double vehiclePoly_PassengerVanFrontGlass[]
void drawAction_drawVehicleAsBoxPlus() const
long onCmdStartTrack(FXObject *, FXSelector, void *)
Called if the vehicle shall be tracked.
double vehiclePoly_TransportLeftGlass[]
bool showBTRange
Information whether the communication range shall be drawn.
Stores the information about how to visualize structures.
render as a transport vehicle
render as a flexible city bus
double y() const
Returns the y-position.
Definition: Position.h:62
Hide all vehicle&#39;s routes.
Definition: GUIAppEnum.h:272
const SUMOVehicleParameter & getParameter() const
Returns the vehicle&#39;s parameter (including departure definition)
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
bool drawLaneChangePreference
Information whether the lane change preference shall be drawn.
show vehicle&#39;s best lanes
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048)
Definition: GLHelper.cpp:635
virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings &s) const
MSDevice_Vehroutes * myRoutes
GUIVisualizationTextSettings vehicleName
double x() const
Returns the x-position.
Definition: Position.h:57
double vehiclePoly_EVehicleBody[]
std::string getImgFile() const
Get this vehicle type&#39;s raster model file name.
virtual MSLane * getLane() const =0
Returns the lane the vehicle is on.
virtual void drawAction_drawLinkItems(const GUIVisualizationSettings &) const
double vehiclePoly_PassengerFrontGlass[]
static double getRange()
Returns the configured range.
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:357
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:165
T MAX2(T a, T b)
Definition: StdDefs.h:76
render as a delivery vehicle
double vehiclePoly_Emergency[]
const MSRoute & getRoute() const
Returns the current route.
double vehiclePoly_PassengerHatchbackLeftGlass[]
double vehiclePoly_PassengerVanBackGlass[]
double vehiclePoly_EmergencyLadder3[]
GUISUMOAbstractView * myParent
The parent window.
render as a sedan passenger vehicle ("Stufenheck")
bool addAdditionalGLVisualisation(const GUIGlObject *const which)
Adds an object to call its additional visualisation method.
#define RAD2DEG(x)
Definition: GeomHelper.h:39
static void drawLinkItem(const Position &pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate)
double vehiclePoly_PassengerSedanBackGlass[]
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:52
virtual void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r) const =0
Draws the route.
double vehiclePoly_PassengerVanLeftGlass[]
virtual void stopTrack()
stop track
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
virtual void selectBlockingFoes() const =0
adds the blocking foes to the current selection
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.
void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the type parameter window.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
bool removeAdditionalGLVisualisation(const GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
Hide vehicle&#39;s best lanes.
Definition: GUIAppEnum.h:268
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Start to track a vehicle.
Definition: GUIAppEnum.h:274
static MSDevice_Vehroutes * buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into, int maxRoutes=std::numeric_limits< int >::max())
Build devices for the given vehicle, if needed.
long onCmdHideAllRoutes(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be hidden.
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:83
PositionVector mySeatPositions
positions of seats in the vehicle (updated at every drawing step)
GUIColorer vehicleColorer
The vehicle colorer.
double vehiclePoly_ShipDeck[]
double vehiclePoly_PassengerCarBody[]
virtual GUIGlID getTrackedID() const
get tracked id
virtual void startTrack(int)
star track
static const RGBColor GREEN
Definition: RGBColor.h:185
GUIVisualizationTextSettings vehicleValue
static const RGBColor GREY
Definition: RGBColor.h:193
Stop to track a vehicle.
Definition: GUIAppEnum.h:276
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
long onCmdShowBestLanes(FXObject *, FXSelector, void *)
Called if the vehicle&#39;s best lanes shall be shown.
bool drawAction_drawVehicleAsPoly(const GUIVisualizationSettings &s) const
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
long onCmdShowAllRoutes(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be shown.
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
render as a hatchback passenger vehicle ("Fliessheck")
Show vehicle&#39;s best lanes.
Definition: GUIAppEnum.h:266
render as a bus
double vehiclePoly_PassengerWagonRightGlass[]
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
double vehiclePoly_ShipSuperStructure[]
void drawOnPos(const GUIVisualizationSettings &s, const Position &pos, const double angle) const
Draws the object on the specified position with the specified angle.
A list of positions.
double scaledSize(double scale, double constFactor=0.1) const
bool drawMinGap
Information whether the minimum gap shall be drawn.
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:198
not defined
render as a bicycle
long onCmdHideBestLanes(FXObject *, FXSelector, void *)
Called if the vehicle&#39;s best lanes shall be hidden.
double vehiclePoly_EmergencyLadder6[]
double vehiclePoly_EmergencyLadder[]
double vehiclePoly_Ship[]
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
#define STEPS2TIME(x)
Definition: SUMOTime.h:58
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
virtual double getColorValue(int activeScheme) const =0
gets the color value according to the current scheme index
void drawAction_drawVehicleAsTrianglePlus() const
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void setPositionInVehicle(const Position &pos)
Definition: GUIPerson.h:119
render as a (city) rail without locomotive
T MIN2(T a, T b)
Definition: StdDefs.h:70
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:119
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:389
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
A MSVehicle extended by some values for usage within the gui.
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.
render as a van
double vehiclePoly_PassengerHatchbackRightGlass[]
double angle
The current view rotation angle.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
const T getColor(const double value) const
static void drawLine(const Position &beg, double rot, double visLength)
Draws a thin line.
Definition: GLHelper.cpp:270
render as a passenger vehicle
Show vehicle&#39;s current route.
Definition: GUIAppEnum.h:262
double vehiclePoly_TransportBody[]
render as a police car
const int VEHPARS_COLOR_SET
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPerson.cpp:276
std::string line
The vehicle&#39;s line (mainly for public transport)
const RGBColor & getColor() const
Returns this type&#39;s color.
long onCmdHideLFLinkItems(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be hidden.
void setPositionInVehicle(const Position &pos)
Definition: GUIContainer.h:118
double vehiclePoly_PassengerSedanLeftGlass[]
render as a cargo train
void drawRoute(const GUIVisualizationSettings &s, int routeNo, double darken) const
Chooses the route to draw and draws it, darkening it as given.
render as a fire brigade
void unlock()
release mutex lock
Definition: MFXMutex.cpp:87
double vehiclePoly_PassengerHatchbackBackGlass[]
GUIBaseVehicle(MSBaseVehicle &vehicle)
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
render as a giant ant
render as a pedestrian
render as a moped
double vehiclePoly_PassengerCarBodyFront[]
GUIBaseVehiclePopupMenu()
default constructor needed by FOX
static const RGBColor RED
named colors
Definition: RGBColor.h:184
~GUIBaseVehicle()
destructor
Show all vehicle&#39;s routes.
Definition: GUIAppEnum.h:270
void removeActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
const MSVehicleType & getVehicleType() const
Returns the vehicle&#39;s type definition.
render as a arbitrary ship
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:82
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const Position & getSeatPosition(int personIndex) const
returns the seat position for the person with the given index
#define M_PI
Definition: odrSpiral.cpp:40
double vehiclePoly_EmergencyLadder5[]
double vehiclePoly_EVehicleBackGlass[]
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
long onCmdShowCurrentRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be shown.
double vehiclePoly_EmergencySign[]
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
virtual bool drawAction_drawCarriageClass(const GUIVisualizationSettings &s, SUMOVehicleShape guiShape, bool asImage) const =0
draws the given guiShape if it has distinc carriages/modules and eturns true if so ...
The popup menu of a globject.
show all vehicle&#39;s routes
virtual double getAngle() const =0
Returns the vehicle&#39;s direction in radians.
long onCmdShowFoes(FXObject *, FXSelector, void *)
Called when show a vehicles foes.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
double getLength() const
Get vehicle&#39;s length [m].
void lock()
lock mutex
Definition: MFXMutex.cpp:77
double vehiclePoly_TransportFrontGlass[]
double vehiclePoly_PassengerWagonBackGlass[]
bool wasSet(int what) const
Returns whether the given parameter was set.
render as an emergency vehicle
GUIGlID getGlID() const
Returns the numerical id of the object.
Position getCenter() const
Returns the center of the boundary.
Definition: Boundary.cpp:113
render as a (futuristic) e-vehicle
double vehiclePoly_DeliveryMediumRightGlass[]
render as a rickshaw
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:234
GUIVisualizationSizeSettings vehicleSize
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
virtual void drawBestLanes() const
Draws the vehicle&#39;s best lanes.
const MSRoute * getRoute(int index) const
Called on route retrieval.
static void drawPoly(double *poses, double offset)
int vehicleQuality
The quality of vehicle drawing.
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
double vehiclePoly_TransportRightGlass[]
MSBaseVehicle & myVehicle
The vehicle to which all calls should be delegated.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
FXDEFMAP(GUIBaseVehicle::GUIBaseVehiclePopupMenu) GUIBaseVehiclePopupMenuMap[]
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:137
GUIGlObject * myObject
The object that belongs to this popup-menu.
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
render as a transport vehicle with one trailer
render as a wagon passenger vehicle ("Combi")
select foes of a vehicle
Definition: GUIAppEnum.h:278
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle *veh)
sets the color according to the current scheme index and some vehicle function
double vehiclePoly_Cyclist[]
void addActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne=false) const
double vehiclePoly_EmergencyLadder7[]
render as a coach
show vehicle&#39;s current route
const int VTYPEPARS_COLOR_SET
bool drawAction_drawVehicleAsImage(const GUIVisualizationSettings &s, double length=-1) const
render as a semi-trailer transport vehicle ("Sattelschlepper")
long onCmdShowLFLinkItems(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be shown.
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
double vehiclePoly_PassengerVanBodyFront[]
double vehiclePoly_DeliveryMediumLeftGlass[]
Hide vehicle&#39;s current route.
Definition: GUIAppEnum.h:264
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
render as a trolley bus
bool hasActiveAddVisualisation(GUISUMOAbstractView *const parent, int which) const
Returns whether the named feature is enabled in the given view.
double vehiclePoly_EmergencyLadder2[]
virtual void drawAction_drawVehicleBlinker(double) const
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:579