]> Creatis software - clitk.git/blob - vv/vvToolSimpleInputSelectorWidget.cxx
- multiple inputs in vv
[clitk.git] / vv / vvToolSimpleInputSelectorWidget.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolSimpleInputSelectorWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/03/24 10:48:18 $
7   Version:   $Revision: 1.2 $
8   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
9
10   Copyright (C) 2010
11   Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12   CREATIS                   http://www.creatis.insa-lyon.fr
13
14   This program is free software: you can redistribute it and/or modify
15   it under the terms of the GNU General Public License as published by
16   the Free Software Foundation, version 3 of the License.
17
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26   =========================================================================*/
27
28 #ifndef VVTOOLINPUTSELECTORWIDGET_CXX
29 #define VVTOOLINPUTSELECTORWIDGET_CXX
30
31 #include "vvToolSimpleInputSelectorWidget.h"
32 #include "vvSlicerManager.h"
33 #include <QAbstractButton>
34
35 //------------------------------------------------------------------------------
36 vvToolSimpleInputSelectorWidget::vvToolSimpleInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
37   QWidget(parent, f) {
38   setupUi(this);  
39   setEnabled(true);
40   mSlicerManagerList.clear();
41 }
42 //------------------------------------------------------------------------------
43
44
45 //------------------------------------------------------------------------------
46 void vvToolSimpleInputSelectorWidget::Initialize() {
47   // Connect signals & slots  
48   connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
49   connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
50   connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));  
51   changeInput(0);
52   if (mSlicerManagerList.size() == 1) {
53     if (!mAllowSkip) accept();
54   }
55 }
56 //------------------------------------------------------------------------------
57
58
59 //------------------------------------------------------------------------------
60 void vvToolSimpleInputSelectorWidget::SetText(QString & s) {
61   mGroupBox->setTitle(s);
62 }
63 //------------------------------------------------------------------------------
64
65
66 //------------------------------------------------------------------------------
67 void vvToolSimpleInputSelectorWidget::EnableAllowSkip(bool b) {
68   mAllowSkip = b;
69   if (mAllowSkip) {
70     mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Discard);
71     connect(mInputSelectionButtonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(skip(QAbstractButton*)));
72   }
73   else 
74     mInputSelectionButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
75 }
76 //------------------------------------------------------------------------------
77
78
79 //------------------------------------------------------------------------------
80 void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector<vvSlicerManager*> & l, int index) {
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   if (mSlicerManagerList.size() == 0) {
90     // TODO !!!
91     DD("no input > error message");
92     reject();
93   }
94 }
95 //------------------------------------------------------------------------------
96
97
98 //------------------------------------------------------------------------------
99 void vvToolSimpleInputSelectorWidget::setEnabled(bool b) {
100   QWidget::setEnabled(b);
101   mInputSelectionButtonBox->setEnabled(b);
102   mInputSequenceBox->setEnabled(b);
103 }
104 //------------------------------------------------------------------------------
105
106
107 //------------------------------------------------------------------------------
108 void vvToolSimpleInputSelectorWidget::accept() {
109   mInputSelectionButtonBox->setEnabled(false);
110   mInputSequenceBox->setEnabled(false);
111   emit accepted();
112 }
113 //------------------------------------------------------------------------------
114
115
116
117 //------------------------------------------------------------------------------
118 void vvToolSimpleInputSelectorWidget::reject() {
119   emit rejected();
120 }
121 //------------------------------------------------------------------------------
122
123
124 //------------------------------------------------------------------------------
125 void vvToolSimpleInputSelectorWidget::skip(QAbstractButton* b) {
126   if (b->text() == "Discard") emit sigskip();
127 }
128 //------------------------------------------------------------------------------
129
130
131 //------------------------------------------------------------------------------
132 void vvToolSimpleInputSelectorWidget::changeInput(int index) {
133   if (index<0) return;
134   mCurrentIndex = index;
135   vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
136   unsigned int d = mCurrentImage->GetNumberOfDimensions();
137   QString size;
138   QString spacing;
139   for(unsigned int i=0; i<d-1; i++) {
140     size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
141     size.append("x");
142     spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
143     spacing.append("x");
144   }
145   size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
146   spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
147   mLabelInputInfo->setText(QString("Image: %1D %2   %3    %4")
148                            .arg(d)
149                            .arg(mCurrentImage->GetScalarTypeAsString().c_str())
150                            .arg(size)
151                            .arg(spacing));
152 }
153 //------------------------------------------------------------------------------
154
155
156 //------------------------------------------------------------------------------
157 vvSlicerManager * vvToolSimpleInputSelectorWidget::GetSelectedInput() {
158   return mSlicerManagerList[GetSelectedInputIndex()];
159 }
160 //------------------------------------------------------------------------------
161
162 #endif
163