SUMO - Simulation of Urban MObility
GNEAdditionalHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
31 
32 #include "GNEAdditionalHandler.h"
33 #include "GNEBusStop.h"
34 #include "GNEChange_Additional.h"
35 #include "GNEChargingStation.h"
36 #include "GNEClosingLaneReroute.h"
37 #include "GNEClosingReroute.h"
38 #include "GNEContainerStop.h"
39 #include "GNEDestProbReroute.h"
40 #include "GNEDetectorE1.h"
41 #include "GNEDetectorE2.h"
42 #include "GNEDetectorE3.h"
43 #include "GNEDetectorEntry.h"
44 #include "GNEDetectorExit.h"
45 #include "GNEEdge.h"
46 #include "GNEJunction.h"
47 #include "GNELane.h"
48 #include "GNENet.h"
49 #include "GNERerouter.h"
50 #include "GNERerouterInterval.h"
51 #include "GNERouteProbReroute.h"
52 #include "GNERouteProbe.h"
53 #include "GNEUndoList.h"
54 #include "GNEVaporizer.h"
55 #include "GNEViewNet.h"
56 #include "GNECalibrator.h"
57 
58 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
63 GNEAdditionalHandler::GNEAdditionalHandler(const std::string& file, GNEViewNet* viewNet) :
64  SUMOSAXHandler(file),
65  myViewNet(viewNet),
66  myE3Parent(NULL),
67  myCalibratorParent(NULL),
68  myVariableSpeedSignParent(NULL),
69  rerouterIntervalToInsertValues(NULL),
70  myLastTag(SUMO_TAG_NOTHING) {
71 }
72 
73 
75 
76 
77 void
79  // Obtain tag of element
80  SumoXMLTag tag = static_cast<SumoXMLTag>(element);
81  // first chek additional parent tag
82  if (checkAdditionalParent(tag)) {
83  // Call parse and build depending of tag
84  switch (element) {
85  case SUMO_TAG_BUS_STOP:
86  parseAndBuildBusStop(attrs, tag);
87  // disable other additional parents
88  myCalibratorParent = NULL;
89  myE3Parent = NULL;
91  break;
93  parseAndBuildContainerStop(attrs, tag);
94  // disable other additional parents
95  myCalibratorParent = NULL;
96  myE3Parent = NULL;
98  break;
100  parseAndBuildChargingStation(attrs, tag);
101  // disable other additional parents
102  myCalibratorParent = NULL;
103  myE3Parent = NULL;
104  break;
105  case SUMO_TAG_E1DETECTOR:
107  parseAndBuildDetectorE1(attrs, tag);
108  // disable other additional parents
109  myCalibratorParent = NULL;
110  myE3Parent = NULL;
112  break;
113  case SUMO_TAG_E2DETECTOR:
115  parseAndBuildDetectorE2(attrs, tag);
116  // disable other additional parents
117  myCalibratorParent = NULL;
118  myE3Parent = NULL;
120  break;
121  case SUMO_TAG_E3DETECTOR:
123  parseAndBuildDetectorE3(attrs, tag);
124  // disable other additional parents
125  myCalibratorParent = NULL;
127  break;
128  case SUMO_TAG_DET_ENTRY:
129  parseAndBuildDetectorEntry(attrs, tag);
130  // disable other additional parents
131  myCalibratorParent = NULL;
133  break;
134  case SUMO_TAG_DET_EXIT:
135  parseAndBuildDetectorExit(attrs, tag);
136  // disable other additional parents
137  myCalibratorParent = NULL;
138  break;
139  case SUMO_TAG_VSS:
140  parseAndBuildVariableSpeedSign(attrs, tag);
141  // disable other additional parents
142  myCalibratorParent = NULL;
143  myE3Parent = NULL;
144  break;
145  case SUMO_TAG_REROUTER:
146  parseAndBuildRerouter(attrs, tag);
147  // disable other additional parents
148  myCalibratorParent = NULL;
149  myE3Parent = NULL;
151  break;
152  case SUMO_TAG_CALIBRATOR:
153  parseAndBuildCalibrator(attrs, tag);
154  // disable other additional parents
155  myE3Parent = NULL;
157  break;
158  case SUMO_TAG_VAPORIZER:
159  parseAndBuildVaporizer(attrs, tag);
160  // disable other additional parents
161  myCalibratorParent = NULL;
162  myE3Parent = NULL;
164  break;
165  case SUMO_TAG_ROUTEPROBE:
166  parseAndBuildRouteProbe(attrs, tag);
167  // disable other additional parents
168  myCalibratorParent = NULL;
169  myE3Parent = NULL;
171  break;
172  case SUMO_TAG_VTYPE:
173  parseCalibratorVehicleType(attrs, tag);
174  // disable other additional parents
175  myCalibratorParent = NULL;
177  break;
178  case SUMO_TAG_ROUTE:
179  parseCalibratorRoute(attrs, tag);
180  // disable other additional parents
181  myCalibratorParent = NULL;
182  // disable other additional parents
183  myE3Parent = NULL;
185  break;
186  case SUMO_TAG_FLOW:
187  parseCalibratorFlow(attrs, tag);
188  // disable other additional parents
189  myE3Parent = NULL;
191  break;
192  case SUMO_TAG_STEP:
193  parseVariableSpeedSignStep(attrs, tag);
194  // disable other additional parents
195  myCalibratorParent = NULL;
196  myE3Parent = NULL;
197  break;
198  default:
199  break;
200  }
201  }
202 }
203 
204 
205 void
207  bool abort = false;
208  // parse attributes of Vaporizer
209  const std::string edgeId = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_EDGE, abort);
210  double startTime = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_STARTTIME, abort);
211  double endTime = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_END, abort);
212  // Continue if all parameters were successfully loaded
213  if (!abort) {
214  // get edge
215  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(edgeId, false);
216  if (edge == NULL) {
217  // Write error if lane isn't valid
218  WRITE_WARNING("The edge '" + edgeId + "' to use within the " + toString(tag) + " is not known.");
219  } else if (startTime > endTime) {
220  // write error if time interval ins't valid
221  WRITE_WARNING("Time interval of " + toString(tag) + " isn't valid. Attribute '" + toString(SUMO_ATTR_STARTTIME) + "' is greater than attribute '" + toString(SUMO_ATTR_END) + "'.");
222  } else {
223  // build Vaporizer
224  buildVaporizer(myViewNet, edge, startTime, endTime);
225  }
226  }
227 }
228 
229 
230 
231 void
233  bool abort = false;
234  // parse attributes of RouteProbe
235  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
236  std::string edgeId = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_EDGE, abort);
237  double freq = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_FREQUENCY, abort);
238  std::string file = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_FILE, abort);
239  double begin = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_BEGIN, abort);
240  // Continue if all parameters were sucesfully loaded
241  if (!abort) {
242  // get edge
243  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(edgeId, false);
244  if (edge == NULL) {
245  // Write error if lane isn't valid
246  WRITE_WARNING("The edge '" + edgeId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
247  } else {
248  // build Vaporizer
249  buildRouteProbe(myViewNet, id, edge, freq, file, begin);
250  }
251  }
252 }
253 
254 
255 void
257  bool abort = false;
258  // parse attribute of calibrator routes
259  std::string routeID = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
260  std::vector<std::string> edgeIDs = getParsedAttribute<std::vector<std::string> >(attrs, 0, tag, SUMO_ATTR_EDGES, abort);
261  std::string color = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_COLOR, abort);
262 
263  // Continue if all parameters were sucesfully loaded
264  if (!abort) {
265  // check if already exist a route with the same ID
266  if (myViewNet->getNet()->routeExists(routeID)) {
267  WRITE_WARNING(toString(SUMO_TAG_ROUTE) + " with ID = '" + routeID + "' cannot be created; Another " +
268  toString(SUMO_TAG_ROUTE) + " with the same ID was previously declared");
269  abort = true;
270  }
271  // declare vector with pointers to GNEEdges
272  std::vector<GNEEdge*> edges;
273  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); (i != edgeIDs.end()) && (abort == false); i++) {
274  GNEEdge* retrievedEdge = myViewNet->getNet()->retrieveEdge((*i), false);
275  // stop
276  if (retrievedEdge != NULL) {
277  edges.push_back(retrievedEdge);
278  } else {
279  WRITE_WARNING(toString(SUMO_TAG_ROUTE) + " with ID = '" + routeID + "' cannot be created; " +
280  toString(SUMO_TAG_EDGE) + " with id '" + (*i) + "' doesn't exist in net");
281  }
282  }
283  // create vehicle type if calibrator parent is currently defined
284  if ((myCalibratorParent != NULL) && (abort == false)) {
285  // create vehicle type and add it to calibrator parent
286  GNECalibratorRoute route(myCalibratorParent, routeID, edges, color);
288  }
289  }
290 }
291 
292 
293 void
295  bool abort = false;
296 
297  // parse attribute of calibrator vehicle types
298  std::string vehicleTypeID = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
299  double accel = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_ACCEL, abort);
300  double decel = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_DECEL, abort);
301  double sigma = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_SIGMA, abort);
302  double tau = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_TAU, abort);
303  double length = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_LENGTH, abort);
304  double minGap = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_MINGAP, abort);
305  double maxSpeed = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_MAXSPEED, abort);
306  double speedFactor = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_SPEEDFACTOR, abort);
307  double speedDev = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_SPEEDDEV, abort);
308  std::string color = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_COLOR, abort);
309  SUMOVehicleClass vClass = getParsedAttribute<SUMOVehicleClass>(attrs, 0, tag, SUMO_ATTR_VCLASS, abort);
310  std::string emissionClass = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_EMISSIONCLASS, abort);
311  SUMOVehicleShape shape = getParsedAttribute<SUMOVehicleShape>(attrs, 0, tag, SUMO_ATTR_GUISHAPE, abort);
312  double width = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_WIDTH, abort);
313  std::string filename = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_IMGFILE, abort);
314  double impatience = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_IMPATIENCE, abort);
315  std::string laneChangeModel = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_LANE_CHANGE_MODEL, abort);
316  std::string carFollowModel = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_CAR_FOLLOW_MODEL, abort);
317  int personCapacity = getParsedAttribute<int>(attrs, 0, tag, SUMO_ATTR_PERSON_CAPACITY, abort);
318  int containerCapacity = getParsedAttribute<int>(attrs, 0, tag, SUMO_ATTR_CONTAINER_CAPACITY, abort);
319  double boardingDuration = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_BOARDING_DURATION, abort);
320  double loadingDuration = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_LOADING_DURATION, abort);
321  std::string latAlignment = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_LATALIGNMENT, abort);
322  double minGapLat = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_MINGAP_LAT, abort);
323  double maxSpeedLat = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_MAXSPEED_LAT, abort);
324 
325  // Continue if all parameters were sucesfully loaded
326  if (!abort) {
327  // check if already exist a vehicleType with the same ID
328  if (myViewNet->getNet()->vehicleTypeExists(vehicleTypeID)) {
329  WRITE_WARNING(toString(SUMO_TAG_VTYPE) + " with ID = '" + vehicleTypeID + "' cannot be created; Another " + toString(SUMO_TAG_VTYPE) + " with the same ID was previously declared");
330  } else if (myCalibratorParent != NULL) {
331  // create vehicle type and add it to calibrator parent
332  GNECalibratorVehicleType vehicleType(myCalibratorParent, vehicleTypeID, accel, decel, sigma, tau, length, minGap, maxSpeed,
333  speedFactor, speedDev, color, vClass, emissionClass, shape, width, filename, impatience,
334  laneChangeModel, carFollowModel, personCapacity, containerCapacity, boardingDuration,
335  loadingDuration, latAlignment, minGapLat, maxSpeedLat);
337  }
338  }
339 }
340 
341 
342 void
344  bool abort = false;
345 
346  // parse attributes of calibrator flows
347  std::string flowID = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
348  std::string vehicleType = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_TYPE, abort);
349  std::string route = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ROUTE, abort);
350  std::string color = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_COLOR, abort);
351  std::string departLane = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_DEPARTLANE, abort);
352  std::string departPos = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_DEPARTPOS, abort);
353  std::string departSpeed = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_DEPARTSPEED, abort);
354  std::string arrivalLane = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ARRIVALLANE, abort);
355  std::string arrivalPos = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ARRIVALPOS, abort);
356  std::string arrivalSpeed = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ARRIVALSPEED, abort);
357  std::string line = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_LINE, abort);
358  int personNumber = getParsedAttribute<int>(attrs, 0, tag, SUMO_ATTR_PERSON_NUMBER, abort);
359  int containerNumber = getParsedAttribute<int>(attrs, 0, tag, SUMO_ATTR_CONTAINER_NUMBER, abort);
360  bool reroute = getParsedAttribute<bool>(attrs, 0, tag, SUMO_ATTR_REROUTE, abort);
361  std::string departPosLat = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_DEPARTPOS_LAT, abort);
362  std::string arrivalPosLat = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ARRIVALPOS_LAT, abort);
363  double begin = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_BEGIN, abort);
364  double end = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_END, abort);
365  double vehsPerHour = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_VEHSPERHOUR, abort);
366  double period = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_PERIOD, abort);
367  double probability = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_PROB, abort);
368  int number = getParsedAttribute<int>(attrs, 0, tag, SUMO_ATTR_NUMBER, abort);
369 
370  // Continue if all parameters were sucesfully loaded
371  if (!abort) {
372  // check if flowID, route and vehicle type already exists
373  if (myViewNet->getNet()->flowExists(flowID) == false) {
374  WRITE_WARNING(toString(SUMO_TAG_FLOW) + " with ID = '" + flowID + "' cannot be created; Another " + toString(SUMO_TAG_FLOW) + " with the same ID was previously declared");
375  abort = true;
376  } else if (myViewNet->getNet()->routeExists(route) == false) {
377  WRITE_WARNING(toString(SUMO_TAG_FLOW) + " with ID = '" + flowID + "' cannot be created; their " + toString(SUMO_TAG_ROUTE) + " with ID = '" + route + "' doesn't exist");
378  abort = true;
379  } else if (myViewNet->getNet()->vehicleTypeExists(vehicleType) == false) {
380  WRITE_WARNING(toString(SUMO_TAG_FLOW) + " with ID = '" + flowID + "' cannot be created; their " + toString(SUMO_TAG_VTYPE) + " with ID = '" + vehicleType + "' doesn't exist");
381  abort = true;
382  }
383  // check if distributions are correct and calibrator parent is defined
384  if ((myCalibratorParent != NULL) && (abort == false)) {
385  // obtain type of distribution
386  GNECalibratorFlow::TypeOfFlow flowType = getTypeOfFlowDistribution(flowID, vehsPerHour, period, probability);
388  WRITE_WARNING(toString(SUMO_TAG_FLOW) + " with ID = '" + flowID + "' cannot be created; Type of distribution undefined");
389  } else {
390  // create Flow and add it to calibrator parent
391  GNECalibratorFlow flow(myCalibratorParent, flowID, vehicleType, route, color, departLane, departPos, departSpeed,
392  arrivalLane, arrivalPos, arrivalSpeed, line, personNumber, containerNumber, reroute,
393  departPosLat, arrivalPosLat, begin, end, vehsPerHour, period, probability, number);
395  }
396  }
397  }
398 }
399 
400 
401 void
403  bool abort = false;
404  // Load step values
405  double time = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_TIME, abort);
406  double speed = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_SPEED, abort);
407  // Continue if all parameters were sucesfully loaded
408  if ((!abort) && (myVariableSpeedSignParent != NULL)) {
409  // create step and check that is valid
411  // show warning if is duplicated
412  if (std::find(myVariableSpeedSignParent->getSteps().begin(), myVariableSpeedSignParent->getSteps().end(), step) != myVariableSpeedSignParent->getSteps().end()) {
413  WRITE_WARNING(toString(step.getTag()) + " cannot be inserted into " + toString(myVariableSpeedSignParent->getTag()) + " with id = '" + myVariableSpeedSignParent->getID() +
414  "'; Already exist another " + toString(step.getTag()) + " with the same " + toString(SUMO_ATTR_TIME) + ".");
415  } else {
417  }
418  }
419 }
420 
421 
422 void
424  bool abort = false;
425  // parse attributes of VSS
426  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
427  std::string file = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_FILE, abort);
428  std::vector<std::string> lanesID = getParsedAttribute<std::vector<std::string> >(attrs, id.c_str(), tag, SUMO_ATTR_LANES, abort);
429  double posx = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_X, abort);
430  double posy = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_Y, abort);
431  // Continue if all parameters were sucesfully loaded
432  if (!abort) {
433  // obtain VSS Values
434  // @todo
435  std::vector<GNEVariableSpeedSignStep> steps;
436  // Obtain pointer to lanes
437  std::vector<GNELane*> lanes;
438  for (std::vector<std::string>::iterator i = lanesID.begin(); (i < lanesID.end()) && (abort == false); i++) {
439  GNELane* lane = myViewNet->getNet()->retrieveLane((*i), false);
440  if (lane != NULL) {
441  lanes.push_back(lane);
442  } else {
443  WRITE_WARNING(toString(SUMO_TAG_VSS) + " with ID = '" + id + "' cannot be created; " + toString(SUMO_TAG_LANE) + " '" + (*i) + "' doesn't exist.");
444  abort = true;
445  }
446  }
447  // if operation of build variable speed signal was sucesfully, save Id
448  if ((abort == false) && buildVariableSpeedSign(myViewNet, id, Position(posx, posy), lanes, file, steps)) {
451  }
452  }
453 }
454 
455 
456 void
458  bool abort = false;
459  // parse attributes of Rerouter
460  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
461  std::vector<std::string> edgesID = getParsedAttribute<std::vector<std::string> >(attrs, id.c_str(), tag, SUMO_ATTR_EDGES, abort);
462  std::string file = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_FILE, abort);
463  double probability = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_PROB, abort);
464  bool off = getParsedAttribute<bool>(attrs, id.c_str(), tag, SUMO_ATTR_OFF, abort);
465  double posx = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_X, abort);
466  double posy = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_Y, abort);
467  // Continue if all parameters were sucesfully loaded
468  if (!abort) {
469  // obtain Rerouter values Values
470 
471  // Obtain pointer to edges
472  std::vector<GNEEdge*> edges;
473  for (int i = 0; i < (int)edgesID.size(); i++) {
474  GNEEdge* edge = myViewNet->getNet()->retrieveEdge(edgesID.at(i));
475  if (edge) {
476  edges.push_back(edge);
477  } else {
478  throw ProcessError(); /**************** ARREGLAR **********/
479  }
480  }
481  // if operation of build variable speed signal was sucesfully, save Id
482  if (buildRerouter(myViewNet, id, Position(posx, posy), edges, probability, file, off)) {
483  ;//myAdditionalParent = id;
484  }
485  }
486 }
487 
488 
489 void
491  bool abort = false;
492  // parse attributes of bus stop
493  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
494  std::string laneId = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_LANE, abort);
495  double startPos = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_STARTPOS, abort);
496  double endPos = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_ENDPOS, abort);
497  std::vector<std::string> lines = getParsedAttribute<std::vector<std::string> >(attrs, id.c_str(), tag, SUMO_ATTR_LINES, abort, false);
498  // Continue if all parameters were sucesfully loaded
499  if (!abort) {
500  // get pointer to lane
501  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
502  if (lane == NULL) {
503  // Write error if lane isn't valid
504  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
505  } else if (!checkStopPos(startPos, endPos, lane->getLaneShapeLength(), POSITION_EPS, getFriendlyPosition(attrs, id.c_str()))) {
506  // Write error if position isn't valid
507  WRITE_WARNING("Invalid position for " + toString(tag) + " with ID = '" + id + "'.");
508  } else if (buildBusStop(myViewNet, id, lane, startPos, endPos, lines)) {
509  myLastTag = tag;
510  }
511  }
512 }
513 
514 
515 void
517  bool abort = false;
518  // parse attributes of container stop
519  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
520  std::string laneId = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_LANE, abort);
521  double startPos = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_STARTPOS, abort);
522  double endPos = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_ENDPOS, abort);
523  std::vector<std::string> lines = getParsedAttribute<std::vector<std::string> >(attrs, id.c_str(), tag, SUMO_ATTR_LINES, abort, false);
524  // Continue if all parameters were sucesfully loaded
525  if (!abort) {
526  // get pointer to lane
527  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
528  if (lane == NULL) {
529  // Write error if lane isn't valid
530  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
531  } else if (!checkStopPos(startPos, endPos, lane->getLaneShapeLength(), POSITION_EPS, getFriendlyPosition(attrs, id.c_str()))) {
532  // write error if position isn't valid
533  WRITE_WARNING("Invalid position for " + toString(tag) + " with ID = '" + id + "'.");
534  } else if (buildContainerStop(myViewNet, id, lane, startPos, endPos, lines)) {
535  myLastTag = tag;
536  }
537  }
538 }
539 
540 
541 void
543  bool abort = false;
544  // parse attributes of charging station
545  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
546  std::string laneId = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_LANE, abort);
547  double startPos = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_STARTPOS, abort);
548  double endPos = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_ENDPOS, abort);
549  double chrgpower = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_CHARGINGPOWER, abort);
550  double efficiency = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_EFFICIENCY, abort);
551  bool chargeInTransit = getParsedAttribute<bool>(attrs, id.c_str(), tag, SUMO_ATTR_CHARGEINTRANSIT, abort);
552  double chargeDelay = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_CHARGEDELAY, abort);
553  // Continue if all parameters were sucesfully loaded
554  if (!abort) {
555  // get pointer to lane
556  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
557  if (lane == NULL) {
558  // Write error if lane isn't valid
559  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
560  } else if (!checkStopPos(startPos, endPos, lane->getLaneShapeLength(), POSITION_EPS, getFriendlyPosition(attrs, id.c_str()))) {
561  // write error if position isn't valid
562  WRITE_WARNING("Invalid position for " + toString(tag) + " with ID = '" + id + "'.");
563  } else if (buildChargingStation(myViewNet, id, lane, startPos, endPos, chrgpower, efficiency, chargeInTransit, chargeDelay)) {
564  myLastTag = tag;
565  }
566  }
567 }
568 
569 
570 void
572  bool abort = false;
573  // parse attributes of calibrator
574  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
575  std::string laneId = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_LANE, abort);
576  std::string outfile = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_OUTPUT, abort);
577  double position = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_POSITION, abort);
578  double freq = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_FREQUENCY, abort);
579  // std::string routeProbe = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_ROUTEPROBE, abort); Currently routeProbe not used
580  std::vector<GNECalibratorRoute> calibratorRoutes;
581  std::vector<GNECalibratorFlow> calibratorFlows;
582  std::vector<GNECalibratorVehicleType> calibratorVehicleTypes;
583  // Continue if all parameters were sucesfully loaded
584  if (!abort) {
585  // get pointer to lane
586  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
587  if (lane == NULL) {
588  // Write error if lane isn't valid
589  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
590  } else if (buildCalibrator(myViewNet, id, lane, position, outfile, freq, calibratorRoutes, calibratorFlows, calibratorVehicleTypes)) {
591  myLastTag = tag;
592  }
593  }
594 }
595 
596 
597 void
599  bool abort = false;
600  // parse attributes of E1
601  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
602  std::string laneId = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_LANE, abort);
603  double position = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_POSITION, abort);
604  double frequency = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_FREQUENCY, abort);
605  std::string file = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_FILE, abort);
606  bool splitByType = getParsedAttribute<bool>(attrs, id.c_str(), tag, SUMO_ATTR_SPLIT_VTYPE, abort);
607  // Continue if all parameters were sucesfully loaded
608  if (!abort) {
609  // get pointer to lane
610  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
611  if (lane == NULL) {
612  // Write error if lane isn't valid
613  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
614  } else if ((position < 0) || (position > (lane->getLaneShapeLength()))) {
615  WRITE_WARNING("Invalid position for " + toString(tag) + " with ID = '" + id + "'.");
616  } else if (buildDetectorE1(myViewNet, id, lane, position, frequency, file, splitByType)) {
617  myLastTag = tag;
618  }
619  }
620 }
621 
622 
623 void
625  bool abort = false;
626  // parse attributes of E2
627  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
628  std::string laneId = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_LANE, abort);
629  double position = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_POSITION, abort);
630  double frequency = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_FREQUENCY, abort);
631  std::string file = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_FILE, abort);
632  double length = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_LENGTH, abort);
633  double haltingTimeThreshold = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_HALTING_TIME_THRESHOLD, abort);
634  double haltingSpeedThreshold = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_HALTING_SPEED_THRESHOLD, abort);
635  double jamDistThreshold = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_JAM_DIST_THRESHOLD, abort);
636  bool cont = getParsedAttribute<bool>(attrs, id.c_str(), tag, SUMO_ATTR_CONT, abort);
637  // Continue if all parameters were sucesfully loaded
638  if (!abort) {
639  // get pointer to lane
640  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
641  if (lane == NULL) {
642  // Write error if lane isn't valid
643  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " '" + id + "' is not known.");
644  } else if ((position < 0) || ((position + length) > (lane->getLaneShapeLength()))) {
645  WRITE_WARNING("Invalid position for " + toString(tag) + " with ID = '" + id + "'.");
646  } else if (buildDetectorE2(myViewNet, id, lane, position, length, frequency, file, cont, haltingTimeThreshold, haltingSpeedThreshold, jamDistThreshold)) {
647  myLastTag = tag;
648  }
649  }
650 }
651 
652 
653 void
655  bool abort = false;
656  // parse attributes of E3
657  std::string id = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_ID, abort);
658  double frequency = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_FREQUENCY, abort);
659  std::string file = getParsedAttribute<std::string>(attrs, id.c_str(), tag, SUMO_ATTR_FILE, abort);
660  double haltingTimeThreshold = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_HALTING_TIME_THRESHOLD, abort);
661  double haltingSpeedThreshold = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_HALTING_SPEED_THRESHOLD, abort);
662  double posx = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_X, abort);
663  double posy = getParsedAttribute<double>(attrs, id.c_str(), tag, SUMO_ATTR_Y, abort);
664  // Continue if all parameters were sucesfully loaded
665  if (!abort) {
666  // Create without possibility of undo/redo
667  if (myViewNet->getNet()->getAdditional(SUMO_TAG_E3DETECTOR, id) == NULL) {
668  myE3Parent = new GNEDetectorE3(id, myViewNet, Position(posx, posy), frequency, file, haltingTimeThreshold, haltingSpeedThreshold);
670  } else {
671  WRITE_WARNING("Could not build " + toString(SUMO_TAG_E3DETECTOR) + " with ID '" + id + "' in netedit; probably declared twice.");
672  myE3Parent = NULL;
673  }
674  }
675 }
676 
677 
678 void
680  bool abort = false;
681  // parse attributes of Entry
682  std::string laneId = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_LANE, abort);
683  double position = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_POSITION, abort);
684  // Check if parsing of parameters was correct
685  if (!abort) {
686  // get pointer to lane
687  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
688  if (lane == NULL) {
689  // Write error if lane isn't valid
690  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " is not known.");
691  } else if ((position < 0) || (position > (lane->getLaneShapeLength()))) {
692  WRITE_WARNING("Invalid position for " + toString(tag) + ".");
693  } else if (myE3Parent != NULL && buildDetectorEntry(myViewNet, myE3Parent, lane, position)) {
694  myLastTag = tag;
695  }
696  }
697 }
698 
699 
700 void
702  bool abort = false;
703  // parse attributes of Exit
704  std::string laneId = getParsedAttribute<std::string>(attrs, 0, tag, SUMO_ATTR_LANE, abort);
705  double position = getParsedAttribute<double>(attrs, 0, tag, SUMO_ATTR_POSITION, abort);
706  // Check if parsing of parameters was correct
707  if (!abort) {
708  // get pointer to lane
709  GNELane* lane = myViewNet->getNet()->retrieveLane(laneId, false);
710  if (lane == NULL) {
711  // Write error if lane isn't valid
712  WRITE_WARNING("The lane '" + laneId + "' to use within the " + toString(tag) + " is not known.");
713  } else if ((position < 0) || (position > (lane->getLaneShapeLength()))) {
714  WRITE_WARNING("Invalid position for " + toString(tag) + ".");
715  } else if (myE3Parent != NULL && buildDetectorExit(myViewNet, myE3Parent, lane, position)) {
716  myLastTag = tag;
717  }
718  }
719 }
720 
721 
722 bool
723 GNEAdditionalHandler::buildAdditional(GNEViewNet* viewNet, SumoXMLTag tag, std::map<SumoXMLAttr, std::string> values) {
724  // create additional depending of the tag
725  switch (tag) {
726  case SUMO_TAG_BUS_STOP: {
727  // obtain specify attributes of busStop
728  std::string id = values[SUMO_ATTR_ID];
729  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
730  double startPos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_STARTPOS]);
731  double endPos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_ENDPOS]);
732  std::vector<std::string> lines = GNEAttributeCarrier::parse<std::vector<std::string> >(values[SUMO_ATTR_LINES]);
733  // Build busStop
734  if (lane) {
735  return buildBusStop(viewNet, id, lane, startPos, endPos, lines);
736  } else {
737  return false;
738  }
739  }
741  // obtain specify attributes of containerStop
742  std::string id = values[SUMO_ATTR_ID];
743  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
744  double startPos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_STARTPOS]);
745  double endPos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_ENDPOS]);
746  std::vector<std::string> lines = GNEAttributeCarrier::parse<std::vector<std::string> >(values[SUMO_ATTR_LINES]);
747  // Build containerStop
748  if (lane) {
749  return buildContainerStop(viewNet, id, lane, startPos, endPos, lines);
750  } else {
751  return false;
752  }
753  }
755  // obtain specify attributes of chargingStation
756  std::string id = values[SUMO_ATTR_ID];
757  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
758  double startPos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_STARTPOS]);
759  double endPos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_ENDPOS]);
760  double chargingPower = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_CHARGINGPOWER]);
761  double efficiency = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_EFFICIENCY]);
762  bool chargeInTransit = GNEAttributeCarrier::parse<bool>(values[SUMO_ATTR_CHARGEINTRANSIT]);
763  double chargeDelay = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_CHARGEDELAY]);
764  // Build chargingStation
765  if (lane) {
766  return buildChargingStation(viewNet, id, lane, startPos, endPos, chargingPower, efficiency, chargeInTransit, chargeDelay);
767  } else {
768  return false;
769  }
770  }
771  case SUMO_TAG_E1DETECTOR: {
772  // obtain specify attributes of detector E1
773  std::string id = values[SUMO_ATTR_ID];
774  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
775  double pos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_POSITION]);
776  double freq = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_FREQUENCY]);
777  std::string filename = values[SUMO_ATTR_FILE];
778  bool splitByType = GNEAttributeCarrier::parse<bool>(values[SUMO_ATTR_SPLIT_VTYPE]);
779  // Build detector E1
780  if (lane) {
781  return buildDetectorE1(viewNet, id, lane, pos, freq, filename, splitByType);
782  } else {
783  return false;
784  }
785  }
786  case SUMO_TAG_E2DETECTOR: {
787  // obtain specify attributes of detector E2
788  std::string id = values[SUMO_ATTR_ID];
789  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
790  double pos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_POSITION]);
791  double freq = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_FREQUENCY]);
792  double length = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_LENGTH]);
793  std::string filename = values[SUMO_ATTR_FILE];
794  bool cont = GNEAttributeCarrier::parse<bool>(values[SUMO_ATTR_CONT]);
795  double timeThreshold = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_HALTING_TIME_THRESHOLD]);
796  double speedThreshold = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_HALTING_SPEED_THRESHOLD]);
797  double jamThreshold = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_JAM_DIST_THRESHOLD]);
798  // Build detector E2
799  if (lane) {
800  return buildDetectorE2(viewNet, id, lane, pos, length, freq, filename, cont, timeThreshold, speedThreshold, jamThreshold);
801  } else {
802  return false;
803  }
804  }
805  case SUMO_TAG_E3DETECTOR: {
806  // obtain specify attributes of detector E3
807  bool ok;
808  std::string id = values[SUMO_ATTR_ID];
809  PositionVector pos = GeomConvHelper::parseShapeReporting(values[SUMO_ATTR_POSITION], "user-supplied position", 0, ok, false);
810  double freq = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_FREQUENCY]);
811  std::string filename = values[SUMO_ATTR_FILE];
812  double timeThreshold = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_HALTING_TIME_THRESHOLD]);
813  double speedThreshold = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_HALTING_SPEED_THRESHOLD]);
814  // Build detector E3
815  if (pos.size() == 1) {
816  return buildDetectorE3(viewNet, id, pos[0], freq, filename, timeThreshold, speedThreshold);
817  } else {
818  return false;
819  }
820  }
821  case SUMO_TAG_DET_ENTRY: {
822  // obtain specify attributes of detector Entry
823  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
824  double pos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_POSITION]);
825  GNEDetectorE3* E3 = dynamic_cast<GNEDetectorE3*>(viewNet->getNet()->retrieveAdditional(values[GNE_ATTR_PARENT]));
826  // Build detector Entry
827  if (lane && E3) {
828  return buildDetectorEntry(viewNet, E3, lane, pos);
829  } else {
830  return false;
831  }
832  }
833  case SUMO_TAG_DET_EXIT: {
834  // obtain specify attributes of Detector Exit
835  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
836  double pos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_POSITION]);
837  GNEDetectorE3* E3 = dynamic_cast<GNEDetectorE3*>(viewNet->getNet()->retrieveAdditional(values[GNE_ATTR_PARENT]));
838  // Build detector Exit
839  if (lane && E3) {
840  return buildDetectorExit(viewNet, E3, lane, pos);
841  } else {
842  return false;
843  }
844  }
845  case SUMO_TAG_VSS: {
846  // obtain specify attributes of variable speed signal
847  std::string id = values[SUMO_ATTR_ID];
848  bool ok;
849  PositionVector pos = GeomConvHelper::parseShapeReporting(values[SUMO_ATTR_POSITION], "user-supplied position", 0, ok, false);
850  // Parse lane Ids
851  std::vector<std::string> laneIds = GNEAttributeCarrier::parse<std::vector<std::string> >(values[SUMO_ATTR_LANES]);
852  // By default, steps are empty
853  std::vector<GNEVariableSpeedSignStep> steps;
854  // Obtain pointers to lanes
855  std::vector<GNELane*> lanes;
856  for (int i = 0; i < (int)laneIds.size(); i++) {
857  lanes.push_back(viewNet->getNet()->retrieveLane(laneIds.at(i)));
858  }
859  std::string file = values[SUMO_ATTR_FILE];
860  if (pos.size() == 1) {
861  return buildVariableSpeedSign(viewNet, id, pos[0], lanes, file, steps);
862  } else {
863  return false;
864  }
865  }
866  case SUMO_TAG_CALIBRATOR: {
867  // obtain specify attributes of calibrator
868  std::string id = values[SUMO_ATTR_ID];
869  GNELane* lane = viewNet->getNet()->retrieveLane(values[SUMO_ATTR_LANE], false);
870  // get rest of parameters
871  // Currently unused double pos = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_POSITION]);
872  double pos = 0;
873  std::string outfile = values[SUMO_ATTR_OUTPUT];
874  double freq = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_FREQUENCY]);
875  // get Calibrator values
876  std::vector<GNECalibratorRoute> calibratorRoutes;
877  std::vector<GNECalibratorFlow> calibratorFlows;
878  std::vector<GNECalibratorVehicleType> calibratorVehicleTypes;
879  // Build calibrator
880  if (lane) {
881  return buildCalibrator(viewNet, id, lane, pos, outfile, freq, calibratorRoutes, calibratorFlows, calibratorVehicleTypes);
882  } else {
883  return false;
884  }
885  }
886  case SUMO_TAG_REROUTER: {
887  // obtain specify attributes of rerouter
888  std::string id = values[SUMO_ATTR_ID];
889  bool ok;
890  PositionVector pos = GeomConvHelper::parseShapeReporting(values[SUMO_ATTR_POSITION], "user-supplied position", 0, ok, false);
891  // Parse edges Ids
892  std::vector<std::string> edgeIds = GNEAttributeCarrier::parse<std::vector<std::string> >(values[SUMO_ATTR_EDGES]);
893  // Get rest of parameters
894  bool off = GNEAttributeCarrier::parse<bool>(values[SUMO_ATTR_OFF]);
895  double prob = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_PROB]);
896  std::string file = values[SUMO_ATTR_FILE];
897  // Obtain pointers to edges
898  std::vector<GNEEdge*> edges;
899  for (int i = 0; i < (int)edgeIds.size(); i++) {
900  edges.push_back(viewNet->getNet()->retrieveEdge(edgeIds.at(i)));
901  }
902  // Build rerouter
903  if (pos.size() == 1) {
904  return buildRerouter(viewNet, id, pos[0], edges, prob, file, off);
905  } else {
906  return false;
907  }
908  }
909  case SUMO_TAG_ROUTEPROBE: {
910  // obtain specify attributes of RouteProbe
911  std::string id = values[SUMO_ATTR_ID];
912  GNEEdge* edge = viewNet->getNet()->retrieveEdge(values[SUMO_ATTR_EDGE], false);
913  double freq = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_FREQUENCY]);
914  std::string filename = values[SUMO_ATTR_FILE];
915  double begin = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_BEGIN]);
916  // Build RouteProbe
917  if (edge) {
918  return buildRouteProbe(viewNet, id, edge, freq, filename, begin);
919  } else {
920  return false;
921  }
922  }
923  case SUMO_TAG_VAPORIZER: {
924  // obtain specify attributes of vaporizer
925  GNEEdge* edge = viewNet->getNet()->retrieveEdge(values[SUMO_ATTR_EDGE], false);
926  double startTime = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_STARTTIME]);
927  double end = GNEAttributeCarrier::parse<double>(values[SUMO_ATTR_END]);
928  // Build RouteProbe
929  if (edge) {
930  return buildVaporizer(viewNet, edge, startTime, end);
931  } else {
932  return false;
933  }
934  }
935  default:
936  return false;
937  }
938 }
939 
940 
941 bool
942 GNEAdditionalHandler::buildBusStop(GNEViewNet* viewNet, const std::string& id, GNELane* lane, double startPos, double endPos, const std::vector<std::string>& lines) {
943  if (viewNet->getNet()->getAdditional(SUMO_TAG_BUS_STOP, id) == NULL) {
944  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_BUS_STOP));
945  GNEBusStop* busStop = new GNEBusStop(id, lane, viewNet, startPos, endPos, lines);
946  viewNet->getUndoList()->add(new GNEChange_Additional(busStop, true), true);
947  viewNet->getUndoList()->p_end();
948  return true;
949  } else {
950  WRITE_WARNING("Could not build " + toString(SUMO_TAG_BUS_STOP) + " with ID '" + id + "' in netedit; probably declared twice.");
951  return false;
952  }
953 }
954 
955 
956 bool
957 GNEAdditionalHandler::buildContainerStop(GNEViewNet* viewNet, const std::string& id, GNELane* lane, double startPos, double endPos, const std::vector<std::string>& lines) {
958  if (viewNet->getNet()->getAdditional(SUMO_TAG_CONTAINER_STOP, id) == NULL) {
959  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_CONTAINER_STOP));
960  GNEContainerStop* containerStop = new GNEContainerStop(id, lane, viewNet, startPos, endPos, lines);
961  viewNet->getUndoList()->add(new GNEChange_Additional(containerStop, true), true);
962  viewNet->getUndoList()->p_end();
963  return true;
964  } else {
965  WRITE_WARNING("Could not build " + toString(SUMO_TAG_CONTAINER_STOP) + " with ID '" + id + "' in netedit; probably declared twice.");
966  return false;
967  }
968 }
969 
970 
971 bool
972 GNEAdditionalHandler::buildChargingStation(GNEViewNet* viewNet, const std::string& id, GNELane* lane, double startPos, double endPos, double chargingPower, double efficiency, bool chargeInTransit, double chargeDelay) {
973  if (viewNet->getNet()->getAdditional(SUMO_TAG_CHARGING_STATION, id) == NULL) {
974  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_CHARGING_STATION));
975  GNEChargingStation* chargingStation = new GNEChargingStation(id, lane, viewNet, startPos, endPos, chargingPower, efficiency, chargeInTransit, chargeDelay);
976  viewNet->getUndoList()->add(new GNEChange_Additional(chargingStation, true), true);
977  viewNet->getUndoList()->p_end();
978  return true;
979  } else {
980  WRITE_WARNING("Could not build " + toString(SUMO_TAG_CHARGING_STATION) + " with ID '" + id + "' in netedit; probably declared twice.");
981  return false;
982  }
983 }
984 
985 
986 bool
987 GNEAdditionalHandler::buildDetectorE1(GNEViewNet* viewNet, const std::string& id, GNELane* lane, double pos, double freq, const std::string& filename, bool splitByType) {
988  if (viewNet->getNet()->getAdditional(SUMO_TAG_E1DETECTOR, id) == NULL) {
989  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_E1DETECTOR));
990  GNEDetectorE1* detectorE1 = new GNEDetectorE1(id, lane, viewNet, pos, freq, filename, splitByType);
991  viewNet->getUndoList()->add(new GNEChange_Additional(detectorE1, true), true);
992  viewNet->getUndoList()->p_end();
993  return true;
994  } else {
995  WRITE_WARNING("Could not build " + toString(SUMO_TAG_E1DETECTOR) + " with ID '" + id + "' in netedit; probably declared twice.");
996  return false;
997  }
998 }
999 
1000 
1001 bool
1002 GNEAdditionalHandler::buildDetectorE2(GNEViewNet* viewNet, const std::string& id, GNELane* lane, double pos, double length, double freq, const std::string& filename,
1003  bool cont, const double timeThreshold, double speedThreshold, double jamThreshold) {
1004  if (viewNet->getNet()->getAdditional(SUMO_TAG_E2DETECTOR, id) == NULL) {
1005  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_E2DETECTOR));
1006  GNEDetectorE2* detectorE2 = new GNEDetectorE2(id, lane, viewNet, pos, length, freq, filename, cont, timeThreshold, speedThreshold, jamThreshold);
1007  viewNet->getUndoList()->add(new GNEChange_Additional(detectorE2, true), true);
1008  viewNet->getUndoList()->p_end();
1009  return true;
1010  } else {
1011  WRITE_WARNING("Could not build " + toString(SUMO_TAG_E2DETECTOR) + " with ID '" + id + "' in netedit; probably declared twice.");
1012  return false;
1013  }
1014 }
1015 
1016 
1017 bool
1018 GNEAdditionalHandler::buildDetectorE3(GNEViewNet* viewNet, const std::string& id, Position pos, double freq, const std::string& filename, const double timeThreshold, double speedThreshold) {
1019  if (viewNet->getNet()->getAdditional(SUMO_TAG_E3DETECTOR, id) == NULL) {
1020  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_E3DETECTOR));
1021  GNEDetectorE3* detectorE3 = new GNEDetectorE3(id, viewNet, pos, freq, filename, timeThreshold, speedThreshold);
1022  viewNet->getUndoList()->add(new GNEChange_Additional(detectorE3, true), true);
1023  viewNet->getUndoList()->p_end();
1024  return true;
1025  } else {
1026  WRITE_WARNING("Could not build " + toString(SUMO_TAG_E3DETECTOR) + " with ID '" + id + "' in netedit; probably declared twice.");
1027  return false;
1028  }
1029 }
1030 
1031 
1032 bool
1034  // Check if Detector E3 parent and lane is correct
1035  if (lane == NULL) {
1036  WRITE_WARNING("Could not build " + toString(SUMO_TAG_DET_ENTRY) + " in netedit; " + toString(SUMO_TAG_LANE) + " doesn't exist.");
1037  return false;
1038  } else if (E3Parent == NULL) {
1039  WRITE_WARNING("Could not build " + toString(SUMO_TAG_DET_ENTRY) + " in netedit; " + toString(SUMO_TAG_E3DETECTOR) + " parent doesn't exist.");
1040  return false;
1041  } else {
1042  // insert E3 parent in net if previoulsy wasn't inserted
1043  if (viewNet->getNet()->getAdditional(E3Parent->getTag(), E3Parent->getID()) == NULL) {
1044  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_E3DETECTOR));
1045  viewNet->getUndoList()->add(new GNEChange_Additional(E3Parent, true), true);
1046  viewNet->getUndoList()->p_end();
1047  }
1048  // Create detector Entry if don't exist already in the net
1049  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_DET_ENTRY));
1050  GNEDetectorEntry* entry = new GNEDetectorEntry(viewNet, E3Parent, lane, pos);
1051  viewNet->getUndoList()->add(new GNEChange_Additional(entry, true), true);
1052  viewNet->getUndoList()->p_end();
1053  return true;
1054  }
1055 }
1056 
1057 
1058 bool
1060  // Check if Detector E3 parent and lane is correct
1061  if (lane == NULL) {
1062  WRITE_WARNING("Could not build " + toString(SUMO_TAG_DET_ENTRY) + " in netedit; " + toString(SUMO_TAG_LANE) + " doesn't exist.");
1063  return false;
1064  } else if (E3Parent == NULL) {
1065  WRITE_WARNING("Could not build " + toString(SUMO_TAG_DET_ENTRY) + " in netedit; " + toString(SUMO_TAG_E3DETECTOR) + " parent doesn't exist.");
1066  return false;
1067  } else {
1068  // insert E3 parent in net if previoulsy wasn't inserted
1069  if (viewNet->getNet()->getAdditional(E3Parent->getTag(), E3Parent->getID()) == NULL) {
1070  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_E3DETECTOR));
1071  viewNet->getUndoList()->add(new GNEChange_Additional(E3Parent, true), true);
1072  viewNet->getUndoList()->p_end();
1073  }
1074  // Create detector Exit if don't exist already in the net
1075  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_DET_EXIT));
1076  GNEDetectorExit* exit = new GNEDetectorExit(viewNet, E3Parent, lane, pos);
1077  viewNet->getUndoList()->add(new GNEChange_Additional(exit, true), true);
1078  viewNet->getUndoList()->p_end();
1079  return true;
1080  }
1081 }
1082 
1083 
1084 bool
1085 GNEAdditionalHandler::buildCalibrator(GNEViewNet* viewNet, const std::string& id, GNELane* lane, double pos, const std::string& outfile, const double freq,
1086  const std::vector<GNECalibratorRoute>& calibratorRoutes, const std::vector<GNECalibratorFlow>& calibratorFlows,
1087  const std::vector<GNECalibratorVehicleType>& calibratorVehicleTypes) {
1088  if (viewNet->getNet()->getAdditional(SUMO_TAG_CALIBRATOR, id) == NULL) {
1089  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_CALIBRATOR));
1090  GNECalibrator* calibrator = new GNECalibrator(id, lane, viewNet, pos, freq, outfile, calibratorRoutes, calibratorFlows, calibratorVehicleTypes);
1091  viewNet->getUndoList()->add(new GNEChange_Additional(calibrator, true), true);
1092  viewNet->getUndoList()->p_end();
1093  return true;
1094  } else {
1095  WRITE_WARNING("Could not build " + toString(SUMO_TAG_CALIBRATOR) + " with ID '" + id + "' in netedit; probably declared twice.");
1096  return false;
1097  }
1098 }
1099 
1100 
1101 bool
1102 GNEAdditionalHandler::buildRerouter(GNEViewNet* viewNet, const std::string& id, Position pos, const std::vector<GNEEdge*>& edges, double prob, const std::string& file, bool off) {
1103  if (viewNet->getNet()->getAdditional(SUMO_TAG_REROUTER, id) == NULL) {
1104  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_REROUTER));
1105  GNERerouter* rerouter = new GNERerouter(id, viewNet, pos, edges, file, prob, off);
1106  viewNet->getUndoList()->add(new GNEChange_Additional(rerouter, true), true);
1107  viewNet->getUndoList()->p_end();
1108  return true;
1109  } else {
1110  WRITE_WARNING("Could not build " + toString(SUMO_TAG_REROUTER) + " with ID '" + id + "' in netedit; probably declared twice.");
1111  return false;
1112  }
1113 }
1114 
1115 
1116 bool
1117 GNEAdditionalHandler::buildRouteProbe(GNEViewNet* viewNet, const std::string& id, GNEEdge* edge, double freq, const std::string& file, double begin) {
1118  if (viewNet->getNet()->getAdditional(SUMO_TAG_ROUTEPROBE, id) == NULL) {
1119  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_ROUTEPROBE));
1120  GNERouteProbe* routeProbe = new GNERouteProbe(id, viewNet, edge, freq, file, begin);
1121  viewNet->getUndoList()->add(new GNEChange_Additional(routeProbe, true), true);
1122  viewNet->getUndoList()->p_end();
1123  return true;
1124  } else {
1125  WRITE_WARNING("Could not build " + toString(SUMO_TAG_ROUTEPROBE) + " with ID '" + id + "' in netedit; probably declared twice.");
1126  return false;
1127  }
1128 }
1129 
1130 
1131 bool
1132 GNEAdditionalHandler::buildVariableSpeedSign(GNEViewNet* viewNet, const std::string& id, Position pos, const std::vector<GNELane*>& lanes, const std::string& file, const std::vector<GNEVariableSpeedSignStep>& steps) {
1133  if (viewNet->getNet()->getAdditional(SUMO_TAG_VSS, id) == NULL) {
1134  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_VSS));
1135  GNEVariableSpeedSign* variableSpeedSign = new GNEVariableSpeedSign(id, viewNet, pos, lanes, file, steps);
1136  viewNet->getUndoList()->add(new GNEChange_Additional(variableSpeedSign, true), true);
1137  viewNet->getUndoList()->p_end();
1138  return true;
1139  } else {
1140  WRITE_WARNING("Could not build " + toString(SUMO_TAG_VSS) + " with ID '" + id + "' in netedit; probably declared twice.");
1141  return false;
1142  }
1143 }
1144 
1145 
1146 bool
1147 GNEAdditionalHandler::buildVaporizer(GNEViewNet* viewNet, GNEEdge* edge, double startTime, double end) {
1148  viewNet->getUndoList()->p_begin("add " + toString(SUMO_TAG_VAPORIZER));
1149  GNEVaporizer* vaporizer = new GNEVaporizer(viewNet, edge, startTime, end);
1150  viewNet->getUndoList()->add(new GNEChange_Additional(vaporizer, true), true);
1151  viewNet->getUndoList()->p_end();
1152  return true;
1153 }
1154 
1155 
1156 std::string
1157 GNEAdditionalHandler::getFileName(const SUMOSAXAttributes& attrs, const std::string& base, const bool allowEmpty) {
1158  // get the file name to read further definitions from
1159  bool ok = true;
1160  std::string file = attrs.getOpt<std::string>(SUMO_ATTR_FILE, 0, ok, "");
1161  if (file == "") {
1162  if (allowEmpty) {
1163  return file;
1164  }
1165  WRITE_WARNING("No filename given.");
1166  }
1167  // check whether absolute or relative filenames are given
1168  if (!FileHelpers::isAbsolute(file)) {
1169  return FileHelpers::getConfigurationRelative(base, file);
1170  }
1171  return file;
1172 }
1173 
1174 
1175 double
1176 GNEAdditionalHandler::getPosition(const SUMOSAXAttributes& attrs, GNELane& lane, const std::string& tt, const std::string& tid) {
1177  bool ok = true;
1178  double pos = attrs.get<double>(SUMO_ATTR_POSITION, 0, ok, false);
1179  const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false);
1180  if (!ok) {
1181  WRITE_WARNING("Error on parsing a position information.");
1182  }
1183  if (pos < 0) {
1184  pos = lane.getLaneShapeLength() + pos;
1185  }
1186  if (pos > lane.getLaneShapeLength()) {
1187  if (friendlyPos) {
1188  pos = lane.getLaneShapeLength() - (double) 0.1;
1189  } else {
1190  WRITE_WARNING("The position of " + tt + " '" + tid + "' lies beyond the lane's '" + lane.getID() + "' length.");
1191  }
1192  }
1193  return pos;
1194 }
1195 
1196 
1197 bool
1198 GNEAdditionalHandler::checkStopPos(double& startPos, double& endPos, const double laneLength, const double minLength, const bool friendlyPos) {
1199  if (minLength > laneLength) {
1200  return false;
1201  }
1202  if (startPos < 0) {
1203  startPos += laneLength;
1204  }
1205  if (endPos < 0) {
1206  endPos += laneLength;
1207  }
1208  if (endPos < minLength || endPos > laneLength) {
1209  if (!friendlyPos) {
1210  return false;
1211  }
1212  if (endPos < minLength) {
1213  endPos = minLength;
1214  }
1215  if (endPos > laneLength) {
1216  endPos = laneLength;
1217  }
1218  }
1219  if (startPos < 0 || startPos > endPos - minLength) {
1220  if (!friendlyPos) {
1221  return false;
1222  }
1223  if (startPos < 0) {
1224  startPos = 0;
1225  }
1226  if (startPos > endPos - minLength) {
1227  startPos = endPos - minLength;
1228  }
1229  }
1230  return true;
1231 }
1232 
1233 
1234 template <typename T> T
1235 GNEAdditionalHandler::getParsedAttribute(const SUMOSAXAttributes& attrs, const char* objectid, SumoXMLTag tag, SumoXMLAttr attribute, bool& abort, bool report) {
1236  bool ok = true;
1237  std::string parsedAttribute = "0";
1238  // only show one warning for every error/warning loading additional
1239  if (!abort) {
1240  // set additionalOfWarningMessage
1241  std::string additionalOfWarningMessage;
1242  if (objectid) {
1243  additionalOfWarningMessage = toString(tag) + " with ID '" + toString(objectid) + "'";
1244  } else {
1245  additionalOfWarningMessage = toString(tag);
1246  }
1247  // first check that attribute exists
1248  if (attrs.hasAttribute(attribute)) {
1249  // Parse attribute as string
1250  parsedAttribute = attrs.get<std::string>(attribute, objectid, ok, false);
1251  // Check if is the attribute is a file name or special attribute "COLOR"
1252  if (!ok && ((attribute == SUMO_ATTR_COLOR) || GNEAttributeCarrier::isFilename(tag, attribute))) {
1253  ok = true;
1254  }
1255  // check that parsed attribute can be converted to type T
1256  if (ok && !GNEAttributeCarrier::canParse<T>(parsedAttribute)) {
1257  ok = false;
1258  }
1259  std::string errorFormat;
1260  // Set extra checks for int values
1261  if (GNEAttributeCarrier::isInt(tag, attribute)) {
1262  if (GNEAttributeCarrier::canParse<int>(parsedAttribute)) {
1263  // parse to int and check if can be negative
1264  int parsedIntAttribute = GNEAttributeCarrier::parse<int>(parsedAttribute);
1265  if (GNEAttributeCarrier::isPositive(tag, attribute) && parsedIntAttribute < 0) {
1266  errorFormat = "Cannot be negative; ";
1267  ok = false;
1268  }
1269  } else {
1270  errorFormat = "Cannot be parsed to int; ";
1271  ok = false;
1272  }
1273  }
1274  // Set extra checks for float(double) values
1275  if (GNEAttributeCarrier::isFloat(tag, attribute)) {
1276  if (GNEAttributeCarrier::canParse<double>(parsedAttribute)) {
1277  // parse to double and check if can be negative
1278  double parsedSumoRealAttribute = GNEAttributeCarrier::parse<double>(parsedAttribute);
1279  if (GNEAttributeCarrier::isPositive(tag, attribute) && parsedSumoRealAttribute < 0) {
1280  errorFormat = "Cannot be negative; ";
1281  ok = false;
1282  }
1283  } else {
1284  errorFormat = "Cannot be parsed to float; ";
1285  ok = false;
1286  }
1287  }
1288  // set extra check for time(double) values
1289  if (GNEAttributeCarrier::isTime(tag, attribute)) {
1290  if (GNEAttributeCarrier::canParse<double>(parsedAttribute)) {
1291  // parse to SUMO Real and check if is negative
1292  double parsedSumoRealAttribute = GNEAttributeCarrier::parse<double>(parsedAttribute);
1293  if (parsedSumoRealAttribute < 0) {
1294  errorFormat = "Time cannot be negative; ";
1295  ok = false;
1296  }
1297  } else {
1298  errorFormat = "Cannot be parsed to time; ";
1299  ok = false;
1300  }
1301  }
1302  // set extra check for filename values
1303  if (GNEAttributeCarrier::isFilename(tag, attribute) && (GNEAttributeCarrier::isValidFilename(parsedAttribute) == false)) {
1304  errorFormat = "Filename contains invalid characters; ";
1305  ok = false;
1306  }
1307  // set extra check for Vehicle Classes
1308  if ((!ok) && (attribute == SUMO_ATTR_VCLASS)) {
1309  errorFormat = "Is not a part of defined set of Vehicle Classes; ";
1310  }
1311  // set extra check for Vehicle Classes
1312  if ((!ok) && (attribute == SUMO_ATTR_GUISHAPE)) {
1313  errorFormat = "Is not a part of defined set of Gui Vehicle Shapes; ";
1314  }
1315  // If attribute has an invalid format
1316  if (!ok) {
1317  // if attribute has a default value, take it as string. In other case, abort.
1318  if (GNEAttributeCarrier::hasDefaultValue(tag, attribute)) {
1319  parsedAttribute = toString(GNEAttributeCarrier::getDefaultValue<T>(tag, attribute));
1320  // report warning of default value
1321  if (report) {
1322  WRITE_WARNING("Format of optional " + GNEAttributeCarrier::getAttributeType(tag, attribute) + " attribute '" + toString(attribute) + "' of " +
1323  additionalOfWarningMessage + " is invalid; " + errorFormat + "Default value '" + toString(parsedAttribute) + "' will be used.");
1324  }
1325  } else {
1326  WRITE_WARNING("Format of essential " + GNEAttributeCarrier::getAttributeType(tag, attribute) + " attribute '" + toString(attribute) + "' of " +
1327  additionalOfWarningMessage + " is invalid; " + errorFormat + "Additional cannot be created");
1328  // set default value of parsedAttribute (to avoid exceptions during conversions)
1329  parsedAttribute = "0";
1330  abort = true;
1331  }
1332  }
1333  } else {
1334  // if attribute has a default value, take it. In other case, abort.
1335  if (GNEAttributeCarrier::hasDefaultValue(tag, attribute)) {
1336  parsedAttribute = toString(GNEAttributeCarrier::getDefaultValue<T>(tag, attribute));
1337  // report warning of default value
1338  if (report) {
1339  WRITE_WARNING("Optional " + GNEAttributeCarrier::getAttributeType(tag, attribute) + " attribute '" + toString(attribute) + "' of " +
1340  additionalOfWarningMessage + " is missing; Default value '" + toString(parsedAttribute) + "' will be used.");
1341  }
1342  } else {
1343  WRITE_WARNING("Essential " + GNEAttributeCarrier::getAttributeType(tag, attribute) + " attribute '" + toString(attribute) + "' of " +
1344  additionalOfWarningMessage + " is missing; Additional cannot be created");
1345  abort = true;
1346  }
1347  }
1348  }
1349  // return parsed attribute
1350  return GNEAttributeCarrier::parse<T>(parsedAttribute);
1351 }
1352 
1353 
1354 bool
1356  bool ok = true;
1357  return attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, objectid, ok, false);
1358 }
1359 
1360 
1362 GNEAdditionalHandler::getTypeOfFlowDistribution(std::string flowID, double vehsPerHour, double period, double probability) {
1363  if ((vehsPerHour == -1) && (period == -1) && (probability == -1)) {
1364  WRITE_WARNING("A type of distribution (" + toString(SUMO_ATTR_VEHSPERHOUR) + ", " + toString(SUMO_ATTR_PERIOD) + " or " +
1365  toString(SUMO_ATTR_PROB) + ") must be defined in " + toString(SUMO_TAG_FLOW) + " '" + flowID + "'");
1367  } else {
1368  int vehsPerHourDefined = (vehsPerHour != -1) ? 1 : 0;
1369  int periodDefined = (period != -1) ? 1 : 0;
1370  int probabilityDefined = (probability != -1) ? 1 : 0;
1371 
1372  if ((vehsPerHourDefined + periodDefined + probabilityDefined) != 1) {
1373  WRITE_WARNING("Only a type of distribution (" + toString(SUMO_ATTR_VEHSPERHOUR) + ", " + toString(SUMO_ATTR_PERIOD) + " or " +
1374  toString(SUMO_ATTR_PROB) + ") can be defined at the same time in " + toString(SUMO_TAG_FLOW) + " '" + flowID + "'");
1376  } else if (vehsPerHourDefined == 1) {
1378  } else if (periodDefined == 1) {
1380  } else if (probabilityDefined == 1) {
1382  } else {
1384  }
1385  }
1386 }
1387 
1388 
1389 void
1393  WRITE_WARNING((toString(myE3Parent->getTag()) + "s without " + toString(SUMO_TAG_DET_ENTRY) + "s or " + toString(SUMO_TAG_DET_EXIT) + " aren't allowed; " +
1394  toString(myE3Parent->getTag()) + " with ID = '" + myE3Parent->getID() + "' cannot be created.").c_str());
1395  delete myE3Parent;
1396  myE3Parent = NULL;
1397  }
1398 }
1399 
1400 
1401 bool
1403  // If last tag was an E3 but next tag isn't an Entry or Exit
1405  !((currentTag == SUMO_TAG_DET_ENTRY) || (currentTag == SUMO_TAG_DET_EXIT))) {
1406  // Remove created E3 to avoid load empty detectors
1407  if (myE3Parent != NULL) {
1408  // show E3 empty warning and delete empty E3
1409  WRITE_WARNING((toString(myE3Parent->getTag()) + "s without " + toString(SUMO_TAG_DET_ENTRY) + "s or " + toString(SUMO_TAG_DET_EXIT) + " aren't allowed; " +
1410  toString(myE3Parent->getTag()) + " with ID = '" + myE3Parent->getID() + "' cannot be created.").c_str());
1411  delete myE3Parent;
1412  myE3Parent = NULL;
1413  }
1414  // continue with the processing of additional
1415  return true;
1416  }
1417 
1418  // if last tag wasn't an E3 but next tag is an entry or exit
1420  ((currentTag == SUMO_TAG_DET_ENTRY) || (currentTag == SUMO_TAG_DET_EXIT))) {
1421  if (myE3Parent != NULL) {
1422  // In this case, we're loading a E3 with multiple entry exits, then continue
1423  return true;
1424  } else {
1425  // return false to stop procesing current entry or exit and go to the next tag (this avoid some useless warnings)
1426  return false;
1427  }
1428  }
1429 
1430  // if last tag was a Calibrator but next tag is a vehicle type, route or flow
1431  if (!(myLastTag == SUMO_TAG_CALIBRATOR) && ((currentTag == SUMO_TAG_ROUTE) || (currentTag == SUMO_TAG_FLOW) || (currentTag == SUMO_TAG_VTYPE))) {
1432  if (myCalibratorParent != NULL) {
1433  // In this case, we're loading a Calibrator with multiple routes/flows/vehicleTypes, then continue
1434  return true;
1435  } else {
1436  // return false to stop procesing current route/flow/vehicleType and go to the next tag (this avoid some useless warnings)
1437  return false;
1438  }
1439  }
1440 
1441  // if last tag wasn't a Variable speed Sign but next tag is a step
1442  if (!(myLastTag != SUMO_TAG_CALIBRATOR) && (currentTag == SUMO_TAG_STEP)) {
1443  if (myVariableSpeedSignParent != NULL) {
1444  // In this case, we're loading a Variable Speed Signal with multiple steps, then continue
1445  return true;
1446  } else {
1447  // return false to stop procesing current step and go to the next tag (this avoid some useless warnings)
1448  return false;
1449  }
1450  }
1451 
1452  // all OK
1453  return true;
1454 }
1455 
1456 /****************************************************************************/
void parseVariableSpeedSignStep(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses step values of VariableSpeedSigns.
SumoXMLTag
Numbers representing SUMO-XML - element names.
void parseCalibratorVehicleType(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses vehicle type values of Calibrators.
void parseCalibratorFlow(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses flow values of Calibrators.
a routeprobe detector
static bool isFloat(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical of type float
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:743
alternative tag for e1 detector
static std::string getConfigurationRelative(const std::string &configPath, const std::string &path)
Returns the second path as a relative path to the first file.
Definition: FileHelpers.cpp:82
description of a vehicle type
void addCalibratorRoute(const GNECalibratorRoute &route)
add calibrator route
static std::string getAttributeType(SumoXMLTag tag, SumoXMLAttr attr)
get type of attribute
void parseAndBuildDetectorE1(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a induction loop detector (E1)
static bool buildRouteProbe(GNEViewNet *viewNet, const std::string &id, GNEEdge *edge, double freq, const std::string &file, double begin)
builds a Route probe
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
begin/end of the description of a single lane
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
bool routeExists(const std::string &routeID) const
Check if exist a route with these ID.
Definition: GNENet.cpp:1417
a flow definition (used by router)
void addCalibratorFlow(const GNECalibratorFlow &flow)
add calibrator flow
static bool buildVariableSpeedSign(GNEViewNet *viewNet, const std::string &id, Position pos, const std::vector< GNELane *> &destLanes, const std::string &file, const std::vector< GNEVariableSpeedSignStep > &steps)
Builds a VariableSpeedSign (lane speed trigger)
void parseAndBuildChargingStation(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a charging station.
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1331
Allow/disallow charge in transit in Charging Stations.
const std::string & getFileName() const
returns the current file name
static bool buildDetectorE2(GNEViewNet *viewNet, const std::string &id, GNELane *lane, double pos, double length, double freq, const std::string &filename, bool cont, const double timeThreshold, double speedThreshold, double jamThreshold)
Builds a lane Area Detector (E2)
GNEAdditionalHandler(const std::string &file, GNEViewNet *viewNet)
Constructor.
bool vehicleTypeExists(const std::string &vehicleTypeID) const
Check if exist a vehicle type with these ID.
Definition: GNENet.cpp:1430
weights: time range begin
static bool buildAdditional(GNEViewNet *viewNet, SumoXMLTag tag, std::map< SumoXMLAttr, std::string > values)
Build additionals.
static bool isPositive(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is only Positive (i.e. cannot take negative values)
void parseAndBuildDetectorExit(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a Exit detector.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:82
static bool buildBusStop(GNEViewNet *viewNet, const std::string &id, GNELane *lane, double startPos, double endPos, const std::vector< std::string > &lines)
Builds a bus stop.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNEVariableSpeedSign * myVariableSpeedSignParent
Pointer to the last inserted variableSpeedSign.
SAX-handler base for SUMO-files.
static bool buildDetectorEntry(GNEViewNet *viewNet, GNEDetectorE3 *E3Parent, GNELane *lane, double pos)
Builds a entry detector (E3)
static bool isValidFilename(const std::string &value)
true if value is a valid file value
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list...
begin/end of the description of a route
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
void parseAndBuildVariableSpeedSign(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a Variable Speed Signal (lane speed trigger)
void parseAndBuildDetectorE2(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a lane area detector (E2)
int getNumberOfEntryChilds() const
get number of entry childs
an e3 entry point
bool checkStopPos(double &startPos, double &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if the position of an stoppingPlace over a lane is valid
static bool isInt(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical or type int
GNECalibratorFlow::TypeOfFlow getTypeOfFlowDistribution(std::string flowID, double vehsPerHour, double period, double probability)
get a error message, if configuration of flow distribution is invalid
bool getFriendlyPosition(const SUMOSAXAttributes &attrs, const char *objectid)
get special attribute friendly position, used in stopping places
static bool isTime(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is time
GNEUndoList * getUndoList() const
get the undoList object
~GNEAdditionalHandler()
Destructor.
TypeOfFlow
type of flow
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
Encapsulated SAX-Attributes.
static bool hasDefaultValue(SumoXMLTag tag, SumoXMLAttr attr)
check if attribute of an element has a default avlue
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
static bool isAbsolute(const std::string &path)
Returns the information whether the given path is absolute.
Definition: FileHelpers.cpp:97
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:89
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
an e3 exit point
static bool buildContainerStop(GNEViewNet *viewNet, const std::string &id, GNELane *lane, double startPos, double endPos, const std::vector< std::string > &lines)
Builds a container stop.
A list of positions.
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:785
static bool isFilename(SumoXMLTag tag, SumoXMLAttr attr)
whether a string attribute is a filename
void parseAndBuildRerouter(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a rerouter.
void addStep(const GNEVariableSpeedSignStep &step)
insert a new step in variable speed signal
A lane area vehicles can halt at (netedit-version)
Definition: GNEBusStop.h:58
#define POSITION_EPS
Definition: config.h:175
static bool buildVaporizer(GNEViewNet *viewNet, GNEEdge *edge, double startTime, double end)
Builds a vaporizer (lane speed trigger)
const std::string getID() const
function to support debugging
static bool buildDetectorE1(GNEViewNet *viewNet, const std::string &id, GNELane *lane, double pos, double freq, const std::string &filename, bool splitByType)
Builds a induction loop detector (E1)
bool checkAdditionalParent(SumoXMLTag currentTag)
used to check hierarchy of aditionals with parents and childs (for example, E3)
GNEViewNet * myViewNet
pointer to View&#39;s Net
GNECalibrator * myCalibratorParent
Pointer to the last inserted Calibrator.
static bool buildChargingStation(GNEViewNet *viewNet, const std::string &id, GNELane *lane, double startPos, double endPos, double chargingPower, double efficiency, bool chargeInTransit, double chargeDelay)
Builds a charging Station.
double getLaneShapeLength() const
returns the length of the lane&#39;s shape
Definition: GNELane.cpp:721
static bool buildDetectorE3(GNEViewNet *viewNet, const std::string &id, Position pos, double freq, const std::string &filename, const double timeThreshold, double speedThreshold)
Builds a multi entry exit detector (E3)
void addCalibratorVehicleType(const GNECalibratorVehicleType &vehicleType)
add calibrator vehicleType
void parseAndBuildDetectorE3(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a multi entry exit detector (E3)
begin/end of the description of an edge
void parseAndBuildRouteProbe(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds routeProbe.
GNEDetectorE3 * myE3Parent
Pointer to the last inserted E3.
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
const std::vector< GNEVariableSpeedSignStep > & getSteps() const
get values of variable speed signal
void parseAndBuildCalibrator(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a mesoscopic or microscopic calibrator.
trigger: the time of the step
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
void parseAndBuildBusStop(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a bus stop.
void parseAndBuildContainerStop(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a container stop.
SUMOVehicleShape
Definition of vehicle classes to differ between different appearences.
static bool buildCalibrator(GNEViewNet *viewNet, const std::string &id, GNELane *lane, double pos, const std::string &outfile, double freq, const std::vector< GNECalibratorRoute > &calibratorRoutes, const std::vector< GNECalibratorFlow > &calibratorFlows, const std::vector< GNECalibratorVehicleType > &calibratorVehicleTypes)
builds a microscopic calibrator
GNEAdditional * retrieveAdditional(const std::string &idl, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1304
weights: time range end
static T getParsedAttribute(const SUMOSAXAttributes &attrs, const char *objectid, SumoXMLTag tag, SumoXMLAttr attribute, bool &abort, bool report=true)
get parsed attribute of XML and show warnings if there are problems
void parseAndBuildVaporizer(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Builds a vaporization.
void resetLastTag()
reset last Tag and clear non-valid Additionals (For example, created E3 withouts Entry/Exit childs) ...
vaporizer of vehicles
GNENet * getNet() const
get the net object
SumoXMLTag getTag() const
get tag
bool flowExists(const std::string &flowID) const
Check if exist a flow with these ID.
Definition: GNENet.cpp:1443
int getNumberOfExitChilds() const
get number of exit childs
A variable speed sign.
Eficiency of the charge in Charging Stations.
SumoXMLTag myLastTag
last used Tag
parent of an additional element
Delay in the charge of charging stations.
A lane area vehicles can halt at (netedit-version)
double getPosition(const SUMOSAXAttributes &attrs, GNELane &lane, const std::string &tt, const std::string &tid)
extracts the position, checks whether it shall be mirrored and checks whether it is within the lane...
void parseCalibratorRoute(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses route values of Calibrators.
A color information.
void parseAndBuildDetectorEntry(const SUMOSAXAttributes &attrs, const SumoXMLTag &tag)
Parses his values and builds a Entry detector.
alternative tag for e3 detector
static PositionVector parseShapeReporting(const std::string &shpdef, const std::string &objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true)
Builds a PositionVector from a string representation, reporting occured errors.
alternative tag for e2 detector
static bool buildDetectorExit(GNEViewNet *viewNet, GNEDetectorE3 *E3Parent, GNELane *lane, double pos)
Builds a exit detector (E3)
static bool buildRerouter(GNEViewNet *viewNet, const std::string &id, Position pos, const std::vector< GNEEdge *> &edges, double prob, const std::string &file, bool off)
builds a rerouter
trigger: a step description
SumoXMLTag getTag() const
get XML Tag assigned to this object