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
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
44GNEVariableSpeedSign::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),
49myVehicleTypes(vTypes) {
50 // update centering boundary without updating grid
51 updateCenteringBoundary(false);
52}
53
54
56}
57
58
59void
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
85 // return move operation for additional placed in view
86 return new GNEMoveOperation(this, myPosition);
87}
88
89
90void
92 // update additional geometry
94 // update geometries (boundaries of all children)
95 for (const auto& additionalChildren : getChildAdditionals()) {
96 additionalChildren->updateGeometry();
97 }
98}
99
100
103 return myPosition;
104}
105
106
107void
109 // remove additional from grid
110 if (updateGrid) {
112 }
113 // update geometry
115 // add shape boundary
117 // add positions of all childrens (symbols and steps)
118 for (const auto& additionalChildren : getChildAdditionals()) {
119 myAdditionalBoundary.add(additionalChildren->getPositionInView());
120 // also update centering boundary
121 additionalChildren->updateCenteringBoundary(false);
122 }
123 // grow
125 // add additional into RTREE again
126 if (updateGrid) {
128 }
129}
130
131
132void
133GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
134 // geometry of this element cannot be splitted
135}
136
137
138void
140 // Open VSS dialog
142}
143
144
145std::string
147 return myNet->getMicrosimID();
148}
149
150
151void
153 // draw parent and child lines
155 // draw VSS
157 // iterate over additionals and check if drawn
158 for (const auto& step : getChildAdditionals()) {
159 // if rerouter or their intevals are selected, then draw
162 step->isAttributeCarrierSelected() || myNet->getViewNet()->isAttributeCarrierInspected(step) ||
163 (myNet->getViewNet()->getFrontAttributeCarrier() == step)) {
164 step->drawGL(s);
165 }
166 }
167}
168
169
170std::string
172 switch (key) {
173 case SUMO_ATTR_ID:
174 return getMicrosimID();
175 case SUMO_ATTR_LANES: {
176 std::vector<std::string> lanes;
177 for (const auto& VSSSymbol : getChildAdditionals()) {
178 if (VSSSymbol->getTagProperty().isSymbol()) {
179 lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
180 }
181 }
182 return toString(lanes);
183 }
185 return toString(myPosition);
186 case SUMO_ATTR_NAME:
187 return myAdditionalName;
188 case SUMO_ATTR_VTYPES:
189 return toString(myVehicleTypes);
193 return getParametersStr();
194 default:
195 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
196 }
197}
198
199
200double
202 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
203}
204
205
208 return getParametersMap();
209}
210
211
212void
213GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
214 if (value == getAttribute(key)) {
215 return; //avoid needless changes, later logic relies on the fact that attributes have changed
216 }
217 switch (key) {
218 // special case for lanes due VSS Symbols
219 case SUMO_ATTR_LANES:
220 // rebuild VSS Symbols
221 rebuildVSSSymbols(value, undoList);
222 break;
223 case SUMO_ATTR_ID:
225 case SUMO_ATTR_NAME:
226 case SUMO_ATTR_VTYPES:
229 undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
230 break;
231 default:
232 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
233 }
234}
235
236
237bool
238GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
239 switch (key) {
240 case SUMO_ATTR_ID:
241 return isValidAdditionalID(value);
243 return canParse<Position>(value);
244 case SUMO_ATTR_LANES:
245 return canParse<std::vector<GNELane*> >(myNet, value, false);
246 case SUMO_ATTR_NAME:
248 case SUMO_ATTR_VTYPES:
249 if (value.empty()) {
250 return true;
251 } else {
253 }
255 return canParse<bool>(value);
257 return areParametersValid(value);
258 default:
259 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
260 }
261}
262
263
264std::string
266 return getTagStr() + ": " + getID();
267}
268
269
270std::string
272 return getTagStr();
273}
274
275// ===========================================================================
276// private
277// ===========================================================================
278
279void
280GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
281 switch (key) {
282 case SUMO_ATTR_LANES:
283 throw InvalidArgument(getTagStr() + " cannot be edited");
284 case SUMO_ATTR_ID:
285 // update microsimID
286 setMicrosimID(value);
287 break;
289 myPosition = parse<Position>(value);
290 // update boundary (except for template)
291 if (getID().size() > 0) {
293 }
294 break;
295 case SUMO_ATTR_NAME:
296 myAdditionalName = value;
297 break;
298 case SUMO_ATTR_VTYPES:
299 myVehicleTypes = parse<std::vector<std::string> >(value);
300 break;
302 if (parse<bool>(value)) {
304 } else {
306 }
307 break;
309 setParametersStr(value);
310 break;
311 default:
312 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
313 }
314}
315
316
317void
319 // update position
320 myPosition = moveResult.shapeToUpdate.front();
321 // update geometry
323}
324
325
326void
328 undoList->begin(GUIIcon::VARIABLESPEEDSIGN, "position of " + getTagStr());
329 undoList->changeAttribute(new GNEChange_Attribute(this, SUMO_ATTR_POSITION, toString(moveResult.shapeToUpdate.front())));
330 undoList->end();
331}
332
333
334void
335GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
336 undoList->begin(GUIIcon::VARIABLESPEEDSIGN, ("change " + getTagStr() + " attribute").c_str());
337 // drop all additional children
338 while (getChildAdditionals().size() > 0) {
339 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
340 }
341 // get lane vector
342 const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
343 // create new VSS Symbols
344 for (const auto& lane : lanes) {
345 // create VSS Symbol
346 GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
347 // add it using GNEChange_Additional
348 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
349 }
350 undoList->end();
351}
352
353/****************************************************************************/
@ 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:300
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:48
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
const std::string getID() const
get ID (all Attribute Carriers have one)
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:1245
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition: GNENet.cpp:1257
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1987
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
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
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 GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:644
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.
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
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 & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
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