]> Creatis software - clitk.git/blob - vv/vvToolInputSelectorWidget.cxx
- multiple inputs in vv
[clitk.git] / vv / vvToolInputSelectorWidget.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvToolInputSelectorWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/03/24 10:48:18 $
7   Version:   $Revision: 1.5 $
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 "vvToolInputSelectorWidget.h"
33 #include "vvSlicerManager.h"
34
35 //------------------------------------------------------------------------------
36 vvToolInputSelectorWidget::vvToolInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
37   QWidget(parent, f) {
38   setupUi(this);  
39   setEnabled(true);
40   mNumberOfAcceptedInputs = 0;
41 }
42 //------------------------------------------------------------------------------
43
44 //------------------------------------------------------------------------------
45 int vvToolInputSelectorWidget::GetNumberOfInput() {
46   return mListOfSimpleInputWidget.size();
47 }
48 //------------------------------------------------------------------------------
49
50
51 //------------------------------------------------------------------------------
52 void vvToolInputSelectorWidget::AddInputSelector(QString & s, 
53                                                  const std::vector<vvSlicerManager*> & l, 
54                                                  int index, 
55                                                  bool allowSkip) {
56   //  DD("ICICICICICICICIC AddInputSelector ADD layout");
57   //  DD(index);
58   //DD(l.size());
59   vvToolSimpleInputSelectorWidget * input = new vvToolSimpleInputSelectorWidget;
60   mListOfSimpleInputWidget.push_back(input);
61   mSkipInput.push_back(false);
62   
63   input->SetText(s);
64   input->EnableAllowSkip(allowSkip);
65
66   // copy list
67   std::vector<vvSlicerManager*> * ll = new std::vector<vvSlicerManager*>;
68   for(unsigned int i=0; i<l.size(); i++)
69     ll->push_back(l[i]);
70
71   // add
72   input->SetInputList(*ll, index);
73   input->setObjectName(QString::fromUtf8("TOTO"));
74   mVerticalLayout->addWidget(input);
75
76   // Enable or disable
77   if (GetNumberOfInput() == 1) input->setEnabled(true);
78   else input->setEnabled(false);
79   //DD(GetNumberOfInput());
80
81   // Connect signals & slots  
82   connect(input, SIGNAL(accepted()), this, SLOT(accept()));
83   connect(input, SIGNAL(rejected()), this, SLOT(reject()));  
84   connect(input, SIGNAL(sigskip()), this, SLOT(skip()));  
85 }
86 //------------------------------------------------------------------------------
87
88
89 //------------------------------------------------------------------------------
90 void vvToolInputSelectorWidget::Initialize() {
91   for(unsigned int i=0; i<mListOfSimpleInputWidget.size(); i++)
92     mListOfSimpleInputWidget[i]->Initialize();
93 }
94 //------------------------------------------------------------------------------
95
96
97 //------------------------------------------------------------------------------
98 void vvToolInputSelectorWidget::accept() {
99   //  DD("vvToolInputSelectorWidget::accept");
100   //DD(mNumberOfAcceptedInputs);
101   mNumberOfAcceptedInputs++;
102   if (mNumberOfAcceptedInputs == GetNumberOfInput()) {
103     setEnabled(false);
104     emit accepted();
105   }
106   else {
107     //DD("accepted");
108     //    for(unsigned int i=mNumberOfAcceptedInputs; i<mListOfSimpleInputWidget.size(); i++) {
109     //      mListOfSimpleInputWidget[i]->Initialize();
110     mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(true);
111     //}
112   }
113 }
114 //------------------------------------------------------------------------------
115
116
117 //------------------------------------------------------------------------------
118 void vvToolInputSelectorWidget::reject() {
119   //  DD("vvToolInputSelectorWidget::reject");
120   if (mNumberOfAcceptedInputs != 0)  {
121     //    for(unsigned int i=mNumberOfAcceptedInputs; i<mListOfSimpleInputWidget.size(); i++) {
122     //      mListOfSimpleInputWidget[i]->Initialize();
123     //    DD(mNumberOfAcceptedInputs);
124     mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(false);
125     mListOfSimpleInputWidget[mNumberOfAcceptedInputs-1]->setEnabled(true);
126     mNumberOfAcceptedInputs--;
127     //}
128   }
129   else {
130     emit rejected();
131   }
132 }
133 //------------------------------------------------------------------------------
134
135
136 //------------------------------------------------------------------------------
137 void vvToolInputSelectorWidget::skip() {
138   DD("SKIP");
139   mSkipInput[mNumberOfAcceptedInputs] = true;
140   accept();//mNumberOfAcceptedInputs++;
141 }
142 //------------------------------------------------------------------------------
143
144
145 //------------------------------------------------------------------------------
146 std::vector<vvSlicerManager*> & vvToolInputSelectorWidget::GetSelectedInputs() {
147   std::vector<vvSlicerManager*> * l = new std::vector<vvSlicerManager*>;
148   for(unsigned int i=0; i<mListOfSimpleInputWidget.size(); i++) {
149     if (!mSkipInput[i])
150       l->push_back(mListOfSimpleInputWidget[i]->GetSelectedInput());
151   }
152   return *l;
153 }
154 //------------------------------------------------------------------------------
155
156
157 //------------------------------------------------------------------------------
158 void vvToolInputSelectorWidget::AnImageIsBeingClosed(vvSlicerManager * m) {
159   //  DD("TODO : verify that the image still exist !!");
160   //  for(int i=0; i<
161 }
162 //------------------------------------------------------------------------------
163
164
165 #endif
166