Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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
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
57
58
59void
61 // avoid write rerouters without edges
62 if (getAttribute(SUMO_ATTR_LANES).size() > 0) {
63 device.openTag(SUMO_TAG_VSS);
64 device.writeAttr(SUMO_ATTR_ID, getID());
67 if (!myAdditionalName.empty()) {
69 }
70 if (!myVehicleTypes.empty()) {
72 }
73 // write all rerouter interval
74 for (const auto& step : getChildAdditionals()) {
75 if (!step->getTagProperty().isSymbol()) {
76 step->writeAdditional(device);
77 }
78 }
79 // write parameters (Always after children to avoid problems with additionals.xsd)
80 writeParams(device);
81 device.closeTag();
82 } else {
83 WRITE_WARNING("Variable Speed Sign '" + getID() + TL("' needs at least one lane"));
84 }
85}
86
87
88bool
89GNEVariableSpeedSign::GNEVariableSpeedSign::isAdditionalValid() const {
90 return true;
91}
92
93
94std::string
95GNEVariableSpeedSign::GNEVariableSpeedSign::getAdditionalProblem() const {
96 return "";
97}
98
99
100void
101GNEVariableSpeedSign::GNEVariableSpeedSign::fixAdditionalProblem() {
102 // nothing to fix
103}
104
105
108 // return move operation for additional placed in view
109 return new GNEMoveOperation(this, myPosition);
110}
111
112
113void
115 // update additional geometry
117 // update geometries (boundaries of all children)
118 for (const auto& additionalChildren : getChildAdditionals()) {
119 additionalChildren->updateGeometry();
120 }
121}
122
123
128
129
130void
132 // remove additional from grid
133 if (updateGrid) {
135 }
136 // update geometry
138 // add shape boundary
140 // add positions of all childrens (symbols and steps)
141 for (const auto& additionalChildren : getChildAdditionals()) {
142 myAdditionalBoundary.add(additionalChildren->getPositionInView());
143 }
144 // grow
146 // add additional into RTREE again
147 if (updateGrid) {
149 }
150}
151
152
153void
154GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
155 // geometry of this element cannot be splitted
156}
157
158
159bool
161 // get edit modes
162 const auto& editModes = myNet->getViewNet()->getEditModes();
163 // check if we're in move mode
164 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
166 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
167 // only move the first element
169 } else {
170 return false;
171 }
172}
173
174
175void
180
181
182std::string
186
187
188void
190 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
191 // draw parent and child lines
193 // draw VSS
195 // iterate over additionals and check if drawn
196 for (const auto& step : getChildAdditionals()) {
197 // if rerouter or their intevals are selected, then draw
199 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
200 step->isAttributeCarrierSelected() || inspectedElements.isACInspected(step) ||
201 (myNet->getViewNet()->getFrontAttributeCarrier() == step)) {
202 step->drawGL(s);
203 }
204 }
205}
206
207
208std::string
210 switch (key) {
211 case SUMO_ATTR_ID:
212 return getMicrosimID();
213 case SUMO_ATTR_LANES: {
214 std::vector<std::string> lanes;
215 for (const auto& VSSSymbol : getChildAdditionals()) {
216 if (VSSSymbol->getTagProperty().isSymbol()) {
217 lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
218 }
219 }
220 return toString(lanes);
221 }
223 return toString(myPosition);
224 case SUMO_ATTR_NAME:
225 return myAdditionalName;
226 case SUMO_ATTR_VTYPES:
227 return toString(myVehicleTypes);
231 return getParametersStr();
232 default:
233 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
234 }
235}
236
237
238double
240 throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
241}
242
243
248
249
250void
251GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
252 if (value == getAttribute(key)) {
253 return; //avoid needless changes, later logic relies on the fact that attributes have changed
254 }
255 switch (key) {
256 // special case for lanes due VSS Symbols
257 case SUMO_ATTR_LANES:
258 // rebuild VSS Symbols
259 rebuildVSSSymbols(value, undoList);
260 break;
261 case SUMO_ATTR_ID:
263 case SUMO_ATTR_NAME:
264 case SUMO_ATTR_VTYPES:
267 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
268 break;
269 default:
270 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
271 }
272}
273
274
275bool
276GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
277 switch (key) {
278 case SUMO_ATTR_ID:
279 return isValidAdditionalID(value);
281 return canParse<Position>(value);
282 case SUMO_ATTR_LANES:
283 return canParse<std::vector<GNELane*> >(myNet, value, false);
284 case SUMO_ATTR_NAME:
286 case SUMO_ATTR_VTYPES:
287 if (value.empty()) {
288 return true;
289 } else {
291 }
293 return canParse<bool>(value);
295 return areParametersValid(value);
296 default:
297 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
298 }
299}
300
301
302std::string
304 return getTagStr() + ": " + getID();
305}
306
307
308std::string
312
313// ===========================================================================
314// private
315// ===========================================================================
316
317void
318GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
319 switch (key) {
320 case SUMO_ATTR_LANES:
321 throw InvalidArgument(getTagStr() + " cannot be edited");
322 case SUMO_ATTR_ID:
323 // update microsimID
324 setAdditionalID(value);
325 break;
327 myPosition = parse<Position>(value);
328 // update boundary (except for template)
329 if (getID().size() > 0) {
331 }
332 break;
333 case SUMO_ATTR_NAME:
334 myAdditionalName = value;
335 break;
336 case SUMO_ATTR_VTYPES:
337 myVehicleTypes = parse<std::vector<std::string> >(value);
338 break;
340 if (parse<bool>(value)) {
342 } else {
344 }
345 break;
347 setParametersStr(value);
348 break;
349 default:
350 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
351 }
352}
353
354
355void
357 // update position
358 myPosition = moveResult.shapeToUpdate.front();
359 // update geometry
361}
362
363
364void
366 undoList->begin(this, "position of " + getTagStr());
368 undoList->end();
369}
370
371
372void
373GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
374 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
375 // drop all additional children
376 while (getChildAdditionals().size() > 0) {
377 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
378 }
379 // get lane vector
380 const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
381 // create new VSS Symbols
382 for (const auto& lane : lanes) {
383 // create VSS Symbol
384 GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
385 // add it using GNEChange_Additional
386 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
387 }
388 undoList->end();
389}
390
391/****************************************************************************/
@ 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
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
@ 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:343
An Element which don't belong to GNENet but has influence in the simulation.
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:1386
void removeGLObjectFromGrid(GNEAttributeCarrier *AC)
add GL Object into net
Definition GNENet.cpp:1396
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
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 GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
GNEViewNetHelper::InspectedElements & getInspectedElements()
get inspected elements
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
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
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.
Stores the information about how to visualize structures.
GUIVisualizationAdditionalSettings additionalSettings
Additional settings.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
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.
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
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.
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
bool showSubAdditionals() const
check if show sub-additionals
static const RGBColor connectionColor
connection color