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-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>
29 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNERerouter.h"
34 #include "GNERerouterInterval.h"
35 
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 GNERerouter::GNERerouter(const std::string& id, GNEViewNet* viewNet, const Position& pos, const std::vector<GNEEdge*>& edges, const std::string& name, const std::string& filename, double probability, bool off, double timeThreshold, const std::string& vTypes, bool blockMovement) :
42  GNEAdditional(id, viewNet, GLO_REROUTER, SUMO_TAG_REROUTER, name, blockMovement, edges),
43  myPosition(pos),
44  myFilename(filename),
45  myProbability(probability),
46  myOff(off),
47  myTimeThreshold(timeThreshold),
48  myVTypes(vTypes) {
49 }
50 
51 
53 }
54 
55 
56 void
57 GNERerouter::updateGeometry(bool updateGrid) {
58  // first check if object has to be removed from grid (SUMOTree)
59  if (updateGrid) {
61  }
62 
63  // Clear shape
64  myGeometry.shape.clear();
65 
66  // Set block icon position
68 
69  // Set block icon offset
70  myBlockIcon.offset = Position(-0.5, -0.5);
71 
72  // Set block icon rotation, and using their rotation for draw logo
74 
75  // Set position
76  myGeometry.shape.push_back(myPosition);
77 
78  // update connection positions
80 
81  // last step is to check if object has to be added into grid (SUMOTree) again
82  if (updateGrid) {
84  }
85 }
86 
87 
90  return myPosition;
91 }
92 
93 
94 void
96  // Open rerouter dialog
97  GNERerouterDialog(this);
98 }
99 
100 
101 void
103  // restore old position, apply offset and update Geometry
105  myPosition.add(offset);
106  // filtern position using snap to active grid
108  updateGeometry(false);
109 }
110 
111 
112 void
114  // commit new position allowing undo/redo
115  undoList->p_begin("position of " + getTagStr());
117  undoList->p_end();
118 }
119 
120 
121 std::string
123  return myViewNet->getNet()->getMicrosimID();
124 }
125 
126 
127 void
129  // Start drawing adding an gl identificator
130  glPushName(getGlID());
131 
132  // Add a draw matrix for drawing logo
133  glPushMatrix();
134  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), getType());
135 
136 
137  // Draw icon depending of detector is selected and if isn't being drawn for selecting
138  if (s.drawForSelecting) {
140  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
141  } else {
142  glColor3d(1, 1, 1);
143  glRotated(180, 0, 0, 1);
146  } else {
148  }
149  }
150 
151  // Pop draw matrix
152  glPopMatrix();
153 
154  // Only lock and childs if isn't being drawn for selecting
155  if (!s.drawForSelecting) {
156 
157  // Show Lock icon depending of the Edit mode
158  myBlockIcon.draw(0.4);
159 
160  // Draw symbols in every lane
161  const double exaggeration = s.addSize.getExaggeration(s, this);
162 
163  if (s.scale * exaggeration >= 3) {
164  // draw rerouter symbol over all lanes
166  glPushMatrix();
167  glTranslated(i.first.x(), i.first.y(), getType());
168  glRotated(-1 * i.second, 0, 0, 1);
169  glScaled(exaggeration, exaggeration, 1);
170  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
171 
172  glBegin(GL_TRIANGLES);
173  glColor3d(1, .8f, 0);
174  // base
175  glVertex2d(0 - 1.4, 0);
176  glVertex2d(0 - 1.4, 6);
177  glVertex2d(0 + 1.4, 6);
178  glVertex2d(0 + 1.4, 0);
179  glVertex2d(0 - 1.4, 0);
180  glVertex2d(0 + 1.4, 6);
181  glEnd();
182 
183  // draw "U"
184  GLHelper::drawText("U", Position(0, 2), .1, 3, RGBColor::BLACK, 180);
185 
186  // draw Probability
187  GLHelper::drawText((toString((int)(myProbability * 100)) + "%").c_str(), Position(0, 4), .1, 0.7, RGBColor::BLACK, 180);
188 
189  glPopMatrix();
190  }
191  }
192 
193  // Draw connections
195  }
196  // check if dotted contour has to be drawn
197  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
199  // draw shape dotte contour aroud alld connections between child and parents
200  for (auto i : myChildConnections.connectionPositions) {
202  }
203  // draw rerouter symbol over all lanes
205  GLHelper::drawShapeDottedContour(getType(), i.first, 2.8, 6, -1 * i.second, 0, 3);
206  }
207  }
208 
209  // Draw name
210  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
211 
212  // Pop name
213  glPopName();
214 }
215 
216 
217 std::string
219  switch (key) {
220  case SUMO_ATTR_ID:
221  return getAdditionalID();
222  case SUMO_ATTR_EDGES:
223  return parseIDs(myEdgeChilds);
224  case SUMO_ATTR_POSITION:
225  return toString(myPosition);
226  case SUMO_ATTR_NAME:
227  return myAdditionalName;
228  case SUMO_ATTR_FILE:
229  return myFilename;
230  case SUMO_ATTR_PROB:
231  return toString(myProbability);
233  return toString(myTimeThreshold);
234  case SUMO_ATTR_VTYPES:
235  return myVTypes;
236  case SUMO_ATTR_OFF:
237  return toString(myOff);
239  return toString(myBlockMovement);
240  case GNE_ATTR_SELECTED:
242  case GNE_ATTR_GENERIC:
243  return getGenericParametersStr();
244  default:
245  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
246  }
247 }
248 
249 
250 void
251 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
252  if (value == getAttribute(key)) {
253  return; //avoid needless changes, later logic relies on the fact that attributes have changed
254  }
255  switch (key) {
256  case SUMO_ATTR_ID: {
257  // change ID of Rerouter Interval
258  undoList->p_add(new GNEChange_Attribute(this, key, value));
259  // Change Ids of all Rerouter interval childs
260  for (auto i : myAdditionalChilds) {
261  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(SUMO_TAG_INTERVAL), undoList);
262  }
263  break;
264  }
265  case SUMO_ATTR_EDGES:
266  case SUMO_ATTR_POSITION:
267  case SUMO_ATTR_NAME:
268  case SUMO_ATTR_FILE:
269  case SUMO_ATTR_PROB:
271  case SUMO_ATTR_VTYPES:
272  case SUMO_ATTR_OFF:
274  case GNE_ATTR_SELECTED:
275  case GNE_ATTR_GENERIC:
276  undoList->p_add(new GNEChange_Attribute(this, key, value));
277  break;
278  default:
279  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
280  }
281 }
282 
283 
284 bool
285 GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
286  switch (key) {
287  case SUMO_ATTR_ID:
288  return isValidAdditionalID(value);
289  case SUMO_ATTR_EDGES:
290  if (value.empty()) {
291  return false;
292  } else {
293  return canParse<std::vector<GNEEdge*> >(myViewNet->getNet(), value, false);
294  }
295  case SUMO_ATTR_POSITION:
296  return canParse<Position>(value);
297  case SUMO_ATTR_NAME:
299  case SUMO_ATTR_FILE:
301  case SUMO_ATTR_PROB:
302  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
304  return canParse<double>(value) && (parse<double>(value) >= 0);
305  case SUMO_ATTR_VTYPES:
306  if (value.empty()) {
307  return true;
308  } else {
310  }
311  case SUMO_ATTR_OFF:
312  return canParse<bool>(value);
314  return canParse<bool>(value);
315  case GNE_ATTR_SELECTED:
316  return canParse<bool>(value);
317  case GNE_ATTR_GENERIC:
318  return isGenericParametersValid(value);
319  default:
320  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
321  }
322 }
323 
324 
325 std::string
327  return getTagStr() + ": " + getID();
328 }
329 
330 
331 std::string
333  return getTagStr();
334 }
335 
336 // ===========================================================================
337 // private
338 // ===========================================================================
339 
340 void
341 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
342  switch (key) {
343  case SUMO_ATTR_ID:
344  changeAdditionalID(value);
345  break;
346  case SUMO_ATTR_EDGES: {
347  // remove references of this rerouter in all edge childs
348  for (auto i : myEdgeChilds) {
349  i->removeAdditionalParent(this);
350  }
351  // set new edges
352  myEdgeChilds = parse<std::vector<GNEEdge*> >(myViewNet->getNet(), value);
353  // add references to this rerouter in all newedge childs
354  for (auto i : myEdgeChilds) {
355  i->addAdditionalParent(this);
356  }
357  break;
358  }
359  case SUMO_ATTR_POSITION:
360  myPosition = parse<Position>(value);
361  break;
362  case SUMO_ATTR_NAME:
363  myAdditionalName = value;
364  break;
365  case SUMO_ATTR_FILE:
366  myFilename = value;
367  break;
368  case SUMO_ATTR_PROB:
369  myProbability = parse<double>(value);
370  break;
372  myTimeThreshold = parse<double>(value);
373  break;
374  case SUMO_ATTR_VTYPES:
375  myVTypes = value;
376  break;
377  case SUMO_ATTR_OFF:
378  myOff = parse<bool>(value);
379  break;
381  myBlockMovement = parse<bool>(value);
382  break;
383  case GNE_ATTR_SELECTED:
384  if (parse<bool>(value)) {
386  } else {
388  }
389  break;
390  case GNE_ATTR_GENERIC:
392  break;
393  default:
394  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
395  }
396  // Update Geometry after setting a new attribute (but avoided for certain attributes)
397  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
398  updateGeometry(true);
399  }
400 }
401 
402 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
double scale
information about a lane&#39;s width (temporary, used for a single view)
~GNERerouter()
Destructor.
Definition: GNERerouter.cpp:52
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (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&#39;t allowed) ...
GUIVisualizationTextSettings addName
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
const std::string & getAdditionalID() const
returns Additional ID
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERerouter.cpp:89
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
Position myPosition
position of rerouter in view
Definition: GNERerouter.h:126
static void drawText(const std::string &text, const Position &pos, const double layer, const double size, const RGBColor &col=RGBColor::BLACK, const double angle=0, int align=0, double width=-1)
Definition: GLHelper.cpp:611
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
bool myOff
attribute to enable or disable inactive initially
Definition: GNERerouter.h:135
BlockIcon myBlockIcon
variable BlockIcon
Position originalViewPosition
value for saving first original position over lane before moving
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:73
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
GNERerouter(const std::string &id, GNEViewNet *viewNet, const Position &pos, const std::vector< GNEEdge *> &edges, const std::string &name, const std::string &filename, double probability, bool off, double timeThreshold, const std::string &vTypes, bool blockMovement)
Constructor.
Definition: GNERerouter.cpp:41
static const RGBColor BLACK
Definition: RGBColor.h:192
double myProbability
probability of rerouter
Definition: GNERerouter.h:132
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
std::vector< std::pair< Position, double > > symbolsPositionAndRotation
position and rotation of every symbol over lane
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
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 ...
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
GUIVisualizationSizeSettings addSize
Dialog for edit rerouters.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void draw() const
draw connections between Parent and childrens
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
std::string myFilename
filename of rerouter
Definition: GNERerouter.h:129
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:80
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
PositionVector shape
The shape of the additional element.
std::string myAdditionalName
name of additional
std::vector< PositionVector > connectionPositions
Matrix with the Vertex&#39;s positions of connections between parents an their childs.
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
ChildConnections myChildConnections
variable ChildConnections
a Rerouter
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
const std::string getID() const
function to support debugging
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse) ...
std::vector< GNEAdditional * > myAdditionalChilds
vector with the Additional childs
std::string myVTypes
optional vehicle types for restricting the rerouter
Definition: GNERerouter.h:141
static const RGBColor RED
named colors
Definition: RGBColor.h:184
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
static void drawShapeDottedContour(const int type, const PositionVector &shape, const double width)
draw a dotted contour around the given Non closed shape with certain width
Definition: GLHelper.cpp:471
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
AdditionalGeometry myGeometry
geometry to be precomputed in updateGeometry(...)
const std::string & getTagStr() const
get tag assigned to this object in string format
element is selected
void updateGeometry(bool updateGrid)
update pre-computed geometry information
Definition: GNERerouter.cpp:57
std::string getGenericParametersStr() const
return generic parameters in string format
std::string getParentName() const
Returns the name of the parent object (if any)
GNENet * getNet() const
get the net object
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
GUIGlID getGlID() const
Returns the numerical id of the object.
an aggreagated-output interval
void update()
update Connection&#39;s geometry
double myTimeThreshold
attribute to configure activation time threshold
Definition: GNERerouter.h:138
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:132
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1153
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
void openAdditionalDialog()
open GNERerouterDialog
Definition: GNERerouter.cpp:95
void draw(double size=0.5) const
draw lock icon
std::vector< GNEEdge * > myEdgeChilds
vector with the edge childs of this additional