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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A network change in which a single junction is created or deleted
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
31 
32 #include "GNEChange_Crossing.h"
33 #include "GNENet.h"
34 #include "GNEViewNet.h"
35 #include "GNECrossing.h"
36 #include "GNEJunction.h"
37 
38 
39 // ===========================================================================
40 // FOX-declarations
41 // ===========================================================================
42 FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, NULL, 0)
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
47 
48 
49 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges,
51  double width, bool priority, int customTLIndex, const PositionVector& customShape, bool selected, bool forward):
52  GNEChange(junctionParent->getNet(), forward),
53  myJunctionParent(junctionParent),
54  myEdges(edges),
55  myWidth(width),
56  myPriority(priority),
57  myCustomTLIndex(customTLIndex),
58  myCustomShape(customShape),
59  mySelected(selected) {
60  assert(myNet);
61 }
62 
63 
65  assert(myNet);
66 }
67 
68 
70  if (myForward) {
71  // show extra information for tests
72  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
73  WRITE_WARNING("removing " + toString(SUMO_TAG_CROSSING) + " from " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
74  }
75  // remove crossing of NBNode
77  // rebuild GNECrossings
79  // Check if Flag "haveNetworkCrossings" has to be disabled
80  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
81  // change flag of NetBuilder (For build GNECrossing)
83  // show extra information for tests
84  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
85  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
86  }
87  }
88  // Update view
89  myNet->getViewNet()->update();
90  } else {
91  // show extra information for tests
92  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
93  std::string selected = mySelected ? ("a previously selected ") : ("");
94  WRITE_WARNING("Adding " + selected + toString(SUMO_TAG_CROSSING) + " into " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
95  }
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  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
103  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
104  }
105  }
106  // rebuild GNECrossings
108  // check if created GNECrossing must be selected
109  if (mySelected) {
110  // iterate over GNECrossing of junction to find GNECrossing and select it
111  for (std::vector<GNECrossing*>::const_iterator i = myJunctionParent->getGNECrossings().begin(); i != myJunctionParent->getGNECrossings().end(); i++) {
112  NBNode::Crossing crossingFromJunction = *(*i)->getNBCrossing();
113  if (crossingFromJunction.edges == myEdges) {
114  gSelected.select((*i)->getGlID());
115  }
116  }
117  }
118  // Update view
119  myNet->getViewNet()->update();
120  }
121 }
122 
123 
125  if (myForward) {
126  // show extra information for tests
127  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
128  std::string selected = mySelected ? ("a previously selected ") : ("");
129  WRITE_WARNING("Adding " + selected + toString(SUMO_TAG_CROSSING) + " into " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
130  }
131  // add crossing of NBNode and update geometry
133  // Check if Flag "haveNetworkCrossings" has to be enabled
134  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
136  // show extra information for tests
137  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
138  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
139  }
140  }
141  // rebuild GNECrossings
143  // check if created GNECrossing must be selected
144  if (mySelected) {
145  // iterate over GNECrossing of junction to find GNECrossing and select it
146  for (std::vector<GNECrossing*>::const_iterator i = myJunctionParent->getGNECrossings().begin(); i != myJunctionParent->getGNECrossings().end(); i++) {
147  NBNode::Crossing crossingFromJunction = *(*i)->getNBCrossing();
148  if (crossingFromJunction.edges == myEdges) {
149  gSelected.select((*i)->getGlID());
150  }
151  }
152  }
153  // Update view
154  myNet->getViewNet()->update();
155  } else {
156  // show extra information for tests
157  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
158  WRITE_WARNING("Removing " + toString(SUMO_TAG_CROSSING) + " from " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
159  }
160  // remove crossing of NBNode and update geometry
162  // rebuild GNECrossings
164  // Check if Flag "haveNetworkCrossings" has to be disabled
165  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
166  // change flag of NetBuilder (For build GNECrossing)
168  // show extra information for tests
169  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
170  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
171  }
172  }
173  // Update view
174  myNet->getViewNet()->update();
175  }
176 }
177 
178 
179 FXString
181  if (myForward) {
182  return ("Undo create " + toString(SUMO_TAG_CROSSING)).c_str();
183  } else {
184  return ("Undo delete " + toString(SUMO_TAG_CROSSING)).c_str();
185  }
186 }
187 
188 
189 FXString
191  if (myForward) {
192  return ("Redo create " + toString(SUMO_TAG_CROSSING)).c_str();
193  } else {
194  return ("Redo delete " + toString(SUMO_TAG_CROSSING)).c_str();
195  }
196 }
void setHaveNetworkCrossings(bool value)
enable crossing in networks
Definition: NBNetBuilder.h:207
int myCustomTLIndex
custom index of GNECrossing
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:48
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1331
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
The representation of a single edge during network building.
Definition: NBEdge.h:70
bool mySelected
flag to indicates if crossing was previously selected
PositionVector myCustomShape
priority of GNECrossing
void redo()
redo action
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
bool netHasGNECrossings() const
check if net has GNECrossings
Definition: GNENet.cpp:1314
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
const std::vector< GNECrossing * > & getGNECrossings() const
Returns GNECrossings.
void removeCrossing(const EdgeVector &edges)
remove a pedestrian crossing from this node (identified by its edges)
Definition: NBNode.cpp:2645
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
A list of positions.
const std::string getID() const
function to support debugging
void addCrossing(EdgeVector edges, double width, bool priority, int tlIndex=-1, const PositionVector &customShape=PositionVector::EMPTY, bool fromSumoNet=false)
add a pedestrian crossing to this node
Definition: NBNode.cpp:2635
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:81
FXString undoName() const
return undoName
bool haveNetworkCrossings()
notify about style of loaded network (Without Crossings)
Definition: NBNetBuilder.h:202
~GNEChange_Crossing()
Destructor.
bool myPriority
priority of GNECrossing
std::vector< NBEdge * > myEdges
vector to save all edges of GNECrossing
crossing between edges for pedestrians
void undo()
undo action
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:137
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:86
A definition of a pedestrian crossing.
Definition: NBNode.h:131
void rebuildGNECrossings(bool rebuildNBNodeCrossings=true)
rebuilds crossing objects for this junction
double myWidth
width of GNECrossing
NBNode * getNBNode() const
Return net build node.
GUISelectedStorage gSelected
A global holder of selected objects.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1607
FXString redoName() const
get Redo name
SumoXMLTag getTag() const
get XML Tag assigned to this object