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 ======================================================================-====*/
18 #ifndef VVTOOLINPUTSELECTORWIDGET_CXX
19 #define VVTOOLINPUTSELECTORWIDGET_CXX
20 #include "vvToolSimpleInputSelectorWidget.h"
21 #include "vvSlicerManager.h"
22 #include <QAbstractButton>
24 //------------------------------------------------------------------------------
25 vvToolSimpleInputSelectorWidget::vvToolSimpleInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
30 mSlicerManagerList.clear();
32 //------------------------------------------------------------------------------
35 //------------------------------------------------------------------------------
36 void vvToolSimpleInputSelectorWidget::Initialize()
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();
45 if (mSlicerManagerList.size() == 0) {
49 //------------------------------------------------------------------------------
52 //------------------------------------------------------------------------------
53 void vvToolSimpleInputSelectorWidget::SetText(QString & s)
55 mGroupBox->setTitle(s);
57 //------------------------------------------------------------------------------
60 //------------------------------------------------------------------------------
61 void vvToolSimpleInputSelectorWidget::EnableAllowSkip(bool b)
65 mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Discard);
66 connect(mInputSelectionButtonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(skip(QAbstractButton*)));
68 mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
70 //------------------------------------------------------------------------------
73 //------------------------------------------------------------------------------
74 void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector<vvSlicerManager*> & l, int index)
78 DD("no input > error message");
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());
88 mInputSequenceBox->setCurrentIndex(mCurrentIndex);
89 changeInput(mCurrentIndex);
91 //------------------------------------------------------------------------------
94 //------------------------------------------------------------------------------
95 void vvToolSimpleInputSelectorWidget::setEnabled(bool b)
97 QWidget::setEnabled(b);
98 mInputSelectionButtonBox->setEnabled(b);
99 mInputSequenceBox->setEnabled(b);
102 //------------------------------------------------------------------------------
105 //------------------------------------------------------------------------------
106 void vvToolSimpleInputSelectorWidget::accept()
108 mInputSelectionButtonBox->setEnabled(false);
109 mInputSequenceBox->setEnabled(false);
112 //------------------------------------------------------------------------------
116 //------------------------------------------------------------------------------
117 void vvToolSimpleInputSelectorWidget::reject()
121 //------------------------------------------------------------------------------
124 //------------------------------------------------------------------------------
125 void vvToolSimpleInputSelectorWidget::skip(QAbstractButton* b)
127 if (b->text() == "Discard") emit sigskip();
129 //------------------------------------------------------------------------------
132 //------------------------------------------------------------------------------
133 void vvToolSimpleInputSelectorWidget::changeInput(int index)
137 if (index>=(int)mSlicerManagerList.size()) return;
138 mCurrentIndex = index;
139 vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
140 if (mCurrentImage == NULL) return;
142 unsigned int d = mCurrentImage->GetNumberOfDimensions();
146 for(unsigned int i=0; i<d-1; i++) {
147 size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
149 spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
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")
156 .arg(mCurrentImage->GetScalarTypeAsString().c_str())
161 //------------------------------------------------------------------------------
164 //------------------------------------------------------------------------------
165 vvSlicerManager * vvToolSimpleInputSelectorWidget::GetSelectedInput()
167 return mSlicerManagerList[GetSelectedInputIndex()];
169 //------------------------------------------------------------------------------