Eclipse SUMO - Simulation of Urban MObility
GNEWalkingArea.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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
51}
52
53
54void
56 // Nothing to update
57}
58
59
63}
64
65
68 // edit depending if shape is being edited
69 if (isShapeEdited()) {
70 // calculate move shape operation
73 } else {
74 return nullptr;
75 }
76}
77
78
79void
80GNEWalkingArea::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
81 // nothing to do
82}
83
84
87 return myParentJunction;
88}
89
90
94}
95
96
97void
99 // check if boundary has to be drawn
100 if (s.drawBoundaries) {
102 }
103 // declare variables
104 const Position mousePosition = myNet->getViewNet()->getPositionInformation();
105 const double walkingAreaExaggeration = getExaggeration(s);
106 // get walking area shape
107 const auto& walkingAreaShape = myParentJunction->getNBNode()->getWalkingArea(getID()).shape;
108 // only continue if exaggeration is greather than 0 and junction's shape is greather than 4
109 if ((myParentJunction->getNBNode()->getShape().area() > 4) && (walkingAreaShape.size() > 0) && s.drawCrossingsAndWalkingareas) {
110 // push junction name
112 // push layer matrix
114 // translate to front
116 // set shape color
118 // recognize full transparency and simply don't draw
119 if (walkingAreaColor.alpha() != 0) {
120 // set color
121 GLHelper::setColor(walkingAreaColor);
122 // adjust shape to exaggeration
123 if (((walkingAreaExaggeration > 1) || (myExaggeration > 1)) && (walkingAreaExaggeration != myExaggeration)) {
124 myExaggeration = walkingAreaExaggeration;
125 myTesselation.setShape(walkingAreaShape);
127 myTesselation.getShapeRef().scaleRelative(walkingAreaExaggeration);
129 }
130 // first check if inner junction polygon can be drawn
132 // only draw a point if mouse is around shape
133 if (myTesselation.getShape().around(mousePosition)) {
134 // push matrix
136 // move to mouse position
137 glTranslated(mousePosition.x(), mousePosition.y(), 0.1);
138 // draw a simple circle
140 // pop matrix
142 }
143 } else if ((s.scale * walkingAreaExaggeration * myParentJunction->getMaxDrawingSize()) >= 40) {
144 // draw shape with high detail
146 } else {
147 // draw shape
149 }
150 }
151 // draw shape points only in Network supemode
153 // color
154 const RGBColor darkerColor = walkingAreaColor.changedBrightness(-32);
155 // draw geometry points
159 // draw moving hint
163 }
164 }
165 // pop layer Matrix
167 // pop junction name
169 // draw walkingArea name
170 if (s.cwaEdgeName.show(this)) {
171 drawName(walkingAreaShape.getCentroid(), s.scale, s.edgeName, 0, true);
172 }
173 // check if mouse is over element
174 mouseWithinGeometry(walkingAreaShape);
175 // inspect contour
178 (walkingAreaExaggeration >= 1) ? walkingAreaExaggeration : 1);
179 }
180 // front element contour
181 if ((myNet->getViewNet()->getFrontAttributeCarrier() == this)) {
183 (walkingAreaExaggeration >= 1) ? walkingAreaExaggeration : 1);
184 }
185 // delete contour
186 if (myNet->getViewNet()->drawDeleteContour(this, this)) {
188 (walkingAreaExaggeration >= 1) ? walkingAreaExaggeration : 1);
189 }
190 // select contour
191 if (myNet->getViewNet()->drawSelectContour(this, this)) {
193 (walkingAreaExaggeration >= 1) ? walkingAreaExaggeration : 1);
194 }
195 }
196}
197
198
199void
201 // currently WalkingAreas cannot be removed
202}
203
204
205void
208}
209
210
213 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
214 buildPopupHeader(ret, app);
217 // build selection and show parameters menu
220 // build position copy entry
221 buildPositionCopyEntry(ret, app);
222 // check if we're in supermode network
224 // create menu commands
225 FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom WalkingArea shape", nullptr, &parent, MID_GNE_WALKINGAREA_EDIT_SHAPE);
226 // check if menu commands has to be disabled
229 mcCustomShape->disable();
230 }
231 // disabled for release 1.15
232 mcCustomShape->disable();
233 }
234 return ret;
235}
236
237
238double
240 return 1;
241}
242
243
244void
245GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
246 // in other case use boundary of parent junction
248 if (shape.size() == 0) {
250 } else {
251 myBoundary = shape.getBoxBoundary();
252 myBoundary.grow(10);
253 }
254}
255
256
257std::string
259 if (key == SUMO_ATTR_ID) {
260 // for security purposes, avoid get WalkingArea if we want only the ID
261 return getMicrosimID();
262 }
263 const auto& walkingArea = getNBWalkingArea();
264 switch (key) {
265 case SUMO_ATTR_WIDTH:
266 return toString(walkingArea.width);
267 case SUMO_ATTR_LENGTH:
268 return toString(walkingArea.length);
269 case SUMO_ATTR_SHAPE:
270 return toString(walkingArea.shape);
273 default:
274 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
275 }
276}
277
278
279void
280GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
281 if (value == getAttribute(key)) {
282 return; //avoid needless changes, later logic relies on the fact that attributes have changed
283 }
284 switch (key) {
285 case SUMO_ATTR_ID:
286 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
287 case SUMO_ATTR_WIDTH:
288 case SUMO_ATTR_LENGTH:
289 case SUMO_ATTR_SHAPE:
291 undoList->add(new GNEChange_Attribute(this, key, value), true);
292 break;
293 default:
294 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
295 }
296}
297
298
299bool
301 switch (key) {
303 return true;
304 default:
305 return false;
306 }
307}
308
309
310bool
311GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
312 switch (key) {
313 case SUMO_ATTR_ID:
314 return false;
315 case SUMO_ATTR_WIDTH:
316 case SUMO_ATTR_LENGTH:
317 return canParse<double>(value) && (parse<double>(value) > 0);
318 case SUMO_ATTR_SHAPE:
319 if (canParse<PositionVector>(value)) {
320 return parse<PositionVector>(value).size() > 0;
321 } else {
322 return false;
323 }
325 return canParse<bool>(value);
326 default:
327 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
328 }
329}
330
331
335}
336
337// ===========================================================================
338// private
339// ===========================================================================
340
341void
342GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
343 auto& walkingArea = getNBWalkingArea();
344 switch (key) {
345 case SUMO_ATTR_ID:
346 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
347 case SUMO_ATTR_WIDTH:
348 walkingArea.width = parse<double>(value);
349 break;
350 case SUMO_ATTR_LENGTH:
351 walkingArea.length = parse<double>(value);
352 break;
353 case SUMO_ATTR_SHAPE:
354 walkingArea.shape = parse<PositionVector>(value);
355 walkingArea.hasCustomShape = true;
356 break;
358 if (parse<bool>(value)) {
360 } else {
362 }
363 break;
364 default:
365 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
366 }
367}
368
369
370void
372 // set custom shape
373 getNBWalkingArea().shape = moveResult.shapeToUpdate;
374 // update geometry
376}
377
378
379void
381 // commit new shape
382 undoList->begin(GUIIcon::WALKINGAREA, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
384 undoList->end();
385}
386
387/****************************************************************************/
NetworkEditMode
@brie enum for network edit modes
@ NETWORK_MOVE
mode for moving network elements
@ NETWORK_CREATE_EDGE
mode for creating new edges
@ NETWORK_TLS
mode for editing tls
@ NETWORK_CONNECT
mode for connecting lanes
@ MID_GNE_WALKINGAREA_EDIT_SHAPE
edit crossing shape
Definition: GUIAppEnum.h:1207
@ 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
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:300
static void drawFilledPoly(const PositionVector &v, bool close)
Draws a filled polygon described by the list of points.
Definition: GLHelper.cpp:203
static void drawBoundary(const Boundary &b)
Draw a boundary (used for debugging)
Definition: GLHelper.cpp:894
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:583
static void drawFilledCircle(double width, int steps=8)
Draws a filled circle around (0,0)
Definition: GLHelper.cpp:498
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:139
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static void popName()
pop Name
Definition: GLHelper.cpp:148
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
friend class GNEChange_Attribute
declare friend class
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
double getMaxDrawingSize() const
get the maximum size (in either x-, or y-dimension) for determining whether to draw or not
Position getPositionInView() const
Returns position of hierarchical element in view.
NBNode * getNBNode() const
Return net build node.
GNEMoveOperation * calculateMoveShapeOperation(const PositionVector originalShape, const Position mousePosition, const double snapRadius, const bool onlyContour)
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:1987
bool myShapeEdited
flag to check if element shape is being edited
bool isShapeEdited() const
check if shape is being edited
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Boundary myBoundary
object boundary
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 changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:632
bool drawSelectContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw select contour
bool drawDeleteContour(const GUIGlObject *GLObject, const GNEAttributeCarrier *AC) const
check if draw delete contour
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:644
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:474
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
~GNEWalkingArea()
Destructor.
GNEMoveOperation * getMoveOperation()
get move operation
std::string getAttribute(SumoXMLAttr key) const
void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)
remove geometry point in the clicked position
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
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.
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.
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
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 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)
build menu command
Definition: GUIDesigns.cpp:42
static void drawDottedContourClosedShape(const GUIVisualizationSettings &s, const DottedContourType type, const PositionVector &shape, const double exaggeration, const double customWidth=1)
draw dotted contour for the given closed shape (used by Juctions, shapes and TAZs)
The popup menu of a globject.
static void drawGeometryPoints(const GUIVisualizationSettings &s, const Position &mousePos, const PositionVector &shape, const RGBColor &geometryPointColor, const RGBColor &textColor, const double radius, const double exaggeration, const bool editingElevation, const bool drawExtremeSymbols)
draw geometry points
static void drawMovingHint(const GUIVisualizationSettings &s, const Position &mousePos, const PositionVector &shape, const RGBColor &hintColor, const double radius, const double exaggeration)
draw moving hint
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:141
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 mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
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.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, const GUIMainWindow &app) const
Builds an entry which allows to copy the cursor position if geo projection is used,...
GUIGlID getGlID() const
Returns the numerical id of the object.
Definition: GUIGlObject.h:102
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
const T getColor(const double value) const
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
bool drawBoundaries
enable or disable draw boundaries
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
GUIVisualizationTextSettings cwaEdgeName
bool drawMovingGeometryPoint(const double exaggeration, const double radius) const
check if moving geometry point can be draw
GUIVisualizationColorSettings colorSettings
color settings
double scale
information about a lane's width (temporary, used for a single view)
GUIVisualizationTextSettings edgeName
int getCircleResolution() const
function to calculate circle resolution for all circles drawn in drawGL(...) functions
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:2447
WalkingArea & getWalkingArea(const std::string &id)
return the walkingArea with the given ID
Definition: NBNode.cpp:3577
std::map< std::string, std::string > Map
parameters map
Definition: Parameterised.h:45
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
A list of positions.
void closePolygon()
ensures that the last position equals the first
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
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)
bool around(const Position &p, double offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point.
static const RGBColor BLUE
Definition: RGBColor.h:187
unsigned char alpha() const
Returns the alpha-amount of the color.
Definition: RGBColor.cpp:92
static const RGBColor GREY
Definition: RGBColor.h:194
static const RGBColor BLACK
Definition: RGBColor.h:193
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
Definition: RGBColor.cpp:200
const PositionVector & getShape() const
Returns whether the shape of the polygon.
Definition: SUMOPolygon.cpp:52
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
Definition: SUMOPolygon.cpp:82
std::vector< GLPrimitive > myTesselation
id of the display list for the cached tesselation
Definition: GUIPolygon.h:74
PositionVector & getShapeRef()
Definition: GUIPolygon.h:76
void drawTesselation(const PositionVector &shape) const
Definition: GUIPolygon.cpp:118
NetworkEditMode networkEditMode
the current Network edit mode
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
bool editingElevation() const
check if we're editing elevation
static const RGBColor editShapeColor
color for edited shapes (Junctions, crossings and connections)
static const double crossingGeometryPointRadius
moving crossing geometry point radius
bool show(const GUIGlObject *o) const
whether to show the text
A definition of a pedestrian walking area.
Definition: NBNode.h:169
PositionVector shape
The polygonal shape.
Definition: NBNode.h:182