Salome HOME
HYDROGUI_Wizard has been refactored and now uses QStackedWidget instead of QWizard.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.cxx
index 795d099b6dba95c607b5443511bca09d128ff9a1..26f9b5ad693a1ca3621a1639613f3672d4c49037 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Lambert93.h>
+#include <HYDROData_Image.h>
 
 #include <SUIT_FileDlg.h>
 #include <SUIT_ResourceMgr.h>
@@ -45,6 +46,7 @@
 #include <QPushButton>
 #include <QRadioButton>
 #include <QToolButton>
+#include <QCheckBox>
 
 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
 : HYDROGUI_InputPanel( theModule, theTitle ),
@@ -53,7 +55,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
 
   // Import image from file
-  myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ) );
+  myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
 
   QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
 
@@ -71,7 +73,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   aFileNameLayout->addWidget( aBrowseBtn );
 
   // Image name
-  myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ) );
+  myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
 
   QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
   myImageName = new QLineEdit( myImageNameGroup );
@@ -83,7 +85,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   anImageNameLayout->addWidget( myImageName );
 
   // Transform image
-  myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ) );
+  myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
 
   // Make a pixmap for arrow
   QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
@@ -96,18 +98,22 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   aPainter.drawPixmap( 0, 0, anArrowPixmap );
   aPainter.end();
 
-  QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
-  QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
+  QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_GEODESIC" ), myTransformGroup );
+  QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup );
   QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
 
   myModeGroup = new QButtonGroup( myTransformGroup );
-  myModeGroup->addButton( aManualLambertBtn, ManualLambert );
-  myModeGroup->addButton( aManualCartesianBtn, ManualCartesian );
-  myModeGroup->addButton( aRefImageBtn, RefImage );
+  myModeGroup->addButton( aManualLambertBtn, HYDROData_Image::ManualLambert );
+  myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian );
+  myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage );
 
   myRefImage = new QComboBox( myTransformGroup );
 
-  QGridLayout* aModeLayout = new QGridLayout();
+  QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
+  aTransformLayout->setMargin( 5 );
+  aTransformLayout->setSpacing( 5 );
+
+  QGridLayout* aModeLayout = new QGridLayout( myTransformGroup );
   aModeLayout->setMargin( 0 );
   aModeLayout->setSpacing( 5 );
   aModeLayout->addWidget( aManualLambertBtn,   0, 0 );
@@ -116,11 +122,28 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   aModeLayout->addWidget( myRefImage,          2, 1 );
   aModeLayout->setColumnStretch( 1, 1 );
 
-  QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup );
-  aTransformLayout->setMargin( 5 );
-  aTransformLayout->setSpacing( 5 );
   aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 );
 
+  QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), myTransformGroup );
+  QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), myTransformGroup );
+  QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), myTransformGroup );
+  QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), myTransformGroup );
+
+  aTransformLayout->addWidget( aImageCSLabel,  2, 1 );
+  aTransformLayout->addWidget( aGeodesicLabel, 2, 3, 1, 6 );
+  aTransformLayout->addWidget( aLambertLabel,  2, 3, 1, 6 );
+  aTransformLayout->addWidget( aRefImageLabel, 2, 3, 1, 6 );
+
+  connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) );
+  connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
+  connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
+  connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) );
+  connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
+  connect( aManualLambertBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) );
+  connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setVisible ( bool ) ) );
+  connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) );
+  connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) );
+
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
   {
@@ -166,8 +189,17 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
     QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
 
-    int aRow = 4 * aPointType + 2;
-    aTransformLayout->addWidget( aPointBtn,        aRow,     0, 1, 9 );
+    int aRow = 4 * aPointType + 3;
+    if ( aPointType == HYDROGUI_PrsImage::PointC )
+    {
+      myPointCEnabler = new QCheckBox( myTransformGroup );
+      aTransformLayout->addWidget( myPointCEnabler, aRow,    0, 1, 2, Qt::AlignHCenter );
+      aTransformLayout->addWidget( aPointBtn,      aRow,     2, 1, 7 );
+    }
+    else
+    {
+      aTransformLayout->addWidget( aPointBtn,      aRow,     0, 1, 9 );
+    }
 
     aTransformLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
     aTransformLayout->addWidget( aPointX,          aRow + 1, 1 );
@@ -236,6 +268,22 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     connect( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
     connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
   }
+
+  // Connect checkbox enabling point C
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointBtnMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYDegMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYMinMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointXSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myPointYSecMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myCartPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
+
   aTransformLayout->setColumnStretch( 1, 1 ); // double
   aTransformLayout->setColumnStretch( 3, 1 ); // degrees
   aTransformLayout->setColumnStretch( 5, 1 ); // minutes
@@ -255,7 +303,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   connect( myRefImage, SIGNAL( activated( const QString& ) ),
            this, SLOT( onRefImageActivated( const QString& ) ) );
 
-  setTransformationMode( ManualLambert );
+  setTransformationMode( HYDROData_Image::ManualLambert );
 
   setMinimumWidth( 350 );
 }
