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-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 /****************************************************************************/
15 //
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
27 #include <utils/gui/div/GLHelper.h>
30 
31 #include "GNERerouter.h"
32 
33 
34 // ===========================================================================
35 // member method definitions
36 // ===========================================================================
37 
38 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, SUMOTime timeThreshold, const std::string& vTypes, bool blockMovement) :
39  GNEAdditional(id, viewNet, GLO_REROUTER, SUMO_TAG_REROUTER, name, blockMovement, {}, {}, {}, {}, {}, edges, {}, {}, {}, {}),
40  myPosition(pos),
41  myFilename(filename),
42  myProbability(probability),
43  myOff(off),
44  myTimeThreshold(timeThreshold),
45 myVTypes(vTypes) {
46 }
47 
48 
50 }
51 
52 
53 void
55  // Set block icon position
57 
58  // Set block icon offset
59  myBlockIcon.offset = Position(-0.5, -0.5);
60 
61  // Set block icon rotation, and using their rotation for draw logo
63 
64  // update connection positions
66 }
67 
68 
71  return myPosition;
72 }
73 
74 
77  // Return Boundary depending if myMovingGeometryBoundary is initialised (important for move geometry)
80  } else {
81  Boundary b;
82  b.add(myPosition);
83  b.grow(5);
84  return b;
85  }
86 }
87 
88 
89 void
91  // Open rerouter dialog
92  GNERerouterDialog(this);
93 }
94 
95 
96 void
98  // restore old position, apply offset and update Geometry
100  myPosition.add(offset);
101  // filtern position using snap to active grid
103  updateGeometry();
104 }
105 
106 
107 void
109  // commit new position allowing undo/redo
110  undoList->p_begin("position of " + getTagStr());
112  undoList->p_end();
113 }
114 
115 
116 std::string
118  return myViewNet->getNet()->getMicrosimID();
119 }
120 
121 
122 void
124  // Obtain exaggeration of the draw
125  const double exaggeration = s.addSize.getExaggeration(s, this);
126  // check if boundary has to be drawn
127  if (s.drawBoundaries) {
129  }
130  // Start drawing adding an gl identificator
131  glPushName(getGlID());
132  // Add a draw matrix for drawing logo
133  glPushMatrix();
134  glTranslated(myPosition.x(), myPosition.y(), getType());
135  // Draw icon depending of detector is selected and if isn't being drawn for selecting
136  if (!s.drawForSelecting && s.drawDetail(s.detailSettings.laneTextures, exaggeration)) {
137  glColor3d(1, 1, 1);
138  glRotated(180, 0, 0, 1);
139  if (drawUsingSelectColor()) {
141  } else {
143  }
144  } else {
146  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
147  }
148  // Pop draw matrix
149  glPopMatrix();
150  // Show Lock icon
151  myBlockIcon.drawIcon(s, exaggeration, 0.4);
152  // Draw child connections
154  // check if dotted contour has to be drawn
155  if (myViewNet->getDottedAC() == this) {
157  // draw shape dotte contour aroud alld connections between child and parents
158  for (auto i : myChildConnections.connectionPositions) {
160  }
161  }
162  // Draw name
164  // Pop name
165  glPopName();
166 }
167 
168 
169 std::string
171  switch (key) {
172  case SUMO_ATTR_ID:
173  return getAdditionalID();
174  case SUMO_ATTR_EDGES:
175  return parseIDs(getEdgeChildren());
176  case SUMO_ATTR_POSITION:
177  return toString(myPosition);
178  case SUMO_ATTR_NAME:
179  return myAdditionalName;
180  case SUMO_ATTR_FILE:
181  return myFilename;
182  case SUMO_ATTR_PROB:
183  return toString(myProbability);
186  case SUMO_ATTR_VTYPES:
187  return myVTypes;
188  case SUMO_ATTR_OFF:
189  return toString(myOff);
191  return toString(myBlockMovement);
192  case GNE_ATTR_SELECTED:
194  case GNE_ATTR_GENERIC:
195  return getGenericParametersStr();
196  default:
197  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
198  }
199 }
200 
201 
202 void
203 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
204  if (value == getAttribute(key)) {
205  return; //avoid needless changes, later logic relies on the fact that attributes have changed
206  }
207  switch (key) {
208  case SUMO_ATTR_ID: {
209  // change ID of Rerouter Interval
210  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
211  // Change Ids of all Rerouter interval children
212  for (auto i : getAdditionalChildren()) {
213  i->setAttribute(SUMO_ATTR_ID, generateChildID(SUMO_TAG_INTERVAL), undoList);
214  }
215  break;
216  }
217  case SUMO_ATTR_EDGES:
218  case SUMO_ATTR_POSITION:
219  case SUMO_ATTR_NAME:
220  case SUMO_ATTR_FILE:
221  case SUMO_ATTR_PROB:
223  case SUMO_ATTR_VTYPES:
224  case SUMO_ATTR_OFF:
226  case GNE_ATTR_SELECTED:
227  case GNE_ATTR_GENERIC:
228  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
229  break;
230  default:
231  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
232  }
233 }
234 
235 
236 bool
237 GNERerouter::isValid(SumoXMLAttr key, const std::string& value) {
238  switch (key) {
239  case SUMO_ATTR_ID:
240  return isValidAdditionalID(value);
241  case SUMO_ATTR_EDGES:
242  if (value.empty()) {
243  return false;
244  } else {
245  return canParse<std::vector<GNEEdge*> >(myViewNet->getNet(), value, false);
246  }
247  case SUMO_ATTR_POSITION:
248  return canParse<Position>(value);
249  case SUMO_ATTR_NAME:
251  case SUMO_ATTR_FILE:
253  case SUMO_ATTR_PROB:
254  return canParse<double>(value) && (parse<double>(value) >= 0) && (parse<double>(value) <= 1);
256  return canParse<SUMOTime>(value);
257  case SUMO_ATTR_VTYPES:
258  if (value.empty()) {
259  return true;
260  } else {
262  }
263  case SUMO_ATTR_OFF:
264  return canParse<bool>(value);
266  return canParse<bool>(value);
267  case GNE_ATTR_SELECTED:
268  return canParse<bool>(value);
269  case GNE_ATTR_GENERIC:
270  return isGenericParametersValid(value);
271  default:
272  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
273  }
274 }
275 
276 
277 std::string
279  return getTagStr() + ": " + getID();
280 }
281 
282 
283 std::string
285  return getTagStr();
286 }
287 
288 // ===========================================================================
289 // private
290 // ===========================================================================
291 
292 void
293 GNERerouter::setAttribute(SumoXMLAttr key, const std::string& value) {
294  switch (key) {
295  case SUMO_ATTR_ID:
296  changeAdditionalID(value);
297  break;
298  case SUMO_ATTR_EDGES:
299  changeEdgeChildren(this, value);
300  break;
301  case SUMO_ATTR_POSITION:
303  myPosition = parse<Position>(value);
305  break;
306  case SUMO_ATTR_NAME:
307  myAdditionalName = value;
308  break;
309  case SUMO_ATTR_FILE:
310  myFilename = value;
311  break;
312  case SUMO_ATTR_PROB:
313  myProbability = parse<double>(value);
314  break;
316  myTimeThreshold = parse<SUMOTime>(value);
317  break;
318  case SUMO_ATTR_VTYPES:
319  myVTypes = value;
320  break;
321  case SUMO_ATTR_OFF:
322  myOff = parse<bool>(value);
323  break;
325  myBlockMovement = parse<bool>(value);
326  break;
327  case GNE_ATTR_SELECTED:
328  if (parse<bool>(value)) {
330  } else {
332  }
333  break;
334  case GNE_ATTR_GENERIC:
336  break;
337  default:
338  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
339  }
340 }
341 
342 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
long long int SUMOTime
Definition: SUMOTime.h:35
double scale
information about a lane&#39;s width (temporary, used for a single view)
~GNERerouter()
Destructor.
Definition: GNERerouter.cpp:49
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
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
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
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Stores the information about how to visualize structures.
const std::vector< GNEEdge * > & getEdgeChildren() const
get edge chidls
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
std::string getAttribute(SumoXMLAttr key) const
Position getPositionInView() const
Returns position of additional in view.
Definition: GNERerouter.cpp:70
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
double x() const
Returns the x-position.
Definition: Position.h:57
Position myPosition
position of rerouter in view
Definition: GNERerouter.h:129
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
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:138
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.
double myProbability
probability of rerouter
Definition: GNERerouter.h:135
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
AdditionalMove myMove
variable AdditionalMove
ChildConnections myChildConnections
variable ChildConnections
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:812
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
Definition: GNERerouter.cpp:97
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
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:48
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
std::string myFilename
filename of rerouter
Definition: GNERerouter.h:132
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
std::string myAdditionalName
name of additional
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:1279
friend class GNEChange_Attribute
declare friend class
void selectAttributeCarrier(bool changeFlag=true)
block movement of a graphic element
static const double laneTextures
details for lane textures
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
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) ...
static void drawShapeDottedContourAroundShape(const GUIVisualizationSettings &s, 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:461
std::string myVTypes
optional vehicle types for restricting the rerouter
Definition: GNERerouter.h:144
static void drawShapeDottedContourRectangle(const GUIVisualizationSettings &s, const int type, const Position &center, const double width, const double height, const double rotation=0, const double offsetX=0, const double offsetY=0)
draw a dotted contour around the given Position with certain width and height
Definition: GLHelper.cpp:555
GUIVisualizationDetailSettings detailSettings
detail settings
std::vector< PositionVector > connectionPositions
Matrix with the Vertex&#39;s positions of connections between parents an their children.
static const RGBColor RED
named colors
Definition: RGBColor.h:190
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void drawChildConnections(const GUIVisualizationSettings &s, const GUIGlObjectType GLTypeParent) const
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
const std::string & getTagStr() const
get tag assigned to this object in string format
Boundary movingGeometryBoundary
boundary used during moving of elements (to avoid insertion in RTREE
element is selected
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:217
std::string getGenericParametersStr() const
return generic parameters in string format
std::string getParentName() const
Returns the name of the parent object (if any)
void updateGeometry()
update pre-computed geometry information
Definition: GNERerouter.cpp:54
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GUIGlID getGlID() const
Returns the numerical id of the object.
an aggreagated-output interval
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
void changeEdgeChildren(GNEAdditional *elementChild, const std::string &newEdgeIDs)
change edge children of an additional
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNERerouter.cpp:76
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
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:1273
static bool isValidFilename(const std::string &value)
whether the given string is a valid attribute for a filename (for example, a name) ...
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, SUMOTime timeThreshold, const std::string &vTypes, bool blockMovement)
Constructor.
Definition: GNERerouter.cpp:38
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
bool drawBoundaries
enable or disable draw boundaries
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
void openAdditionalDialog()
open GNERerouterDialog
Definition: GNERerouter.cpp:90
SUMOTime myTimeThreshold
attribute to configure activation time threshold
Definition: GNERerouter.h:141