Salome HOME
refs #1461: draft patch for some simple acceleration
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageOp.cxx
index a7f9e98c904944e390638bda0bec3a0b3a823cae..eef9bd9a7a4dc810fff8fbc9e7962e50ea98dd41 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
@@ -27,7 +23,7 @@
 #include "HYDROGUI_ImportImageDlg.h"
 #include "HYDROGUI_Module.h"
 #include "HYDROGUI_PrsImage.h"
-#include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Tool2.h"
 #include "HYDROGUI_UpdateFlags.h"
 
 #include <HYDROData_Iterator.h>
@@ -89,7 +85,7 @@ void HYDROGUI_ImportImageOp::startOperation()
       myEditedObject->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
 
       // Create the edited image preview presentation in the viewer
-      onCreatePreview( anImage );
+      onCreatePreview( anImage, NULL ); //TODO
 
       // Set transformation local points A,B,C to the image preview presentation
       setPresentationTrsfPoints( myPreviewPrs, anIsByTwoPoints, aLocalPointA, 
@@ -272,7 +268,8 @@ void HYDROGUI_ImportImageOp::commitOperation()
 HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
 {
   HYDROGUI_InputPanel* aPanel = new HYDROGUI_ImportImageDlg( module(), getName() );
-  connect( aPanel, SIGNAL( createPreview( QImage ) ), SLOT( onCreatePreview( QImage ) ) );
+  connect( aPanel, SIGNAL( createPreview( QImage, HYDROData_Image::ECW_FileInfo* ) ), 
+    SLOT( onCreatePreview( QImage, HYDROData_Image::ECW_FileInfo* ) ) );
   connect( aPanel, SIGNAL( activatePointSelection( int ) ), SLOT( onActivatePointSelection( int ) ) );
   connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ), 
                      SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
@@ -280,6 +277,8 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
   connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
                      SLOT( onRefImageActivated( const QString& ) ) );
   connect( aPanel, SIGNAL( setCIsUsed( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
+  connect( aPanel, SIGNAL( filesSelected( const QStringList& ) ),
+                   SLOT( onFilesSelected( const QStringList& ) ) );
   return aPanel;
 }
 
@@ -352,9 +351,22 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
 {
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
 
+  if( !myIsEdit )
+  {
+    QString aFilePath = aPanel->getFileName();
+    if( aFilePath.isEmpty() )
+    {
+      theErrorMsg = tr( "SELECT_IMAGE_FILE" ).arg( aFilePath );
+      return false;
+    }
+  }
+
   QString anImageName = aPanel->getImageName();
   if( anImageName.isEmpty() )
+  {
+    theErrorMsg = tr( "SELECT_IMAGE_NAME" ).arg( anImageName );
     return false;
+  }
 
   if( !myIsEdit || ( !myEditedObject.IsNull() && myEditedObject->GetName() != anImageName ) )
   {
@@ -511,6 +523,23 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   if ( isApplyAndClose() )
     theUpdateFlags |= UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
 
+  if( isApplyAndClose() )
+  {
+    commitDocOperation(); // to save the modifications in the data model
+    return true;
+  }
+
+  if( SetNextFile() )
+  {
+    theErrorMsg = "";
+    module()->updateObjBrowser();
+    return false;         // and to continue the operation
+  }
+
+  /*if( myFiles.count() > 1 )
+  {
+    setIsApplyAndClose( true );
+  }*/
   return true;
 }
 
@@ -561,7 +590,7 @@ void HYDROGUI_ImportImageOp::apply()
   }
 }
 
-void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
+void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage, HYDROData_Image::ECW_FileInfo* theFileInfo )
 {
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
 
@@ -660,7 +689,10 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
 
   aPanel->setImageSize( myImage.size() );
 
-  aPanel->initializePointSelection();
+  if (!theFileInfo)
+    aPanel->initializePointSelection();
+  else
+     aPanel->ECW_initializePointSelection(theFileInfo);
   onPointSelected( false );
   onSetCIsUsed( !aPanel->isByTwoPoints() );
 }
@@ -894,3 +926,22 @@ void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
     aViewMgr = 0;
   }
 }
+
+void HYDROGUI_ImportImageOp::onFilesSelected( const QStringList& theFileNames )
+{
+  myFiles = theFileNames;
+  myFileIndex = -1;
+  SetNextFile();
+}
+
+bool HYDROGUI_ImportImageOp::SetNextFile()
+{
+  myFileIndex++;
+  bool isEnabledEdit = myFiles.count()==1 || myFileIndex==myFiles.count();
+  bool isValid = ( myFileIndex>=0 && myFileIndex<myFiles.count() );
+  QString aFile = isValid ? myFiles[myFileIndex] : "";
+
+  HYDROGUI_ImportImageDlg* aPanel = dynamic_cast<HYDROGUI_ImportImageDlg*>( inputPanel() );
+  aPanel->ActivateFile( aFile, isEnabledEdit );
+  return isValid;
+}