]> Creatis software - clitk.git/blob - vv/vvToolInputSelectorWidget.cxx
0cb8c01f528a700e653d308f12e99da3a96aeacc
[clitk.git] / vv / vvToolInputSelectorWidget.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolInputSelectorWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/01/29 13:54:37 $
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 "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   DD("Initialize"); DD(index);
52   mInputSequenceBox->clear();
53   mSlicerManagerList = l;
54   mCurrentIndex = index;
55   for (unsigned int i = 0; i < mSlicerManagerList.size(); i++) {
56     mInputSequenceBox->addItem(mSlicerManagerList[i]->GetFileName().c_str());
57   }
58   mInputSequenceBox->setCurrentIndex(mCurrentIndex);
59   if (mSlicerManagerList.size() == 0) {
60     // TODO !!!
61     DD("no input > error message");
62     reject();
63   }
64   if (mSlicerManagerList.size() == 1) {
65     accept();
66   }
67 }
68 //------------------------------------------------------------------------------
69
70
71 //------------------------------------------------------------------------------
72 void vvToolInputSelectorWidget::SetToolTip(QString s) {
73   //  mLabelSelection->setToolTip(s);
74   //mInputSequenceBox->setToolTip(s);
75   setToolTip(s);
76 }
77 //------------------------------------------------------------------------------
78
79
80 //------------------------------------------------------------------------------
81 void vvToolInputSelectorWidget::accept() {
82   mInputSelectionButtonBox->setEnabled(false);
83   mInputSequenceBox->setEnabled(false);
84   emit accepted();
85 }
86 //------------------------------------------------------------------------------
87
88
89 //------------------------------------------------------------------------------
90 void vvToolInputSelectorWidget::reject() {
91   emit rejected();
92 }
93 //------------------------------------------------------------------------------
94
95
96 //------------------------------------------------------------------------------
97 void vvToolInputSelectorWidget::changeInput(int index) {
98   mCurrentIndex = index;
99   vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
100   unsigned int d = mCurrentImage->GetNumberOfDimensions();
101   QString size;
102   QString spacing;
103   for(unsigned int i=0; i<d-1; i++) {
104     size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
105     size.append("x");
106     spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
107     spacing.append("x");
108   }
109   size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
110   spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
111   mLabelInputInfo->setText(QString("Image: %1D %2   %3    %4")
112                            .arg(d)
113                            .arg(mCurrentImage->GetScalarTypeAsString().c_str())
114                            .arg(size)
115                            .arg(spacing));
116 }
117 //------------------------------------------------------------------------------
118
119 #endif
120