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-2024 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#include <config.h>
21
22#include <netedit/GNENet.h>
23#include <netedit/GNEUndoList.h>
24#include <netedit/GNEViewNet.h>
32
33#include "GNEWalkingArea.h"
34
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39
40GNEWalkingArea::GNEWalkingArea(GNEJunction* parentJunction, const std::string& ID) :
41 GNENetworkElement(parentJunction->getNet(), ID, GLO_WALKINGAREA, SUMO_TAG_WALKINGAREA,
42 GUIIconSubSys::getIcon(GUIIcon::WALKINGAREA), {}, {}, {}, {}, {}, {}),
43 myParentJunction(parentJunction),
44myTesselation(ID, "", RGBColor::GREY, parentJunction->getNBNode()->getWalkingArea(ID).shape, false, true, 0) {
45 // update centering boundary without updating grid
46 updateCenteringBoundary(false);
47}
48
49
52
53
54void
56 // Nothing to update
57}
58
59
64
65
66bool
68 return false;
69}
70
71
72bool
74 return false;
75}
76
77
78bool
80 return false;
81}
82
83
84bool
86 return false;
87}
88
89
90bool
92 // get edit modes
93 const auto& editModes = myNet->getViewNet()->getEditModes();
94 // check if we're in delete mode
95 if (editModes.isCurrentSupermodeNetwork() && (editModes.networkEditMode == NetworkEditMode::NETWORK_DELETE)) {
97 } else {
98 return false;
99 }
100}
101
102
103bool
105 // get edit modes
106 const auto& editModes = myNet->getViewNet()->getEditModes();
107 // check if we're in select mode
108 if (editModes.isCurrentSupermodeNetwork() && (editModes.networkEditMode == NetworkEditMode::NETWORK_SELECT)) {
110 } else {
111 return false;
112 }
113}
114
115
116bool
118 return false;
119}
120
121
124 // edit depending if shape is being edited
125 if (isShapeEdited()) {
126 // calculate move shape operation
127 return calculateMoveShapeOperation(this, getNBWalkingArea().shape, false);
128 } else {
129 return nullptr;
130 }
131}
132
133
134void
135GNEWalkingArea::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
136 // nothing to do
137}
138
139
144
145
150
151
152void
154 // declare variables
155 const double walkingAreaExaggeration = getExaggeration(s);
156 // get walking area shape
157 const auto& walkingAreaShape = myParentJunction->getNBNode()->getWalkingArea(getID()).shape;
158 // only continue if exaggeration is greater than 0 and junction's shape is greater than 4
159 if ((myParentJunction->getNBNode()->getShape().area() > 4) &&
160 (walkingAreaShape.size() > 0) && s.drawCrossingsAndWalkingareas) {
161 // don't draw this walking area if we're editing their junction parent
163 if (!editedNetworkElement || (editedNetworkElement != myParentJunction)) {
164 // get detail level
165 const auto d = s.getDetailLevel(walkingAreaExaggeration);
166 // draw geometry only if we'rent in drawForObjectUnderCursor mode
168 // draw walking area
169 drawWalkingArea(s, d, walkingAreaShape, walkingAreaExaggeration);
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
176 }
177 // draw dotted contour (except in contour mode) checking if junction parent was inserted with full boundary
179 myNetworkElementContour.calculateContourClosedShape(s, d, this, walkingAreaShape, getType(), walkingAreaExaggeration);
180 }
181 }
182 }
183}
184
185
186void
188 // currently WalkingAreas cannot be removed
189}
190
191
192void
196
197
200 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
201 buildPopupHeader(ret, app);
204 // build selection and show parameters menu
207 // build position copy entry
208 buildPositionCopyEntry(ret, app);
209 // check if we're in supermode network
211 // create menu commands
212 FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom WalkingArea shape", nullptr, &parent, MID_GNE_WALKINGAREA_EDIT_SHAPE);
213 // check if menu commands has to be disabled
216 mcCustomShape->disable();
217 }
218 // disabled for release 1.15
219 mcCustomShape->disable();
220 }
221 return ret;
222}
223
224
229
230
231void
232GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
233 // nothing to update
234}
235
236
237std::string
239 if (key == SUMO_ATTR_ID) {
240 // for security purposes, avoid get WalkingArea if we want only the ID
241 return getMicrosimID();
242 }
243 const auto& walkingArea = getNBWalkingArea();
244 switch (key) {
245 case SUMO_ATTR_WIDTH:
246 return toString(walkingArea.width);
247 case SUMO_ATTR_LENGTH:
248 return toString(walkingArea.length);
249 case SUMO_ATTR_SHAPE:
250 return toString(walkingArea.shape);
253 default:
254 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
255 }
256}
257
258
261 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
262}
263
264
265void
266GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
267 if (value == getAttribute(key)) {
268 return; //avoid needless changes, later logic relies on the fact that attributes have changed
269 }
270 switch (key) {
271 case SUMO_ATTR_ID:
272 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
273 case SUMO_ATTR_WIDTH:
274 case SUMO_ATTR_LENGTH:
275 case SUMO_ATTR_SHAPE:
277 GNEChange_Attribute::changeAttribute(this, key, value, undoList, true);
278 break;
279 default:
280 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
281 }
282}
283
284
285bool
287 switch (key) {
289 return true;
290 default:
291 return false;
292 }
293}
294
295
296bool
297GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
298 switch (key) {
299 case SUMO_ATTR_ID:
300 return false;
301 case SUMO_ATTR_WIDTH:
302 case SUMO_ATTR_LENGTH:
303 return canParse<double>(value) && (parse<double>(value) > 0);
304 case SUMO_ATTR_SHAPE:
305 if (canParse<PositionVector>(value)) {
306 return parse<PositionVector>(value).size() > 0;
307 } else {
308 return false;
309 }
311 return canParse<bool>(value);
312 default:
313 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
314 }
315}
316
317
322
323// ===========================================================================
324// private
325// ===========================================================================
326
327void
329 const PositionVector& shape, const double exaggeration) const {
330 // adjust shape to exaggeration
331 if (((exaggeration > 1) || (myExaggeration > 1)) && (exaggeration != myExaggeration)) {
332 myExaggeration = exaggeration;
333 myTesselation.setShape(shape);
337 }
338 // push layer matrix
340 // translate to front
342 // set color
343 if (myShapeEdited) {
345 } else if (isAttributeCarrierSelected()) {
347 } else {
349 }
350 // check if draw walking area tesselated or contour
351 if (drawInContourMode()) {
353 } else {
355 }
356 // pop layer Matrix
358}
359
360
361bool
363 const auto& modes = myNet->getViewNet()->getEditModes();
364 // check modes
365 if (!modes.isCurrentSupermodeNetwork()) {
366 return false;
367 } else if (modes.networkEditMode != NetworkEditMode::NETWORK_MOVE) {
368 return false;
369 } else if (modes.networkEditMode != NetworkEditMode::NETWORK_CONNECT) {
370 return false;
371 } else {
372 return true;
373 }
374}
375
376
377void
379 // check if draw polygon or tesselation
381 // draw shape with high detail
383 } else {
384 // draw shape
386 }
387 // draw shape points only in Network supemode
389 // draw geometry points
393 }
394}
395
396
397void
398GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
399 auto& walkingArea = getNBWalkingArea();
400 switch (key) {
401 case SUMO_ATTR_ID:
402 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
403 case SUMO_ATTR_WIDTH:
404 walkingArea.width = parse<double>(value);
405 break;
406 case SUMO_ATTR_LENGTH:
407 walkingArea.length = parse<double>(value);
408 break;
409 case SUMO_ATTR_SHAPE:
410 walkingArea.shape = parse<PositionVector>(value);
411 walkingArea.hasCustomShape = true;
412 break;
414 if (parse<bool>(value)) {
416 } else {
418 }
419 break;
420 default:
421 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
422 }
423}
424
425
426void
428 // set custom shape
429 getNBWalkingArea().shape = moveResult.shapeToUpdate;
430 // update geometry
432}
433
434
435void
437 // commit new shape
438 undoList->begin(this, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
440 undoList->end();
441}
442
443/****************************************************************************/
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
GUIViewObjectsHandler gViewObjectsHandler
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
@ 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:203
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition GLHelper.cpp:654
static void popMatrix()
pop matrix
Definition GLHelper.cpp:130
static RGBColor getColor()
gets the gl-color
Definition GLHelper.cpp:660
static void pushMatrix()
push matrix
Definition GLHelper.cpp:117
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 (instead of GUIGlObjectStorage)
const std::string & getTagStr() const
get tag assigned to this object in string format
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
static void changeAttribute(GNEAttributeCarrier *AC, SumoXMLAttr key, const std::string &value, GNEUndoList *undoList, const bool force=false)
change attribute
void calculateContourClosedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double layer, const double scale) 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)
void 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...)
Boundary getContourBoundary() const
get contour boundary
Position getPositionInView() const
Returns position of hierarchical element in view.
NBNode * getNBNode() const
Return net build node.
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:2147
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
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
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
bool checkOverLockedElement(const GUIGlObject *GLObject, const bool isSelected) const
check if given element is locked (used for drawing select and delete contour)
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
~GNEWalkingArea()
Destructor.
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
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
GNEJunction * myParentJunction
the parent junction of this crossing
TesselatedPolygon myTesselation
An object that stores the shape and its tesselation.
GNEWalkingArea(GNEJunction *parentJunction, const std::string &ID)
Constructor.
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
GNEJunction * getParentJunction() const
get parent Junction
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.
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.
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildNameCopyPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds entries which allow to copy the name / typed name into the clipboard.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
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 buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
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
bool checkBoundaryParentObject(const GUIGlObject *GLObject, const GUIGlObject *parent, const double layer)
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
const PositionVector & getShape() const
retrieve the junction shape
Definition NBNode.cpp:2616
WalkingArea & getWalkingArea(const std::string &id)
return the walkingArea with the given ID
Definition NBNode.cpp:3895
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.
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
double area() const
Returns the area (0 for non-closed)
static const RGBColor BLUE
Definition RGBColor.h:187
static const RGBColor GREY
Definition RGBColor.h:194
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:74
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