SUMO - Simulation of Urban MObility
GNECalibratorRoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 //
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(RGBColor::BLACK) {
64 }
65 
66 
67 GNECalibratorRoute::GNECalibratorRoute(GNECalibrator* calibratorParent, std::string routeID, std::vector<std::string> edges, const RGBColor& color) :
68  myCalibratorParent(calibratorParent), myRouteID(calibratorParent->generateRouteID()), myColor(color) {
69  // set values using set functions to avoid non-valid values
70  setRouteID(routeID);
71  setEdges(edges);
72 }
73 
74 
75 GNECalibratorRoute::GNECalibratorRoute(GNECalibrator* calibratorParent, std::string routeID, std::vector<GNEEdge*> edges, const RGBColor& color) :
76  myCalibratorParent(calibratorParent), myRouteID(""), myColor(color) {
77  // set values using set functions to avoid non-valid values
78  setRouteID(routeID);
79  setEdges(edges);
80 }
81 
83 
84 
87  return myCalibratorParent;
88 }
89 
90 
93  return SUMO_TAG_ROUTE;
94 }
95 
96 
97 const std::string&
99  return myRouteID;
100 }
101 
102 
103 std::vector<std::string>
105  std::vector<std::string> edgeIDs;
106  for (std::vector<GNEEdge*>::const_iterator i = myEdges.begin(); i != myEdges.end(); i++) {
107  edgeIDs.push_back((*i)->getID());
108  }
109  return edgeIDs;
110 }
111 
112 
113 const std::vector<GNEEdge*>&
115  return myEdges;
116 }
117 
118 
119 const RGBColor&
121  return myColor;
122 }
123 
124 
125 bool
126 GNECalibratorRoute::setRouteID(std::string routeID) {
127  if (routeID.empty()) {
128  return false;
129  } else if (myCalibratorParent->getViewNet()->getNet()->routeExists(routeID)) {
130  return false;
131  } else {
132  myRouteID = routeID;
133  return true;
134  }
135 }
136 
137 
138 bool
139 GNECalibratorRoute::setEdges(const std::vector<std::string>& edgeIDs) {
140  std::vector<GNEEdge*> edges;
141  GNEEdge* edgeTmp;
142  for (std::vector<std::string>::const_iterator i = edgeIDs.begin(); i != edgeIDs.end(); i++) {
143  // check that current edges exist in the net
144  edgeTmp = myCalibratorParent->getViewNet()->getNet()->retrieveEdge((*i), false);
145  if (edgeTmp != NULL) {
146  edges.push_back(edgeTmp);
147  } else {
148  return false;
149  }
150  }
151  return setEdges(edges);
152 }
153 
154 
155 bool
156 GNECalibratorRoute::setEdges(const std::vector<GNEEdge*>& edges) {
157  myEdges = edges;
158  return true;
159 }
160 
161 
162 bool
163 GNECalibratorRoute::setEdges(const std::string& edgeIDs) {
164  if (GNEAttributeCarrier::canParse<std::vector<std::string> >(edgeIDs)) {
165  return setEdges(GNEAttributeCarrier::parse<std::vector<std::string> >(edgeIDs));
166  } else {
167  return false;
168  }
169 }
170 
171 
172 bool
174  myColor = color;
175  return true;
176 }
177 
178 
179 bool
180 GNECalibratorRoute::setColor(std::string color) {
181  if (GNEAttributeCarrier::canParse<RGBColor>(color)) {
182  return setColor(GNEAttributeCarrier::parse<RGBColor>(color));
183  } else {
184  return false;
185  }
186 }
187 
188 
189 std::string
190 GNECalibratorRoute::checkEdgeRoute(const std::vector<std::string>& edgeIDs) const {
191  std::vector<GNEEdge*> edges;
192  // check that there aren't to equal adjacent edges
193  for (std::vector<std::string>::const_iterator i = edgeIDs.begin() + 1; i != edgeIDs.end(); i++) {
194  GNEEdge* retrievedEdge = myCalibratorParent->getViewNet()->getNet()->retrieveEdge((*i), false);
195  if (retrievedEdge != NULL) {
196  edges.push_back(retrievedEdge);
197  } else {
198  return (toString(SUMO_TAG_EDGE) + " '" + *i + "' doesn't exist");
199  }
200  }
201  // check that there aren't to equal adjacent edges
202  for (std::vector<GNEEdge*>::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
203  if ((*(i - 1))->getID() == (*i)->getID()) {
204  return (toString(SUMO_TAG_EDGE) + " '" + (*i)->getID() + "' is adjacent to itself");
205  }
206  }
207  // check that edges are adjacents
208  for (std::vector<GNEEdge*>::const_iterator i = edges.begin() + 1; i != edges.end(); i++) {
209  std::vector<GNEEdge*> adyacents = (*(i - 1))->getGNEJunctionDestiny()->getGNEOutgoingEdges();
210  if (std::find(adyacents.begin(), adyacents.end(), (*i)) == adyacents.end()) {
211  return (toString(SUMO_TAG_EDGE) + " '" + (*(i - 1))->getID() + "' isn't adjacent to " + toString(SUMO_TAG_EDGE) + " '" + (*i)->getID() + "'");
212  }
213  }
214  // all ok, then return ""
215  return "";
216 }
217 
218 
219 bool
220 GNECalibratorRoute::operator==(const GNECalibratorRoute& calibratorRoute) const {
221  return (myRouteID == calibratorRoute.getRouteID());
222 }
223 
224 /****************************************************************************/
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:899
bool setEdges(const std::vector< std::string > &edgeIDs)
set edges of route using IDs
const std::string & getRouteID() const
get route ID
bool routeExists(const std::string &routeID) const
Check if exist a route with these ID.
Definition: GNENet.cpp:1766
std::vector< GNEEdge * > myEdges
edges of route
std::string myRouteID
route in which this flow is used
begin/end of the description of a route
std::vector< std::string > getEdgesIDs() const
get IDs of Edges
bool operator==(const GNECalibratorRoute &calibratorRoute) const
overload operator ==
GNECalibrator * myCalibratorParent
pointer to calibrator parent
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
const std::vector< GNEEdge * > & getEdges() const
get edges
RGBColor 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:58
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent
static bool canParse(const std::string &string)
true if a number of type T can be parsed from string
std::string checkEdgeRoute(const std::vector< std::string > &edge) const
check if a list of edges is valid to set a route
SumoXMLTag getTag() const
get tag
GNENet * getNet() const
get the net object
bool setColor(const RGBColor &color)
set color of route
const RGBColor & getColor() const
get color of route
static T parse(const std::string &string)
parses a number of type T from string
const std::vector< GNEEdge * > & getGNEOutgoingEdges() const
Returns incoming GNEEdges.
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:200