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 #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 #include <netedit/GNEViewNet.h>
40 #include <netedit/GNENet.h>
43 #include <netedit/GNEUndoList.h>
44 
45 #include "GNECalibratorFlow.h"
47 #include "GNECalibratorRoute.h"
48 #include "GNECalibrator.h"
49 
50 
51 // ===========================================================================
52 // member method definitions
53 // ===========================================================================
54 
55 
57  GNEAdditional(calibratorParent, calibratorParent->getViewNet(), GLO_CALIBRATOR, SUMO_TAG_FLOW, "", false),
58  myVehicleType(calibratorParent->getViewNet()->getNet()->retrieveAdditional(SUMO_TAG_VTYPE, DEFAULT_VTYPE_ID)),
59  myRoute(calibratorParent->getViewNet()->getNet()->getAdditionalByType(SUMO_TAG_ROUTE).begin()->second) {
60  // fill calibrator flows with default values
62 }
63 
64 
65 GNECalibratorFlow::GNECalibratorFlow(GNEAdditional* calibratorParent, GNEAdditional* vehicleType, GNEAdditional* route, const std::string& vehsPerHour, const std::string& speed,
66  const RGBColor& color, const std::string& departLane, const std::string& departPos, const std::string& departSpeed, const std::string& arrivalLane,
67  const std::string& arrivalPos, const std::string& arrivalSpeed, const std::string& line, int personNumber, int containerNumber, bool reroute,
68  const std::string& departPosLat, const std::string& arrivalPosLat, double begin, double end) :
69  GNEAdditional(calibratorParent, calibratorParent->getViewNet(), GLO_CALIBRATOR, SUMO_TAG_FLOW, "", false),
70  myVehicleType(vehicleType),
71  myRoute(route),
72  myVehsPerHour(vehsPerHour),
73  mySpeed(speed),
74  myColor(color),
75  myDepartLane(departLane),
76  myDepartPos(departPos),
77  myDepartSpeed(departSpeed),
78  myArrivalLane(arrivalLane),
79  myArrivalPos(arrivalPos),
80  myArrivalSpeed(arrivalSpeed),
81  myLine(line),
82  myPersonNumber(personNumber),
83  myContainerNumber(containerNumber),
84  myReroute(reroute),
85  myDepartPosLat(departPosLat),
86  myArrivalPosLat(arrivalPosLat),
87  myBegin(begin),
88  myEnd(end) {
89 }
90 
91 
93 
94 
95 void
97  // This additional cannot be moved
98 }
99 
100 
101 void
103  // This additional cannot be moved
104 }
105 
106 
107 void
108 GNECalibratorFlow::updateGeometry(bool /*updateGrid*/) {
109  // Currently this additional doesn't own a Geometry
110 }
111 
112 
113 Position
116 }
117 
118 
119 std::string
121  return myFirstAdditionalParent->getID();
122 }
123 
124 
125 void
127  // Currently This additional isn't drawn
128 }
129 
130 
131 std::string
133  switch (key) {
134  case SUMO_ATTR_ID:
135  return getAdditionalID();
136  case SUMO_ATTR_TYPE:
137  return myVehicleType->getID();
138  case SUMO_ATTR_ROUTE:
139  return myRoute->getID();
141  return toString(myVehsPerHour);
142  case SUMO_ATTR_SPEED:
143  return toString(mySpeed);
144  case SUMO_ATTR_COLOR:
145  return toString(myColor);
146  case SUMO_ATTR_BEGIN:
147  return toString(myBegin);
148  case SUMO_ATTR_END:
149  return toString(myEnd);
151  return myDepartLane;
152  case SUMO_ATTR_DEPARTPOS:
153  return myDepartPos;
155  return myDepartSpeed;
157  return myArrivalLane;
159  return myArrivalPos;
161  return myArrivalSpeed;
162  case SUMO_ATTR_LINE:
163  return myLine;
165  return toString(myPersonNumber);
167  return toString(myContainerNumber);
168  case SUMO_ATTR_REROUTE:
169  return toString(myReroute);
171  return myDepartPosLat;
173  return myArrivalPosLat;
174  case GNE_ATTR_PARENT:
175  return myFirstAdditionalParent->getID();
176  case GNE_ATTR_GENERIC:
177  return getGenericParametersStr();
178  default:
179  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
180  }
181 }
182 
183 
184 void
185 GNECalibratorFlow::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
186  if (value == getAttribute(key)) {
187  return; //avoid needless changes, later logic relies on the fact that attributes have changed
188  }
189  switch (key) {
190  case SUMO_ATTR_ID:
191  case SUMO_ATTR_TYPE:
192  case SUMO_ATTR_ROUTE:
193  case SUMO_ATTR_COLOR:
195  case SUMO_ATTR_SPEED:
196  case SUMO_ATTR_BEGIN:
197  case SUMO_ATTR_END:
199  case SUMO_ATTR_DEPARTPOS:
204  case SUMO_ATTR_LINE:
207  case SUMO_ATTR_REROUTE:
210  case GNE_ATTR_GENERIC:
211  undoList->p_add(new GNEChange_Attribute(this, key, value));
212  break;
213  default:
214  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 bool
220 GNECalibratorFlow::isValid(SumoXMLAttr key, const std::string& value) {
221  switch (key) {
222  case SUMO_ATTR_ID:
223  return isValidAdditionalID(value);
224  case SUMO_ATTR_TYPE:
225  return SUMOXMLDefinitions::isValidTypeID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_VTYPE, value, false) != nullptr);
226  case SUMO_ATTR_ROUTE:
227  return SUMOXMLDefinitions::isValidVehicleID(value) && (myViewNet->getNet()->retrieveAdditional(SUMO_TAG_ROUTE, value, false) != nullptr);
229  if (value.empty()) {
230  // speed and vehsPerHour cannot be empty at the same time
231  if (mySpeed.empty()) {
232  return false;
233  } else {
234  return true;
235  }
236  } else if (canParse<double>(value)) {
237  return (parse<double>(value) >= 0);
238  } else {
239  return false;
240  }
241  case SUMO_ATTR_SPEED:
242  if (value.empty()) {
243  // speed and vehsPerHour cannot be empty at the same time
244  if (myVehsPerHour.empty()) {
245  return false;
246  } else {
247  return true;
248  }
249  } else if (canParse<double>(value)) {
250  return (parse<double>(value) >= 0);
251  } else {
252  return false;
253  }
254  case SUMO_ATTR_COLOR:
255  return canParse<RGBColor>(value);
256  case SUMO_ATTR_BEGIN:
257  return canParse<double>(value) && (parse<double>(value) >= 0);
258  case SUMO_ATTR_END:
259  return canParse<double>(value) && (parse<double>(value) >= 0);
261  if ((value == "random") || (value == "free") || (value == "allowed") || (value == "best") || (value == "first")) {
262  return true;
263  } else {
264  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
265  }
266  case SUMO_ATTR_DEPARTPOS:
267  if ((value == "random") || (value == "free") || (value == "random_free") || (value == "base") || (value == "last")) {
268  return true;
269  } else {
270  return canParse<double>(value);
271  }
273  if ((value == "random") || (value == "max")) {
274  return true;
275  } else {
276  return canParse<double>(value);
277  }
279  if (value == "current") {
280  return true;
281  } else {
282  return (myViewNet->getNet()->retrieveLane(value, false) != nullptr);
283  }
285  if ((value == "random") || (value == "max")) {
286  return true;
287  } else {
288  return canParse<double>(value);
289  }
291  if (value == "current") {
292  return true;
293  } else {
294  return canParse<double>(value);
295  }
296  case SUMO_ATTR_LINE:
297  return true;
299  return canParse<int>(value) && parse<int>(value) >= 0;
301  return canParse<int>(value) && parse<int>(value) >= 0;
302  case SUMO_ATTR_REROUTE:
303  return canParse<bool>(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());
319 }
320 
321 
322 std::string
324  return toString(getTag()) + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
325 }
326 
327 // ===========================================================================
328 // private
329 // ===========================================================================
330 
331 void
332 GNECalibratorFlow::setAttribute(SumoXMLAttr key, const std::string& value) {
333  switch (key) {
334  case SUMO_ATTR_ID:
335  changeAdditionalID(value);
336  break;
337  case SUMO_ATTR_TYPE:
339  break;
340  case SUMO_ATTR_ROUTE:
342  break;
344  myVehsPerHour = value;
345  break;
346  case SUMO_ATTR_SPEED:
347  mySpeed = value;
348  break;
349  case SUMO_ATTR_COLOR:
350  myColor = parse<RGBColor>(value);
351  break;
352  case SUMO_ATTR_BEGIN:
353  myBegin = parse<double>(value);
354  break;
355  case SUMO_ATTR_END:
356  myEnd = parse<double>(value);
357  break;
359  myDepartLane = value;
360  break;
361  case SUMO_ATTR_DEPARTPOS:
362  myDepartPos = value;
363  break;
365  myDepartSpeed = value;
366  break;
368  myArrivalLane = value;
369  break;
371  myArrivalPos = value;
372  break;
374  myArrivalSpeed = value;
375  break;
376  case SUMO_ATTR_LINE:
377  myLine = value;
378  break;
380  myPersonNumber = parse<int>(value);
381  break;
383  myContainerNumber = parse<int>(value);
384  break;
385  case SUMO_ATTR_REROUTE:
386  myReroute = parse<bool>(value);
387  break;
389  myDepartPosLat = value;
390  break;
392  myArrivalPosLat = value;
393  break;
394  case GNE_ATTR_GENERIC:
396  break;
397  default:
398  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
399  }
400 }
401 
402 /****************************************************************************/
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:1795
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(const Position &oldPos, 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.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
std::string myArrivalSpeed
arrival speed
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
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:1074
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 Addititional parent
SumoXMLTag getTag() const
get XML Tag assigned to this object
virtual Position getPositionInView() const =0
Returns position of additional in view.