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 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
26 
27 #include "GNECalibratorRoute.h"
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
34  GNEAdditional(viewNet->getNet()->generateAdditionalID(SUMO_TAG_ROUTE), viewNet, GLO_CALIBRATOR, SUMO_TAG_ROUTE, "", false) {
35  // fill route type with default values
37 }
38 
39 
40 GNECalibratorRoute::GNECalibratorRoute(GNEViewNet* viewNet, const std::string& routeID, const std::vector<GNEEdge*>& edges, const RGBColor& color) :
41  GNEAdditional(routeID, viewNet, GLO_CALIBRATOR, SUMO_TAG_ROUTE, "", false),
42  myEdges(edges),
43  myColor(color) {
44 }
45 
46 
48 
49 
50 const std::vector<GNEEdge*>&
52  return myEdges;
53 }
54 
55 
56 void
58  // This additional cannot be moved
59 }
60 
61 
62 void
64  // This additional cannot be moved
65 }
66 
67 
68 void
69 GNECalibratorRoute::updateGeometry(bool /*updateGrid*/) {
70  // Currently this additional doesn't own a Geometry
71 }
72 
73 
76  return Position();
77 }
78 
79 
80 std::string
82  return myViewNet->getNet()->getMicrosimID();
83 }
84 
85 
86 void
88  // Currently This additional isn't drawn
89 }
90 
91 
92 std::string
94  switch (key) {
95  case SUMO_ATTR_ID:
96  return getAdditionalID();
97  case SUMO_ATTR_EDGES:
98  return parseIDs(myEdges);
99  case SUMO_ATTR_COLOR:
100  return toString(myColor);
101  case GNE_ATTR_GENERIC:
102  return getGenericParametersStr();
103  default:
104  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
105  }
106 }
107 
108 
109 void
110 GNECalibratorRoute::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
111  if (value == getAttribute(key)) {
112  return; //avoid needless changes, later logic relies on the fact that attributes have changed
113  }
114  switch (key) {
115  case SUMO_ATTR_ID:
116  case SUMO_ATTR_EDGES:
117  case SUMO_ATTR_COLOR:
118  case GNE_ATTR_GENERIC:
119  undoList->p_add(new GNEChange_Attribute(this, key, value));
120  break;
121  default:
122  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
123  }
124 }
125 
126 
127 bool
128 GNECalibratorRoute::isValid(SumoXMLAttr key, const std::string& value) {
129  switch (key) {
130  case SUMO_ATTR_ID:
131  return isValidAdditionalID(value);
132  case SUMO_ATTR_EDGES:
133  if (canParse<std::vector<GNEEdge*> >(myViewNet->getNet(), value, false)) {
134  // all edges exist, then check if compounds a valid route
135  return GNEAdditional::isRouteValid(parse<std::vector<GNEEdge*> >(myViewNet->getNet(), value), false);
136  } else {
137  return false;
138  }
139  case SUMO_ATTR_COLOR:
140  return canParse<RGBColor>(value);
141  case GNE_ATTR_GENERIC:
142  return isGenericParametersValid(value);
143  default:
144  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
145  }
146 }
147 
148 
149 std::string
151  return getTagStr() + ": " + getID();
152 }
153 
154 
155 std::string
157  return getTagStr();
158 }
159 
160 // ===========================================================================
161 // private
162 // ===========================================================================
163 
164 void
165 GNECalibratorRoute::setAttribute(SumoXMLAttr key, const std::string& value) {
166  switch (key) {
167  case SUMO_ATTR_ID:
168  changeAdditionalID(value);
169  break;
170  case SUMO_ATTR_EDGES:
171  myEdges = parse<std::vector<GNEEdge*> >(myViewNet->getNet(), value);
172  break;
173  case SUMO_ATTR_COLOR:
174  myColor = parse<RGBColor>(value);
175  break;
176  case GNE_ATTR_GENERIC:
178  break;
179  default:
180  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
181  }
182 }
183 
184 
185 /****************************************************************************/
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.
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
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.
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
a Calibrator
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:48
const std::string & getTagStr() const
get tag assigned to this object in string format
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
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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.)