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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 //
19 /****************************************************************************/
20 #include <config.h>
21 
23 #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"
34 
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNENet* net, const Position& pos, const std::string& name, bool blockMovement) :
41  GNEAdditional(id, net, GLO_VSS, SUMO_TAG_VSS, name, blockMovement,
42 {}, {}, {}, {}, {}, {}, {}, {}),
43 myPosition(pos) {
44  // update centering boundary without updating grid
46 }
47 
48 
50 }
51 
52 
54 GNEVariableSpeedSign::getMoveOperation(const double /*shapeOffset*/) {
55  if (myBlockMovement) {
56  // element blocked, then nothing to move
57  return nullptr;
58  } else {
59  // return move operation for additional placed in view
60  return new GNEMoveOperation(this, myPosition);
61  }
62 }
63 
64 
65 void
67  // update additional geometry
69  // Update Hierarchical connections geometry
71 }
72 
73 
74 void
76  // remove additional from grid
77  if (updateGrid) {
79  }
80  // update geometry
82  // add shape boundary
84  // grow
85  myBoundary.grow(10);
86  // add additional into RTREE again
87  if (updateGrid) {
89  }
90  // Update Hierarchical connections geometry
92 }
93 
94 
95 void
96 GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
97  // geometry of this element cannot be splitted
98 }
99 
100 
101 void
103  // Open VSS dialog
105 }
106 
107 
108 std::string
110  return myNet->getMicrosimID();
111 }
112 
113 
114 void
116  // obtain exaggeration
117  const double VSSExaggeration = s.addSize.getExaggeration(s, this);
118  // first check if additional has to be drawn
119  if (s.drawAdditionals(VSSExaggeration) && myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
120  // check if boundary has to be drawn
121  if (s.drawBoundaries) {
123  }
124  // push name
125  glPushName(getGlID());
126  // push layer matrix
127  glPushMatrix();
128  // translate to front
130  // push texture matrix
131  glPushMatrix();
132  // translate to position
133  glTranslated(myPosition.x(), myPosition.y(), 0);
134  // scale
135  glScaled(VSSExaggeration, VSSExaggeration, 1);
136  // Draw icon depending of variable speed sign is or if isn't being drawn for selecting
137  if (!s.drawForRectangleSelection && s.drawDetail(s.detailSettings.laneTextures, VSSExaggeration)) {
138  // set white color
139  glColor3d(1, 1, 1);
140  // rotate
141  glRotated(180, 0, 0, 1);
142  // draw texture
143  if (drawUsingSelectColor()) {
145  } else {
147  }
148  } else {
149  // set white color
151  // just draw a withe square
153  }
154  // Pop texture matrix
155  glPopMatrix();
156  // draw lock icon
157  GNEViewNetHelper::LockIcon::drawLockIcon(this, myAdditionalGeometry, VSSExaggeration, -0.5, -0.5, false, 0.4);
158  // Pop layer matrix
159  glPopMatrix();
160  // Pop name
161  glPopName();
162  // push connection matrix
163  glPushMatrix();
164  // translate to front
166  // Draw child connections
167  drawHierarchicalConnections(s, this, VSSExaggeration);
168  // Pop connection matrix
169  glPopMatrix();
170  // Draw additional ID
171  drawAdditionalID(s);
172  // draw additional name
174  // check if dotted contour has to be drawn
177  }
178  if (s.drawDottedContour() || (myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
180  }
181  }
182 }
183 
184 
185 std::string
187  switch (key) {
188  case SUMO_ATTR_ID:
189  return getID();
190  case SUMO_ATTR_LANES: {
191  std::vector<std::string> lanes;
192  for (const auto& VSSSymbol : getChildAdditionals()) {
193  if (VSSSymbol->getTagProperty().isSymbol()) {
194  lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
195  }
196  }
197  return toString(lanes);
198  }
199  case SUMO_ATTR_POSITION:
200  return toString(myPosition);
201  case SUMO_ATTR_NAME:
202  return myAdditionalName;
204  return toString(myBlockMovement);
205  case GNE_ATTR_SELECTED:
207  case GNE_ATTR_PARAMETERS:
208  return getParametersStr();
209  default:
210  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
211  }
212 }
213 
214 
215 double
217  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
218 }
219 
220 
221 void
222 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
223  if (value == getAttribute(key)) {
224  return; //avoid needless changes, later logic relies on the fact that attributes have changed
225  }
226  switch (key) {
227  // special case for lanes due VSS Symbols
228  case SUMO_ATTR_LANES:
229  // rebuild VSS Symbols
230  rebuildVSSSymbols(value, undoList);
231  break;
232  case SUMO_ATTR_ID:
233  case SUMO_ATTR_POSITION:
234  case SUMO_ATTR_NAME:
236  case GNE_ATTR_SELECTED:
237  case GNE_ATTR_PARAMETERS:
238  undoList->p_add(new GNEChange_Attribute(this, key, value));
239  break;
240  default:
241  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
242  }
243 }
244 
245 
246 bool
247 GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
248  switch (key) {
249  case SUMO_ATTR_ID:
250  return isValidAdditionalID(value);
251  case SUMO_ATTR_POSITION:
252  return canParse<Position>(value);
253  case SUMO_ATTR_LANES:
254  return canParse<std::vector<GNELane*> >(myNet, value, false);
255  case SUMO_ATTR_NAME:
258  return canParse<bool>(value);
259  case GNE_ATTR_SELECTED:
260  return canParse<bool>(value);
261  case GNE_ATTR_PARAMETERS:
262  return Parameterised::areParametersValid(value);
263  default:
264  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
265  }
266 }
267 
268 
269 bool
271  return true;
272 }
273 
274 
275 std::string
277  return getTagStr() + ": " + getID();
278 }
279 
280 
281 std::string
283  return getTagStr();
284 }
285 
286 // ===========================================================================
287 // private
288 // ===========================================================================
289 
290 void
291 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
292  switch (key) {
293  case SUMO_ATTR_LANES:
294  throw InvalidArgument(getTagStr() + " cannot be edited");
295  case SUMO_ATTR_ID:
296  myNet->getAttributeCarriers()->updateID(this, value);
297  break;
298  case SUMO_ATTR_POSITION:
299  myPosition = parse<Position>(value);
300  // update boundary
302  break;
303  case SUMO_ATTR_NAME:
304  myAdditionalName = value;
305  break;
307  myBlockMovement = parse<bool>(value);
308  break;
309  case GNE_ATTR_SELECTED:
310  if (parse<bool>(value)) {
312  } else {
314  }
315  break;
316  case GNE_ATTR_PARAMETERS:
317  setParametersStr(value);
318  break;
319  default:
320  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
321  }
322 }
323 
324 
325 void
327  // update position
328  myPosition = moveResult.shapeToUpdate.front();
329  // update geometry
330  updateGeometry();
331 }
332 
333 
334 void
336  undoList->p_begin("position of " + getTagStr());
337  undoList->p_add(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
338  undoList->p_end();
339 }
340 
341 
342 void
343 GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
344  undoList->p_begin(("change " + getTagStr() + " attribute").c_str());
345  // drop all additional children
346  while (getChildAdditionals().size() > 0) {
347  undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
348  }
349  // get lane vector
350  const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
351  // create new VSS Symbols
352  for (const auto& lane : lanes) {
353  // create VSS Symbol
354  GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
355  // add it using GNEChange_Additional
356  myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
357  }
358  undoList->p_end();
359 }
360 
361 /****************************************************************************/
@ GLO_VSS
a Variable Speed Sign
@ GNETEXTURE_VARIABLESPEEDSIGNSELECTED
Definition: GUITextures.h:48
@ GNETEXTURE_VARIABLESPEEDSIGN
Definition: GUITextures.h:47
@ SUMO_TAG_VSS
A variable speed sign.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ GNE_ATTR_BLOCK_MOVEMENT
block movement of a graphic element
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_LANES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:647
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:446
static void drawBoxLine(const Position &beg, double rot, double visLength, double width, double offset=0)
Draws a thick line.
Definition: GLHelper.cpp:135
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
const std::string & getID() const
get ID
GNEGeometry::Geometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
void drawAdditionalID(const GUIVisualizationSettings &s) const
draw additional ID
bool myBlockMovement
boolean to check if additional element is blocked (i.e. cannot be moved with mouse)
std::string myAdditionalName
name of additional
void drawAdditionalName(const GUIVisualizationSettings &s) const
draw additional name
Boundary myBoundary
Additional Boundary.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
bool drawUsingSelectColor() const
check if attribute carrier must be drawn using selecting color.
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const PositionVector & getShape() const
The shape of the additional element.
void updateGeometry(const PositionVector &shape, double startPos=-1, double endPos=-1, const Position &extraFirstPosition=Position::INVALID, const Position &extraLastPosition=Position::INVALID)
update geometry shape
Definition: GNEGeometry.cpp:81
void update()
update Connection's geometry
void drawHierarchicalConnections(const GUIVisualizationSettings &s, const GNEAttributeCarrier *AC, const double exaggeration) const
Draw hierarchical connections between parent and children.
GNEGeometry::HierarchicalConnections myHierarchicalConnections
hierarchical connections
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1411
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1423
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
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:71
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
GNEVariableSpeedSign(const std::string &id, GNENet *net, const Position &pos, const std::string &name, bool blockMovement)
Constructor.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const
bool isAttributeEnabled(SumoXMLAttr key) const
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
void rebuildVSSSymbols(const std::string &value, GNEUndoList *undoList)
rebuild VSS Symbols
GNEMoveOperation * getMoveOperation(const double shapeOffset)
get move operation for the given shapeOffset
Position myPosition
position of VSS in view
std::string getAttribute(SumoXMLAttr key) const
void updateGeometry()
update pre-computed geometry information
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
void openAdditionalDialog()
open GNEVariableSpeedSignDialog
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
GNEUndoList * getUndoList() const
get the undoList object
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlID getGlID() const
Returns the numerical id of the object.
static GUIGlID getTexture(GUITexture which)
returns a texture previously defined in the enum GUITexture
static void drawTexturedBox(int which, double size)
Draws a named texture as a box with the given size.
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
bool drawForRectangleSelection
whether drawing is performed for the purpose of selecting objects using a rectangle
GUIVisualizationDetailSettings detailSettings
detail settings
GUIVisualizationSizeSettings addSize
bool drawDottedContour() const
check if dotted contour can be drawn
bool drawAdditionals(const double exaggeration) const
check if additionals must be drawn
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
static bool areParametersValid(const std::string &value, bool report=false, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:36
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static const RGBColor WHITE
Definition: RGBColor.h:187
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
bool showAdditionals() const
check if additionals has to be drawn
static void drawLockIcon(const GNEAttributeCarrier *AC, const GNEGeometry::Geometry &geometry, const double exaggeration, const double offsetx, const double offsety, const bool overlane, const double size=0.5)
draw lock icon
static const double laneTextures
details for lane textures
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values