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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // A MSVehicle extended by some values for usage within the gui
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <cmath>
26 #include <vector>
27 #include <string>
28 #include <functional>
31 #include <utils/geom/GeomHelper.h>
39 #include <utils/gui/div/GLHelper.h>
42 #include <mesosim/MEVehicle.h>
43 #include <mesosim/MELoop.h>
44 #include <microsim/MSVehicle.h>
45 #include <microsim/MSLane.h>
49 #include <microsim/MSStop.h>
55 #include <gui/GUIGlobals.h>
57 
58 #include "GUIBaseVehicle.h"
59 #include "GUIPerson.h"
60 #include "GUIContainer.h"
61 #include "GUINet.h"
62 #include "GUIEdge.h"
63 #include "GUILane.h"
64 #include "GUIParkingArea.h"
65 
66 //#define DRAW_BOUNDING_BOX
67 
68 // ===========================================================================
69 // FOX callback mapping
70 // ===========================================================================
71 FXDEFMAP(GUIBaseVehicle::GUIBaseVehiclePopupMenu) GUIBaseVehiclePopupMenuMap[] = {
90 };
91 
92 // Object implementation
93 FXIMPLEMENT(GUIBaseVehicle::GUIBaseVehiclePopupMenu, GUIGLObjectPopupMenu, GUIBaseVehiclePopupMenuMap, ARRAYNUMBER(GUIBaseVehiclePopupMenuMap))
94 
95 // ===========================================================================
96 // method definitions
97 // ===========================================================================
98 /* -------------------------------------------------------------------------
99  * GUIBaseVehicle::GUIBaseVehiclePopupMenu - methods
100  * ----------------------------------------------------------------------- */
103  : GUIGLObjectPopupMenu(app, parent, o) {
104 }
105 
106 
108 
109 
110 long
112  assert(myObject->getType() == GLO_VEHICLE);
113  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES)) {
114  static_cast<GUIBaseVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES);
115  }
116  return 1;
117 }
118 
119 long
121  assert(myObject->getType() == GLO_VEHICLE);
122  static_cast<GUIBaseVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ALL_ROUTES);
123  return 1;
124 }
125 
126 
127 long
129  assert(myObject->getType() == GLO_VEHICLE);
130  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE)) {
131  static_cast<GUIBaseVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ROUTE);
132  }
133  return 1;
134 }
135 
136 long
138  assert(myObject->getType() == GLO_VEHICLE);
139  static_cast<GUIBaseVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ROUTE);
140  return 1;
141 }
142 
143 
144 long
146  assert(myObject->getType() == GLO_VEHICLE);
147  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_FUTURE_ROUTE)) {
148  static_cast<GUIBaseVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_FUTURE_ROUTE);
149  }
150  return 1;
151 }
152 
153 long
155  assert(myObject->getType() == GLO_VEHICLE);
156  static_cast<GUIBaseVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_FUTURE_ROUTE);
157  return 1;
158 }
159 
160 
161 long
163  assert(myObject->getType() == GLO_VEHICLE);
164  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_ROUTE_NOLOOP)) {
165  static_cast<GUIBaseVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_ROUTE_NOLOOP);
166  }
167  return 1;
168 }
169 
170 long
172  assert(myObject->getType() == GLO_VEHICLE);
173  static_cast<GUIBaseVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_ROUTE_NOLOOP);
174  return 1;
175 }
176 
177 
178 long
180  assert(myObject->getType() == GLO_VEHICLE);
181  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES)) {
182  static_cast<GUIBaseVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES);
183  }
184  return 1;
185 }
186 
187 long
189  assert(myObject->getType() == GLO_VEHICLE);
190  static_cast<GUIBaseVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_BEST_LANES);
191  return 1;
192 }
193 
194 
195 long
197  assert(myObject->getType() == GLO_VEHICLE);
198  if (myParent->getTrackedID() != static_cast<GUIBaseVehicle*>(myObject)->getGlID()) {
199  myParent->startTrack(static_cast<GUIBaseVehicle*>(myObject)->getGlID());
200  }
201  return 1;
202 }
203 
204 long
206  assert(myObject->getType() == GLO_VEHICLE);
207  myParent->stopTrack();
208  return 1;
209 }
210 
211 
212 long
214  assert(myObject->getType() == GLO_VEHICLE);
215  if (!static_cast<GUIBaseVehicle*>(myObject)->hasActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS)) {
216  static_cast<GUIBaseVehicle*>(myObject)->addActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS);
217  }
218  return 1;
219 }
220 
221 long
223  assert(myObject->getType() == GLO_VEHICLE);
224  static_cast<GUIBaseVehicle*>(myObject)->removeActiveAddVisualisation(myParent, VO_SHOW_LFLINKITEMS);
225  return 1;
226 }
227 
228 long
230  assert(myObject->getType() == GLO_VEHICLE);
231  static_cast<GUIBaseVehicle*>(myObject)->selectBlockingFoes();
232  myParent->update();
233  return 1;
234 }
235 
236 
237 long
239  assert(myObject->getType() == GLO_VEHICLE);
240  const MSBaseVehicle& veh = static_cast<GUIBaseVehicle*>(myObject)->getVehicle();
241  for (const MSTransportable* t : veh.getPersons()) {
242  gSelected.select((static_cast<const GUIPerson*>(t))->getGlID());
243  }
244  for (MSTransportable* t : veh.getContainers()) {
245  gSelected.select((static_cast<const GUIContainer*>(t))->getGlID());
246  }
247  myParent->update();
248  return 1;
249 }
250 
251 long
253  GUIBaseVehicle* baseVeh = static_cast<GUIBaseVehicle*>(myObject);
254  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&baseVeh->myVehicle);
255  if (microVeh != nullptr) {
257  if (microVeh->getLane() != nullptr) {
258  MSLane* lane = microVeh->getMutableLane();
260  }
261  } else {
262  MEVehicle* mesoVeh = dynamic_cast<MEVehicle*>(&baseVeh->myVehicle);
264  }
266  myParent->update();
267  return 1;
268 }
269 
270 
271 long
273  GUIBaseVehicle* baseVeh = static_cast<GUIBaseVehicle*>(myObject);
274  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&baseVeh->myVehicle);
275  if (microVeh != nullptr) {
276  if (microVeh->isStopped()) {
277  microVeh->resumeFromStopping();
278  } else {
279  std::string errorOut;
280  const double brakeGap = microVeh->getCarFollowModel().brakeGap(microVeh->getSpeed());
281  std::pair<const MSLane*, double> stopPos = microVeh->getLanePosAfterDist(brakeGap);
282  if (stopPos.first != nullptr) {
284  stop.lane = stopPos.first->getID();
285  stop.startPos = stopPos.second;
286  stop.endPos = stopPos.second + POSITION_EPS;
287  stop.duration = TIME2STEPS(3600);
288  microVeh->addTraciStop(stop, errorOut);
289  if (errorOut != "") {
290  WRITE_WARNING(errorOut);
291  }
292  }
293  }
294  } else {
295  WRITE_WARNING("GUI-triggered stop not implemented for meso");
296  }
297  myParent->update();
298  return 1;
299 }
300 
301 
302 /* -------------------------------------------------------------------------
303  * GUIBaseVehicle - methods
304  * ----------------------------------------------------------------------- */
305 
307  GUIGlObject(GLO_VEHICLE, vehicle.getID()),
308  myVehicle(vehicle),
309  myPopup(nullptr) {
310  // as it is possible to show all vehicle routes, we have to store them... (bug [ 2519761 ])
312  myVehicle.myMoveReminders.push_back(std::make_pair(myRoutes, 0.));
313  mySeatPositions.push_back(Seat()); // ensure length 1
314  myContainerPositions.push_back(Seat()); // ensure length 1
315 }
316 
317 
319  myLock.lock();
320  for (std::map<GUISUMOAbstractView*, int>::iterator i = myAdditionalVisualizations.begin(); i != myAdditionalVisualizations.end(); ++i) {
321  while (i->first->removeAdditionalGLVisualisation(this));
322  }
323  myLock.unlock();
324  delete myRoutes;
325  if (myPopup != nullptr) {
327  }
328 }
329 
330 
333  GUISUMOAbstractView& parent) {
334  GUIGLObjectPopupMenu* ret = new GUIBaseVehiclePopupMenu(app, parent, *this);
335  buildPopupHeader(ret, app);
339  //
341  GUIDesigns::buildFXMenuCommand(ret, "Hide Current Route", nullptr, ret, MID_HIDE_CURRENTROUTE);
342  } else {
343  GUIDesigns::buildFXMenuCommand(ret, "Show Current Route", nullptr, ret, MID_SHOW_CURRENTROUTE);
344  }
346  GUIDesigns::buildFXMenuCommand(ret, "Hide Future Route", nullptr, ret, MID_HIDE_FUTUREROUTE);
347  } else {
348  GUIDesigns::buildFXMenuCommand(ret, "Show Future Route", nullptr, ret, MID_SHOW_FUTUREROUTE);
349  }
351  GUIDesigns::buildFXMenuCommand(ret, "Hide All Routes", nullptr, ret, MID_HIDE_ALLROUTES);
352  } else {
353  GUIDesigns::buildFXMenuCommand(ret, "Show All Routes", nullptr, ret, MID_SHOW_ALLROUTES);
354  }
356  FXMenuCheck* showLoops = new FXMenuCheck(ret, "Draw looped routes", ret, MID_HIDE_ROUTE_NOLOOPS);
357  showLoops->setCheck(false);
358  } else {
359  FXMenuCheck* showLoops = new FXMenuCheck(ret, "Draw looped routes", ret, MID_SHOW_ROUTE_NOLOOPS);
360  showLoops->setCheck(true);
361  }
363  GUIDesigns::buildFXMenuCommand(ret, "Hide Best Lanes", nullptr, ret, MID_HIDE_BEST_LANES);
364  } else {
365  GUIDesigns::buildFXMenuCommand(ret, "Show Best Lanes", nullptr, ret, MID_SHOW_BEST_LANES);
366  }
368  GUIDesigns::buildFXMenuCommand(ret, "Hide Link Items", nullptr, ret, MID_HIDE_LFLINKITEMS);
369  } else {
370  GUIDesigns::buildFXMenuCommand(ret, "Show Link Items", nullptr, ret, MID_SHOW_LFLINKITEMS);
371  }
372  new FXMenuSeparator(ret);
373  if (parent.getTrackedID() != getGlID()) {
374  GUIDesigns::buildFXMenuCommand(ret, "Start Tracking", nullptr, ret, MID_START_TRACK);
375  } else {
376  GUIDesigns::buildFXMenuCommand(ret, "Stop Tracking", nullptr, ret, MID_STOP_TRACK);
377  }
378  GUIDesigns::buildFXMenuCommand(ret, "Select Foes", nullptr, ret, MID_SHOW_FOES);
379  if (myVehicle.getPersons().size() + myVehicle.getContainers().size() > 0) {
380  GUIDesigns::buildFXMenuCommand(ret, "Select transported", nullptr, ret, MID_SELECT_TRANSPORTED);
381  }
382  GUIDesigns::buildFXMenuCommand(ret, myVehicle.isStopped() ? "Abort stop" : "Stop", nullptr, ret, MID_TOGGLE_STOP);
383  GUIDesigns::buildFXMenuCommand(ret, "Remove", nullptr, ret, MID_REMOVE_OBJECT);
384 
385  new FXMenuSeparator(ret);
386  //
387  buildShowParamsPopupEntry(ret, false);
389  buildPositionCopyEntry(ret, false);
390  myPopup = ret;
391  return ret;
392 }
393 
394 
395 void
397  myPopup = nullptr;
398 }
399 
400 
401 double
403  return (s.vehicleSize.getExaggeration(s, this) *
405 }
406 
407 
408 Boundary
410  Boundary b;
411  b.add(getPosition());
413  return b;
414 }
415 
416 
417 const std::string
419  return myVehicle.getParameter().getParameter("name", "");
420 }
421 
422 
423 void
424 GUIBaseVehicle::drawOnPos(const GUIVisualizationSettings& s, const Position& pos, const double angle) const {
427  Position p1 = pos;
428  const double degAngle = RAD2DEG(angle + M_PI / 2.);
429  const double length = getVType().getLength();
430  glTranslated(p1.x(), p1.y(), getType());
431  glRotated(degAngle, 0, 0, 1);
432  // set vehicle color
433  RGBColor col = setColor(s);
434  // scale
435  const double upscale = getExaggeration(s);
436  double upscaleLength = upscale;
437  if (upscale > 1 && length > 5 && s.vehicleQuality != 4) {
438  // reduce the length/width ratio because this is not usefull at high zoom
439  const double widthLengthFactor = length / getVType().getWidth();
440  const double shrinkFactor = MIN2(widthLengthFactor, sqrt(upscaleLength));
441  upscaleLength /= shrinkFactor;
442  }
443  glScaled(upscale, upscaleLength, 1);
444  /*
445  MSLaneChangeModel::DK2004 &m2 = static_cast<MSLaneChangeModel::DK2004&>(veh->getLaneChangeModel());
446  if((m2.getState()&LCA_URGENT)!=0) {
447  glColor3d(1, .4, .4);
448  } else if((m2.getState()&LCA_SPEEDGAIN)!=0) {
449  glColor3d(.4, .4, 1);
450  } else {
451  glColor3d(.4, 1, .4);
452  }
453  */
454  // draw the vehicle
455  bool drawCarriages = false;
456  const double geometryFactor = (s.scaleLength ?
457  ((myVehicle.getLane() != nullptr
459  : (myVehicle.getEdge()->getLanes().size() > 0 ? myVehicle.getEdge()->getLanes()[0]->getLengthGeometryFactor() : 1)))
460  : 1);
461  double scaledLength = length * geometryFactor;
462  if (col.alpha() != 0) {
463  switch (s.vehicleQuality) {
464  case 0:
466  break;
467  case 1:
469  break;
470  case 2:
471  drawCarriages = drawAction_drawVehicleAsPolyWithCarriagges(s, scaledLength);
472  // draw flashing blue light for emergency vehicles
473  if (getVType().getGuiShape() == SUMOVehicleShape::EMERGENCY) {
474  glTranslated(0, 0, .1);
476  }
477  break;
478  case 3:
479  drawCarriages = drawAction_drawVehicleAsPolyWithCarriagges(s, scaledLength, true);
480  break;
481  case 4:
482  // do not scale circle radius by lengthGeometryFactor
483  GUIBaseVehicleHelper::drawAction_drawVehicleAsCircle(getVType().getWidth(), length, s.scale * upscale);
484  // display text at circle center
485  scaledLength = 0;
486  break;
487  default:
488  break;
489  }
490  if (s.drawMinGap) {
491  const double minGap = -getVType().getMinGap();
492  glColor3d(0., 1., 0.);
493  glBegin(GL_LINES);
494  glVertex2d(0., 0);
495  glVertex2d(0., minGap);
496  glVertex2d(-.5, minGap);
497  glVertex2d(.5, minGap);
498  glEnd();
499  }
502  const double brakeGap = -static_cast<MSVehicle&>(myVehicle).getCarFollowModel().brakeGap(myVehicle.getSpeed());
503  glColor3d(1., 0., 0.);
504  glBegin(GL_LINES);
505  glVertex2d(0., 0);
506  glVertex2d(0., brakeGap);
507  glVertex2d(-.5, brakeGap);
508  glVertex2d(.5, brakeGap);
509  glEnd();
510  }
512  if (dev != nullptr && s.showBTRange) {
513  glColor3d(1., 0., 0.);
514  GLHelper::drawOutlineCircle(dev->getRange(), dev->getRange() - .2, 32);
515  }
516  // draw the blinker and brakelights if wished
517  if (s.showBlinker) {
518  glTranslated(0, 0, .1);
519  switch (getVType().getGuiShape()) {
528  break;
531  drawAction_drawVehicleBlinker(scaledLength);
532  drawAction_drawVehicleBrakeLight(scaledLength, true);
533  break;
534  default:
535  // only SUMOVehicleShape::RAIL_CAR has blinkers and brake lights but they are drawn along with the carriages
536  if (!drawCarriages) {
537  drawAction_drawVehicleBlinker(scaledLength);
538  drawAction_drawVehicleBrakeLight(scaledLength);
539  }
540  break;
541  }
542  }
543  // draw the wish to change the lane
544  if (s.drawLaneChangePreference) {
545  /*
546  if(gSelected.isSelected(GLO_VEHICLE, veh->getGlID())) {
547  MSLaneChangeModel::DK2004 &m = static_cast<MSLaneChangeModel::DK2004&>(veh->getLaneChangeModel());
548  glColor3d(.5, .5, 1);
549  glBegin(GL_LINES);
550  glVertex2f(0, 0);
551  glVertex2f(m.getChangeProbability(), .5);
552  glEnd();
553 
554  glColor3d(1, 0, 0);
555  glBegin(GL_LINES);
556  glVertex2f(0.1, 0);
557  glVertex2f(0.1, m.myMaxJam1);
558  glEnd();
559 
560  glColor3d(0, 1, 0);
561  glBegin(GL_LINES);
562  glVertex2f(-0.1, 0);
563  glVertex2f(-0.1, m.myTDist);
564  glEnd();
565  }
566  */
567  }
568  }
569  glTranslated(0, MIN2(scaledLength / 2, double(5)), -getType()); // drawing name at GLO_MAX fails unless translating z
570  glScaled(1 / upscale, 1 / upscaleLength, 1);
571  glRotated(-degAngle, 0, 0, 1);
572  drawName(Position(0, 0), s.scale, s.vehicleName, s.angle);
573  if (s.vehicleName.show(this) && myVehicle.getParameter().line != "") {
574  glRotated(-s.angle, 0, 0, 1);
575  glTranslated(0, 0.7 * s.vehicleName.scaledSize(s.scale), 0);
576  glRotated(s.angle, 0, 0, 1);
578  }
579  if (s.vehicleValue.show(this)) {
580  glRotated(-s.angle, 0, 0, 1);
581  glTranslated(0, 0.7 * s.vehicleName.scaledSize(s.scale), 0);
582  glRotated(s.angle, 0, 0, 1);
583  const double value = getColorValue(s, s.vehicleColorer.getActive());
585  }
586  if (s.vehicleScaleValue.show(this)) {
587  glRotated(-s.angle, 0, 0, 1);
588  glTranslated(0, 0.7 * s.vehicleName.scaledSize(s.scale), 0);
589  glRotated(s.angle, 0, 0, 1);
590  const double value = getScaleValue(s, s.vehicleScaler.getActive());
592  }
593  if (s.vehicleText.show(this)) {
594  std::string error;
595  std::string value = myVehicle.getPrefixedParameter(s.vehicleTextParam, error);
596  if (value != "") {
597  auto lines = StringTokenizer(value, StringTokenizer::NEWLINE).getVector();
598  glRotated(-s.angle, 0, 0, 1);
599  glTranslated(0, 0.7 * s.vehicleText.scaledSize(s.scale) * lines.size(), 0);
600  glRotated(s.angle, 0, 0, 1);
601  for (std::string& line : lines) {
603  glRotated(-s.angle, 0, 0, 1);
604  glTranslated(0, -0.7 * s.vehicleText.scaledSize(s.scale), 0);
605  glRotated(s.angle, 0, 0, 1);
606  }
607  }
608  }
611  glRotated(-s.angle, 0, 0, 1);
612  glTranslated(0, 0.7 * s.vehicleName.scaledSize(s.scale), 0);
613  glRotated(s.angle, 0, 0, 1);
614  const double value = myVehicle.getNumberParkingReroutes();
616  }
617 
618  if (!drawCarriages) {
619  mySeatPositions.clear();
620  myContainerPositions.clear();
621  int requiredSeats = getNumPassengers();
622  int requiredContainerPositions = getNumContainers();
623  const Position back = (p1 + Position(-scaledLength * upscaleLength, 0)).rotateAround2D(angle, p1);
624  computeSeats(p1, back, SUMO_const_waitingPersonWidth, getVType().getPersonCapacity(), upscale, requiredSeats, mySeatPositions);
625  computeSeats(p1, back, SUMO_const_waitingContainerWidth, getVType().getContainerCapacity(), upscale, requiredContainerPositions, myContainerPositions);
626  }
627 
631 }
632 
633 
634 void
636  drawOnPos(s, getPosition(), getAngle());
637 }
638 
639 
640 void
642  if (!myVehicle.isOnRoad()) {
643  drawGL(s);
644  }
647  glTranslated(0, 0, getType() - .1); // don't draw on top of other cars
649  drawBestLanes();
650  }
651  bool noLoop = hasActiveAddVisualisation(parent, VO_SHOW_ROUTE_NOLOOP);
653  drawRoute(s, 0, 0.25, false, noLoop);
654  }
656  drawRoute(s, 0, 0.25, true, noLoop);
657  }
659  if (myVehicle.getNumberReroutes() > 0) {
660  const int noReroutePlus1 = myVehicle.getNumberReroutes() + 1;
661  for (int i = noReroutePlus1 - 1; i >= 0; i--) {
662  double darken = double(0.4) / double(noReroutePlus1) * double(i);
663  drawRoute(s, i, darken);
664  }
665  } else {
666  drawRoute(s, 0, 0.25, false, noLoop);
667  }
668  }
671  }
674 }
675 
676 
677 void
678 GUIBaseVehicle::drawLinkItem(const Position& pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate) {
679  glTranslated(pos.x(), pos.y(), -.1);
681  std::string times = toString(STEPS2TIME(arrivalTime)) + "/" + toString(STEPS2TIME(leaveTime));
682  GLHelper::drawText(times.c_str(), Position(), .1, 1.6 * exagerate, RGBColor::GREEN, 0);
683  glTranslated(-pos.x(), -pos.y(), .1);
684 }
685 
686 
687 RGBColor
689  RGBColor col;
690  const GUIColorer& c = s.vehicleColorer;
691  if (!setFunctionalColor(c.getActive(), &myVehicle, col)) {
692  col = c.getScheme().getColor(getColorValue(s, c.getActive()));
693  }
694  GLHelper::setColor(col);
695  return col;
696 }
697 
698 
699 bool
700 GUIBaseVehicle::setFunctionalColor(int activeScheme, const MSBaseVehicle* veh, RGBColor& col) {
701  switch (activeScheme) {
702  case 0: {
703  //test for emergency vehicle
705  col = RGBColor::WHITE;
706  return true;
707  }
708  //test for firebrigade
710  col = RGBColor::RED;
711  return true;
712  }
713  //test for police car
715  col = RGBColor::BLUE;
716  return true;
717  }
718  if (veh->getParameter().wasSet(VEHPARS_COLOR_SET)) {
719  col = veh->getParameter().color;
720  return true;
721  }
723  col = veh->getVehicleType().getColor();
724  return true;
725  }
726  if (&(veh->getRoute().getColor()) != &RGBColor::DEFAULT_COLOR) {
727  col = veh->getRoute().getColor();
728  return true;
729  }
730  return false;
731  }
732  case 2: {
733  if (veh->getParameter().wasSet(VEHPARS_COLOR_SET)) {
734  col = veh->getParameter().color;
735  return true;
736  }
737  return false;
738  }
739  case 3: {
741  col = veh->getVehicleType().getColor();
742  return true;
743  }
744  return false;
745  }
746  case 4: {
747  if (&(veh->getRoute().getColor()) != &RGBColor::DEFAULT_COLOR) {
748  col = veh->getRoute().getColor();
749  return true;
750  }
751  return false;
752  }
753  case 5: {
754  Position p = veh->getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
755  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
756  Position center = b.getCenter();
757  double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
758  double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
759  col = RGBColor::fromHSV(hue, sat, 1.);
760  return true;
761  }
762  case 6: {
763  Position p = veh->getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
764  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
765  Position center = b.getCenter();
766  double hue = 180. + atan2(center.x() - p.x(), center.y() - p.y()) * 180. / M_PI;
767  double sat = p.distanceTo(center) / center.distanceTo(Position(b.xmin(), b.ymin()));
768  col = RGBColor::fromHSV(hue, sat, 1.);
769  return true;
770  }
771  case 7: {
772  Position pb = veh->getRoute().getEdges()[0]->getLanes()[0]->getShape()[0];
773  Position pe = veh->getRoute().getEdges().back()->getLanes()[0]->getShape()[-1];
774  const Boundary& b = ((GUINet*) MSNet::getInstance())->getBoundary();
775  double hue = 180. + atan2(pb.x() - pe.x(), pb.y() - pe.y()) * 180. / M_PI;
776  Position minp(b.xmin(), b.ymin());
777  Position maxp(b.xmax(), b.ymax());
778  double sat = pb.distanceTo(pe) / minp.distanceTo(maxp);
779  col = RGBColor::fromHSV(hue, sat, 1.);
780  return true;
781  }
782  case 33: { // color randomly (by pointer hash)
783  std::hash<const MSBaseVehicle*> ptr_hash;
784  const double hue = (double)(ptr_hash(veh) % 360); // [0-360]
785  const double sat = ((ptr_hash(veh) / 360) % 67) / 100.0 + 0.33; // [0.33-1]
786  col = RGBColor::fromHSV(hue, sat, 1.);
787  return true;
788  }
789  case 34: { // color by angle
790  double hue = GeomHelper::naviDegree(veh->getAngle());
791  col = RGBColor::fromHSV(hue, 1., 1.);
792  return true;
793  }
794  }
795  return false;
796 }
797 
798 
799 double
800 GUIBaseVehicle::getScaleValue(const GUIVisualizationSettings& s, int activeScheme) const {
801  switch (activeScheme) {
802  case 0: // uniform
803  return 0;
804  case 1: // selection
805  return myVehicle.isSelected();
806  case 2: // by speed
807  if (myVehicle.isStopped()) {
808  return myVehicle.isParking() ? -2 : -1;
809  }
810  return myVehicle.getSpeed();
811  case 3:
812  return myVehicle.getWaitingSeconds();
813  case 4: {
814  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&myVehicle);
815  return (microVeh != nullptr ? microVeh->getAccumulatedWaitingSeconds() : 0);
816  }
817  case 5: {
818  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&myVehicle);
819  return (microVeh != nullptr ? microVeh->getLane()->getVehicleMaxSpeed(microVeh) : myVehicle.getEdge()->getVehicleMaxSpeed(&myVehicle));
820  }
821  case 6:
822  return myVehicle.getNumberReroutes();
823  case 7: {
824  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&myVehicle);
825  return (microVeh != nullptr
826  ? (microVeh->getLaneChangeModel().isOpposite() ? -100 : microVeh->getBestLaneOffset())
827  : 0);
828  }
829  case 8:
830  return myVehicle.getAcceleration();
831  case 9: {
832  MSVehicle* microVeh = dynamic_cast<MSVehicle*>(&myVehicle);
833  return (microVeh != nullptr ? microVeh->getTimeGapOnLane() : 0);
834  }
835  case 10:
837  case 11:
838  return myVehicle.getTimeLossSeconds();
839  case 12:
840  return myVehicle.getStopDelay();
841  case 13:
843  case 14: // by numerical param value
844  std::string error;
845  std::string val = myVehicle.getPrefixedParameter(s.vehicleScaleParam, error);
846  try {
847  if (val == "") {
848  return 0;
849  } else {
850  return StringUtils::toDouble(val);
851  }
852  } catch (NumberFormatException&) {
853  try {
854  return StringUtils::toBool(val);
855  } catch (BoolFormatException&) {
856  WRITE_WARNING("Vehicle parameter '" + myVehicle.getParameter().getParameter(s.vehicleScaleParam, "0")
857  + "' key '" + s.vehicleScaleParam + "' is not a number for vehicle '" + myVehicle.getID() + "'");
858  return -1;
859  }
860  }
861  }
862  return 0;
863 }
864 
865 
866 // ------------ Additional visualisations
867 bool
869  return myAdditionalVisualizations.find(parent) != myAdditionalVisualizations.end() && (myAdditionalVisualizations.find(parent)->second & which) != 0;
870 }
871 
872 
873 void
875  if (myAdditionalVisualizations.find(parent) == myAdditionalVisualizations.end()) {
876  myAdditionalVisualizations[parent] = 0;
877  }
878  myAdditionalVisualizations[parent] |= which;
879  parent->addAdditionalGLVisualisation(this);
880 }
881 
882 
883 void
885  myAdditionalVisualizations[parent] &= ~which;
886  if (myAdditionalVisualizations[parent] == 0) {
887  myAdditionalVisualizations.erase(parent);
888  }
889  parent->removeAdditionalGLVisualisation(this);
890 }
891 
892 
893 void
894 GUIBaseVehicle::drawRoute(const GUIVisualizationSettings& s, int routeNo, double darken, bool future, bool noLoop) const {
895  RGBColor vehColor = setColor(s);
896  RGBColor darker = vehColor.changedBrightness((int)(darken * -255));
897  if (darker == RGBColor::BLACK) {
898  darker = vehColor.multiply(1 - darken);
899  }
900  GLHelper::setColor(darker);
901  if (routeNo == 0) {
902  drawRouteHelper(s, myVehicle.getRoute(), future, noLoop, darker);
903  return;
904  }
905  const MSRoute* route = myRoutes->getRoute(routeNo - 1); // only prior routes are stored
906  if (route != nullptr) {
907  drawRouteHelper(s, *route, future, noLoop, darker);
908  }
909 }
910 
911 
912 void
913 GUIBaseVehicle::drawStopLabels(const GUIVisualizationSettings& s, bool noLoop, const RGBColor& col) const {
914  // (vertical shift for repeated stops at the same position
915  std::map<std::pair<const MSLane*, double>, int> repeat; // count repeated occurrences of the same position
916  int stopIndex = 0;
917  for (const MSStop& stop : myVehicle.getStops()) {
918  double stopLanePos;
919  if (stop.pars.speed > 0) {
920  stopLanePos = stop.reached ? stop.pars.endPos : stop.pars.startPos;
921  } else {
922  stopLanePos = stop.reached ? myVehicle.getPositionOnLane() : MAX2(0.0, stop.getEndPos(myVehicle));
923  }
924  if (stop.isOpposite && !stop.reached) {
925  stopLanePos = stop.lane->getLength() - stopLanePos;
926  }
927  Position pos = stop.lane->geometryPositionAtOffset(stopLanePos);
928  GLHelper::setColor(col);
929  GLHelper::drawBoxLines(stop.lane->getShape().getOrthogonal(pos, 10, true, stop.lane->getWidth()), 0.1);
930  std::string label = (stop.pars.speed > 0
931  ? (stop.reached ? "passing waypoint" : "waypoint ")
932  : (stop.reached ? "stopped" : "stop "));
933  if (!stop.reached) {
934  label += toString(stopIndex);
935  }
936 
937  if (stop.isOpposite) {
938  label += " (opposite)";
939  }
940 #ifdef _DEBUG
941  label += " (" + toString(stop.edge - myVehicle.getCurrentRouteEdge()) + "e)";
942 #endif
944  label += " triggered:";
945  if (stop.triggered) {
946  label += "person";
947  if (stop.numExpectedPerson > 0) {
948  label += "(" + toString(stop.numExpectedPerson) + ")";
949  }
950  }
951  if (stop.containerTriggered) {
952  label += "container";
953  if (stop.numExpectedContainer > 0) {
954  label += "(" + toString(stop.numExpectedContainer) + ")";
955  }
956  }
957  if (stop.joinTriggered) {
958  label += "join";
959  if (stop.pars.join != "") {
960  label += "(" + stop.pars.join + ")";
961  }
962  }
963  }
964  if (stop.pars.until >= 0) {
965  label += " until:" + time2string(stop.pars.until);
966  }
967  if (stop.duration >= 0 || stop.pars.duration > 0) {
968  if (STEPS2TIME(stop.duration) > 3600 * 24) {
969  label += " duration:1day+";
970  } else {
971  label += " duration:" + time2string(stop.duration);
972  }
973  }
974  if (stop.pars.speed > 0) {
975  label += " speed:" + toString(stop.pars.speed);
976  }
977  if (stop.pars.actType != "") {
978  label += " actType:" + stop.pars.actType;
979  }
980  std::pair<const MSLane*, double> stopPos = std::make_pair(stop.lane, stopLanePos);
981  const double nameSize = s.vehicleName.size / s.scale;
982  Position pos2 = pos - Position(0, nameSize * repeat[stopPos]);
983  if (noLoop && repeat[stopPos] > 0) {
984  break;
985  }
986  GLHelper::drawTextSettings(s.vehicleText, label, pos2, s.scale, s.angle, 1.0);
987  repeat[stopPos]++;
988  stopIndex++;
989  }
990 }
991 
992 void
994  if (s.showParkingInfo) {
996  if (pm != nullptr) {
997  for (auto item : *pm) {
998  const GUIParkingArea* pa = dynamic_cast<const GUIParkingArea*>(item.first);
999  if (item.second.blockedAtTime >= 0) {
1000  std::string seenAgo = time2string(SIMSTEP - item.second.blockedAtTime);
1001  //if (item.second.blockedAtTime >= 0) {
1002  // seenAgo += ", " + time2string(SIMSTEP - item.second.blockedAtTimeLocal);
1003  //}
1004  GLHelper::drawTextSettings(s.vehicleValue, seenAgo, pa->getSignPos(), s.scale, s.angle, 1.0);
1005  }
1006  if (item.second.score != "") {
1007  const double dist = 0.4 * (s.vehicleText.scaledSize(s.scale) + s.vehicleValue.scaledSize(s.scale));
1008  Position shift(0, -dist);
1009  GLHelper::drawTextSettings(s.vehicleText, item.second.score, pa->getSignPos() + shift, s.scale, s.angle, 1.0);
1010  }
1011  }
1012  }
1013  }
1014 }
1015 
1016 const GUIBaseVehicle::Seat&
1017 GUIBaseVehicle::getSeatPosition(int personIndex) const {
1019  return mySeatPositions[MIN2(personIndex, (int)mySeatPositions.size() - 1)];
1020 }
1021 
1022 const GUIBaseVehicle::Seat&
1023 GUIBaseVehicle::getContainerPosition(int containerIndex) const {
1025  return myContainerPositions[MIN2(containerIndex, (int)myContainerPositions.size() - 1)];
1026 }
1027 
1028 
1029 void
1031  if (myVehicle.myPersonDevice != nullptr) {
1032  const std::vector<MSTransportable*>& ps = myVehicle.myPersonDevice->getTransportables();
1033  int personIndex = 0;
1034  for (std::vector<MSTransportable*>::const_iterator i = ps.begin(); i != ps.end(); ++i) {
1035  GUIPerson* person = dynamic_cast<GUIPerson*>(*i);
1036  assert(person != 0);
1037  person->setPositionInVehicle(getSeatPosition(personIndex++));
1038  person->drawGL(s);
1039  }
1040  }
1041  if (myVehicle.myContainerDevice != nullptr) {
1042  const std::vector<MSTransportable*>& cs = myVehicle.myContainerDevice->getTransportables();
1043  int containerIndex = 0;
1044  for (std::vector<MSTransportable*>::const_iterator i = cs.begin(); i != cs.end(); ++i) {
1045  GUIContainer* container = dynamic_cast<GUIContainer*>(*i);
1046  assert(container != 0);
1047  container->setPositionInVehicle(getContainerPosition(containerIndex++));
1048  container->drawGL(s);
1049  }
1050  }
1051 #ifdef DRAW_BOUNDING_BOX
1052  if (!MSGlobals::gUseMesoSim) {
1053  MSVehicle& microVeh = dynamic_cast<MSVehicle&>(myVehicle);
1056  glTranslated(0, 0, getType());
1057  PositionVector smallBB = microVeh.getBoundingPoly();
1058  glColor3d(0.5, .8, 0);
1059  GLHelper::drawBoxLines(smallBB, 0.3);
1060  glTranslated(0, 0, 0.1);
1061  PositionVector boundingBox = microVeh.getBoundingBox();
1062  boundingBox.push_back(boundingBox.front());
1063  glColor3d(1, 0, 0);
1064  GLHelper::drawBoxLines(boundingBox, 0.15);
1067  }
1068 #endif
1069 }
1070 
1071 
1072 bool
1074  if (getVType().getParameter().carriageLength > 0) {
1075  drawAction_drawCarriageClass(s, asImage);
1076  return true;
1077  } else {
1079  s, getVType().getImgFile(), this, getVType().getWidth(), scaledLength)) {
1080  return false;
1081  }
1082  GUIBaseVehicleHelper::drawAction_drawVehicleAsPoly(s, getVType().getGuiShape(), getVType().getWidth(), scaledLength);
1083  return false;
1084  }
1085 }
1086 
1087 
1088 int
1090  if (myVehicle.getPersonDevice() != nullptr) {
1091  return (int)myVehicle.getPersonDevice()->size();
1092  }
1093  return 0;
1094 }
1095 
1096 
1097 int
1099  if (myVehicle.getContainerDevice() != nullptr) {
1100  return (int)myVehicle.getContainerDevice()->size();
1101  }
1102  return 0;
1103 }
1104 
1105 std::string
1107  std::vector<std::string> devs;
1108  for (MSDevice* d : myVehicle.getDevices()) {
1109  devs.push_back(d->deviceName());
1110  }
1111  return joinToString(devs, " ");
1112 }
1113 
1114 
1115 void
1116 GUIBaseVehicle::computeSeats(const Position& front, const Position& back, double seatOffset, int maxSeats, double exaggeration, int& requiredSeats, Seats& into) const {
1117  if (requiredSeats <= 0) {
1118  return;
1119  }
1120  maxSeats = MAX2(maxSeats, 1); // compute at least one seat
1121  seatOffset *= exaggeration;
1122  const double vehWidth = getVType().getWidth() * exaggeration;
1123  const double length = front.distanceTo2D(back);
1124  const int rowSize = MAX2(1, (int)floor(vehWidth / seatOffset));
1125  const double rowOffset = MAX2(1.0, (length - getVType().getFrontSeatPos() - 1)) / ceil((double)maxSeats / rowSize);
1126  const double sideOffset = (rowSize - 1) / 2.0 * seatOffset;
1127  double rowPos = getVType().getFrontSeatPos() - rowOffset;
1128  double angle = back.angleTo2D(front);
1129  const int fillDirection = MSGlobals::gLefthand ? -1 : 1;
1130  //if (myVehicle.getID() == "v0") std::cout << SIMTIME << " seatOffset=" << seatOffset << " max=" << maxSeats << " ex=" << exaggeration << " req=" << requiredSeats << " rowSize=" << rowSize << " sideOffset=" << sideOffset << " front=" << front << " back=" << back << " a=" << angle << " da=" << RAD2DEG(angle) << "\n";
1131  for (int i = 0; requiredSeats > 0 && i < maxSeats; i++) {
1132  int seat = (i % rowSize);
1133  if (seat == 0) {
1134  rowPos += rowOffset;
1135  }
1136  into.push_back(Seat(PositionVector::positionAtOffset2D(front, back, rowPos, (sideOffset - seat * seatOffset) * fillDirection), angle));
1137  requiredSeats--;
1138  }
1139 }
1140 
1141 
1142 /****************************************************************************/
@ MID_HIDE_ALLROUTES
Hide all vehicle's routes.
Definition: GUIAppEnum.h:465
@ MID_HIDE_BEST_LANES
Hide vehicle's best lanes.
Definition: GUIAppEnum.h:461
@ MID_HIDE_CURRENTROUTE
Hide vehicle's current route.
Definition: GUIAppEnum.h:449
@ MID_SHOW_FOES
select foes of a vehicle
Definition: GUIAppEnum.h:471
@ MID_SHOW_BEST_LANES
Show vehicle's best lanes.
Definition: GUIAppEnum.h:459
@ MID_START_TRACK
Start to track a vehicle.
Definition: GUIAppEnum.h:467
@ MID_SHOW_ALLROUTES
Show all vehicle's routes.
Definition: GUIAppEnum.h:463
@ MID_SHOW_LFLINKITEMS
Definition: GUIAppEnum.h:472
@ MID_SHOW_ROUTE_NOLOOPS
Show vehicle's future route (without loops)
Definition: GUIAppEnum.h:455
@ MID_HIDE_ROUTE_NOLOOPS
Hide vehicle's future route (without loops)
Definition: GUIAppEnum.h:457
@ MID_TOGGLE_STOP
toggle stop state of a vehice or person
Definition: GUIAppEnum.h:477
@ MID_HIDE_LFLINKITEMS
Definition: GUIAppEnum.h:473
@ MID_REMOVE_OBJECT
remove a vehice or person
Definition: GUIAppEnum.h:479
@ MID_SHOW_FUTUREROUTE
Show vehicle's future route.
Definition: GUIAppEnum.h:451
@ MID_HIDE_FUTUREROUTE
Hide vehicle's future route.
Definition: GUIAppEnum.h:453
@ MID_SHOW_CURRENTROUTE
Show vehicle's current route.
Definition: GUIAppEnum.h:447
@ MID_STOP_TRACK
Stop to track a vehicle.
Definition: GUIAppEnum.h:469
@ MID_SELECT_TRANSPORTED
select transportables of a vehicle
Definition: GUIAppEnum.h:475
FXDEFMAP(GUIBaseVehicle::GUIBaseVehiclePopupMenu) GUIBaseVehiclePopupMenuMap[]
@ GLO_VEHICLE
a vehicle
GUISelectedStorage gSelected
A global holder of selected objects.
#define RAD2DEG(x)
Definition: GeomHelper.h:36
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:280
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define SIMSTEP
Definition: SUMOTime.h:59
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
long long int SUMOTime
Definition: SUMOTime.h:32
const int VTYPEPARS_COLOR_SET
@ RAIL_CARGO
render as a cargo train
@ EMERGENCY
render as an emergency vehicle
@ RAIL
render as a rail
@ SCOOTER
render as a scooter
@ RAIL_CAR
render as a (city) rail without locomotive
@ SHIP
render as a arbitrary ship
@ BICYCLE
render as a bicycle
@ MOTORCYCLE
render as a motorcycle
@ ANT
render as a giant ant
@ FIREBRIGADE
render as a fire brigade
@ MOPED
render as a moped
@ POLICE
render as a police car
@ PEDESTRIAN
render as a pedestrian
const int VEHPARS_COLOR_SET
T MIN2(T a, T b)
Definition: StdDefs.h:74
T MAX2(T a, T b)
Definition: StdDefs.h:80
const double SUMO_const_waitingContainerWidth
Definition: StdDefs.h:57
const double SUMO_const_waitingPersonWidth
Definition: StdDefs.h:55
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:269
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
Position getCenter() const
Returns the center of the boundary.
Definition: Boundary.cpp:111
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
double ymin() const
Returns minimum y-coordinate.
Definition: Boundary.cpp:129
double xmin() const
Returns minimum x-coordinate.
Definition: Boundary.cpp:117
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
double ymax() const
Returns maximum y-coordinate.
Definition: Boundary.cpp:135
double xmax() const
Returns maximum x-coordinate.
Definition: Boundary.cpp:123
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:431
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void drawOutlineCircle(double width, double iwidth, int steps=8)
Draws an unfilled circle around (0,0)
Definition: GLHelper.cpp:455
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void drawBoxLines(const PositionVector &geom, const std::vector< double > &rots, const std::vector< double > &lengths, double width, int cornerDetail=0, double offset=0)
Draws thick lines.
Definition: GLHelper.cpp:277
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
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, const int align=0, double width=-1)
Definition: GLHelper.cpp:609
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:640
long onCmdHideFutureRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be hidden.
long onCmdStartTrack(FXObject *, FXSelector, void *)
Called if the vehicle shall be tracked.
long onCmdHideBestLanes(FXObject *, FXSelector, void *)
Called if the vehicle's best lanes shall be hidden.
long onCmdHideCurrentRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be hidden.
long onCmdShowBestLanes(FXObject *, FXSelector, void *)
Called if the vehicle's best lanes shall be shown.
long onCmdShowRouteNoLoops(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be shown.
long onCmdShowLFLinkItems(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be shown.
long onCmdShowFoes(FXObject *, FXSelector, void *)
Called to show (select) a vehicles foes.
long onCmdHideRouteNoLoops(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be hidden.
long onCmdShowFutureRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be shown.
long onCmdShowAllRoutes(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be shown.
long onCmdToggleStop(FXObject *, FXSelector, void *)
Called when toggling stop state.
long onCmdStopTrack(FXObject *, FXSelector, void *)
Called if the current shall not be tracked any longer.
long onCmdSelectTransported(FXObject *, FXSelector, void *)
Called to select all riding persons and continers.
long onCmdRemoveObject(FXObject *, FXSelector, void *)
Called when removing the vehicle.
long onCmdHideAllRoutes(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be hidden.
long onCmdHideLFLinkItems(FXObject *, FXSelector, void *)
Called if all routes of the vehicle shall be hidden.
long onCmdShowCurrentRoute(FXObject *, FXSelector, void *)
Called if the current route of the vehicle shall be shown.
static void drawAction_drawVehicleAsCircle(const double width, const double length, double detail)
draw vehicle as a circle
static void drawAction_drawVehicleAsPoly(const GUIVisualizationSettings &s, const SUMOVehicleShape shape, const double width, const double length, int carriageIndex=-1)
draw vehicle as a polygon
static void drawAction_drawVehicleAsTrianglePlus(const double width, const double length)
draw vehicle as a triangle
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
static void drawAction_drawVehicleAsBoxPlus(const double width, const double length)
draw vehicle as a Box
A MSVehicle extended by some values for usage within the gui.
void drawParkingInfo(const GUIVisualizationSettings &s, const RGBColor &col) const
const Seat & getContainerPosition(int containerIndex) const
static bool setFunctionalColor(int activeScheme, const MSBaseVehicle *veh, RGBColor &col)
sets the color according to the current scheme index and some vehicle function
const std::string getOptionalName() const
Returns the value for generic parameter 'name' or ''.
virtual void drawAction_drawLinkItems(const GUIVisualizationSettings &) const
const Seat & getSeatPosition(int personIndex) const
returns the seat position for the person with the given index
RGBColor setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
int getNumContainers() const
return the number of passengers
void drawOnPos(const GUIVisualizationSettings &s, const Position &pos, const double angle) const
Draws the object on the specified position with the specified angle.
GUIGLObjectPopupMenu * myPopup
current popup (to clean up in destructor). GUIBaseVehicle is not responsible for removal
GUIBaseVehicle(MSBaseVehicle &vehicle)
const MSBaseVehicle & getVehicle()
MSDevice_Vehroutes * myRoutes
virtual void drawAction_drawPersonsAndContainers(const GUIVisualizationSettings &s) const
bool hasActiveAddVisualisation(GUISUMOAbstractView *const parent, int which) const
Returns whether the named feature is enabled in the given view.
void removeActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
void drawRoute(const GUIVisualizationSettings &s, int routeNo, double darken, bool future=false, bool noLoop=false) const
Chooses the route to draw and draws it, darkening it as given.
std::vector< Seat > Seats
MSBaseVehicle & myVehicle
The vehicle to which all calls should be delegated.
virtual void drawAction_drawVehicleBlinker(double) const
void removedPopupMenu()
notify object about popup menu removal
void addActiveAddVisualisation(GUISUMOAbstractView *const parent, int which)
Adds the named visualisation feature to the given view.
static void drawLinkItem(const Position &pos, SUMOTime arrivalTime, SUMOTime leaveTime, double exagerate)
double getScaleValue(const GUIVisualizationSettings &s, int activeScheme) const
gets the size multiplier value according to the current scheme index
virtual void drawBestLanes() const
Draws the vehicle's best lanes.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void computeSeats(const Position &front, const Position &back, double seatOffset, int maxSeats, double exaggeration, int &requiredSeats, Seats &into) const
add seats to mySeatPositions and update requiredSeats
virtual Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
@ VO_SHOW_LFLINKITEMS
LFLinkItems.
@ VO_SHOW_ALL_ROUTES
show all vehicle's routes
@ VO_SHOW_ROUTE_NOLOOP
show vehicle's routes without loops
@ VO_SHOW_FUTURE_ROUTE
show vehicle's current continued from the current position
@ VO_SHOW_ROUTE
show vehicle's current route
@ VO_SHOW_BEST_LANES
show vehicle's best lanes
virtual void drawAction_drawCarriageClass(const GUIVisualizationSettings &s, bool asImage) const =0
draws the given guiShape with distinct carriages/modules
virtual void drawGLAdditional(GUISUMOAbstractView *const parent, const GUIVisualizationSettings &s) const
Draws additionally triggered visualisations.
Seats myContainerPositions
virtual double getAngle() const =0
Returns the vehicle's direction in radians.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
FXMutex myLock
The mutex used to avoid concurrent updates of the vehicle buffer.
virtual void drawAction_drawVehicleBrakeLight(double length, bool onlyOne=false) const
virtual double getColorValue(const GUIVisualizationSettings &s, int activeScheme) const =0
gets the color value according to the current scheme index
int getNumPassengers() const
return the number of passengers
bool drawAction_drawVehicleAsPolyWithCarriagges(const GUIVisualizationSettings &s, double scaledLength, bool asImage=false) const
draw vehicle body and return whether carriages are being drawn
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
~GUIBaseVehicle()
destructor
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
virtual void drawAction_drawVehicleBlueLight() const
virtual void drawRouteHelper(const GUIVisualizationSettings &s, const MSRoute &r, bool future, bool noLoop, const RGBColor &col) const =0
Draws the route.
std::map< GUISUMOAbstractView *, int > myAdditionalVisualizations
Enabled visualisations, per view.
virtual void selectBlockingFoes() const =0
adds the blocking foes to the current selection
void drawStopLabels(const GUIVisualizationSettings &s, bool noLoop, const RGBColor &col) const
Seats mySeatPositions
positions of seats in the vehicle (updated at every drawing step)
std::string getDeviceDescription()
lists equipped device (types) for the current vehicle
const MSVehicleType & getVType() const
A shortcut to myVehicle.myType.
void setPositionInVehicle(const GUIBaseVehicle::Seat &pos)
Definition: GUIContainer.h:113
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:42
The popup menu of a globject.
GUISUMOAbstractView * getParentView()
return the real owner of this popup
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
void buildShowTypeParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the type parameter window.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void buildSelectionPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to (de)select the object.
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
A MSNet extended by some values for usage within the gui.
Definition: GUINet.h:81
A lane area vehicles can halt at (gui-version)
const Position & getSignPos() const
void setPositionInVehicle(const GUIBaseVehicle::Seat &pos)
Definition: GUIPerson.cpp:382
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
Definition: GUIPerson.cpp:283
const T getColor(const double value) const
bool removeAdditionalGLVisualisation(GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
void destroyPopup()
destoys the popup
bool addAdditionalGLVisualisation(GUIGlObject *const which)
Adds an object to call its additional visualisation method.
virtual GUIGlID getTrackedID() const
get tracked id
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
Stores the information about how to visualize structures.
GUIVisualizationTextSettings vehicleName
GUIVisualizationSizeSettings vehicleSize
bool showBlinker
Information whether vehicle blinkers shall be drawn.
GUIColorer vehicleColorer
The vehicle colorer.
GUIVisualizationTextSettings vehicleScaleValue
std::string vehicleScaleParam
key for scaling by vehicle parameter
bool showParkingInfo
Set whether parking related information should be shown.
GUIVisualizationTextSettings vehicleValue
int vehicleQuality
The quality of vehicle drawing.
std::string vehicleTextParam
key for rendering vehicle textual parameter
bool scaleLength
Whether vehicle length shall be scaled with length/geometry factor.
GUIScaler vehicleScaler
The size scaling settings for vehicles.
double scale
information about a lane's width (temporary, used for a single view)
bool drawMinGap
Information whether the minimum gap shall be drawn.
GUIVisualizationTextSettings vehicleText
bool showBTRange
Information whether the communication range shall be drawn.
bool drawBrakeGap
Information whether the brake gap shall be drawn.
bool drawLaneChangePreference
Information whether the lane change preference shall be drawn.
double angle
The current view rotation angle.
static double naviDegree(const double angle)
Definition: GeomHelper.cpp:192
void vaporizeCar(MEVehicle *v, MSMoveReminder::Notification reason)
remove the given car and clean up the relevant data structures
Definition: MELoop.cpp:240
A vehicle from the mesoscopic point of view.
Definition: MEVehicle.h:42
The base class for microscopic and mesoscopic vehicles.
Definition: MSBaseVehicle.h:51
MSVehicleDevice * getDevice(const std::type_info &type) const
Returns a device of the given type if it exists or 0.
virtual bool isSelected() const
whether this vehicle is selected in the GUI
const MSDevice_Transportable * getPersonDevice() const
const std::vector< MSTransportable * > & getPersons() const
retrieve riding persons
std::map< const MSParkingArea *, PaMemory, ComparatorIdLess > ParkingMemory
virtual double getStopDelay() const
Returns the estimated public transport stop (departure) delay in seconds.
MoveReminderCont myMoveReminders
Currently relevant move reminders.
const std::list< MSStop > & getStops() const
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
int getNumberParkingReroutes() const
std::vector< MSVehicleDevice * > myDevices
The devices this vehicle has.
virtual double getTimeLossSeconds() const
Returns the time loss in seconds.
bool isParking() const
Returns whether the vehicle is parking.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
const MSDevice_Transportable * getContainerDevice() const
MSDevice_Transportable * myContainerDevice
The containers this vehicle may have.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
const MSRouteIterator & getCurrentRouteEdge() const
Returns an iterator pointing to the current edge in this vehicles route.
MSDevice_Transportable * myPersonDevice
The passengers this vehicle may have.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
const ParkingMemory * getParkingMemory() const
std::string getPrefixedParameter(const std::string &key, std::string &error) const
retrieve parameters of devices, models and the vehicle itself
virtual double getStopArrivalDelay() const
Returns the estimated public transport stop arrival delay in seconds.
bool isStoppedTriggered() const
Returns whether the vehicle is on a triggered stop.
const std::vector< MSVehicleDevice * > & getDevices() const
Returns this vehicle's devices.
virtual double getAcceleration() const
Returns the vehicle's acceleration.
SUMOTime getDepartDelay() const
Returns the depart delay.
int getNumberReroutes() const
Returns the number of new routes this vehicle got.
virtual bool isOnRoad() const
Returns the information whether the vehicle is on a road (is simulated)
const std::vector< MSTransportable * > & getContainers() const
retrieve riding containers
const MSRoute & getRoute() const
Returns the current route.
bool isStopped() const
Returns whether the vehicle is at a stop.
virtual double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
Definition: MSCFModel.h:334
static double getRange()
Returns the configured range.
const std::vector< MSTransportable * > & getTransportables() const
Returns the list of transportables using this vehicle.
int size() const
Return the number of passengers / containers.
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.
const MSRoute * getRoute(int index) const
Called on route retrieval.
Abstract in-vehicle / in-person device.
Definition: MSDevice.h:61
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:168
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the maximum speed the vehicle may use on this edge.
Definition: MSEdge.cpp:1002
static bool gUseMesoSim
Definition: MSGlobals.h:94
static MELoop * gMesoNet
mesoscopic simulation infrastructure
Definition: MSGlobals.h:100
static bool gLefthand
Whether lefthand-drive is being simulated.
Definition: MSGlobals.h:157
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
virtual MSVehicle * removeVehicle(MSVehicle *remVehicle, MSMoveReminder::Notification notification, bool notify=true)
Definition: MSLane.cpp:2282
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
Definition: MSLane.h:519
double getLengthGeometryFactor() const
return shape.length() / myLength
Definition: MSLane.h:483
@ NOTIFICATION_VAPORIZED_GUI
The vehicle got removed via the GUI.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:376
const RGBColor & getColor() const
Returns the color.
Definition: MSRoute.cpp:380
const ConstMSEdgeVector & getEdges() const
Definition: MSRoute.h:120
Definition: MSStop.h:44
void scheduleVehicleRemoval(SUMOVehicle *veh, bool checkDuplicate=false)
Removes a vehicle after it has ended.
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:75
double getTimeGapOnLane() const
Returns the time gap in seconds to the leader of the vehicle on the same lane.
Definition: MSVehicle.cpp:5769
PositionVector getBoundingPoly(double offset=0) const
get bounding polygon
Definition: MSVehicle.cpp:6166
double getAccumulatedWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s) within the last millisecs.
Definition: MSVehicle.h:662
MSAbstractLaneChangeModel & getLaneChangeModel()
Definition: MSVehicle.cpp:5051
MSLane * getMutableLane() const
Returns the lane the vehicle is on Non const version indicates that something volatile is going on.
Definition: MSVehicle.h:560
bool addTraciStop(SUMOVehicleParameter::Stop stop, std::string &errorMsg)
Definition: MSVehicle.cpp:6291
PositionVector getBoundingBox(double offset=0) const
get bounding rectangle
Definition: MSVehicle.cpp:6135
void onRemovalFromNet(const MSMoveReminder::Notification reason)
Called when the vehicle is removed from the network.
Definition: MSVehicle.cpp:978
bool resumeFromStopping()
Definition: MSVehicle.cpp:6329
int getBestLaneOffset() const
Definition: MSVehicle.cpp:5668
std::pair< const MSLane *, double > getLanePosAfterDist(double distance) const
return lane and position along bestlanes at the given distance
Definition: MSVehicle.cpp:5693
double getSpeed() const
Returns the vehicle's current speed.
Definition: MSVehicle.h:462
const MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:552
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
Definition: MSVehicle.h:917
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
double getMinGap() const
Get the free space in front of vehicles of this class.
const RGBColor & getColor() const
Returns this type's color.
double getFrontSeatPos() const
Get offset of first seat from vehicle front.
double getLength() const
Get vehicle's length [m].
SUMOVehicleShape getGuiShape() const
Get this vehicle type's shape.
bool wasSet(int what) const
Returns whether the given parameter was set.
Definition: MSVehicleType.h:79
const std::string & getID() const
Returns the id.
Definition: Named.h:74
virtual const std::string getParameter(const std::string &key, const std::string defaultValue="") const
Returns the value for a given key.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:252
double distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
Definition: Position.h:242
double x() const
Returns the x-position.
Definition: Position.h:55
double angleTo2D(const Position &other) const
returns the angle in the plane of the vector pointing from here to the other position
Definition: Position.h:262
double y() const
Returns the y-position.
Definition: Position.h:60
A list of positions.
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
static const RGBColor WHITE
Definition: RGBColor.h:192
static const RGBColor BLUE
Definition: RGBColor.h:187
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.cpp:92
RGBColor multiply(double factor) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:227
static const RGBColor GREEN
Definition: RGBColor.h:186
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb, inspired by http://alvyray.com/Papers/CG/hsv2rgb....
Definition: RGBColor.cpp:368
static const RGBColor BLACK
Definition: RGBColor.h:193
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:197
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
Definition: RGBColor.h:199
static const RGBColor RED
named colors
Definition: RGBColor.h:185
virtual double getSpeed() const =0
Returns the object's current speed.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
virtual double getAngle() const =0
Get the vehicle's angle.
Definition of vehicle stop (position and duration)
std::string lane
The lane to stop at.
double startPos
The stopping position start.
double endPos
The stopping position end.
SUMOTime duration
The stopping duration.
RGBColor color
The vehicle's color, TraCI may change this.
bool wasSet(int what) const
Returns whether the given parameter was set.
std::string line
The vehicle's line (mainly for public transport)
static const int NEWLINE
identifier for splitting the given string at all newline characters
std::vector< std::string > getVector()
return vector of strings
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static bool toBool(const std::string &sData)
converts a string into the bool value described by it by calling the char-type converter
#define M_PI
Definition: odrSpiral.cpp:40
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool constantSizeSelected
whether only selected objects shall be drawn with constant
bool show(const GUIGlObject *o) const
whether to show the text
double scaledSize(double scale, double constFactor=0.1) const
get scale size