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 const auto contourMode = drawInContourMode();
165 // get detail level
166 const auto d = s.getDetailLevel(walkingAreaExaggeration);
167 // draw geometry only if we'rent in drawForObjectUnderCursor mode
169 // draw walking area
170 if (!contourMode) {
171 drawWalkingArea(s, d, walkingAreaShape, walkingAreaExaggeration);
172 }
173 // draw walkingArea name
174 if (s.cwaEdgeName.show(this)) {
175 drawName(walkingAreaShape.getCentroid(), s.scale, s.edgeName, 0, true);
176 }
177 // draw dotted contour
178 if (contourMode) {
180 } else {
182 }
183 }
184 // draw dotted contour (except in contour mode) checking if junction parent was inserted with full boundary
185 myNetworkElementContour.calculateContourClosedShape(s, d, this, walkingAreaShape, getType(),
186 walkingAreaExaggeration, myParentJunction, !contourMode);
187 }
188 }
189}
190
191
192void
194 // currently WalkingAreas cannot be removed
195}
196
197
198void
202
203
206 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
207 buildPopupHeader(ret, app);
210 // build selection and show parameters menu
213 // build position copy entry
214 buildPositionCopyEntry(ret, app);
215 // check if we're in supermode network
217 // create menu commands
218 FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom WalkingArea shape", nullptr, &parent, MID_GNE_WALKINGAREA_EDIT_SHAPE);
219 // check if menu commands has to be disabled
222 mcCustomShape->disable();
223 }
224 // disabled for release 1.15
225 mcCustomShape->disable();
226 }
227 return ret;
228}
229
230
235
236
237void
238GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
239 // nothing to update
240}
241
242
243std::string
245 if (key == SUMO_ATTR_ID) {
246 // for security purposes, avoid get WalkingArea if we want only the ID
247 return getMicrosimID();
248 }
249 const auto& walkingArea = getNBWalkingArea();
250 switch (key) {
251 case SUMO_ATTR_WIDTH:
252 return toString(walkingArea.width);
253 case SUMO_ATTR_LENGTH:
254 return toString(walkingArea.length);
255 case SUMO_ATTR_SHAPE:
256 return toString(walkingArea.shape);
257 default:
258 return getCommonAttribute(key);
259 }
260}
261
262
265 switch (key) {
266 case SUMO_ATTR_SHAPE:
267 return getNBWalkingArea().shape;
268 default:
269 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
270 }
271}
272
273
274void
275GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
276 if (value == getAttribute(key)) {
277 return; //avoid needless changes, later logic relies on the fact that attributes have changed
278 }
279 switch (key) {
280 case SUMO_ATTR_ID:
281 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
282 case SUMO_ATTR_WIDTH:
283 case SUMO_ATTR_LENGTH:
284 case SUMO_ATTR_SHAPE:
285 GNEChange_Attribute::changeAttribute(this, key, value, undoList, true);
286 break;
287 default:
288 setCommonAttribute(key, value, undoList);
289 break;
290 }
291}
292
293
294bool
296 switch (key) {
298 return true;
299 default:
300 return false;
301 }
302}
303
304
305bool
306GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
307 switch (key) {
308 case SUMO_ATTR_ID:
309 return false;
310 case SUMO_ATTR_WIDTH:
311 case SUMO_ATTR_LENGTH:
312 return canParse<double>(value) && (parse<double>(value) > 0);
313 case SUMO_ATTR_SHAPE:
314 if (canParse<PositionVector>(value)) {
315 return parse<PositionVector>(value).size() > 0;
316 } else {
317 return false;
318 }
319 default:
320 return isCommonValid(key, value);
321 }
322}
323
324
329
330// ===========================================================================
331// private
332// ===========================================================================
333
334void
336 const PositionVector& shape, const double exaggeration) const {
337 // adjust shape to exaggeration
338 if (((exaggeration > 1) || (myExaggeration > 1)) && (exaggeration != myExaggeration)) {
339 myExaggeration = exaggeration;
340 myTesselation.setShape(shape);
344 }
345 // push layer matrix
347 // translate to front
349 // set color
350 if (myShapeEdited) {
352 } else if (isAttributeCarrierSelected()) {
354 } else {
356 }
357 // check if draw walking area tesselated or contour
358 if (drawInContourMode()) {
360 } else {
362 }
363 // pop layer Matrix
365}
366
367
368bool
370 const auto& modes = myNet->getViewNet()->getEditModes();
371 // check modes
372 if (!modes.isCurrentSupermodeNetwork()) {
373 return true;
374 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_MOVE) {
375 return true;
376 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_DELETE) {
377 return true;
378 } else if (modes.networkEditMode == NetworkEditMode::NETWORK_CONNECT) {
379 return true;
380 } else {
381 return false;
382 }
383}
384
385
386void
388 // check if draw polygon or tesselation
390 // draw shape with high detail
392 } else {
393 // draw shape
395 }
396 // draw shape points only in Network supemode
398 // draw geometry points
402 }
403}
404
405
406void
407GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
408 auto& walkingArea = getNBWalkingArea();
409 switch (key) {
410 case SUMO_ATTR_ID:
411 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
412 case SUMO_ATTR_WIDTH:
413 walkingArea.width = parse<double>(value);
414 break;
415 case SUMO_ATTR_LENGTH:
416 walkingArea.length = parse<double>(value);
417 break;
418 case SUMO_ATTR_SHAPE:
419 walkingArea.shape = parse<PositionVector>(value);
420 walkingArea.hasCustomShape = true;
421 break;
422 default:
423 setCommonAttribute(key, value);
424 break;
425 }
426}
427
428
429void
431 // set custom shape
432 getNBWalkingArea().shape = moveResult.shapeToUpdate;
433 // update geometry
435}
436
437
438void
440 // commit new shape
441 undoList->begin(this, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
443 undoList->end();
444}
445
446/****************************************************************************/
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
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: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)
void setCommonAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
const std::string & getTagStr() const
get tag assigned to this object in string format
bool isCommonValid(SumoXMLAttr key, const std::string &value)
void drawInLayer(const double typeOrLayer, const double extraOffset=0) const
draw element in the given layer, or in front if corresponding flag is enabled
static const Parameterised::Map PARAMETERS_EMPTY
empty parameter maps (used by ACs without parameters)
GNENet * myNet
pointer to net
std::string getCommonAttribute(SumoXMLAttr key) const
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...)
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:2163
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
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
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:2667
WalkingArea & getWalkingArea(const std::string &id)
return the walkingArea with the given ID
Definition NBNode.cpp:3948
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