CMS 3D CMS Logo

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 //
FWModelChangeManager.h
FWSelectionManager::finishedAllSelections
void finishedAllSelections()
Definition: FWSelectionManager.cc:91
funct::false
false
Definition: Factorize.h:29
FWSelectionManager::unselect
void unselect(const FWModelId &iId)
Definition: FWSelectionManager.cc:117
FWEventItem::preItemChanged_
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:186
FWSelectionManager::m_changeManager
FWModelChangeManager * m_changeManager
Definition: FWSelectionManager.h:70
FWModelId
Definition: FWModelId.h:28
cms::cuda::assert
assert(be >=bs)
FWEventItem::id
unsigned int id() const
Definition: FWEventItem.cc:433
FWModelChangeManager
Definition: FWModelChangeManager.h:33
FWModelId::item
const FWEventItem * item() const
Definition: FWModelId.h:39
FWSelectionManager::clearSelection
void clearSelection()
Definition: FWSelectionManager.cc:63
FWModelChangeManager::changeSignalsAreDone_
sigc::signal< void > changeSignalsAreDone_
Definition: FWModelChangeManager.h:50
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
FWSelectionManager::select
void select(const FWModelId &iId)
Definition: FWSelectionManager.cc:99
FWSelectionManager::itemChanged
void itemChanged(const FWEventItem *)
Definition: FWSelectionManager.cc:129
FWSelectionManager::itemSelectionChanged_
sigc::signal< void, const FWSelectionManager & > itemSelectionChanged_
Definition: FWSelectionManager.h:54
FWSelectionManager.h
FWSelectionManager::selectionChanged_
sigc::signal< void, const FWSelectionManager & > selectionChanged_
Definition: FWSelectionManager.h:53
FWChangeSentry
Definition: FWModelChangeManager.h:68
FWSelectionManager::selected
const std::set< FWModelId > & selected() const
Definition: FWSelectionManager.cc:168
FWSelectionManager::selectItem
void selectItem(FWEventItem *)
Definition: FWSelectionManager.cc:157
FWSelectionManager::selectedItems
const std::set< FWEventItem * > & selectedItems() const
Definition: FWSelectionManager.cc:170
FWSelectionManager::clearModelSelectionLeaveItem
void clearModelSelectionLeaveItem()
Definition: FWSelectionManager.cc:83
FWSelectionManager::m_wasChanged
bool m_wasChanged
Definition: FWSelectionManager.h:73
FWEventItem.h
FWSelectionManager::clearItemSelection
void clearItemSelection()
Definition: FWSelectionManager.cc:72
LaserClient_cfi.high
high
Definition: LaserClient_cfi.py:50
FWEventItem
Definition: FWEventItem.h:56
FWSelectionManager::m_itemConnectionCount
std::vector< std::pair< int, sigc::connection > > m_itemConnectionCount
Definition: FWSelectionManager.h:74
FWSelectionManager::m_itemSelection
std::set< FWEventItem * > m_itemSelection
Definition: FWSelectionManager.h:75
FWSelectionManager::m_newSelection
std::set< FWModelId > m_newSelection
Definition: FWSelectionManager.h:72
FWSelectionManager::FWSelectionManager
FWSelectionManager(FWModelChangeManager *iCM)
Definition: FWSelectionManager.cc:34
FWSelectionManager::unselectItem
void unselectItem(FWEventItem *)
Definition: FWSelectionManager.cc:161
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
FWSelectionManager::m_selection
std::set< FWModelId > m_selection
Definition: FWSelectionManager.h:71