SUMO - Simulation of Urban MObility
GNECalibratorRoute.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
29 #include <utils/common/ToString.h>
30 #include <utils/geom/GeomHelper.h>
35 #include <utils/gui/div/GLHelper.h>
44 #include <netedit/GNEViewNet.h>
45 #include <netedit/GNENet.h>
46 #include <netedit/GNEUndoList.h>
47 
48 #include "GNECalibratorRoute.h"
49 
50 // ===========================================================================
51 // member method definitions
52 // ===========================================================================
53 
55  GNEAdditional(viewNet->getNet()->generateAdditionalID(SUMO_TAG_ROUTE), viewNet, GLO_CALIBRATOR, SUMO_TAG_ROUTE, "", false) {
56  // fill route type with default values
58 }
59 
60 
61 GNECalibratorRoute::GNECalibratorRoute(GNEViewNet* viewNet, const std::string& routeID, const std::vector<GNEEdge*>& edges, const RGBColor& color) :
62  GNEAdditional(routeID, viewNet, GLO_CALIBRATOR, SUMO_TAG_ROUTE, "", false),
63  myEdges(edges),
64  myColor(color) {
65 }
66 
67 
69 
70 
71 const std::vector<GNEEdge*>&
73  return myEdges;
74 }
75 
76 
77 void
79  // This additional cannot be moved
80 }
81 
82 
83 void
85  // This additional cannot be moved
86 }
87 
88 
89 void
90 GNECalibratorRoute::updateGeometry(bool /*updateGrid*/) {
91  // Currently this additional doesn't own a Geometry
92 }
93 
94 
97  return Position();
98 }
99 
100 
101 std::string
103  return myViewNet->getNet()->getMicrosimID();
104 }
105 
106 
107 void
109  // Currently This additional isn't drawn
110 }
111 
112 
113 std::string
115  switch (key) {
116  case SUMO_ATTR_ID:
117  return getAdditionalID();
118  case SUMO_ATTR_EDGES:
119  return parseIDs(myEdges);
120  case SUMO_ATTR_COLOR:
121  return toString(myColor);
122  case GNE_ATTR_GENERIC:
123  return getGenericParametersStr();
124  default:
125  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
126  }
127 }
128 
129 
130 void
131 GNECalibratorRoute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
132  if (value == getAttribute(key)) {
133  return; //avoid needless changes, later logic relies on the fact that attributes have changed
134  }
135  switch (key) {
136  case SUMO_ATTR_ID:
137  case SUMO_ATTR_EDGES:
138  case SUMO_ATTR_COLOR:
139  case GNE_ATTR_GENERIC:
140  undoList->p_add(new GNEChange_Attribute(this, key, value));
141  break;
142  default:
143  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
144  }
145 }
146 
147 
148 bool
149 GNECalibratorRoute::isValid(SumoXMLAttr key, const std::string& value) {
150  switch (key) {
151  case SUMO_ATTR_ID:
152  return isValidAdditionalID(value);
153  case SUMO_ATTR_EDGES:
154  if (canParse<std::vector<GNEEdge*> >(myViewNet->getNet(), value, false)) {
155  // all edges exist, then check if compounds a valid route
156  return GNEAdditional::isRouteValid(parse<std::vector<GNEEdge*> >(myViewNet->getNet(), value), false);
157  } else {
158  return false;
159  }
160  case SUMO_ATTR_COLOR:
161  return canParse<RGBColor>(value);
162  case GNE_ATTR_GENERIC:
163  return isGenericParametersValid(value);
164  default:
165  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
166  }
167 }
168 
169 
170 std::string
172  return toString(getTag()) + ": " + getID();
173 }
174 
175 
176 std::string
178  return toString(getTag());
179 }
180 
181 // ===========================================================================
182 // private
183 // ===========================================================================
184 
185 void
186 GNECalibratorRoute::setAttribute(SumoXMLAttr key, const std::string& value) {
187  switch (key) {
188  case SUMO_ATTR_ID:
189  changeAdditionalID(value);
190  break;
191  case SUMO_ATTR_EDGES:
192  myEdges = parse<std::vector<GNEEdge*> >(myViewNet->getNet(), value);
193  break;
194  case SUMO_ATTR_COLOR:
195  myColor = parse<RGBColor>(value);
196  break;
197  case GNE_ATTR_GENERIC:
199  break;
200  default:
201  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
202  }
203 }
204 
205 
206 /****************************************************************************/
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Stores the information about how to visualize structures.
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
std::string getParentName() const
Returns the name of the parent object.
const std::vector< GNEEdge * > & getGNEEdges() const
get GNEEdges of Calibrator ROute
GNECalibratorRoute(GNEViewNet *viewNet)
default constructor (used only in GNECalibratorDialog)
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
std::vector< GNEEdge * > myEdges
edges of route
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
begin/end of the description of a route
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
friend class GNEChange_Attribute
declare friend class
RGBColor myColor
color of ROute
~GNECalibratorRoute()
destructor
void updateGeometry(bool updateGrid)
update pre-computed geometry information
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
const std::string getID() const
function to support debugging
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
a Calibrator
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
static bool canParse(const std::string &string)
true if a value of type T can be parsed from string
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Position getPositionInView() const
Returns position of additional in view.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
std::string getGenericParametersStr() const
return generic parameters in string format
GNENet * getNet() const
get the net object
static bool isRouteValid(const std::vector< GNEEdge *> &edges, bool report)
check if a route is valid
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
A color information.
static T parse(const std::string &string)
parses a value of type T from string (used for basic types: int, double, bool, etc.)
SumoXMLTag getTag() const
get XML Tag assigned to this object