]> Creatis software - clitk.git/blobdiff - vv/vvMainWindow.cxx
Corrected tab key bugs for one image and reverse order with shift
[clitk.git] / vv / vvMainWindow.cxx
index 1c2230f57160a8aa43e904f4e40734ed6233211a..6bd2d79731ca7b34b13b27dddc19738397d98aea 100644 (file)
@@ -45,6 +45,8 @@
 #include "vvMesh.h"
 #include "vvStructSelector.h"
 #include "vvMeshReader.h"
+#include "vvSaveState.h"
+#include "vvReadState.h"
 #include "clitkConfiguration.h"
 
 // ITK include
@@ -144,6 +146,16 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   connect(actionSave_image,SIGNAL(triggered()),this,SLOT(SaveAs()));
   contextActions.push_back(actionSave_image);
 
+  QAction* actionSave_state = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
+                              tr("Save Current State"));
+  connect(actionSave_state,SIGNAL(triggered()),this,SLOT(SaveCurrentState()));
+  contextActions.push_back(actionSave_state);
+
+  QAction* actionRead_state = contextMenu.addAction(QIcon(QString::fromUtf8(":/common/icons/filesave.png")),
+                              tr("Read Saved State"));
+  connect(actionRead_state,SIGNAL(triggered()),this,SLOT(ReadSavedState()));
+  contextActions.push_back(actionRead_state);
+
   contextMenu.addSeparator();
 
   contextMenu.addAction(actionAdd_VF_to_current_Image);
@@ -255,6 +267,8 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   connect(actionOpen_Image_With_Time,SIGNAL(triggered()),this,SLOT(OpenImageWithTime()));
   connect(actionMerge_images_as_n_dim_t, SIGNAL(triggered()), this, SLOT(MergeImagesWithTime()));
   connect(actionSave_As,SIGNAL(triggered()),this,SLOT(SaveAs()));
+  connect(actionSave_current_state,SIGNAL(triggered()),this,SLOT(SaveCurrentState()));
+  connect(actionRead_saved_state,SIGNAL(triggered()),this,SLOT(ReadSavedState()));
   connect(actionExit,SIGNAL(triggered()),this,SLOT(close()));
   connect(actionAdd_VF_to_current_Image,SIGNAL(triggered()),this,SLOT(OpenField()));
   connect(actionNavigation_Help,SIGNAL(triggered()),this,SLOT(ShowHelpDialog()));
@@ -275,6 +289,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
   connect(actionNorth_West_Window,SIGNAL(triggered()),this,SLOT(SaveNOScreenshot()));
   connect(actionSouth_East_Window,SIGNAL(triggered()),this,SLOT(SaveSEScreenshot()));
   connect(actionSouth_West_Window,SIGNAL(triggered()),this,SLOT(SaveSOScreenshot()));
