+// 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
+//
+// 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.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "HYDROGUI_ImportImageDlg.h"
+
+#include "HYDROGUI_PrsImage.h"
+#include "HYDROGUI_Tool.h"
+
+#include <HYDROData_Lambert93.h>
+
+#include <SUIT_FileDlg.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+
+#include <QtxDoubleSpinBox.h>
+#include <QtxIntSpinBox.h>
+
+#include <QButtonGroup>
+#include <QComboBox>
+#include <QGroupBox>
+#include <QLabel>
+#include <QLayout>
+#include <QLineEdit>
+#include <QPainter>
+#include <QPicture>
+#include <QPushButton>
+#include <QRadioButton>
+#include <QToolButton>
+#include <QCheckBox>
+
+HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
+: HYDROGUI_InputPanel( theModule, theTitle ),
+ myIsInitialized( false )
+{
+ SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
+
+ // Import image from file
+ myFileNameGroup = new QGroupBox( tr( "IMPORT_IMAGE_FROM_FILE" ), this );
+
+ QLabel* aFileNameLabel = new QLabel( tr( "FILE_NAME" ), myFileNameGroup );
+
+ myFileName = new QLineEdit( myFileNameGroup );
+ myFileName->setReadOnly( true );
+
+ QToolButton* aBrowseBtn = new QToolButton( myFileNameGroup );
+ aBrowseBtn->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 );
+
+ // Image name
+ myImageNameGroup = new QGroupBox( tr( "IMAGE_NAME" ), this );
+
+ QLabel* anImageNameLabel = new QLabel( tr( "NAME" ), myImageNameGroup );
+ myImageName = new QLineEdit( myImageNameGroup );
+
+ QBoxLayout* anImageNameLayout = new QHBoxLayout( myImageNameGroup );
+ anImageNameLayout->setMargin( 5 );
+ anImageNameLayout->setSpacing( 5 );
+ anImageNameLayout->addWidget( anImageNameLabel );
+ anImageNameLayout->addWidget( myImageName );
+
+ // Transform image
+ myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ), this );
+
+ // Make a pixmap for arrow
+ QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
+
+ QPicture anArrowPicture;
+ anArrowPicture.setBoundingRect( QRect( QPoint( 0, 0 ), anArrowPixmap.size() ) );
+
+ QPainter aPainter;
+ aPainter.begin( &anArrowPicture );
+ aPainter.drawPixmap( 0, 0, anArrowPixmap );
+ aPainter.end();
+
+ QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup );
+ QRadioButton* aManualLambertBtn = 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 );
+
+ myRefImage = new QComboBox( myTransformGroup );
+
+ 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( aRefImageBtn, 2, 0 );
+ aModeLayout->addWidget( myRefImage, 2, 1 );
+ aModeLayout->setColumnStretch( 1, 1 );
+
+ 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++ )
+ {
+ QString aPointStr;
+ switch( aPointType )
+ {
+ case HYDROGUI_PrsImage::PointA: aPointStr = tr( "ACTIVATE_POINT_A_SELECTION" ); break;
+ case HYDROGUI_PrsImage::PointB: aPointStr = tr( "ACTIVATE_POINT_B_SELECTION" ); break;
+ case HYDROGUI_PrsImage::PointC: aPointStr = tr( "ACTIVATE_POINT_C_SELECTION" ); break;
+ }
+ QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
+ aPointBtn->setCheckable( true );
+
+ QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
+ QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
+
+ QtxIntSpinBox* aPointX = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
+ QtxIntSpinBox* aPointY = new QtxIntSpinBox( 0, 0, 1, myTransformGroup ); // max is updated later
+
+ QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
+ 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 );
+ myLambertLabels << aPointXDegLabel << aPointYDegLabel
+ << aPointXMinLabel << aPointYMinLabel
+ << aPointXSecLabel << aPointYSecLabel;
+
+ QtxIntSpinBox* aPointXDeg = new QtxIntSpinBox( -180, 180, 1, myTransformGroup );
+ QtxIntSpinBox* aPointYDeg = new QtxIntSpinBox( -90, 90, 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 );
+
+ QtxDoubleSpinBox* aCartPointX = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
+ QtxDoubleSpinBox* aCartPointY = new QtxDoubleSpinBox( 0, 1e8, 1, 2, 2, myTransformGroup );
+
+ 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 + 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 );
+ 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( 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( aCartPointY, aRow + 2, 3, 1, 6 );
+ aTransformLayout->addWidget( aRefPointY, aRow + 2, 3, 1, 6 );
+
+ if( aPointType != HYDROGUI_PrsImage::PointC )
+ {
+ QFrame* aLine = new QFrame( myTransformGroup );
+ aLine->setFrameShape( QFrame::HLine );
+ aLine->setFrameShadow( QFrame::Sunken );
+ aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
+ }
+
+ myPointBtnMap[ aPointType ] = aPointBtn;
+ myPointXMap[ aPointType ] = aPointX;
+ myPointYMap[ aPointType ] = aPointY;
+ myPointXDegMap[ aPointType ] = aPointXDeg;
+ myPointYDegMap[ aPointType ] = aPointYDeg;
+ myPointXMinMap[ aPointType ] = aPointXMin;
+ myPointYMinMap[ aPointType ] = aPointYMin;
+ myPointXSecMap[ aPointType ] = aPointXSec;
+ myPointYSecMap[ aPointType ] = aPointYSec;
+
+ myCartPointXMap[ aPointType ] = aCartPointX;
+ myCartPointYMap[ aPointType ] = aCartPointY;
+
+ myRefPointXMap[ aPointType ] = aRefPointX;
+ myRefPointYMap[ aPointType ] = aRefPointY;
+
+ connect( aPointBtn, SIGNAL( toggled( bool ) ), this, SLOT( onPointBtnToggled( bool ) ) );
+
+ connect( aPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
+ connect( aPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
+
+ connect( aPointXDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
+ connect( aPointYDeg, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
+ connect( aPointXMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
+ connect( aPointYMin, SIGNAL( valueChanged( int ) ), this, SLOT( onLambertCoordChanged() ) );
+ connect( aPointXSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
+ connect( aPointYSec, SIGNAL( valueChanged( double ) ), this, SLOT( onLambertCoordChanged() ) );
+
+ connect( aCartPointX, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
+ connect( aCartPointY, SIGNAL( valueChanged( double ) ), this, SLOT( onCartesianCoordChanged() ) );
+
+ 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
+ aTransformLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
+
+ // Common
+ addWidget( myFileNameGroup );
+ addWidget( myImageNameGroup );
+ addWidget( myTransformGroup );
+ addStretch();
+
+ connect( aBrowseBtn, SIGNAL( clicked() ), this, SLOT( onBrowse() ) );
+
+ connect( myModeGroup, SIGNAL( buttonClicked( int ) ),
+ this, SLOT( onModeActivated( int ) ) );
+
+ connect( myRefImage, SIGNAL( activated( const QString& ) ),
+ this, SLOT( onRefImageActivated( const QString& ) ) );
+
+ setTransformationMode( ManualLambert );
+
+ setMinimumWidth( 350 );
+}
+
+HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
+{
+}
+
+void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
+{
+ myFileNameGroup->setVisible( !theIsEdit );
+ myImageNameGroup->setEnabled( theIsEdit );
+ myTransformGroup->setEnabled( theIsEdit );
+}
+
+void HYDROGUI_ImportImageDlg::reset()
+{
+ myFileName->clear();
+ myImageName->clear();
+ myImageNameGroup->setEnabled( false );
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ QPushButton* aBtn = myPointBtnMap[ aPointType ];
+ bool anIsBlocked = aBtn->blockSignals( true );
+ 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();
+
+ myRefPointXMap[ aPointType ]->clear();
+ myRefPointYMap[ aPointType ]->clear();
+
+ myCartPointXMap[ aPointType ]->clear();
+ myCartPointYMap[ aPointType ]->clear();
+ }
+ myPointCEnabler->setChecked( true );
+ myPointCEnabler->toggle();
+ myTransformGroup->setEnabled( false );
+ myRefImage->clear();
+
+ setTransformationMode( ManualLambert );
+
+ myPrsPointDataList.clear();
+
+ myIsInitialized = false;
+}
+
+void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
+{
+ myImageName->setText( theName );
+}
+
+QString HYDROGUI_ImportImageDlg::getImageName() const
+{
+ return myImageName->text();
+}
+
+QString HYDROGUI_ImportImageDlg::getFileName() const
+{
+ return myFileName->text();
+}
+
+void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize,
+ const bool theIsRefImage )
+{
+ int aWidth = theSize.width();
+ int aHeight = theSize.height();
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ if( theIsRefImage )
+ {
+ myRefPointXMap[ aPointType ]->setRange( 0, aWidth );
+ myRefPointYMap[ aPointType ]->setRange( 0, aHeight );
+ }
+ else
+ {
+ myPointXMap[ aPointType ]->setRange( 0, aWidth );
+ myPointYMap[ aPointType ]->setRange( 0, aHeight );
+ }
+ }
+}
+
+void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode )
+{
+ myModeGroup->button( theMode )->setChecked( true );
+ onModeActivated( theMode );
+}
+
+int HYDROGUI_ImportImageDlg::getTransformationMode() const
+{
+ return myModeGroup->checkedId();
+}
+
+void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
+ const bool theIsOnlyInput,
+ const bool theIsRefImage )
+{
+ blockSignalsLambert( true );
+ blockSignalsCartesian( true );
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ if( theMap.contains( aPointType ) )
+ {
+ const TransformationData& aData = theMap[ aPointType ];
+
+ QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
+ QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
+ aPointX->setValue( aData.ImagePoint.x() );
+ aPointY->setValue( aData.ImagePoint.y() );
+
+ if( !theIsOnlyInput && !theIsRefImage )
+ {
+ QPointF aLPoint = aData.LambertPoint;
+ 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 );
+
+ myPointXDegMap[ aPointType ]->setValue( aXDeg );
+ myPointYDegMap[ aPointType ]->setValue( aYDeg );
+ myPointXMinMap[ aPointType ]->setValue( aXMin );
+ myPointYMinMap[ aPointType ]->setValue( aYMin );
+ myPointXSecMap[ aPointType ]->setValue( aXSec );
+ myPointYSecMap[ aPointType ]->setValue( aYSec );
+
+ QPointF aCPoint = aData.CartesianPoint;
+ myCartPointXMap[ aPointType ]->setValue( aCPoint.x() );
+ myCartPointYMap[ aPointType ]->setValue( aCPoint.y() );
+ }
+ }
+ }
+ blockSignalsLambert( false );
+ blockSignalsCartesian( false );
+}
+
+bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
+ const bool theIsRefImage ) const
+{
+ theMap.clear();
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ bool anIsOk[10];
+ for( int i = 0; i < 10; i++ )
+ anIsOk[ i ] = true;
+
+ QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
+ QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
+ int aX1 = aPointX->text().toInt( &anIsOk[0] );
+ int aY1 = aPointY->text().toInt( &anIsOk[1] );
+
+ int aXDeg = 0, aYDeg = 0;
+ int aXMin = 0, aYMin = 0;
+ double aXSec = 0, aYSec = 0;
+ double aXCart = 0, aYCart = 0;
+ if( !theIsRefImage )
+ {
+ aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
+ aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
+ aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
+ aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
+ aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
+ aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
+
+ aXCart = myCartPointXMap[ aPointType ]->text().toDouble( &anIsOk[8] );
+ aYCart = myCartPointYMap[ aPointType ]->text().toDouble( &anIsOk[9] );
+ }
+
+ for( int i = 0; i < 10; i++ )
+ if( !anIsOk[ i ] )
+ return false;
+
+ double aX2 = 0, aY2 = 0;
+ HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 );
+ HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 );
+
+ TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, aY2 ), QPointF( aXCart, aYCart ) );
+ theMap[ aPointType ] = aData;
+ }
+ 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 );
+
+ myRefImage->clear();
+ myRefImage->addItem( "" ); // first empty item
+
+ PrsPointDataListIterator anIter( myPrsPointDataList );
+ while( anIter.hasNext() )
+ myRefImage->addItem( anIter.next().first );
+ }
+ else
+ myModeGroup->button( RefImage )->setEnabled( false );
+}
+
+void HYDROGUI_ImportImageDlg::initializePointSelection()
+{
+ if( myIsInitialized )
+ return;
+
+ myIsInitialized = true;
+
+ myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
+
+ // ouv: tmp
+ /*
+ blockSignalsLambert( true );
+
+ myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
+ myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
+ myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
+ myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setValue( 50 );
+ myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
+ myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setValue( 0 );
+
+ myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
+ myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 1 );
+ myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
+ myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setValue( 50 );
+ myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
+ myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setValue( 0 );
+
+ myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
+ myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
+ myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
+ myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setValue( 50 );
+ myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setValue( 1 );
+ myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setValue( 0 );
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ onLambertCoordChanged( aPointType );
+
+ blockSignalsLambert( false );
+ */
+
+ //double aCartX0 = 600000;
+ //double aCartY0 = 6800000;
+ double aCartX0 = 0;
+ double aCartY0 = 0;
+
+ blockSignalsCartesian( true );
+
+ myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 );
+ myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 + 500 );
+
+ myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 500 );
+ myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 + 500 );
+
+ myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 );
+ myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 );
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ onCartesianCoordChanged( aPointType );
+
+ blockSignalsCartesian( false );
+}
+
+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() )
+ {
+ QImage anImage( aFileName );
+ if( !anImage.isNull() )
+ {
+ myFileName->setText( aFileName );
+ emit createPreview( anImage );
+ myImageNameGroup->setEnabled( true );
+ myTransformGroup->setEnabled( true );
+ }
+ }
+}
+
+void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
+{
+ bool anIsManualLambert = theMode == ManualLambert;
+ bool anIsManualCartesian = theMode == ManualCartesian;
+ bool anIsRefImage = theMode == RefImage;
+
+ myRefImage->setEnabled( anIsRefImage );
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ myPointXDegMap[ aPointType ]->setVisible( anIsManualLambert );
+ myPointYDegMap[ aPointType ]->setVisible( anIsManualLambert );
+ myPointXMinMap[ aPointType ]->setVisible( anIsManualLambert );
+ myPointYMinMap[ aPointType ]->setVisible( anIsManualLambert );
+ myPointXSecMap[ aPointType ]->setVisible( anIsManualLambert );
+ myPointYSecMap[ aPointType ]->setVisible( anIsManualLambert );
+
+ myCartPointXMap[ aPointType ]->setVisible( anIsManualCartesian );
+ myCartPointYMap[ aPointType ]->setVisible( anIsManualCartesian );
+
+ myRefPointXMap[ aPointType ]->setVisible( anIsRefImage );
+ myRefPointYMap[ aPointType ]->setVisible( anIsRefImage );
+ }
+
+ QListIterator<QLabel*> anIter( myLambertLabels );
+ while( anIter.hasNext() )
+ anIter.next()->setVisible( anIsManualLambert );
+
+ emit modeActivated( theMode );
+}
+
+void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
+{
+ emit refImageActivated( theName );
+}
+
+void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
+{
+ int aPointType = HYDROGUI_PrsImage::None;
+ if( theState )
+ {
+ QMapIterator<int, QPushButton*> anIter( myPointBtnMap );
+ while( anIter.hasNext() )
+ {
+ int aBtnPointType = anIter.next().key();
+ QPushButton* aBtn = anIter.value();
+ if( aBtn == sender() )
+ aPointType = aBtnPointType;
+ else
+ {
+ bool anIsBlocked = aBtn->blockSignals( true );
+ aBtn->setChecked( false );
+ aBtn->blockSignals( anIsBlocked );
+ }
+ }
+ }
+ emit activatePointSelection( aPointType );
+}
+
+void HYDROGUI_ImportImageDlg::onPointCoordChanged( int theValue )
+{
+ QObject* aSender = sender();
+ if( !aSender )
+ return;
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ if( aSender == myPointXMap[ aPointType ] ||
+ aSender == myPointYMap[ aPointType ] )
+ {
+ bool anIsY = aSender == myPointYMap[ aPointType ];
+ emit pointCoordChanged( false, aPointType, anIsY, theValue );
+ }
+ else if( aSender == myRefPointXMap[ aPointType ] ||
+ aSender == myRefPointYMap[ aPointType ] )
+ {
+ bool anIsY = aSender == myRefPointYMap[ aPointType ];
+ emit pointCoordChanged( true, aPointType, anIsY, theValue );
+ }
+ }
+}
+
+void HYDROGUI_ImportImageDlg::onLambertCoordChanged()
+{
+ QObject* aSender = sender();
+ if( !aSender )
+ return;
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ if( aSender == myPointXDegMap[ aPointType ] ||
+ aSender == myPointYDegMap[ aPointType ] ||
+ aSender == myPointXMinMap[ aPointType ] ||
+ aSender == myPointYMinMap[ aPointType ] ||
+ aSender == myPointXSecMap[ aPointType ] ||
+ aSender == myPointYSecMap[ aPointType ] )
+ {
+ onLambertCoordChanged( aPointType );
+ return;
+ }
+ }
+}
+
+void HYDROGUI_ImportImageDlg::onLambertCoordChanged( const int thePointType )
+{
+ bool anIsOk[6];
+ for( int i = 0; i < 6; i++ )
+ anIsOk[ i ] = true;
+
+ int aXDeg = myPointXDegMap[ thePointType ]->text().toInt( &anIsOk[0] );
+ int aYDeg = myPointYDegMap[ thePointType ]->text().toInt( &anIsOk[1] );
+ int aXMin = myPointXMinMap[ thePointType ]->text().toInt( &anIsOk[2] );
+ int aYMin = myPointYMinMap[ thePointType ]->text().toInt( &anIsOk[3] );
+ double aXSec = myPointXSecMap[ thePointType ]->text().toDouble( &anIsOk[4] );
+ double aYSec = myPointYSecMap[ thePointType ]->text().toDouble( &anIsOk[5] );
+
+ for( int i = 0; i < 6; i++ )
+ if( !anIsOk[ i ] )
+ return;
+
+ double aLonDeg = 0, aLatDeg = 0;
+ HYDROData_Lambert93::DMSToDeg( aXDeg, aXMin, aXSec, aLonDeg );
+ HYDROData_Lambert93::DMSToDeg( aYDeg, aYMin, aYSec, aLatDeg );
+
+ double aXCart = 0, aYCart = 0;
+ HYDROData_Lambert93::toXY( aLatDeg, aLonDeg, aXCart, aYCart );
+
+ blockSignalsCartesian( true );
+
+ myCartPointXMap[ thePointType ]->setValue( aXCart );
+ myCartPointYMap[ thePointType ]->setValue( aYCart );
+
+ blockSignalsCartesian( false );
+}
+
+void HYDROGUI_ImportImageDlg::onCartesianCoordChanged()
+{
+ QObject* aSender = sender();
+ if( !aSender )
+ return;
+
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ if( aSender == myCartPointXMap[ aPointType ] ||
+ aSender == myCartPointYMap[ aPointType ] )
+ {
+ onCartesianCoordChanged( aPointType );
+ return;
+ }
+ }
+}
+
+void HYDROGUI_ImportImageDlg::onCartesianCoordChanged( const int thePointType )
+{
+ bool anIsOk[2];
+ for( int i = 0; i < 2; i++ )
+ anIsOk[ i ] = true;
+
+ double aXCart = myCartPointXMap[ thePointType ]->text().toDouble( &anIsOk[0] );
+ double aYCart = myCartPointYMap[ thePointType ]->text().toDouble( &anIsOk[1] );
+
+ for( int i = 0; i < 2; i++ )
+ if( !anIsOk[ i ] )
+ return;
+
+ double aLonDeg = 0, aLatDeg = 0;
+ HYDROData_Lambert93::toGeo( aXCart, aYCart, aLatDeg, aLonDeg );
+
+ int aXDeg = 0, aYDeg = 0;
+ int aXMin = 0, aYMin = 0;
+ double aXSec = 0, aYSec = 0;
+ HYDROData_Lambert93::degToDMS( aLonDeg, aXDeg, aXMin, aXSec );
+ HYDROData_Lambert93::degToDMS( aLatDeg, aYDeg, aYMin, aYSec );
+
+ blockSignalsLambert( true );
+
+ myPointXDegMap[ thePointType ]->setValue( aXDeg );
+ myPointYDegMap[ thePointType ]->setValue( aYDeg );
+ myPointXMinMap[ thePointType ]->setValue( aXMin );
+ myPointYMinMap[ thePointType ]->setValue( aYMin );
+ myPointXSecMap[ thePointType ]->setValue( aXSec );
+ myPointYSecMap[ thePointType ]->setValue( aYSec );
+
+ blockSignalsLambert( false );
+}
+
+void HYDROGUI_ImportImageDlg::blockSignalsLambert( const bool theState )
+{
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ myPointXDegMap[ aPointType ]->blockSignals( theState );
+ myPointXMinMap[ aPointType ]->blockSignals( theState );
+ myPointXSecMap[ aPointType ]->blockSignals( theState );
+ myPointYDegMap[ aPointType ]->blockSignals( theState );
+ myPointYMinMap[ aPointType ]->blockSignals( theState );
+ myPointYSecMap[ aPointType ]->blockSignals( theState );
+ }
+}
+
+void HYDROGUI_ImportImageDlg::blockSignalsCartesian( const bool theState )
+{
+ for( int aPointType = HYDROGUI_PrsImage::PointA;
+ aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
+ {
+ myCartPointXMap[ aPointType ]->blockSignals( theState );
+ myCartPointYMap[ aPointType ]->blockSignals( theState );
+ }
+}