Eclipse 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-2019 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>
43 #include <mesosim/MEVehicle.h>
44 #include <mesosim/MELoop.h>
45 #include <microsim/MSVehicle.h>
46 #include <microsim/MSLane.h>
55 #include <gui/GUIGlobals.h>
56 
57 #include "GUIBaseVehicle.h"
58 #include "GUIPerson.h"
59 #include "GUIContainer.h"
60 #include "GUINet.h"
61 #include "GUIEdge.h"
62 #include "GUILane.h"
63 
64 //#define DRAW_BOUNDING_BOX
65 
66 // ===========================================================================
67 // FOX callback mapping
68 // ===========================================================================
69 FXDEFMAP(GUIBaseVehicle::GUIBaseVehiclePopupMenu) GUIBaseVehiclePopupMenuMap[] = {
84 };
85 
86 // Object implementation
87 FXIMPLEMENT(GUIBaseVehicle::GUIBaseVehiclePopupMenu, GUIGLObjectPopupMenu, GUIBaseVehiclePopupMenuMap, ARRAYNUMBER(GUIBaseVehiclePopupMenuMap))
88 
89 // ===========================================================================
90 // method definitions
91 // ===========================================================================
92 /* -------------------------------------------------------------------------
93  * GUIBaseVehicle::GUIBaseVehiclePopupMenu - methods
94  * ----------------------------------------------------------------------- */
96  GUIMainWindow& app, GUISUMOAbstractView& parent,
97  GUIGlObject& o, std::map<GUISUMOAbstractView*, int>& additionalVisualizations)
98  : GUIGLObjectPopupMenu(app, parent, o), myVehiclesAdditionalVisualizations(additionalVisualizations) {
99 }
100 
101 
103 
104 
105 long
107  assert(myObject->getType() == GLO_VEHICLE);
108  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES)) {
110  }
111  return 1;
112 }
113 
114 long
116  assert(myObject->getType() == GLO_VEHICLE);
118  return 1;
119 }
120 
121 
122 long
124  assert(myObject->getType() == GLO_VEHICLE);
125  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE)) {
127  }
128  return 1;
129 }
130 
131 long
133  assert(myObject->getType() == GLO_VEHICLE);
135  return 1;
136 }
137 
138 
139 long
141  assert(myObject->getType() == GLO_VEHICLE);
142  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_FUTURE_ROUTE)) {
144  }
145  return 1;
146 }
147 
148 long
150  assert(myObject->getType() == GLO_VEHICLE);
152  return 1;
153 }
154 
155 
156 long
158  assert(myObject->getType() == GLO_VEHICLE);
159  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES)) {
161  }
162  return 1;
163 }
164 
165 long
167  assert(myObject->getType() == GLO_VEHICLE);
169  return 1;
170 }
171 
172 
173 long
175  assert(myObject->getType() == GLO_VEHICLE);
176  if (myParent->getTrackedID() != static_cast<GUIBaseVehicle*>(myObject)->getGlID()) {
177  myParent->startTrack(static_cast<GUIBaseVehicle*>(myObject)->getGlID());
178  }
179  return 1;
180 }
181 
182 long
184  assert(myObject->getType() == GLO_VEHICLE);
185  myParent->stopTrack();
186  return 1;
187 }
188 
189 
190 long
192  assert(myObject->getType() == GLO_VEHICLE);
193  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS)) {
195  }
196  return 1;
197 }
198 
199 long
201  assert(myObject->getType() == GLO_VEHICLE);
203  return 1;
204 }
205 
206 long
208  assert(myObject->getType() == GLO_VEHICLE);
209  static_cast<GUIBaseVehicle*>(myObject)->selectBlockingFoes();
210  myParent->update();
211  return 1;
212 }
213 
214 
215 long
217  GUIBaseVehicle* baseVeh = static_cast<GUIBaseVehicle*>(myObject);
218  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&baseVeh->myVehicle);
219  if (microVeh != nullptr) {
221  if (microVeh->getLane() != nullptr) {
223  }
224  } else {
225  MEVehicle* mesoVeh = dynamic_cast<MEVehicle*>(&baseVeh->myVehicle);
227  }
229  myParent->update();
230  return 1;
231 }
232 
233 
234 /* -------------------------------------------------------------------------
235  * GUIBaseVehicle - methods
236  * ----------------------------------------------------------------------- */
237 
239  GUIGlObject(GLO_VEHICLE, vehicle.getID()),
240  myVehicle(vehicle) {
241  // as it is possible to show all vehicle routes, we have to store them... (bug [ 2519761 ])
243  myVehicle.myMoveReminders.push_back(std::make_pair(myRoutes, 0.));
244  mySeatPositions.push_back(Position(0, 0)); // ensure length 1
245 }
246 
247 
249  myLock.lock();
250  for (std::map<GUISUMOAbstractView*, int>::iterator i = myAdditionalVisualizations.begin(); i != myAdditionalVisualizations.end(); ++i) {
251  if (i->first->getTrackedID() == getGlID()) {
252  i->first->stopTrack();
253  }
254  while (i->first->removeAdditionalGLVisualisation(this));
255  }
256  myLock.unlock();
257  delete myRoutes;
258 }
259 
260 
263  GUISUMOAbstractView& parent) {
265  buildPopupHeader(ret, app);
269  //
271  new FXMenuCommand(ret, "Hide Current Route", nullptr, ret, MID_HIDE_CURRENTROUTE);
272  } else {
273  new FXMenuCommand(ret, "Show Current Route", nullptr, ret, MID_SHOW_CURRENTROUTE);
274  }
276  new FXMenuCommand(ret, "Hide Future Route", nullptr, ret, MID_HIDE_FUTUREROUTE);
277  } else {
278  new FXMenuCommand(ret, "Show Future Route", nullptr, ret, MID_SHOW_FUTUREROUTE);
279  }
281  new FXMenuCommand(ret, "Hide All Routes", nullptr, ret, MID_HIDE_ALLROUTES);
282  } else {
283  new FXMenuCommand(ret, "Show All Routes", nullptr, ret, MID_SHOW_ALLROUTES);
284  }
286  new FXMenuCommand(ret, "Hide Best Lanes", nullptr, ret, MID_HIDE_BEST_LANES);
287  } else {
288  new FXMenuCommand(ret, "Show Best Lanes", nullptr, ret, MID_SHOW_BEST_LANES);
289  }
291  new FXMenuCommand(ret, "Hide Link Items", nullptr, ret, MID_HIDE_LFLINKITEMS);
292  } else {
293  new FXMenuCommand(ret, "Show Link Items", nullptr, ret, MID_SHOW_LFLINKITEMS);
294  }
295  new FXMenuSeparator(ret);
296  if (parent.getTrackedID() != getGlID()) {
297  new FXMenuCommand(ret, "Start Tracking", nullptr, ret, MID_START_TRACK);
298  } else {
299  new FXMenuCommand(ret, "Stop Tracking", nullptr, ret, MID_STOP_TRACK);
300  }
301  new FXMenuCommand(ret, "Select Foes", nullptr, ret, MID_SHOW_FOES);
302 
303 
304  new FXMenuCommand(ret, "Remove", nullptr, ret, MID_REMOVE_OBJECT);
305 
306  new FXMenuSeparator(ret);
307  //
308  buildShowParamsPopupEntry(ret, false);
310  buildPositionCopyEntry(ret, false);
311  return ret;
312 }
313 
314 
315 Boundary
317  Boundary b;
318  b.add(getPosition());
320  return b;
321 }
322 
323 
324 const std::string
326  return myVehicle.getParameter().getParameter("name", "");
327 }
328 
329 
330 void
331 GUIBaseVehicle::drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const {
332  glPushName(getGlID());
333  glPushMatrix();
334  Position p1 = pos;
335  const double degAngle = RAD2DEG(angle + M_PI / 2.);
336  const double length = getVType().getLength();
337  glTranslated(p1.x(), p1.y(), getType());
338  glRotated(degAngle, 0, 0, 1);
339  // set lane color
340  setColor(s);
341  // scale
342  const double upscale = s.vehicleSize.getExaggeration(s, this);
343  double upscaleLength = upscale;
344  if (upscale > 1 && length > 5) {
345  // reduce the length/width ratio because this is not usefull at high zoom
346  upscaleLength = MAX2(1.0, upscaleLength * (5 + sqrt(length - 5)) / length);
347  }
348  glScaled(upscale, upscaleLength, 1);
349  /*
350  MSLCM_DK2004 &m2 = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
351  if((m2.getState()&LCA_URGENT)!=0) {
352  glColor3d(1, .4, .4);
353  } else if((m2.getState()&LCA_SPEEDGAIN)!=0) {
354  glColor3d(.4, .4, 1);
355  } else {
356  glColor3d(.4, 1, .4);
357  }
358  */
359  // draw the vehicle
360  bool drawCarriages = false;
361  switch (s.vehicleQuality) {
362  case 0:
364  break;
365  case 1:
367  break;
368  case 2:
370  // draw flashing blue light for emergency vehicles
371  if (getVType().getGuiShape() == SVS_EMERGENCY) {
372  glTranslated(0, 0, .1);
374  }
375  break;
376  case 3:
377  default:
378  drawCarriages = drawAction_drawVehicleAsPolyWithCarriagges(s, true);
379  break;
380  }
381  if (s.drawMinGap) {
382  const double minGap = -getVType().getMinGap();
383  glColor3d(0., 1., 0.);
384  glBegin(GL_LINES);
385  glVertex2d(0., 0);
386  glVertex2d(0., minGap);
387  glVertex2d(-.5, minGap);
388  glVertex2d(.5, minGap);
389  glEnd();
390  }
392  const double brakeGap = -static_cast<MSVehicle&>(myVehicle).getCarFollowModel().brakeGap(myVehicle.getSpeed());
393  glColor3d(1., 0., 0.);
394  glBegin(GL_LINES);
395  glVertex2d(0., 0);
396  glVertex2d(0., brakeGap);
397  glVertex2d(-.5, brakeGap);
398  glVertex2d(.5, brakeGap);
399  glEnd();
400  }
402  if (dev != nullptr && s.showBTRange) {
403  glColor3d(1., 0., 0.);
404  GLHelper::drawOutlineCircle(dev->getRange(), dev->getRange() - .2, 32);
405  }
406  // draw the blinker and brakelights if wished
407  if (s.showBlinker) {
408  glTranslated(0, 0, .1);
409  switch (getVType().getGuiShape()) {
410  case SVS_PEDESTRIAN:
411  case SVS_BICYCLE:
412  case SVS_ANT:
413  case SVS_SHIP:
414  case SVS_RAIL:
415  case SVS_RAIL_CARGO:
416  case SVS_RAIL_CAR:
417  break;
418  case SVS_MOTORCYCLE:
419  case SVS_MOPED:
421  drawAction_drawVehicleBrakeLight(length, true);
422  break;
423  default:
424  // only SVS_RAIL_CAR has blinkers and brake lights but they are drawn along with the carriages
425  if (!drawCarriages) {
428  }
429  break;
430  }
431  }
432  // draw the wish to change the lane
433  if (s.drawLaneChangePreference) {
434  /*
435  if(gSelected.isSelected(GLO_VEHICLE, veh->getGlID())) {
436  MSLCM_DK2004 &m = static_cast<MSLCM_DK2004&>(veh->getLaneChangeModel());
437  glColor3d(.5, .5, 1);
438  glBegin(GL_LINES);
439  glVertex2f(0, 0);
440  glVertex2f(m.getChangeProbability(), .5);
441  glEnd();
442 
443  glColor3d(1, 0, 0);
444  glBegin(GL_LINES);
445  glVertex2f(0.1, 0);
446  glVertex2f(0.1, m.myMaxJam1);
447  glEnd();
448 
449  glColor3d(0, 1, 0);
450  glBegin(GL_LINES);
451  glVertex2f(-0.1, 0);
452  glVertex2f(-0.1, m.myTDist);
453  glEnd();
454  }
455  */
456  }
457  // draw best lanes
458  /*
459  if (true) {
460  const MSLane &l = veh->getLane();
461  double r1 = veh->allowedContinuationsLength(&l, 0);
462  double r2 = l.getLeftLane()!=0 ? veh->allowedContinuationsLength(l.getLeftLane(), 0) : 0;
463  double r3 = l.getRightLane()!=0 ? veh->allowedContinuationsLength(l.getRightLane(), 0) : 0;
464  double mmax = MAX3(r1, r2, r3);
465  glBegin(GL_LINES);
466  glVertex2f(0, 0);
467  glVertex2f(0, r1/mmax/2.);
468  glEnd();
469  glBegin(GL_LINES);
470  glVertex2f(.4, 0);
471  glVertex2f(.4, r2/mmax/2.);
472  glEnd();
473  glBegin(GL_LINES);
474  glVertex2f(-.4, 0);
475  glVertex2f(-.4, r3/mmax/2.);
476  glEnd();
477  }
478  */
479  glTranslated(0, MIN2(length / 2, double(5)), -getType()); // drawing name at GLO_MAX fails unless translating z
480  glScaled(1 / upscale, 1 / upscaleLength, 1);
481  glRotated(-degAngle, 0, 0, 1);
482  drawName(Position(0, 0), s.scale, s.vehicleName, s.angle);
483  if (s.vehicleName.show && myVehicle.getParameter().line != "") {
484  glRotated(-s.angle, 0, 0, 1);
485  glTranslated(0, 0.7 * s.vehicleName.scaledSize(s.scale), 0);
486  glRotated(s.angle, 0, 0, 1);
488  }
489  if (s.vehicleValue.show) {
490  glRotated(-s.angle, 0, 0, 1);
491  glTranslated(0, 0.7 * s.vehicleName.scaledSize(s.scale), 0);
492  glRotated(s.angle, 0, 0, 1);
493  const double value = getColorValue(s, s.vehicleColorer.getActive());
495  }
496 
497  if (!drawCarriages) {
498  mySeatPositions.clear();
499  int requiredSeats = getNumPassengers() + getNumContainers();
500  const int totalSeats = getVType().getPersonCapacity() + getVType().getContainerCapacity();
501  const Position back = (p1 + Position(-length * upscaleLength, 0)).rotateAround2D(angle, p1);
502  computeSeats(p1, back, totalSeats, upscale, requiredSeats);
503  }
504 
505  glPopMatrix();
506  glPopName();
508 }
509 
510 
511 void
513  drawOnPos(s, getPosition(), getAngle());
514 }
515 
516 
517 void
519  if (!myVehicle.isOnRoad()) {
520  drawGL(s);
521  }
522  glPushName(getGlID());
523  glPushMatrix();
524  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
526  drawBestLanes();
527  }
529  drawRoute(s, 0, 0.25, false);
530  }
532  drawRoute(s, 0, 0.25, true);
533  }
535  if (myVehicle.getNumberReroutes() > 0) {
536  const int noReroutePlus1 = myVehicle.getNumberReroutes() + 1;
537  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
538  double darken = double(0.4) / double(noReroutePlus1) * double(i);
539  drawRoute(s, i, darken);
540  }
541  } else {
542  drawRoute(s, 0, 0.25);
543  }
544  }
547  }
548  glPopMatrix();
549  glPopName();
550 }
551 
552 
553 void
554 GUIBaseVehicle::drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate) {
555  glTranslated(pos.x(), pos.y(), -.1);
557  std::string times = toString(STEPS2TIME(arrivalTime)) + "/" + toString(STEPS2TIME(leaveTime));
558  GLHelper::drawText(times.c_str(), Position(), .1, 1.6 * exagerate, RGBColor::GREEN, 0);
559  glTranslated(-pos.x(), -pos.y(), .1);
560 }
561 
562 
563 void
565  const GUIColorer& c = s.vehicleColorer;
566  if (!setFunctionalColor(c.getActive(), &myVehicle)) {
568  }
569 }
570 
571 
572 bool
573 GUIBaseVehicle::setFunctionalColor(int activeScheme, const MSBaseVehicle* veh) {
574  switch (activeScheme) {
575  case 0: {
576  //test for emergency vehicle
577  if (veh->getVehicleType().getGuiShape() == SVS_EMERGENCY) {
579  return true;
580  }
581  //test for firebrigade
582  if (veh->getVehicleType().getGuiShape() == SVS_FIREBRIGADE) {
584  return true;
585  }
586  //test for police car
587  if (veh->getVehicleType().getGuiShape() == SVS_POLICE) {
589  return true;
590  }
591  if (veh->getParameter().wasSet(VEHPARS_COLOR_SET)) {
593  return true;
594  }
597  return true;
598  }
599  if (&(veh->getRoute().getColor()) != &RGBColor::DEFAULT_COLOR) {
601  return true;
602  }
603  return false;
604  }
605  case 2: {
606  if (veh->getParameter().wasSet(VEHPARS_COLOR_SET)) {
608  return true;
609  }
610  return false;
611  }
612  case 3: {
615  return true;
616  }
617  return false;
618  }
619  case 4: {
620  if (&(veh->getRoute().getColor()) != &RGBColor::DEFAULT_COLOR) {
622  return true;
623  }
624  return false;
625  }
626  case 5: {
627  Position p = veh->getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
628  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
629  Position center = b.getCenter();
630  double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
631  double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
632  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
633  return true;
634  }
635  case 6: {
636  Position p = veh->getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
637  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
638  Position center = b.getCenter();
639  double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
640  double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
641  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
642  return true;
643  }
644  case 7: {
645  Position pb = veh->getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
646  Position pe = veh->getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
647  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
648  double hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / M_PI;
649  Position minp(b.xmin(), b.ymin());
650  Position maxp(b.xmax(), b.ymax());
651  double sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
652  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
653  return true;
654  }
655  case 30: { // color randomly (by pointer hash)
656  std::hash<const MSBaseVehicle*> ptr_hash;
657  const double hue = (double)(ptr_hash(veh) % 360); // [0-360]
658  const double sat = ((ptr_hash(veh) / 360) % 67) / 100.0 + 0.33; // [0.33-1]
659  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
660  return true;
661  }
662  }
663  return false;
664 }
665 
666 
667 // ------------ Additional visualisations
668 bool
670  return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
671 }
672 
673 
674 void
676  if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
677  myAdditionalVisualizations[parent] = 0;
678  }
679  myAdditionalVisualizations[parent] |= which;
680  parent->addAdditionalGLVisualisation(this);
681 }
682 
683 
684 void
686  myAdditionalVisualizations[parent] &= ~which;
687  parent->removeAdditionalGLVisualisation(this);
688 }
689 
690 
691 void
692 GUIBaseVehicle::drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future) const {
693  setColor(s);
694  GLdouble colors[4];
695  glGetDoublev(GL_CURRENT_COLOR, colors);
696  colors[0] -= darken;
697  if (colors[0] < 0) {
698  colors[0] = 0;
699  }
700  colors[1] -= darken;
701  if (colors[1] < 0) {
702  colors[1] = 0;
703  }
704  colors[2] -= darken;
705  if (colors[2] < 0) {
706  colors[2] = 0;
707  }
708  colors[3] -= darken;
709  if (colors[3] < 0) {
710  colors[3] = 0;
711  }
712  glColor3dv(colors);
713  if (routeNo == 0) {
714  drawRouteHelper(s, myVehicle.getRoute(), future);
715  return;
716  }
717  --routeNo; // only prior routes are stored
718  const MSRoute* route = myRoutes->getRoute(routeNo);
719  if (route != nullptr) {
720  drawRouteHelper(s, *route, future);
721  }
722 }
723 
724 
725 const Position&
726 GUIBaseVehicle::getSeatPosition(int personIndex) const {
728  return mySeatPositions[MIN2(personIndex, (int)mySeatPositions.size() - 1)];
729 }
730 
731 
732 void
734  if (myVehicle.myPersonDevice != nullptr) {
735  const std::vector<MSTransportable*>& ps = myVehicle.myPersonDevice->getTransportables();
736  int personIndex = 0;
737  for (std::vector<MSTransportable*>::const_iterator i = ps.begin(); i != ps.end(); ++i) {
738  GUIPerson* person = dynamic_cast<GUIPerson*>(*i);
739  assert(person != 0);
740  person->setPositionInVehicle(getSeatPosition(personIndex++));
741  person->drawGL(s);
742  }
743  }
744  if (myVehicle.myContainerDevice != nullptr) {
745  const std::vector<MSTransportable*>& cs = myVehicle.myContainerDevice->getTransportables();
746  int containerIndex = 0;
747  for (std::vector<MSTransportable*>::const_iterator i = cs.begin(); i != cs.end(); ++i) {
748  GUIContainer* container = dynamic_cast<GUIContainer*>(*i);
749  assert(container != 0);
750  container->setPositionInVehicle(getSeatPosition(containerIndex++));
751  container->drawGL(s);
752  }
753  }
754 #ifdef DRAW_BOUNDING_BOX
755  glPushName(getGlID());
756  glPushMatrix();
757  glTranslated(0, 0, getType());
758  PositionVector boundingBox = getBoundingBox();
759  boundingBox.push_back(boundingBox.front());
760  PositionVector smallBB = getBoundingPoly();
761  glColor3d(0, .8, 0);
762  GLHelper::drawLine(boundingBox);
763  glColor3d(0.5, .8, 0);
764  GLHelper::drawLine(smallBB);
765  //GLHelper::drawBoxLines(getBoundingBox(), 0.5);
766  glPopMatrix();
767  glPopName();
768 #endif
769 }
770 
771 
772 bool
774  if (getVType().getParameter().carriageLength > 0) {
775  drawAction_drawCarriageClass(s, asImage);
776  return true;
777  } else {
779  s, getVType().getImgFile(), this, getVType().getWidth(), getVType().getLength())) {
780  return false;
781  }
782  GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(s, getVType().getGuiShape(), getVType().getWidth(), getVType().getLength());
783  return false;
784  }
785 }
786 
787 
788 int
790  if (myVehicle.getPersonDevice() != nullptr) {
791  return (int)myVehicle.getPersonDevice()->size();
792  }
793  return 0;
794 }
795 
796 
797 int
799  if (myVehicle.getContainerDevice() != nullptr) {
800  return (int)myVehicle.getContainerDevice()->size();
801  }
802  return 0;
803 }
804 
805 
806 void
807 GUIBaseVehicle::computeSeats(const Position& front, const Position& back, int maxSeats, double exaggeration, int& requiredSeats) const {
808  if (requiredSeats <= 0) {
809  return; // save some work
810  }
811  const double vehWidth = getVType().getWidth() * exaggeration;
812  const double length = front.distanceTo2D(back);
813  const double seatOffset = SUMO_const_waitingPersonWidth * exaggeration;
814  const int rowSize = MAX2(1, (int)floor(vehWidth / seatOffset));
815  const double rowOffset = (length - 1) / ceil((double)maxSeats / rowSize);
816  const double sideOffset = (rowSize - 1) / 2 * seatOffset;
817  double rowPos = 1 - rowOffset;
818  for (int i = 0; requiredSeats > 0 && i < maxSeats; i++) {
819  int seat = (i % rowSize);
820  if (seat == 0) {
821  rowPos += rowOffset;
822  }
823  mySeatPositions.push_back(PositionVector::positionAtOffset2D(front, back, rowPos,
824  seat * seatOffset - sideOffset));
825  requiredSeats--;
826  }
827 }
828 
829 
830 
831 /****************************************************************************/
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
bool drawBrakeGap
Information whether the brake gap shall be drawn.
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:192
show vehicle&#39;s current continued from the current position
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.
SUMOVehicleShape getGuiShape() const
Get this vehicle type&#39;s shape.
render as a rail
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:125
RGBColor color
The vehicle&#39;s color, TraCI may change this.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:80
long long int SUMOTime
Definition: SUMOTime.h:35
double scale
information about a lane&#39;s width (temporary, used for a single view)
virtual void drawAction_drawVehicleBlueLight() const
int size() const
Return the number of passengers / containers.
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:45
MoveReminderCont myMoveReminders
Currently relevant move reminders.
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:121
bool showBlinker
Information whether vehicle blinkers shall be drawn.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
virtual void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r, bool future) const =0
Draws the route.
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length)
draw vehicle as a Box
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:561
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb.htm.
Definition: RGBColor.cpp:299
static const RGBColor WHITE
Definition: RGBColor.h:197
render as a motorcycle
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:244
long onCmdStartTrack(FXObject *, FXSelector, void *)
Called if the vehicle shall be tracked.
bool showBTRange
Information whether the communication range shall be drawn.
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
Stores the information about how to visualize structures.
const MSDevice_Transportable * getPersonDevice() const
double y() const
Returns the y-position.
Definition: Position.h:62
Hide all vehicle&#39;s routes.
Definition: GUIAppEnum.h:417
void computeSeats(const Position &front, const Position &back, int maxSeats, double exaggeration, int &requiredSeats) const
add seats to mySeatPositions and update requiredSeats
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:701
virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings &s) const
MSDevice_Vehroutes * myRoutes
GUIVisualizationTextSettings vehicleName
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2169
double x() const
Returns the x-position.
Definition: Position.h:57
virtual void drawAction_drawLinkItems(const GUIVisualizationSettings &) const
void drawRoute(const GUIVisualizationSettings &s, int routeNo, double darken, bool future=false) const
Chooses the route to draw and draws it, darkening it as given.
static double getRange()
Returns the configured range.
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:366
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:668
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
T MAX2(T a, T b)
Definition: StdDefs.h:80
const MSRoute & getRoute() const
Returns the current route.
The vehicle got vaporized.
const double SUMO_const_waitingPersonWidth
Definition: StdDefs.h:57
GUISUMOAbstractView * myParent
The parent window.
bool addAdditionalGLVisualisation(const GUIGlObject *const which)
Adds an object to call its additional visualisation method.
virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings &s, bool asImage) const =0
draws the given guiShape with distinct carriages/modules
#define RAD2DEG(x)
Definition: GeomHelper.h:39
static void drawLinkItem(const Position &pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate)
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 stopTrack()
stop track
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:348
virtual void selectBlockingFoes() const =0
adds the blocking foes to the current selection
int getPersonCapacity() const
Get this vehicle type&#39;s person capacity.
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.
int getContainerCapacity() const
Get this vehicle type&#39;s container capacity.
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:413
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:419
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 onCmdHideFutureRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be hidden.
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)
virtual double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const =0
gets the color value according to the current scheme index
GUIColorer vehicleColorer
The vehicle colorer.
const std::string getOptionalName() const
Returns the value for generic parameter &#39;name&#39; or &#39;&#39;.
static void drawAction_drawVehicleAsTrianglePlus(const double width, const double length)
draw vehicle as a triangle
virtual GUIGlID getTrackedID() const
get tracked id
virtual void startTrack(int)
star track
static const RGBColor GREEN
Definition: RGBColor.h:191
GUIVisualizationTextSettings vehicleValue
Stop to track a vehicle.
Definition: GUIAppEnum.h:421
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.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
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:616
Show vehicle&#39;s best lanes.
Definition: GUIAppEnum.h:411
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
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
get scale size
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:204
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:337
render as a bicycle
long onCmdHideBestLanes(FXObject *, FXSelector, void *)
Called if the vehicle&#39;s best lanes shall be hidden.
long onCmdRemoveObject(FXObject *, FXSelector, void *)
Called when removing the vehicle.
long onCmdShowFutureRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be shown.
#define STEPS2TIME(x)
Definition: SUMOTime.h:57
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void setPositionInVehicle(const Position &pos)
Definition: GUIPerson.cpp:367
render as a (city) rail without locomotive
T MIN2(T a, T b)
Definition: StdDefs.h:74
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:393
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.
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:1055
int getNumPassengers() const
return the number of passengers
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.
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:274
Show vehicle&#39;s current route.
Definition: GUIAppEnum.h:403
bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings &s, bool asImage=false) const
draw vehicle body and return whether carriages are being drawn
render as a police car
const int VEHPARS_COLOR_SET
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GUIPerson.cpp:277
Hide vehicle&#39;s future route.
Definition: GUIAppEnum.h:409
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.
static void drawAction_drawVehicleAsPoly(const GUIVisualizationSettings &s, const SUMOVehicleShape shape, const double width, const double length, int carriageIndex=-1)
draw vehicle as a polygon
void setPositionInVehicle(const Position &pos)
Definition: GUIContainer.h:118
render as a cargo train
render as a fire brigade
remove a vehice or person
Definition: GUIAppEnum.h:427
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
static const RGBColor RED
named colors
Definition: RGBColor.h:190
~GUIBaseVehicle()
destructor
Show all vehicle&#39;s routes.
Definition: GUIAppEnum.h:415
void removeActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
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:83
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
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.
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
The popup menu of a globject.
const std::string getParameter(const std::string &key, const std::string &defaultValue="") const
Returns the value for a given key.
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.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:106
double getLength() const
Get vehicle&#39;s length [m].
Show vehicle&#39;s future route.
Definition: GUIAppEnum.h:407
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
const MSDevice_Transportable * getContainerDevice() const
static bool drawAction_drawVehicleAsImage(const GUIVisualizationSettings &s, const std::string &file, const GUIGlObject *o, const double width, double length)
try to draw vehicle as raster image and return true if sucessful
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.
int vehicleQuality
The quality of vehicle drawing.
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
select foes of a vehicle
Definition: GUIAppEnum.h:423
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle *veh)
sets the color according to the current scheme index and some vehicle function
void addActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne=false) const
static bool gUseMesoSim
Definition: MSGlobals.h:91
show vehicle&#39;s current route
const int VTYPEPARS_COLOR_SET
void vaporizeCar(MEVehicle *v)
remove the given car and clean up the relevant data structures
Definition: MELoop.cpp:224
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
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.
Hide vehicle&#39;s current route.
Definition: GUIAppEnum.h:405
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
bool hasActiveAddVisualisation(GUISUMOAbstractView *const parent, int which) const
Returns whether the named feature is enabled in the given view.
virtual void drawAction_drawVehicleBlinker(double) const
int getNumContainers() const
return the number of passengers