+  connect(actionSave_all_slices,SIGNAL(triggered()),this,SLOT(SaveScreenshotAllSlices()));
 
   connect(DataTree,SIGNAL(itemSelectionChanged()),this,SLOT(ImageInfoChanged()));
   connect(DataTree,SIGNAL(itemClicked(QTreeWidgetItem*, int)),this,
@@ -291,6 +306,7 @@ vvMainWindow::vvMainWindow():vvMainWindowBase()
 
   connect(this,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(ShowContextMenu(QPoint)));
 
+#include "vvSaveState.h"
   connect(linkPanel,SIGNAL(addLink(QString,QString)),this,SLOT(AddLink(QString,QString)));
   connect(linkPanel,SIGNAL(removeLink(QString,QString)),this,SLOT(RemoveLink(QString,QString)));
   connect(overlayPanel,SIGNAL(VFPropertyUpdated(int,int,int,int,double,double,double)),this,SLOT(SetVFProperty(int,int,int,int,double,double,double)));
@@ -2200,6 +2216,7 @@ void vvMainWindow::SaveAs()
   OutputListeFormat.clear();
   if (dimension == 1) {
     OutputListeFormat.push_back(".mhd");
+    OutputListeFormat.push_back(".mha");
   }
   if (dimension == 2) {
     OutputListeFormat.push_back(".bmp");
@@ -2261,6 +2278,54 @@ void vvMainWindow::SaveAs()
 }
 //------------------------------------------------------------------------------
 
+//------------------------------------------------------------------------------
+void vvMainWindow::SaveCurrentState()
+{
+  QString Extensions = "XML Files(*.xml)";
+  QString fileName = QFileDialog::getSaveFileName(this,
+                     tr("Save Current Window State"),
+                     "",
+                     Extensions);
+                     
+  SaveCurrentStateAs(fileName.toStdString());
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvMainWindow::SaveCurrentStateAs(const std::string& stateFile)
+{
+  vvSaveState save_state;
+  save_state.Run(this, stateFile);
+  
+  std::cout << "void vvMainWindow::SaveCurrentState()" << std::endl;
+}
+
+//------------------------------------------------------------------------------
+void vvMainWindow::ReadSavedState()
+{
+  QString Extensions = "XML Files(*.xml)";
+  QString fileName = QFileDialog::getOpenFileName(this,
+                     tr("Load Window State"),
+                     "",
+                     Extensions);
+                     
+  ReadSavedStateFile(fileName.toStdString());
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvMainWindow::ReadSavedStateFile(const std::string& stateFile)
+{
+  vvReadState read_state;
+  read_state.Run(this, stateFile);
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+void vvMainWindow::LinkAllImages()
+{
+       linkPanel->linkAll();
+}
 
 //------------------------------------------------------------------------------
 void vvMainWindow::AddLink(QString image1,QString image2)
@@ -2307,10 +2372,13 @@ void vvMainWindow::RemoveLink(QString image1,QString image2)
 //------------------------------------------------------------------------------
 void vvMainWindow::ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset)
 {
+  if(mSlicerManagers.size()==1)
+    return;
+
   int index = 0;
   while(sm != mSlicerManagers[index])
     index++;
-  index = (index+offset) % mSlicerManagers.size();
+  index = (index+offset+mSlicerManagers.size()) % mSlicerManagers.size();
 
   QTreeWidgetItem* item = GetItemFromSlicerManager(mSlicerManagers[index]);
   item->setData(slicer+1,Qt::CheckStateRole,2);         //change checkbox
@@ -2572,6 +2640,56 @@ void vvMainWindow::SaveSEScreenshot()
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvMainWindow::SaveScreenshotAllSlices()
+{
+  QVTKWidget *widget = NOViewWidget;
+
+  int index = 0;// GetSlicerIndexFromItem(DataTree->selectedItems()[0]);
+  vvSlicerManager * SM = mSlicerManagers[index];
+  vvImage * image = SM->GetImage();
+  vvSlicer * slicer = SM->GetSlicer(0);
+  int orientation = slicer->GetOrientation();
+  int nbSlices = image->GetSize()[orientation];
+  vtkSmartPointer<vtkRenderWindow>  renderWindow = widget->GetRenderWindow();
+
+  // Select filename base
+  QString filename = QFileDialog::getSaveFileName(this,
+                                                  tr("Save As (filename will be completed by slice number)"),
+                                                  itksys::SystemTools::GetFilenamePath(mSlicerManagers[index]->GetFileName()).c_str(),
+                                                  "Images( *.png);;Images( *.jpg)");
+
+  // Loop on slices
+  for(int i=0; i<nbSlices; i++) {
+    // Change the slice
+    slicer->SetSlice(i); // -> change the slice of the current slicer
+    SM->UpdateSlice(0); // --> this one emit UpdateSlice
+    QCoreApplication::flush(); // -> needed to force display of contours 
+
+    // Screenshot  
+    vtkSmartPointer<vtkWindowToImageFilter> windowToImageFilter = vtkSmartPointer<vtkWindowToImageFilter>::New();
+    windowToImageFilter->SetInput(renderWindow);
+    windowToImageFilter->SetMagnification(1);
+    windowToImageFilter->SetInputBufferTypeToRGBA(); //also record the alpha (transparency) channel
+    windowToImageFilter->Update();
+    
+    vtkSmartPointer<vtkPNGWriter> writer = vtkSmartPointer<vtkPNGWriter>::New();
+    std::string fn = itksys::SystemTools::GetFilenameWithoutLastExtension(filename.toStdString());
+    std::string num = clitk::toString(i);
+    if (i<10) num = "0"+num;
+    if (i<100) num = "0"+num;
+    if (i<1000) num = "0"+num;
+
+    fn = itksys::SystemTools::GetFilenamePath(filename.toStdString()) + "/"+ fn 
+      + "_" + num + itksys::SystemTools::GetFilenameLastExtension(filename.toStdString());
+    writer->SetFileName(fn.c_str());
+    writer->SetInput(windowToImageFilter->GetOutput());
+    writer->Write();
+  }
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvMainWindow::SaveScreenshot(QVTKWidget *widget)
 {