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-2022 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, "",
39 {}, {}, {}, {}, {}, {}, {}, {},
40 std::map<std::string, std::string>()) {
41  // reset default values
42  resetDefaultValues();
43 }
44 
45 
46 GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNENet* net, const Position& pos, const std::string& name,
47  const std::vector<std::string>& vTypes, const std::map<std::string, std::string>& parameters) :
48  GNEAdditional(id, net, GLO_VSS, SUMO_TAG_VSS, name,
49 {}, {}, {}, {}, {}, {}, {}, {},
50 parameters),
51 myPosition(pos),
52 myVehicleTypes(vTypes) {
53  // update centering boundary without updating grid
54  updateCenteringBoundary(false);
55 }
56 
57 
59 }
60 
61 
62 void
64  device.openTag(SUMO_TAG_VSS);
65  device.writeAttr(SUMO_ATTR_ID, getID());
68  if (!myAdditionalName.empty()) {
70  }
71  if (!myVehicleTypes.empty()) {
73  }
74  // write all rerouter interval
75  for (const auto& step : getChildAdditionals()) {
76  if (!step->getTagProperty().isSymbol()) {
77  step->writeAdditional(device);
78  }
79  }
80  // write parameters (Always after children to avoid problems with additionals.xsd)
81  writeParams(device);
82  device.closeTag();
83 }
84 
85 
88  // return move operation for additional placed in view
89  return new GNEMoveOperation(this, myPosition);
90 }
91 
92 
93 void
95  // update additional geometry
97  // update geometries (boundaries of all children)
98  for (const auto& additionalChildren : getChildAdditionals()) {
99  additionalChildren->updateGeometry();
100  }
101 }
102 
103 
104 Position
106  return myPosition;
107 }
108 
109 
110 void
112  // remove additional from grid
113  if (updateGrid) {
115  }
116  // update geometry
117  updateGeometry();
118  // add shape boundary
120  // add positions of all childrens (symbols and steps)
121  for (const auto& additionalChildren : getChildAdditionals()) {
122  myAdditionalBoundary.add(additionalChildren->getPositionInView());
123  // also update centering boundary
124  additionalChildren->updateCenteringBoundary(false);
125  }
126  // grow
128  // add additional into RTREE again
129  if (updateGrid) {
130  myNet->addGLObjectIntoGrid(this);
131  }
132 }
133 
134 
135 void
136 GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
137  // geometry of this element cannot be splitted
138 }
139 
140 
141 void
143  // Open VSS dialog
145 }
146 
147 
148 std::string
150  return myNet->getMicrosimID();
151 }
152 
153 
154 void
156  // draw parent and child lines
158  // draw VSS
160  // iterate over additionals and check if drawn
161  for (const auto& step : getChildAdditionals()) {
162  // if rerouter or their intevals are selected, then draw
165  step->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(step) ||
166  (myNet->getViewNet()->getFrontAttributeCarrier() == step)) {
167  step->drawGL(s);
168  }
169  }
170 }
171 
172 
173 std::string
175  switch (key) {
176  case SUMO_ATTR_ID:
177  return getID();
178  case SUMO_ATTR_LANES: {
179  std::vector<std::string> lanes;
180  for (const auto& VSSSymbol : getChildAdditionals()) {
181  if (VSSSymbol->getTagProperty().isSymbol()) {
182  lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
183  }
184  }
185  return toString(lanes);
186  }
187  case SUMO_ATTR_POSITION:
188  return toString(myPosition);
189  case SUMO_ATTR_NAME:
190  return myAdditionalName;
191  case SUMO_ATTR_VTYPES:
192  return toString(myVehicleTypes);
193  case GNE_ATTR_SELECTED:
195  case GNE_ATTR_PARAMETERS:
196  return getParametersStr();
197  default:
198  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
199  }
200 }
201 
202 
203 double
205  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
206 }
207 
208 
209 void
210 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
211  if (value == getAttribute(key)) {
212  return; //avoid needless changes, later logic relies on the fact that attributes have changed
213  }
214  switch (key) {
215  // special case for lanes due VSS Symbols
216  case SUMO_ATTR_LANES:
217  // rebuild VSS Symbols
218  rebuildVSSSymbols(value, undoList);
219  break;
220  case SUMO_ATTR_ID:
221  case SUMO_ATTR_POSITION:
222  case SUMO_ATTR_NAME:
223  case SUMO_ATTR_VTYPES:
224  case GNE_ATTR_SELECTED:
225  case GNE_ATTR_PARAMETERS:
226  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
227  break;
228  default:
229  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
230  }
231 }
232 
233 
234 bool
235 GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
236  switch (key) {
237  case SUMO_ATTR_ID:
238  return isValidAdditionalID(value);
239  case SUMO_ATTR_POSITION:
240  return canParse<Position>(value);
241  case SUMO_ATTR_LANES:
242  return canParse<std::vector<GNELane*> >(myNet, value, false);
243  case SUMO_ATTR_NAME:
245  case SUMO_ATTR_VTYPES:
246  if (value.empty()) {
247  return true;
248  } else {
250  }
251  case GNE_ATTR_SELECTED:
252  return canParse<bool>(value);
253  case GNE_ATTR_PARAMETERS:
254  return Parameterised::areParametersValid(value);
255  default:
256  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
257  }
258 }
259 
260 
261 bool
263  return true;
264 }
265 
266 
267 std::string
269  return getTagStr() + ": " + getID();
270 }
271 
272 
273 std::string
275  return getTagStr();
276 }
277 
278 // ===========================================================================
279 // private
280 // ===========================================================================
281 
282 void
283 GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
284  switch (key) {
285  case SUMO_ATTR_LANES:
286  throw InvalidArgument(getTagStr() + " cannot be edited");
287  case SUMO_ATTR_ID:
288  // update microsimID
289  setMicrosimID(value);
290  break;
291  case SUMO_ATTR_POSITION:
292  myPosition = parse<Position>(value);
293  // update boundary (except for template)
294  if (getID().size() > 0) {
296  }
297  break;
298  case SUMO_ATTR_NAME:
299  myAdditionalName = value;
300  break;
301  case SUMO_ATTR_VTYPES:
302  myVehicleTypes = parse<std::vector<std::string> >(value);
303  break;
304  case GNE_ATTR_SELECTED:
305  if (parse<bool>(value)) {
307  } else {
309  }
310  break;
311  case GNE_ATTR_PARAMETERS:
312  setParametersStr(value);
313  break;
314  default:
315  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
316  }
317 }
318 
319 
320 void
322  // update position
323  myPosition = moveResult.shapeToUpdate.front();
324  // update geometry
325  updateGeometry();
326 }
327 
328 
329 void
331  undoList->begin(GUIIcon::VARIABLESPEEDSIGN, "position of " + getTagStr());
332  undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
333  undoList->end();
334 }
335 
336 
337 void
338 GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
339  undoList->begin(GUIIcon::VARIABLESPEEDSIGN, ("change " + getTagStr() + " attribute").c_str());
340  // drop all additional children
341  while (getChildAdditionals().size() > 0) {
342  undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
343  }
344  // get lane vector
345  const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
346  // create new VSS Symbols
347  for (const auto& lane : lanes) {
348  // create VSS Symbol
349  GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
350  // add it using GNEChange_Additional
351  myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
352  }
353  undoList->end();
354 }
355 
356 /****************************************************************************/
@ GLO_VSS
a Variable Speed Sign
@ 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:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
An Element which don't belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
const std::string & getID() const
get 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.
bool isValidAdditionalID(const std::string &newID) const
check if a new additional ID is valid
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
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
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
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:1210
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1222
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
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...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
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
bool isAttributeEnabled(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 conrrespond attribute are valids
void rebuildVSSSymbols(const std::string &value, GNEUndoList *undoList)
rebuild VSS Symbols
Position myPosition
position of VSS in view
void writeAdditional(OutputDevice &device) const
writte additional element into a xml file
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 GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:525
GNEUndoList * getUndoList() const
get the undoList object
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.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
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:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
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|....
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"
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