]> Creatis software - clitk.git/blob - vv/vvToolWidgetBase.cxx
- autotool
[clitk.git] / vv / vvToolWidgetBase.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolWidgetBase.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/03/01 15:38:09 $
7   Version:   $Revision: 1.2 $
8   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
9
10   Copyright (C) 2008
11   Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12   CREATIS-LRMN 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 #include "vvToolWidgetBase.h"
29 #include "vvMainWindowBase.h"
30 #include "vvSlicerManager.h"
31
32 //------------------------------------------------------------------------------
33 vvToolWidgetBase::vvToolWidgetBase(vvMainWindowBase * parent, Qt::WindowFlags f)
34   :QDialog(parent, f), 
35    Ui::vvToolWidgetBase() {
36
37   // Set Modality : dialog is not modal but stay always on top because
38   // parent is set at construction
39   mIsInitialized = false;
40   mFilter = 0;
41   mMainWindowBase = parent;
42   setModal(false);
43   setAttribute(Qt::WA_DeleteOnClose);
44   
45   // GUI Initialization
46   setupUi(this);
47
48   // Connect signals & slots  
49   connect(mMainWindowBase, SIGNAL(AnImageIsBeingClosed(vvSlicerManager*)), 
50           this, SLOT(AnImageIsBeingClosed(vvSlicerManager*)));
51   connect(mToolInputSelectionWidget, SIGNAL(accepted()), this, SLOT(InputIsSelected()));
52   connect(mToolInputSelectionWidget, SIGNAL(rejected()), this, SLOT(close()));
53   connect(buttonBox, SIGNAL(accepted()), this, SLOT(apply()));
54   connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
55
56   // Disable main widget while input image is not selected
57   mToolWidget->setEnabled(false);
58 }
59 //------------------------------------------------------------------------------
60
61
62 //------------------------------------------------------------------------------
63 vvToolWidgetBase::~vvToolWidgetBase() {
64   
65 }
66 //------------------------------------------------------------------------------
67
68
69 //------------------------------------------------------------------------------
70 void vvToolWidgetBase::show() {
71  if (!mIsInitialized) {
72    InitializeInputs();
73  }
74  QDialog::show();
75 }
76 //------------------------------------------------------------------------------
77
78
79 //------------------------------------------------------------------------------
80 bool vvToolWidgetBase::close() {
81   return QDialog::close();
82 }
83 //------------------------------------------------------------------------------
84
85
86 //------------------------------------------------------------------------------
87 void vvToolWidgetBase::AnImageIsBeingClosed(vvSlicerManager * m) {
88   if (m == mCurrentSlicerManager) {
89     close();
90   }
91 }
92 //------------------------------------------------------------------------------
93
94
95 //------------------------------------------------------------------------------
96 void vvToolWidgetBase::InitializeInputs() {
97   if (mFilter) {
98     int j=0;
99     mToolInputSelectionWidget->setToolTip(QString("%1").arg(mFilter->GetAvailableImageTypes().c_str()));
100     for(unsigned int i=0; i<mMainWindowBase->GetSlicerManagers().size(); i++) {
101       vvImage * s = mMainWindowBase->GetSlicerManagers()[i]->GetImage();
102       if (mFilter->CheckImageType(s->GetNumberOfDimensions(), 
103                                   s->GetNumberOfScalarComponents(), 
104                                   s->GetScalarTypeAsString())) {
105         mSlicerManagersCompatible.push_back(mMainWindowBase->GetSlicerManagers()[i]);
106         if ((int)i == mMainWindowBase->GetSlicerManagerCurrentIndex()) mCurrentCompatibleIndex = j;
107         j++;
108       }
109     }
110   }
111   else {
112     mSlicerManagersCompatible = mMainWindowBase->GetSlicerManagers();
113     mCurrentCompatibleIndex = mMainWindowBase->GetSlicerManagerCurrentIndex();
114   }
115   mToolInputSelectionWidget->Initialize(mSlicerManagersCompatible, 
116                                         mCurrentCompatibleIndex);
117   mIsInitialized = true;
118 }
119 //------------------------------------------------------------------------------
120
121
122 //------------------------------------------------------------------------------
123 void vvToolWidgetBase::InputIsSelected() {
124   // Common
125   int index = mToolInputSelectionWidget->GetSelectedInputIndex();
126   mCurrentSlicerManager = mSlicerManagersCompatible[index];
127   mCurrentImage = mCurrentSlicerManager->GetImage();
128   mToolWidget->setEnabled(true);
129   if (!mCurrentSlicerManager) close();
130   InputIsSelected(mCurrentSlicerManager);
131 }
132 //------------------------------------------------------------------------------
133