]> Creatis software - clitk.git/blob - vv/vvToolSimpleInputSelectorWidget.cxx
02d02775d7025e97d8180d9e65646c7eaac17dc2
[clitk.git] / vv / vvToolSimpleInputSelectorWidget.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 #ifndef VVTOOLINPUTSELECTORWIDGET_CXX
19 #define VVTOOLINPUTSELECTORWIDGET_CXX
20 #include "vvToolSimpleInputSelectorWidget.h"
21 #include "vvSlicerManager.h"
22 #include <QAbstractButton>
23
24 //------------------------------------------------------------------------------
25 vvToolSimpleInputSelectorWidget::vvToolSimpleInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
26   QWidget(parent, f) {
27   setupUi(this);  
28   setEnabled(true);
29   mSlicerManagerList.clear();
30 }
31 //------------------------------------------------------------------------------
32
33
34 //------------------------------------------------------------------------------
35 void vvToolSimpleInputSelectorWidget::Initialize() {
36   // Connect signals & slots  
37   connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
38   connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
39   connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));  
40   if (mSlicerManagerList.size() == 1) {
41     if (!mAllowSkip) accept();
42   }
43   if (mSlicerManagerList.size() == 0) {
44     reject();
45   }
46 }
47 //------------------------------------------------------------------------------
48
49
50 //------------------------------------------------------------------------------
51 void vvToolSimpleInputSelectorWidget::SetText(QString & s) {
52   mGroupBox->setTitle(s);
53 }
54 //------------------------------------------------------------------------------
55
56
57 //------------------------------------------------------------------------------
58 void vvToolSimpleInputSelectorWidget::EnableAllowSkip(bool b) {
59   mAllowSkip = b;
60   if (mAllowSkip) {
61     mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Discard);
62     connect(mInputSelectionButtonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(skip(QAbstractButton*)));
63   }
64   else 
65     mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
66 }
67 //------------------------------------------------------------------------------
68
69
70 //------------------------------------------------------------------------------
71 void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector<vvSlicerManager*> & l, int index) {
72   if (l.size() == 0) {
73     // TODO !!!
74     DD("no input > error message");
75     reject();
76   }
77   mInputSequenceBox->clear();
78   for(unsigned int i=0; i<l.size(); i++)
79     mSlicerManagerList.push_back(l[i]);
80   mCurrentIndex = index;
81   for (unsigned int i = 0; i < mSlicerManagerList.size(); i++) {
82     mInputSequenceBox->addItem(mSlicerManagerList[i]->GetFileName().c_str());
83   }
84   mInputSequenceBox->setCurrentIndex(mCurrentIndex);
85   changeInput(mCurrentIndex);
86 }
87 //------------------------------------------------------------------------------
88
89
90 //------------------------------------------------------------------------------
91 void vvToolSimpleInputSelectorWidget::setEnabled(bool b) {
92   QWidget::setEnabled(b);
93   mInputSelectionButtonBox->setEnabled(b);
94   mInputSequenceBox->setEnabled(b);
95 }
96 //------------------------------------------------------------------------------
97
98
99 //------------------------------------------------------------------------------
100 void vvToolSimpleInputSelectorWidget::accept() {
101   mInputSelectionButtonBox->setEnabled(false);
102   mInputSequenceBox->setEnabled(false);
103   emit accepted();
104 }
105 //------------------------------------------------------------------------------
106
107
108
109 //------------------------------------------------------------------------------
110 void vvToolSimpleInputSelectorWidget::reject() {
111   emit rejected();
112 }
113 //------------------------------------------------------------------------------
114
115
116 //------------------------------------------------------------------------------
117 void vvToolSimpleInputSelectorWidget::skip(QAbstractButton* b) {
118   if (b->text() == "Discard") emit sigskip();
119 }
120 //------------------------------------------------------------------------------
121
122
123 //------------------------------------------------------------------------------
124 void vvToolSimpleInputSelectorWidget::changeInput(int index) {
125   if (index<0) return;
126   mCurrentIndex = index;
127   vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
128   unsigned int d = mCurrentImage->GetNumberOfDimensions();
129   QString size;
130   QString spacing;
131   for(unsigned int i=0; i<d-1; i++) {
132     size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
133     size.append("x");
134     spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
135     spacing.append("x");
136   }
137   size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
138   spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
139   mLabelInputInfo->setText(QString("Image: %1D %2   %3    %4")
140                            .arg(d)
141                            .arg(mCurrentImage->GetScalarTypeAsString().c_str())
142                            .arg(size)
143                            .arg(spacing));
144 }
145 //------------------------------------------------------------------------------
146
147
148 //------------------------------------------------------------------------------
149 vvSlicerManager * vvToolSimpleInputSelectorWidget::GetSelectedInput() {
150   return mSlicerManagerList[GetSelectedInputIndex()];
151 }
152 //------------------------------------------------------------------------------
153
154 #endif
155