SUMO - Simulation of Urban MObility
GNERerouterInterval.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 <utils/common/ToString.h>
25 #include "GNERerouterInterval.h"
30 #include <netedit/GNEUndoList.h>
31 #include <netedit/GNEViewNet.h>
32 #include <netedit/GNENet.h>
33 
34 #include "GNERerouter.h"
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
41  GNEAdditional(rerouterDialog->getEditedAdditional(), rerouterDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false) {
42  // fill reroute interval with default values
44 }
45 
46 
47 GNERerouterInterval::GNERerouterInterval(GNEAdditional* rerouterParent, double begin, double end) :
48  GNEAdditional(rerouterParent, rerouterParent->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false),
49  myBegin(begin),
50  myEnd(end) {
51 }
52 
53 
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
70  // Currently this additional doesn't own a Geometry
71 }
72 
73 
77 }
78 
79 
80 std::string
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_BEGIN:
98  return toString(myBegin);
99  case SUMO_ATTR_END:
100  return toString(myEnd);
101  case GNE_ATTR_PARENT:
102  return myFirstAdditionalParent->getID();
103  case GNE_ATTR_GENERIC:
104  return getGenericParametersStr();
105  default:
106  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
107  }
108 }
109 
110 
111 void
112 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
113  if (value == getAttribute(key)) {
114  return; //avoid needless changes, later logic relies on the fact that attributes have changed
115  }
116  switch (key) {
117  case SUMO_ATTR_ID: {
118  // change ID of Rerouter Interval
119  undoList->p_add(new GNEChange_Attribute(this, key, value));
120  // Change Ids of all Rerouter childs
121  for (auto i : myAdditionalChilds) {
122  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(i->getTag()), undoList);
123  }
124  break;
125  }
126  case SUMO_ATTR_BEGIN:
127  case SUMO_ATTR_END:
128  case GNE_ATTR_GENERIC:
129  undoList->p_add(new GNEChange_Attribute(this, key, value));
130  break;
131  default:
132  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
133  }
134 }
135 
136 
137 bool
138 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
139  switch (key) {
140  case SUMO_ATTR_ID:
141  return isValidAdditionalID(value);
142  case SUMO_ATTR_BEGIN:
143  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) < myEnd);
144  case SUMO_ATTR_END:
145  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) > myBegin);
146  case GNE_ATTR_GENERIC:
147  return isGenericParametersValid(value);
148  default:
149  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
150  }
151 }
152 
153 
154 std::string
156  return toString(getTag());
157 }
158 
159 
160 std::string
162  return toString(getTag()) + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
163 }
164 
165 // ===========================================================================
166 // private
167 // ===========================================================================
168 
169 void
170 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
171  switch (key) {
172  case SUMO_ATTR_ID:
173  changeAdditionalID(value);
174  break;
175  case SUMO_ATTR_BEGIN:
176  myBegin = parse<double>(value);
177  break;
178  case SUMO_ATTR_END:
179  myEnd = parse<double>(value);
180  break;
181  case GNE_ATTR_GENERIC:
183  break;
184  default:
185  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
186  }
187 }
188 
189 /****************************************************************************/
std::string getParentName() const
Returns the name of the parent object.
void updateGeometry(bool updateGrid)
update pre-computed geometry information
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
GNERerouterInterval(GNERerouterDialog *rerouterDialog)
constructor (Used in GNERerouterDialog)
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Stores the information about how to visualize structures.
weights: time range begin
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
void setDefaultValues()
change all attributes of additional with their default values (note: this cannot be undo) ...
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
Position getPositionInView() const
Returns position of additional in view.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Dialog for edit rerouters.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
double myBegin
begin timeStep
a Rerouter
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
const std::string getID() const
function to support debugging
double myEnd
end timeStep
std::string getAttribute(SumoXMLAttr key) const
std::vector< GNEAdditional * > myAdditionalChilds
vector with the Additional childs
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
weights: time range end
std::string getGenericParametersStr() const
return generic parameters in string format
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
an aggreagated-output interval
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
parent of an additional element
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
~GNERerouterInterval()
destructor
GNEAdditional * myFirstAdditionalParent
pointer to first Addititional parent
SumoXMLTag getTag() const
get XML Tag assigned to this object
virtual Position getPositionInView() const =0
Returns position of additional in view.