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 /****************************************************************************/
14 // A network change in which a single junction is created or deleted
15 /****************************************************************************/
16 
17 // ===========================================================================
18 // included modules
19 // ===========================================================================
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
25 #include <netbuild/NBNetBuilder.h>
26 #include <netedit/GNEViewNet.h>
27 
28 #include "GNEChange_Crossing.h"
29 
30 
31 // ===========================================================================
32 // FOX-declarations
33 // ===========================================================================
34 FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, nullptr, 0)
35 
36 // ===========================================================================
37 // member method definitions
38 // ===========================================================================
39 
40 
41 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges,
42  double width, bool priority, int customTLIndex, int customTLIndex2, const PositionVector& customShape, bool selected, bool forward):
43  GNEChange(junctionParent->getNet(), forward),
44  myJunctionParent(junctionParent),
45  myEdges(edges),
46  myWidth(width),
47  myPriority(priority),
48  myCustomTLIndex(customTLIndex),
49  myCustomTLIndex2(customTLIndex2),
50  myCustomShape(customShape),
51  mySelected(selected) {
52  assert(myNet);
53 }
54 
55 
56 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const NBNode::Crossing& crossing, bool forward):
57  GNEChange(junctionParent->getNet(), forward),
58  myJunctionParent(junctionParent),
59  myEdges(crossing.edges),
60  myWidth(crossing.width),
61  myPriority(crossing.priority),
62  myCustomTLIndex(crossing.customTLIndex),
63  myCustomTLIndex2(crossing.customTLIndex2),
64  myCustomShape(crossing.customShape),
65  mySelected(false) {
66  assert(myNet);
67 }
68 
69 
71  assert(myNet);
72 }
73 
74 
76  if (myForward) {
77  // show extra information for tests
78  WRITE_DEBUG("removing " + toString(SUMO_TAG_CROSSING) + " from " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
79  // remove crossing of NBNode
81  // rebuild GNECrossings
83  // Check if Flag "haveNetworkCrossings" has to be disabled
84  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
85  // change flag of NetBuilder (For build GNECrossing)
87  // show extra information for tests
88  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
89  }
90  // Update view
91  myNet->getViewNet()->update();
92  } else {
93  // show extra information for tests
94  WRITE_DEBUG("Adding " + toString(SUMO_TAG_CROSSING) + " into " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
95  // add crossing of NBNode
97  // Check if Flag "haveNetworkCrossings" has to be enabled
98  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
100  // show extra information for tests
101  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
102  }
103  // rebuild GNECrossings
105  // select if mySelected is enabled
106  if (mySelected) {
108  }
109  // Update view
110  myNet->getViewNet()->update();
111  }
112  // enable save netElements
113  myNet->requireSaveNet(true);
114 }
115 
116 
118  if (myForward) {
119  // show extra information for tests
120  WRITE_DEBUG("Adding " + toString(SUMO_TAG_CROSSING) + " into " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
121  // add crossing of NBNode and update geometry
123  // Check if Flag "haveNetworkCrossings" has to be enabled
124  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
126  // show extra information for tests
127  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
128  }
129  // rebuild GNECrossings
131  // select if mySelected is enabled
132  if (mySelected) {
134  }
135  // Update view
136  myNet->getViewNet()->update();
137  } else {
138  // show extra information for tests
139  WRITE_DEBUG("Removing " + toString(SUMO_TAG_CROSSING) + " from " + myJunctionParent->getTagStr() + " '" + myJunctionParent->getID() + "'");
140  // remove crossing of NBNode and update geometry
142  // rebuild GNECrossings
144  // Check if Flag "haveNetworkCrossings" has to be disabled
145  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
146  // change flag of NetBuilder (For build GNECrossing)
148  // show extra information for tests
149  WRITE_DEBUG("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
150  }
151  // Update view
152  myNet->getViewNet()->update();
153  }
154  // enable save netElements
155  myNet->requireSaveNet(true);
156 }
157 
158 
159 FXString
161  if (myForward) {
162  return ("Undo create " + toString(SUMO_TAG_CROSSING)).c_str();
163  } else {
164  return ("Undo delete " + toString(SUMO_TAG_CROSSING)).c_str();
165  }
166 }
167 
168 
169 FXString
171  if (myForward) {
172  return ("Redo create " + toString(SUMO_TAG_CROSSING)).c_str();
173  } else {
174  return ("Redo delete " + toString(SUMO_TAG_CROSSING)).c_str();
175  }
176 }
GNENet::requireSaveNet
void requireSaveNet(bool value)
inform that net has to be saved
Definition: GNENet.cpp:982
GNEAttributeCarrier::getID
const std::string getID() const
function to support debugging
Definition: GNEAttributeCarrier.cpp:1289
GNENet::netHasGNECrossings
bool netHasGNECrossings() const
check if net has GNECrossings
Definition: GNENet.cpp:1575
GNEChange::myForward
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag
Definition: GNEChange.h:80
GNEChange_Crossing::undoName
FXString undoName() const
return undoName
Definition: GNEChange_Crossing.cpp:160
NBNode::removeCrossing
void removeCrossing(const EdgeVector &edges)
remove a pedestrian crossing from this node (identified by its edges)
Definition: NBNode.cpp:3081
GNEChange_Crossing::undo
void undo()
undo action
Definition: GNEChange_Crossing.cpp:75
GNEChange_Crossing::myPriority
bool myPriority
priority of GNECrossing
Definition: GNEChange_Crossing.h:97
GNEViewNet::update
void update() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:299
PositionVector
A list of positions.
Definition: PositionVector.h:45
GNEChange_Crossing::myJunctionParent
GNEJunction * myJunctionParent
full information regarding the Junction in which GNECRossing is created
Definition: GNEChange_Crossing.h:88
NBEdge
The representation of a single edge during network building.
Definition: NBEdge.h:91
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:41
GNEJunction.h
GNEChange_Crossing::~GNEChange_Crossing
~GNEChange_Crossing()
Destructor.
Definition: GNEChange_Crossing.cpp:70
GNEJunction::getNBNode
NBNode * getNBNode() const
Return net build node.
Definition: GNEJunction.cpp:398
GNENet::getNetBuilder
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1592
GNEChange_Crossing::redoName
FXString redoName() const
get Redo name
Definition: GNEChange_Crossing.cpp:170
GNEChange_Crossing::myWidth
double myWidth
width of GNECrossing
Definition: GNEChange_Crossing.h:94
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:75
GNEJunction::rebuildGNECrossings
void rebuildGNECrossings(bool rebuildNBNodeCrossings=true)
rebuilds crossing objects for this junction
Definition: GNEJunction.cpp:128
GNEChange_Crossing::myCustomTLIndex
int myCustomTLIndex
custom index of GNECrossing
Definition: GNEChange_Crossing.h:100
GNECrossing.h
GNEChange_Crossing::myEdges
std::vector< NBEdge * > myEdges
vector to save all edges of GNECrossing
Definition: GNEChange_Crossing.h:91
GNENet::getViewNet
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2117
GNEChange_Crossing::myCustomTLIndex2
int myCustomTLIndex2
custom index of GNECrossing (reverse direction)
Definition: GNEChange_Crossing.h:103
NBNetBuilder::haveNetworkCrossings
bool haveNetworkCrossings()
notify about style of loaded network (Without Crossings)
Definition: NBNetBuilder.h:195
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNEChange_Crossing::myCustomShape
PositionVector myCustomShape
priority of GNECrossing
Definition: GNEChange_Crossing.h:106
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:3069
GNEChange_Crossing::redo
void redo()
redo action
Definition: GNEChange_Crossing.cpp:117
SUMO_TAG_CROSSING
@ SUMO_TAG_CROSSING
crossing between edges for pedestrians
Definition: SUMOXMLDefinitions.h:226
GNEChange_Crossing
Definition: GNEChange_Crossing.h:48
GNEChange_Crossing::mySelected
bool mySelected
flag to check if crossing is selected
Definition: GNEChange_Crossing.h:109
config.h
NBNetBuilder::setHaveNetworkCrossings
void setHaveNetworkCrossings(bool value)
enable crossing in networks
Definition: NBNetBuilder.h:200
GNEChange_Crossing.h
GNENetElement::selectAttributeCarrier
void selectAttributeCarrier(bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
Definition: GNENetElement.cpp:83
GNEAttributeCarrier::getTagStr
const std::string & getTagStr() const
get tag assigned to this object in string format
Definition: GNEAttributeCarrier.cpp:1267
GNEJunction
Definition: GNEJunction.h:47
NBNode::Crossing
A definition of a pedestrian crossing.
Definition: NBNode.h:131
GNEChange
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:42
WRITE_DEBUG
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:284
GNENet.h
GNEJunction::retrieveGNECrossing
GNECrossing * retrieveGNECrossing(NBNode::Crossing *NBNodeCrossing, bool createIfNoExist=true)
get GNECrossing if exist, and if not create it if create is enabled
Definition: GNEJunction.cpp:896