SUMO - Simulation of Urban MObility
GNEChange_Crossing.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A network change in which a single junction is created or deleted
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
32 
33 #include "GNEChange_Crossing.h"
34 #include "GNENet.h"
35 #include "GNEViewNet.h"
36 #include "GNECrossing.h"
37 #include "GNEJunction.h"
38 
39 
40 // ===========================================================================
41 // FOX-declarations
42 // ===========================================================================
43 FXIMPLEMENT_ABSTRACT(GNEChange_Crossing, GNEChange, NULL, 0)
44 
45 // ===========================================================================
46 // member method definitions
47 // ===========================================================================
48 
49 
50 GNEChange_Crossing::GNEChange_Crossing(GNEJunction* junctionParent, const std::vector<NBEdge*>& edges, double width, bool priority, bool selected, bool forward):
52  GNEChange(junctionParent->getNet(), forward),
53  myJunctionParent(junctionParent),
54  myEdges(edges),
55  myWidth(width),
56  myPriority(priority),
57  mySelected(selected) {
58  assert(myNet);
59 }
60 
61 
63  assert(myNet);
64 }
65 
66 
68  if (myForward) {
69  // show extra information for tests
70  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
71  WRITE_WARNING("removing " + toString(SUMO_TAG_CROSSING) + " from " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
72  }
73  // remove crossing of NBNode
75  // rebuild GNECrossings
77  // Check if Flag "haveNetworkCrossings" has to be disabled
78  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
79  // change flag of NetBuilder (For build GNECrossing)
81  // show extra information for tests
82  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
83  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
84  }
85  }
86  // Update view
87  myNet->getViewNet()->update();
88  } else {
89  // show extra information for tests
90  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
91  std::string selected = mySelected ? ("a previously selected ") : ("");
92  WRITE_WARNING("Adding " + selected + toString(SUMO_TAG_CROSSING) + " into " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
93  }
94  // add crossing of NBNode
96  // Check if Flag "haveNetworkCrossings" has to be enabled
97  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
99  // show extra information for tests
100  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
101  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
102  }
103  }
104  // rebuild GNECrossings
106  // check if created GNECrossing must be selected
107  if (mySelected) {
108  // iterate over GNECrossing of junction to find GNECrossing and select it
109  for (std::vector<GNECrossing*>::const_iterator i = myJunctionParent->getGNECrossings().begin(); i != myJunctionParent->getGNECrossings().end(); i++) {
110  NBNode::Crossing crossingFromJunction = *(*i)->getNBCrossing();
111  if (crossingFromJunction.edges == myEdges) {
112  gSelected.select((*i)->getGlID());
113  }
114  }
115  }
116  // Update view
117  myNet->getViewNet()->update();
118  }
119 }
120 
121 
123  if (myForward) {
124  // show extra information for tests
125  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
126  std::string selected = mySelected ? ("a previously selected ") : ("");
127  WRITE_WARNING("Adding " + selected + toString(SUMO_TAG_CROSSING) + " into " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
128  }
129  // add crossing of NBNode and update geometry
131  // Check if Flag "haveNetworkCrossings" has to be enabled
132  if (myNet->getNetBuilder()->haveNetworkCrossings() == false) {
134  // show extra information for tests
135  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
136  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'false' to 'true'");
137  }
138  }
139  // rebuild GNECrossings
141  // check if created GNECrossing must be selected
142  if (mySelected) {
143  // iterate over GNECrossing of junction to find GNECrossing and select it
144  for (std::vector<GNECrossing*>::const_iterator i = myJunctionParent->getGNECrossings().begin(); i != myJunctionParent->getGNECrossings().end(); i++) {
145  NBNode::Crossing crossingFromJunction = *(*i)->getNBCrossing();
146  if (crossingFromJunction.edges == myEdges) {
147  gSelected.select((*i)->getGlID());
148  }
149  }
150  }
151  // Update view
152  myNet->getViewNet()->update();
153  } else {
154  // show extra information for tests
155  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
156  WRITE_WARNING("Removing " + toString(SUMO_TAG_CROSSING) + " from " + toString(myJunctionParent->getTag()) + " '" + myJunctionParent->getID() + "'");
157  }
158  // remove crossing of NBNode and update geometry
160  // rebuild GNECrossings
162  // Check if Flag "haveNetworkCrossings" has to be disabled
163  if ((myNet->netHasGNECrossings() == false) && (myNet->getNetBuilder()->haveNetworkCrossings())) {
164  // change flag of NetBuilder (For build GNECrossing)
166  // show extra information for tests
167  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
168  WRITE_WARNING("Changed flag netBuilder::haveNetworkCrossings from 'true' to 'false'");
169  }
170  }
171  // Update view
172  myNet->getViewNet()->update();
173  }
174 }
175 
176 
177 FXString
179  if (myForward) {
180  return ("Undo create " + toString(SUMO_TAG_CROSSING)).c_str();
181  } else {
182  return ("Undo delete " + toString(SUMO_TAG_CROSSING)).c_str();
183  }
184 }
185 
186 
187 FXString
189  if (myForward) {
190  return ("Redo create " + toString(SUMO_TAG_CROSSING)).c_str();
191  } else {
192  return ("Redo delete " + toString(SUMO_TAG_CROSSING)).c_str();
193  }
194 }
void setHaveNetworkCrossings(bool value)
enable crossing in networks
Definition: NBNetBuilder.h:203
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:49
FXString undoName() const
return undoName
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:71
NBNode * getNBNode() const
Return net build node.
bool mySelected
flag to indicates if crossing was previously selected
void redo()
redo action
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
void removeCrossing(const EdgeVector &edges)
remove a pedestrian crossing from this node (identified by its edges)
Definition: NBNode.cpp:2606
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
const std::vector< GNECrossing * > & getGNECrossings() const
Returns GNECrossings.
const std::string getID() const
function to support debugging
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:82
bool haveNetworkCrossings()
notify about style of loaded network (Without Crossings)
Definition: NBNetBuilder.h:198
~GNEChange_Crossing()
Destructor.
bool myPriority
priority of GNECrossing
std::vector< NBEdge * > myEdges
vector to save all edges of GNECrossing
void rebuildGNECrossings()
rebuilds crossing objects for this junction
crossing between edges for pedestrians
void undo()
undo action
bool netHasGNECrossings() const
check if net has GNECrossings
Definition: GNENet.cpp:1257
EdgeVector edges
The edges being crossed.
Definition: NBNode.h:148
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:87
void addCrossing(EdgeVector edges, double width, bool priority, bool fromSumoNet=false)
add a pedestrian crossing to this node
Definition: NBNode.cpp:2597
A definition of a pedestrian crossing.
Definition: NBNode.h:135
SumoXMLTag getTag() const
get XML Tag assigned to this object
FXString redoName() const
get Redo name
double myWidth
width of GNECrossing
GUISelectedStorage gSelected
A global holder of selected objects.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1519
NBNetBuilder * getNetBuilder() const
get net builder
Definition: GNENet.cpp:1274