Eclipse SUMO - Simulation of Urban MObility
GNERerouter.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-2020 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 <netedit/GNENet.h>
21 #include <netedit/GNEUndoList.h>
22 #include <netedit/GNEViewNet.h>
26 #include <utils/gui/div/GLHelper.h>
29 
30 #include "GNERerouter.h"
31 #include "GNERerouterSymbol.h"
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
38 GNERerouter::GNERerouter(const std::string& id, GNENet* net, const Position& pos,
39  const std::string& name, const std::string& filename, double probability,
40  bool off, SUMOTime timeThreshold, const std::string& vTypes, bool blockMovement) :
41  GNEAdditional(id, net, GLO_REROUTER, SUMO_TAG_REROUTER, name, blockMovement,
42 {}, {}, {}, {}, {}, {}, {}, {}),
43 myPosition(pos),
44 myFilename(filename),
45 myProbability(probability),
46 myOff(off),
47 myTimeThreshold(timeThreshold),
48 myVTypes(vTypes) {
49  // update centering boundary without updating grid
50  updateCenteringBoundary(false);
51 }
52 
53 
55 }
56 
57 
59 GNERerouter::getMoveOperation(const double /*shapeOffset*/) {
60  if (myBlockMovement) {
61  // element blocked, then nothing to move
62  return nullptr;
63  } else {
64  // return move operation for additional placed in view
65  return new GNEMoveOperation(this, myPosition);
66  }
67 }
68 
69 
70 void
72  // update additional geometry
74  // Update Hierarchical connections geometry
76 }
77 
78 
79 void
80 GNERerouter::updateCenteringBoundary(const bool updateGrid) {
81  // remove additional from grid
82  if (updateGrid) {
84  }
85  // now update geometry
87  // add shape boundary
89  // grow
90  myBoundary.grow(10);
91  // add additional into RTREE again
92  if (updateGrid) {
94  }
95  // Update Hierarchical connections geometry
97 }
98 
99 
100 void
101 GNERerouter::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
102  // geometry of this element cannot be splitted
103 }
104 
105 
106 void
108  // Open rerouter dialog
109  GNERerouterDialog(this);
110 }
111 
112 
113 std::string
115  return myNet->getMicrosimID();
116 }
117 
118 
119 void
121  // Obtain exaggeration of the draw
122  const double rerouterExaggeration = s.addSize.getExaggeration(s, this);
123  // first check if additional has to be drawn
124  if (s.drawAdditionals(rerouterExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
125  // check if boundary has to be drawn
126  if (s.drawBoundaries) {
128  }
129  // push name
130  glPushName(getGlID());
131  // push layer matrix
132  glPushMatrix();
133  // translate to front
135  // Add layer matrix
136  glPushMatrix();
137  // translate to position
138  glTranslated(myPosition.x(), myPosition.y(), 0);
139  // scale
140  glScaled(rerouterExaggeration, rerouterExaggeration, 1);
141  // Draw icon depending of detector is selected and if isn't being drawn for selecting
142  if (!s.drawForPositionSelection) {
143  // set White color
144  glColor3d(1, 1, 1);
145  // rotate
146  glRotated(180, 0, 0, 1);
147  // draw texture depending of selection
148  if (drawUsingSelectColor()) {
150  } else {
152  }
153  } else {
154  // set redcolor
156  // just draw a square
158  }
159  // Pop texture matrix
160  glPopMatrix();
161  // draw lock icon
162  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, rerouterExaggeration, -0.5, -0.5, false, 0.4);
163  // Pop layer matrix
164  glPopMatrix();
165  // Pop name
166  glPopName();
167  // push connection matrix
168  glPushMatrix();
169  // translate to front
171  // Draw child connections
172  drawHierarchicalConnections(s, this, rerouterExaggeration);
173  // Pop connection matrix
174  glPopMatrix();
175  // Draw additional ID
176  drawAdditionalID(s);
177  // draw additional name
179  // check if dotted contour has to be drawn
182  }
183  if (s.drawDottedContour() || (myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
185  }
186  }
187 }
188 
189 
190 std::string
192  switch (key) {
193  case SUMO_ATTR_ID:
194  return getID();
195  case SUMO_ATTR_EDGES: {
196  std::vector<std::string> edges;
197  for (const auto& rerouterSymbol : getChildAdditionals()) {
198  if (rerouterSymbol->getTagProperty().isSymbol()) {
199  edges.push_back(rerouterSymbol->getAttribute(SUMO_ATTR_EDGE));
200  }
201  }
202  return toString(edges);
203  }
204  case SUMO_ATTR_POSITION:
205  return toString(myPosition);
206  case SUMO_ATTR_NAME:
207  return myAdditionalName;
208  case SUMO_ATTR_FILE:
209  return myFilename;
210  case SUMO_ATTR_PROB:
211  return toString(myProbability);
214  case SUMO_ATTR_VTYPES:
215  return myVTypes;
216  case SUMO_ATTR_OFF:
217  return toString(myOff);
219  return toString(myBlockMovement);
220  case GNE_ATTR_SELECTED:
222  case GNE_ATTR_PARAMETERS:
223  return getParametersStr();
224  default:
225  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
226  }
227 }
228 
229 
230 double
232  switch (key) {
233  case SUMO_ATTR_PROB:
234  return myProbability;
235  default:
236  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
237  }
238 }
239 
240 
241 void
242 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
243  if (value == getAttribute(key)) {
244  return; //avoid needless changes, later logic relies on the fact that attributes have changed
245  }
246  switch (key) {
247  // special case for lanes due rerouter Symbols
248  case SUMO_ATTR_EDGES:
249  // rebuild rerouter Symbols
250  rebuildRerouterSymbols(value, undoList);
251  break;
252  case SUMO_ATTR_ID:
253  case SUMO_ATTR_POSITION:
254  case SUMO_ATTR_NAME:
255  case SUMO_ATTR_FILE:
256  case SUMO_ATTR_PROB:
258  case SUMO_ATTR_VTYPES:
259  case SUMO_ATTR_OFF:
261  case GNE_ATTR_SELECTED:
262  case GNE_ATTR_PARAMETERS:
263  undoList->p_add(new GNEChange_Attribute(this, key, value));
264  break;
265  default:
266  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
267  }
268 }
269 
270 
271 bool
272 GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
273  switch (key) {
274  case SUMO_ATTR_ID:
275  return isValidAdditionalID(value);
276  case SUMO_ATTR_EDGES:
277  return canParse<std::vector<GNEEdge*> >(myNet, value, false);
278  case SUMO_ATTR_POSITION:
279  return canParse<Position>(value);
280  case SUMO_ATTR_NAME:
282  case SUMO_ATTR_FILE:
284  case SUMO_ATTR_PROB:
285  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
287  return canParse<SUMOTime>(value);
288  case SUMO_ATTR_VTYPES:
289  if (value.empty()) {
290  return true;
291  } else {
293  }
294  case SUMO_ATTR_OFF:
295  return canParse<bool>(value);
297  return canParse<bool>(value);
298  case GNE_ATTR_SELECTED:
299  return canParse<bool>(value);
300  case GNE_ATTR_PARAMETERS:
301  return Parameterised::areParametersValid(value);
302  default:
303  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
304  }
305 }
306 
307 
308 bool
310  return true;
311 }
312 
313 
314 std::string
316  return getTagStr() + ": " + getID();
317 }
318 
319 
320 std::string
322  return getTagStr();
323 }
324 
325 // ===========================================================================
326 // private
327 // ===========================================================================
328 
329 void
330 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
331  switch (key) {
332  case SUMO_ATTR_EDGES:
333  throw InvalidArgument(getTagStr() + " cannot be edited");
334  case SUMO_ATTR_ID:
335  myNet->getAttributeCarriers()->updateID(this, value);
336  break;
337  case SUMO_ATTR_POSITION:
338  myPosition = parse<Position>(value);
339  // update boundary
341  break;
342  case SUMO_ATTR_NAME:
343  myAdditionalName = value;
344  break;
345  case SUMO_ATTR_FILE:
346  myFilename = value;
347  break;
348  case SUMO_ATTR_PROB:
349  myProbability = parse<double>(value);
350  break;
352  myTimeThreshold = parse<SUMOTime>(value);
353  break;
354  case SUMO_ATTR_VTYPES:
355  myVTypes = value;
356  break;
357  case SUMO_ATTR_OFF:
358  myOff = parse<bool>(value);
359  break;
361  myBlockMovement = parse<bool>(value);
362  break;
363  case GNE_ATTR_SELECTED:
364  if (parse<bool>(value)) {
366  } else {
368  }
369  break;
370  case GNE_ATTR_PARAMETERS:
371  setParametersStr(value);
372  break;
373  default:
374  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
375  }
376 }
377 
378 
379 void
381  // update position
382  myPosition = moveResult.shapeToUpdate.front();
383  // update geometry
384  updateGeometry();
385 }
386 
387 
388 void
390  undoList->p_begin("position of " + getTagStr());
391  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
392  undoList->p_end();
393 }
394 
395 
396 void
397 GNERerouter::rebuildRerouterSymbols(const std::string& value, GNEUndoList* undoList) {
398  undoList->p_begin(("change " + getTagStr() + " attribute").c_str());
399  // drop all additional children
400  while (getChildAdditionals().size() > 0) {
401  undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
402  }
403  // get edge vector
404  const std::vector<GNEEdge*> edges = parse<std::vector<GNEEdge*> >(myNet, value);
405  // create new VSS Symbols
406  for (const auto& edge : edges) {
407  // create VSS Symbol
408  GNEAdditional* VSSSymbol = new GNERerouterSymbol(this, edge);
409  // add it using GNEChange_Additional
410  myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
411  }
412  undoList->p_end();
413 }
414 
415 
416 /****************************************************************************/
@ GLO_REROUTER
a Rerouter
@ GNETEXTURE_REROUTER
Definition: GUITextures.h:40
@ GNETEXTURE_REROUTERSELECTED
Definition: GUITextures.h:41
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
long long int SUMOTime
Definition: SUMOTime.h:31
@ SUMO_TAG_REROUTER
A rerouter.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_FILE
@ SUMO_ATTR_EDGE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_OFF
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_HALTING_TIME_THRESHOLD
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
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
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
void update()
update Connection's geometry
void drawHierarchicalConnections(const GUIVisualizationSettings &s, const GNEAttributeCarrier *AC, const double exaggeration) const
Draw hierarchical connections between parent and children.
GNEGeometry::HierarchicalConnections myHierarchicalConnections
hierarchical connections
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1411
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1423
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
Dialog for edit rerouters.
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
SUMOTime myTimeThreshold
attribute to configure activation time threshold
Definition: GNERerouter.h:142
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
Definition: GNERerouter.cpp:59
GNERerouter(const std::string &id, GNENet *net, const Position &pos, const std::string &name, const std::string &filename, double probability, bool off, SUMOTime timeThreshold, const std::string &vTypes, bool blockMovement)
Constructor.
Definition: GNERerouter.cpp:38
std::string myVTypes
optional vehicle types for restricting the rerouter
Definition: GNERerouter.h:145
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
double getAttributeDouble(SumoXMLAttr key) const
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void rebuildRerouterSymbols(const std::string &value, GNEUndoList *undoList)
rebuild Rerouter Symbols
Position myPosition
position of rerouter in view
Definition: GNERerouter.h:130
bool myOff
attribute to enable or disable inactive initially
Definition: GNERerouter.h:139
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
double myProbability
probability of rerouter
Definition: GNERerouter.h:136
std::string getParentName() const
Returns the name of the parent object (if any)
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void openAdditionalDialog()
open GNERerouterDialog
~GNERerouter()
Destructor.
Definition: GNERerouter.cpp:54
std::string getAttribute(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
Definition: GNERerouter.cpp:80
bool isAttributeEnabled(SumoXMLAttr key) const
std::string myFilename
filename of rerouter
Definition: GNERerouter.h:133
void updateGeometry()
update pre-computed geometry information
Definition: GNERerouter.cpp:71
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlID getGlID() const
Returns the numerical id of the object.
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
GUIVisualizationSizeSettings addSize
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor RED
named colors
Definition: RGBColor.h:180
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name)
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
static const double rerouterSize
rerouter size
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values