1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
19 #include "vvToolWidgetBase.h"
20 #include "vvMainWindowBase.h"
21 #include "vvSlicerManager.h"
22 #include <QMessageBox>
24 //------------------------------------------------------------------------------
25 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f)
27 Ui::vvToolWidgetBase()
30 // Set Modality : dialog is not modal but stay always on top because
31 // parent is set at construction
32 mIsInitialized = false;
36 setAttribute(Qt::WA_DeleteOnClose);
37 mCurrentSlicerManager = 0;
42 // Connect signals & slots
43 connect(mMainWindow, SIGNAL(AnImageIsBeingClosed(vvSlicerManager*)),
44 this, SLOT(AnImageIsBeingClosed(vvSlicerManager*)));
45 connect(mToolInputSelectionWidget, SIGNAL(accepted()), this, SLOT(InputIsSelected()));
46 connect(mToolInputSelectionWidget, SIGNAL(rejected()), this, SLOT(close()));
47 connect(buttonBox, SIGNAL(accepted()), this, SLOT(apply()));
48 connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
50 // Disable main widget while input image is not selected
51 mToolWidget->setEnabled(false);
53 //------------------------------------------------------------------------------
56 //------------------------------------------------------------------------------
57 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f, bool b):
59 Ui::vvToolWidgetBase()
61 DD("const without qdialog");
64 mIsInitialized = false;
68 //setAttribute(Qt::WA_DeleteOnClose);
69 mCurrentSlicerManager = 0;
74 // Connect signals & slots
75 connect(mMainWindow, SIGNAL(AnImageIsBeingClosed(vvSlicerManager*)),
76 this, SLOT(AnImageIsBeingClosed(vvSlicerManager*)));
77 connect(mToolInputSelectionWidget, SIGNAL(accepted()), this, SLOT(InputIsSelected()));
78 connect(mToolInputSelectionWidget, SIGNAL(rejected()), this, SLOT(close()));
79 //connect(buttonBox, SIGNAL(accepted()), this, SLOT(apply()));
80 //connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
82 // Disable main widget while input image is not selected
83 mToolWidget->setEnabled(false);
88 //------------------------------------------------------------------------------
91 //------------------------------------------------------------------------------
92 vvToolWidgetBase::~vvToolWidgetBase()
96 //------------------------------------------------------------------------------
99 //------------------------------------------------------------------------------
100 void vvToolWidgetBase::AddInputSelector(QString s, clitk::ImageToImageGenericFilterBase * f, bool allowSkip)
104 mSlicerManagersCompatible.clear();
105 mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str()));
106 for(unsigned int i=0; i<mMainWindow->GetSlicerManagers().size(); i++) {
107 vvImage * s = mMainWindow->GetSlicerManagers()[i]->GetImage();
108 if (mFilter->CheckImageType(s->GetNumberOfDimensions(),
109 s->GetNumberOfScalarComponents(),
110 s->GetScalarTypeAsString())) {
111 mSlicerManagersCompatible.push_back(mMainWindow->GetSlicerManagers()[i]);
112 if ((int)i == mMainWindow->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j;
116 if (mSlicerManagersCompatible.size() == 0) {
117 QMessageBox::information(this, "No image","Sorry, could not perform operation. No (compatible) opened image type.");
121 mToolInputSelectionWidget->AddInputSelector(s, mSlicerManagersCompatible, mCurrentCompatibleIndex, allowSkip);
123 //------------------------------------------------------------------------------
126 //------------------------------------------------------------------------------
127 void vvToolWidgetBase::AddInputSelector(QString s, bool allowSkip)
129 mSlicerManagersCompatible.clear();
130 for(unsigned int i=0; i<mMainWindow->GetSlicerManagers().size(); i++) {
131 mSlicerManagersCompatible.push_back(mMainWindow->GetSlicerManagers()[i]);
133 if (mMainWindow->GetSlicerManagers().size() == 0) {
134 QMessageBox::information(this, "No image","Sorry, could not perform operation. No opened image type.");
138 mToolInputSelectionWidget->AddInputSelector(s, mMainWindow->GetSlicerManagers(),
139 mMainWindow->GetSlicerManagerCurrentIndex(), allowSkip);
141 //------------------------------------------------------------------------------
144 //------------------------------------------------------------------------------
145 void vvToolWidgetBase::HideInputSelector()
150 splitter->setSizes(s);
152 //------------------------------------------------------------------------------
155 //------------------------------------------------------------------------------
156 void vvToolWidgetBase::show()
158 if (!mIsInitialized) {
159 mToolInputSelectionWidget->Initialize();
160 mIsInitialized = true;
164 //------------------------------------------------------------------------------
167 //------------------------------------------------------------------------------
168 bool vvToolWidgetBase::close()
170 return QDialog::close();
172 //------------------------------------------------------------------------------
175 //------------------------------------------------------------------------------
176 void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m)
178 mToolInputSelectionWidget->AnImageIsBeingClosed(m);
179 if (m == mCurrentSlicerManager) {
183 //------------------------------------------------------------------------------
186 //------------------------------------------------------------------------------
187 void vvToolWidgetBase::InitializeInputs()
192 mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str()));
193 for(unsigned int i=0; i<mMainWindow->GetSlicerManagers().size(); i++) {
194 vvImage * s = mMainWindow->GetSlicerManagers()[i]->GetImage();
195 if (mFilter->CheckImageType(s->GetNumberOfDimensions(),
196 s->GetNumberOfScalarComponents(),
197 s->GetScalarTypeAsString())) {
198 mSlicerManagersCompatible.push_back(mMainWindow->GetSlicerManagers()[i]);
199 if ((int)i == mMainWindow->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j;
205 mSlicerManagersCompatible = mMainWindow->GetSlicerManagers();
206 mCurrentCompatibleIndex = mMainWindow->GetSlicerManagerCurrentIndex();
208 mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible,
209 mCurrentCompatibleIndex);
210 mIsInitialized = true;
213 //------------------------------------------------------------------------------
216 //------------------------------------------------------------------------------
217 // void vvToolWidgetBase::SetNumberOfNeededInputs(int i) {
218 // DD("SetNumberOfNeededInputs");
221 //------------------------------------------------------------------------------
224 //------------------------------------------------------------------------------
225 void vvToolWidgetBase::InputIsSelected()
227 // DD("InputIsSelected");
228 buttonBox->setEnabled(true);
229 std::vector<vvSlicerManager*> & l = mToolInputSelectionWidget->GetSelectedInputs();
230 mCurrentSlicerManager = l[0];
231 mCurrentImage = mCurrentSlicerManager->GetImage();
232 mToolWidget->setEnabled(true);
233 if (!mCurrentSlicerManager) close();
234 if (l.size() == 1) InputIsSelected(mCurrentSlicerManager);
235 else InputIsSelected(l);
237 //------------------------------------------------------------------------------
240 //------------------------------------------------------------------------------
241 void vvToolWidgetBase::InputIsSelected(vvSlicerManager * m)
243 std::cerr << "You MUST overwrite this method vvToolWidgetBase::InputIsSelected(vvSlicerManager * m) if you use one single input" << std::endl;
246 //------------------------------------------------------------------------------
249 //------------------------------------------------------------------------------
250 void vvToolWidgetBase::InputIsSelected(std::vector<vvSlicerManager*> & l)
252 buttonBox->setEnabled(true);
253 // DD("InputIsSelected(vector)");
255 if (l.size() == 1) InputIsSelected(l[0]);
257 std::cerr << "You MUST overwrite this method vvToolWidgetBase::InputIsSelected(vector<vvSlicerManager *> m) if you use several input" << std::endl;
261 //------------------------------------------------------------------------------