Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <boost/bind.hpp>
00016 #include <iostream>
00017 #include <cassert>
00018
00019
00020 #include "Fireworks/Core/interface/FWSelectionManager.h"
00021 #include "Fireworks/Core/interface/FWModelChangeManager.h"
00022 #include "Fireworks/Core/interface/FWEventItem.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 FWSelectionManager::FWSelectionManager(FWModelChangeManager* iCM) :
00037 m_changeManager(iCM),
00038 m_wasChanged(false)
00039 {
00040 assert(0!=m_changeManager);
00041 m_changeManager->changeSignalsAreDone_.connect(boost::bind(&FWSelectionManager::finishedAllSelections,this));
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 void
00069 FWSelectionManager::clearSelection()
00070 {
00071 FWChangeSentry sentry(*m_changeManager);
00072 for(std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end();
00073 it != itEnd;
00074 ++it) {
00075
00076 it->unselect();
00077 }
00078 clearItemSelection();
00079 }
00080
00081 void
00082 FWSelectionManager::clearItemSelection()
00083 {
00084
00085
00086 std::set<FWEventItem*> items;
00087 items.swap(m_itemSelection);
00088 for(std::set<FWEventItem*>::iterator it = items.begin(), itEnd = items.end();
00089 it != itEnd;
00090 ++it) {
00091
00092 (*it)->unselectItem();
00093 }
00094 }
00095
00096 void
00097 FWSelectionManager::clearModelSelectionLeaveItem()
00098 {
00099 FWChangeSentry sentry(*m_changeManager);
00100 for(std::set<FWModelId>::iterator it = m_selection.begin(), itEnd = m_selection.end();
00101 it != itEnd;
00102 ++it) {
00103
00104 it->unselect();
00105 }
00106 }
00107
00108 void
00109 FWSelectionManager::finishedAllSelections()
00110 {
00111 if(m_wasChanged) {
00112 m_selection=m_newSelection;
00113 selectionChanged_(*this);
00114 m_wasChanged = false;
00115 }
00116 }
00117
00118 void
00119 FWSelectionManager::select(const FWModelId& iId)
00120 {
00121 bool changed = m_newSelection.insert(iId).second;
00122 m_wasChanged |=changed;
00123 if(changed) {
00124
00125 if(m_itemConnectionCount.size()<= iId.item()->id()) {
00126 m_itemConnectionCount.resize(iId.item()->id()+1);
00127 }
00128 if(1 ==++(m_itemConnectionCount[iId.item()->id()].first) ) {
00129
00130
00131
00132 m_itemConnectionCount[iId.item()->id()].second =
00133 iId.item()->preItemChanged_.connect(boost::bind(&FWSelectionManager::itemChanged,this,_1));
00134 }
00135 }
00136 }
00137
00138 void
00139 FWSelectionManager::unselect(const FWModelId& iId)
00140 {
00141 bool changed = (0 != m_newSelection.erase(iId));
00142 m_wasChanged |=changed;
00143 if(changed) {
00144 assert(m_itemConnectionCount.size() > iId.item()->id());
00145
00146 if(0 ==--(m_itemConnectionCount[iId.item()->id()].first)) {
00147 m_itemConnectionCount[iId.item()->id()].second.disconnect();
00148 }
00149 }
00150 }
00151
00152 void
00153 FWSelectionManager::itemChanged(const FWEventItem* iItem)
00154 {
00155 assert(0!=iItem);
00156 assert(m_itemConnectionCount.size() > iItem->id());
00157
00158 FWModelId low(iItem,0);
00159 FWModelId high(iItem,0x7FFFFFFF);
00160 bool someoneChanged = false;
00161 {
00162 std::set<FWModelId>::iterator itL=m_newSelection.lower_bound(low),
00163 itH=m_newSelection.upper_bound(high);
00164 if(itL!=itH) {
00165 m_wasChanged =true;
00166 someoneChanged=true;
00167 m_newSelection.erase(itL,itH);
00168 }
00169 }
00170 {
00171 std::set<FWModelId>::iterator itL=m_selection.lower_bound(low),
00172 itH=m_selection.upper_bound(high);
00173 if(itL!=itH) {
00174 m_wasChanged =true;
00175 someoneChanged = true;
00176
00177 }
00178 }
00179 assert(someoneChanged);
00180 m_itemConnectionCount[iItem->id()].second.disconnect();
00181 m_itemConnectionCount[iItem->id()].first = 0;
00182 }
00183
00184 void
00185 FWSelectionManager::selectItem(FWEventItem* iItem)
00186 {
00187 m_itemSelection.insert(iItem);
00188 itemSelectionChanged_(*this);
00189 }
00190 void
00191 FWSelectionManager::unselectItem(FWEventItem* iItem)
00192 {
00193 m_itemSelection.erase(iItem);
00194 itemSelectionChanged_(*this);
00195 }
00196
00197
00198
00199 const std::set<FWModelId>&
00200 FWSelectionManager::selected() const
00201 {
00202 return m_selection;
00203 }
00204
00205 const std::set<FWEventItem*>&
00206 FWSelectionManager::selectedItems() const
00207 {
00208 return m_itemSelection;
00209 }
00210
00211
00212
00213