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-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 #include <config.h>
22 
23 #include <string>
24 #include <iostream>
25 #include <utility>
30 #include <utils/common/ToString.h>
31 #include <utils/geom/GeomHelper.h>
36 #include <utils/gui/div/GLHelper.h>
43 #include <netedit/GNEViewParent.h>
44 #include <netedit/GNEViewNet.h>
45 #include <netedit/GNEUndoList.h>
46 #include <netedit/GNENet.h>
47 
48 #include "GNEVariableSpeedSign.h"
50 
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
55 
56 GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNEViewNet* viewNet, const Position& pos, const std::vector<GNELane*>& lanes, const std::string& name, bool blockMovement) :
57  GNEAdditional(id, viewNet, GLO_VSS, SUMO_TAG_VSS, name, blockMovement, lanes),
58  myPosition(pos) {
59 }
60 
61 
63 }
64 
65 
66 void
68  // first check if object has to be removed from grid (SUMOTree)
69  if (updateGrid) {
71  }
72 
73  // Clear shape
74  myShape.clear();
75 
76  // Set block icon position
78 
79  // Set block icon offset
80  myBlockIconOffset = Position(-0.5, -0.5);
81 
82  // Set block icon rotation, and using their rotation for draw logo
84 
85  // Set position
86  myShape.push_back(myPosition);
87 
88  // clear mySymbolsPositionAndRotation
90 
91  // update child connections
93 
94  // last step is to check if object has to be added into grid (SUMOTree) again
95  if (updateGrid) {
97  }
98 }
99 
100 
101 Position
103  return myPosition;
104 }
105 
106 
107 void
109  // Open VSS dialog
111 }
112 
113 
114 void
115 GNEVariableSpeedSign::moveGeometry(const Position& oldPos, const Position& offset) {
116  // restore old position, apply offset and update Geometry
117  myPosition = oldPos;
118  myPosition.add(offset);
119  updateGeometry(false);
120 }
121 
122 
123 void
125  // commit new position allowing undo/redo
126  undoList->p_begin("position of " + toString(getTag()));
127  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(myPosition), true, toString(oldPos)));
128  undoList->p_end();
129 }
130 
131 
132 std::string
134  return myViewNet->getNet()->getMicrosimID();
135 }
136 
137 
138 void
140  // Start drawing adding an gl identificator
141  glPushName(getGlID());
142 
143  // Add a draw matrix for drawing logo
144  glPushMatrix();
145  glTranslated(myShape[0].x(), myShape[0].y(), getType());
146 
147  // Draw icon depending of variable speed sign is or if isn't being drawn for selecting
148  if (s.drawForSelecting) {
150  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
151  } else {
152  glColor3d(1, 1, 1);
153  glRotated(180, 0, 0, 1);
156  } else {
158  }
159  }
160 
161  // Pop draw icon matrix
162  glPopMatrix();
163 
164  // Only lock and childs if isn't being drawn for selecting
165  if (!s.drawForSelecting) {
166 
167  // Show Lock icon depending of the Edit mode
168  drawLockIcon(0.4);
169 
170  // obtain exxageration
171  const double exaggeration = s.addSize.getExaggeration(s);
172 
173  // iterate over symbols and rotation
174  for (auto i : mySymbolsPositionAndRotation) {
175  glPushMatrix();
176  glScaled(exaggeration, exaggeration, 1);
177  glTranslated(i.first.x(), i.first.y(), getType());
178  glRotated(-1 * i.second, 0, 0, 1);
179  glTranslated(0, -1.5, 0);
180 
181  int noPoints = 9;
182  if (s.scale > 25) {
183  noPoints = (int)(9.0 + s.scale / 10.0);
184  if (noPoints > 36) {
185  noPoints = 36;
186  }
187  }
188  glColor3d(1, 0, 0);
189  GLHelper::drawFilledCircle((double) 1.3, noPoints);
190  if (s.scale >= 5) {
191  glTranslated(0, 0, .1);
192  glColor3d(0, 0, 0);
193  GLHelper::drawFilledCircle((double) 1.1, noPoints);
194  // draw the speed string
195  //draw
196  glColor3d(1, 1, 0);
197  glTranslated(0, 0, .1);
198  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
199 
200  // draw last value string
201  GLHelper::drawText("S", Position(0, 0), .1, 1.2, RGBColor(255, 255, 0), 180);
202  }
203  glPopMatrix();
204  }
205 
206  // Draw connections
208  }
209 
210  // Pop symbol matrix
211  glPopMatrix();
212 
213  // Draw name if isn't being drawn for selecting
214  if (!s.drawForSelecting) {
215  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
216  }
217 
218  // check if dotted contour has to be drawn
219  if (!s.drawForSelecting && (myViewNet->getACUnderCursor() == this)) {
221  // draw shape dotte contour aroud alld connections between child and parents
222  for (auto i : myChildConnectionPositions) {
224  }
225  // draw rerouter symbol over all lanes
226  for (auto i : mySymbolsPositionAndRotation) {
227  GLHelper::drawShapeDottedContour(getType(), i.first, 2.6, 2.6, -1 * i.second, 0, -1.5);
228  }
229  }
230 
231  // Pop name
232  glPopName();
233 }
234 
235 
236 std::string
238  switch (key) {
239  case SUMO_ATTR_ID:
240  return getAdditionalID();
241  case SUMO_ATTR_LANES:
242  return parseIDs(myLaneChilds);
243  case SUMO_ATTR_POSITION:
244  return toString(myPosition);
245  case SUMO_ATTR_NAME:
246  return myAdditionalName;
248  return toString(myBlockMovement);
249  case GNE_ATTR_SELECTED:
251  case GNE_ATTR_GENERIC:
252  return getGenericParametersStr();
253  default:
254  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
255  }
256 }
257 
258 
259 void
260 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
261  if (value == getAttribute(key)) {
262  return; //avoid needless changes, later logic relies on the fact that attributes have changed
263  }
264  switch (key) {
265  case SUMO_ATTR_ID: {
266  // change ID of Rerouter Interval
267  undoList->p_add(new GNEChange_Attribute(this, key, value));
268  // Change Ids of all Variable Speed Sign
269  for (auto i : myAdditionalChilds) {
270  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(SUMO_TAG_STEP), undoList);
271  }
272  break;
273  }
274  case SUMO_ATTR_LANES:
275  case SUMO_ATTR_POSITION:
276  case SUMO_ATTR_NAME:
278  case GNE_ATTR_SELECTED:
279  case GNE_ATTR_GENERIC:
280  undoList->p_add(new GNEChange_Attribute(this, key, value));
281  break;
282  default:
283  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
284  }
285 }
286 
287 
288 bool
289 GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
290  switch (key) {
291  case SUMO_ATTR_ID:
292  return isValidAdditionalID(value);
293  case SUMO_ATTR_POSITION:
294  return canParse<Position>(value);
295  case SUMO_ATTR_LANES:
296  if (value.empty()) {
297  return false;
298  } else {
299  return canParse<std::vector<GNELane*> >(myViewNet->getNet(), value, false);
300  }
301  case SUMO_ATTR_NAME:
304  return canParse<bool>(value);
305  case GNE_ATTR_SELECTED:
306  return canParse<bool>(value);
307  case GNE_ATTR_GENERIC:
308  return isGenericParametersValid(value);
309  default:
310  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
311  }
312 }
313 
314 
315 std::string
317  return toString(getTag()) + ": " + getID();
318 }
319 
320 
321 std::string
323  return toString(getTag());
324 }
325 
326 // ===========================================================================
327 // private
328 // ===========================================================================
329 
330 void
331 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
332  switch (key) {
333  case SUMO_ATTR_ID:
334  changeAdditionalID(value);
335  break;
336  case SUMO_ATTR_LANES:
337  myLaneChilds = parse<std::vector<GNELane*> >(myViewNet->getNet(), value);
338  break;
339  case SUMO_ATTR_POSITION:
340  myPosition = parse<Position>(value);
341  break;
342  case SUMO_ATTR_NAME:
343  myAdditionalName = value;
344  break;
346  myBlockMovement = parse<bool>(value);
347  break;
348  case GNE_ATTR_SELECTED:
349  if (parse<bool>(value)) {
351  } else {
353  }
354  break;
355  case GNE_ATTR_GENERIC:
357  break;
358  default:
359  throw InvalidArgument(toString(getTag()) + " doesn't have an attribute of type '" + toString(key) + "'");
360  }
361  // After setting attribute always update Geometry
362  updateGeometry(true);
363 }
364 
365 /****************************************************************************/
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
const GNEAttributeCarrier * getACUnderCursor() const
get AttributeCarrier under cursor
double scale
information about a lane&#39;s width (temporary, used for a single view)
void setBlockIconRotation(GNELane *additionalLane=nullptr)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name) ...
void commitGeometryMoving(const Position &oldPos, GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
GUIVisualizationTextSettings addName
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:126
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
a Variable Speed Sign
const std::string & getAdditionalID() const
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:179
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.
void openAdditionalDialog()
open GNEVariableSpeedSignDialog
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
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
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Position getPositionInView() const
Returns position of additional in view.
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:78
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:344
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void changeAdditionalID(const std::string &newID)
change ID of additional
generic attribute
std::vector< PositionVector > myChildConnectionPositions
Matrix with the Vertex&#39;s positions of connections between parents an their childs.
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.
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GUIVisualizationSizeSettings addSize
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void drawChildConnections() const
draw connections between Parent and childrens
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
void drawLockIcon(double size=0.5) const
draw lock icon
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
PositionVector myShape
The shape of the additional element.
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:85
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:1167
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)
void updateGeometry(bool updateGrid)
update pre-computed geometry information
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 updateChildConnections()
update Connection&#39;s geometry
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 ...
Position myBlockIconOffset
The offSet of the block icon.
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
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:53
element is selected
std::vector< std::pair< Position, double > > mySymbolsPositionAndRotation
position and rotation of every simbol over lane
std::string getGenericParametersStr() const
return generic parameters in string format
~GNEVariableSpeedSign()
Destructor.
GNENet * getNet() const
get the net object
std::string generateAdditionalChildID(SumoXMLTag childTag)
gererate a new ID for an additional child
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.
double getExaggeration(const GUIVisualizationSettings &s, double factor=20) const
return the drawing size including exaggeration and constantSize values
void moveGeometry(const Position &oldPos, const Position &offset)
change the position of the element geometry without saving in undoList
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:132
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1160
Position myBlockIconPosition
position of the block icon
std::vector< GNELane * > myLaneChilds
vector with the lane childs of this additional
trigger: a step description
SumoXMLTag getTag() const
get XML Tag assigned to this object