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
22
26#include <netedit/GNENet.h>
27#include <netedit/GNEUndoList.h>
28
31
32// ===========================================================================
33// member method definitions
34// ===========================================================================
35
36#ifdef _MSC_VER
37#pragma warning(push)
38#pragma warning(disable: 4355) // mask warning about "this" in initializers
39#endif
44
45
46GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNENet* net, FileBucket* fileBucket,
47 const Position& pos, const std::string& name, const std::vector<std::string>& vTypes,
48 const Parameterised::Map& parameters) :
49 GNEAdditional(id, net, SUMO_TAG_VSS, fileBucket, name),
50 GNEAdditionalSquared(this, pos),
51 Parameterised(parameters),
52 myVehicleTypes(vTypes) {
53 // update centering boundary without updating grid
55}
56#ifdef _MSC_VER
57#pragma warning(pop)
58#endif
59
60
63
64
69
70
75
76
77const Parameterised*
79 return this;
80}
81
82
83void
85 // avoid write rerouters without edges
86 if (getAttribute(SUMO_ATTR_LANES).size() > 0) {
87 device.openTag(SUMO_TAG_VSS);
88 // write common additional attributes
90 // write move atributes
92 // write specific attributes
94 if (!myVehicleTypes.empty()) {
96 }
97 // write all rerouter interval
98 for (const auto& step : getChildAdditionals()) {
99 if (!step->getTagProperty()->isSymbol()) {
100 step->writeAdditional(device);
101 }
102 }
103 // write parameters (Always after children to avoid problems with additionals.xsd)
104 XMLHelpers::writeParams(device, *this);
105 device.closeTag();
106 } else {
107 WRITE_WARNING("Variable Speed Sign '" + getID() + TL("' needs at least one lane"));
108 }
109}
110
111
112bool
113GNEVariableSpeedSign::GNEVariableSpeedSign::isAdditionalValid() const {
114 return true;
115}
116
117
118std::string
119GNEVariableSpeedSign::GNEVariableSpeedSign::getAdditionalProblem() const {
120 return "";
121}
122
123
124void
125GNEVariableSpeedSign::GNEVariableSpeedSign::fixAdditionalProblem() {
126 // nothing to fix
127}
128
129
130void
134
135
140
141
142void
146
147
148void
149GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
150 // geometry of this element cannot be splitted
151}
152
153
154bool
156 // get edit modes
157 const auto& editModes = myNet->getViewNet()->getEditModes();
158 // check if we're in move mode
159 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
161 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
162 // only move the first element
164 } else {
165 return false;
166 }
167}
168
169
170void
171GNEVariableSpeedSign::openAdditionalDialog(FXWindow* restoringFocusWindow) {
172 // Open VSS dialog
173 UNUSED_PARAMETER(restoringFocusWindow);
175}
176
177
178std::string
182
183
184void
186 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
187 // first check if additional has to be drawn
189 // draw parent and child lines
191 // draw VSS
193 // iterate over additionals and check if drawn
194 for (const auto& step : getChildAdditionals()) {
195 // if rerouter or their intevals are selected, then draw
197 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
198 step->isAttributeCarrierSelected() || inspectedElements.isACInspected(step) ||
199 step->isMarkedForDrawingFront()) {
200 step->drawGL(s);
201 }
202 }
203 }
204}
205
206
207std::string
209 switch (key) {
210 case SUMO_ATTR_ID:
211 return getMicrosimID();
212 case SUMO_ATTR_LANES: {
213 std::vector<std::string> lanes;
214 for (const auto& VSSSymbol : getChildAdditionals()) {
215 if (VSSSymbol->getTagProperty()->isSymbol()) {
216 lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
217 }
218 }
219 return toString(lanes);
220 }
221 case SUMO_ATTR_NAME:
222 return myAdditionalName;
223 case SUMO_ATTR_VTYPES:
224 return toString(myVehicleTypes);
225 default:
227 }
228}
229
230
231double
235
236
241
242
247
248
249void
250GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
251 if (value == getAttribute(key)) {
252 return; //avoid needless changes, later logic relies on the fact that attributes have changed
253 }
254 switch (key) {
255 // special case for lanes due VSS Symbols
256 case SUMO_ATTR_LANES:
257 // rebuild VSS Symbols
258 rebuildVSSSymbols(value, undoList);
259 break;
260 case SUMO_ATTR_ID:
261 case SUMO_ATTR_NAME:
262 case SUMO_ATTR_VTYPES:
263 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
264 break;
265 default:
266 myMoveElementView->setMovingAttribute(key, value, undoList);
267 break;
268 }
269}
270
271
272bool
273GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
274 switch (key) {
275 case SUMO_ATTR_ID:
276 return isValidAdditionalID(value);
277 case SUMO_ATTR_LANES:
278 return canParse<std::vector<GNELane*> >(myNet, value, false);
279 case SUMO_ATTR_NAME:
280 return StringUtils::isValidAttribute(value);
281 case SUMO_ATTR_VTYPES:
282 if (value.empty()) {
283 return true;
284 } else {
286 }
287 default:
288 return myMoveElementView->isMovingAttributeValid(key, value);
289 }
290}
291
292
293std::string
295 return getTagStr() + ": " + getID();
296}
297
298
299std::string
303
304// ===========================================================================
305// private
306// ===========================================================================
307
308void
309GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
310 switch (key) {
311 case SUMO_ATTR_LANES:
312 throw InvalidArgument(getTagStr() + " cannot be edited");
313 case SUMO_ATTR_ID:
314 // update microsimID
315 setAdditionalID(value);
316 break;
317 case SUMO_ATTR_NAME:
318 myAdditionalName = value;
319 break;
320 case SUMO_ATTR_VTYPES:
321 myVehicleTypes = parse<std::vector<std::string> >(value);
322 break;
323 default:
325 break;
326 }
327 // update boundary (except for template)
328 if (getID().size() > 0) {
330 }
331}
332
333
334void
335GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
336 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
337 // drop all additional symbol children
338 std::vector<GNEAdditional*> symbols;
339 for (const auto symbol : getChildAdditionals()) {
340 if (symbol->getTagProperty()->isSymbol()) {
341 symbols.push_back(symbol);
342 }
343 }
344 for (const auto symbol : symbols) {
345 undoList->add(new GNEChange_Additional(symbol, false), true);
346 }
347 // get lane vector
348 const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
349 // create new VSS Symbols
350 for (const auto& lane : lanes) {
351 // create VSS Symbol
352 GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
353 // add it using GNEChange_Additional
354 myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
355 }
356 undoList->end();
357}
358
359/****************************************************************************/
@ NETWORK_MOVE
mode for moving network elements
@ VARIABLESPEEDSIGN_SELECTED
#define WRITE_WARNING(msg)
Definition MsgHandler.h:298
#define TL(string)
Definition MsgHandler.h:316
@ 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:57
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, const bool escape=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
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)
static OutputDevice & writeParams(OutputDevice &device, const Parameterised &params)
write the parameters of the given object as param tags
#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