]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
refs #530: import of several images
authorasl <asl@opencascade.com>
Wed, 20 May 2015 10:34:34 +0000 (13:34 +0300)
committerasl <asl@opencascade.com>
Wed, 20 May 2015 10:34:34 +0000 (13:34 +0300)
src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx
src/HYDROGUI/HYDROGUI_ImportImageDlg.h
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/HYDROGUI_Operation.cxx

index 59c706eba98876ee1480fbece44c761c1bb8bd8d..2a65913e0af635fdbfcb97f1b48283a3c3d2421e 100644 (file)
@@ -62,15 +62,15 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   myFileName = new QLineEdit( myFileNameGroup );
   myFileName->setReadOnly( true );
 
-  QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
-  aBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
+  myBrowseBtn = new QToolButton( myFileNameGroup );
+  myBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) );
 
   QBoxLayout* aFileNameLayout = new QHBoxLayout( myFileNameGroup );
   aFileNameLayout->setMargin( 5 );
   aFileNameLayout->setSpacing( 5 );
   aFileNameLayout->addWidget( aFileNameLabel );
   aFileNameLayout->addWidget( myFileName );
-  aFileNameLayout->addWidget( aBrowseBtn );
+  aFileNameLayout->addWidget( myBrowseBtn );
 
   // Image name
   myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
@@ -339,7 +339,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   addWidget( myTransformGroup );
   addStretch();
 
-  connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+  connect( myBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
 
   connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
            this, SLOT( onModeActivated( int ) ) );
@@ -697,20 +697,29 @@ HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsf
 void HYDROGUI_ImportImageDlg::onBrowse()
 {
   QString aFilter( tr( "IMAGE_FILTER" ) );
-  QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
-  if( !aFileName.isEmpty() )
+  QStringList aFileNamesList = SUIT_FileDlg::getOpenFileNames( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
+  emit filesSelected( aFileNamesList );
+}
+
+void HYDROGUI_ImportImageDlg::ActivateFile( const QString& theFileName, bool isEnableFilesChoice )
+{
+  myFileName->setEnabled( isEnableFilesChoice );
+  myBrowseBtn->setEnabled( isEnableFilesChoice );
+
+  if( !theFileName.isEmpty() )
   {
-    QImage anImage( aFileName );
+    QImage anImage( theFileName );
     if( anImage.isNull() )
     {
       QString aTitle = QObject::tr( "INPUT_VALID_DATA" );
       QString aMessage = QObject::tr( "FILE_CAN_NOT_BE_IMPORTED" ).
-        arg( aFileName ).arg( QFileInfo( aFileName ).suffix() );
+        arg( theFileName ).arg( QFileInfo( theFileName ).suffix() );
       SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
     }
     else
     {
-      setFileName( aFileName );
+      setFileName( theFileName );
+      setImageName( "" );
       emit createPreview( anImage );
     }
   }
index 9072a3e2f5e58ee970b1136c55bcccfeeb07fea7..2adcb89592d532a9bb874e9e6b2da8494969c923 100644 (file)
@@ -39,6 +39,7 @@ class QCheckBox;
 class QtxDoubleSpinBox;
 class QtxIntSpinBox;
 class QAbstractSpinBox;
+class QToolButton;
 
 class HYDROGUI_ImportImageDlg : public HYDROGUI_InputPanel
 {
@@ -105,6 +106,8 @@ public:
 
   void                       initializePointSelection();
 
+  void                       ActivateFile( const QString& theFileName, bool isEnableFilesChoice );
+
 public:
 
   static TransformationData  ComputeTrsfData( const int      theMode,
@@ -142,10 +145,12 @@ signals:
   void                       modeActivated( int );
   void                       refImageActivated( const QString& );
   void                       setCIsUsed( bool theIsByTwoPoints );
+  void                       filesSelected( const QStringList& );
 
 private:
   QGroupBox*                   myFileNameGroup;    //!< The group for the source image file selection
   QLineEdit*                   myFileName;         //!< Source image file name input field
+  QToolButton*                 myBrowseBtn;
 
   QGroupBox*                   myImageNameGroup;   //!< The group for the image name input field
   QLineEdit*                   myImageName;        //!< The image name input field
index b0cda46b7ed5ded76e3541e67a04096d35d74443..6d661e9a59191a78da913ef19e6759224277d71d 100644 (file)
@@ -274,6 +274,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;
 }
 
@@ -501,6 +503,14 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   anImageObj->Update();
 
   theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
+
+  if( SetNextFile() )
+  {
+    theErrorMsg = "";
+    commitDocOperation(); // to save the modifications in the data model
+    return false;         // and to continue the operation
+  }
+
   return true;
 }
 
@@ -881,3 +891,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;
+}
index 6ab54d217b1827d91f9eb68ac7bda3c56ec68945..f59c3725658dd30b36d0898d82eb64a5f008a7a7 100644 (file)
@@ -64,6 +64,7 @@ protected slots:
   void                       onPointSelected();
   void                       onRefPointSelected();
   void                       onPointSelected( bool theIsRefImage );
+  void                       onFilesSelected( const QStringList& );
 
 private:
   void                       closePreview();
@@ -106,6 +107,8 @@ private:
   void                       getReferenceDataList(
                                  HYDROGUI_ImportImageDlg::PrsPointDataList& theList ) const;
 
+  bool SetNextFile();
+
 private:
   bool                       myIsEdit;
   Handle(HYDROData_Image)    myEditedObject;
@@ -120,6 +123,8 @@ private:
   QImage                     myImage;              //!< The loaded image to import
 
   int                        myPointType;
+  QStringList                myFiles;
+  int                        myFileIndex;
 };
 
 #endif
index b01e44949da11a4cba518a5ddb9088f8ee908402..75d9c7b3f9c667033da662fe9482e2930a4b70c3 100644 (file)
@@ -313,7 +313,7 @@ void HYDROGUI_Operation::onApply()
     commit();
     browseObjects( aBrowseObjectsEntries );
   }
-  else
+  else if( !anErrorMsg.isEmpty() )
   {
     // Abort document opeartion only if requested
     if ( isToAbortOnApply() )