Salome HOME
HYDROGUI_Wizard has been refactored and now uses QStackedWidget instead of QWizard.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.cxx
index 4251a04c178ea74e9472c6ada1ba8523302792e6..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>
@@ -54,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 );
 
@@ -72,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 );
@@ -84,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" ) );
@@ -97,35 +98,36 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   aPainter.drawPixmap( 0, 0, anArrowPixmap );
   aPainter.end();
 
-  QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
-  QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), 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( aManualCartesianBtn, ManualCartesian );
-  myModeGroup->addButton( aManualLambertBtn, ManualLambert );
-  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( aManualCartesianBtn, 0, 0 );
-  aModeLayout->addWidget( aManualLambertBtn,   1, 0 );
+  aModeLayout->addWidget( aManualLambertBtn,   0, 0 );
+  aModeLayout->addWidget( aManualCartesianBtn, 1, 0 );
   aModeLayout->addWidget( aRefImageBtn,        2, 0 );
   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( "GEODESIC", myTransformGroup );
-  QLabel* aLambertLabel = new QLabel( "LAMBERT93", myTransformGroup );
-  QLabel* aRefImageLabel = new QLabel( "REFERENCE_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 );
@@ -301,16 +303,13 @@ 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 );
 }
 
 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
 {
-  delete myFileNameGroup;
-  delete myImageNameGroup;
-  delete myTransformGroup;
 }
 
 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
@@ -353,7 +352,7 @@ void HYDROGUI_ImportImageDlg::reset()
   myTransformGroup->setEnabled( false );
   myRefImage->clear();
 
-  setTransformationMode( ManualLambert );
+  setTransformationMode( HYDROData_Image::ManualLambert );
 
   myPrsPointDataList.clear();
 
@@ -370,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();
@@ -407,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 )
@@ -498,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
@@ -519,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()
@@ -586,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" ) );
@@ -605,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 );