]> Creatis software - clitk.git/blob - vv/vvToolInputSelectorWidget.cxx
- toolbase
[clitk.git] / vv / vvToolInputSelectorWidget.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolInputSelectorWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/02/24 11:42:42 $
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 "vvToolInputSelectorWidget.h"
32 #include "vvSlicerManager.h"
33
34 //------------------------------------------------------------------------------
35 vvToolInputSelectorWidget::vvToolInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
36   QWidget(parent, f) {
37   setupUi(this);  
38
39   setEnabled(true);
40
41   // Connect signals & slots  
42   connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
43   connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
44   connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));  
45 }
46 //------------------------------------------------------------------------------
47
48
49 //------------------------------------------------------------------------------
50 void vvToolInputSelectorWidget::Initialize(std::vector<vvSlicerManager*> l, int index) {
51   mInputSequenceBox->clear();
52   mSlicerManagerList = l;
53   mCurrentIndex = index;
54   for (unsigned int i = 0; i < mSlicerManagerList.size(); i++) {
55     mInputSequenceBox->addItem(mSlicerManagerList[i]->GetFileName().c_str());
56   }
57   mInputSequenceBox->setCurrentIndex(mCurrentIndex);
58   if (mSlicerManagerList.size() == 0) {
59     // TODO !!!
60     DD("no input > error message");
61     reject();
62   }
63   if (mSlicerManagerList.size() == 1) {
64     accept();
65   }
66 }
67 //------------------------------------------------------------------------------
68
69
70 //------------------------------------------------------------------------------
71 void vvToolInputSelectorWidget::SetToolTip(QString s) {
72   setToolTip(s);
73 }
74 //------------------------------------------------------------------------------
75
76
77 //------------------------------------------------------------------------------
78 void vvToolInputSelectorWidget::accept() {
79   mInputSelectionButtonBox->setEnabled(false);
80   mInputSequenceBox->setEnabled(false);
81   emit accepted();
82 }
83 //------------------------------------------------------------------------------
84
85
86 //------------------------------------------------------------------------------
87 void vvToolInputSelectorWidget::reject() {
88   emit rejected();
89 }
90 //------------------------------------------------------------------------------
91
92
93 //------------------------------------------------------------------------------
94 void vvToolInputSelectorWidget::changeInput(int index) {
95   mCurrentIndex = index;
96   vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
97   unsigned int d = mCurrentImage->GetNumberOfDimensions();
98   QString size;
99   QString spacing;
100   for(unsigned int i=0; i<d-1; i++) {
101     size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
102     size.append("x");
103     spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
104     spacing.append("x");
105   }
106   size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
107   spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
108   mLabelInputInfo->setText(QString("Image: %1D %2   %3    %4")
109                            .arg(d)
110                            .arg(mCurrentImage->GetScalarTypeAsString().c_str())
111                            .arg(size)
112                            .arg(spacing));
113 }
114 //------------------------------------------------------------------------------
115
116 #endif
117