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 
24 #include <utils/gui/div/GLHelper.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEUndoList.h>
30 #include <netedit/GNENet.h>
32 
33 #include "GNEVariableSpeedSign.h"
34 
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNEViewNet* viewNet, const Position& pos, const std::vector<GNELane*>& lanes, const std::string& name, bool blockMovement) :
41  GNEAdditional(id, viewNet, GLO_VSS, SUMO_TAG_VSS, name, blockMovement, lanes),
42  myPosition(pos) {
43 }
44 
45 
47 }
48 
49 
50 void
52  // first check if object has to be removed from grid (SUMOTree)
53  if (updateGrid) {
55  }
56 
57  // Clear shape
58  myGeometry.shape.clear();
59 
60  // Set block icon position
62 
63  // Set block icon offset
64  myBlockIcon.offset = Position(-0.5, -0.5);
65 
66  // Set block icon rotation, and using their rotation for draw logo
68 
69  // Set position
70  myGeometry.shape.push_back(myPosition);
71 
72  // update child connections
74 
75  // last step is to check if object has to be added into grid (SUMOTree) again
76  if (updateGrid) {
78  }
79 }
80 
81 
84  return myPosition;
85 }
86 
87 
88 void
90  // Open VSS dialog
92 }
93 
94 
95 void
97  // restore old position, apply offset and update Geometry
99  myPosition.add(offset);
100  // filtern position using snap to active grid
102  updateGeometry(false);
103 }
104 
105 
106 void
108  // commit new position allowing undo/redo
109  undoList->p_begin("position of " + getTagStr());
111  undoList->p_end();
112 }
113 
114 
115 std::string
117  return myViewNet->getNet()->getMicrosimID();
118 }
119 
120 
121 void
123  // Start drawing adding an gl identificator
124  glPushName(getGlID());
125 
126  // Add a draw matrix for drawing logo
127  glPushMatrix();
128  glTranslated(myGeometry.shape[0].x(), myGeometry.shape[0].y(), getType());
129 
130  // Draw icon depending of variable speed sign is or if isn't being drawn for selecting
131  if (s.drawForSelecting) {
133  GLHelper::drawBoxLine(Position(0, 1), 0, 2, 1);
134  } else {
135  glColor3d(1, 1, 1);
136  glRotated(180, 0, 0, 1);
139  } else {
141  }
142  }
143 
144  // Pop draw icon matrix
145  glPopMatrix();
146 
147  // Only lock and childs if isn't being drawn for selecting
148  if (!s.drawForSelecting) {
149 
150  // Show Lock icon depending of the Edit mode
151  myBlockIcon.draw(0.4);
152 
153  // obtain exxageration
154  const double exaggeration = s.addSize.getExaggeration(s, this);
155 
156  // iterate over symbols and rotation
158  glPushMatrix();
159  glScaled(exaggeration, exaggeration, 1);
160  glTranslated(i.first.x(), i.first.y(), getType());
161  glRotated(-1 * i.second, 0, 0, 1);
162  glTranslated(0, -1.5, 0);
163 
164  int noPoints = 9;
165  if (s.scale > 25) {
166  noPoints = (int)(9.0 + s.scale / 10.0);
167  if (noPoints > 36) {
168  noPoints = 36;
169  }
170  }
171  glColor3d(1, 0, 0);
172  GLHelper::drawFilledCircle((double) 1.3, noPoints);
173  if (s.scale >= 5) {
174  glTranslated(0, 0, .1);
175  glColor3d(0, 0, 0);
176  GLHelper::drawFilledCircle((double) 1.1, noPoints);
177  // draw the speed string
178  //draw
179  glColor3d(1, 1, 0);
180  glTranslated(0, 0, .1);
181  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
182 
183  // draw last value string
184  GLHelper::drawText("S", Position(0, 0), .1, 1.2, RGBColor(255, 255, 0), 180);
185  }
186  glPopMatrix();
187  }
188 
189  // Draw connections
191  }
192 
193  // Pop symbol matrix
194  glPopMatrix();
195 
196  // Draw name if isn't being drawn for selecting
197  if (!s.drawForSelecting) {
198  drawName(getCenteringBoundary().getCenter(), s.scale, s.addName);
199  }
200 
201  // check if dotted contour has to be drawn
202  if (!s.drawForSelecting && (myViewNet->getDottedAC() == this)) {
204  // draw shape dotte contour aroud alld connections between child and parents
205  for (auto i : myChildConnections.connectionPositions) {
207  }
208  // draw rerouter symbol over all lanes
210  GLHelper::drawShapeDottedContour(getType(), i.first, 2.6, 2.6, -1 * i.second, 0, -1.5);
211  }
212  }
213 
214  // Pop name
215  glPopName();
216 }
217 
218 
219 std::string
221  switch (key) {
222  case SUMO_ATTR_ID:
223  return getAdditionalID();
224  case SUMO_ATTR_LANES:
225  return parseIDs(myLaneChilds);
226  case SUMO_ATTR_POSITION:
227  return toString(myPosition);
228  case SUMO_ATTR_NAME:
229  return myAdditionalName;
231  return toString(myBlockMovement);
232  case GNE_ATTR_SELECTED:
234  case GNE_ATTR_GENERIC:
235  return getGenericParametersStr();
236  default:
237  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
238  }
239 }
240 
241 
242 void
243 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
244  if (value == getAttribute(key)) {
245  return; //avoid needless changes, later logic relies on the fact that attributes have changed
246  }
247  switch (key) {
248  case SUMO_ATTR_ID: {
249  // change ID of Rerouter Interval
250  undoList->p_add(new GNEChange_Attribute(this, key, value));
251  // Change Ids of all Variable Speed Sign
252  for (auto i : myAdditionalChilds) {
253  i->setAttribute(SUMO_ATTR_ID, generateAdditionalChildID(SUMO_TAG_STEP), undoList);
254  }
255  break;
256  }
257  case SUMO_ATTR_LANES:
258  case SUMO_ATTR_POSITION:
259  case SUMO_ATTR_NAME:
261  case GNE_ATTR_SELECTED:
262  case GNE_ATTR_GENERIC:
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 GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
273  switch (key) {
274  case SUMO_ATTR_ID:
275  return isValidAdditionalID(value);
276  case SUMO_ATTR_POSITION:
277  return canParse<Position>(value);
278  case SUMO_ATTR_LANES:
279  if (value.empty()) {
280  return false;
281  } else {
282  return canParse<std::vector<GNELane*> >(myViewNet->getNet(), value, false);
283  }
284  case SUMO_ATTR_NAME:
287  return canParse<bool>(value);
288  case GNE_ATTR_SELECTED:
289  return canParse<bool>(value);
290  case GNE_ATTR_GENERIC:
291  return isGenericParametersValid(value);
292  default:
293  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
294  }
295 }
296 
297 
298 std::string
300  return getTagStr() + ": " + getID();
301 }
302 
303 
304 std::string
306  return getTagStr();
307 }
308 
309 // ===========================================================================
310 // private
311 // ===========================================================================
312 
313 void
314 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
315  switch (key) {
316  case SUMO_ATTR_ID:
317  changeAdditionalID(value);
318  break;
319  case SUMO_ATTR_LANES:
320  myLaneChilds = parse<std::vector<GNELane*> >(myViewNet->getNet(), value);
321  break;
322  case SUMO_ATTR_POSITION:
323  myPosition = parse<Position>(value);
324  break;
325  case SUMO_ATTR_NAME:
326  myAdditionalName = value;
327  break;
329  myBlockMovement = parse<bool>(value);
330  break;
331  case GNE_ATTR_SELECTED:
332  if (parse<bool>(value)) {
334  } else {
336  }
337  break;
338  case GNE_ATTR_GENERIC:
340  break;
341  default:
342  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
343  }
344  // Update Geometry after setting a new attribute (but avoided for certain attributes)
345  if((key != SUMO_ATTR_ID) && (key != GNE_ATTR_GENERIC) && (key != GNE_ATTR_SELECTED)) {
346  updateGeometry(true);
347  }
348 }
349 
350 /****************************************************************************/
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)
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
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
returns Additional ID
static const RGBColor WHITE
Definition: RGBColor.h:191
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.
Position snapToActiveGrid(const Position &pos) const
Returns a position that is mapped to the closest grid point if the grid is active.
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
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 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.
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< std::pair< Position, double > > symbolsPositionAndRotation
position and rotation of every symbol over lane
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
GUIVisualizationSizeSettings addSize
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void draw() const
draw connections between Parent and childrens
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:49
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:573
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
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)
ChildConnections myChildConnections
variable ChildConnections
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) ...
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: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
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.
A variable speed sign.
void update()
update Connection&#39;s geometry
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
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(...)
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
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry(bool updateGrid) function) ...
std::vector< GNELane * > myLaneChilds
vector with the lane childs of this additional
void draw(double size=0.5) const
draw lock icon
trigger: a step description