Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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>
28
29#include "GNEWalkingArea.h"
30
31// ===========================================================================
32// method definitions
33// ===========================================================================
34
35GNEWalkingArea::GNEWalkingArea(GNEJunction* junction, const std::string& ID) :
36 GNENetworkElement(junction->getNet(), ID, SUMO_TAG_WALKINGAREA),
37 myTesselation(ID, "", RGBColor::GREY, junction->getNBNode()->getWalkingArea(ID).shape, false, true, 0) {
38 // set parent
39 setParent<GNEJunction*>(junction);
40}
41
42
45
46
49 return nullptr;
50}
51
52
55 return nullptr;
56}
57
58
59const Parameterised*
61 return nullptr;
62}
63
64
65void
67 // Nothing to update
68}
69
70
73 return getParentJunctions().front()->getPositionInView();
74}
75
76
77bool
79 return false;
80}
81
82
83bool
85 return false;
86}
87
88
89bool
91 // check opened popup
92 if (myNet->getViewNet()->getPopup()) {
93 return myNet->getViewNet()->getPopup()->getGLObject() == this;
94 }
95 return false;
96}
97
98
99bool
101 return false;
102}
103
104
105bool
107 // get edit modes
108 const auto& editModes = myNet->getViewNet()->getEditModes();
109 // check if we're in delete mode
110 if (editModes.isCurrentSupermodeNetwork() && (editModes.networkEditMode == NetworkEditMode::NETWORK_DELETE)) {
112 } else {
113 return false;
114 }
115}
116
117
118bool
120 return false;
121}
122
123
124bool
126 // get edit modes
127 const auto& editModes = myNet->getViewNet()->getEditModes();
128 // check if we're in select mode
129 if (editModes.isCurrentSupermodeNetwork() && (editModes.networkEditMode == NetworkEditMode::NETWORK_SELECT)) {
131 } else {
132 return false;
133 }
134}
135
136
137bool
139 return false;
140}
141
142
145 return getParentJunctions().front()->getNBNode()->getWalkingArea(getMicrosimID());
146}
147
148
149void
151 // declare variables
152 const double walkingAreaExaggeration = getExaggeration(s);
153 // get walking area shape
154 const auto& walkingAreaShape = getParentJunctions().front()->getNBNode()->getWalkingArea(getID()).shape;
155 // only continue if exaggeration is greater than 0 and junction's shape is greater than 4
156 if ((getParentJunctions().front()->getNBNode()->getShape().area() > 4) &&
157 (walkingAreaShape.size() > 0) && s.drawCrossingsAndWalkingareas) {
158 // don't draw this walking area if we're editing their junction parent
160 if (!editedNetworkElement || (editedNetworkElement != getParentJunctions().front())) {
161 const auto contourMode = drawInContourMode();
162 // get detail level
163 const auto d = s.getDetailLevel(walkingAreaExaggeration);
164 // draw geometry only if we'rent in drawForObjectUnderCursor mode
166 // draw walking area
167 if (!contourMode) {
168 drawWalkingArea(s, d, walkingAreaShape, walkingAreaExaggeration);
169 }
170 // draw walkingArea name
171 if (s.cwaEdgeName.show(this)) {
172 drawName(walkingAreaShape.getCentroid(), s.scale, s.edgeName, 0, true);
173 }
174 // draw dotted contour
175 if (contourMode) {
177 } else {
179 }
180 }
181 // draw dotted contour (except in contour mode) checking if junction parent was inserted with full boundary
182 myNetworkElementContour.calculateContourClosedShape(s, d, this, walkingAreaShape, getType(),
183 walkingAreaExaggeration, getParentJunctions().front(), !contourMode);
184 }
185 }
186}
187
188
189void
191 // currently WalkingAreas cannot be removed
192}
193
194
195void
199
200
203 // create popup
204 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
205 // build common options
207 // check if we're in supermode network
209 // create menu commands
210 FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom WalkingArea shape", nullptr, &parent, MID_GNE_WALKINGAREA_EDIT_SHAPE);
211 // check if menu commands has to be disabled
214 mcCustomShape->disable();
215 }
216 // disabled for release 1.15
217 mcCustomShape->disable();
218 }
219 return ret;
220}
221
222
227
228
229void
230GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
231 // nothing to update
232}
233
234
235std::string
237 if (key == SUMO_ATTR_ID) {
238 // for security purposes, avoid get WalkingArea if we want only the ID
239 return getMicrosimID();
240 }
241 const auto& walkingArea = getNBWalkingArea();
242 switch (key) {
243 case SUMO_ATTR_WIDTH:
244 return toString(walkingArea.width);
245 case SUMO_ATTR_LENGTH:
246 return toString(walkingArea.length);
247 case SUMO_ATTR_SHAPE:
248 return toString(walkingArea.shape);
249 default:
250 return getCommonAttribute(key);
251 }
252}
253
254
255double
259
260
265
266
269 switch (key) {
270 case SUMO_ATTR_SHAPE:
271 return getNBWalkingArea().shape;
272 default:
274 }
275}
276
277
278void
279GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
280 if (value == getAttribute(key)) {
281 return; //avoid needless changes, later logic relies on the fact that attributes have changed
282 }
283 switch (key) {
284 case SUMO_ATTR_ID:
285 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
286 case SUMO_ATTR_WIDTH:
287 case SUMO_ATTR_LENGTH:
288 case SUMO_ATTR_SHAPE:
289 GNEChange_Attribute::changeAttribute(this, key, value, undoList, true);
290 break;
291 default:
292 setCommonAttribute(key, value, undoList);
293 break;
294 }
295}
296
297
298bool
300 switch (key) {
302 return true;
303 default:
304 return false;
305 }
306}
307
308
309bool
310GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
311 switch (key) {
312 case SUMO_ATTR_ID:
313 return false;
314 case SUMO_ATTR_WIDTH:
315 case SUMO_ATTR_LENGTH:
316 return canParse<double>(value) && (parse<double>(value) > 0);
317 case SUMO_ATTR_SHAPE:
318 if (canParse<PositionVector>(value)) {
319 return parse<PositionVector>(value).size() > 0;
320 } else {
321 return false;
322 }
323 default:
324 return isCommonAttributeValid(key, value);
325 }
326}
327
328// ===========================================================================
329// private
330// ===========================================================================
331
332void
334 const PositionVector& shape, const double exaggeration) const {
335 // adjust shape to exaggeration
336 if (((exaggeration > 1) || (myExaggeration > 1)) && (exaggeration != myExaggeration)) {
337 myExaggeration = exaggeration;
338 myTesselation.setShape(shape);
342 }
343 // push layer matrix
345 // translate to front
347 // set color
348 if (myShapeEdited) {
350 } else if (isAttributeCarrierSelected()) {
352 } else {
354 }
355 // check if draw walking area tesselated or contour
356 if (drawInContourMode()) {
358 } else {
360 }
361 // pop layer Matrix
363}
364
365
366bool
368 const auto& modes = myNet->getViewNet()->getEditModes();
369 // check modes
370 if (!modes.isCurrentSupermodeNetwork()) {
371 return true;
372 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_MOVE) {
373 return true;
374 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_DELETE) {
375 return true;
376 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_CONNECT) {
377 return true;
378 } else {
379 return false;
380 }
381}
382
383
384void
386 // check if draw polygon or tesselation
388 // draw shape with high detail
390 } else {
391 // draw shape
393 }
394 // draw shape points only in Network supemode
396 // draw geometry points
400 }
401}
402
403
404void
405GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
406 auto& walkingArea = getNBWalkingArea();
407 switch (key) {
408 case SUMO_ATTR_ID:
409 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
410 case SUMO_ATTR_WIDTH:
411 walkingArea.width = parse<double>(value);
412 break;
413 case SUMO_ATTR_LENGTH:
414 walkingArea.length = parse<double>(value);
415 break;
416 case SUMO_ATTR_SHAPE:
417 walkingArea.shape = parse<PositionVector>(value);
418 walkingArea.hasCustomShape = true;
419 break;
420 default:
421 setCommonAttribute(key, value);
422 break;
423 }
424}
425
426/****************************************************************************/
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
double getCommonAttributeDouble(SumoXMLAttr key) const
bool mySelected
boolean to check if this AC is selected (more quickly as checking GUIGlObjectStorage)
PositionVector getCommonAttributePositionVector(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
Position getCommonAttributePosition(SumoXMLAttr key) const
GNENet * myNet
pointer to net
bool isCommonAttributeValid(SumoXMLAttr key, const std::string &value) const
std::string getCommonAttribute(SumoXMLAttr key) 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
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2193
GNEContour myNetworkElementContour
network element contour
bool myShapeEdited
flag to check if element shape is being edited
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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)
GNEMoveElement * getMoveElement() const override
methods to retrieve the elements linked to this walkingArea
~GNEWalkingArea()
Destructor.
bool checkDrawToContour() const override
check if draw from contour (magenta)
GNEWalkingArea(GNEJunction *junction, const std::string &ID)
Constructor.
bool isValid(SumoXMLAttr key, const std::string &value) override
bool checkDrawDeleteContourSmall() const override
check if draw delete contour small (pink/white)
double getAttributeDouble(SumoXMLAttr key) const override
void drawWalkingArea(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const PositionVector &shape, const double exaggeration) const
draw walking area
GNEContour myInnenContour
variable used for draw innen contour
bool checkDrawDeleteContour() const override
check if draw delete contour (pink/white)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
double myExaggeration
exaggeration used in tesselation
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)
Position getAttributePosition(SumoXMLAttr key) const override
NBNode::WalkingArea & getNBWalkingArea() const
get referente to NBode::WalkingArea
void deleteGLObject()
delete element
bool checkDrawRelatedContour() const override
check if draw related contour (cyan)
bool checkDrawSelectContour() const override
check if draw select contour (blue)
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList) override
std::string getAttribute(SumoXMLAttr key) const override
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
bool checkDrawOverContour() const override
check if draw over contour (orange)
bool drawInContourMode() const
check if draw walking area in contour mode
void updateGeometry() override
update pre-computed geometry information
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
bool checkDrawFromContour() const override
check if draw from contour (green)
Parameterised * getParameters() override
get parameters associated with this walkingArea
bool isAttributeEnabled(SumoXMLAttr key) const
bool checkDrawMoveContour() const override
check if draw move contour (red)
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 crossings and walkingareas shall be drawn
GUIColorer junctionColorer
The junction colorer.
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
An upper class for objects with additional parameters.
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