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 /****************************************************************************/
GUIGlObject::getType
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
Definition: GUIGlObject.cpp:181
SUMOXMLDefinitions::isValidAttribute
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
Definition: SUMOXMLDefinitions.cpp:988
GNEAdditional::BlockIcon::position
Position position
position of the block icon
Definition: GNEAdditional.h:351
GNEVariableSpeedSign::isValid
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEVariableSpeedSign.cpp:221
GNEVariableSpeedSign.h
GNEAdditional
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
GNEAdditional::setGenericParametersStr
void setGenericParametersStr(const std::string &value)
set generic parameters in string format
Definition: GNEAdditional.cpp:704
GNEVariableSpeedSign::getCenteringBoundary
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEVariableSpeedSign.cpp:72
GNEAdditional::getAdditionalID
const std::string & getAdditionalID() const
Definition: GNEAdditional.cpp:578
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNEAdditional::BlockIcon::setRotation
void setRotation(GNELane *additionalLane=nullptr)
set Rotation of block Icon (must be called in updateGeometry() function)
Definition: GNEAdditional.cpp:502
GNEAdditional::AdditionalMove::movingGeometryBoundary
Boundary movingGeometryBoundary
boundary used during moving of elements (to avoid insertion in RTREE
Definition: GNEAdditional.h:326
GUIGlObject::drawName
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0) const
draw name of item
Definition: GUIGlObject.cpp:355
GNEUndoList::p_end
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:80
GNEHierarchicalElementChildren::myChildConnections
ChildConnections myChildConnections
variable ChildConnections
Definition: GNEHierarchicalElementChildren.h:238
GNEAttributeCarrier::parseIDs
static std::string parseIDs(const std::vector< T > &ACs)
parses a list of specific Attribute Carriers into a string of IDs
GUIVisualizationSettings::drawBoundaries
bool drawBoundaries
enable or disable draw boundaries
Definition: GUIVisualizationSettings.h:629
GNENet::removeGLObjectFromGrid
void removeGLObjectFromGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1279
GNEVariableSpeedSign::commitGeometryMoving
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEVariableSpeedSign.cpp:104
GNEAdditional::generateChildID
std::string generateChildID(SumoXMLTag childTag)
gererate a new ID for an element child
Definition: GNEAdditional.cpp:183
GNEVariableSpeedSign::updateGeometry
void updateGeometry()
update pre-computed geometry information
Definition: GNEVariableSpeedSign.cpp:50
GNETEXTURE_VARIABLESPEEDSIGNSELECTED
Definition: GUITextures.h:51
GNEAttributeCarrier::isGenericParametersValid
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
Definition: GNEAttributeCarrier.cpp:1354
GNEViewNet
Definition: GNEViewNet.h:43
SUMO_ATTR_ID
Definition: SUMOXMLDefinitions.h:379
GLHelper.h
GNEVariableSpeedSign::getPopUpID
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEVariableSpeedSign.cpp:248
GNEAdditional::changeAdditionalID
void changeAdditionalID(const std::string &newID)
change ID of additional
Definition: GNEAdditional.cpp:604
GNEAdditional::unselectAttributeCarrier
void unselectAttributeCarrier(bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
Definition: GNEAdditional.cpp:634
GNEAdditional::myBlockIcon
BlockIcon myBlockIcon
variable BlockIcon
Definition: GNEAdditional.h:380
GLHelper::setColor
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:616
GNEVariableSpeedSign::drawGL
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEVariableSpeedSign.cpp:119
GUISUMOAbstractView::snapToActiveGrid
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.
Definition: GUISUMOAbstractView.cpp:194
GUITexturesHelper::drawTexturedBox
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Definition: GUITexturesHelper.cpp:73
GNEVariableSpeedSign::getAttribute
std::string getAttribute(SumoXMLAttr key) const
Definition: GNEVariableSpeedSign.cpp:169
GNEAdditional::myMove
AdditionalMove myMove
variable AdditionalMove
Definition: GNEAdditional.h:371
GNEAdditional::myViewNet
GNEViewNet * myViewNet
The GNEViewNet this additional element belongs.
Definition: GNEAdditional.h:365
GLHelper::drawBoundary
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:812
GNEAttributeCarrier::GNEChange_Attribute
friend class GNEChange_Attribute
declare friend class
Definition: GNEAttributeCarrier.h:57
GNEVariableSpeedSign::moveGeometry
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEVariableSpeedSign.cpp:93
GNEUndoList::p_add
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
Definition: GNEUndoList.cpp:132
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNEVariableSpeedSign::getPositionInView
Position getPositionInView() const
Returns position of additional in view.
Definition: GNEVariableSpeedSign.cpp:66
GNEAdditional::isAttributeCarrierSelected
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
Definition: GNEAdditional.cpp:650
GNEHierarchicalElementChildren::getLaneChildren
const std::vector< GNELane * > & getLaneChildren() const
get lanes of VSS
Definition: GNEHierarchicalElementChildren.cpp:409
GUIVisualizationSettings::addName
GUIVisualizationTextSettings addName
Definition: GUIVisualizationSettings.h:582
GUIVisualizationSettings::detailSettings
GUIVisualizationDetailSettings detailSettings
detail settings
Definition: GUIVisualizationSettings.h:655
GNEVariableSpeedSign::getHierarchyName
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEVariableSpeedSign.cpp:254
SUMO_TAG_VSS
A variable speed sign.
Definition: SUMOXMLDefinitions.h:90
GNEAdditional::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
Definition: GNEAdditional.cpp:619
GNEViewNet.h
GNEHierarchicalElementChildren::drawChildConnections
void drawChildConnections(const GUIVisualizationSettings &s, const GUIGlObjectType GLTypeParent) const
Definition: GNEHierarchicalElementChildren.cpp:90
GUIGlObject::getGlID
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.cpp:150
GNEViewNet::getDottedAC
const GNEAttributeCarrier * getDottedAC() const
get AttributeCarrier under cursor
Definition: GNEViewNet.cpp:939
Boundary
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:42
GNEVariableSpeedSignDialog.h
GUITextureSubSys::getTexture
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
Definition: GUITextureSubSys.cpp:102
GLHelper::drawShapeDottedContourRectangle
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
GUIVisualizationSettings::scale
double scale
information about a lane's width (temporary, used for a single view)
Definition: GUIVisualizationSettings.h:623
SUMO_TAG_STEP
trigger: a step description
Definition: SUMOXMLDefinitions.h:158
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
Position::x
double x() const
Returns the x-position.
Definition: Position.h:57
Boundary::add
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:79
GNEVariableSpeedSign::~GNEVariableSpeedSign
~GNEVariableSpeedSign()
Destructor.
Definition: GNEVariableSpeedSign.cpp:45
GNEAdditional::myAdditionalName
std::string myAdditionalName
name of additional
Definition: GNEAdditional.h:374
GNEHierarchicalElementChildren::changeLaneChildren
void changeLaneChildren(GNEAdditional *elementChild, const std::string &newEdgeIDs)
change edge children of an additional
Definition: GNEHierarchicalElementChildren.cpp:480
GNEVariableSpeedSign::setAttribute
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
Definition: GNEVariableSpeedSign.cpp:192
GUIVisualizationDetailSettings::laneTextures
static const double laneTextures
details for lane textures
Definition: GUIVisualizationSettings.h:284
GNEAdditional::myBlockMovement
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
Definition: GNEAdditional.h:377
GLHelper::drawShapeDottedContourAroundShape
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
SUMO_ATTR_POSITION
Definition: SUMOXMLDefinitions.h:658
GNEVariableSpeedSignDialog
Definition: GNEVariableSpeedSignDialog.h:45
GNEHierarchicalElementChildren::ChildConnections::connectionPositions
std::vector< PositionVector > connectionPositions
Matrix with the Vertex's positions of connections between parents an their children.
Definition: GNEHierarchicalElementChildren.h:224
SUMO_ATTR_LANES
Definition: SUMOXMLDefinitions.h:636
GLIncludes.h
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNE_ATTR_GENERIC
generic attribute
Definition: SUMOXMLDefinitions.h:986
GNEAdditional::BlockIcon::drawIcon
void drawIcon(const GUIVisualizationSettings &s, const double exaggeration, const double size=0.5) const
draw lock icon
Definition: GNEAdditional.cpp:518
GNENet::addGLObjectIntoGrid
void addGLObjectIntoGrid(GUIGlObject *o)
add GL Object into net
Definition: GNENet.cpp:1273
Position::y
double y() const
Returns the y-position.
Definition: Position.h:62
InvalidArgument
Definition: UtilExceptions.h:57
GLHelper::drawBoxLine
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:136
GNEAdditional::getGenericParametersStr
std::string getGenericParametersStr() const
return generic parameters in string format
Definition: GNEAdditional.cpp:678
GNEHierarchicalElementChildren::getAdditionalChildren
const std::vector< GNEAdditional * > & getAdditionalChildren() const
return vector of additionals that have as Parent this edge (For example, Calibrators)
Definition: GNEHierarchicalElementChildren.cpp:132
GNETEXTURE_VARIABLESPEEDSIGN
Definition: GUITextures.h:50
GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
Definition: SUMOXMLDefinitions.h:978
GNEAdditional::drawUsingSelectColor
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
Definition: GNEAdditional.cpp:656
GNEVariableSpeedSign::GNEVariableSpeedSign
GNEVariableSpeedSign(const std::string &id, GNEViewNet *viewNet, const Position &pos, const std::vector< GNELane * > &lanes, const std::string &name, bool blockMovement)
Constructor.
Definition: GNEVariableSpeedSign.cpp:39
GNEVariableSpeedSign::myPosition
Position myPosition
position of VSS in view
Definition: GNEVariableSpeedSign.h:127
config.h
GUIVisualizationSettings::addSize
GUIVisualizationSizeSettings addSize
Definition: GUIVisualizationSettings.h:580
Position::add
void add(const Position &pos)
Adds the given position to this one.
Definition: Position.h:127
Boundary::isInitialised
bool isInitialised() const
check if Boundary is Initialised
Definition: Boundary.cpp:217
GNE_ATTR_SELECTED
element is selected
Definition: SUMOXMLDefinitions.h:968
Boundary::grow
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:301
GNEHierarchicalElementChildren::ChildConnections::update
void update()
update Connection's geometry
Definition: GNEHierarchicalElementChildren.cpp:518
GUIVisualizationSettings::drawDetail
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
Definition: GUIVisualizationSettings.cpp:1621
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
SUMO_ATTR_NAME
Definition: SUMOXMLDefinitions.h:381
GNEUndoList
Definition: GNEUndoList.h:49
GUIVisualizationSettings
Stores the information about how to visualize structures.
Definition: GUIVisualizationSettings.h:346
GNEVariableSpeedSign::getParentName
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEVariableSpeedSign.cpp:113
GNEAdditional::isValidAdditionalID
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Definition: GNEAdditional.cpp:584
GNEUndoList::p_begin
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
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
Definition: SUMOXMLDefinitions.h:373
GNEAdditional::AdditionalMove::originalViewPosition
Position originalViewPosition
value for saving first original position over lane before moving
Definition: GNEAdditional.h:329
GUIGlObject::getMicrosimID
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.cpp:164
GUITextureSubSys.h
GNEChange_Attribute.h
GNENet.h
GLO_VSS
a Variable Speed Sign
Definition: GUIGlObjectTypes.h:90
GUIVisualizationSizeSettings::getExaggeration
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
Definition: GUIVisualizationSettings.cpp:212
GNEVariableSpeedSign::openAdditionalDialog
void openAdditionalDialog()
open GNEVariableSpeedSignDialog
Definition: GNEVariableSpeedSign.cpp:86
GNEAdditional::BlockIcon::offset
Position offset
The offSet of the block icon.
Definition: GNEAdditional.h:354
RGBColor::WHITE
static const RGBColor WHITE
Definition: RGBColor.h:197
GNEUndoList.h
GUIVisualizationSettings::drawForSelecting
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
Definition: GUIVisualizationSettings.h:635