SUMO - Simulation of Urban MObility
GNENet.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // The lop level container for GNE-network-components such as GNEEdge and
8 // GNEJunction. Contains an internal instances of NBNetBuilder GNE components
9 // wrap netbuild-components of this underlying NBNetBuilder and supply
10 // visualisation and editing capabilities (adapted from GUINet)
11 //
12 // Workflow (rough draft)
13 // wrap NB-components
14 // do netedit stuff
15 // call NBNetBuilder::buildLoaded to save results
16 //
17 /****************************************************************************/
18 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
19 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
20 /****************************************************************************/
21 //
22 // This file is part of SUMO.
23 // SUMO is free software: you can redistribute it and/or modify
24 // it under the terms of the GNU General Public License as published by
25 // the Free Software Foundation, either version 3 of the License, or
26 // (at your option) any later version.
27 //
28 /****************************************************************************/
29 #ifndef GNENet_h
30 #define GNENet_h
31 
32 
33 // ===========================================================================
34 // included modules
35 // ===========================================================================
36 #ifdef _MSC_VER
37 #include <windows_config.h>
38 #else
39 #include <config.h>
40 #endif
41 
42 #include <string>
43 #include <utility>
45 #include <netbuild/NBNetBuilder.h>
46 #include <utils/geom/Boundary.h>
47 #include <utils/geom/Position.h>
54 #include <utils/common/RGBColor.h>
58 #include "GNEDetectorE3.h"
59 
60 
61 // ===========================================================================
62 // class declarations
63 // ===========================================================================
66 class GNEEdge;
67 class GNELane;
68 class GNEJunction;
69 class GNEUndoList;
70 class GNEAdditional;
71 class GNEBusStop;
72 class GNEChargingStation;
73 class GNEDetectorE1;
74 class GNEDetectorE2;
75 class GNEDetectorE3;
76 class GNEDetectorE3EntryExit;
77 class GNEConnection;
78 class GNECrossing;
79 
80 // ===========================================================================
81 // class definitions
82 // ===========================================================================
87 class GNENet : public GUIGlObject {
88 
90  friend class GNEChange_Junction;
91  friend class GNEChange_Edge;
92  friend class GNEChange_Connection;
93 
94 public:
96  static const RGBColor selectionColor;
97 
100 
103 
108  GNENet(NBNetBuilder* netBuilder);
109 
111  ~GNENet();
112 
115 
123 
132 
139 
141  const Boundary& getZBoundary() const;
142 
147  void drawGL(const GUIVisualizationSettings& s) const;
149 
151  const Boundary& getBoundary() const;
152 
156 
159  const SUMORTree& getVisualisationSpeedUp() const;
160 
166  GNEJunction* createJunction(const Position& pos, GNEUndoList* undoList);
167 
179  GNEEdge* createEdge(GNEJunction* src, GNEJunction* dest, GNEEdge* tpl, GNEUndoList* undoList,
180  const std::string& suggestedName = "", bool wasSplit = false, bool allowDuplicateGeom = false);
181 
186  void deleteJunction(GNEJunction* junction, GNEUndoList* undoList);
187 
192  void deleteEdge(GNEEdge* edge, GNEUndoList* undoList);
193 
198  void deleteLane(GNELane* lane, GNEUndoList* undoList);
199 
204  void deleteConnection(GNEConnection* connection, GNEUndoList* undoList);
205 
210  void deleteCrossing(GNECrossing* crossing, GNEUndoList* undoList);
211 
216  void duplicateLane(GNELane* lane, GNEUndoList* undoList);
217 
218 
224  bool restrictLane(SUMOVehicleClass vclass, GNELane* lane, GNEUndoList* undoList);
225 
230  bool revertLaneRestriction(GNELane* lane, GNEUndoList* undoList);
231 
237  bool addSRestrictedLane(SUMOVehicleClass vclass, GNEEdge& edge, GNEUndoList* undoList);
238 
244  bool removeRestrictedLane(SUMOVehicleClass vclass, GNEEdge& edge, GNEUndoList* undoList);
245 
252  void deleteGeometryOrEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList);
253 
259  GNEJunction* splitEdge(GNEEdge* edge, const Position& pos, GNEUndoList* undoList, GNEJunction* newJunction = 0);
260 
265  void splitEdgesBidi(const std::set<GNEEdge*>& edges, const Position& pos, GNEUndoList* undoList);
266 
270  void reverseEdge(GNEEdge* edge, GNEUndoList* undoList);
271 
276  GNEEdge* addReversedEdge(GNEEdge* edge, GNEUndoList* undoList);
277 
284  void mergeJunctions(GNEJunction* moved, GNEJunction* target, GNEUndoList* undoList);
285 
291  GNEJunction* retrieveJunction(const std::string& id, bool failHard = true);
292 
298  GNEEdge* retrieveEdge(const std::string& id, bool failHard = true);
299 
305  std::vector<GNEAttributeCarrier*> retrieveAttributeCarriers(const std::set<GUIGlID>& ids, GUIGlObjectType type);
306 
310  std::vector<GNEEdge*> retrieveEdges(bool onlySelected = false);
311 
315  std::vector<GNELane*> retrieveLanes(bool onlySelected = false);
316 
322  GNELane* retrieveLane(const std::string& id, bool failHard = true);
323 
327  std::vector<GNEJunction*> retrieveJunctions(bool onlySelected = false);
328 
332  void save(OptionsCont& oc);
333 
337  void saveAdditionals(const std::string& filename);
338 
342  void savePlain(OptionsCont& oc);
343 
347  void saveJoined(OptionsCont& oc);
348 
350  void setViewNet(GNEViewNet* viewNet);
351 
353  void refreshElement(GUIGlObject* o);
354 
357  void refreshAdditional(GNEAdditional* additional);
358 
360  void renameEdge(GNEEdge* edge, const std::string& newID);
361 
363  void renameJunction(GNEJunction* junction, const std::string& newID);
364 
366  void changeEdgeEndpoints(GNEEdge* edge, const std::string& newSourceID, const std::string& newDestID);
367 
369  GNEViewNet* getViewNet() const;
370 
373 
374  /* @brief get ids of currently active objects
375  * param[in] type If type != GLO_MAX, get active ids of that type, otherwise get all active ids
376  */
377  std::set<GUIGlID> getGlIDs(GUIGlObjectType type = GLO_MAX);
378 
380  void initGNEConnections();
381 
383  void computeAndUpdate(OptionsCont& oc);
384 
385  /* @brief trigger full netbuild computation
386  * param[in] window The window to inform about delay
387  * param[in] force Whether to force recomputation even if not needed
388  */
389  void computeEverything(GNEApplicationWindow* window, bool force = false);
390 
391  /* @brief join selected junctions
392  * @note difference to mergeJunctions:
393  * - can join more than 2
394  * - connected edges will keep their geometry (big junction shape is created)
395  * - no hirarchy: if any junction has a traffic light than the resuling junction will
396  */
397  void joinSelectedJunctions(GNEUndoList* undoList);
398 
400  void removeSolitaryJunctions(GNEUndoList* undoList);
401 
403  void replaceJunctionByGeometry(GNEJunction* junction, GNEUndoList* undoList);
404 
405  /* @brief trigger recomputation of junction shape and logic
406  * param[in] window The window to inform about delay
407  */
408  void computeJunction(GNEJunction* junction);
409 
411  void requireRecompute();
412 
414  bool netHasCrossings() const;
415 
417  FXApp* getApp();
418 
420  NBNetBuilder* getNetBuilder() const;
421 
423  void addExplicitTurnaround(std::string id);
424 
426  void removeExplicitTurnaround(std::string id);
427 
430  void moveSelection(const Position& moveSrc, const Position& moveDest);
431 
433  void finishMoveSelection(GNEUndoList* undoList);
434 
437 
442  void insertAdditional(GNEAdditional* additional, bool hardFail = true);
443 
447  void deleteAdditional(GNEAdditional* additional);
448 
451  void updateAdditionalID(const std::string& oldID, GNEAdditional* additional);
452 
457  GNEAdditional* retrieveAdditional(const std::string& idl, bool hardFail = true) const;
458 
464  GNEAdditional* getAdditional(SumoXMLTag type, const std::string& id) const;
465 
472  std::string getAdditionalID(SumoXMLTag type, const GNELane* lane, const SUMOReal pos) const;
473 
478  std::vector<GNEAdditional*> getAdditionals(SumoXMLTag type = SUMO_TAG_NOTHING);
479 
485 
486 protected:
489 
492 
495 
498  typedef std::map<std::string, GNEJunction*> GNEJunctions;
499  typedef std::map<std::string, GNEEdge*> GNEEdges;
500  typedef std::map<std::pair<std::string, SumoXMLTag>, GNEAdditional*> GNEAdditionals;
501  // @}
502 
504  GNEJunctions myJunctions;
505 
507  GNEEdges myEdges;
508 
510  GNEAdditionals myAdditionals;
511 
513  // @{
516  // @}
517 
520 
522  std::set<std::string> myExplicitTurnarounds;
523 
526 
527 private:
529  void initDetectors();
530 
532  void initTLMap();
533 
535  void insertJunction(GNEJunction* junction);
536 
538  void insertEdge(GNEEdge* edge);
539 
542 
544  GNEEdge* registerEdge(GNEEdge* edge);
545 
547  void deleteSingleJunction(GNEJunction* junction);
548 
550  void deleteSingleEdge(GNEEdge* edge);
551 
553  void update();
554 
556  void reserveEdgeID(const std::string& id);
557 
559  void reserveJunctionID(const std::string& id);
560 
561  /* @brief helper function for changing the endpoints of a junction
562  * @param[in] keepEndpoints Whether to keep the original edge endpoints (influences junction shape)
563  */
564  void remapEdge(GNEEdge* oldEdge, GNEJunction* from, GNEJunction* to, GNEUndoList* undoList, bool keepEndpoints = false);
565 
568 
570  static const SUMOReal Z_INITIALIZED;
571 };
572 
573 #endif
574 
575 /****************************************************************************/
void setViewNet(GNEViewNet *viewNet)
Set the viewNet to be notified of network changes.
Definition: GNENet.cpp:713
GNEJunction * splitEdge(GNEEdge *edge, const Position &pos, GNEUndoList *undoList, GNEJunction *newJunction=0)
split edge at position by inserting a new junction
Definition: GNENet.cpp:532
void computeAndUpdate(OptionsCont &oc)
recompute the network and update lane geometries
Definition: GNENet.cpp:1430
std::vector< GNEJunction * > retrieveJunctions(bool onlySelected=false)
return all junctions
Definition: GNENet.cpp:794
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNENet.cpp:196
ShapeContainer & getShapeContainer()
get shape container
Definition: GNENet.cpp:1201
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
Definition: GNENet.cpp:759
GNEViewNet * myViewNet
The viewNet to be notofied of about changes.
Definition: GNENet.h:491
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:732
IDSupplier myEdgeIDSupplier
Definition: GNENet.h:514
SUMORTree myGrid
the rtree which contains all GUIGlObjects (so named for historical reasons)
Definition: GNENet.h:488
void joinSelectedJunctions(GNEUndoList *undoList)
Definition: GNENet.cpp:1007
GUIGlObjectType
FXApp * getApp()
get pointer to the main App
Definition: GNENet.cpp:995
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
Storage for geometrical objects extended by mutexes.
void refreshElement(GUIGlObject *o)
refreshes boundary information for o and update
Definition: GNENet.cpp:806
GNEAdditionals myAdditionals
map with the name and pointer to additional elements of net
Definition: GNENet.h:510
The main window of the Netedit.
static const RGBColor selectedLaneColor
color of selected lane
Definition: GNENet.h:99
bool revertLaneRestriction(GNELane *lane, GNEUndoList *undoList)
revert prevously restricted lane
Definition: GNENet.cpp:477
A container for traffic light definitions and built programs.
Stores the information about how to visualize structures.
std::set< GUIGlID > getGlIDs(GUIGlObjectType type=GLO_MAX)
Definition: GNENet.cpp:864
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNENet.cpp:217
void computeEverything(GNEApplicationWindow *window, bool force=false)
Definition: GNENet.cpp:937
void reverseEdge(GNEEdge *edge, GNEUndoList *undoList)
reverse edge
Definition: GNENet.cpp:596
void update()
notify myViewNet
Definition: GNENet.cpp:1400
void insertJunction(GNEJunction *junction)
inserts a single junction into the net and into the underlying netbuild-container ...
Definition: GNENet.cpp:1315
void deleteConnection(GNEConnection *connection, GNEUndoList *undoList)
remove connection
Definition: GNENet.cpp:407
void splitEdgesBidi(const std::set< GNEEdge * > &edges, const Position &pos, GNEUndoList *undoList)
split all edges at position by inserting one new junction
Definition: GNENet.cpp:585
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:87
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:54
GNEEdge * createEdge(GNEJunction *src, GNEJunction *dest, GNEEdge *tpl, GNEUndoList *undoList, const std::string &suggestedName="", bool wasSplit=false, bool allowDuplicateGeom=false)
creates a new edge (unless an edge with the same geometry already exists)
Definition: GNENet.cpp:252
void addExplicitTurnaround(std::string id)
add edge id to the list of explicit turnarounds
Definition: GNENet.cpp:1135
GUIShapeContainer myShapeContainer
the container for additional pois and polygons
Definition: GNENet.h:519
Storage for geometrical objects.
void insertEdge(GNEEdge *edge)
inserts a single edge into the net and into the underlying netbuild-container
Definition: GNENet.cpp:1322
void deleteEdge(GNEEdge *edge, GNEUndoList *undoList)
removes edge
Definition: GNENet.cpp:337
A RT-tree for efficient storing of SUMO&#39;s GL-objects.
Definition: SUMORTree.h:74
std::string getAdditionalID(SumoXMLTag type, const GNELane *lane, const SUMOReal pos) const
Returns the additional close to the given position.
Definition: GNENet.cpp:1277
void remapEdge(GNEEdge *oldEdge, GNEJunction *from, GNEJunction *to, GNEUndoList *undoList, bool keepEndpoints=false)
Definition: GNENet.cpp:664
GNEJunction * registerJunction(GNEJunction *junction)
registers a junction with GNENet containers
Definition: GNENet.cpp:1333
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:48
bool myNeedRecompute
whether the net needs recomputation
Definition: GNENet.h:525
NBNetBuilder * myNetBuilder
The internal netbuilder.
Definition: GNENet.h:494
const Boundary & getBoundary() const
returns the bounder of the network
Definition: GNENet.cpp:189
bool restrictLane(SUMOVehicleClass vclass, GNELane *lane, GNEUndoList *undoList)
transform lane to restricted lane
Definition: GNENet.cpp:451
void renameJunction(GNEJunction *junction, const std::string &newID)
updates the map and reserves new id
Definition: GNENet.cpp:1126
IDSupplier myJunctionIDSupplier
Definition: GNENet.h:515
void updateAdditionalID(const std::string &oldID, GNEAdditional *additional)
update additional ID in container
Definition: GNENet.cpp:1237
bool removeRestrictedLane(SUMOVehicleClass vclass, GNEEdge &edge, GNEUndoList *undoList)
remove restricted lane
Definition: GNENet.cpp:510
std::map< std::string, GNEJunction * > GNEJunctions
Definition: GNENet.h:498
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
Definition: GNECrossing.h:51
GUIParameterTableWindow * getParameterWindow(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own parameter window.
Definition: GNENet.cpp:206
void refreshAdditional(GNEAdditional *additional)
refreshes boundary information of an additional after a geometry update
Definition: GNENet.cpp:814
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
Definition: GNENet.cpp:719
GNEJunctions myJunctions
map with the name and pointer to junctions of net
Definition: GNENet.h:504
GNELane * retrieveLane(const std::string &id, bool failHard=true)
get lane by id
Definition: GNENet.cpp:774
Boundary myZBoundary
the z boundary (stored in the x-coordinate), values of 0 are ignored
Definition: GNENet.h:567
void deleteLane(GNELane *lane, GNEUndoList *undoList)
removes lane
Definition: GNENet.cpp:374
void deleteGeometryOrEdge(GNEEdge *edge, const Position &pos, GNEUndoList *undoList)
removes geometry when pos is close to a geometry node, deletes the whole edge otherwise ...
Definition: GNENet.cpp:524
std::vector< GNEAdditional * > getAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING)
get vector with additionals
Definition: GNENet.cpp:1288
void computeJunction(GNEJunction *junction)
Definition: GNENet.cpp:959
A lane area vehicles can halt at (netedit-version)
Definition: GNEBusStop.h:58
void initGNEConnections()
initialize GNEConnections
Definition: GNENet.cpp:1420
int getNumberOfAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING)
Returns the number of additionals of the net.
Definition: GNENet.cpp:1300
void save(OptionsCont &oc)
save the network
Definition: GNENet.cpp:679
std::vector< GNEAttributeCarrier * > retrieveAttributeCarriers(const std::set< GUIGlID > &ids, GUIGlObjectType type)
get the attribute carriers based on GlIDs
Definition: GNENet.cpp:826
void deleteCrossing(GNECrossing *crossing, GNEUndoList *undoList)
remove crossing
Definition: GNENet.cpp:425
void moveSelection(const Position &moveSrc, const Position &moveDest)
move all selected junctions and edges
Definition: GNENet.cpp:1147
GNEJunction * createJunction(const Position &pos, GNEUndoList *undoList)
creates a new junction
Definition: GNENet.cpp:241
SUMORTree & getVisualisationSpeedUp()
Returns the RTree used for visualisation speed-up.
Definition: GNENet.cpp:229
std::set< std::string > myExplicitTurnarounds
list of edge ids for which turn-arounds must be added explicitly
Definition: GNENet.h:522
void replaceJunctionByGeometry(GNEJunction *junction, GNEUndoList *undoList)
replace the selected junction by geometry node(s) and merge the edges
Definition: GNENet.cpp:1074
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:54
void reserveJunctionID(const std::string &id)
reserve junction ID (To avoid duplicates)
Definition: GNENet.cpp:1414
GNEAdditional * getAdditional(SumoXMLTag type, const std::string &id) const
Returns the named additional.
Definition: GNENet.cpp:1265
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNENet.cpp:212
void deleteSingleJunction(GNEJunction *junction)
deletes a single junction
Definition: GNENet.cpp:1368
~GNENet()
Destructor.
Definition: GNENet.cpp:158
const Boundary & getZBoundary() const
Returns the Z boundary (stored in the x() coordinate) values of 0 do not affect the boundary...
Definition: GNENet.cpp:223
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
Definition: GNENet.cpp:747
GNEEdge * registerEdge(GNEEdge *edge)
registers an edge with GNENet containers
Definition: GNENet.cpp:1350
GNENet(NBNetBuilder *netBuilder)
Constructor.
Definition: GNENet.cpp:101
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:62
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
void removeSolitaryJunctions(GNEUndoList *undoList)
removes junctions that have no edges
Definition: GNENet.cpp:1057
static const RGBColor selectedConnectionColor
color of selected connection
Definition: GNENet.h:102
A storage for options typed value containers)
Definition: OptionsCont.h:99
The popup menu of a globject.
void initTLMap()
Initialises the tl-logic map and wrappers.
void renameEdge(GNEEdge *edge, const std::string &newID)
updates the map and reserves new id
Definition: GNENet.cpp:1095
void deleteJunction(GNEJunction *junction, GNEUndoList *undoList)
removes junction and all incident edges
Definition: GNENet.cpp:307
void initDetectors()
Initialises the detector wrappers.
void removeExplicitTurnaround(std::string id)
remove edge id from the list of explicit turnarounds
Definition: GNENet.cpp:1141
void saveJoined(OptionsCont &oc)
save log of joined junctions (and nothing else)
Definition: GNENet.cpp:706
void deleteAdditional(GNEAdditional *additional)
delete additional element previously inserted
Definition: GNENet.cpp:1223
GNEEdge * addReversedEdge(GNEEdge *edge, GNEUndoList *undoList)
add reversed edge
Definition: GNENet.cpp:607
#define SUMOReal
Definition: config.h:208
GNEEdges myEdges
map with the name and pointer to edges of net
Definition: GNENet.h:507
std::map< std::pair< std::string, SumoXMLTag >, GNEAdditional * > GNEAdditionals
Definition: GNENet.h:500
static const RGBColor selectionColor
color of selection
Definition: GNENet.h:96
empty max
void reserveEdgeID(const std::string &id)
reserve edge ID (To avoid duplicates)
Definition: GNENet.cpp:1408
void deleteSingleEdge(GNEEdge *edge)
deletes a single edge
Definition: GNENet.cpp:1381
std::map< std::string, GNEEdge * > GNEEdges
Definition: GNENet.h:499
GNEAdditional * retrieveAdditional(const std::string &idl, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1250
void mergeJunctions(GNEJunction *moved, GNEJunction *target, GNEUndoList *undoList)
merge the given junctions edges between the given junctions will be deleted
Definition: GNENet.cpp:640
bool netHasCrossings() const
check if net has crossings
Definition: GNENet.cpp:984
void insertAdditional(GNEAdditional *additional, bool hardFail=true)
Insert a additional element previously created in GNEAdditionalHandler.
Definition: GNENet.cpp:1207
bool addSRestrictedLane(SUMOVehicleClass vclass, GNEEdge &edge, GNEUndoList *undoList)
add restricted lane to edge
Definition: GNENet.cpp:495
A window containing a gl-object&#39;s parameter.
void changeEdgeEndpoints(GNEEdge *edge, const std::string &newSourceID, const std::string &newDestID)
modifies endpoins of the given edge
Definition: GNENet.cpp:1104
NBTrafficLightLogicCont & getTLLogicCont()
returns the tllcont of the underlying netbuilder
Definition: GNENet.cpp:1120
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1114
void saveAdditionals(const std::string &filename)
save additional elements of the network
Definition: GNENet.cpp:688
void savePlain(OptionsCont &oc)
save plain xml representation of the network (and nothing else)
Definition: GNENet.cpp:699
void requireRecompute()
inform the net about the need for recomputation
Definition: GNENet.cpp:978
static const SUMOReal Z_INITIALIZED
marker for whether the z-boundary is initialized
Definition: GNENet.h:570
void duplicateLane(GNELane *lane, GNEUndoList *undoList)
duplicates lane
Definition: GNENet.cpp:439
void finishMoveSelection(GNEUndoList *undoList)
register changes to junction and edge positions with the undoList
Definition: GNENet.cpp:1177
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1001