]> Creatis software - clitk.git/blob - vv/vvToolWidgetBase.cxx
210027dbcc11bb79ab47692caccf1535a5c45dcf
[clitk.git] / vv / vvToolWidgetBase.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18
19 #include "vvToolWidgetBase.h"
20 #include "vvMainWindowBase.h"
21 #include "vvSlicerManager.h"
22 #include <QMessageBox>
23
24 //------------------------------------------------------------------------------
25 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f)
26   :QDialog(parent, f),
27    Ui::vvToolWidgetBase()
28 {
29
30   // Set Modality : dialog is not modal but stay always on top because
31   // parent is set at construction
32   mIsInitialized = false;
33   mFilter = 0;
34   mMainWindow = parent;
35   setModal(false);
36   setAttribute(Qt::WA_DeleteOnClose);
37   mCurrentSlicerManager = 0;
38
39   // GUI Initialization
40   setupUi(this);
41
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()));
49
50   // Disable main widget while input image is not selected
51   mToolWidget->setEnabled(false);
52 }
53 //------------------------------------------------------------------------------
54
55
56 //------------------------------------------------------------------------------
57 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f, bool b):
58   QDialog(NULL, f), 
59   Ui::vvToolWidgetBase()
60 {
61   DD("const without qdialog");
62   // TRIAL 
63
64   mIsInitialized = false;
65   mFilter = 0;
66   mMainWindow = parent;
67   //  setModal(false);
68   //setAttribute(Qt::WA_DeleteOnClose);
69   mCurrentSlicerManager = 0;
70
71   // GUI Initialization
72   setupUi(this);
73
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()));
81
82   // Disable main widget while input image is not selected
83   mToolWidget->setEnabled(false);
84   buttonBox->hide();
85   hide();
86   DD("end const");
87 }
88 //------------------------------------------------------------------------------
89
90
91 //------------------------------------------------------------------------------
92 vvToolWidgetBase::~vvToolWidgetBase()
93 {
94
95 }
96 //------------------------------------------------------------------------------
97
98
99 //------------------------------------------------------------------------------
100 void vvToolWidgetBase::AddInputSelector(QString s, clitk::ImageToImageGenericFilterBase * f, bool allowSkip)
101 {
102   int j=0;
103   mFilter = f;
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;
113       j++;
114     }
115   }
116   if (mSlicerManagersCompatible.size() == 0) {
117     QMessageBox::information(this, "No image","Sorry, could not perform operation. No (compatible) opened image type.");
118     close();
119     return;
120   }
121   mToolInputSelectionWidget->AddInputSelector(s, mSlicerManagersCompatible, mCurrentCompatibleIndex, allowSkip);
122 }
123 //------------------------------------------------------------------------------
124
125
126 //------------------------------------------------------------------------------
127 void vvToolWidgetBase::AddInputSelector(QString s, bool allowSkip)
128 {
129   mSlicerManagersCompatible.clear();
130   for(unsigned int i=0; i<mMainWindow->GetSlicerManagers().size(); i++) {
131     mSlicerManagersCompatible.push_back(mMainWindow->GetSlicerManagers()[i]);
132   }
133   if (mMainWindow->GetSlicerManagers().size() == 0) {
134     QMessageBox::information(this, "No image","Sorry, could not perform operation. No opened image type.");
135     close();
136     return;
137   }
138   mToolInputSelectionWidget->AddInputSelector(s, mMainWindow->GetSlicerManagers(),
139       mMainWindow->GetSlicerManagerCurrentIndex(), allowSkip);
140 }
141 //------------------------------------------------------------------------------
142
143
144 //------------------------------------------------------------------------------
145 void vvToolWidgetBase::HideInputSelector()
146 {
147   QList<int> s;
148   s.push_back(0);
149   s.push_back(1);
150   splitter->setSizes(s);
151 }
152 //------------------------------------------------------------------------------
153
154
155 //------------------------------------------------------------------------------
156 void vvToolWidgetBase::show()
157 {
158   if (!mIsInitialized) {
159     mToolInputSelectionWidget->Initialize();
160     mIsInitialized = true;
161   }
162   QDialog::show();
163 }
164 //------------------------------------------------------------------------------
165
166
167 //------------------------------------------------------------------------------
168 bool vvToolWidgetBase::close()
169 {
170   return QDialog::close();
171 }
172 //------------------------------------------------------------------------------
173
174
175 //------------------------------------------------------------------------------
176 void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m)
177 {
178   mToolInputSelectionWidget->AnImageIsBeingClosed(m);
179   if (m == mCurrentSlicerManager) {
180     close();
181   }
182 }
183 //------------------------------------------------------------------------------
184
185
186 //------------------------------------------------------------------------------
187 void vvToolWidgetBase::InitializeInputs()
188 {
189   /*
190     if (mFilter) {
191     int j=0;
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;
200     j++;
201     }
202     }
203     }
204     else {
205     mSlicerManagersCompatible = mMainWindow->GetSlicerManagers();
206     mCurrentCompatibleIndex = mMainWindow->GetSlicerManagerCurrentIndex();
207     }
208     mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible,
209     mCurrentCompatibleIndex);
210     mIsInitialized = true;
211   */
212 }
213 //------------------------------------------------------------------------------
214
215
216 //------------------------------------------------------------------------------
217 // void vvToolWidgetBase::SetNumberOfNeededInputs(int i) {
218 //   DD("SetNumberOfNeededInputs");
219 //   DD(i);
220 // }
221 //------------------------------------------------------------------------------
222
223
224 //------------------------------------------------------------------------------
225 void vvToolWidgetBase::InputIsSelected()
226 {
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);
236 }
237 //------------------------------------------------------------------------------
238
239
240 //------------------------------------------------------------------------------
241 void vvToolWidgetBase::InputIsSelected(vvSlicerManager * m)
242 {
243   std::cerr << "You MUST overwrite this method vvToolWidgetBase::InputIsSelected(vvSlicerManager * m) if you use one single input" << std::endl;
244   exit(0);
245 }
246 //------------------------------------------------------------------------------
247
248
249 //------------------------------------------------------------------------------
250 void vvToolWidgetBase::InputIsSelected(std::vector<vvSlicerManager*> & l)
251 {
252   buttonBox->setEnabled(true);
253   // DD("InputIsSelected(vector)");
254   //   DD(l.size());
255   if (l.size() == 1) InputIsSelected(l[0]);
256   else {
257     std::cerr << "You MUST overwrite this method vvToolWidgetBase::InputIsSelected(vector<vvSlicerManager *> m) if you use several input" << std::endl;
258     exit(0);
259   }
260 }
261 //------------------------------------------------------------------------------