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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
27 
28 #include "GNERerouterInterval.h"
29 
30 // ===========================================================================
31 // member method definitions
32 // ===========================================================================
33 
36 {}, {}, {}, {}, {}, {}, {}, {},
37 std::map<std::string, std::string>()),
38  myBegin(0),
39 myEnd(0) {
40  // reset default values
41  resetDefaultValues();
42 }
43 
44 
46  GNEAdditional(rerouterDialog->getEditedAdditional()->getNet(), GLO_REROUTER_INTERVAL, SUMO_TAG_INTERVAL, "",
47 {}, {}, {}, {rerouterDialog->getEditedAdditional()}, {}, {}, {}, {},
48 std::map<std::string, std::string>()),
49 myBegin(0),
50 myEnd(0) {
51  // reset default values
52  resetDefaultValues();
53  // update boundary of rerouter parent
54  rerouterDialog->getEditedAdditional()->updateCenteringBoundary(true);
55 }
56 
57 
59  GNEAdditional(rerouterParent->getNet(), GLO_REROUTER, SUMO_TAG_INTERVAL, "",
60 {}, {}, {}, {rerouterParent}, {}, {}, {}, {},
61 std::map<std::string, std::string>()),
62 myBegin(begin),
63 myEnd(end) {
64  // update boundary of rerouter parent
65  rerouterParent->updateCenteringBoundary(true);
66 }
67 
68 
70 
71 
72 void
74  // avoid write empty intervals
75  if (getChildAdditionals().size() > 0) {
76  device.openTag(SUMO_TAG_INTERVAL);
79  // write all rerouter interval
80  for (const auto& rerouterElement : getChildAdditionals()) {
81  rerouterElement->writeAdditional(device);
82  }
83  device.closeTag();
84  }
85 }
86 
87 
90  // rerouter intervals cannot be moved
91  return nullptr;
92 }
93 
94 
95 void
97  // update centering boundary (needed for centering)
99  // update geometries (boundaries of all children)
100  for (const auto& rerouterElement : getChildAdditionals()) {
101  rerouterElement->updateGeometry();
102  }
103 }
104 
105 
106 Position
108  // get rerouter parent position
109  Position signPosition = getParentAdditionals().front()->getPositionInView();
110  // set position depending of indexes
111  signPosition.add(4.5, (getDrawPositionIndex() * -1) + 1, 0);
112  // return signPosition
113  return signPosition;
114 }
115 
116 
117 void
122 }
123 
124 
125 void
126 GNERerouterInterval::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
127  // geometry of this element cannot be splitted
128 }
129 
130 
131 std::string
133  return getParentAdditionals().at(0)->getID();
134 }
135 
136 
137 void
139  // draw rerouter interval as listed attribute
143  // iterate over additionals and check if drawn
144  for (const auto& rerouterElement : getChildAdditionals()) {
145  // if rerouter or their child is selected, then draw
147  rerouterElement->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(rerouterElement) ||
148  (myNet->getViewNet()->getFrontAttributeCarrier() == rerouterElement)) {
149  rerouterElement->drawGL(s);
150  }
151  }
152 }
153 
154 
155 std::string
157  switch (key) {
158  case SUMO_ATTR_ID:
159  return getParentAdditionals().front()->getID();
160  case SUMO_ATTR_BEGIN:
161  return time2string(myBegin);
162  case SUMO_ATTR_END:
163  return time2string(myEnd);
164  case GNE_ATTR_PARENT:
165  return getParentAdditionals().at(0)->getID();
166  case GNE_ATTR_SELECTED:
168  default:
169  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
170  }
171 }
172 
173 
174 double
176  switch (key) {
177  case SUMO_ATTR_BEGIN:
178  return STEPS2TIME(myBegin);
179  case SUMO_ATTR_END:
180  return STEPS2TIME(myEnd);
181  default:
182  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
183  }
184 }
185 
186 
187 void
188 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
189  if (value == getAttribute(key)) {
190  return; //avoid needless changes, later logic relies on the fact that attributes have changed
191  }
192  switch (key) {
193  case SUMO_ATTR_BEGIN:
194  case SUMO_ATTR_END:
195  case GNE_ATTR_SELECTED:
196  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
197  break;
198  default:
199  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
200  }
201 }
202 
203 
204 bool
205 GNERerouterInterval::isValid(SumoXMLAttr key, const std::string& value) {
206  switch (key) {
207  case SUMO_ATTR_BEGIN:
208  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) < myEnd);
209  case SUMO_ATTR_END:
210  return canParse<SUMOTime>(value) && (parse<SUMOTime>(value) > myBegin);
211  case GNE_ATTR_SELECTED:
212  return canParse<bool>(value);
213  default:
214  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
215  }
216 }
217 
218 
219 bool
221  return true;
222 }
223 
224 
225 std::string
227  return getTagStr();
228 }
229 
230 
231 std::string
233  return getTagStr() + ": " + getAttribute(SUMO_ATTR_BEGIN) + " -> " + getAttribute(SUMO_ATTR_END);
234 }
235 
236 // ===========================================================================
237 // private
238 // ===========================================================================
239 
240 void
241 GNERerouterInterval::setAttribute(SumoXMLAttr key, const std::string& value) {
242  switch (key) {
243  case SUMO_ATTR_BEGIN:
244  myBegin = parse<SUMOTime>(value);
245  break;
246  case SUMO_ATTR_END:
247  myEnd = parse<SUMOTime>(value);
248  break;
249  case GNE_ATTR_SELECTED:
250  if (parse<bool>(value)) {
252  } else {
254  }
255  break;
256  default:
257  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
258  }
259 }
260 
261 
262 void
264  // nothing to do
265 }
266 
267 
268 void
269 GNERerouterInterval::commitMoveShape(const GNEMoveResult& /*moveResult*/, GNEUndoList* /*undoList*/) {
270  // nothing to do
271 }
272 
273 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
@ GLO_REROUTER_INTERVAL
a rerouter interval
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:32
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_PARENT
parent of an additional element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_BEGIN
weights: time range begin
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
void reset()
Resets the boundary.
Definition: Boundary.cpp:65
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
virtual void updateCenteringBoundary(const bool updateGrid)=0
update centering boundary (implies change in RTREE)
void drawListedAddtional(const GUIVisualizationSettings &s, const Position &parentPosition, const int offsetX, const int extraOffsetY, const RGBColor baseCol, const RGBColor textCol, GUITexture texture, const std::string text) const
draw listed additional
int getDrawPositionIndex() const
get draw position index (used in rerouters and VSS)
Boundary myAdditionalBoundary
Additional Boundary.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const std::vector< GNEAdditional * > & getParentAdditionals() const
get parent additionals
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
Dialog for edit rerouters.
Position getPositionInView() const
Returns position of additional in view.
GNEMoveOperation * getMoveOperation()
get move operation
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
std::string getAttribute(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
SUMOTime myEnd
end timeStep
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
SUMOTime myBegin
begin timeStep
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void updateGeometry()
update pre-computed geometry information
bool isAttributeEnabled(SumoXMLAttr key) const
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
GNERerouterInterval(GNENet *net)
default constructor
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
Stores the information about how to visualize structures.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:125
static const RGBColor YELLOW
Definition: RGBColor.h:188
static const RGBColor RED
named colors
Definition: RGBColor.h:185