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