SUMO - Simulation of Urban MObility
GNECalibratorFlow.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 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
26 
27 #include "GNECalibratorFlow.h"
28 
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
34 
36  GNEAdditional(calibratorParent, calibratorParent->getViewNet(), GLO_CALIBRATOR, SUMO_TAG_FLOW, "", false),
37  myVehicleType(calibratorParent->getViewNet()->getNet()->retrieveAdditional(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)),
38  myRoute(calibratorParent->getViewNet()->getNet()->getAdditionalByType(SUMO_TAG_ROUTE).begin()->second) {
39  // fill calibrator flows with default values
41 }
42 
43 
44 GNECalibratorFlow::GNECalibratorFlow(GNEAdditional* calibratorParent, GNEAdditional* vehicleType, GNEAdditional* route, const std::string& vehsPerHour, const std::string& speed,
45  const RGBColor& color, const std::string& departLane, const std::string& departPos, const std::string& departSpeed, const std::string& arrivalLane,
46  const std::string& arrivalPos, const std::string& arrivalSpeed, const std::string& line, int personNumber, int containerNumber, bool reroute,
47  const std::string& departPosLat, const std::string& arrivalPosLat, double begin, double end) :
48  GNEAdditional(calibratorParent, calibratorParent->getViewNet(), GLO_CALIBRATOR, SUMO_TAG_FLOW, "", false),
49  myVehicleType(vehicleType),
50  myRoute(route),
51  myVehsPerHour(vehsPerHour),
52  mySpeed(speed),
53  myColor(color),
54  myDepartLane(departLane),
55  myDepartPos(departPos),
56  myDepartSpeed(departSpeed),
57  myArrivalLane(arrivalLane),
58  myArrivalPos(arrivalPos),
59  myArrivalSpeed(arrivalSpeed),
60  myLine(line),
61  myPersonNumber(personNumber),
62  myContainerNumber(containerNumber),
63  myReroute(reroute),
64  myDepartPosLat(departPosLat),
65  myArrivalPosLat(arrivalPosLat),
66  myBegin(begin),
67  myEnd(end) {
68 }
69 
70 
72 
73 
74 void
76  // This additional cannot be moved
77 }
78 
79 
80 void
82  // This additional cannot be moved
83 }
84 
85 
86 void
87 GNECalibratorFlow::updateGeometry(bool /*updateGrid*/) {
88  // Currently this additional doesn't own a Geometry
89 }
90 
91 
95 }
96 
97 
98 std::string
100  return myFirstAdditionalParent->getID();
101 }
102 
103 
104 void
106  // Currently This additional isn't drawn
107 }
108 
109 
110 std::string
112  switch (key) {
113  case SUMO_ATTR_ID:
114  return getAdditionalID();
115  case SUMO_ATTR_TYPE:
116  return myVehicleType->getID();
117  case SUMO_ATTR_ROUTE:
118  return myRoute->getID();
120  return toString(myVehsPerHour);
121  case SUMO_ATTR_SPEED:
122  return toString(mySpeed);
123  case SUMO_ATTR_COLOR:
124  return toString(myColor);
125  case SUMO_ATTR_BEGIN:
126  return toString(myBegin);
127  case SUMO_ATTR_END:
128  return toString(myEnd);
130  return myDepartLane;
131  case SUMO_ATTR_DEPARTPOS:
132  return myDepartPos;
134  return myDepartSpeed;
136  return myArrivalLane;
138  return myArrivalPos;
140  return myArrivalSpeed;
141  case SUMO_ATTR_LINE:
142  return myLine;
144  return toString(myPersonNumber);
146  return toString(myContainerNumber);
147  case SUMO_ATTR_REROUTE:
148  return toString(myReroute);
150  return myDepartPosLat;
152  return myArrivalPosLat;
153  case GNE_ATTR_PARENT:
154  return myFirstAdditionalParent->getID();
155  case GNE_ATTR_GENERIC:
156  return getGenericParametersStr();
157  default:
158  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
159  }
160 }
161 
162 
163 void
164 GNECalibratorFlow::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
165  if (value == getAttribute(key)) {
166  return; //avoid needless changes, later logic relies on the fact that attributes have changed
167  }
168  switch (key) {
169  case SUMO_ATTR_ID:
170  case SUMO_ATTR_TYPE:
171  case SUMO_ATTR_ROUTE:
172  case SUMO_ATTR_COLOR:
174  case SUMO_ATTR_SPEED:
175  case SUMO_ATTR_BEGIN:
176  case SUMO_ATTR_END:
178  case SUMO_ATTR_DEPARTPOS:
183  case SUMO_ATTR_LINE:
186  case SUMO_ATTR_REROUTE:
189  case GNE_ATTR_GENERIC:
190  undoList->p_add(new GNEChange_Attribute(this, key, value));
191  break;
192  default:
193  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
194  }
195 }
196 
197 
198 bool
199 GNECalibratorFlow::isValid(SumoXMLAttr key, const std::string& value) {
200  switch (key) {
201  case SUMO_ATTR_ID:
202  return isValidAdditionalID(value);
203  case SUMO_ATTR_TYPE:
204  return SUMOXMLDefinitions::isValidTypeID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_VTYPE, value, false) != nullptr);
205  case SUMO_ATTR_ROUTE:
206  return SUMOXMLDefinitions::isValidVehicleID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_ROUTE, value, false) != nullptr);
208  if (value.empty()) {
209  // speed and vehsPerHour cannot be empty at the same time
210  if (mySpeed.empty()) {
211  return false;
212  } else {
213  return true;
214  }
215  } else if (canParse<double>(value)) {
216  return (parse<double>(value) >= 0);
217  } else {
218  return false;
219  }
220  case SUMO_ATTR_SPEED:
221  if (value.empty()) {
222  // speed and vehsPerHour cannot be empty at the same time
223  if (myVehsPerHour.empty()) {
224  return false;
225  } else {
226  return true;
227  }
228  } else if (canParse<double>(value)) {
229  return (parse<double>(value) >= 0);
230  } else {
231  return false;
232  }
233  case SUMO_ATTR_COLOR:
234  return canParse<RGBColor>(value);
235  case SUMO_ATTR_BEGIN:
236  return canParse<double>(value) && (parse<double>(value) >= 0);
237  case SUMO_ATTR_END:
238  return canParse<double>(value) && (parse<double>(value) >= 0);
240  if ((value == "random") || (value == "free") || (value == "allowed") || (value == "best") || (value == "first")) {
241  return true;
242  } else {
243  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
244  }
245  case SUMO_ATTR_DEPARTPOS:
246  if ((value == "random") || (value == "free") || (value == "random_free") || (value == "base") || (value == "last")) {
247  return true;
248  } else {
249  return canParse<double>(value);
250  }
252  if ((value == "random") || (value == "max")) {
253  return true;
254  } else {
255  return canParse<double>(value);
256  }
258  if (value == "current") {
259  return true;
260  } else {
261  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
262  }
264  if ((value == "random") || (value == "max")) {
265  return true;
266  } else {
267  return canParse<double>(value);
268  }
270  if (value == "current") {
271  return true;
272  } else {
273  return canParse<double>(value);
274  }
275  case SUMO_ATTR_LINE:
276  return true;
278  return canParse<int>(value) && parse<int>(value) >= 0;
280  return canParse<int>(value) && parse<int>(value) >= 0;
281  case SUMO_ATTR_REROUTE:
282  return canParse<bool>(value);
287  case GNE_ATTR_GENERIC:
288  return isGenericParametersValid(value);
289  default:
290  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
291  }
292 }
293 
294 
295 std::string
297  return getTagStr();
298 }
299 
300 
301 std::string
303  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
304 }
305 
306 // ===========================================================================
307 // private
308 // ===========================================================================
309 
310 void
311 GNECalibratorFlow::setAttribute(SumoXMLAttr key, const std::string& value) {
312  switch (key) {
313  case SUMO_ATTR_ID:
314  changeAdditionalID(value);
315  break;
316  case SUMO_ATTR_TYPE:
318  break;
319  case SUMO_ATTR_ROUTE:
321  break;
323  myVehsPerHour = value;
324  break;
325  case SUMO_ATTR_SPEED:
326  mySpeed = value;
327  break;
328  case SUMO_ATTR_COLOR:
329  myColor = parse<RGBColor>(value);
330  break;
331  case SUMO_ATTR_BEGIN:
332  myBegin = parse<double>(value);
333  break;
334  case SUMO_ATTR_END:
335  myEnd = parse<double>(value);
336  break;
338  myDepartLane = value;
339  break;
340  case SUMO_ATTR_DEPARTPOS:
341  myDepartPos = value;
342  break;
344  myDepartSpeed = value;
345  break;
347  myArrivalLane = value;
348  break;
350  myArrivalPos = value;
351  break;
353  myArrivalSpeed = value;
354  break;
355  case SUMO_ATTR_LINE:
356  myLine = value;
357  break;
359  myPersonNumber = parse<int>(value);
360  break;
362  myContainerNumber = parse<int>(value);
363  break;
364  case SUMO_ATTR_REROUTE:
365  myReroute = parse<bool>(value);
366  break;
368  myDepartPosLat = value;
369  break;
371  myArrivalPosLat = value;
372  break;
373  case GNE_ATTR_GENERIC:
375  break;
376  default:
377  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
378  }
379 }
380 
381 /****************************************************************************/
Position getPositionInView() const
Returns position of additional in view.
RGBColor myColor
color of flow
description of a vehicle type
GNECalibratorFlow(GNEAdditional *calibratorParent)
default constructor (used only in GNECalibratorDialog)
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
a flow definition (used by router)
const std::string & getAdditionalID() const
returns Additional ID
~GNECalibratorFlow()
destructor
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string myLine
line of bus/container stop
Stores the information about how to visualize structures.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNEAdditional * myRoute
route in which this flow is used
std::string myDepartPosLat
departPosLat
weights: time range begin
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
const std::string DEFAULT_VTYPE_ID
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
bool myReroute
reroute
begin/end of the description of a route
std::string myArrivalPos
arrival pos
double myEnd
time step end
std::string getParentName() const
Returns the name of the parent object.
std::string myArrivalPosLat
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
int myPersonNumber
number of person
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1785
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
std::string myDepartPos
depart position
void updateGeometry(bool updateGrid)
update pre-computed geometry information
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
std::string myDepartLane
depart lane
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
std::string myArrivalLane
arrival lane
friend class GNEChange_Attribute
declare friend class
const std::string getID() const
function to support debugging
std::string mySpeed
flow speed (String instead float because can be empty)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
int myContainerNumber
number of container
a Calibrator
GNEAdditional * myVehicleType
type of flow
static StringBijection< LateralAlignment > LateralAlignments
lateral alignments
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
std::string myArrivalSpeed
arrival speed
const std::string & getTagStr() const
get tag assigned to this object in string format
weights: time range end
std::string myDepartSpeed
depart speed
std::string getGenericParametersStr() const
return generic parameters in string format
std::string myVehsPerHour
flows per hour (String instead float because can be empty)
GNENet * getNet() const
get the net object
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
static bool isValidTypeID(const std::string &value)
whether the given string is a valid id for an edge or vehicle type
bool hasString(const std::string &str) const
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1059
A color information.
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
GNEAdditional * myFirstAdditionalParent
pointer to first Additional parent
virtual Position getPositionInView() const =0
Returns position of additional in view.