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://www.centreleonberard.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 ===========================================================================**/
18 #ifndef VVTOOLINPUTSELECTORWIDGET_CXX
19 #define VVTOOLINPUTSELECTORWIDGET_CXX
22 #include "vvToolSimpleInputSelectorWidget.h"
23 #include "vvSlicerManager.h"
26 #include <QAbstractButton>
28 //------------------------------------------------------------------------------
29 vvToolSimpleInputSelectorWidget::vvToolSimpleInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
34 mSlicerManagerList.clear();
36 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 void vvToolSimpleInputSelectorWidget::Initialize()
42 // Connect signals & slots
43 connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
44 connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
45 connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));
46 if (mSlicerManagerList.size() == 1) {
47 if (!mAllowSkip) accept();
49 if (mSlicerManagerList.size() == 0) {
53 //------------------------------------------------------------------------------
56 //------------------------------------------------------------------------------
57 void vvToolSimpleInputSelectorWidget::SetText(QString & s)
59 mGroupBox->setTitle(s);
61 //------------------------------------------------------------------------------
64 //------------------------------------------------------------------------------
65 void vvToolSimpleInputSelectorWidget::EnableAllowSkip(bool b)
69 mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Discard);
70 connect(mInputSelectionButtonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(skip(QAbstractButton*)));
72 mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
74 //------------------------------------------------------------------------------
77 //------------------------------------------------------------------------------
78 void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector<vvSlicerManager*> & l, int index)
82 DD("no input > error message");
85 mInputSequenceBox->clear();
86 for(unsigned int i=0; i<l.size(); i++)
87 mSlicerManagerList.push_back(l[i]);
88 mCurrentIndex = index;
89 for (unsigned int i = 0; i < mSlicerManagerList.size(); i++) {
90 mInputSequenceBox->addItem(mSlicerManagerList[i]->GetFileName().c_str());
92 mInputSequenceBox->setCurrentIndex(mCurrentIndex);
93 changeInput(mCurrentIndex);
95 //------------------------------------------------------------------------------
98 //------------------------------------------------------------------------------
99 void vvToolSimpleInputSelectorWidget::setEnabled(bool b)
101 QWidget::setEnabled(b);
102 mInputSelectionButtonBox->setEnabled(b);
103 mInputSequenceBox->setEnabled(b);
106 //------------------------------------------------------------------------------
109 //------------------------------------------------------------------------------
110 void vvToolSimpleInputSelectorWidget::accept()
112 mInputSelectionButtonBox->setEnabled(false);
113 mInputSequenceBox->setEnabled(false);
116 //------------------------------------------------------------------------------
120 //------------------------------------------------------------------------------
121 void vvToolSimpleInputSelectorWidget::reject()
125 //------------------------------------------------------------------------------
128 //------------------------------------------------------------------------------
129 void vvToolSimpleInputSelectorWidget::skip(QAbstractButton* b)
131 if (b->text() == "Discard") emit sigskip();
133 //------------------------------------------------------------------------------
136 //------------------------------------------------------------------------------
137 void vvToolSimpleInputSelectorWidget::changeInput(int index)
140 if (index>=(int)mSlicerManagerList.size()) return;
141 mCurrentIndex = index;
142 vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
143 if (mCurrentImage == NULL) return;
144 unsigned int d = mCurrentImage->GetNumberOfDimensions();
147 for(unsigned int i=0; i<d-1; i++) {
148 size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
150 spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
153 size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
154 spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
155 mLabelInputInfo->setText(QString("%1D %2\n%3\n%4")
157 .arg(mCurrentImage->GetScalarTypeAsITKString().c_str())
161 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165 vvSlicerManager * vvToolSimpleInputSelectorWidget::GetSelectedInput()
167 return mSlicerManagerList[GetSelectedInputIndex()];
169 //------------------------------------------------------------------------------