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.dev/sumo
3 // Copyright (C) 2001-2024 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 
25 #include <netedit/GNEViewNet.h>
26 #include <netedit/GNEUndoList.h>
27 #include <netedit/GNENet.h>
28 
29 #include "GNEVariableSpeedSign.h"
31 
32 
33 // ===========================================================================
34 // member method definitions
35 // ===========================================================================
36 
38  GNEAdditional("", net, GLO_VSS, SUMO_TAG_VSS, GUIIconSubSys::getIcon(GUIIcon::VARIABLESPEEDSIGN), "", {}, {}, {}, {}, {}, {}) {
39  // reset default values
40  resetDefaultValues();
41 }
42 
43 
44 GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNENet* net, const Position& pos, const std::string& name,
45  const std::vector<std::string>& vTypes, const Parameterised::Map& parameters) :
46  GNEAdditional(id, net, GLO_VSS, SUMO_TAG_VSS, GUIIconSubSys::getIcon(GUIIcon::VARIABLESPEEDSIGN), name, {}, {}, {}, {}, {}, {}),
47  Parameterised(parameters),
48  myPosition(pos),
49 myVehicleTypes(vTypes) {
50  // update centering boundary without updating grid
51  updateCenteringBoundary(false);
52 }
53 
54 
56 }
57 
58 
59 void
61  device.openTag(SUMO_TAG_VSS);
62  device.writeAttr(SUMO_ATTR_ID, getID());
65  if (!myAdditionalName.empty()) {
67  }
68  if (!myVehicleTypes.empty()) {
70  }
71  // write all rerouter interval
72  for (const auto& step : getChildAdditionals()) {
73  if (!step->getTagProperty().isSymbol()) {
74  step->writeAdditional(device);
75  }
76  }
77  // write parameters (Always after children to avoid problems with additionals.xsd)
78  writeParams(device);
79  device.closeTag();
80 }
81 
82 
83 bool
84 GNEVariableSpeedSign::GNEVariableSpeedSign::isAdditionalValid() const {
85  return true;
86 }
87 
88 
89 std::string
90 GNEVariableSpeedSign::GNEVariableSpeedSign::getAdditionalProblem() const {
91  return "";
92 }
93 
94 
95 void
96 GNEVariableSpeedSign::GNEVariableSpeedSign::fixAdditionalProblem() {
97  // nothing to fix
98 }
99 
100 
103  // return move operation for additional placed in view
104  return new GNEMoveOperation(this, myPosition);
105 }
106 
107 
108 void
110  // update additional geometry
112  // update geometries (boundaries of all children)
113  for (const auto& additionalChildren : getChildAdditionals()) {
114  additionalChildren->updateGeometry();
115  }
116 }
117 
118 
119 Position
121  return myPosition;
122 }
123 
124 
125 void
127  // remove additional from grid
128  if (updateGrid) {
130  }
131  // update geometry
132  updateGeometry();
133  // add shape boundary
135  // add positions of all childrens (symbols and steps)
136  for (const auto& additionalChildren : getChildAdditionals()) {
137  myAdditionalBoundary.add(additionalChildren->getPositionInView());
138  }
139  // grow
141  // add additional into RTREE again
142  if (updateGrid) {
143  myNet->addGLObjectIntoGrid(this);
144  }
145 }
146 
147 
148 void
149 GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
150  // geometry of this element cannot be splitted
151 }
152 
153 
154 bool
156  // get edit modes
157  const auto& editModes = myNet->getViewNet()->getEditModes();
158  // check if we're in move mode
159  if (!myNet->getViewNet()->isMovingElement() && editModes.isCurrentSupermodeNetwork() &&
160  (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
161  // only move the first element
163  } else {
164  return false;
165  }
166 }
167 
168 
169 void
171  // Open VSS dialog
173 }
174 
175 
176 std::string
178  return myNet->getMicrosimID();
179 }
180 
181 
182 void
184  // draw parent and child lines
186  // draw VSS
188  // iterate over additionals and check if drawn
189  for (const auto& step : getChildAdditionals()) {
190  // if rerouter or their intevals are selected, then draw
193  step->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(step) ||
194  (myNet->getViewNet()->getFrontAttributeCarrier() == step)) {
195  step->drawGL(s);
196  }
197  }
198 }
199 
200 
201 std::string
203  switch (key) {
204  case SUMO_ATTR_ID:
205  return getMicrosimID();
206  case SUMO_ATTR_LANES: {
207  std::vector<std::string> lanes;
208  for (const auto& VSSSymbol : getChildAdditionals()) {
209  if (VSSSymbol->getTagProperty().isSymbol()) {
210  lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
211  }
212  }
213  return toString(lanes);
214  }
215  case SUMO_ATTR_POSITION:
216  return toString(myPosition);
217  case SUMO_ATTR_NAME:
218  return myAdditionalName;
219  case SUMO_ATTR_VTYPES:
220  return toString(myVehicleTypes);
221  case GNE_ATTR_SELECTED:
223  case GNE_ATTR_PARAMETERS:
224  return getParametersStr();
225  default:
226  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
227  }
228 }
229 
230 
231 double
233  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
234 }
235 
236 
237 const Parameterised::Map&
239  return getParametersMap();
240 }
241 
242 
243 void
244 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
245  if (value == getAttribute(key)) {
246  return; //avoid needless changes, later logic relies on the fact that attributes have changed
247  }
248  switch (key) {
249  // special case for lanes due VSS Symbols
250  case SUMO_ATTR_LANES:
251  // rebuild VSS Symbols
252  rebuildVSSSymbols(value, undoList);
253  break;
254  case SUMO_ATTR_ID:
255  case SUMO_ATTR_POSITION:
256  case SUMO_ATTR_NAME:
257  case SUMO_ATTR_VTYPES:
258  case GNE_ATTR_SELECTED:
259  case GNE_ATTR_PARAMETERS:
260  GNEChange_Attribute::changeAttribute(this, key, value, undoList);
261  break;
262  default:
263  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
264  }
265 }
266 
267 
268 bool
269 GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
270  switch (key) {
271  case SUMO_ATTR_ID:
272  return isValidAdditionalID(value);
273  case SUMO_ATTR_POSITION:
274  return canParse<Position>(value);
275  case SUMO_ATTR_LANES:
276  return canParse<std::vector<GNELane*> >(myNet, value, false);
277  case SUMO_ATTR_NAME:
279  case SUMO_ATTR_VTYPES:
280  if (value.empty()) {
281  return true;
282  } else {
284  }
285  case GNE_ATTR_SELECTED:
286  return canParse<bool>(value);
287  case GNE_ATTR_PARAMETERS:
288  return areParametersValid(value);
289  default:
290  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
291  }
292 }
293 
294 
295 std::string
297  return getTagStr() + ": " + getID();
298 }
299 
300 
301 std::string
303  return getTagStr();
304 }
305 
306 // ===========================================================================
307 // private
308 // ===========================================================================
309 
310 void
311 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
312  switch (key) {
313  case SUMO_ATTR_LANES:
314  throw InvalidArgument(getTagStr() + " cannot be edited");
315  case SUMO_ATTR_ID:
316  // update microsimID
317  setAdditionalID(value);
318  break;
319  case SUMO_ATTR_POSITION:
320  myPosition = parse<Position>(value);
321  // update boundary (except for template)
322  if (getID().size() > 0) {
324  }
325  break;
326  case SUMO_ATTR_NAME:
327  myAdditionalName = value;
328  break;
329  case SUMO_ATTR_VTYPES:
330  myVehicleTypes = parse<std::vector<std::string> >(value);
331  break;
332  case GNE_ATTR_SELECTED:
333  if (parse<bool>(value)) {
335  } else {
337  }
338  break;
339  case GNE_ATTR_PARAMETERS:
340  setParametersStr(value);
341  break;
342  default:
343  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
344  }
345 }
346 
347 
348 void
350  // update position
351  myPosition = moveResult.shapeToUpdate.front();
352  // update geometry
353  updateGeometry();
354 }
355 
356 
357 void
359  undoList->begin(this, "position of " + getTagStr());
361  undoList->end();
362 }
363 
364 
365 void
366 GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
367  undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
368  // drop all additional children
369  while (getChildAdditionals().size() > 0) {
370  undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
371  }
372  // get lane vector
373  const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
374  // create new VSS Symbols
375  for (const auto& lane : lanes) {
376  // create VSS Symbol
377  GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
378  // add it using GNEChange_Additional
379  myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
380  }
381  undoList->end();
382 }
383 
384 /****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ GLO_VSS
a Variable Speed Sign
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
@ VARIABLESPEEDSIGN
@ VARIABLESPEEDSIGN_SELECTED
@ SUMO_TAG_VSS
A variable speed sign.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ GNE_ATTR_SELECTED
element is selected
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_LANES
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:78
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:319
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
bool isValidAdditionalID(const std::string &value) const
check if a new additional ID is valid
void setAdditionalID(const std::string &newID)
set additional ID
GUIGeometry myAdditionalGeometry
geometry to be precomputed in updateGeometry(...)
std::string myAdditionalName
name of additional
void drawSquaredAdditional(const GUIVisualizationSettings &s, const Position &pos, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
Boundary myAdditionalBoundary
Additional Boundary (used only by additionals placed over grid)
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (instead of GUIGlObjectStorage)
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
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void addGLObjectIntoGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1282
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1291
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2055
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
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
Position getPositionInView() const
Returns position of additional in view.
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const
GNEVariableSpeedSign(GNENet *net)
default Constructor
GNEMoveOperation * getMoveOperation()
get move operation
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 correspondent attribute are valids
bool checkDrawMoveContour() const
check if draw move contour (red)
void rebuildVSSSymbols(const std::string &value, GNEUndoList *undoList)
rebuild VSS Symbols
Position myPosition
position of VSS in view
void writeAdditional(OutputDevice &device) const
write additional element into a xml file
const Parameterised::Map & getACParametersMap() const
get parameters map
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
std::vector< std::string > myVehicleTypes
attribute vehicle types
const GUIGlObject * getGUIGlObjectFront() const
get front attribute carrier or a pointer to nullptr
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:703
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:715
bool isMovingElement() const
check if an element is being moved
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
GNEUndoList * getUndoList() const
get the undoList object
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
Definition: GNEViewNet.cpp:468
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void updateSinglePosGeometry(const Position &position, const double rotation)
update position and rotation
const PositionVector & getShape() const
The shape of the additional element.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
Stores the information about how to visualize structures.
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
An upper class for objects with additional parameters.
Definition: Parameterised.h:41
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
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"
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
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:37
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
static bool isValidListOfTypeID(const std::string &value)
whether the given string is a valid list of ids for an edge or vehicle type (empty aren't allowed)
static bool isValidAttribute(const std::string &value)
whether the given string is a valid attribute for a certain key (for example, a name)
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.
bool showSubAdditionals() const
check if show sub-additionals
static const RGBColor connectionColor
connection color