SUMO - Simulation of Urban MObility
GNECalibratorRoute.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 
30 #include <string>
31 #include <iostream>
32 #include <utility>
37 #include <utils/common/ToString.h>
38 #include <utils/geom/GeomHelper.h>
45 #include <utils/gui/div/GLHelper.h>
49 
50 #include "GNECalibratorRoute.h"
51 #include "GNECalibrator.h"
52 #include "GNEEdge.h"
53 #include "GNEViewNet.h"
54 #include "GNENet.h"
55 #include "GNEJunction.h"
56 
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
61 
63  myCalibratorParent(calibratorParent), myRouteID(calibratorParent->generateRouteID()), myColor("") {
64 }
65 
66 
67 GNECalibratorRoute::GNECalibratorRoute(GNECalibrator* calibratorParent, std::string routeID, std::vector<std::string> edges, std::string color) :
68  myCalibratorParent(calibratorParent), myRouteID(calibratorParent->generateRouteID()), myColor("") {
69  // set values using set functions to avoid non-valid values
70  setRouteID(routeID);
71  setEdges(edges);
72  setColor(color);
73 }
74 
75 
76 GNECalibratorRoute::GNECalibratorRoute(GNECalibrator* calibratorParent, std::string routeID, std::vector<GNEEdge*> edges, std::string color) :
77  myCalibratorParent(calibratorParent), myRouteID(""), myColor("") {
78  // set values using set functions to avoid non-valid values
79  setRouteID(routeID);
80  setEdges(edges);
81  setColor(color);
82 }
83 
85 
86 
89  return myCalibratorParent;
90 }
91 
92 
95  return SUMO_TAG_ROUTE;
96 }
97 
98 
99 const std::string&
101  return myRouteID;
102 }
103 
104 
105 std::vector<std::string>
107  std::vector<std::string> edgeIDs;
108  for (std::vector<GNEEdge*>::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
109  edgeIDs.push_back((*i)->getID());
110  }
111  return edgeIDs;
112 }
113 
114 
115 const std::vector<GNEEdge*>&
117  return myEdges;
118 }
119 
120 
121 const std::string&
123  return myColor;
124 }
125 
126 
127 bool
128 GNECalibratorRoute::setRouteID(std::string routeID) {
129  if (routeID.empty()) {
130  return false;
131  } else if (myCalibratorParent->getViewNet()->getNet()->routeExists(routeID) == true) {
132  return false;
133  } else {
134  myRouteID = routeID;
135  return true;
136  }
137 }
138 
139 
140 bool
141 GNECalibratorRoute::setEdges(const std::vector<std::string>& edgeIDs) {
142  std::vector<GNEEdge*> edges;
143  GNEEdge* edgeTmp;
144  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); i++) {
145  // check that current edges exist in the net
146  edgeTmp = myCalibratorParent->getViewNet()->getNet()->retrieveEdge((*i), false);
147  if (edgeTmp != NULL) {
148  edges.push_back(edgeTmp);
149  } else {
150  return false;
151  }
152  }
153  return setEdges(edges);
154 }
155 
156 
157 bool
158 GNECalibratorRoute::setEdges(const std::vector<GNEEdge*>& edges) {
159  myEdges = edges;
160  return true;
161 }
162 
163 
164 bool
165 GNECalibratorRoute::setEdges(const std::string& edgeIDs) {
166  if (GNEAttributeCarrier::canParse<std::vector<std::string> >(edgeIDs)) {
167  return setEdges(GNEAttributeCarrier::parse<std::vector<std::string> >(edgeIDs));
168  } else {
169  return false;
170  }
171 }
172 
173 
174 bool
175 GNECalibratorRoute::setColor(std::string color) {
176  myColor = color;
177  return true;
178 }
179 
180 
181 std::string
182 GNECalibratorRoute::checkEdgeRoute(const std::vector<std::string>& edgeIDs) const {
183  std::vector<GNEEdge*> edges;
184  // check that there aren't to equal adjacent edges
185  for (std::vector<std::string>::const_iterator i = edgeIDs.begin() + 1; i != edgeIDs.end(); i++) {
186  GNEEdge* retrievedEdge = myCalibratorParent->getViewNet()->getNet()->retrieveEdge((*i), false);
187  if (retrievedEdge != NULL) {
188  edges.push_back(retrievedEdge);
189  } else {
190  return (toString(SUMO_TAG_EDGE) + " '" + *i + "' doesn't exist");
191  }
192  }
193  // check that there aren't to equal adjacent edges
194  for (std::vector<GNEEdge*>::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
195  if ((*(i - 1))->getID() == (*i)->getID()) {
196  return (toString(SUMO_TAG_EDGE) + " '" + (*i)->getID() + "' is adjacent to itself");
197  }
198  }
199  // check that edges are adjacents
200  for (std::vector<GNEEdge*>::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
201  std::vector<GNEEdge*> adyacents = (*(i - 1))->getGNEJunctionDestiny()->getGNEOutgoingEdges();
202  if (std::find(adyacents.begin(), adyacents.end(), (*i)) == adyacents.end()) {
203  return (toString(SUMO_TAG_EDGE) + " '" + (*(i - 1))->getID() + "' isn't adjacent to " + toString(SUMO_TAG_EDGE) + " '" + (*i)->getID() + "'");
204  }
205  }
206  // all ok, then return ""
207  return "";
208 }
209 
210 
211 bool
212 GNECalibratorRoute::operator==(const GNECalibratorRoute& calibratorRoute) const {
213  return (myRouteID == calibratorRoute.getRouteID());
214 }
215 
216 /****************************************************************************/
const std::string & getColor() const
get color of route
GNECalibratorRoute(GNECalibrator *calibratorParent)
default constructor
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:743
std::string checkEdgeRoute(const std::vector< std::string > &edge) const
check if a list of edges is valid to set a route
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
bool setEdges(const std::vector< std::string > &edgeIDs)
set edges of route using IDs
bool routeExists(const std::string &routeID) const
Check if exist a route with these ID.
Definition: GNENet.cpp:1417
SumoXMLTag getTag() const
get tag
const std::vector< GNEEdge * > & getEdges() const
get edges
std::vector< GNEEdge * > myEdges
edges of route
std::string myRouteID
route in which this flow is used
const std::string & getRouteID() const
get route ID
begin/end of the description of a route
GNECalibrator * myCalibratorParent
pointer to calibrator parent
std::vector< std::string > getEdgesIDs() const
get IDs of Edges
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:165
std::string myColor
color of flow
~GNECalibratorRoute()
destructor
begin/end of the description of an edge
bool setRouteID(std::string routeID)
set route ID
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:57
static bool canParse(const std::string &string)
true if a number of type T can be parsed from string
bool operator==(const GNECalibratorRoute &calibratorRoute) const
overload operator ==
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
bool setColor(std::string color="")
set color of route
GNENet * getNet() const
get the net object
static T parse(const std::string &string)
parses a number of type T from string
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent