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-2026 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
24#include <netedit/GNENet.h>
25#include <netedit/GNEUndoList.h>
26
29
30// ===========================================================================
31// member method definitions
32// ===========================================================================
33
34#ifdef _MSC_VER
35#pragma warning(push)
36#pragma warning(disable: 4355) // mask warning about "this" in initializers
37#endif
42
43
44GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNENet* net, FileBucket* fileBucket,
45 const Position& pos, const std::string& name, const std::vector<std::string>& vTypes,
46 const Parameterised::Map& parameters) :
47 GNEAdditional(id, net, SUMO_TAG_VSS, fileBucket, name),
48 GNEAdditionalSquared(this, pos),
49 Parameterised(parameters),
50 myVehicleTypes(vTypes) {
51 // update centering boundary without updating grid
53}
54#ifdef _MSC_VER
55#pragma warning(pop)
56#endif
57
58
61
62
67
68
73
74
75const Parameterised*
77 return this;
78}
79
80
81void
83 // avoid write rerouters without edges
84 if (getAttribute(SUMO_ATTR_LANES).size() > 0) {
85 device.openTag(SUMO_TAG_VSS);
86 // write common additional attributes
88 // write move atributes
90 // write specific attributes
92 if (!myVehicleTypes.empty()) {
94 }
95 // write all rerouter interval
96 for (const auto& step : getChildAdditionals()) {
97 if (!step->getTagProperty()->isSymbol()) {
98 step->writeAdditional(device);
99 }
100 }
101 // write parameters (Always after children to avoid problems with additionals.xsd)
102 writeParams(device);
103 device.closeTag();
104 } else {
105 WRITE_WARNING("Variable Speed Sign '" + getID() + TL("' needs at least one lane"));
106 }
107}
108
109
110bool
111GNEVariableSpeedSign::GNEVariableSpeedSign::isAdditionalValid() const {
112 return true;
113}
114
115
116std::string
117GNEVariableSpeedSign::GNEVariableSpeedSign::getAdditionalProblem() const {
118 return "";
119}
120
121
122void
123GNEVariableSpeedSign::GNEVariableSpeedSign::fixAdditionalProblem() {
124 // nothing to fix
125}
126
127
128void
132
133
138
139
140void
144
145
146void
147GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
148 // geometry of this element cannot be splitted
149}
150
151
152bool
154 // get edit modes
155 const auto& editModes = myNet->getViewNet()->getEditModes();
156 // check if we're in move mode
157 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
159 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
160 // only move the first element
162 } else {
163 return false;
164 }
165}
166
167
168void
169GNEVariableSpeedSign::openAdditionalDialog(FXWindow* restoringFocusWindow) {
170 // Open VSS dialog
171 UNUSED_PARAMETER(restoringFocusWindow);
173}
174
175
176std::string
180
181
182void
184 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
185 // first check if additional has to be drawn
187 // draw parent and child lines
189 // draw VSS
191 // iterate over additionals and check if drawn
192 for (const auto& step : getChildAdditionals()) {
193 // if rerouter or their intevals are selected, then draw
195 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
196 step->isAttributeCarrierSelected() || inspectedElements.isACInspected(step) ||
197 step->isMarkedForDrawingFront()) {
198 step->drawGL(s);
199 }
200 }
201 }
202}
203
204
205std::string
207 switch (key) {
208 case SUMO_ATTR_ID:
209 return getMicrosimID();
210 case SUMO_ATTR_LANES: {
211 std::vector<std::string> lanes;
212 for (const auto& VSSSymbol : getChildAdditionals()) {
213 if (VSSSymbol->getTagProperty()->isSymbol()) {
214 lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
215 }
216 }
217 return toString(lanes);
218 }
219 case SUMO_ATTR_NAME:
220 return myAdditionalName;
221 case SUMO_ATTR_VTYPES:
222 return toString(myVehicleTypes);
223 default:
225 }
226}
227
228
229double
233
234
239
240
245
246
247void
248GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
249 if (value == getAttribute(key)) {
250 return; //avoid needless changes, later logic relies on the fact that attributes have changed
251 }
252 switch (key) {
253 // special case for lanes due VSS Symbols
254 case SUMO_ATTR_LANES:
255 // rebuild VSS Symbols
256 rebuildVSSSymbols(value, undoList);
257 break;
258 case SUMO_ATTR_ID:
259 case SUMO_ATTR_NAME:
260 case SUMO_ATTR_VTYPES:
261 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
262 break;
263 default:
264 myMoveElementView->setMovingAttribute(key, value, undoList);
265 break;
266 }
267}
268
269
270bool
271GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
272 switch (key) {
273 case SUMO_ATTR_ID:
274 return isValidAdditionalID(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 default:
286 return myMoveElementView->isMovingAttributeValid(key, value);
287 }
288}
289
290
291std::string
293 return getTagStr() + ": " + getID();
294}
295
296
297std::string
301
302// ===========================================================================
303// private
304// ===========================================================================
305
306void
307GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
308 switch (key) {
309 case SUMO_ATTR_LANES:
310 throw InvalidArgument(getTagStr() + " cannot be edited");
311 case SUMO_ATTR_ID:
312 // update microsimID
313 setAdditionalID(value);
314 break;
315 case SUMO_ATTR_NAME:
316 myAdditionalName = value;
317 break;
318 case SUMO_ATTR_VTYPES:
319 myVehicleTypes = parse<std::vector<std::string> >(value);
320 break;
321 default:
323 break;
324 }
325 // update boundary (except for template)
326 if (getID().size() > 0) {
328 }
329}
330
331
332void
333GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
334 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
335 // drop all additional symbol children
336 std::vector<GNEAdditional*> symbols;
337 for (const auto symbol : getChildAdditionals()) {
338 if (symbol->getTagProperty()->isSymbol()) {
339 symbols.push_back(symbol);
340 }
341 }
342 for (const auto symbol : symbols) {
343 undoList->add(new GNEChange_Additional(symbol, false), true);
344 }
345 // get lane vector
346 const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
347 // create new VSS Symbols
348 for (const auto& lane : lanes) {
349 // create VSS Symbol
350 GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
351 // add it using GNEChange_Additional
352 myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
353 }
354 undoList->end();
355}
356
357/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ VARIABLESPEEDSIGN_SELECTED
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
@ SUMO_TAG_VSS
A variable speed sign.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_LANE
@ SUMO_ATTR_LANES
@ SUMO_ATTR_VTYPES
@ SUMO_ATTR_NAME
@ SUMO_ATTR_ID
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.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
std::string myAdditionalName
name of additional
void writeAdditionalAttributes(OutputDevice &device) const
write common additional attributes
void drawParentChildLines(const GUIVisualizationSettings &s, const RGBColor &color, const bool onlySymbols=false) const
draw parent and child lines
void updatedSquaredGeometry()
updated squared geometry
Position myPosOverView
position over view
void updatedSquaredCenteringBoundary(const bool updateGrid)
updated squared centering boundary
GNEMoveElementView * myMoveElementView
move element over view
void drawSquaredAdditional(const GUIVisualizationSettings &s, const double size, GUITexture texture, GUITexture selectedTexture) const
draw squared additional
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
const std::string getID() const override
get ID (all Attribute Carriers have one)
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
Position getMovingAttributePosition(SumoXMLAttr key) const override
get moving attribute position
void writeMoveAttributes(OutputDevice &device) const
write move attributes
void setMovingAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
set moving attribute (using undo-list)
PositionVector getMovingAttributePositionVector(SumoXMLAttr key) const override
get moving attribute positionVector
double getMovingAttributeDouble(SumoXMLAttr key) const override
get moving attribute double
std::string getMovingAttribute(SumoXMLAttr key) const override
get moving attribute
bool isMovingAttributeValid(SumoXMLAttr key, const std::string &value) const override
check if the given moving attribute is valid
GNEUndoList * getUndoList() const
get undo list(used for simplify code)
Definition GNENet.cpp:156
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
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 updateGeometry() override
update pre-computed geometry information
Position getAttributePosition(SumoXMLAttr key) const override
void openAdditionalDialog(FXWindow *restoringFocusWindow) override
open GNEVariableSpeedSignDialog
Parameterised * getParameters() override
get parameters associated with this variableSpeedSign
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
double getAttributeDouble(SumoXMLAttr key) const override
void drawGL(const GUIVisualizationSettings &s) const override
Draws the object.
GNEVariableSpeedSign(GNENet *net)
default Constructor
Position getPositionInView() const override
Returns position of additional in view.
void rebuildVSSSymbols(const std::string &value, GNEUndoList *undoList)
rebuild VSS Symbols
void writeAdditional(OutputDevice &device) const override
write additional element into a xml file
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
std::string getAttribute(SumoXMLAttr key) const override
std::string getParentName() const override
Returns the name of the parent object.
bool checkDrawMoveContour() const override
check if draw move contour (red)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this variableSpeedSign
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList) override
split geometry
bool isValid(SumoXMLAttr key, const std::string &value) override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
std::vector< std::string > myVehicleTypes
attribute vehicle types
void updateCenteringBoundary(const bool updateGrid) override
update centering boundary (implies change in RTREE)
const GUIGlObject * getGUIGlObjectFront() const
get front GUIGLObject or a pointer to nullptr
bool isCurrentlyMovingElements() const
check if an element is being moved
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
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)
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
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 & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false)
writes a named attribute
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.
std::map< std::string, std::string > Map
parameters map
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
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)
#define UNUSED_PARAMETER(x)
bool showAdditionals() const
check if additionals has to be drawn
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
bool showSubAdditionals() const
check if show sub-additionals
static const RGBColor connectionColor
connection color