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-2023 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
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
89
90
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 // draw shape points only in Network supemode
152 // color
153 const RGBColor darkerColor = walkingAreaColor.changedBrightness(-32);
154 // draw geometry points
158 // draw moving hint
162 }
163 }
164 // pop layer Matrix
166 // pop junction name
168 }
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
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
238void
239GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
240 // in other case use boundary of parent junction
242 if (shape.size() == 0) {
244 } else {
245 myBoundary = shape.getBoxBoundary();
246 myBoundary.grow(10);
247 }
248}
249
250
251std::string
253 if (key == SUMO_ATTR_ID) {
254 // for security purposes, avoid get WalkingArea if we want only the ID
255 return getMicrosimID();
256 }
257 const auto& walkingArea = getNBWalkingArea();
258 switch (key) {
259 case SUMO_ATTR_WIDTH:
260 return toString(walkingArea.width);
261 case SUMO_ATTR_LENGTH:
262 return toString(walkingArea.length);
263 case SUMO_ATTR_SHAPE:
264 return toString(walkingArea.shape);
267 default:
268 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
269 }
270}
271
272
273void
274GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
275 if (value == getAttribute(key)) {
276 return; //avoid needless changes, later logic relies on the fact that attributes have changed
277 }
278 switch (key) {
279 case SUMO_ATTR_ID:
280 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
281 case SUMO_ATTR_WIDTH:
282 case SUMO_ATTR_LENGTH:
283 case SUMO_ATTR_SHAPE:
285 undoList->add(new GNEChange_Attribute(this, key, value), true);
286 break;
287 default:
288 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
289 }
290}
291
292
293bool
295 switch (key) {
297 return true;
298 default:
299 return false;
300 }
301}
302
303
304bool
305GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
306 switch (key) {
307 case SUMO_ATTR_ID:
308 return false;
309 case SUMO_ATTR_WIDTH:
310 case SUMO_ATTR_LENGTH:
311 return canParse<double>(value) && (parse<double>(value) > 0);
312 case SUMO_ATTR_SHAPE:
313 if (canParse<PositionVector>(value)) {
314 return parse<PositionVector>(value).size() > 0;
315 } else {
316 return false;
317 }
319 return canParse<bool>(value);
320 default:
321 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
322 }
323}
324
325
330
331// ===========================================================================
332// private
333// ===========================================================================
334
335void
336GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
337 auto& walkingArea = getNBWalkingArea();
338 switch (key) {
339 case SUMO_ATTR_ID:
340 throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
341 case SUMO_ATTR_WIDTH:
342 walkingArea.width = parse<double>(value);
343 break;
344 case SUMO_ATTR_LENGTH:
345 walkingArea.length = parse<double>(value);
346 break;
347 case SUMO_ATTR_SHAPE:
348 walkingArea.shape = parse<PositionVector>(value);
349 walkingArea.hasCustomShape = true;
350 break;
352 if (parse<bool>(value)) {
354 } else {
356 }
357 break;
358 default:
359 throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
360 }
361}
362
363
364void
366 // set custom shape
367 getNBWalkingArea().shape = moveResult.shapeToUpdate;
368 // update geometry
370}
371
372
373void
375 // commit new shape
376 undoList->begin(GUIIcon::WALKINGAREA, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
378 undoList->end();
379}
380
381/****************************************************************************/
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
@ 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:897
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:2030
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
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
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.
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.
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
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.
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.
bool mouseWithinGeometry(const Position center, const double radius) const
check if mouse is within elements geometry (for circles)
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,...
GUIGlID getGlID() const
Returns the numerical id of the object.
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
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:2571
WalkingArea & getWalkingArea(const std::string &id)
return the walkingArea with the given ID
Definition NBNode.cpp:3713
std::map< std::string, std::string > Map
parameters map
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 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
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:175
PositionVector shape
The polygonal shape.
Definition NBNode.h:188