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