Salome HOME
refs #550: fix crash when myObject is NULL
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageOp.cxx
index a7f9e98c904944e390638bda0bec3a0b3a823cae..bf837ade79e883bcac198a7b6be658d5d2aa1fab 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
@@ -280,6 +276,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;
 }
 
@@ -511,6 +509,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;
 }
 
@@ -894,3 +909,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;
+}