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