]> Creatis software - clitk.git/blob - vv/vvToolSimpleInputSelectorWidget.cxx
- new multiple input selector
[clitk.git] / vv / vvToolSimpleInputSelectorWidget.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolSimpleInputSelectorWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/03/17 11:23:46 $
7   Version:   $Revision: 1.1 $
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
34 //------------------------------------------------------------------------------
35 vvToolSimpleInputSelectorWidget::vvToolSimpleInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
36   QWidget(parent, f) {
37   setupUi(this);  
38   setEnabled(true);
39   mSlicerManagerList.clear();
40 }
41 //------------------------------------------------------------------------------
42
43
44 //------------------------------------------------------------------------------
45 void vvToolSimpleInputSelectorWidget::Initialize() {
46   // Connect signals & slots  
47   connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
48   connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
49   connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));  
50   DD("vvToolSimpleInputSelectorWidget::Initialize");
51   DD(mSlicerManagerList.size());
52   if (mSlicerManagerList.size() == 1) {
53     DD("Initialize::accept");
54     accept();
55   }
56 }
57 //------------------------------------------------------------------------------
58
59
60 //------------------------------------------------------------------------------
61 void vvToolSimpleInputSelectorWidget::SetInputList(const std::vector<vvSlicerManager*> & l, int index) {
62   DD("vvToolSimpleInputSelectorWidget::SetInputList");
63   DD(index);
64   mInputSequenceBox->clear();
65   for(unsigned int i=0; i<l.size(); i++)
66     mSlicerManagerList.push_back(l[i]);
67   mCurrentIndex = index;
68   for (unsigned int i = 0; i < mSlicerManagerList.size(); i++) {
69     mInputSequenceBox->addItem(mSlicerManagerList[i]->GetFileName().c_str());
70   }
71   mInputSequenceBox->setCurrentIndex(mCurrentIndex);
72   if (mSlicerManagerList.size() == 0) {
73     // TODO !!!
74     DD("no input > error message");
75     reject();
76   }
77 }
78 //------------------------------------------------------------------------------
79
80
81 //------------------------------------------------------------------------------
82 void vvToolSimpleInputSelectorWidget::setEnabled(bool b) {
83   QWidget::setEnabled(b);
84   mInputSelectionButtonBox->setEnabled(b);
85   mInputSequenceBox->setEnabled(b);
86 }
87 //------------------------------------------------------------------------------
88
89
90 //------------------------------------------------------------------------------
91 void vvToolSimpleInputSelectorWidget::accept() {
92   mInputSelectionButtonBox->setEnabled(false);
93   mInputSequenceBox->setEnabled(false);
94   emit accepted();
95 }
96 //------------------------------------------------------------------------------
97
98
99 //------------------------------------------------------------------------------
100 void vvToolSimpleInputSelectorWidget::reject() {
101   DD("vvToolSimpleInputSelectorWidget::reject()");
102   emit rejected();
103 }
104 //------------------------------------------------------------------------------
105
106
107 //------------------------------------------------------------------------------
108 void vvToolSimpleInputSelectorWidget::changeInput(int index) {
109   DD("changeInput");
110   DD(index);
111   if (index<0) return;
112   mCurrentIndex = index;
113   vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
114   unsigned int d = mCurrentImage->GetNumberOfDimensions();
115   QString size;
116   QString spacing;
117   for(unsigned int i=0; i<d-1; i++) {
118     size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
119     size.append("x");
120     spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
121     spacing.append("x");
122   }
123   size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
124   spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
125   mLabelInputInfo->setText(QString("Image: %1D %2   %3    %4")
126                            .arg(d)
127                            .arg(mCurrentImage->GetScalarTypeAsString().c_str())
128                            .arg(size)
129                            .arg(spacing));
130 }
131 //------------------------------------------------------------------------------
132
133
134 //------------------------------------------------------------------------------
135 vvSlicerManager * vvToolSimpleInputSelectorWidget::GetSelectedInput() {
136   return mSlicerManagerList[GetSelectedInputIndex()];
137 }
138 //------------------------------------------------------------------------------
139
140 #endif
141