]> Creatis software - clitk.git/blobdiff - vv/vvToolInputSelectorWidget.cxx
Better control to avoid segfault
[clitk.git] / vv / vvToolInputSelectorWidget.cxx
index 217b53be2340c3f615f00eab5ea07673dca06829..ca1ed293ec30b5a30b948e43b4d3d85bb7de4922 100644 (file)
 /*=========================================================================
+  Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Program:   vv
-  Module:    $RCSfile: vvToolInputSelectorWidget.cxx,v $
-  Language:  C++
-  Date:      $Date: 2010/02/24 11:42:42 $
-  Version:   $Revision: 1.2 $
-  Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
+  Authors belong to:
+  - University of LYON              http://www.universite-lyon.fr/
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
+  - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
-  Copyright (C) 2010
-  Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
-  CREATIS                   http://www.creatis.insa-lyon.fr
+  This software is distributed WITHOUT ANY WARRANTY; without even
+  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+  PURPOSE.  See the copyright notices for more information.
 
-  This program is free software: you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation, version 3 of the License.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-
-  =========================================================================*/
+  It is distributed under dual licence
 
+  - BSD        See included LICENSE.txt file
+  - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+===========================================================================**/
 #ifndef VVTOOLINPUTSELECTORWIDGET_CXX
 #define VVTOOLINPUTSELECTORWIDGET_CXX
 
+#include "vvToolSimpleInputSelectorWidget.h"
 #include "vvToolInputSelectorWidget.h"
 #include "vvSlicerManager.h"
 
 //------------------------------------------------------------------------------
 vvToolInputSelectorWidget::vvToolInputSelectorWidget(QWidget * parent, Qt::WindowFlags f):
