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 }
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1187
GNENet::netHasGNECrossings
bool netHasGNECrossings() const
check if net has GNECrossings
Definition: GNENet.cpp:1526
GNENet::requiereSaveNet
void requiereSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:933
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:81
GNEChange_Crossing::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Crossing.cpp:161
GNEJunction::retrieveGNECrossing
GNECrossing * retrieveGNECrossing(NBNode::Crossing *crossing, bool createIfNoExist=true)
get GNECrossing if exist, and if not create it if create is enabled
Definition: GNEJunction.cpp:961
NBNode::removeCrossing
void removeCrossing(const EdgeVector &edges)
remove a pedestrian crossing from this node (identified by its edges)
Definition: NBNode.cpp:3101
GNEChange_Crossing::undo
void undo()
undo action
Definition: GNEChange_Crossing.cpp:76
GNEChange_Crossing::myPriority
bool myPriority
priority of GNECrossing
Definition: GNEChange_Crossing.h:98
GNEViewNet::update
void update() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:292
PositionVector
A list of positions.
Definition: PositionVector.h:46
GNEChange_Crossing::myJunctionParent
GNEJunction * myJunctionParent
full information regarding the Junction in which GNECRossing is created
Definition: GNEChange_Crossing.h:89
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:86
GNEChange_Crossing::GNEChange_Crossing
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.
Definition: GNEChange_Crossing.cpp:42
GNEJunction.h
GNEChange_Crossing::~GNEChange_Crossing
~GNEChange_Crossing()
Destructor.
Definition: GNEChange_Crossing.cpp:71
GNEJunction::getNBNode
NBNode * getNBNode() const
Return net build node.
Definition: GNEJunction.cpp:452
GNENet::getNetBuilder
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1543
GNEChange_Crossing::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Crossing.cpp:171
GNEChange_Crossing::myWidth
double myWidth
width of GNECrossing
Definition: GNEChange_Crossing.h:95
GNEViewNet.h
NBNetBuilder.h
GNEChange::myNet
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
GNEJunction::rebuildGNECrossings
void rebuildGNECrossings(bool rebuildNBNodeCrossings=true)
rebuilds crossing objects for this junction
Definition: GNEJunction.cpp:119
GNEChange_Crossing::myCustomTLIndex
int myCustomTLIndex
custom index of GNECrossing
Definition: GNEChange_Crossing.h:101
GNECrossing.h
GNEChange_Crossing::myEdges
std::vector< NBEdge * > myEdges
vector to save all edges of GNECrossing
Definition: GNEChange_Crossing.h:92
GNENet::getViewNet
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2067
GNEChange_Crossing::myCustomTLIndex2
int myCustomTLIndex2
custom index of GNECrossing (reverse direction)
Definition: GNEChange_Crossing.h:104
NBNetBuilder::haveNetworkCrossings
bool haveNetworkCrossings()
notify about style of loaded network (Without Crossings)
Definition: NBNetBuilder.h:196
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNEChange_Crossing::myCustomShape
PositionVector myCustomShape
priority of GNECrossing
Definition: GNEChange_Crossing.h:107
NBNode::addCrossing
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
GNEChange_Crossing::redo
void redo()
redo action
Definition: GNEChange_Crossing.cpp:118
SUMO_TAG_CROSSING
crossing between edges for pedestrians
Definition: SUMOXMLDefinitions.h:227
GNEChange_Crossing
Definition: GNEChange_Crossing.h:49
GNEChange_Crossing::mySelected
bool mySelected
flag to check if crossing is selected
Definition: GNEChange_Crossing.h:110
config.h
NBNetBuilder::setHaveNetworkCrossings
void setHaveNetworkCrossings(bool value)
enable crossing in networks
Definition: NBNetBuilder.h:201
GNEChange_Crossing.h
GNENetElement::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
Definition: GNENetElement.cpp:132
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1165
GNEJunction
Definition: GNEJunction.h:48
NBNode::Crossing
A definition of a pedestrian crossing.
Definition: NBNode.h:132
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:43
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:246
GNENet.h