Salome HOME
Fix for the bug #255: VTK viewer is not updated after modification of objects.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageDlg.cxx
index c31cbdb62671fcbd17d8ceac1ad803288de48add..0b63f5f45c84d6b108c42d302c1bb0eafab47c62 100644 (file)
 
 #include "HYDROGUI_PrsImage.h"
 #include "HYDROGUI_Tool.h"
+#include "HYDROGUI_Module.h"
 
 #include <HYDROData_Lambert93.h>
 #include <HYDROData_Image.h>
 
+#include <LightApp_Application.h>
 #include <SUIT_FileDlg.h>
 #include <SUIT_ResourceMgr.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
 #include <SUIT_Session.h>
 
 #include <QtxDoubleSpinBox.h>
@@ -172,12 +176,15 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     QLabel* aPointYMinLabel = new QLabel( "'", myTransformGroup );
     QLabel* aPointXSecLabel = new QLabel( "\"", myTransformGroup );
     QLabel* aPointYSecLabel = new QLabel( "\"", myTransformGroup );
+    QLabel* aPointLatLabel = new QLabel( tr( "POINT_LATITUDE" ), myTransformGroup );
+    QLabel* aPointLonLabel = new QLabel( tr( "POINT_LONGITUDE" ), myTransformGroup );
     myGeodesicLabels << aPointXDegLabel << aPointYDegLabel
                     << aPointXMinLabel << aPointYMinLabel
-                    << aPointXSecLabel << aPointYSecLabel;
+                    << aPointXSecLabel << aPointYSecLabel
+                    << aPointLonLabel << aPointLatLabel;
 
-    QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( 0, 360, 1, myTransformGroup );
-    QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 180, 1, myTransformGroup );
+    QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -179, 179, 1, myTransformGroup );
+    QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 89, 1, myTransformGroup );
     QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
     QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, myTransformGroup );
     QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup );
@@ -194,11 +201,11 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     {
       myPointCEnabler = new QCheckBox( myTransformGroup );
       aTransformLayout->addWidget( myPointCEnabler, aRow,    0, 1, 2, Qt::AlignHCenter );
-      aTransformLayout->addWidget( aPointBtn,      aRow,     2, 1, 7 );
+      aTransformLayout->addWidget( aPointBtn,      aRow,     2, 1, 8 );
     }
     else
     {
-      aTransformLayout->addWidget( aPointBtn,      aRow,     0, 1, 9 );
+      aTransformLayout->addWidget( aPointBtn,      aRow,     0, 1, 10 );
     }
 
     aTransformLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
@@ -210,6 +217,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     aTransformLayout->addWidget( aPointXMinLabel,  aRow + 1, 6 );
     aTransformLayout->addWidget( aPointXSec,       aRow + 1, 7 );
     aTransformLayout->addWidget( aPointXSecLabel,  aRow + 1, 8 );
+    aTransformLayout->addWidget( aPointLonLabel,   aRow + 1, 9 );
 
     aTransformLayout->addWidget( aCartPointX,      aRow + 1, 3, 1, 6 );
     aTransformLayout->addWidget( aRefPointX,       aRow + 1, 3, 1, 6 );
@@ -222,6 +230,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     aTransformLayout->addWidget( aPointYMinLabel,  aRow + 2, 6 );
     aTransformLayout->addWidget( aPointYSec,       aRow + 2, 7 );
     aTransformLayout->addWidget( aPointYSecLabel,  aRow + 2, 8 );
+    aTransformLayout->addWidget( aPointLatLabel,   aRow + 2, 9 );
 
     aTransformLayout->addWidget( aCartPointY,      aRow + 2, 3, 1, 6 );
     aTransformLayout->addWidget( aRefPointY,       aRow + 2, 3, 1, 6 );
@@ -231,7 +240,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
       QFrame* aLine = new QFrame( myTransformGroup );
       aLine->setFrameShape( QFrame::HLine );
       aLine->setFrameShadow( QFrame::Sunken );
-      aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
+      aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 10 );
     }
 
     myPointBtnMap[ aPointType ] = aPointBtn;
@@ -284,6 +293,8 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointXMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
   connect( myPointCEnabler, SIGNAL( toggled( bool ) ), myRefPointYMap[ HYDROGUI_PrsImage::PointC ], SLOT( setEnabled( bool ) ) );
 
+  connect( myPointCEnabler, SIGNAL( toggled( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
+
   aTransformLayout->setColumnStretch( 1, 1 ); // double
   aTransformLayout->setColumnStretch( 3, 1 ); // degrees
   aTransformLayout->setColumnStretch( 5, 1 ); // minutes
@@ -312,6 +323,16 @@ HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
 {
 }
 
+void HYDROGUI_ImportImageDlg::onSetCIsUsed( bool theCIsUsed )
+{
+  if ( !theCIsUsed  && myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->isChecked() )
+  {
+    // Turn on point A selection if point C selection has been activated and we disable point C.
+    myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->toggle();
+  }
+  emit setCIsUsed( theCIsUsed );
+}
+
 void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
 {
   myFileNameGroup->setVisible( !theIsEdit );
@@ -347,8 +368,28 @@ void HYDROGUI_ImportImageDlg::reset()
     myCartPointXMap[ aPointType ]->clear();
     myCartPointYMap[ aPointType ]->clear();
   }
-  myPointCEnabler->setChecked( true );
-  myPointCEnabler->toggle();
+  
+  // Emulate turning off C point usage
+  myPointCEnabler->blockSignals( true );
+  
+  myPointCEnabler->setChecked( false );
+  myPointBtnMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myRefPointXMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  myRefPointYMap[ HYDROGUI_PrsImage::PointC ]->setEnabled( false );
+  onSetCIsUsed( false );
+
+  myPointCEnabler->blockSignals( false );
+  
   myTransformGroup->setEnabled( false );
   myRefImage->clear();
 
@@ -450,8 +491,8 @@ void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationData
         int aXDeg = 0, aYDeg = 0;
         int aXMin = 0, aYMin = 0;
         double aXSec = 0, aYSec = 0;
-        HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
-        HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
+        HYDROData_Lambert93::degToDMS( aLPoint.x(), aXDeg, aXMin, aXSec );
+        HYDROData_Lambert93::degToDMS( aLPoint.y(), aYDeg, aYMin, aYSec );
 
         myPointXDegMap[ aPointType ]->setValue( aXDeg );
         myPointYDegMap[ aPointType ]->setValue( aYDeg );
@@ -508,8 +549,8 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t
         return false;
 
     double aX2 = 0, aY2 = 0;
-    HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
-    HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
+    HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aX2 );
+    HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aY2 );
 
     TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
     theMap[ aPointType ] = aData;
@@ -580,7 +621,8 @@ HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsf
   {
     // Geodesic to Cartesian
     double aXCart = 0, aYCart = 0;
-    HYDROData_Lambert93::toXY( arx, ary, aXCart, aYCart );
+    // Interpreting arY as attitude and arX as longitude
+    HYDROData_Lambert93::toXY( ary, arx, aXCart, aYCart );
 
     aResTrsfData.GeodesicPoint = theGlobalPoint;
     aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
@@ -605,7 +647,14 @@ void HYDROGUI_ImportImageDlg::onBrowse()
   if( !aFileName.isEmpty() )
   {
     QImage anImage( aFileName );
-    if( !anImage.isNull() )
+    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() );
+      SUIT_MessageBox::warning( module()->getApp()->desktop(), aTitle, aMessage );
+    }
+    else
     {
       myFileName->setText( aFileName );
       emit createPreview( anImage );