Eclipse SUMO - Simulation of Urban MObility
GNEChange_Crossing.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A network change in which a single junction is created or deleted
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include <netedit/GNENet.h>
26 #include <netbuild/NBNetBuilder.h>
27 #include <netedit/GNEViewNet.h>
28 
29 #include "GNEChange_Crossing.h"
30 
31 
32 // ===========================================================================
33 // FOX-declarations
34 // ===========================================================================
35 FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, nullptr, 0)
36 
37 // ===========================================================================
38 // member method definitions
39 // ===========================================================================
40 
41 
42 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges,
43  double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector& customShape, bool selected, bool forward):
44  GNEChange(junctionParent->getNet(), forward),
45  myJunctionParent(junctionParent),
46  myEdges(edges),
47  myWidth(width),
48  myPriority(priority),
49  myCustomTLIndex(customTLIndex),
50  myCustomTLIndex2(customTLIndex2),
51  myCustomShape(customShape),
52  mySelected(selected) {
53  assert(myNet);
54 }
55 
56 
57 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const NBNode::Crossing& crossing, bool forward):
58  GNEChange(junctionParent->getNet(), forward),
59  myJunctionParent(junctionParent),
60  myEdges(crossing.edges),
61  myWidth(crossing.width),
62  myPriority(crossing.priority),
63  myCustomTLIndex(crossing.customTLIndex),
64  myCustomTLIndex2(crossing.customTLIndex2),
65  myCustomShape(crossing.customShape),
66  mySelected(false) {
67  assert(myNet);
68 }
69 
70 
72  assert(myNet);
73 }
74 
75 
77  if (myForward) {
78  // show extra information for tests
79  WRITE_DEBUG("removing " + toString(SUMO_TAG_CROSSING) + " from " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
80  // remove crossing of NBNode
82  // rebuild GNECrossings
84  // Check if Flag "haveNetworkCrossings" has to be disabled
85  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
86  // change flag of NetBuilder (For build GNECrossing)
88  // show extra information for tests
89  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
90  }
91  // Update view
92  myNet->getViewNet()->update();
93  } else {
94  // show extra information for tests
95  WRITE_DEBUG("Adding " + toString(SUMO_TAG_CROSSING) + " into " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
96  // add crossing of NBNode
98  // Check if Flag "haveNetworkCrossings" has to be enabled
99  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
101  // show extra information for tests
102  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
103  }
104  // rebuild GNECrossings
106  // select if mySelected is enabled
107  if (mySelected) {
109  }
110  // Update view
111  myNet->getViewNet()->update();
112  }
113  // enable save netElements
114  myNet->requiereSaveNet(true);
115 }
116 
117 
119  if (myForward) {
120  // show extra information for tests
121  WRITE_DEBUG("Adding " + toString(SUMO_TAG_CROSSING) + " into " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
122  // add crossing of NBNode and update geometry
124  // Check if Flag "haveNetworkCrossings" has to be enabled
125  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
127  // show extra information for tests
128  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
129  }
130  // rebuild GNECrossings
132  // select if mySelected is enabled
133  if (mySelected) {
135  }
136  // Update view
137  myNet->getViewNet()->update();
138  } else {
139  // show extra information for tests
140  WRITE_DEBUG("Removing " + toString(SUMO_TAG_CROSSING) + " from " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
141  // remove crossing of NBNode and update geometry
143  // rebuild GNECrossings
145  // Check if Flag "haveNetworkCrossings" has to be disabled
146  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
147  // change flag of NetBuilder (For build GNECrossing)
149  // show extra information for tests
150  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
151  }
152  // Update view
153  myNet->getViewNet()->update();
154  }
155  // enable save netElements
156  myNet->requiereSaveNet(true);
157 }
158 
159 
160 FXString
162  if (myForward) {
163  return ("Undo create " + toString(SUMO_TAG_CROSSING)).c_str();
164  } else {
165  return ("Undo delete " + toString(SUMO_TAG_CROSSING)).c_str();
166  }
167 }
168 
169 
170 FXString
172  if (myForward) {
173  return ("Redo create " + toString(SUMO_TAG_CROSSING)).c_str();
174  } else {
175  return ("Redo delete " + toString(SUMO_TAG_CROSSING)).c_str();
176  }
177 }
void setHaveNetworkCrossings(bool value)
enable crossing in networks
Definition: NBNetBuilder.h:201
int myCustomTLIndex
custom index of GNECrossing
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
void update() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:292
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1543
The representation of a single edge during network building.
Definition: NBEdge.h:86
bool mySelected
flag to check if crossing is selected
GNEChange_Crossing(GNEJunction *junctionParent, const std::vector< NBEdge *> &edges, double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector &customShape, bool selected, bool forward)
Constructor for creating/deleting an crossing.
PositionVector myCustomShape
priority of GNECrossing
void redo()
redo action
bool netHasGNECrossings() const
check if net has GNECrossings
Definition: GNENet.cpp:1526
void removeCrossing(const EdgeVector &edges)
remove a pedestrian crossing from this node (identified by its edges)
Definition: NBNode.cpp:3101
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
A list of positions.
const std::string getID() const
function to support debugging
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
void selectAttributeCarrier(bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
NBNode::Crossing * addCrossing(EdgeVector edges, double width, bool priority, int tlIndex=-1, int tlIndex2=-1, const PositionVector &customShape=PositionVector::EMPTY, bool fromSumoNet=false)
add a pedestrian crossing to this node
Definition: NBNode.cpp:3089
GNEJunction * myJunctionParent
full information regarding the Junction in which GNECRossing is created
GNENet * myNet
the net to which operations shall be applied or which shall be informed about gui updates (we are not...
Definition: GNEChange.h:76
FXString undoName() const
return undoName
bool haveNetworkCrossings()
notify about style of loaded network (Without Crossings)
Definition: NBNetBuilder.h:196
~GNEChange_Crossing()
Destructor.
bool myPriority
priority of GNECrossing
const std::string & getTagStr() const
get tag assigned to this object in string format
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:933
std::vector< NBEdge * > myEdges
vector to save all edges of GNECrossing
int myCustomTLIndex2
custom index of GNECrossing (reverse direction)
crossing between edges for pedestrians
void undo()
undo action
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:81
A definition of a pedestrian crossing.
Definition: NBNode.h:132
void rebuildGNECrossings(bool rebuildNBNodeCrossings=true)
rebuilds crossing objects for this junction
GNECrossing * retrieveGNECrossing(NBNode::Crossing *crossing, bool createIfNoExist=true)
get GNECrossing if exist, and if not create it if create is enabled
double myWidth
width of GNECrossing
NBNode * getNBNode() const
Return net build node.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2067
FXString redoName() const
get Redo name