Salome HOME
refs #568: use ordered list view with selection synchronized with object browser...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.cxx
index e39985b3675e23eb1fcf61d8f7dfc1e561afd468..2a65913e0af635fdbfcb97f1b48283a3c3d2421e 100644 (file)
@@ -1,12 +1,8 @@
-// Copyright (C) 2007-2013  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
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -66,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 );
@@ -343,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 ) ) );
@@ -385,6 +381,9 @@ void HYDROGUI_ImportImageDlg::reset()
   myImageName->clear();
   myImageNameGroup->setEnabled( false );
   myGeoFileName->clear();
+  bool isPBlocked = blockSignalsPoints( true );
+  bool isGBlocked = blockSignalsGeodesic( true );
+  bool isCBlocked = blockSignalsCartesian( true );
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
   {
@@ -393,21 +392,24 @@ void HYDROGUI_ImportImageDlg::reset()
     aBtn->setChecked( false );
     aBtn->blockSignals( anIsBlocked );
 
-    myPointXMap[ aPointType ]->clear();
-    myPointYMap[ aPointType ]->clear();
-    myPointXDegMap[ aPointType ]->clear();
-    myPointYDegMap[ aPointType ]->clear();
-    myPointXMinMap[ aPointType ]->clear();
-    myPointYMinMap[ aPointType ]->clear();
-    myPointXSecMap[ aPointType ]->clear();
-    myPointYSecMap[ aPointType ]->clear();
+    clearSpins( myPointXMap[ aPointType ] );
+    clearSpins( myPointYMap[ aPointType ] );
+    clearSpins( myPointXDegMap[ aPointType ] );
+    clearSpins( myPointYDegMap[ aPointType ] );
+    clearSpins( myPointXMinMap[ aPointType ] );
+    clearSpins( myPointYMinMap[ aPointType ] );
+    clearSpins( myPointXSecMap[ aPointType ] );
+    clearSpins( myPointYSecMap[ aPointType ] );
 
-    myRefPointXMap[ aPointType ]->clear();
-    myRefPointYMap[ aPointType ]->clear();
+    clearSpins( myRefPointXMap[ aPointType ] );
+    clearSpins( myRefPointYMap[ aPointType ] );
 
-    myCartPointXMap[ aPointType ]->clear();
-    myCartPointYMap[ aPointType ]->clear();
+    clearSpins( myCartPointXMap[ aPointType ] );
+    clearSpins( myCartPointYMap[ aPointType ] );
   }
+  blockSignalsPoints( isPBlocked );
+  blockSignalsGeodesic( isGBlocked );
+  blockSignalsCartesian( isCBlocked );
   
   // Emulate turning off C point usage
   myPointCEnabler->blockSignals( true );
@@ -465,6 +467,13 @@ QString HYDROGUI_ImportImageDlg::getFileName() const
   return myFileName->text();
 }
 
+void HYDROGUI_ImportImageDlg::setFileName( const QString& theName )
+{
+  myFileName->setText( theName );
+  myImageNameGroup->setEnabled( true );
+  myTransformGroup->setEnabled( true );
+}
+
 QString HYDROGUI_ImportImageDlg::getGeoreferencementFileName() const
 {
   return myGeoFileName->text();
@@ -688,23 +697,30 @@ 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
     {
-      myFileName->setText( aFileName );
+      setFileName( theFileName );
+      setImageName( "" );
       emit createPreview( anImage );
-      myImageNameGroup->setEnabled( true );
-      myTransformGroup->setEnabled( true );
     }
   }
 }
@@ -908,26 +924,64 @@ void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
   blockSignalsGeodesic( false );
 }
 
-void HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
+void HYDROGUI_ImportImageDlg::clearSpins( QAbstractSpinBox* theSpin )
+{
+  if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
+  {
+    QtxIntSpinBox* aSpin = dynamic_cast<QtxIntSpinBox*>( theSpin );
+    aSpin->setValue( aSpin->minimum() );
+  }
+  else if ( dynamic_cast<QtxIntSpinBox*>( theSpin ) )
+  {
+    QtxDoubleSpinBox* aDblSpin = dynamic_cast<QtxDoubleSpinBox*>( theSpin );
+    aDblSpin->setValue( aDblSpin->minimum() );
+  }
+
+  theSpin->clear();
+}
+
+bool HYDROGUI_ImportImageDlg::blockSignalsPoints( const bool theState )
+{
+  bool isBlocked = false;
+  for( int aPointType = HYDROGUI_PrsImage::PointA;
+       aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+  {
+    isBlocked = 
+    myPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
+    myPointYMap[ aPointType ]->blockSignals( theState );
+
+    myRefPointXMap[ aPointType ]->blockSignals( theState );
+    myRefPointYMap[ aPointType ]->blockSignals( theState );
+  }
+  return isBlocked;
+}
+
+bool HYDROGUI_ImportImageDlg::blockSignalsGeodesic( const bool theState )
 {
+  bool isBlocked = false;
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
   {
-    myPointXDegMap[ aPointType ]->blockSignals( theState );
+    isBlocked = 
+    myPointXDegMap[ aPointType ]->blockSignals( theState ) || isBlocked;
     myPointXMinMap[ aPointType ]->blockSignals( theState );
     myPointXSecMap[ aPointType ]->blockSignals( theState );
     myPointYDegMap[ aPointType ]->blockSignals( theState );
     myPointYMinMap[ aPointType ]->blockSignals( theState );
     myPointYSecMap[ aPointType ]->blockSignals( theState );
   }
+  return isBlocked;
 }
 
-void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
+bool HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
 {
+  bool isBlocked = false;
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
   {
-    myCartPointXMap[ aPointType ]->blockSignals( theState );
+    isBlocked = 
+    myCartPointXMap[ aPointType ]->blockSignals( theState ) || isBlocked;
     myCartPointYMap[ aPointType ]->blockSignals( theState );
   }
+  return isBlocked;
 }