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.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>
26 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEWalkingArea.h"
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
39 
40 GNEWalkingArea::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),
44 myTesselation(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 
54 void
56  // Nothing to update
57 }
58 
59 
63 }
64 
65 
66 bool
68  return false;
69 }
70 
71 
72 bool
74  return false;
75 }
76 
77 
78 bool
80  return false;
81 }
82 
83 
84 bool
86  return false;
87 }
88 
89 
90 bool
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 
103 bool
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 
116 bool
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 
134 void
135 GNEWalkingArea::removeGeometryPoint(const Position /*clickedPosition*/, GNEUndoList* /*undoList*/) {
136  // nothing to do
137 }
138 
139 
142  return myParentJunction;
143 }
144 
145 
149 }
150 
151 
152 void
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  // get detail level
162  const auto d = s.getDetailLevel(walkingAreaExaggeration);
163  // draw geometry only if we'rent in drawForObjectUnderCursor mode
164  if (!s.drawForViewObjectsHandler) {
165  // draw walking area
166  drawWalkingArea(s, d, walkingAreaShape, walkingAreaExaggeration);
167  // draw walkingArea name
168  if (s.cwaEdgeName.show(this)) {
169  drawName(walkingAreaShape.getCentroid(), s.scale, s.edgeName, 0, true);
170  }
171  // draw dotted contour
173  }
174  // draw dotted contour (except in contour mode) checking if junction parent was inserted with full boundary
176  myNetworkElementContour.calculateContourClosedShape(s, d, this, walkingAreaShape, walkingAreaExaggeration);
177  }
178  }
179 }
180 
181 
182 void
184  // currently WalkingAreas cannot be removed
185 }
186 
187 
188 void
190  updateGeometry();
191 }
192 
193 
196  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
197  buildPopupHeader(ret, app);
200  // build selection and show parameters menu
203  // build position copy entry
204  buildPositionCopyEntry(ret, app);
205  // check if we're in supermode network
207  // create menu commands
208  FXMenuCommand* mcCustomShape = GUIDesigns::buildFXMenuCommand(ret, "Set custom WalkingArea shape", nullptr, &parent, MID_GNE_WALKINGAREA_EDIT_SHAPE);
209  // check if menu commands has to be disabled
211  if ((editMode == NetworkEditMode::NETWORK_CONNECT) || (editMode == NetworkEditMode::NETWORK_TLS) || (editMode == NetworkEditMode::NETWORK_CREATE_EDGE)) {
212  mcCustomShape->disable();
213  }
214  // disabled for release 1.15
215  mcCustomShape->disable();
216  }
217  return ret;
218 }
219 
220 
221 Boundary
224 }
225 
226 
227 void
228 GNEWalkingArea::updateCenteringBoundary(const bool /*updateGrid*/) {
229  // nothing to update
230 }
231 
232 
233 std::string
235  if (key == SUMO_ATTR_ID) {
236  // for security purposes, avoid get WalkingArea if we want only the ID
237  return getMicrosimID();
238  }
239  const auto& walkingArea = getNBWalkingArea();
240  switch (key) {
241  case SUMO_ATTR_WIDTH:
242  return toString(walkingArea.width);
243  case SUMO_ATTR_LENGTH:
244  return toString(walkingArea.length);
245  case SUMO_ATTR_SHAPE:
246  return toString(walkingArea.shape);
247  case GNE_ATTR_SELECTED:
249  default:
250  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
251  }
252 }
253 
254 
255 void
256 GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
257  if (value == getAttribute(key)) {
258  return; //avoid needless changes, later logic relies on the fact that attributes have changed
259  }
260  switch (key) {
261  case SUMO_ATTR_ID:
262  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
263  case SUMO_ATTR_WIDTH:
264  case SUMO_ATTR_LENGTH:
265  case SUMO_ATTR_SHAPE:
266  case GNE_ATTR_SELECTED:
267  GNEChange_Attribute::changeAttribute(this, key, value, undoList, true);
268  break;
269  default:
270  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
271  }
272 }
273 
274 
275 bool
277  switch (key) {
278  case GNE_ATTR_SELECTED:
279  return true;
280  default:
281  return false;
282  }
283 }
284 
285 
286 bool
287 GNEWalkingArea::isValid(SumoXMLAttr key, const std::string& value) {
288  switch (key) {
289  case SUMO_ATTR_ID:
290  return false;
291  case SUMO_ATTR_WIDTH:
292  case SUMO_ATTR_LENGTH:
293  return canParse<double>(value) && (parse<double>(value) > 0);
294  case SUMO_ATTR_SHAPE:
295  if (canParse<PositionVector>(value)) {
296  return parse<PositionVector>(value).size() > 0;
297  } else {
298  return false;
299  }
300  case GNE_ATTR_SELECTED:
301  return canParse<bool>(value);
302  default:
303  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
304  }
305 }
306 
307 
308 const Parameterised::Map&
311 }
312 
313 // ===========================================================================
314 // private
315 // ===========================================================================
316 
317 void
319  const PositionVector& shape, const double exaggeration) const {
320  // adjust shape to exaggeration
321  if (((exaggeration > 1) || (myExaggeration > 1)) && (exaggeration != myExaggeration)) {
322  myExaggeration = exaggeration;
323  myTesselation.setShape(shape);
325  myTesselation.getShapeRef().scaleRelative(exaggeration);
327  }
328  // push layer matrix
330  // translate to front
332  // set color
333  if (myShapeEdited) {
335  } else if (isAttributeCarrierSelected()) {
337  } else {
339  }
340  // check if draw walking area tesselated or contour
341  if (drawInContourMode()) {
343  } else {
345  }
346  // pop layer Matrix
348 }
349 
350 
351 bool
353  const auto& modes = myNet->getViewNet()->getEditModes();
354  // check modes
355  if (!modes.isCurrentSupermodeNetwork()) {
356  return false;
357  } else if (modes.networkEditMode != NetworkEditMode::NETWORK_MOVE) {
358  return false;
359  } else if (modes.networkEditMode != NetworkEditMode::NETWORK_CONNECT) {
360  return false;
361  } else {
362  return true;
363  }
364 }
365 
366 
367 void
369  // check if draw polygon or tesselation
371  // draw shape with high detail
373  } else {
374  // draw shape
376  }
377  // draw shape points only in Network supemode
379  // draw geometry points
383  }
384 }
385 
386 
387 void
388 GNEWalkingArea::setAttribute(SumoXMLAttr key, const std::string& value) {
389  auto& walkingArea = getNBWalkingArea();
390  switch (key) {
391  case SUMO_ATTR_ID:
392  throw InvalidArgument("Modifying attribute '" + toString(key) + "' of " + getTagStr() + " isn't allowed");
393  case SUMO_ATTR_WIDTH:
394  walkingArea.width = parse<double>(value);
395  break;
396  case SUMO_ATTR_LENGTH:
397  walkingArea.length = parse<double>(value);
398  break;
399  case SUMO_ATTR_SHAPE:
400  walkingArea.shape = parse<PositionVector>(value);
401  walkingArea.hasCustomShape = true;
402  break;
403  case GNE_ATTR_SELECTED:
404  if (parse<bool>(value)) {
406  } else {
408  }
409  break;
410  default:
411  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
412  }
413 }
414 
415 
416 void
418  // set custom shape
419  getNBWalkingArea().shape = moveResult.shapeToUpdate;
420  // update geometry
421  updateGeometry();
422 }
423 
424 
425 void
427  // commit new shape
428  undoList->begin(this, "moving " + toString(SUMO_ATTR_SHAPE) + " of " + getTagStr());
430  undoList->end();
431 }
432 
433 /****************************************************************************/
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
Definition: GUIAppEnum.h:1283
@ 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:655
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:130
static RGBColor getColor()
gets the gl-color
Definition: GLHelper.cpp:661
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 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)
Definition: GNEContour.cpp:356
void drawDottedContours(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const
drawing contour functions
Definition: GNEContour.cpp:263
Boundary getContourBoundary() const
get contour boundary
Definition: GNEContour.cpp:59
void calculateContourClosedShape(const GUIVisualizationSettings &s, const GUIVisualizationSettings::Detail d, const GUIGlObject *glObject, const PositionVector &shape, const double scale) const
calculate contours
Definition: GNEContour.cpp:75
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:2056
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
Definition: GNEViewNet.cpp:703
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:715
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.
Definition: GNEViewNet.cpp:538
~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.
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
Definition: GUIDesigns.cpp:42
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
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.
virtual double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration associated with this GLObject
Definition: GUIGlObject.h:176
const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
Definition: GUIGlObject.h:143
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 checkBoundaryParentElement(const GUIGlObject *GLObject, const GUIGlObject *parent)
check boundary parent element
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
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:2605
WalkingArea & getWalkingArea(const std::string &id)
return the walkingArea with the given ID
Definition: NBNode.cpp:3865
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
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.
Definition: SUMOPolygon.cpp:51
PositionVector & getShapeRef()
Return the exterior shape of the polygon.
Definition: SUMOPolygon.h:130
virtual void setShape(const PositionVector &shape)
Sets the shape of the polygon.
Definition: SUMOPolygon.cpp:87
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
Definition: GUIPolygon.cpp:117
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 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