@@ -299,10 +347,12 @@ void HYDROGUI_ImportImageDlg::reset()
     myCartPointXMap[ aPointType ]->clear();
     myCartPointYMap[ aPointType ]->clear();
   }
+  myPointCEnabler->setChecked( true );
+  myPointCEnabler->toggle();
   myTransformGroup->setEnabled( false );
   myRefImage->clear();
 
-  setTransformationMode( ManualCartesian );
+  setTransformationMode( HYDROData_Image::ManualLambert );
 
   myPrsPointDataList.clear();
 
@@ -319,6 +369,16 @@ QString HYDROGUI_ImportImageDlg::getImageName() const
   return myImageName->text();
 }
 
+void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
+{
+  myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
+}
+
+QString HYDROGUI_ImportImageDlg::getRefImageName() const
+{
+  return myRefImage->currentText();
+}
+
 QString HYDROGUI_ImportImageDlg::getFileName() const
 {
   return myFileName->text();
@@ -356,6 +416,16 @@ int HYDROGUI_ImportImageDlg::getTransformationMode() const
   return myModeGroup->checkedId();
 }
 
+void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
+{
+  myPointCEnabler->setChecked( !theIsByTwoPoints );
+}
+
+bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
+{
+  return !myPointCEnabler->isChecked();
+}
+
 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
                                                         const bool theIsOnlyInput,
                                                         const bool theIsRefImage )
@@ -447,18 +517,13 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t
   return true;
 }
 
-QString HYDROGUI_ImportImageDlg::getRefImageName() const
-{
-  return myRefImage->currentText();
-}
-
 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
 {
   myPrsPointDataList = theList;
 
   if( !myPrsPointDataList.isEmpty() )
   {
-    myModeGroup->button( RefImage )->setEnabled( true );
+    myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
 
     myRefImage->clear();
     myRefImage->addItem( "" ); // first empty item
@@ -468,7 +533,7 @@ void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theLi
       myRefImage->addItem( anIter.next().first );
   }
   else
-    myModeGroup->button( RefImage )->setEnabled( false );
+    myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
 }
 
 void HYDROGUI_ImportImageDlg::initializePointSelection()
@@ -535,6 +600,38 @@ void HYDROGUI_ImportImageDlg::initializePointSelection()
   blockSignalsCartesian( false );
 }
 
+HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
+  const int      theMode,
+  const QPoint&  theLocalPoint,
+  const QPointF& theGlobalPoint )
+{
+  TransformationData aResTrsfData;
+  aResTrsfData.ImagePoint = theLocalPoint;
+
+  double arx = theGlobalPoint.x();
+  double ary = theGlobalPoint.y();
+  if ( theMode == HYDROData_Image::ManualLambert )
+  {
+    // Lambert to Cartesian
+    double aXCart = 0, aYCart = 0;
+    HYDROData_Lambert93::toXY( arx, ary, aXCart, aYCart );
+
+    aResTrsfData.LambertPoint = theGlobalPoint;
+    aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
+  }
+  else if ( theMode == HYDROData_Image::ManualCartesian )
+  {
+    // Cartesian to Lambert
+    double aLonDeg = 0, aLatDeg = 0;
+    HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
+
+    aResTrsfData.CartesianPoint = theGlobalPoint;
+    aResTrsfData.LambertPoint = QPointF( aLonDeg, aLatDeg );
+  }
+
+  return aResTrsfData;
+}
+
 void HYDROGUI_ImportImageDlg::onBrowse()
 {
   QString aFilter( tr( "IMAGE_FILTER" ) );
@@ -554,9 +651,9 @@ void HYDROGUI_ImportImageDlg::onBrowse()
 
 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
 {
-  bool anIsManualLambert = theMode == ManualLambert;
-  bool anIsManualCartesian = theMode == ManualCartesian;
-  bool anIsRefImage = theMode == RefImage;
+  bool anIsManualLambert = theMode == HYDROData_Image::ManualLambert;
+  bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
+  bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
 
   myRefImage->setEnabled( anIsRefImage );