CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // $Id: FWSelectionManager.cc,v 1.12 2012/09/21 09:26:26 eulisse Exp $
12 //
13 
14 // system include files
15 #include <boost/bind.hpp>
16 #include <iostream>
17 #include <cassert>
18 
19 // user include files
23 
24 
25 //
26 // constants, enums and typedefs
27 //
28 
29 //
30 // static data member definitions
31 //
32 
33 //
34 // constructors and destructor
35 //
37  m_changeManager(iCM),
38  m_wasChanged(false)
39 {
40  assert(0!=m_changeManager);
42 }
43 
44 // FWSelectionManager::FWSelectionManager(const FWSelectionManager& rhs)
45 // {
46 // // do actual copying here;
47 // }
48 
49 /*FWSelectionManager::~FWSelectionManager()
50  {
51  }*/
52 
53 //
54 // assignment operators
55 //
56 // const FWSelectionManager& FWSelectionManager::operator=(const FWSelectionManager& rhs)
57 // {
58 // //An exception safe implementation is
59 // FWSelectionManager temp(rhs);
60 // swap(rhs);
61 //
62 // return *this;
63 // }
64 
65 //
66 // member functions
67 //
68 void
70 {
72  for(std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end();
73  it != itEnd;
74  ++it) {
75  //NOTE: this will cause
76  it->unselect();
77  }
79 }
80 
81 void
83 {
84  //may need this in the future
85  //FWChangeSentry sentry(*m_changeManager);
86  std::set<FWEventItem*> items;
87  items.swap(m_itemSelection);
88  for(std::set<FWEventItem*>::iterator it = items.begin(), itEnd = items.end();
89  it != itEnd;
90  ++it) {
91  //NOTE: this will cause
92  (*it)->unselectItem();
93  }
94 }
95 
96 void
98 {
100  for(std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end();
101  it != itEnd;
102  ++it) {
103  //NOTE: this will cause
104  it->unselect();
105  }
106 }
107 
108 void
110 {
111  if(m_wasChanged) {
113  selectionChanged_(*this);
114  m_wasChanged = false;
115  }
116 }
117 
118 void
120 {
121  bool changed = m_newSelection.insert(iId).second;
122  m_wasChanged |=changed;
123  if(changed) {
124  //if this is new, we need to connect to the 'item' just incase it changes
125  if(m_itemConnectionCount.size()<= iId.item()->id()) {
126  m_itemConnectionCount.resize(iId.item()->id()+1);
127  }
128  if(1 ==++(m_itemConnectionCount[iId.item()->id()].first) ) {
129  //want to know early about item change so we can send the 'selectionChanged' message
130  // as part of the itemChange message from the ChangeManager
131  // This way if more than one Item has changed, we still only send one 'selectionChanged' message
132  m_itemConnectionCount[iId.item()->id()].second =
133  iId.item()->preItemChanged_.connect(boost::bind(&FWSelectionManager::itemChanged,this,_1));
134  }
135  }
136 }
137 
138 void
140 {
141  bool changed = (0 != m_newSelection.erase(iId));
142  m_wasChanged |=changed;
143  if(changed) {
144  assert(m_itemConnectionCount.size() > iId.item()->id());
145  //was this the last model selected for this item?
146  if(0 ==--(m_itemConnectionCount[iId.item()->id()].first)) {
147  m_itemConnectionCount[iId.item()->id()].second.disconnect();
148  }
149  }
150 }
151 
152 void
154 {
155  assert(0!=iItem);
156  assert(m_itemConnectionCount.size() > iItem->id());
157  //if this appears in any of our models we need to remove them
158  FWModelId low(iItem,0);
159  FWModelId high(iItem,0x7FFFFFFF); //largest signed 32 bit number
160  bool someoneChanged = false;
161  {
162  std::set<FWModelId>::iterator itL=m_newSelection.lower_bound(low),
163  itH=m_newSelection.upper_bound(high);
164  if(itL!=itH) {
165  m_wasChanged =true;
166  someoneChanged=true;
167  m_newSelection.erase(itL,itH);
168  }
169  }
170  {
171  std::set<FWModelId>::iterator itL=m_selection.lower_bound(low),
172  itH=m_selection.upper_bound(high);
173  if(itL!=itH) {
174  m_wasChanged =true;
175  someoneChanged = true;
176  //Don't need to erase here since will happen in 'finishedAllSelection'
177  }
178  }
179  assert(someoneChanged);
180  m_itemConnectionCount[iItem->id()].second.disconnect();
181  m_itemConnectionCount[iItem->id()].first = 0;
182 }
183 
184 void
186 {
187  m_itemSelection.insert(iItem);
188  itemSelectionChanged_(*this);
189 }
190 void
192 {
193  m_itemSelection.erase(iItem);
194  itemSelectionChanged_(*this);
195 }
196 //
197 // const member functions
198 //
199 const std::set<FWModelId>&
201 {
202  return m_selection;
203 }
204 
205 const std::set<FWEventItem*>&
207 {
208  return m_itemSelection;
209 }
210 
211 //
212 // static member functions
213 //
const std::set< FWModelId > & selected() const
FWItemChangeSignal preItemChanged_
Definition: FWEventItem.h:204
void itemChanged(const FWEventItem *)
void select(const FWModelId &iId)
const std::set< FWEventItem * > & selectedItems() const
std::set< FWEventItem * > m_itemSelection
std::set< FWModelId > m_newSelection
void unselectItem(FWEventItem *)
unsigned int id() const
Definition: FWEventItem.cc:495
void unselect(const FWModelId &iId)
FWModelChangeManager * m_changeManager
sigc::signal< void > changeSignalsAreDone_
sigc::signal< void, const FWSelectionManager & > itemSelectionChanged_
std::vector< std::pair< int, sigc::connection > > m_itemConnectionCount
sigc::signal< void, const FWSelectionManager & > selectionChanged_
FWSelectionManager(FWModelChangeManager *iCM)
std::set< FWModelId > m_selection
const FWEventItem * item() const
Definition: FWModelId.h:45
void selectItem(FWEventItem *)