SUMO - Simulation of Urban MObility
GNECalibratorVehicleType.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
29 #include <utils/common/ToString.h>
30 #include <utils/geom/GeomHelper.h>
35 #include <utils/gui/div/GLHelper.h>
39 
41 #include "GNECalibrator.h"
43 #include <netedit/GNEViewNet.h>
44 #include <netedit/GNENet.h>
45 #include <netedit/GNEUndoList.h>
47 
48 
49 // ===========================================================================
50 // member method definitions
51 // ===========================================================================
52 
54  GNEAdditional(viewNet->getNet()->generateAdditionalID(SUMO_TAG_VTYPE), viewNet, GLO_CALIBRATOR, SUMO_TAG_VTYPE, "", false) {
55  // fill calibrator vehicle type with default values
57 }
58 
59 
61  GNEAdditional(id, viewNet, GLO_CALIBRATOR, SUMO_TAG_VTYPE, "", false) {
62  // fill calibrator vehicle type with default values
64 }
65 
66 
68  double accel, double decel, double sigma, double tau, double length, double minGap, double maxSpeed,
69  double speedFactor, double speedDev, const RGBColor& color, SUMOVehicleClass vClass, const std::string& emissionClass,
70  SUMOVehicleShape shape, double width, const std::string& filename, double impatience, const std::string& laneChangeModel,
71  const std::string& carFollowModel, int personCapacity, int containerCapacity, double boardingDuration,
72  double loadingDuration, const std::string& latAlignment, double minGapLat, double maxSpeedLat) :
73  GNEAdditional(vehicleTypeID, viewNet, GLO_CALIBRATOR, SUMO_TAG_VTYPE, "", false),
74  myAccel(accel),
75  myDecel(decel),
76  mySigma(sigma),
77  myTau(tau),
78  myLength(length),
79  myMinGap(minGap),
80  myMaxSpeed(maxSpeed),
81  mySpeedFactor(speedFactor),
82  mySpeedDev(speedDev),
83  myColor(color),
84  myVClass(vClass),
85  myEmissionClass(emissionClass),
86  myShape(shape),
87  myWidth(width),
88  myFilename(filename),
89  myImpatience(impatience),
90  myLaneChangeModel(laneChangeModel),
91  myCarFollowModel(carFollowModel),
92  myPersonCapacity(personCapacity),
93  myContainerCapacity(containerCapacity),
94  myBoardingDuration(boardingDuration),
95  myLoadingDuration(loadingDuration),
96  myLatAlignment(latAlignment),
97  myMinGapLat(minGapLat),
98  myMaxSpeedLat(maxSpeedLat) {
99 }
100 
101 
103 
104 
105 void
107  // This additional cannot be moved
108 }
109 
110 
111 void
113  // This additional cannot be moved
114 }
115 
116 
117 void
119  // Currently this additional doesn't own a Geometry
120 }
121 
122 
123 Position
125  return Position();
126 }
127 
128 
129 std::string
131  return myViewNet->getNet()->getMicrosimID();
132 }
133 
134 
135 void
137  // Currently This additional isn't drawn
138 }
139 
140 
141 std::string
143  switch (key) {
144  case SUMO_ATTR_ID:
145  return getAdditionalID();
146  case SUMO_ATTR_ACCEL:
147  return toString(myAccel);
148  case SUMO_ATTR_DECEL:
149  return toString(myDecel);
150  case SUMO_ATTR_SIGMA:
151  return toString(mySigma);
152  case SUMO_ATTR_TAU:
153  return toString(myTau);
154  case SUMO_ATTR_LENGTH:
155  return toString(myLength);
156  case SUMO_ATTR_MINGAP:
157  return toString(myMinGap);
158  case SUMO_ATTR_MAXSPEED:
159  return toString(myMaxSpeed);
161  return toString(mySpeedFactor);
162  case SUMO_ATTR_SPEEDDEV:
163  return toString(mySpeedDev);
164  case SUMO_ATTR_COLOR:
165  return toString(myColor);
166  case SUMO_ATTR_VCLASS:
167  return toString(myVClass);
169  return myEmissionClass;
170  case SUMO_ATTR_GUISHAPE:
172  case SUMO_ATTR_WIDTH:
173  return toString(myWidth);
174  case SUMO_ATTR_IMGFILE:
175  return myFilename;
177  return toString(myImpatience);
179  return myLaneChangeModel;
181  return myCarFollowModel;
183  return toString(myPersonCapacity);
189  return toString(myLoadingDuration);
191  return myLatAlignment;
193  return toString(myMinGapLat);
195  return toString(myMaxSpeedLat);
196  case GNE_ATTR_GENERIC:
197  return getGenericParametersStr();
198  default:
199  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
200  }
201 }
202 
203 
204 void
205 GNECalibratorVehicleType::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
206  if (value == getAttribute(key)) {
207  return; //avoid needless changes, later logic relies on the fact that attributes have changed
208  }
209  switch (key) {
210  case SUMO_ATTR_ID:
211  case SUMO_ATTR_ACCEL:
212  case SUMO_ATTR_DECEL:
213  case SUMO_ATTR_SIGMA:
214  case SUMO_ATTR_TAU:
215  case SUMO_ATTR_LENGTH:
216  case SUMO_ATTR_MINGAP:
217  case SUMO_ATTR_MAXSPEED:
219  case SUMO_ATTR_SPEEDDEV:
220  case SUMO_ATTR_COLOR:
221  case SUMO_ATTR_VCLASS:
223  case SUMO_ATTR_GUISHAPE:
224  case SUMO_ATTR_WIDTH:
225  case SUMO_ATTR_IMGFILE:
236  case GNE_ATTR_GENERIC:
237  undoList->p_add(new GNEChange_Attribute(this, key, value));
238  break;
239  default:
240  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
241  }
242 }
243 
244 
245 bool
246 GNECalibratorVehicleType::isValid(SumoXMLAttr key, const std::string& value) {
247  switch (key) {
248  case SUMO_ATTR_ID:
249  return isValidAdditionalID(value);
250  case SUMO_ATTR_ACCEL:
251  return canParse<double>(value);
252  case SUMO_ATTR_DECEL:
253  return canParse<double>(value);
254  case SUMO_ATTR_SIGMA:
255  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
256  case SUMO_ATTR_TAU:
257  return canParse<double>(value);
258  case SUMO_ATTR_LENGTH:
259  return canParse<double>(value) && (parse<double>(value) > 0);
260  case SUMO_ATTR_MINGAP:
261  return canParse<double>(value);
262  case SUMO_ATTR_MAXSPEED:
263  return canParse<double>(value);
265  return canParse<double>(value);
266  case SUMO_ATTR_SPEEDDEV:
267  return canParse<double>(value);
268  case SUMO_ATTR_COLOR:
269  return canParse<RGBColor>(value);
270  case SUMO_ATTR_VCLASS:
271  return canParseVehicleClasses(value);
273  if ((value == "zero") || (value == "LDV") || (value == "LDV_G_EU0") || (value == "LDV_G_EU1") || (value == "LDV_G_EU2") || (value == "LDV_G_EU3") || (value == "LDV_G_EU4") || (value == "LDV_G_EU5") ||
274  (value == "LDV_G_EU6") || (value == "LDV_G_East") || (value == "LDV_D_EU0") || (value == "LDV_D_EU1") || (value == "LDV_D_EU2") || (value == "LDV_D_EU3") || (value == "LDV_D_EU4") || (value == "LDV_D_EU5") || (value == "LDV_D_EU6") ||
275  (value == "PC") || (value == "PC_Alternative") || (value == "PC_G_EU0") || (value == "PC_G_EU1") || (value == "PC_G_EU2") || (value == "PC_G_EU3") || (value == "PC_G_EU4") || (value == "PC_G_EU5") || (value == "PC_G_EU6") || (value == "PC_G_East") ||
276  (value == "PC_D_EU0") || (value == "PC_D_EU1") || (value == "PC_D_EU2") || (value == "PC_D_EU3") || (value == "PC_D_EU4") || (value == "PC_D_EU5") || (value == "PC_D_EU6") || (value == "Bus") || (value == "Coach") || (value == "HDV") || (value == "HDV_G") ||
277  (value == "HDV_D_EU0") || (value == "HDV_D_EU1") || (value == "HDV_D_EU2") || (value == "HDV_D_EU3") || (value == "HDV_D_EU4") || (value == "HDV_D_EU5") || (value == "HDV_D_EU6") || (value == "HDV_D_East")) {
278  return true;
279  } else {
280  return false;
281  }
282  case SUMO_ATTR_GUISHAPE:
283  return canParseVehicleShape(value);
284  case SUMO_ATTR_WIDTH:
285  return canParse<double>(value);
286  case SUMO_ATTR_IMGFILE:
289  return canParse<double>(value);
295  return canParse<int>(value);
297  return canParse<int>(value);
299  return canParse<double>(value);
301  return canParse<double>(value);
305  return canParse<double>(value);
307  return canParse<double>(value);
308  case GNE_ATTR_GENERIC:
309  return isGenericParametersValid(value);
310  default:
311  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
312  }
313 }
314 
315 
316 std::string
318  return toString(getTag()) + ": " + getID();
319 }
320 
321 
322 std::string
324  return toString(getTag());
325 }
326 
327 // ===========================================================================
328 // private
329 // ===========================================================================
330 
331 void
332 GNECalibratorVehicleType::setAttribute(SumoXMLAttr key, const std::string& value) {
333  switch (key) {
334  case SUMO_ATTR_ID:
335  changeAdditionalID(value);
336  break;
337  case SUMO_ATTR_ACCEL:
338  myAccel = parse<double>(value);
339  break;
340  case SUMO_ATTR_DECEL:
341  myDecel = parse<double>(value);
342  break;
343  case SUMO_ATTR_SIGMA:
344  mySigma = parse<double>(value);
345  break;
346  case SUMO_ATTR_TAU:
347  myTau = parse<double>(value);
348  break;
349  case SUMO_ATTR_LENGTH:
350  myLength = parse<double>(value);
351  break;
352  case SUMO_ATTR_MINGAP:
353  myMinGap = parse<double>(value);
354  break;
355  case SUMO_ATTR_MAXSPEED:
356  myMaxSpeed = parse<double>(value);
357  break;
359  mySpeedFactor = parse<double>(value);
360  break;
361  case SUMO_ATTR_SPEEDDEV:
362  mySpeedDev = parse<double>(value);
363  break;
364  case SUMO_ATTR_COLOR:
365  myColor = parse<RGBColor>(value);
366  break;
367  case SUMO_ATTR_VCLASS:
368  myVClass = getVehicleClassID(value);
369  break;
371  myEmissionClass = value;
372  break;
373  case SUMO_ATTR_GUISHAPE:
374  myShape = getVehicleShapeID(value);
375  break;
376  case SUMO_ATTR_WIDTH:
377  myWidth = parse<double>(value);
378  break;
379  case SUMO_ATTR_IMGFILE:
380  myFilename = value;
381  break;
383  myImpatience = parse<double>(value);
384  break;
386  myLaneChangeModel = value;
387  break;
389  myCarFollowModel = value;
390  break;
392  myPersonCapacity = parse<int>(value);
393  break;
395  myContainerCapacity = parse<int>(value);
396  break;
398  myBoardingDuration = parse<double>(value);
399  break;
401  myLoadingDuration = parse<double>(value);
402  break;
404  myLatAlignment = value;
405  break;
407  myMinGapLat = parse<double>(value);
408  break;
410  myMaxSpeedLat = parse<double>(value);
411  break;
412  case GNE_ATTR_GENERIC:
414  break;
415  default:
416  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
417  }
418 }
419 
420 /****************************************************************************/
SUMOVehicleClass getVehicleClassID(const std::string &name)
Returns the class id of the abstract class given by its name.
double myTau
Car-following model parameter.
double myMinGap
Empty space after leader [m].
double myMaxSpeedLat
The maximum lateral speed when using the sublane-model.
static StringBijection< SumoXMLTag > CarFollowModels
car following models
description of a vehicle type
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Stores the information about how to visualize structures.
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
double myImpatience
Willingess of drivers to impede vehicles with higher priority. See below for semantics.
double myWidth
The vehicle&#39;s width [m] (only used for drawing)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double myAccel
The acceleration ability of vehicles of this type (in m/s^2)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
GNECalibratorVehicleType(GNEViewNet *viewNet)
constructor (Used only in GNECalibratorDialog)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
double myDecel
The deceleration ability of vehicles of this type (in m/s^2)
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
std::string myLatAlignment
The preferred lateral alignment when using the sublane-model. One of (left, right, center, compact, nice, arbitrary).
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
double myLength
The vehicle&#39;s netto-length (length) (in m)
std::string getVehicleShapeName(SUMOVehicleShape id)
Returns the class name of the shape class given by its id.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
bool canParseVehicleShape(const std::string &shape)
Checks whether the given string contains only known vehicle shape.
double mySigma
Car-following model parameter.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Position getPositionInView() const
Returns position of additional in view.
std::string myCarFollowModel
The model used for car following.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
RGBColor myColor
This vehicle type&#39;s color.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
int myPersonCapacity
The number of persons (excluding an autonomous driver) the vehicle can transport. ...
double mySpeedDev
The deviation of the speedFactor; see below for details.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
friend class GNEChange_Attribute
declare friend class
SUMOVehicleClass myVClass
An abstract vehicle class.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
SUMOVehicleShape myShape
How this vehicle is rendered.
std::string myEmissionClass
An abstract emission class.
std::string myFilename
Image file for rendering vehicles of this type (should be grayscale to allow functional coloring) ...
a Calibrator
bool canParseVehicleClasses(const std::string &classes)
Checks whether the given string contains only known vehicle classes.
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
double myBoardingDuration
The time required by a person to board the vehicle.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
double myLoadingDuration
The time required to load a container onto the vehicle.
SUMOVehicleShape getVehicleShapeID(const std::string &name)
Returns the class id of the shape class given by its name.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double myMinGapLat
The minimum lateral gap at a speed difference of 100km/h when using the sublane-model.
bool hasString(const std::string &str) const
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
A color information.
double myMaxSpeed
The vehicle&#39;s maximum velocity (in m/s)
static StringBijection< LaneChangeModel > LaneChangeModels
lane change models
double mySpeedFactor
The vehicles expected multiplicator for lane speed limits.
std::string myLaneChangeModel
The model used for changing lanes.
int myContainerCapacity
The number of containers the vehicle can transport.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
SumoXMLTag getTag() const
get XML Tag assigned to this object