Eclipse 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-2019 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 /****************************************************************************/
14 //
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
24 #include <netedit/GNEUndoList.h>
25 #include <netedit/GNEViewNet.h>
26 
27 #include "GNERerouterInterval.h"
28 
29 // ===========================================================================
30 // member method definitions
31 // ===========================================================================
32 
34  GNEAdditional(rerouterDialog->getEditedAdditional(), rerouterDialog->getEditedAdditional()->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false,
35 {}, {}, {}, {rerouterDialog->getEditedAdditional()}, {}, {}, {}, {}, {}, {}) {
36  // fill reroute interval with default values
37  setDefaultValues();
38 }
39 
40 
42  GNEAdditional(rerouterParent, rerouterParent->getViewNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "", false,
43 {}, {}, {}, {rerouterParent}, {}, {}, {}, {}, {}, {}),
44 myBegin(begin),
45 myEnd(end) {
46 }
47 
48 
50 
51 void
53  // This additional cannot be moved
54 }
55 
56 
57 void
59  // This additional cannot be moved
60 }
61 
62 
63 void
65  // Currently this additional doesn't own a Geometry
66 }
67 
68 
71  return getParentAdditionals().at(0)->getPositionInView();
72 }
73 
74 
77  return getParentAdditionals().at(0)->getCenteringBoundary();
78 }
79 
80 
81 void
82 GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetElement* /*originalElement*/, const GNENetElement* /*newElement*/, GNEUndoList* /*undoList*/) {
83  // geometry of this element cannot be splitted
84 }
85 
86 
87 std::string
89  return getParentAdditionals().at(0)->getID();
90 }
91 
92 
93 void
95  // Currently This additional isn't drawn
96 }
97 
98 
99 std::string
101  switch (key) {
102  case SUMO_ATTR_ID:
103  return getAdditionalID();
104  case SUMO_ATTR_BEGIN:
105  return time2string(myBegin);
106  case SUMO_ATTR_END:
107  return time2string(myEnd);
108  case GNE_ATTR_PARENT:
109  return getParentAdditionals().at(0)->getID();
110  case GNE_ATTR_PARAMETERS:
111  return getParametersStr();
112  default:
113  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
114  }
115 }
116 
117 
118 double
120  switch (key) {
121  case SUMO_ATTR_BEGIN:
122  return STEPS2TIME(myBegin);
123  case SUMO_ATTR_END:
124  return STEPS2TIME(myEnd);
125  default:
126  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
127  }
128 }
129 
130 
131 void
132 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
133  if (value == getAttribute(key)) {
134  return; //avoid needless changes, later logic relies on the fact that attributes have changed
135  }
136  switch (key) {
137  case SUMO_ATTR_ID: {
138  // change ID of Rerouter Interval
139  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
140  // Change Ids of all Rerouter children
141  for (auto i : getChildAdditionals()) {
142  i->setAttribute(SUMO_ATTR_ID, generateChildID(i->getTagProperty().getTag()), undoList);
143  }
144  break;
145  }
146  case SUMO_ATTR_BEGIN:
147  case SUMO_ATTR_END:
148  case GNE_ATTR_PARAMETERS:
149  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
150  break;
151  default:
152  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
153  }
154 }
155 
156 
157 bool
158 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
159  switch (key) {
160  case SUMO_ATTR_ID:
161  return isValidAdditionalID(value);
162  case SUMO_ATTR_BEGIN:
163  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
164  case SUMO_ATTR_END:
165  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
166  case GNE_ATTR_PARAMETERS:
167  return Parameterised::areParametersValid(value);
168  default:
169  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
170  }
171 }
172 
173 
174 bool
176  return true;
177 }
178 
179 
180 std::string
182  return getTagStr();
183 }
184 
185 
186 std::string
188  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
189 }
190 
191 // ===========================================================================
192 // private
193 // ===========================================================================
194 
195 void
196 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
197  switch (key) {
198  case SUMO_ATTR_ID:
199  changeAdditionalID(value);
200  break;
201  case SUMO_ATTR_BEGIN:
202  myBegin = parse<SUMOTime>(value);
203  break;
204  case SUMO_ATTR_END:
205  myEnd = parse<SUMOTime>(value);
206  break;
207  case GNE_ATTR_PARAMETERS:
208  setParametersStr(value);
209  break;
210  default:
211  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
212  }
213 }
214 
215 /****************************************************************************/
GNERerouterDialog.h
GNERerouterInterval::isAttributeEnabled
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNERerouterInterval.cpp:175
GNERerouterInterval::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNERerouterInterval.cpp:132
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
Parameterised::getParametersStr
std::string getParametersStr() const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
Definition: Parameterised.cpp:112
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:476
GNERerouterInterval::~GNERerouterInterval
~GNERerouterInterval()
destructor
Definition: GNERerouterInterval.cpp:49
GNEAdditional::generateChildID
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition: GNEAdditional.cpp:96
GNERerouterInterval::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNERerouterInterval.cpp:58
GNERerouterDialog
Dialog for edit rerouters.
Definition: GNERerouterDialog.h:44
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:34
GNERerouterInterval::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNERerouterInterval.cpp:88
SUMO_ATTR_ID
@ SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:378
GNERerouterInterval::getAttributeDouble
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNERerouterInterval.cpp:119
GNERerouterInterval::GNERerouterInterval
GNERerouterInterval(GNERerouterDialog *rerouterDialog)
constructor (Used in GNERerouterDialog)
Definition: GNERerouterInterval.cpp:33
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:502
GNERerouterInterval::myEnd
SUMOTime myEnd
end timeStep
Definition: GNERerouterInterval.h:141
GNERerouterInterval::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNERerouterInterval.cpp:64
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:335
SUMO_ATTR_BEGIN
@ SUMO_ATTR_BEGIN
weights: time range begin
Definition: SUMOXMLDefinitions.h:678
GNERerouterInterval::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNERerouterInterval.cpp:94
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:131
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:1014
GNEHierarchicalParentElements::getParentAdditionals
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
Definition: GNEHierarchicalParentElements.cpp:85
GNERerouterInterval.h
GNERerouterInterval::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERerouterInterval.cpp:76
GNERerouterInterval::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNERerouterInterval.cpp:100
GNERerouterInterval::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNERerouterInterval.cpp:187
GNERerouterInterval::splitEdgeGeometry
void splitEdgeGeometry(const double splitPosition, const GNENetElement *originalElement, const GNENetElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNERerouterInterval.cpp:82
GNERerouterInterval::myBegin
SUMOTime myBegin
begin timeStep
Definition: GNERerouterInterval.h:138
GNEViewNet.h
STEPS2TIME
#define STEPS2TIME(x)
Definition: SUMOTime.h:56
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:41
GNE_ATTR_PARAMETERS
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
Definition: SUMOXMLDefinitions.h:989
GNERerouterInterval::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERerouterInterval.cpp:70
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:67
GNENetElement
Definition: GNENetElement.h:43
GNERerouterInterval::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNERerouterInterval.cpp:181
GNERerouterInterval::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNERerouterInterval.cpp:158
Parameterised::setParametersStr
void setParametersStr(const std::string &paramsString)
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
Definition: Parameterised.cpp:139
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
Parameterised::areParametersValid
static bool areParametersValid(const std::string &value, bool report=false)
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
Definition: Parameterised.cpp:166
InvalidArgument
Definition: UtilExceptions.h:56
GLO_REROUTER
@ GLO_REROUTER
a Rerouter
Definition: GUIGlObjectTypes.h:85
config.h
SUMO_ATTR_END
@ SUMO_ATTR_END
weights: time range end
Definition: SUMOXMLDefinitions.h:680
SUMO_TAG_INTERVAL
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
Definition: SUMOXMLDefinitions.h:159
GNERerouterInterval::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNERerouterInterval.cpp:52
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEUndoList
Definition: GNEUndoList.h:48
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:345
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:482
SumoXMLAttr
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:372
GNEHierarchicalChildElements::getChildAdditionals
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
Definition: GNEHierarchicalChildElements.cpp:131
GNEChange_Attribute.h
GNEUndoList.h
GNE_ATTR_PARENT
@ GNE_ATTR_PARENT
parent of an additional element
Definition: SUMOXMLDefinitions.h:987