Eclipse SUMO - Simulation of Urban MObility
GNEVariableSpeedSign.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 #include <config.h>
22 
24 #include <utils/gui/div/GLHelper.h>
27 #include <netedit/GNEViewNet.h>
28 #include <netedit/GNEUndoList.h>
29 #include <netedit/GNENet.h>
31 
32 #include "GNEVariableSpeedSign.h"
33 
34 
35 // ===========================================================================
36 // member method definitions
37 // ===========================================================================
38 
39 GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNEViewNet* viewNet, const Position& pos, const std::vector<GNELane*>& lanes, const std::string& name, bool blockMovement) :
40  GNEAdditional(id, viewNet, GLO_VSS, SUMO_TAG_VSS, name, blockMovement, {}, {}, {}, {}, {}, {}, lanes, {}, {}, {}),
41 myPosition(pos) {
42 }
43 
44 
46 }
47 
48 
49 void
51  // Set block icon position
53 
54  // Set block icon offset
55  myBlockIcon.offset = Position(-0.5, -0.5);
56 
57  // Set block icon rotation, and using their rotation for draw logo
59 
60  // update child connections
62 }
63 
64 
67  return myPosition;
68 }
69 
70 
73  // Return Boundary depending if myMovingGeometryBoundary is initialised (important for move geometry)
76  } else {
77  Boundary b;
78  b.add(myPosition);
79  b.grow(5);
80  return b;
81  }
82 }
83 
84 
85 void
87  // Open VSS dialog
89 }
90 
91 
92 void
94  // restore old position, apply offset and update Geometry
96  myPosition.add(offset);
97  // filtern position using snap to active grid
100 }
101 
102 
103 void
105  // commit new position allowing undo/redo
106  undoList->p_begin("position of " + getTagStr());
108  undoList->p_end();
109 }
110 
111 
112 std::string
114  return myViewNet->getNet()->getMicrosimID();
115 }
116 
117 
118 void
120  // obtain exaggeration
121  const double exaggeration = s.addSize.getExaggeration(s, this);
122  // check if boundary has to be drawn
123  if (s.drawBoundaries) {
125  }
126  // Start drawing adding an gl identificator
127  glPushName(getGlID());
128  // Add a draw matrix for drawing logo
129  glPushMatrix();
130  glTranslated(myPosition.x(), myPosition.y(), getType());
131  // Draw icon depending of variable speed sign is or if isn't being drawn for selecting
132  if (!s.drawForSelecting && s.drawDetail(s.detailSettings.laneTextures, exaggeration)) {
133  glColor3d(1, 1, 1);
134  glRotated(180, 0, 0, 1);
135  if (drawUsingSelectColor()) {
137  } else {
139  }
140  } else {
142  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
143 
144  }
145  // Pop draw icon matrix
146  glPopMatrix();
147  // Show Lock icon
148  myBlockIcon.drawIcon(s, exaggeration, 0.4);
149  // Draw child connections
151  // Draw name if isn't being drawn for selecting
152  if (!s.drawForSelecting) {
154  }
155  // check if dotted contour has to be drawn
156  if (myViewNet->getDottedAC() == this) {
158  // draw shape dotte contour aroud alld connections between child and parents
159  for (auto i : myChildConnections.connectionPositions) {
161  }
162  }
163  // Pop name
164  glPopName();
165 }
166 
167 
168 std::string
170  switch (key) {
171  case SUMO_ATTR_ID:
172  return getAdditionalID();
173  case SUMO_ATTR_LANES:
174  return parseIDs(getLaneChildren());
175  case SUMO_ATTR_POSITION:
176  return toString(myPosition);
177  case SUMO_ATTR_NAME:
178  return myAdditionalName;
180  return toString(myBlockMovement);
181  case GNE_ATTR_SELECTED:
183  case GNE_ATTR_GENERIC:
184  return getGenericParametersStr();
185  default:
186  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
187  }
188 }
189 
190 
191 void
192 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
193  if (value == getAttribute(key)) {
194  return; //avoid needless changes, later logic relies on the fact that attributes have changed
195  }
196  switch (key) {
197  case SUMO_ATTR_ID: {
198  // change ID of Rerouter Interval
199  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
200  // Change Ids of all Variable Speed Sign
201  for (auto i : getAdditionalChildren()) {
202  i->setAttribute(SUMO_ATTR_ID, generateChildID(SUMO_TAG_STEP), undoList);
203  }
204  break;
205  }
206  case SUMO_ATTR_LANES:
207  case SUMO_ATTR_POSITION:
208  case SUMO_ATTR_NAME:
210  case GNE_ATTR_SELECTED:
211  case GNE_ATTR_GENERIC:
212  undoList->p_add(new GNEChange_Attribute(this, myViewNet->getNet(), key, value));
213  break;
214  default:
215  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
216  }
217 }
218 
219 
220 bool
221 GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
222  switch (key) {
223  case SUMO_ATTR_ID:
224  return isValidAdditionalID(value);
225  case SUMO_ATTR_POSITION:
226  return canParse<Position>(value);
227  case SUMO_ATTR_LANES:
228  if (value.empty()) {
229  return false;
230  } else {
231  return canParse<std::vector<GNELane*> >(myViewNet->getNet(), value, false);
232  }
233  case SUMO_ATTR_NAME:
236  return canParse<bool>(value);
237  case GNE_ATTR_SELECTED:
238  return canParse<bool>(value);
239  case GNE_ATTR_GENERIC:
240  return isGenericParametersValid(value);
241  default:
242  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
243  }
244 }
245 
246 
247 std::string
249  return getTagStr() + ": " + getID();
250 }
251 
252 
253 std::string
255  return getTagStr();
256 }
257 
258 // ===========================================================================
259 // private
260 // ===========================================================================
261 
262 void
263 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
264  switch (key) {
265  case SUMO_ATTR_ID:
266  changeAdditionalID(value);
267  break;
268  case SUMO_ATTR_LANES:
269  changeLaneChildren(this, value);
270  break;
271  case SUMO_ATTR_POSITION:
273  myPosition = parse<Position>(value);
275  break;
276  case SUMO_ATTR_NAME:
277  myAdditionalName = value;
278  break;
280  myBlockMovement = parse<bool>(value);
281  break;
282  case GNE_ATTR_SELECTED:
283  if (parse<bool>(value)) {
285  } else {
287  }
288  break;
289  case GNE_ATTR_GENERIC:
291  break;
292  default:
293  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
294  }
295 }
296 
297 /****************************************************************************/
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.
double scale
information about a lane&#39;s width (temporary, used for a single view)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
GUIVisualizationTextSettings addName
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
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
a Variable Speed Sign
const std::string & getAdditionalID() const
static const RGBColor WHITE
Definition: RGBColor.h:197
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
std::string getParentName() const
Returns the name of the parent object.
Stores the information about how to visualize structures.
Position offset
The offSet of the block icon.
double y() const
Returns the y-position.
Definition: Position.h:62
void openAdditionalDialog()
open GNEVariableSpeedSignDialog
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
const std::vector< GNELane * > & getLaneChildren() const
get lanes of VSS
double x() const
Returns the x-position.
Definition: Position.h:57
void changeLaneChildren(GNEAdditional *elementChild, const std::string &newEdgeIDs)
change edge children of an additional
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position position
position of the block icon
BlockIcon myBlockIcon
variable BlockIcon
Position getPositionInView() const
Returns position of additional in view.
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.
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
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
GUIVisualizationSizeSettings addSize
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
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
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
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
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
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void updateGeometry()
update pre-computed geometry information
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
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
std::string getAttribute(SumoXMLAttr key) const
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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
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.
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
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
~GNEVariableSpeedSign()
Destructor.
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNEVariableSpeedSign(const std::string &id, GNEViewNet *viewNet, const Position &pos, const std::vector< GNELane *> &lanes, const std::string &name, bool blockMovement)
Constructor.
GUIGlID getGlID() const
Returns the numerical id of the object.
A variable speed sign.
Position myPosition
position of VSS in view
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:136
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
bool drawBoundaries
enable or disable draw boundaries
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
trigger: a step description