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