Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNENetworkElement.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-2025 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 abstract class for networkElements
19/****************************************************************************/
20
23#include <netedit/GNENet.h>
32
33#include "GNENetworkElement.h"
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38
40 GNEAttributeCarrier(tag, net, net->getGNEApplicationWindow()->getFileBucketHandler()->getDefaultBucket(FileBucket::Type::NETWORK)),
41 GUIGlObject(myTagProperty->getGLType(), "", GUIIconSubSys::getIcon(myTagProperty->getGUIIcon())),
42 myShapeEdited(false) {
43}
44
45
46GNENetworkElement::GNENetworkElement(GNENet* net, const std::string& id, SumoXMLTag tag) :
47 GNEAttributeCarrier(tag, net, net->getGNEApplicationWindow()->getFileBucketHandler()->getDefaultBucket(FileBucket::Type::NETWORK)),
48 GUIGlObject(myTagProperty->getGLType(), id,
49 GUIIconSubSys::getIcon(myTagProperty->getGUIIcon())),
50 myShapeEdited(false) {
51}
52
53
55
56
61
62
65 return this;
66}
67
68
69const GUIGlObject*
71 return this;
72}
73
74
79
80
81bool
82GNENetworkElement::GNENetworkElement::isNetworkElementValid() const {
83 // implement in children
84 return true;
85}
86
87
88std::string
89GNENetworkElement::GNENetworkElement::getNetworkElementProblem() const {
90 // implement in children
91 return "";
92}
93
94
97 // Create table
99 // Iterate over attributes
100 for (const auto& attributeProperty : myTagProperty->getAttributeProperties()) {
101 // Add attribute and set it dynamic if aren't unique
102 if (attributeProperty->isUnique()) {
103 ret->mkItem(attributeProperty->getAttrStr().c_str(), false, getAttribute(attributeProperty->getAttr()));
104 } else {
105 ret->mkItem(attributeProperty->getAttrStr().c_str(), true, getAttribute(attributeProperty->getAttr()));
106 }
107 }
108 // close building
109 ret->closeBuilding();
110 return ret;
111}
112
113
114bool
122
123
124void
128
129
130void
140
141
142const std::string
144 try {
146 } catch (InvalidArgument&) {
147 return "";
148 }
149}
150
151
152std::string
156 } else {
157 return getTagStr() + ": " + getID();
158 }
159}
160
161
162std::string
166 } else if (myTagProperty->getTag() == SUMO_TAG_CONNECTION) {
169 return getPopUpID();
170 } else {
171 return getTagStr();
172 }
173}
174
175
176void
178 myShapeEdited = value;
179}
180
181
182bool
186
187
188int
190 const auto& s = myNet->getViewNet()->getVisualisationSettings();
191 // calculate squared geometry point radius depending of edited item
192 double geometryPointRadius = s.neteditSizeSettings.polygonGeometryPointRadius;
194 geometryPointRadius = s.neteditSizeSettings.junctionGeometryPointRadius;
195 } else if (myTagProperty->getTag() == SUMO_TAG_EDGE) {
196 geometryPointRadius = s.neteditSizeSettings.edgeGeometryPointRadius;
197 } else if (myTagProperty->getTag() == SUMO_TAG_LANE) {
198 geometryPointRadius = s.neteditSizeSettings.laneGeometryPointRadius;
199 } else if (myTagProperty->getTag() == SUMO_TAG_CONNECTION) {
200 geometryPointRadius = s.neteditSizeSettings.connectionGeometryPointRadius;
201 } else if (myTagProperty->getTag() == SUMO_TAG_CROSSING) {
202 geometryPointRadius = s.neteditSizeSettings.crossingGeometryPointRadius;
203 }
204 const auto geometryPointRadiusSquared = (geometryPointRadius * geometryPointRadius);
206 const auto mousePos = myNet->getViewNet()->getPositionInformation();
207 for (int i = 0; i < (int)shape.size(); i++) {
208 if (shape[i].distanceSquaredTo2D(mousePos) < geometryPointRadiusSquared) {
209 return i;
210 }
211 }
212 return -1;
213}
214
215
216void
219 const Boundary b = shape.getBoxBoundary();
220 // create a square as simplified shape
221 PositionVector simplifiedShape;
222 simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
223 simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
224 simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
225 simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
226 if (shape.isClosed()) {
227 simplifiedShape.push_back(simplifiedShape[0]);
228 }
229 setAttribute(SUMO_ATTR_SHAPE, toString(simplifiedShape), undoList);
230}
231
232
233void
236 PositionVector straigthenShape;
237 straigthenShape.push_front(shape.front());
238 straigthenShape.push_back(shape.back());
239 setAttribute(SUMO_ATTR_SHAPE, toString(straigthenShape), undoList);
240}
241
242
243void
246 shape.closePolygon();
247 setAttribute(SUMO_ATTR_SHAPE, toString(shape), undoList);
248}
249
250
251void
254 shape.pop_back();
255 setAttribute(SUMO_ATTR_SHAPE, toString(shape), undoList);
256}
257
258
259void
262 PositionVector newShape;
263 for (int i = index; i < (int)shape.size(); i++) {
264 newShape.push_back(shape[i]);
265 }
266 for (int i = 0; i < index; i++) {
267 newShape.push_back(shape[i]);
268 }
269 setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
270}
271
272
273void
276 PositionVector newShape;
277 for (int i = 0; i < (int)shape.size(); i++) {
278 if (i != index) {
279 newShape.push_back(shape[i]);
280 }
281 }
282 setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
283}
284
285
286void
290
291
292void
293GNENetworkElement::setNetworkElementID(const std::string& newID) {
294 // set microsim ID
295 setMicrosimID(newID);
296 // enable save add elements if this network element has children
297 if ((getChildAdditionals().size() > 0) || (getChildTAZSourceSinks().size() > 0)) {
299 }
300 // enable save demand elements if this network element has children
301 if (getChildDemandElements().size() > 0) {
303 }
304 // enable save data elements if this network element has children
305 if (getChildGenericDatas().size() > 0) {
307 }
308}
309
310
311bool
314 return true;
315 } else if (!gViewObjectsHandler.isObjectSelected(this)) {
316 return true;
317 } else {
318 return false;
319 }
320}
321
322
325 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
326 const std::string headerName = TLF("% (Edited shape)", getFullName());
327 new MFXMenuHeader(ret, app.getBoldFont(), headerName.c_str(), getGLIcon(), nullptr, 0);
328 if (OptionsCont::getOptions().getBool("gui-testing")) {
329 GUIDesigns::buildFXMenuCommand(ret, TL("Copy test coordinates to clipboard"), nullptr, ret, MID_COPY_TEST_COORDINATES);
330 }
331 // add separator
332 new FXMenuSeparator(ret);
333 // only allow open/close for junctions
335 FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, TL("Simplify shape"), TL("Replace current shape with a rectangle"), nullptr, &parent, MID_GNE_SHAPEEDITED_SIMPLIFY);
336 // disable simplify shape if polygon is only a line
337 if (shape.size() <= 2) {
338 simplifyShape->disable();
339 }
340 if (shape.isClosed()) {
341 GUIDesigns::buildFXMenuCommand(ret, TL("Open shape"), TL("Open junction's shape"), nullptr, &parent, MID_GNE_SHAPEEDITED_OPEN);
342 } else {
343 GUIDesigns::buildFXMenuCommand(ret, TL("Close shape"), TL("Close junction's shape"), nullptr, &parent, MID_GNE_SHAPEEDITED_CLOSE);
344 }
345 } else {
346 FXMenuCommand* straightenShape = GUIDesigns::buildFXMenuCommand(ret, TL("Straighten shape"), TL("Replace current shape with a rectangle"), nullptr, &parent, MID_GNE_SHAPEEDITED_STRAIGHTEN);
347 // disable straighten shape if polygon is already straight
348 if (shape.size() <= 2) {
349 straightenShape->disable();
350 }
351 }
352 // create a extra FXMenuCommand if mouse is over a vertex
353 const int index = getGeometryPointUnderCursorShapeEdited();
354 if (index != -1) {
355 FXMenuCommand* removeGeometryPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Remove geometry point (shift+click)"), TL("Remove geometry point under mouse"), nullptr, &parent, MID_GNE_SHAPEEDITED_DELETE_GEOMETRY_POINT);
356 FXMenuCommand* setFirstPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Set first geometry point"), TL("Set first geometry point"), nullptr, &parent, MID_GNE_SHAPEEDITED_SET_FIRST_POINT);
357 // disable setFirstPoint if shape only have three points
358 if ((shape.isClosed() && (shape.size() <= 4)) || (!shape.isClosed() && (shape.size() <= 2))) {
359 removeGeometryPoint->disable();
360 }
361 // disable setFirstPoint if mouse is over first point
362 if (index == 0) {
363 setFirstPoint->disable();
364 }
365 }
366 // add separator
367 new FXMenuSeparator(ret);
368 // add finish
369 GUIDesigns::buildFXMenuCommand(ret, TL("Finish editing (Enter)"), nullptr, &parent, MID_GNE_SHAPEEDITED_FINISH);
370 return ret;
371}
372
373
374int
376 // first check if vertex already exists
377 for (const auto& shapePosition : shape) {
378 if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
379 return shape.indexOfClosest(shapePosition);
380 }
381 }
382 return -1;
383}
384
385/****************************************************************************/
@ NETWORK
Network mode (Edges, junctions, etc..)
@ MID_COPY_TEST_COORDINATES
Copy test coordinates.
Definition GUIAppEnum.h:459
@ MID_GNE_SHAPEEDITED_DELETE_GEOMETRY_POINT
delete geometry point in shape edited
@ MID_GNE_SHAPEEDITED_STRAIGHTEN
straighten shape edited geometry
@ MID_GNE_SHAPEEDITED_OPEN
open closed shape edited
@ MID_GNE_SHAPEEDITED_SIMPLIFY
simplify shape edited geometry
@ MID_GNE_SHAPEEDITED_FINISH
finish editing shape edited
@ MID_GNE_SHAPEEDITED_CLOSE
close opened shape edited
@ MID_GNE_SHAPEEDITED_SET_FIRST_POINT
Set a vertex of shape edited as first vertex.
GUIViewObjectsHandler gViewObjectsHandler
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CONNECTION
connectioon between two lanes
@ SUMO_TAG_JUNCTION
begin/end of the description of a junction
@ SUMO_TAG_CROSSING
crossing between edges for pedestrians
@ SUMO_TAG_LANE
begin/end of the description of a single lane
@ SUMO_TAG_EDGE
begin/end of the description of an edge
@ SUMO_ATTR_FROM_LANE
@ SUMO_ATTR_SHAPE
edge: the shape in xml-definition
@ SUMO_ATTR_INDEX
@ SUMO_ATTR_NAME
@ SUMO_ATTR_TO
@ SUMO_ATTR_FROM
@ SUMO_ATTR_TO_LANE
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
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:127
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:115
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:133
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:121
virtual PositionVector getAttributePositionVector(SumoXMLAttr key) const =0
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
void markForDrawingFront()
mark for drawing front
FileBucket * myFileBucket
filebucket vinculated whith this AC
const std::string getID() const override
get ID (all Attribute Carriers have one)
void unselectAttributeCarrier()
unselect attribute carrier using GUIGlobalSelection
const std::string & getTagStr() const
get tag assigned to this object in string format
GNENet * myNet
pointer to net
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
virtual std::string getAttribute(SumoXMLAttr key) const =0
const GNETagProperties * myTagProperty
reference to tagProperty associated with this attribute carrier
const GNEHierarchicalContainerChildren< GNEGenericData * > & getChildGenericDatas() const
return child generic data elements
const GNEHierarchicalContainerChildren< GNEAdditional * > & getChildAdditionals() const
return child additionals
const GNEHierarchicalContainerChildrenSet< GNETAZSourceSink * > & getChildTAZSourceSinks() const
return child TAZSourceSinks (Set)
const GNEHierarchicalContainerChildren< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
void requireSaveAdditionals()
inform that additionals has to be saved
void requireSaveDataElements()
inform that data elements has to be saved
void requireSaveDemandElements()
inform that demand elements has to be saved
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:186
GNEViewParent * getViewParent() const
get view parent (used for simplify code)
Definition GNENet.cpp:150
GNEViewNet * getViewNet() const
get view net (used for simplify code)
Definition GNENet.cpp:144
bool checkDrawingBoundarySelection() const
void closeShapeEdited(GNEUndoList *undoList)
close shape edited
void setFirstGeometryPointShapeEdited(const int index, GNEUndoList *undoList)
set first geometry point shape edited
void openShapeEdited(GNEUndoList *undoList)
open shape edited
GUIGlObject * getGUIGlObject() override
get GUIGlObject associated with this AttributeCarrier
GNEHierarchicalElement * getHierarchicalElement() override
methods to retrieve the elements linked to this network element
bool isGLObjectLocked() const override
check if element is locked
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent) override
Returns an own parameter window.
void setShapeEdited(const bool value)
set shape edited
int getGeometryPointUnderCursorShapeEdited() const
get index geometry point under cursor of shape edited
bool myShapeEdited
flag to check if element shape is being edited
FileBucket * getFileBucket() const override
get reference to fileBucket in which save this AC
GNENetworkElement(GNENet *net, SumoXMLTag tag)
Constructor for templates.
void simplifyShapeEdited(GNEUndoList *undoList)
simplify shape edited
void straigthenShapeEdited(GNEUndoList *undoList)
straighten shape edited
GUIGLObjectPopupMenu * getShapeEditedPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent, const PositionVector &shape)
get shape edited popup menu
void markAsFrontElement() override
mark element as front element
void deleteGeometryPointShapeEdited(const int index, GNEUndoList *undoList)
delete geometry point shape edited
void resetShapeEdited(GNEUndoList *undoList)
reset shape edited
void selectGLObject() override
select element
virtual const std::string getOptionalName() const override
Returns the name of the object (default "")
std::string getPopUpID() const override
get PopPup ID (Used in AC Hierarchy)
void setNetworkElementID(const std::string &newID)
set network element id
bool isShapeEdited() const
check if shape is being edited
int getVertexIndex(const PositionVector &shape, const Position &pos)
return index of a vertex of shape, or of a new vertex if position is over an shape's edge
virtual ~GNENetworkElement()
Destructor.
std::string getHierarchyName() const override
get Hierarchy Name (Used in AC Hierarchy)
void updateInformationLabel()
update information label
SelectionInformation * getSelectionInformation() const
get modul for selection information
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::vector< const GNEAttributeProperties * > & getAttributeProperties() const
get all attribute properties
bool isObjectLocked(GUIGlObjectType objectType, const bool selected) const
check if given GLObject is locked for inspect, select, delete and move
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
GNEViewNetHelper::LockManager & getLockManager()
get lock manager
GNESelectorFrame * getSelectorFrame() const
get frame for select elements
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.
FXIcon * getGLIcon() const
get icon associated with this GL Object
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
const std::string & getFullName() const
Definition GUIGlObject.h:95
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
FXFont * getBoldFont()
get bold front
A window containing a gl-object's parameter.
void mkItem(const char *name, bool dynamic, ValueSource< T > *src)
Adds a row which obtains its value from a ValueSource.
void closeBuilding(const Parameterised *p=0)
Closes the building of the table.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
bool isObjectSelected(const GUIGlObject *GLObject) const
check if element was already selected
bool selectingUsingRectangle() const
return true if we're selecting using a triangle
GUIVisualizationNeteditSizeSettings neteditSizeSettings
netedit size settings
static OptionsCont & getOptions()
Retrieves the options.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
int indexOfClosest(const Position &p, bool twoD=false) const
void push_front(const Position &p)
insert in front a Position
bool isClosed() const
check if PositionVector is closed
bool isCurrentSupermodeNetwork() const
@check if current supermode is Network
static const double polygonGeometryPointRadius
moving geometry point radius