CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWSelectionManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWSelectionManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Jan 18 14:40:51 EST 2008
11 //
12 
13 // system include files
14 #include <functional>
15 #include <iostream>
16 #include <cassert>
17 
18 // user include files
22 
23 //
24 // constants, enums and typedefs
25 //
26 
27 //
28 // static data member definitions
29 //
30 
31 //
32 // constructors and destructor
33 //
34 FWSelectionManager::FWSelectionManager(FWModelChangeManager* iCM) : m_changeManager(iCM), m_wasChanged(false) {
35  assert(nullptr != m_changeManager);
37 }
38 
39 // FWSelectionManager::FWSelectionManager(const FWSelectionManager& rhs)
40 // {
41 // // do actual copying here;
42 // }
43 
44 /*FWSelectionManager::~FWSelectionManager()
45  {
46  }*/
47 
48 //
49 // assignment operators
50 //
51 // const FWSelectionManager& FWSelectionManager::operator=(const FWSelectionManager& rhs)
52 // {
53 // //An exception safe implementation is
54 // FWSelectionManager temp(rhs);
55 // swap(rhs);
56 //
57 // return *this;
58 // }
59 
60 //
61 // member functions
62 //
65  for (std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end(); it != itEnd; ++it) {
66  //NOTE: this will cause
67  it->unselect();
68  }
70 }
71 
73  //may need this in the future
74  //FWChangeSentry sentry(*m_changeManager);
75  std::set<FWEventItem*> items;
76  items.swap(m_itemSelection);
77  for (std::set<FWEventItem*>::iterator it = items.begin(), itEnd = items.end(); it != itEnd; ++it) {
78  //NOTE: this will cause
79  (*it)->unselectItem();
80  }
81 }
82 
85  for (std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end(); it != itEnd; ++it) {
86  //NOTE: this will cause
87  it->unselect();
88  }
89 }
90 
92  if (m_wasChanged) {
94  selectionChanged_(*this);
95  m_wasChanged = false;
96  }
97 }
98 
100  bool changed = m_newSelection.insert(iId).second;
101  m_wasChanged |= changed;
102  if (changed) {
103  //if this is new, we need to connect to the 'item' just incase it changes
104  if (m_itemConnectionCount.size() <= iId.item()->id()) {
105  m_itemConnectionCount.resize(iId.item()->id() + 1);
106  }
107  if (1 == ++(m_itemConnectionCount[iId.item()->id()].first)) {
108  //want to know early about item change so we can send the 'selectionChanged' message
109  // as part of the itemChange message from the ChangeManager
110  // This way if more than one Item has changed, we still only send one 'selectionChanged' message
111  m_itemConnectionCount[iId.item()->id()].second =
112  iId.item()->preItemChanged_.connect(std::bind(&FWSelectionManager::itemChanged, this, std::placeholders::_1));
113  }
114  }
115 }
116 
118  bool changed = (0 != m_newSelection.erase(iId));
119  m_wasChanged |= changed;
120  if (changed) {
121  assert(m_itemConnectionCount.size() > iId.item()->id());
122  //was this the last model selected for this item?
123  if (0 == --(m_itemConnectionCount[iId.item()->id()].first)) {
124  m_itemConnectionCount[iId.item()->id()].second.disconnect();
125  }
126  }
127 }
128 
130  assert(nullptr != iItem);
131  assert(m_itemConnectionCount.size() > iItem->id());
132  //if this appears in any of our models we need to remove them
133  FWModelId low(iItem, 0);
134  FWModelId high(iItem, 0x7FFFFFFF); //largest signed 32 bit number
135  bool someoneChanged = false;
136  {
137  std::set<FWModelId>::iterator itL = m_newSelection.lower_bound(low), itH = m_newSelection.upper_bound(high);
138  if (itL != itH) {
139  m_wasChanged = true;
140  someoneChanged = true;
141  m_newSelection.erase(itL, itH);
142  }
143  }
144  {
145  std::set<FWModelId>::iterator itL = m_selection.lower_bound(low), itH = m_selection.upper_bound(high);
146  if (itL != itH) {
147  m_wasChanged = true;
148  someoneChanged = true;
149  //Don't need to erase here since will happen in 'finishedAllSelection'
150  }
151  }
152  assert(someoneChanged);
153  m_itemConnectionCount[iItem->id()].second.disconnect();
154  m_itemConnectionCount[iItem->id()].first = 0;
155 }
156 
158  m_itemSelection.insert(iItem);
159  itemSelectionChanged_(*this);
160 }
162  m_itemSelection.erase(iItem);
163  itemSelectionChanged_(*this);
164 }
165 //
166 // const member functions
167 //
168 const std::set<FWModelId>& FWSelectionManager::selected() const { return m_selection; }
169 
170 const std::set<FWEventItem*>& FWSelectionManager::selectedItems() const { return m_itemSelection; }
171 
172 //
173 // static member functions
174 //
const std::set< FWModelId > & selected() const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:186
void itemChanged(const FWEventItem *)
void select(const FWModelId &iId)
sigc::signal< void(const FWSelectionManager &)> itemSelectionChanged_
const std::set< FWEventItem * > & selectedItems() const
assert(be >=bs)
std::set< FWEventItem * > m_itemSelection
std::set< FWModelId > m_newSelection
void unselectItem(FWEventItem *)
sigc::signal< void()> changeSignalsAreDone_
unsigned int id() const
Definition: FWEventItem.cc:433
void unselect(const FWModelId &iId)
FWModelChangeManager * m_changeManager
sigc::signal< void(const FWSelectionManager &)> selectionChanged_
std::vector< std::pair< int, sigc::connection > > m_itemConnectionCount
FWSelectionManager(FWModelChangeManager *iCM)
std::set< FWModelId > m_selection
const FWEventItem * item() const
Definition: FWModelId.h:39
void selectItem(FWEventItem *)