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-2025 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
38
39
40GNEVariableSpeedSign::GNEVariableSpeedSign(const std::string& id, GNENet* net, FileBucket* fileBucket,
41 const Position& pos, const std::string& name, const std::vector<std::string>& vTypes,
42 const Parameterised::Map& parameters) :
43 GNEAdditional(id, net, SUMO_TAG_VSS, fileBucket, name),
44 GNEAdditionalSquared(this, pos),
45 Parameterised(parameters),
46 myVehicleTypes(vTypes) {
47 // update centering boundary without updating grid
49}
50
51
54
55
60
61
66
67
68const Parameterised*
70 return this;
71}
72
73
74void
76 // avoid write rerouters without edges
77 if (getAttribute(SUMO_ATTR_LANES).size() > 0) {
78 device.openTag(SUMO_TAG_VSS);
79 // write common additional attributes
81 // write move atributes
83 // write specific attributes
85 if (!myVehicleTypes.empty()) {
87 }
88 // write all rerouter interval
89 for (const auto& step : getChildAdditionals()) {
90 if (!step->getTagProperty()->isSymbol()) {
91 step->writeAdditional(device);
92 }
93 }
94 // write parameters (Always after children to avoid problems with additionals.xsd)
95 writeParams(device);
96 device.closeTag();
97 } else {
98 WRITE_WARNING("Variable Speed Sign '" + getID() + TL("' needs at least one lane"));
99 }
100}
101
102
103bool
104GNEVariableSpeedSign::GNEVariableSpeedSign::isAdditionalValid() const {
105 return true;
106}
107
108
109std::string
110GNEVariableSpeedSign::GNEVariableSpeedSign::getAdditionalProblem() const {
111 return "";
112}
113
114
115void
116GNEVariableSpeedSign::GNEVariableSpeedSign::fixAdditionalProblem() {
117 // nothing to fix
118}
119
120
121void
125
126
131
132
133void
137
138
139void
140GNEVariableSpeedSign::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
141 // geometry of this element cannot be splitted
142}
143
144
145bool
147 // get edit modes
148 const auto& editModes = myNet->getViewNet()->getEditModes();
149 // check if we're in move mode
150 if (!myNet->getViewNet()->isCurrentlyMovingElements() && editModes.isCurrentSupermodeNetwork() &&
152 (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) && myNet->getViewNet()->checkOverLockedElement(this, mySelected)) {
153 // only move the first element
155 } else {
156 return false;
157 }
158}
159
160
161void
162GNEVariableSpeedSign::openAdditionalDialog(FXWindow* restoringFocusWindow) {
163 // Open VSS dialog
164 UNUSED_PARAMETER(restoringFocusWindow);
166}
167
168
169std::string
173
174
175void
177 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
178 // first check if additional has to be drawn
180 // draw parent and child lines
182 // draw VSS
184 // iterate over additionals and check if drawn
185 for (const auto& step : getChildAdditionals()) {
186 // if rerouter or their intevals are selected, then draw
188 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
189 step->isAttributeCarrierSelected() || inspectedElements.isACInspected(step) ||
190 step->isMarkedForDrawingFront()) {
191 step->drawGL(s);
192 }
193 }
194 }
195}
196
197
198std::string
200 switch (key) {
201 case SUMO_ATTR_ID:
202 return getMicrosimID();
203 case SUMO_ATTR_LANES: {
204 std::vector<std::string> lanes;
205 for (const auto& VSSSymbol : getChildAdditionals()) {
206 if (VSSSymbol->getTagProperty()->isSymbol()) {
207 lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
208 }
209 }
210 return toString(lanes);
211 }
212 case SUMO_ATTR_NAME:
213 return myAdditionalName;
214 case SUMO_ATTR_VTYPES:
215 return toString(myVehicleTypes);
216 default:
218 }
219}
220
221
222double
226
227
232
233
238
239
240void
241GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
242 if (value == getAttribute(key)) {
243 return; //avoid needless changes, later logic relies on the fact that attributes have changed
244 }
245 switch (key) {
246 // special case for lanes due VSS Symbols
247 case SUMO_ATTR_LANES:
248 // rebuild VSS Symbols
249 rebuildVSSSymbols(value, undoList);
250 break;
251 case SUMO_ATTR_ID:
252 case SUMO_ATTR_NAME:
253 case SUMO_ATTR_VTYPES:
254 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
255 break;
256 default:
257 myMoveElementView->setMovingAttribute(key, value, undoList);
258 break;
259 }
260}
261
262
263bool
264GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
265 switch (key) {
266 case SUMO_ATTR_ID:
267 return isValidAdditionalID(value);
268 case SUMO_ATTR_LANES:
269 return canParse<std::vector<GNELane*> >(myNet, value, false);
270 case SUMO_ATTR_NAME:
272 case SUMO_ATTR_VTYPES:
273 if (value.empty()) {
274 return true;
275 } else {
277 }
278 default:
279 return myMoveElementView->isMovingAttributeValid(key, value);
280 }
281}
282
283
284std::string
286 return getTagStr() + ": " + getID();
287}
288
289
290std::string
294
295// ===========================================================================
296// private
297// ===========================================================================
298
299void
300GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
301 switch (key) {
302 case SUMO_ATTR_LANES:
303 throw InvalidArgument(getTagStr() + " cannot be edited");
304 case SUMO_ATTR_ID:
305 // update microsimID
306 setAdditionalID(value);
307 break;
308 case SUMO_ATTR_NAME:
309 myAdditionalName = value;
310 break;
311 case SUMO_ATTR_VTYPES:
312 myVehicleTypes = parse<std::vector<std::string> >(value);
313 break;
314 default:
316 break;
317 }
318 // update boundary (except for template)
319 if (getID().size() > 0) {
321 }
322}
323
324
325void
326GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
327 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
328 // drop all additional children
329 while (getChildAdditionals().size() > 0) {
330 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
331 }
332 // get lane vector
333 const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
334 // create new VSS Symbols
335 for (const auto& lane : lanes) {
336 // create VSS Symbol
337 GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
338 // add it using GNEChange_Additional
339 myNet->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
340 }
341 undoList->end();
342}
343
344/****************************************************************************/
@ 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:46
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 & 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.
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