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, const std::string& filename,
41 const Position& pos, const std::string& name, const std::vector<std::string>& vTypes,
42 const Parameterised::Map& parameters) :
43 GNEAdditional(id, net, filename, SUMO_TAG_VSS, 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
166
167
168std::string
172
173
174void
176 const auto& inspectedElements = myNet->getViewNet()->getInspectedElements();
177 // first check if additional has to be drawn
179 // draw parent and child lines
181 // draw VSS
183 // iterate over additionals and check if drawn
184 for (const auto& step : getChildAdditionals()) {
185 // if rerouter or their intevals are selected, then draw
187 isAttributeCarrierSelected() || inspectedElements.isACInspected(this) ||
188 step->isAttributeCarrierSelected() || inspectedElements.isACInspected(step) ||
189 step->isMarkedForDrawingFront()) {
190 step->drawGL(s);
191 }
192 }
193 }
194}
195
196
197std::string
199 switch (key) {
200 case SUMO_ATTR_ID:
201 return getMicrosimID();
202 case SUMO_ATTR_LANES: {
203 std::vector<std::string> lanes;
204 for (const auto& VSSSymbol : getChildAdditionals()) {
205 if (VSSSymbol->getTagProperty()->isSymbol()) {
206 lanes.push_back(VSSSymbol->getAttribute(SUMO_ATTR_LANE));
207 }
208 }
209 return toString(lanes);
210 }
211 case SUMO_ATTR_NAME:
212 return myAdditionalName;
213 case SUMO_ATTR_VTYPES:
214 return toString(myVehicleTypes);
215 default:
217 }
218}
219
220
221double
225
226
231
232
237
238
239void
240GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
241 if (value == getAttribute(key)) {
242 return; //avoid needless changes, later logic relies on the fact that attributes have changed
243 }
244 switch (key) {
245 // special case for lanes due VSS Symbols
246 case SUMO_ATTR_LANES:
247 // rebuild VSS Symbols
248 rebuildVSSSymbols(value, undoList);
249 break;
250 case SUMO_ATTR_ID:
251 case SUMO_ATTR_NAME:
252 case SUMO_ATTR_VTYPES:
253 GNEChange_Attribute::changeAttribute(this, key, value, undoList);
254 break;
255 default:
256 myMoveElementView->setMovingAttribute(key, value, undoList);
257 break;
258 }
259}
260
261
262bool
263GNEVariableSpeedSign::isValid(SumoXMLAttr key, const std::string& value) {
264 switch (key) {
265 case SUMO_ATTR_ID:
266 return isValidAdditionalID(value);
267 case SUMO_ATTR_LANES:
268 return canParse<std::vector<GNELane*> >(myNet, value, false);
269 case SUMO_ATTR_NAME:
271 case SUMO_ATTR_VTYPES:
272 if (value.empty()) {
273 return true;
274 } else {
276 }
277 default:
278 return myMoveElementView->isMovingAttributeValid(key, value);
279 }
280}
281
282
283std::string
285 return getTagStr() + ": " + getID();
286}
287
288
289std::string
293
294// ===========================================================================
295// private
296// ===========================================================================
297
298void
299GNEVariableSpeedSign::setAttribute(SumoXMLAttr key, const std::string& value) {
300 switch (key) {
301 case SUMO_ATTR_LANES:
302 throw InvalidArgument(getTagStr() + " cannot be edited");
303 case SUMO_ATTR_ID:
304 // update microsimID
305 setAdditionalID(value);
306 break;
307 case SUMO_ATTR_NAME:
308 myAdditionalName = value;
309 break;
310 case SUMO_ATTR_VTYPES:
311 myVehicleTypes = parse<std::vector<std::string> >(value);
312 break;
313 default:
315 break;
316 }
317 // update boundary (except for template)
318 if (getID().size() > 0) {
320 }
321}
322
323
324void
325GNEVariableSpeedSign::rebuildVSSSymbols(const std::string& value, GNEUndoList* undoList) {
326 undoList->begin(this, ("change " + getTagStr() + " attribute").c_str());
327 // drop all additional children
328 while (getChildAdditionals().size() > 0) {
329 undoList->add(new GNEChange_Additional(getChildAdditionals().front(), false), true);
330 }
331 // get lane vector
332 const std::vector<GNELane*> lanes = parse<std::vector<GNELane*> >(myNet, value);
333 // create new VSS Symbols
334 for (const auto& lane : lanes) {
335 // create VSS Symbol
336 GNEAdditional* VSSSymbol = new GNEVariableSpeedSignSymbol(this, lane);
337 // add it using GNEChange_Additional
338 myNet->getViewNet()->getUndoList()->add(new GNEChange_Additional(VSSSymbol, true), true);
339 }
340 undoList->end();
341}
342
343/****************************************************************************/
@ 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
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 (more quickly as checking GUIGlObjectStorage)
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
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
Parameterised * getParameters() override
get parameters associated with this variableSpeedSign
PositionVector getAttributePositionVector(SumoXMLAttr key) const override
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Position getPositionInView() const
Returns position of additional in view.
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
std::string getParentName() const
Returns the name of the parent object.
double getAttributeDouble(SumoXMLAttr key) const override
GNEVariableSpeedSign(GNENet *net)
default Constructor
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
void rebuildVSSSymbols(const std::string &value, GNEUndoList *undoList)
rebuild VSS Symbols
void writeAdditional(OutputDevice &device) const
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
bool checkDrawMoveContour() const override
check if draw move contour (red)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this variableSpeedSign
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
bool isValid(SumoXMLAttr key, const std::string &value) override
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
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 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)
GNEUndoList * getUndoList() const
get the undoList object
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)
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