Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEWalkingArea.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// A class for visualizing and editing WalkingAreas
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
32
33#include "GNEWalkingArea.h"
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38
39GNEWalkingArea::GNEWalkingArea(GNEJunction* junction, const std::string& ID) :
40 GNENetworkElement(junction->getNet(), ID, SUMO_TAG_WALKINGAREA),
41 myTesselation(ID, "", RGBColor::GREY, junction->getNBNode()->getWalkingArea(ID).shape, false, true, 0) {
42 // set parent
43 setParent<GNEJunction*>(junction);
44}
45
46
49
50
51void
53 // Nothing to update
54}
55
56
59 return getParentJunctions().front()->getPositionInView();
60}
61
62
63bool
65 return false;
66}
67
68
69bool
71 return false;
72}
73
74
75bool
77 // check opened popup
78 if (myNet->getViewNet()->getPopup()) {
79 return myNet->getViewNet()->getPopup()->getGLObject() == this;
80 }
81 return false;
82}
83
84
85bool
87 return false;
88}
89
90
91bool
93 // get edit modes
94 const auto& editModes = myNet->getViewNet()->getEditModes();
95 // check if we're in delete mode
96 if (editModes.isCurrentSupermodeNetwork() && (editModes.networkEditMode == NetworkEditMode::NETWORK_DELETE)) {
98 } else {
99 return false;
100 }
101}
102
103
104bool
106 return false;
107}
108
109
110bool
112 // get edit modes
113 const auto& editModes = myNet->getViewNet()->getEditModes();
114 // check if we're in select mode
115 if (editModes.isCurrentSupermodeNetwork() && (editModes.networkEditMode == NetworkEditMode::NETWORK_SELECT)) {
117 } else {
118 return false;
119 }
120}
121
122
123bool
125 return false;
126}
127
128
131 // edit depending if shape is being edited
132 if (isShapeEdited()) {
133 // calculate move shape operation
134 return calculateMoveShapeOperation(this, getNBWalkingArea().shape, false);
135 } else {
136 return nullptr;
137 }
138}
139
140
141void
142GNEWalkingArea::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
143 // nothing to do
144}
145
146
149 return getParentJunctions().front()->getNBNode()->getWalkingArea(getMicrosimID());
150}
151
152
153void
155 // declare variables
156 const double walkingAreaExaggeration = getExaggeration(s);
157 // get walking area shape
158 const auto& walkingAreaShape = getParentJunctions().front()->getNBNode()->getWalkingArea(getID()).shape;
159 // only continue if exaggeration is greater than 0 and junction's shape is greater than 4
160 if ((getParentJunctions().front()->getNBNode()->getShape().area() > 4) &&
161 (walkingAreaShape.size() > 0) && s.drawCrossingsAndWalkingareas) {
162 // don't draw this walking area if we're editing their junction parent
164 if (!editedNetworkElement || (editedNetworkElement != getParentJunctions().front())) {
165 const auto contourMode = drawInContourMode();
166 // get detail level
167 const auto d = s.getDetailLevel(walkingAreaExaggeration);
168 // draw geometry only if we'rent in drawForObjectUnderCursor mode
170 // draw walking area
171 if (!contourMode) {
172 drawWalkingArea(s, d, walkingAreaShape, walkingAreaExaggeration);
173 }
174 // draw walkingArea name
175 if (s.cwaEdgeName.show(this)) {
176 drawName(walkingAreaShape.getCentroid(), s.scale, s.edgeName, 0, true);
177 }
178 // draw dotted contour
179 if (contourMode) {
181 } else {
183 }
184 }
185 // draw dotted contour (except in contour mode) checking if junction parent was inserted with full boundary
186 myNetworkElementContour.calculateContourClosedShape(s, d, this, walkingAreaShape, getType(),
187 walkingAreaExaggeration, getParentJunctions().front(), !contourMode);
188 }
189 }
190}
191
192
193void
195 // currently WalkingAreas cannot be removed
196}
197
198
199void
203
204
207 // create popup
208 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
209 // build common options
211 // check if we're in supermode network
213 // create menu commands
214 FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom WalkingArea shape", nullptr, &parent, MID_GNE_WALKINGAREA_EDIT_SHAPE);
215 // check if menu commands has to be disabled
218 mcCustomShape->disable();
219 }
220 // disabled for release 1.15
221 mcCustomShape->disable();
222 }
223 return ret;
224}
225
226
231
232
233void
234GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
235 // nothing to update
236}
237
238
239std::string
241 if (key == SUMO_ATTR_ID) {
242 // for security purposes, avoid get WalkingArea if we want only the ID
243 return getMicrosimID();
244 }
245 const auto& walkingArea = getNBWalkingArea();
246 switch (key) {
247 case SUMO_ATTR_WIDTH:
248 return toString(walkingArea.width);
249 case SUMO_ATTR_LENGTH:
250 return toString(walkingArea.length);
251 case SUMO_ATTR_SHAPE:
252 return toString(walkingArea.shape);
253 default:
254 return getCommonAttribute(nullptr, key);
255 }
256}
257
258
261 switch (key) {
262 case SUMO_ATTR_SHAPE:
263 return getNBWalkingArea().shape;
264 default:
265 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
266 }
267}
268
269
270void
271GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
272 if (value == getAttribute(key)) {
273 return; //avoid needless changes, later logic relies on the fact that attributes have changed
274 }
275 switch (key) {
276 case SUMO_ATTR_ID:
277 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
278 case SUMO_ATTR_WIDTH:
279 case SUMO_ATTR_LENGTH:
280 case SUMO_ATTR_SHAPE:
281 GNEChange_Attribute::changeAttribute(this, key, value, undoList, true);
282 break;
283 default:
284 setCommonAttribute(key, value, undoList);
285 break;
286 }
287}
288
289
290bool
292 switch (key) {
294 return true;
295 default:
296 return false;
297 }
298}
299
300
301bool
302GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
303 switch (key) {
304 case SUMO_ATTR_ID:
305 return false;
306 case SUMO_ATTR_WIDTH:
307 case SUMO_ATTR_LENGTH:
308 return canParse<double>(value) && (parse<double>(value) > 0);
309 case SUMO_ATTR_SHAPE:
310 if (canParse<PositionVector>(value)) {
311 return parse<PositionVector>(value).size() > 0;
312 } else {
313 return false;
314 }
315 default:
316 return isCommonValid(key, value);
317 }
318}
319
320
325
326// ===========================================================================
327// private
328// ===========================================================================
329
330void
332 const PositionVector& shape, const double exaggeration) const {
333 // adjust shape to exaggeration
334 if (((exaggeration > 1) || (myExaggeration > 1)) && (exaggeration != myExaggeration)) {
335 myExaggeration = exaggeration;
336 myTesselation.setShape(shape);
340 }
341 // push layer matrix
343 // translate to front
345 // set color
346 if (myShapeEdited) {
348 } else if (isAttributeCarrierSelected()) {
350 } else {
352 }
353 // check if draw walking area tesselated or contour
354 if (drawInContourMode()) {
356 } else {
358 }
359 // pop layer Matrix
361}
362
363
364bool
366 const auto& modes = myNet->getViewNet()->getEditModes();
367 // check modes
368 if (!modes.isCurrentSupermodeNetwork()) {
369 return true;
370 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_MOVE) {
371 return true;
372 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_DELETE) {
373 return true;
374 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_CONNECT) {
375 return true;
376 } else {
377 return false;
378 }
379}
380
381
382void
384 // check if draw polygon or tesselation
386 // draw shape with high detail
388 } else {
389 // draw shape
391 }
392 // draw shape points only in Network supemode
394 // draw geometry points
398 }
399}
400
401
402void
403GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
404 auto& walkingArea = getNBWalkingArea();
405 switch (key) {
406 case SUMO_ATTR_ID:
407 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
408 case SUMO_ATTR_WIDTH:
409 walkingArea.width = parse<double>(value);
410 break;
411 case SUMO_ATTR_LENGTH:
412 walkingArea.length = parse<double>(value);
413 break;
414 case SUMO_ATTR_SHAPE:
415 walkingArea.shape = parse<PositionVector>(value);
416 walkingArea.hasCustomShape = true;
417 break;
418 default:
419 setCommonAttribute(nullptr, key, value);
420 break;
421 }
422}
423
424
425void
427 // set custom shape
428 getNBWalkingArea().shape = moveResult.shapeToUpdate;
429}
430
431
432void
434 // commit new shape
435 undoList->begin(this, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
437 undoList->end();
438}
439
440/****************************************************************************/
NetworkEditMode
@brie enum for network edit modes
@ NETWORK_DELETE
mode for deleting network elements
@ NETWORK_MOVE
mode for moving network elements
@ NETWORK_CREATE_EDGE
mode for creating new edges
@ NETWORK_TLS
mode for editing tls
@ NETWORK_SELECT
mode for selecting network elements
@ NETWORK_CONNECT
mode for connecting lanes
@ MID_GNE_WALKINGAREA_EDIT_SHAPE
edit crossing shape
@ GLO_WALKINGAREA
a walkingArea
@ SUMO_TAG_WALKINGAREA
walking area for pedestrians
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_SHAPE
edge: the shape in xml-definition
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_WIDTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
A class that stores a 2D geometrical boundary.
Definition Boundary.h:39
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition GLHelper.cpp:204
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:649
static void popMatrix()
pop matrix
Definition GLHelper.cpp:131
static RGBColor getColor()
gets the gl-color
Definition GLHelper.cpp:655
static void pushMatrix()
push matrix
Definition GLHelper.cpp:118
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)
std::string getCommonAttribute(const Parameterised *parameterised, SumoXMLAttr key) const
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
GNENet * myNet
pointer to net
bool isCommonValid(SumoXMLAttr key, const std::string &value) const
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
bool drawDottedContour(const GUIVisualizationSettings &s, GUIDottedGeometry::DottedContourType type, const double lineWidth, const bool addOffset) const
draw dotted contour (call out of this class only in special cases, for example in WalkingAreas)
void calculateContourClosedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double scale, const GUIGlObject *boundaryParent, const bool addToSelectedObjects=true) const
calculate contours
void drawInnenContourClosed(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const PositionVector &shape, const double scale, const double lineWidth) const
draw innen contour (currently used only in walkingAreas)
Boundary getContourBoundary() const
get contour boundary
bool drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
draw dotted contours (basics, select, delete, inspect...)
const GNEHierarchicalContainerParents< GNEJunction * > & getParentJunctions() const
get parent junctions
GNEMoveOperation * calculateMoveShapeOperation(const GUIGlObject *obj, const PositionVector originalShape, const bool maintainShapeClosed)
calculate move shape operation
move operation
move result
PositionVector shapeToUpdate
shape to update (edited in moveElement)
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2194
GNEContour myNetworkElementContour
network element contour
bool myShapeEdited
flag to check if element shape is being edited
bool isShapeEdited() const
check if shape is being edited
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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...
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
const GNEViewNetHelper::EditNetworkElementShapes & getEditNetworkElementShapes() const
get Edit Shape module
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)
~GNEWalkingArea()
Destructor.
GNEWalkingArea(GNEJunction *junction, const std::string &ID)
Constructor.
bool checkDrawMoveContour() const
check if draw move contour (red)
GNEMoveOperation * getMoveOperation()
get move operation
std::string getAttribute(SumoXMLAttr key) const
void drawWalkingArea(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const PositionVector &shape, const double exaggeration) const
draw walking area
bool checkDrawToContour() const
check if draw from contour (magenta)
GNEContour myInnenContour
variable used for draw innen contour
bool checkDrawOverContour() const
check if draw over contour (orange)
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
bool checkDrawRelatedContour() const
check if draw related contour (cyan)
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
bool checkDrawSelectContour() const
check if draw select contour (blue)
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double myExaggeration
exaggeration used in tesselation
bool checkDrawFromContour() const
check if draw from contour (green)
Position getPositionInView() const
Returns position of hierarchical element in view.
PositionVector getAttributePositionVector(SumoXMLAttr key) const
void updateCenteringBoundary(const bool updateGrid)
update centering boundary (implies change in RTREE)
NBNode::WalkingArea & getNBWalkingArea() const
get referente to NBode::WalkingArea
bool checkDrawDeleteContourSmall() const
check if draw delete contour small (pink/white)
void deleteGLObject()
delete element
bool isValid(SumoXMLAttr key, const std::string &value)
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
bool checkDrawDeleteContour() const
check if draw delete contour (pink/white)
bool drawInContourMode() const
check if draw walking area in contour mode
TesselatedPolygon myTesselation
An object that stores the shape and its tesselation.
void updateGLObject()
update GLObject (geometry, ID, etc.)
void drawTesselatedWalkingArea(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d) const
draw tesselated walking area
void updateGeometry()
update pre-computed geometry information
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
bool isAttributeEnabled(SumoXMLAttr key) const
const Parameterised::Map & getACParametersMap() const
get parameters map
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel, const bool disable=false)
build menu command
The popup menu of a globject.
GUIGlObject * getGLObject() const
The object that belongs to this popup-menu.
static void drawGeometryPoints(const GUIVisualizationSettings::Detail d, const PositionVector &shape, const RGBColor &color, const double radius, const double exaggeration, const bool editingElevation)
draw geometry points
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
virtual double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
void buildPopUpMenuCommonOptions(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, GUISUMOAbstractView *parent, const SumoXMLTag tag, const bool selected, bool addSeparator=true)
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
T getColor(const double value) const
GUIGLObjectPopupMenu * getPopup() const
ge the current popup-menu
Stores the information about how to visualize structures.
Detail getDetailLevel(const double exaggeration) const
return the detail level
GUIVisualizationTextSettings cwaEdgeName
bool drawMovingGeometryPoint(const double exaggeration, const double radius) const
check if moving geometry point can be draw
GUIVisualizationColorSettings colorSettings
color settings
GUIVisualizationDottedContourSettings dottedContourSettings
dotted contour settings
double scale
information about a lane's width (temporary, used for a single view)
bool drawForViewObjectsHandler
whether drawing is performed for the purpose of selecting objects in view using ViewObjectsHandler
GUIVisualizationTextSettings edgeName
Setting bundles for optional drawing names with size and color.
bool drawCrossingsAndWalkingareas
whether crosings and walkingareas shall be drawn
GUIColorer junctionColorer
The junction colorer.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
std::map< std::string, std::string > Map
parameters map
const Parameterised::Map & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
void closePolygon()
ensures that the last position equals the first
void scaleRelative(double factor)
enlarges/shrinks the polygon by a factor based at the centroid
static const RGBColor BLUE
Definition RGBColor.h:190
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition RGBColor.cpp:200
const PositionVector & getShape() const
Returns the shape of the polygon.
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
PositionVector & getShapeRef()
Return the exterior shape of the polygon.
std::vector< GLPrimitive > myTesselation
id of the display list for the cached tesselation
Definition GUIPolygon.h:72
void drawTesselation(const PositionVector &shape) const
perform the tesselation / drawing
NetworkEditMode networkEditMode
the current Network edit mode
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
GNENetworkElement * getEditedNetworkElement() const
pointer to edited network element
bool editingElevation() const
check if we're editing elevation
static const RGBColor editShapeColor
color for edited shapes (Junctions, crossings and connections)
static const double segmentWidth
width of dotted contour segments
static const double crossingGeometryPointRadius
moving crossing geometry point radius
static const double junctionGeometryPointRadius
moving junction geometry point radius
bool show(const GUIGlObject *o) const
whether to show the text
A definition of a pedestrian walking area.
Definition NBNode.h:177
PositionVector shape
The polygonal shape.
Definition NBNode.h:190