From: mzn Date: Fri, 27 Dec 2013 12:21:42 +0000 (+0000) Subject: Feature #296: Georeferencement of images on the base of files. X-Git-Tag: BR_hydro_v_0_7~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=216439f38d7dd618833b75c5dcb640915a62ba77;p=modules%2Fhydro.git Feature #296: Georeferencement of images on the base of files. --- diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 0d1d5bcb..e1ea0bfb 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -17,6 +17,9 @@ #include #include +#include + +#include static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8"); static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27"); @@ -598,6 +601,80 @@ bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode, return true; } +bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName ) +{ + bool aRes = false; + + // Try to open the file + QFile aFile( theFileName ); + if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) { + return aRes; + } + + QPointF aPointA, aPointB; + double aXmin, anYmin, aXmax, anYmax; + aXmin = anYmin = aXmax = anYmax = -1; + + while ( !aFile.atEnd() && + ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) { + // Read line + QString aLine = aFile.readLine().simplified(); + aLine.replace( " ", "" ); + if ( aLine.isEmpty() ) { + continue; + } + + // Try to read double value after ":" + bool isDoubleOk = false; + double aDoubleValue = -1; + QStringList aValues = aLine.split( ":", QString::SkipEmptyParts ); + if ( aValues.count() == 2 ) { + aDoubleValue = aValues.last().toDouble( &isDoubleOk ); + } + + // Check the result + if ( !isDoubleOk || + boost::math::isnan( aDoubleValue ) || + boost::math::isinf( aDoubleValue ) ) { + continue; + } + + // Set the value + if ( aLine.startsWith( "Xminimum" ) ) { + aXmin = aDoubleValue; + } + else if ( aLine.startsWith( "Yminimum" ) ) { + anYmin = aDoubleValue; + } + else if ( aLine.startsWith( "Xmaximum" ) ) { + aXmax = aDoubleValue; + } + else if ( aLine.startsWith( "Ymaximum" ) ) { + anYmax = aDoubleValue; + } + } + + // Close the file + aFile.close(); + + if ( aXmin >= 0 && anYmin >= 0 ) { + aPointA.setX( aXmin ); + aPointA.setY( anYmin ); + } + + if ( aXmax >= 0 && anYmax >= 0 ) { + aPointB.setX( aXmax ); + aPointB.setY( anYmax ); + } + + if ( !aPointA.isNull() && !aPointB.isNull() ) { + SetGlobalPoints( ManualCartesian, aPointA, aPointB ); + aRes = true; + } + + return aRes; +} + bool HYDROData_Image::HasGlobalPoints() const { TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false ); diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index 66193e01..d7eccacc 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -24,6 +24,7 @@ public: { ManualGeodesic = 0, ManualCartesian, + CartesianFromFile, ReferenceImage }; @@ -192,6 +193,13 @@ public: QPointF& thePointB, QPointF& thePointC ) const; + /** + * Get transformation points from the file and stores them in global cs + * \param theFileName the image georeferencement file name + * \return true in case of success + */ + HYDRODATA_EXPORT bool SetGlobalPointsFromFile( const QString& theFileName ); + /** * Returns true if global points has been set before */ diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx index 0b63f5f4..e39985b3 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx @@ -104,16 +104,18 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co QRadioButton* aManualGeodesicBtn = new QRadioButton( tr( "MANUALLY_GEODESIC" ), myTransformGroup ); QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup ); + QRadioButton* aCartesianFromFileBtn = new QRadioButton( tr( "LAMBERT93_FROM_FILE" ), myTransformGroup ); QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup ); myModeGroup = new QButtonGroup( myTransformGroup ); myModeGroup->addButton( aManualGeodesicBtn, HYDROData_Image::ManualGeodesic ); myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian ); + myModeGroup->addButton( aCartesianFromFileBtn, HYDROData_Image::CartesianFromFile ); myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage ); myRefImage = new QComboBox( myTransformGroup ); - QGridLayout* aTransformLayout = new QGridLayout( myTransformGroup ); + QVBoxLayout* aTransformLayout = new QVBoxLayout( myTransformGroup ); aTransformLayout->setMargin( 5 ); aTransformLayout->setSpacing( 5 ); @@ -122,31 +124,28 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co aModeLayout->setSpacing( 5 ); aModeLayout->addWidget( aManualGeodesicBtn, 0, 0 ); aModeLayout->addWidget( aManualCartesianBtn, 1, 0 ); - aModeLayout->addWidget( aRefImageBtn, 2, 0 ); - aModeLayout->addWidget( myRefImage, 2, 1 ); + aModeLayout->addWidget( aCartesianFromFileBtn, 2, 0 ); + aModeLayout->addWidget( aRefImageBtn, 3, 0 ); + aModeLayout->addWidget( myRefImage, 3, 1 ); aModeLayout->setColumnStretch( 1, 1 ); - aTransformLayout->addLayout( aModeLayout, 0, 0, 1, 9 ); + aTransformLayout->addLayout( aModeLayout ); - 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 ); + // Manual input widget + QWidget* aManualInputGroup = new QWidget( myTransformGroup ); + QGridLayout* aManualInputLayout = new QGridLayout( aManualInputGroup ); + aManualInputLayout->setMargin( 5 ); + aManualInputLayout->setSpacing( 5 ); - 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 ); + QLabel* aImageCSLabel = new QLabel( tr( "IMAGE_CS" ), aManualInputGroup ); + QLabel* aGeodesicLabel = new QLabel( tr( "GEODESIC" ), aManualInputGroup ); + QLabel* aLambertLabel = new QLabel( tr( "LAMBERT93" ), aManualInputGroup ); + QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE_CS" ), aManualInputGroup ); - connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) ); - connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) ); - connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) ); - connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) ); - connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) ); - connect( aManualGeodesicBtn, 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 ) ) ); + aManualInputLayout->addWidget( aImageCSLabel, 0, 1 ); + aManualInputLayout->addWidget( aGeodesicLabel, 0, 2, 1, 6 ); + aManualInputLayout->addWidget( aLambertLabel, 0, 2, 1, 6 ); + aManualInputLayout->addWidget( aRefImageLabel, 0, 2, 1, 6 ); for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ ) @@ -161,86 +160,86 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup ); aPointBtn->setCheckable( true ); - QLabel* aPointXLabel = new QLabel( "X", myTransformGroup ); - QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup ); + QLabel* aPointXLabel = new QLabel( "X", aManualInputGroup ); + QLabel* aPointYLabel = new QLabel( "Y", aManualInputGroup ); - QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later - QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later + QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later + QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later - QLabel* aPointArrowLabel = new QLabel( myTransformGroup ); + QLabel* aPointArrowLabel = new QLabel( aManualInputGroup ); aPointArrowLabel->setPicture( anArrowPicture ); - QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup ); - QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myTransformGroup ); - QLabel* aPointXMinLabel = new QLabel( "'", myTransformGroup ); - 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 ); + QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), aManualInputGroup ); + QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), aManualInputGroup ); + QLabel* aPointXMinLabel = new QLabel( "'", aManualInputGroup ); + QLabel* aPointYMinLabel = new QLabel( "'", aManualInputGroup ); + QLabel* aPointXSecLabel = new QLabel( "\"", aManualInputGroup ); + QLabel* aPointYSecLabel = new QLabel( "\"", aManualInputGroup ); + QLabel* aPointLatLabel = new QLabel( tr( "POINT_LATITUDE" ), aManualInputGroup ); + QLabel* aPointLonLabel = new QLabel( tr( "POINT_LONGITUDE" ), aManualInputGroup ); myGeodesicLabels << aPointXDegLabel << aPointYDegLabel << aPointXMinLabel << aPointYMinLabel << aPointXSecLabel << aPointYSecLabel << aPointLonLabel << aPointLatLabel; - 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 ); - QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, myTransformGroup ); + QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -179, 179, 1, aManualInputGroup ); + QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( 0, 89, 1, aManualInputGroup ); + QtxIntSpinBox* aPointXMin = new QtxIntSpinBox( 0, 59, 1, aManualInputGroup ); + QtxIntSpinBox* aPointYMin = new QtxIntSpinBox( 0, 59, 1, aManualInputGroup ); + QtxDoubleSpinBox* aPointXSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, aManualInputGroup ); + QtxDoubleSpinBox* aPointYSec = new QtxDoubleSpinBox( 0, 59.9999, 1, 4, 4, aManualInputGroup ); - QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup ); - QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup ); + QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, aManualInputGroup ); + QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, aManualInputGroup ); - QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later - QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later + QtxIntSpinBox* aRefPointX = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later + QtxIntSpinBox* aRefPointY = new QtxIntSpinBox( 0, 0, 1, aManualInputGroup ); // max is updated later - int aRow = 4 * aPointType + 3; + int aRow = 4 * aPointType; if ( aPointType == HYDROGUI_PrsImage::PointC ) { - myPointCEnabler = new QCheckBox( myTransformGroup ); - aTransformLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter ); - aTransformLayout->addWidget( aPointBtn, aRow, 2, 1, 8 ); + myPointCEnabler = new QCheckBox( aManualInputGroup ); + aManualInputLayout->addWidget( myPointCEnabler, aRow, 0, 1, 2, Qt::AlignHCenter ); + aManualInputLayout->addWidget( aPointBtn, aRow, 2, 1, 8 ); } else { - aTransformLayout->addWidget( aPointBtn, aRow, 0, 1, 10 ); + aManualInputLayout->addWidget( aPointBtn, aRow, 0, 1, 10 ); } - aTransformLayout->addWidget( aPointXLabel, aRow + 1, 0 ); - aTransformLayout->addWidget( aPointX, aRow + 1, 1 ); - aTransformLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 ); - aTransformLayout->addWidget( aPointXDeg, aRow + 1, 3 ); - aTransformLayout->addWidget( aPointXDegLabel, aRow + 1, 4 ); - aTransformLayout->addWidget( aPointXMin, aRow + 1, 5 ); - 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 ); - - aTransformLayout->addWidget( aPointYLabel, aRow + 2, 0 ); - aTransformLayout->addWidget( aPointY, aRow + 2, 1 ); - aTransformLayout->addWidget( aPointYDeg, aRow + 2, 3 ); - aTransformLayout->addWidget( aPointYDegLabel, aRow + 2, 4 ); - aTransformLayout->addWidget( aPointYMin, aRow + 2, 5 ); - 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 ); + aManualInputLayout->addWidget( aPointXLabel, aRow + 1, 0 ); + aManualInputLayout->addWidget( aPointX, aRow + 1, 1 ); + aManualInputLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 ); + aManualInputLayout->addWidget( aPointXDeg, aRow + 1, 3 ); + aManualInputLayout->addWidget( aPointXDegLabel, aRow + 1, 4 ); + aManualInputLayout->addWidget( aPointXMin, aRow + 1, 5 ); + aManualInputLayout->addWidget( aPointXMinLabel, aRow + 1, 6 ); + aManualInputLayout->addWidget( aPointXSec, aRow + 1, 7 ); + aManualInputLayout->addWidget( aPointXSecLabel, aRow + 1, 8 ); + aManualInputLayout->addWidget( aPointLonLabel, aRow + 1, 9 ); + + aManualInputLayout->addWidget( aCartPointX, aRow + 1, 3, 1, 6 ); + aManualInputLayout->addWidget( aRefPointX, aRow + 1, 3, 1, 6 ); + + aManualInputLayout->addWidget( aPointYLabel, aRow + 2, 0 ); + aManualInputLayout->addWidget( aPointY, aRow + 2, 1 ); + aManualInputLayout->addWidget( aPointYDeg, aRow + 2, 3 ); + aManualInputLayout->addWidget( aPointYDegLabel, aRow + 2, 4 ); + aManualInputLayout->addWidget( aPointYMin, aRow + 2, 5 ); + aManualInputLayout->addWidget( aPointYMinLabel, aRow + 2, 6 ); + aManualInputLayout->addWidget( aPointYSec, aRow + 2, 7 ); + aManualInputLayout->addWidget( aPointYSecLabel, aRow + 2, 8 ); + aManualInputLayout->addWidget( aPointLatLabel, aRow + 2, 9 ); + + aManualInputLayout->addWidget( aCartPointY, aRow + 2, 3, 1, 6 ); + aManualInputLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 ); if( aPointType != HYDROGUI_PrsImage::PointC ) { - QFrame* aLine = new QFrame( myTransformGroup ); + QFrame* aLine = new QFrame( aManualInputGroup ); aLine->setFrameShape( QFrame::HLine ); aLine->setFrameShadow( QFrame::Sunken ); - aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 10 ); + aManualInputLayout->addWidget( aLine, aRow + 3, 0, 1, 10 ); } myPointBtnMap[ aPointType ] = aPointBtn; @@ -295,10 +294,48 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co connect( myPointCEnabler, SIGNAL( toggled( bool ) ), SLOT( onSetCIsUsed( bool ) ) ); - aTransformLayout->setColumnStretch( 1, 1 ); // double - aTransformLayout->setColumnStretch( 3, 1 ); // degrees - aTransformLayout->setColumnStretch( 5, 1 ); // minutes - aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits) + aManualInputLayout->setColumnStretch( 1, 1 ); // double + aManualInputLayout->setColumnStretch( 3, 1 ); // degrees + aManualInputLayout->setColumnStretch( 5, 1 ); // minutes + aManualInputLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits) + + // Image georeferencement file widget + QWidget* aFromFileInputGroup = new QWidget( myTransformGroup ); + QBoxLayout* aFromFileInputLayout = new QHBoxLayout( aFromFileInputGroup ); + aFromFileInputLayout->setMargin( 5 ); + aFromFileInputLayout->setSpacing( 5 ); + + QLabel* aGeoFileNameLabel = new QLabel( tr( "FILE_NAME" ), aFromFileInputGroup ); + + myGeoFileName = new QLineEdit( aFromFileInputGroup ); + myGeoFileName->setReadOnly( true ); + + QToolButton* aGeoBrowseBtn = new QToolButton( aFromFileInputGroup ); + aGeoBrowseBtn->setIcon( aResMgr->loadPixmap( "HYDRO", tr( "BROWSE_ICO" ) ) ); + + aFromFileInputLayout->addWidget( aGeoFileNameLabel ); + aFromFileInputLayout->addWidget( myGeoFileName ); + aFromFileInputLayout->addWidget( aGeoBrowseBtn ); + + // Widgets connections + connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setVisible ( bool ) ) ); + connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setHidden ( bool ) ) ); + connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) ); + connect( aManualCartesianBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) ); + connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aGeodesicLabel, SLOT( setVisible ( bool ) ) ); + connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aLambertLabel, SLOT( setHidden ( bool ) ) ); + connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aRefImageLabel, SLOT( setHidden ( bool ) ) ); + connect( aManualGeodesicBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, 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 ) ) ); + connect( aRefImageBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setHidden ( bool ) ) ); + connect( aCartesianFromFileBtn, SIGNAL( toggled( bool ) ), aFromFileInputGroup, SLOT( setVisible ( bool ) ) ); + connect( aCartesianFromFileBtn, SIGNAL( toggled( bool ) ), aManualInputGroup, SLOT( setHidden ( bool ) ) ); + + // Input widgets + aTransformLayout->addWidget( aManualInputGroup ); + aTransformLayout->addWidget( aFromFileInputGroup ); // Common addWidget( myFileNameGroup ); @@ -311,6 +348,8 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co connect( myModeGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( onModeActivated( int ) ) ); + connect( aGeoBrowseBtn, SIGNAL( clicked() ), this, SLOT( onGeoBrowse() ) ); + connect( myRefImage, SIGNAL( activated( const QString& ) ), this, SLOT( onRefImageActivated( const QString& ) ) ); @@ -345,6 +384,7 @@ void HYDROGUI_ImportImageDlg::reset() myFileName->clear(); myImageName->clear(); myImageNameGroup->setEnabled( false ); + myGeoFileName->clear(); for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ ) { @@ -425,6 +465,11 @@ QString HYDROGUI_ImportImageDlg::getFileName() const return myFileName->text(); } +QString HYDROGUI_ImportImageDlg::getGeoreferencementFileName() const +{ + return myGeoFileName->text(); +} + void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize, const bool theIsRefImage ) { @@ -664,6 +709,15 @@ void HYDROGUI_ImportImageDlg::onBrowse() } } +void HYDROGUI_ImportImageDlg::onGeoBrowse() +{ + QString aFilter( tr( "IMAGE_GEOREFERENCEMENT_FILTER" ) ); + QString aGeoFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_GEO_DATA_FROM_FILE" ), true ); + if( !aGeoFileName.isEmpty() ) { + myGeoFileName->setText( aGeoFileName ); + } +} + void HYDROGUI_ImportImageDlg::onModeActivated( int theMode ) { bool anIsManualGeodesic = theMode == HYDROData_Image::ManualGeodesic; diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.h b/src/HYDROGUI/HYDROGUI_ImportImageDlg.h index 12c550f9..f1f2a647 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.h @@ -86,6 +86,7 @@ public: QString getRefImageName() const; QString getFileName() const; + QString getGeoreferencementFileName() const; void setImageSize( const QSize& theSize, const bool theIsRefImage = false ); @@ -114,6 +115,7 @@ public: protected slots: void onBrowse(); + void onGeoBrowse(); void onModeActivated( int ); void onRefImageActivated( const QString& ); void onPointBtnToggled( bool ); @@ -153,6 +155,8 @@ private: QButtonGroup* myModeGroup; //!< The group for the input mode selector QComboBox* myRefImage; //!< Reference image selector + QLineEdit* myGeoFileName; //!< Image georeferencement file name input field + QList myGeodesicLabels; //!< Labels for geodesic coords input fields QMap myPointBtnMap; //!< A,B,C points selection modes activators diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 06836f63..383c7448 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -359,77 +359,82 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, } } - HYDROGUI_ImportImageDlg::TransformationDataMap aMap; - if( !aPanel->getTransformationDataMap( aMap ) ) - return false; - - bool anIsByTwoPoints = aPanel->isByTwoPoints(); + HYDROData_Image::TransformationMode aTransformationMode = + (HYDROData_Image::TransformationMode)aPanel->getTransformationMode(); + + QPoint aPointA, aPointB, aPointC; + QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN ); + Handle(HYDROData_Image) aRefImageObj; - QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint; - QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint; - QPoint aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : - aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint; + if ( aTransformationMode != HYDROData_Image::CartesianFromFile ) { + HYDROGUI_ImportImageDlg::TransformationDataMap aMap; + if( !aPanel->getTransformationDataMap( aMap ) ) + return false; - // first, we check correctness of image points - if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints, - tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ), - tr( "POINTS_A_B_ARE_IDENTICAL" ), - theErrorMsg, true ) ) - return false; + bool anIsByTwoPoints = aPanel->isByTwoPoints(); - Handle(HYDROData_Image) aRefImageObj; - QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN ); + aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint; + aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint; + aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) : + aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint; - HYDROData_Image::TransformationMode aTransformationMode = - (HYDROData_Image::TransformationMode)aPanel->getTransformationMode(); - if ( aTransformationMode == HYDROData_Image::ReferenceImage ) - { - QString aRefImageName = aPanel->getRefImageName(); - if( aRefImageName.isEmpty() ) - { - theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" ); + // first, we check correctness of image points + if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints, + tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ), + tr( "POINTS_A_B_ARE_IDENTICAL" ), + theErrorMsg, true ) ) return false; - } - HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap; - if( !aPanel->getTransformationDataMap( aRefMap, true ) ) - return false; + if ( aTransformationMode == HYDROData_Image::ReferenceImage ) + { + QString aRefImageName = aPanel->getRefImageName(); + if( aRefImageName.isEmpty() ) + { + theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" ); + return false; + } - aRefImageObj = Handle(HYDROData_Image)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) ); - if( aRefImageObj.IsNull() ) - return false; + HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap; + if( !aPanel->getTransformationDataMap( aRefMap, true ) ) + return false; - else if ( !isReferenceCorrect() ) - aRefImageObj->RemoveAllReferences(); + aRefImageObj = Handle(HYDROData_Image)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) ); + if( aRefImageObj.IsNull() ) { + return false; + } + else if ( !isReferenceCorrect() ) { + aRefImageObj->RemoveAllReferences(); + } - aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint; - aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint; - if ( !anIsByTwoPoints ) + aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint; + aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint; + if ( !anIsByTwoPoints ) aTrsfPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint; - // the same check of correctness for the reference points - if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints, - tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ), - tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ), - theErrorMsg, false ) ) - return false; - } - else - { - if ( aTransformationMode == HYDROData_Image::ManualGeodesic ) - { - aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].GeodesicPoint; - aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].GeodesicPoint; - if ( !anIsByTwoPoints ) - aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].GeodesicPoint; + // the same check of correctness for the reference points + if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints, + tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ), + tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ), + theErrorMsg, false ) ) + return false; } else { - aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint; - aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint; - if ( !anIsByTwoPoints ) - aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint; + if ( aTransformationMode == HYDROData_Image::ManualGeodesic ) + { + aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].GeodesicPoint; + aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].GeodesicPoint; + if ( !anIsByTwoPoints ) + aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].GeodesicPoint; + } + else + { + aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint; + aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint; + if ( !anIsByTwoPoints ) + aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint; + } } } @@ -444,17 +449,34 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, anImageObj->SetName( anImageName ); anImageObj->SetImage( myImage ); - anImageObj->SetLocalPoints( aPointA, aPointB, aPointC, false ); + + if ( aTransformationMode == HYDROData_Image::CartesianFromFile ) { + QString aGeoreferencementFileName = aPanel->getGeoreferencementFileName(); + if ( aGeoreferencementFileName.isEmpty() ) { + return false; + } - if ( aTransformationMode == HYDROData_Image::ReferenceImage ) - { - anImageObj->SetReferencePoints( aRefImageObj, + QPoint aLocalPointA( 0, 0 ), + aLocalPointB( anImageObj->Image().width(), 0 ), + aLocalPointC( INT_MIN, INT_MIN ); + anImageObj->SetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC, false ); + if ( !anImageObj->SetGlobalPointsFromFile( aGeoreferencementFileName ) ) { + theErrorMsg = tr( "CANT_LOAD_GEOREFERENCEMENT_FILE" ); + return false; + } + } else { + anImageObj->SetLocalPoints( aPointA, aPointB, aPointC, false ); + + if ( aTransformationMode == HYDROData_Image::ReferenceImage ) + { + anImageObj->SetReferencePoints( aRefImageObj, aTrsfPointA, aTrsfPointB, aTrsfPointC ); - } - else - { - anImageObj->SetGlobalPoints( aTransformationMode, + } + else + { + anImageObj->SetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ); + } } if( !myIsEdit ) diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index d3575e9e..471fcaf4 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1,4 +1,4 @@ - + @@ -489,6 +489,10 @@ file cannot be correctly imported for a Bathymetry definition. MANUALLY_LAMBERT93 Manually input Plane coordinates (Lambert93) + + LAMBERT93_FROM_FILE + Get Plane coordinates (Lambert93) from file + IMAGE_CS Image CS @@ -521,6 +525,14 @@ file cannot be correctly imported for a Bathymetry definition. TRANSFORM_IMAGE Transform image + + IMPORT_GEO_DATA_FROM_FILE + Import georeferencement data from file + + + IMAGE_GEOREFERENCEMENT_FILTER + Image georeferencement files (*.grf);;All files (*.* *) + @@ -578,6 +590,10 @@ file cannot be correctly imported for a Bathymetry definition. The image "%1" has a reference to the current object. Would you like to remove all references from the image? + + CANT_LOAD_GEOREFERENCEMENT_FILE + Can't load data from the image georeferencement file. +