-  QWidget(parent, f) {
-  setupUi(this);  
-
+  QWidget(parent, f)
+{
+  setupUi(this);
   setEnabled(true);
+  mNumberOfAcceptedInputs = 0;
+}
+//------------------------------------------------------------------------------
 
-  // Connect signals & slots  
-  connect(mInputSelectionButtonBox, SIGNAL(accepted()), this, SLOT(accept()));
-  connect(mInputSelectionButtonBox, SIGNAL(rejected()), this, SLOT(reject()));
-  connect(mInputSequenceBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeInput(int)));  
+//------------------------------------------------------------------------------
+int vvToolInputSelectorWidget::GetNumberOfInput()
+{
+  return mListOfSimpleInputWidget.size();
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolInputSelectorWidget::Initialize(std::vector<vvSlicerManager*> l, int index) {
-  mInputSequenceBox->clear();
-  mSlicerManagerList = l;
-  mCurrentIndex = index;
-  for (unsigned int i = 0; i < mSlicerManagerList.size(); i++) {
-    mInputSequenceBox->addItem(mSlicerManagerList[i]->GetFileName().c_str());
-  }
-  mInputSequenceBox->setCurrentIndex(mCurrentIndex);
-  if (mSlicerManagerList.size() == 0) {
-    // TODO !!!
-    DD("no input > error message");
-    reject();
-  }
-  if (mSlicerManagerList.size() == 1) {
-    accept();
-  }
+void vvToolInputSelectorWidget::AddInputSelector(QString & s,
+                                                const std::vector<vvSlicerManager*> & l,
+                                                int index,
+                                                bool allowSkip)
+{
+  // Create a input selector widget 
+  vvToolSimpleInputSelectorWidget * input = new vvToolSimpleInputSelectorWidget;
+  mListOfSimpleInputWidget.push_back(input);
+  mSkipInput.push_back(false);
+  input->SetText(s);
+  input->EnableAllowSkip(allowSkip);
+
+  // Copy the list of slicermanager
+  std::vector<vvSlicerManager*> * ll = new std::vector<vvSlicerManager*>;
+  for(unsigned int i=0; i<l.size(); i++)
+    ll->push_back(l[i]);
+
+  // Add
+  input->SetInputList(*ll, index);
+  mVerticalLayout->addWidget(input);
+
+  // Enable or disable
+  if (GetNumberOfInput() == 1) input->setEnabled(true);
+  else input->setEnabled(false);
+
+  // Connect signals & slots
+  connect(input, SIGNAL(accepted()), this, SLOT(accept()));
+  connect(input, SIGNAL(rejected()), this, SLOT(reject()));
+  connect(input, SIGNAL(sigskip()), this, SLOT(skip()));
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolInputSelectorWidget::SetToolTip(QString s) {
-  setToolTip(s);
+void vvToolInputSelectorWidget::Initialize()
+{
+  for(unsigned int i=0; i<mListOfSimpleInputWidget.size(); i++)
+    mListOfSimpleInputWidget[i]->Initialize();
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolInputSelectorWidget::accept() {
-  mInputSelectionButtonBox->setEnabled(false);
-  mInputSequenceBox->setEnabled(false);
-  emit accepted();
+void vvToolInputSelectorWidget::accept()
+{
+  mNumberOfAcceptedInputs++;
+  if (mNumberOfAcceptedInputs == GetNumberOfInput()) {
+    setEnabled(false);
+    emit accepted();
+  } else if (mNumberOfAcceptedInputs < GetNumberOfInput()) {
+    mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(true);
+  }
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolInputSelectorWidget::reject() {
-  emit rejected();
+void vvToolInputSelectorWidget::reject()
+{
+  if (mNumberOfAcceptedInputs != 0)  {
+    mListOfSimpleInputWidget[mNumberOfAcceptedInputs]->setEnabled(false);
+    mListOfSimpleInputWidget[mNumberOfAcceptedInputs-1]->setEnabled(true);
+    mNumberOfAcceptedInputs--;
+  } else {
+    emit rejected();
+  }
 }
 //------------------------------------------------------------------------------
 
 
 //------------------------------------------------------------------------------
-void vvToolInputSelectorWidget::changeInput(int index) {
-  mCurrentIndex = index;
-  vvImage * mCurrentImage = mSlicerManagerList[index]->GetImage();
-  unsigned int d = mCurrentImage->GetNumberOfDimensions();
-  QString size;
-  QString spacing;
-  for(unsigned int i=0; i<d-1; i++) {
-    size.append(QString("%1").arg(mCurrentImage->GetSize()[i]));
-    size.append("x");
-    spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[i]));
-    spacing.append("x");
+void vvToolInputSelectorWidget::skip()
+{
+  mSkipInput[mNumberOfAcceptedInputs] = true;
+  accept();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+std::vector<vvSlicerManager*> & vvToolInputSelectorWidget::GetSelectedInputs()
+{
+  std::vector<vvSlicerManager*> * l = new std::vector<vvSlicerManager*>;
+  for(unsigned int i=0; i<mListOfSimpleInputWidget.size(); i++) {
+    if (!mSkipInput[i])
+      l->push_back(mListOfSimpleInputWidget[i]->GetSelectedInput());
   }
-  size.append(QString("%1").arg(mCurrentImage->GetSize()[d-1]));
-  spacing.append(QString("%1").arg(mCurrentImage->GetSpacing()[d-1]));
-  mLabelInputInfo->setText(QString("Image: %1D %2   %3    %4")
-                           .arg(d)
-                           .arg(mCurrentImage->GetScalarTypeAsString().c_str())
-                           .arg(size)
-                           .arg(spacing));
+  return *l;
 }
 //------------------------------------------------------------------------------
 
+
+//------------------------------------------------------------------------------
+void vvToolInputSelectorWidget::AnImageIsBeingClosed(vvSlicerManager * m)
+{
+  //  DD("TODO : verify that the image still exist !!");
+  //  for(int i=0; i<
+}
+//------------------------------------------------------------------------------
+
+
 #endif