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-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 abstract class for networkElements
19/****************************************************************************/
20
21#include <netedit/GNENet.h>
22#include <netedit/GNEViewNet.h>
31
32#include "GNENetworkElement.h"
33
34
35// ===========================================================================
36// method definitions
37// ===========================================================================
38
39GNENetworkElement::GNENetworkElement(GNENet* net, const std::string& id, GUIGlObjectType type, SumoXMLTag tag, FXIcon* icon,
40 const std::vector<GNEJunction*>& junctionParents,
41 const std::vector<GNEEdge*>& edgeParents,
42 const std::vector<GNELane*>& laneParents,
43 const std::vector<GNEAdditional*>& additionalParents,
44 const std::vector<GNEDemandElement*>& demandElementParents,
45 const std::vector<GNEGenericData*>& genericDataParents) :
46 GUIGlObject(type, id, icon),
47 GNEHierarchicalElement(net, tag, junctionParents, edgeParents, laneParents, additionalParents, demandElementParents, genericDataParents),
48 myShapeEdited(false) {
49}
50
51
53
54
57 return this;
58}
59
60
61const GUIGlObject*
63 return this;
64}
65
66
67bool
68GNENetworkElement::GNENetworkElement::isNetworkElementValid() const {
69 // implement in children
70 return true;
71}
72
73
74std::string
75GNENetworkElement::GNENetworkElement::getNetworkElementProblem() const {
76 // implement in children
77 return "";
78}
79
80
83 // Create table
85 // Iterate over attributes
86 for (const auto& i : myTagProperty) {
87 // Add attribute and set it dynamic if aren't unique
88 if (i.isUnique()) {
89 ret->mkItem(i.getAttrStr().c_str(), false, getAttribute(i.getAttr()));
90 } else {
91 ret->mkItem(i.getAttrStr().c_str(), true, getAttribute(i.getAttr()));
92 }
93 }
94 // close building
95 ret->closeBuilding();
96 return ret;
97}
98
99
100bool
108
109
110void
114
115
116void
126
127
128const std::string
130 try {
132 } catch (InvalidArgument&) {
133 return "";
134 }
135}
136
137
138std::string
142 } else {
143 return getTagStr() + ": " + getID();
144 }
145}
146
147
148std::string
152 } else if (myTagProperty.getTag() == SUMO_TAG_CONNECTION) {
155 return getPopUpID();
156 } else {
157 return getTagStr();
158 }
159}
160
161
162void
164 myShapeEdited = value;
165}
166
167
168bool
172
173
174int
176 const auto& s = myNet->getViewNet()->getVisualisationSettings();
177 // calculate squared geometry point radius depending of edited item
178 double geometryPointRadius = s.neteditSizeSettings.polygonGeometryPointRadius;
180 geometryPointRadius = s.neteditSizeSettings.junctionGeometryPointRadius;
181 } else if (myTagProperty.getTag() == SUMO_TAG_EDGE) {
182 geometryPointRadius = s.neteditSizeSettings.edgeGeometryPointRadius;
183 } else if (myTagProperty.getTag() == SUMO_TAG_LANE) {
184 geometryPointRadius = s.neteditSizeSettings.laneGeometryPointRadius;
185 } else if (myTagProperty.getTag() == SUMO_TAG_CONNECTION) {
186 geometryPointRadius = s.neteditSizeSettings.connectionGeometryPointRadius;
187 } else if (myTagProperty.getTag() == SUMO_TAG_CROSSING) {
188 geometryPointRadius = s.neteditSizeSettings.crossingGeometryPointRadius;
189 }
190 const auto geometryPointRadiusSquared = (geometryPointRadius * geometryPointRadius);
192 const auto mousePos = myNet->getViewNet()->getPositionInformation();
193 for (int i = 0; i < (int)shape.size(); i++) {
194 if (shape[i].distanceSquaredTo2D(mousePos) < geometryPointRadiusSquared) {
195 return i;
196 }
197 }
198 return -1;
199}
200
201
202void
205 const Boundary b = shape.getBoxBoundary();
206 // create a square as simplified shape
207 PositionVector simplifiedShape;
208 simplifiedShape.push_back(Position(b.xmin(), b.ymin()));
209 simplifiedShape.push_back(Position(b.xmin(), b.ymax()));
210 simplifiedShape.push_back(Position(b.xmax(), b.ymax()));
211 simplifiedShape.push_back(Position(b.xmax(), b.ymin()));
212 if (shape.isClosed()) {
213 simplifiedShape.push_back(simplifiedShape[0]);
214 }
215 setAttribute(SUMO_ATTR_SHAPE, toString(simplifiedShape), undoList);
216}
217
218
219void
222 PositionVector straigthenShape;
223 straigthenShape.push_front(shape.front());
224 straigthenShape.push_back(shape.back());
225 setAttribute(SUMO_ATTR_SHAPE, toString(straigthenShape), undoList);
226}
227
228
229void
232 shape.closePolygon();
233 setAttribute(SUMO_ATTR_SHAPE, toString(shape), undoList);
234}
235
236
237void
240 shape.pop_back();
241 setAttribute(SUMO_ATTR_SHAPE, toString(shape), undoList);
242}
243
244
245void
248 PositionVector newShape;
249 for (int i = index; i < (int)shape.size(); i++) {
250 newShape.push_back(shape[i]);
251 }
252 for (int i = 0; i < index; i++) {
253 newShape.push_back(shape[i]);
254 }
255 setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
256}
257
258
259void
262 PositionVector newShape;
263 for (int i = 0; i < (int)shape.size(); i++) {
264 if (i != index) {
265 newShape.push_back(shape[i]);
266 }
267 }
268 setAttribute(SUMO_ATTR_SHAPE, toString(newShape), undoList);
269}
270
271
272void
276
277
278void
279GNENetworkElement::setNetworkElementID(const std::string& newID) {
280 // set microsim ID
281 setMicrosimID(newID);
282 // enable save add elements if this network element has children
283 if (getChildAdditionals().size() > 0) {
285 }
286 // enable save demand elements if this network element has children
287 if (getChildDemandElements().size() > 0) {
289 }
290 // enable save data elements if this network element has children
291 if (getChildGenericDatas().size() > 0) {
293 }
294}
295
296
297bool
300 return true;
301 } else if (!gViewObjectsHandler.isObjectSelected(this)) {
302 return true;
303 } else {
304 return false;
305 }
306}
307
308
311 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
312 const std::string headerName = TLF("% (Edited shape)", getFullName());
313 new MFXMenuHeader(ret, app.getBoldFont(), headerName.c_str(), getGLIcon(), nullptr, 0);
314 if (OptionsCont::getOptions().getBool("gui-testing")) {
315 GUIDesigns::buildFXMenuCommand(ret, TL("Copy test coordinates to clipboard"), nullptr, ret, MID_COPY_TEST_COORDINATES);
316 }
317 // add separator
318 new FXMenuSeparator(ret);
319 // only allow open/close for junctions
321 FXMenuCommand* simplifyShape = GUIDesigns::buildFXMenuCommand(ret, TL("Simplify shape"), TL("Replace current shape with a rectangle"), nullptr, &parent, MID_GNE_SHAPEEDITED_SIMPLIFY);
322 // disable simplify shape if polygon is only a line
323 if (shape.size() <= 2) {
324 simplifyShape->disable();
325 }
326 if (shape.isClosed()) {
327 GUIDesigns::buildFXMenuCommand(ret, TL("Open shape"), TL("Open junction's shape"), nullptr, &parent, MID_GNE_SHAPEEDITED_OPEN);
328 } else {
329 GUIDesigns::buildFXMenuCommand(ret, TL("Close shape"), TL("Close junction's shape"), nullptr, &parent, MID_GNE_SHAPEEDITED_CLOSE);
330 }
331 } else {
332 FXMenuCommand* straightenShape = GUIDesigns::buildFXMenuCommand(ret, TL("Straighten shape"), TL("Replace current shape with a rectangle"), nullptr, &parent, MID_GNE_SHAPEEDITED_STRAIGHTEN);
333 // disable straighten shape if polygon is already straight
334 if (shape.size() <= 2) {
335 straightenShape->disable();
336 }
337 }
338 // create a extra FXMenuCommand if mouse is over a vertex
339 const int index = getGeometryPointUnderCursorShapeEdited();
340 if (index != -1) {
341 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);
342 FXMenuCommand* setFirstPoint = GUIDesigns::buildFXMenuCommand(ret, TL("Set first geometry point"), TL("Set first geometry point"), nullptr, &parent, MID_GNE_SHAPEEDITED_SET_FIRST_POINT);
343 // disable setFirstPoint if shape only have three points
344 if ((shape.isClosed() && (shape.size() <= 4)) || (!shape.isClosed() && (shape.size() <= 2))) {
345 removeGeometryPoint->disable();
346 }
347 // disable setFirstPoint if mouse is over first point
348 if (index == 0) {
349 setFirstPoint->disable();
350 }
351 }
352 // add separator
353 new FXMenuSeparator(ret);
354 // add finish
355 GUIDesigns::buildFXMenuCommand(ret, TL("Finish editing (Enter)"), nullptr, &parent, MID_GNE_SHAPEEDITED_FINISH);
356 return ret;
357}
358
359
360int
362 // first check if vertex already exists
363 for (const auto& shapePosition : shape) {
364 if (shapePosition.distanceTo2D(pos) < myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.polygonGeometryPointRadius) {
365 return shape.indexOfClosest(shapePosition);
366 }
367 }
368 return -1;
369}
370
371/****************************************************************************/
@ MID_COPY_TEST_COORDINATES
Copy test coordinates.
Definition GUIAppEnum.h:457
@ 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.
GUIGlObjectType
GUIViewObjectsHandler gViewObjectsHandler
#define TL(string)
Definition MsgHandler.h:315
#define TLF(string,...)
Definition MsgHandler.h:317
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
bool isInitialised() const
check if Boundary is Initialised
Definition Boundary.cpp:259
double ymin() const
Returns minimum y-coordinate.
Definition Boundary.cpp:130
double xmin() const
Returns minimum x-coordinate.
Definition Boundary.cpp:118
double ymax() const
Returns maximum y-coordinate.
Definition Boundary.cpp:136
double xmax() const
Returns maximum x-coordinate.
Definition Boundary.cpp:124
const std::string getID() const
get ID (all Attribute Carriers have one)
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
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
GNENet * myNet
pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNEAdditional * > & getChildAdditionals() const
return child additionals
const std::vector< GNEGenericData * > & getChildGenericDatas() const
return child generic data elements
virtual void removeGeometryPoint(const Position clickedPosition, GNEUndoList *undoList)=0
remove geometry point in the clicked position
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
A NBNetBuilder extended by visualisation and editing capabilities.
Definition GNENet.h:42
GNENetHelper::SavingStatus * getSavingStatus() const
get saving status
Definition GNENet.cpp:131
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2147
bool checkDrawingBoundarySelection() const
void closeShapeEdited(GNEUndoList *undoList)
close shape edited
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void setFirstGeometryPointShapeEdited(const int index, GNEUndoList *undoList)
set first geometry point shape edited
void openShapeEdited(GNEUndoList *undoList)
open shape edited
virtual std::string getAttribute(SumoXMLAttr key) const =0
void selectGLObject()
select element
void setShapeEdited(const bool value)
set shape edited
int getGeometryPointUnderCursorShapeEdited() const
get index geometry point under cursor of shape edited
void markAsFrontElement()
mark element as front element
bool myShapeEdited
flag to check if element shape is being edited
virtual PositionVector getAttributePositionVector(SumoXMLAttr key) const =0
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
void simplifyShapeEdited(GNEUndoList *undoList)
simplify shape edited
void straigthenShapeEdited(GNEUndoList *undoList)
straigthen shape edited
GUIGLObjectPopupMenu * getShapeEditedPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent, const PositionVector &shape)
get shape edited popup menu
void deleteGeometryPointShapeEdited(const int index, GNEUndoList *undoList)
delete geometry point shape edited
void resetShapeEdited(GNEUndoList *undoList)
reset shape edited
virtual const std::string getOptionalName() const
Returns the name of the object (default "")
GNENetworkElement(GNENet *net, const std::string &id, GUIGlObjectType type, SumoXMLTag tag, FXIcon *icon, const std::vector< GNEJunction * > &junctionParents, const std::vector< GNEEdge * > &edgeParents, const std::vector< GNELane * > &laneParents, const std::vector< GNEAdditional * > &additionalParents, const std::vector< GNEDemandElement * > &demandElementParents, const std::vector< GNEGenericData * > &genericDataParents)
Constructor.
void setNetworkElementID(const std::string &newID)
set network element id
bool isShapeEdited() const
check if shape is being edited
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
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.
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
GUIGlObject * getGUIGlObject()
get GUIGlObject associated with this AttributeCarrier
bool isGLObjectLocked() const
check if element is locked
void updateInformationLabel()
update information label
SelectionInformation * getSelectionInformation() const
get modul for selection information
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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
void setFrontAttributeCarrier(GNEAttributeCarrier *AC)
set front attributeCarrier
GNEViewParent * getViewParent() const
get the net object
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:94
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.
const Boundary & getSelectionBoundary() const
get selection boundary
bool isObjectSelected(const GUIGlObject *GLObject) const
check if element was already selected
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