SUMO - Simulation of Urban MObility
GNEChange_Selection.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 change to the network selection
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 
33 
34 #include "GNEChange_Selection.h"
35 #include "GNENet.h"
36 #include "GNEViewNet.h"
37 
38 
39 // ===========================================================================
40 // FOX-declarations
41 // ===========================================================================
42 FXIMPLEMENT_ABSTRACT(GNEChange_Selection, GNEChange, NULL, 0)
43 
44 // ===========================================================================
45 // member method definitions
46 // ===========================================================================
47 
48 
49 GNEChange_Selection::GNEChange_Selection(GNENet* net, const std::set<GUIGlID>& selected, const std::set<GUIGlID>& deselected, bool forward):
51  GNEChange(net, forward),
52  mySelectedIDs(selected),
53  myDeselectedIDs(deselected) {
54  assert(myNet);
55 }
56 
57 
59 }
60 
61 
62 void
64  if (myForward) {
65  int counter = 0;
66  for (std::set<GUIGlID>::const_iterator it = mySelectedIDs.begin(); it != mySelectedIDs.end(); it++) {
67  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
68  gSelected.deselect(*it);
69  counter++;
70  }
71  }
72  // show information if testing mode is enabled
73  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
74  WRITE_WARNING("Deselected " + toString(counter) + " elements in GNEChange_Selection");
75  }
76  counter = 0;
77  for (std::set<GUIGlID>::const_iterator it = myDeselectedIDs.begin(); it != myDeselectedIDs.end(); it++) {
78  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
79  gSelected.select(*it);
80  counter++;
81  }
82  }
83  // show information if testing mode is enabled
84  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
85  WRITE_WARNING("Selected " + toString(counter) + " elements in GNEChange_Selection");
86  }
87  } else {
88  int counter = 0;
89  for (std::set<GUIGlID>::const_iterator it = mySelectedIDs.begin(); it != mySelectedIDs.end(); it++) {
90  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
91  gSelected.select(*it);
92  counter++;
93  }
94  }
95  // show information if testing mode is enabled
96  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
97  WRITE_WARNING("Selected " + toString(counter) + " elements in GNEChange_Selection");
98  }
99  counter = 0;
100  for (std::set<GUIGlID>::const_iterator it = myDeselectedIDs.begin(); it != myDeselectedIDs.end(); it++) {
101  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
102  gSelected.deselect(*it);
103  counter++;
104  }
105  }
106  // show information if testing mode is enabled
107  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
108  WRITE_WARNING("Deselected " + toString(counter) + " elements in GNEChange_Selection");
109  }
110  }
111  myNet->getViewNet()->update();
112 }
113 
114 
115 void
117  if (myForward) {
118  int counter = 0;
119  for (std::set<GUIGlID>::const_iterator it = mySelectedIDs.begin(); it != mySelectedIDs.end(); it++) {
120  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
121  gSelected.select(*it);
122  counter++;
123  }
124  }
125  // show information if testing mode is enabled
126  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
127  WRITE_WARNING("Selected " + toString(counter) + " elements in GNEChange_Selection");
128  }
129  counter = 0;
130  for (std::set<GUIGlID>::const_iterator it = myDeselectedIDs.begin(); it != myDeselectedIDs.end(); it++) {
131  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
132  gSelected.deselect(*it);
133  counter++;
134  }
135  }
136  // show information if testing mode is enabled
137  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
138  WRITE_WARNING("Deselected " + toString(counter) + " elements in GNEChange_Selection");
139  }
140  } else {
141  int counter = 0;
142  for (std::set<GUIGlID>::const_iterator it = mySelectedIDs.begin(); it != mySelectedIDs.end(); it++) {
143  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
144  gSelected.deselect(*it);
145  counter++;
146  }
147  }
148  // show information if testing mode is enabled
149  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
150  WRITE_WARNING("Deselected " + toString(counter) + " elements in GNEChange_Selection");
151  }
152  counter = 0;
153  for (std::set<GUIGlID>::const_iterator it = myDeselectedIDs.begin(); it != myDeselectedIDs.end(); it++) {
154  if (GUIGlObjectStorage::gIDStorage.getObjectBlocking(*it)) {
155  gSelected.select(*it);
156  counter++;
157  }
158  }
159  // show information if testing mode is enabled
160  if ((counter > 0) && (OptionsCont::getOptions().getBool("gui-testing-debug"))) {
161  WRITE_WARNING("Selected " + toString(counter) + " elements in GNEChange_Selection");
162  }
163  }
164  myNet->getViewNet()->update();
165 }
166 
167 
168 FXString
170  if (myForward) {
171  return ("Undo change selection");
172  } else {
173  return ("Undo change selection");
174  }
175 }
176 
177 
178 FXString
180  if (myForward) {
181  return ("Redo change selection");
182  } else {
183  return ("Redo change selection");
184  }
185 }
the function-object for an editing operation (abstract base)
Definition: GNEChange.h:48
void select(GUIGlID id, bool update=true)
Adds the object with the given id.
~GNEChange_Selection()
Destructor.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:91
std::set< GUIGlID > myDeselectedIDs
all ids that were deselected in this change
void redo()
redo action
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
std::set< GUIGlID > mySelectedIDs
all ids that were selected in this change
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
void undo()
undo action
unsigned int GUIGlID
Definition: GUIGlObject.h:49
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
void deselect(GUIGlID id)
Deselects the object with the given id.
FXString redoName() const
get Redo name
FXString undoName() const
return undoName
bool myForward
we group antagonistic commands (create junction/delete junction) and keep them apart by this flag ...
Definition: GNEChange.h:86
GUISelectedStorage gSelected
A global holder of selected objects.
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1607