From 41f291766eb87fc4ed3871fc89d3371581b8014d Mon Sep 17 00:00:00 2001 From: ouv Date: Mon, 30 Sep 2013 14:00:59 +0000 Subject: [PATCH] Feature 32: Image positionning: cartesian coordinates. --- src/HYDROData/HYDROData_Image.cxx | 139 ++++++---- src/HYDROData/HYDROData_Image.h | 78 ++++-- src/HYDROData/HYDROData_Lambert93.cxx | 50 ++++ src/HYDROData/HYDROData_Lambert93.h | 53 ++-- src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx | 309 ++++++++++++++++++---- src/HYDROGUI/HYDROGUI_ImportImageDlg.h | 40 ++- src/HYDROGUI/HYDROGUI_ImportImageOp.cxx | 155 +++++++---- src/HYDROGUI/HYDROGUI_ImportImageOp.h | 1 + src/HYDROGUI/HYDROGUI_Module.cxx | 7 +- src/HYDROGUI/HYDROGUI_Tool.cxx | 23 -- src/HYDROGUI/HYDROGUI_Tool.h | 16 -- src/HYDROGUI/resources/HYDROGUI_msg_en.ts | 14 +- 12 files changed, 634 insertions(+), 251 deletions(-) diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 694e65f8..8a94d751 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -74,32 +75,44 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject // Dump transformation points for image aResList << QString( "" ); - QPoint aPointAIn, aPointBIn, aPointCIn; - QPointF aPointAOut, aPointBOut, aPointCOut; - TrsfPoints( aPointAIn, aPointBIn, aPointCIn, - aPointAOut, aPointBOut, aPointCOut ); + QPoint aPointA, aPointB, aPointC; + QPointF aLambertPointA, aLambertPointB, aLambertPointC; + QPointF aCartesianPointA, aCartesianPointB, aCartesianPointC; + TrsfPoints( aPointA, aPointB, aPointC, + aLambertPointA, aLambertPointB, aLambertPointC, + aCartesianPointA, aCartesianPointB, aCartesianPointC ); - aResList << QString( "a_in = QPoint( %1, %2 );" ) - .arg( aPointAIn.x() ).arg( aPointAIn.y() ); + aResList << QString( "pa = QPoint( %1, %2 );" ) + .arg( aPointA.x() ).arg( aPointA.y() ); - aResList << QString( "b_in = QPoint( %1, %2 );" ) - .arg( aPointBIn.x() ).arg( aPointBIn.y() ); + aResList << QString( "pb = QPoint( %1, %2 );" ) + .arg( aPointB.x() ).arg( aPointB.y() ); - aResList << QString( "c_in = QPoint( %1, %2 );" ) - .arg( aPointCIn.x() ).arg( aPointCIn.y() ); + aResList << QString( "pc = QPoint( %1, %2 );" ) + .arg( aPointC.x() ).arg( aPointC.y() ); - aResList << QString( "a_out = QPointF( %1, %2 );" ) - .arg( aPointAOut.x() ).arg( aPointAOut.y() ); + aResList << QString( "lpa = QPointF( %1, %2 );" ) + .arg( aLambertPointA.x() ).arg( aLambertPointA.y() ); - aResList << QString( "b_out = QPointF( %1, %2 );" ) - .arg( aPointBOut.x() ).arg( aPointBOut.y() ); + aResList << QString( "lpb = QPointF( %1, %2 );" ) + .arg( aLambertPointB.x() ).arg( aLambertPointB.y() ); - aResList << QString( "c_out = QPointF( %1, %2 );" ) - .arg( aPointCOut.x() ).arg( aPointCOut.y() ); + aResList << QString( "lpc = QPointF( %1, %2 );" ) + .arg( aLambertPointC.x() ).arg( aLambertPointC.y() ); + + aResList << QString( "cpa = QPointF( %1, %2 );" ) + .arg( aCartesianPointA.x() ).arg( aCartesianPointA.y() ); + + aResList << QString( "cpb = QPointF( %1, %2 );" ) + .arg( aCartesianPointB.x() ).arg( aCartesianPointB.y() ); + + aResList << QString( "cpc = QPointF( %1, %2 );" ) + .arg( aCartesianPointC.x() ).arg( aCartesianPointC.y() ); QString aGap = QString().fill( ' ', anImageName.size() + 16 ); - aResList << QString( "%1.SetTrsfPoints( a_in, b_in, c_in," ).arg( anImageName ); - aResList << QString( aGap + "a_out, b_out, c_out );" ); + aResList << QString( "%1.SetTrsfPoints( pa, pb, pc," ).arg( anImageName ); + aResList << QString( aGap + "lpa, lpb, lpc," ); + aResList << QString( aGap + "cpa, cpb, cpc );" ); } else { @@ -309,46 +322,61 @@ QTransform HYDROData_Image::Trsf() const return aTrsf; } -void HYDROData_Image::SetTrsfPoints(const QPoint& thePointAIn, - const QPoint& thePointBIn, - const QPoint& thePointCIn, - const QPointF& thePointAOut, - const QPointF& thePointBOut, - const QPointF& thePointCOut) +void HYDROData_Image::SetTrsfPoints(const QPoint& thePointA, + const QPoint& thePointB, + const QPoint& thePointC, + const QPointF& theLambertPointA, + const QPointF& theLambertPointB, + const QPointF& theLambertPointC, + const QPointF& theCartesianPointA, + const QPointF& theCartesianPointB, + const QPointF& theCartesianPointC) { Handle(TDataStd_RealArray) anArray; if (!myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray)) { - anArray = TDataStd_RealArray::Set(myLab.FindChild(DataTag_TrsfPoints), 1, 12); + anArray = TDataStd_RealArray::Set(myLab.FindChild(DataTag_TrsfPoints), 1, 18); } - anArray->SetValue(1, thePointAIn.x()); - anArray->SetValue(2, thePointAIn.y()); - anArray->SetValue(3, thePointBIn.x()); - anArray->SetValue(4, thePointBIn.y()); - anArray->SetValue(5, thePointCIn.x()); - anArray->SetValue(6, thePointCIn.y()); - anArray->SetValue(7, thePointAOut.x()); - anArray->SetValue(8, thePointAOut.y()); - anArray->SetValue(9, thePointBOut.x()); - anArray->SetValue(10, thePointBOut.y()); - anArray->SetValue(11, thePointCOut.x()); - anArray->SetValue(12, thePointCOut.y()); + anArray->SetValue(1, thePointA.x()); + anArray->SetValue(2, thePointA.y()); + anArray->SetValue(3, thePointB.x()); + anArray->SetValue(4, thePointB.y()); + anArray->SetValue(5, thePointC.x()); + anArray->SetValue(6, thePointC.y()); + anArray->SetValue(7, theLambertPointA.x()); + anArray->SetValue(8, theLambertPointA.y()); + anArray->SetValue(9, theLambertPointB.x()); + anArray->SetValue(10, theLambertPointB.y()); + anArray->SetValue(11, theLambertPointC.x()); + anArray->SetValue(12, theLambertPointC.y()); + anArray->SetValue(13, theCartesianPointA.x()); + anArray->SetValue(14, theCartesianPointA.y()); + anArray->SetValue(15, theCartesianPointB.x()); + anArray->SetValue(16, theCartesianPointB.y()); + anArray->SetValue(17, theCartesianPointC.x()); + anArray->SetValue(18, theCartesianPointC.y()); } -void HYDROData_Image::TrsfPoints(QPoint& thePointAIn, - QPoint& thePointBIn, - QPoint& thePointCIn, - QPointF& thePointAOut, - QPointF& thePointBOut, - QPointF& thePointCOut) const +void HYDROData_Image::TrsfPoints(QPoint& thePointA, + QPoint& thePointB, + QPoint& thePointC, + QPointF& theLambertPointA, + QPointF& theLambertPointB, + QPointF& theLambertPointC, + QPointF& theCartesianPointA, + QPointF& theCartesianPointB, + QPointF& theCartesianPointC) const { Handle(TDataStd_RealArray) anArray; if (myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray)) { - thePointAIn = QPointF( anArray->Value(1), anArray->Value(2) ).toPoint(); - thePointBIn = QPointF( anArray->Value(3), anArray->Value(4) ).toPoint(); - thePointCIn = QPointF( anArray->Value(5), anArray->Value(6) ).toPoint(); - thePointAOut = QPointF( anArray->Value(7), anArray->Value(8) ); - thePointBOut = QPointF( anArray->Value(9), anArray->Value(10) ); - thePointCOut = QPointF( anArray->Value(11), anArray->Value(12) ); + thePointA = QPointF( anArray->Value(1), anArray->Value(2) ).toPoint(); + thePointB = QPointF( anArray->Value(3), anArray->Value(4) ).toPoint(); + thePointC = QPointF( anArray->Value(5), anArray->Value(6) ).toPoint(); + theLambertPointA = QPointF( anArray->Value(7), anArray->Value(8) ); + theLambertPointB = QPointF( anArray->Value(9), anArray->Value(10) ); + theLambertPointC = QPointF( anArray->Value(11), anArray->Value(12) ); + theCartesianPointA = QPointF( anArray->Value(13), anArray->Value(14) ); + theCartesianPointB = QPointF( anArray->Value(15), anArray->Value(16) ); + theCartesianPointC = QPointF( anArray->Value(17), anArray->Value(18) ); } } @@ -358,6 +386,19 @@ bool HYDROData_Image::HasTrsfPoints() const return myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray); } +void HYDROData_Image::SetTrsfMode(const int theMode) +{ + TDataStd_Integer::Set(myLab.FindChild(DataTag_TrsfMode), theMode); +} + +int HYDROData_Image::TrsfMode() const +{ + Handle(TDataStd_Integer) aMode; + if(myLab.FindChild(DataTag_TrsfMode).FindAttribute(TDataStd_Integer::GetID(), aMode)) + return aMode->Get(); + return 0; +} + void HYDROData_Image::AppendReference( const Handle(HYDROData_Object)& theReferenced ) { AddReferenceObject( theReferenced, 0 ); diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index 16a691a6..ad598412 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -24,7 +24,8 @@ protected: { DataTag_First = HYDROData_Object::DataTag_First + 100, ///< first tag, to reserve DataTag_Operator, ///< name of the operator that must be executed for image update - DataTag_TrsfPoints, ///< image transformation points (3 input + 3 output) + DataTag_TrsfMode, ///< transformation mode (0 - Lambert93, 1 - Cartesian) + DataTag_TrsfPoints, ///< image transformation points (3 input + 3 output lambert + 3 output cartesian) DataTag_FilePath ///< image imported file path }; @@ -98,38 +99,63 @@ public: /** * Stores the image transformation points (3 input + 3 output) - * \param thePointAIn input point A - * \param thePointBIn input point B - * \param thePointCIn input point C - * \param thePointAOut output point A - * \param thePointBOut output point B - * \param thePointCOut output point C + * \param thePointA input point A + * \param thePointB input point B + * \param thePointC input point C + * \param theLambertPointA output point A in Lambert93 coordinates + * \param theLambertPointB output point B in Lambert93 coordinates + * \param theLambertPointC output point C in Lambert93 coordinates + * \param theCartesianPointA output point A in Cartesian coordinates + * \param theCartesianPointB output point B in Cartesian coordinates + * \param theCartesianPointC output point C in Cartesian coordinates */ - HYDRODATA_EXPORT void SetTrsfPoints(const QPoint& thePointAIn, - const QPoint& thePointBIn, - const QPoint& thePointCIn, - const QPointF& thePointAOut, - const QPointF& thePointBOut, - const QPointF& thePointCOut); + HYDRODATA_EXPORT void SetTrsfPoints(const QPoint& thePointA, + const QPoint& thePointB, + const QPoint& thePointC, + const QPointF& theLambertPointA, + const QPointF& theLambertPointB, + const QPointF& theLambertPointC, + const QPointF& theCartesianPointA, + const QPointF& theCartesianPointB, + const QPointF& theCartesianPointC); /** * Returns the image transformation points (3 input + 3 output) - * \param thePointAIn input point A - * \param thePointBIn input point B - * \param thePointCIn input point C - * \param thePointAOut output point A - * \param thePointBOut output point B - * \param thePointCOut output point C - */ - HYDRODATA_EXPORT void TrsfPoints(QPoint& thePointAIn, - QPoint& thePointBIn, - QPoint& thePointCIn, - QPointF& thePointAOut, - QPointF& thePointBOut, - QPointF& thePointCOut) const; + * \param thePointA input point A + * \param thePointB input point B + * \param thePointC input point C + * \param theLambertPointA output point A in Lambert93 coordinates + * \param theLambertPointB output point B in Lambert93 coordinates + * \param theLambertPointC output point C in Lambert93 coordinates + * \param theCartesianPointA output point A in Cartesian coordinates + * \param theCartesianPointB output point B in Cartesian coordinates + * \param theCartesianPointC output point C in Cartesian coordinates + */ + HYDRODATA_EXPORT void TrsfPoints(QPoint& thePointA, + QPoint& thePointB, + QPoint& thePointC, + QPointF& theLambertPointA, + QPointF& theLambertPointB, + QPointF& theLambertPointC, + QPointF& theCartesianPointA, + QPointF& theCartesianPointB, + QPointF& theCartesianPointC) const; + /** + * Returns true if the image has stored transformation points + */ HYDRODATA_EXPORT bool HasTrsfPoints() const; + /** + * Stores the transformation mode (0 - Lambert93, 1 - Cartesian) + */ + HYDRODATA_EXPORT void SetTrsfMode(const int theMode); + + /** + * Returns the transformation mode (0 - Lambert93, 1 - Cartesian) + */ + HYDRODATA_EXPORT int TrsfMode() const; + /** * Appends reference to other object (image or polyline). * \param theReferenced the object referenced by this diff --git a/src/HYDROData/HYDROData_Lambert93.cxx b/src/HYDROData/HYDROData_Lambert93.cxx index 504eab76..88390eb8 100755 --- a/src/HYDROData/HYDROData_Lambert93.cxx +++ b/src/HYDROData/HYDROData_Lambert93.cxx @@ -332,3 +332,53 @@ void HYDROData_Lambert93::toGeo( double theX, double theY, } +void HYDROData_Lambert93::DMSToDeg( int theDeg, + int theMin, + double theSec, + double& theDegOut ) +{ + double aCoef = theDeg > 0 ? 1.0 : -1.0; + + theDegOut = (double)theDeg; + theDegOut += aCoef * ( (double)theMin ) / 60.0; + theDegOut += aCoef * theSec / 3600.0; +} + +void HYDROData_Lambert93::DMSToSec( int theDeg, + int theMin, + double theSec, + double& theSecOut ) +{ + double aCoef = theDeg > 0 ? 1.0 : -1.0; + + theSecOut = theDeg * 3600.0; + theSecOut += aCoef * theMin * 60.0; + theSecOut += aCoef * theSec; +} + +void HYDROData_Lambert93::degToDMS( double theDegIn, + int& theDeg, + int& theMin, + double& theSec ) +{ + theDeg = int( theDegIn ); + + double aRemainder = fabs( theDegIn - theDeg ) * 60.0; + theMin = int( aRemainder ); + + aRemainder = ( aRemainder - theMin ) * 60.0; + theSec = aRemainder; +} + +void HYDROData_Lambert93::secToDMS( double theSecIn, + int& theDeg, + int& theMin, + double& theSec ) +{ + theDeg = int( theSecIn / 3600.0 ); + + double aRemainder = fabs( theSecIn - theDeg * 3600.0 ); + theMin = int( aRemainder / 60.0 ); + + theSec = fabs( aRemainder - theMin * 60.0 ); +} diff --git a/src/HYDROData/HYDROData_Lambert93.h b/src/HYDROData/HYDROData_Lambert93.h index f6e8a16c..b29d145d 100755 --- a/src/HYDROData/HYDROData_Lambert93.h +++ b/src/HYDROData/HYDROData_Lambert93.h @@ -1,44 +1,45 @@ - - #ifndef HYDROData_Lambert93_HeaderFile - #define HYDROData_Lambert93_HeaderFile - +#include class HYDROData_Lambert93 - { - public: + static double HYDRODATA_EXPORT toRad( double theDeg ); + static double HYDRODATA_EXPORT toDeg( double theRad ); - static double toRad( double theDeg ); - - static double toDeg( double theRad ); - + static void HYDRODATA_EXPORT toXY( double theLatitudeDeg, double theLongitudeDeg, + double& theX, double& theY ); + static void HYDRODATA_EXPORT toGeo( double theX, double theY, + double& theLatitudeDeg, double& theLongitudeDeg, + double theEps = 1e-5 ); - static void toXY( double theLatitudeDeg, double theLongitudeDeg, + static void HYDRODATA_EXPORT DMSToDeg( int theDeg, + int theMin, + double theSec, + double& theDegOut ); - double& theX, double& theY ); + static void HYDRODATA_EXPORT DMSToSec( int theDeg, + int theMin, + double theSec, + double& theSecOut ); - static void toGeo( double theX, double theY, + static void HYDRODATA_EXPORT degToDMS( double theDegIn, + int& theDeg, + int& theMin, + double& theSec ); - double& theLatitudeDeg, double& theLongitudeDeg, - - double theEps ); + static void HYDRODATA_EXPORT secToDMS( double theSecIn, + int& theDeg, + int& theMin, + double& theSec ); private: - - static double calc_rho( double phi ); - - static double calc_phi_inv( double rho, double eps ); - - static double calc_phi_ign( double rho, double eps ); - + static double calc_rho( double phi ); + static double calc_phi_inv( double rho, double eps ); + static double calc_phi_ign( double rho, double eps ); }; - - #endif - diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx index 8495a6bb..a8ccf8a5 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx @@ -25,6 +25,8 @@ #include "HYDROGUI_PrsImage.h" #include "HYDROGUI_Tool.h" +#include + #include #include #include @@ -45,7 +47,8 @@ #include HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle ) -: HYDROGUI_InputPanel( theModule, theTitle ) +: HYDROGUI_InputPanel( theModule, theTitle ), + myIsInitialized( false ) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); @@ -93,35 +96,30 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co aPainter.drawPixmap( 0, 0, anArrowPixmap ); aPainter.end(); - QRadioButton* aManualBtn = new QRadioButton( tr( "MANUALLY" ), myTransformGroup ); + QRadioButton* aManualLambertBtn = new QRadioButton( tr( "MANUALLY_LAMBERT93" ), myTransformGroup ); + QRadioButton* aManualCartesianBtn = new QRadioButton( tr( "MANUALLY_CARTESIAN" ), myTransformGroup ); QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup ); myModeGroup = new QButtonGroup( myTransformGroup ); - myModeGroup->addButton( aManualBtn, Manual ); + myModeGroup->addButton( aManualLambertBtn, ManualLambert ); + myModeGroup->addButton( aManualCartesianBtn, ManualCartesian ); myModeGroup->addButton( aRefImageBtn, RefImage ); - QBoxLayout* aModeLayout = new QHBoxLayout(); + myRefImage = new QComboBox( myTransformGroup ); + + QGridLayout* aModeLayout = new QGridLayout(); aModeLayout->setMargin( 0 ); aModeLayout->setSpacing( 5 ); - aModeLayout->addWidget( aManualBtn ); - aModeLayout->addWidget( aRefImageBtn ); - - myRefImageWg = new QWidget( myTransformGroup ); - QLabel* aRefImageLabel = new QLabel( tr( "REFERENCE_IMAGE" ), myRefImageWg ); - myRefImage = new QComboBox( myRefImageWg ); - - QBoxLayout* aRefImageLayout = new QHBoxLayout( myRefImageWg ); - aRefImageLayout->setMargin( 0 ); - aRefImageLayout->setSpacing( 5 ); - aRefImageLayout->addWidget( aRefImageLabel ); - aRefImageLayout->addWidget( myRefImage ); - aRefImageLayout->setStretch( 1, 1 ); + 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 ); - aTransformLayout->addWidget( myRefImageWg, 1, 0, 1, 9 ); for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ ) @@ -162,6 +160,9 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co 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 @@ -178,6 +179,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co 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 ); @@ -189,6 +191,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co 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 ) @@ -209,6 +212,9 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co myPointXSecMap[ aPointType ] = aPointXSec; myPointYSecMap[ aPointType ] = aPointYSec; + myCartPointXMap[ aPointType ] = aCartPointX; + myCartPointYMap[ aPointType ] = aCartPointY; + myRefPointXMap[ aPointType ] = aRefPointX; myRefPointYMap[ aPointType ] = aRefPointY; @@ -216,6 +222,17 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co 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 ) ) ); } @@ -238,7 +255,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co connect( myRefImage, SIGNAL( activated( const QString& ) ), this, SLOT( onRefImageActivated( const QString& ) ) ); - onModeActivated( Manual ); + setTransformationMode( ManualLambert ); setMinimumWidth( 350 ); } @@ -278,14 +295,18 @@ void HYDROGUI_ImportImageDlg::reset() myRefPointXMap[ aPointType ]->clear(); myRefPointYMap[ aPointType ]->clear(); + + myCartPointXMap[ aPointType ]->clear(); + myCartPointYMap[ aPointType ]->clear(); } myTransformGroup->setEnabled( false ); - myModeGroup->button( Manual )->setChecked( true ); myRefImage->clear(); - onModeActivated( Manual ); + setTransformationMode( ManualCartesian ); myPrsPointDataList.clear(); + + myIsInitialized = false; } void HYDROGUI_ImportImageDlg::setImageName( const QString& theName ) @@ -324,15 +345,23 @@ void HYDROGUI_ImportImageDlg::setImageSize( const QSize& theSize, } } +void HYDROGUI_ImportImageDlg::setTransformationMode( const int theMode ) +{ + myModeGroup->button( theMode )->setChecked( true ); + onModeActivated( theMode ); +} + int HYDROGUI_ImportImageDlg::getTransformationMode() const { - return myModeGroup->button( Manual )->isChecked() ? Manual : RefImage; + 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++ ) { @@ -342,17 +371,17 @@ void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationData QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ]; QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ]; - aPointX->setValue( aData.first.x() ); - aPointY->setValue( aData.first.y() ); + aPointX->setValue( aData.ImagePoint.x() ); + aPointY->setValue( aData.ImagePoint.y() ); if( !theIsOnlyInput && !theIsRefImage ) { - QPointF aPoint = aData.second; + QPointF aLPoint = aData.LambertPoint; int aXDeg = 0, aYDeg = 0; int aXMin = 0, aYMin = 0; double aXSec = 0, aYSec = 0; - HYDROGUI_Tool::DoubleToLambert( aPoint.x(), aXDeg, aXMin, aXSec ); - HYDROGUI_Tool::DoubleToLambert( aPoint.y(), aYDeg, aYMin, aYSec ); + HYDROData_Lambert93::secToDMS( aLPoint.x(), aXDeg, aXMin, aXSec ); + HYDROData_Lambert93::secToDMS( aLPoint.y(), aYDeg, aYMin, aYSec ); myPointXDegMap[ aPointType ]->setValue( aXDeg ); myPointYDegMap[ aPointType ]->setValue( aYDeg ); @@ -360,9 +389,15 @@ void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationData 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, @@ -372,8 +407,8 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t for( int aPointType = HYDROGUI_PrsImage::PointA; aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ ) { - bool anIsOk[8]; - for( int i = 0; i < 8; i++ ) + bool anIsOk[10]; + for( int i = 0; i < 10; i++ ) anIsOk[ i ] = true; QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ]; @@ -384,6 +419,7 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t 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] ); @@ -392,22 +428,30 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t 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 < 8; i++ ) + for( int i = 0; i < 10; i++ ) if( !anIsOk[ i ] ) return false; double aX2 = 0, aY2 = 0; - HYDROGUI_Tool::LambertToDouble( aXDeg, aXMin, aXSec, aX2 ); - HYDROGUI_Tool::LambertToDouble( aYDeg, aYMin, aYSec, aY2 ); + HYDROData_Lambert93::DMSToSec( aXDeg, aXMin, aXSec, aX2 ); + HYDROData_Lambert93::DMSToSec( aYDeg, aYMin, aYSec, aY2 ); - TransformationData aData( QPoint( aX1, aY1 ), QPointF( aX2, 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; @@ -429,9 +473,17 @@ void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theLi 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 ); @@ -452,6 +504,33 @@ void HYDROGUI_ImportImageDlg::initializePointSelection() 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; + + blockSignalsCartesian( true ); + + myCartPointXMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartX0 ); + myCartPointYMap[ HYDROGUI_PrsImage::PointA ]->setValue( aCartY0 ); + + myCartPointXMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartX0 + 1000 ); + myCartPointYMap[ HYDROGUI_PrsImage::PointB ]->setValue( aCartY0 ); + + myCartPointXMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartX0 ); + myCartPointYMap[ HYDROGUI_PrsImage::PointC ]->setValue( aCartY0 + 1000 ); + + for( int aPointType = HYDROGUI_PrsImage::PointA; + aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ ) + onCartesianCoordChanged( aPointType ); + + blockSignalsCartesian( false ); } void HYDROGUI_ImportImageDlg::onBrowse() @@ -473,26 +552,34 @@ void HYDROGUI_ImportImageDlg::onBrowse() void HYDROGUI_ImportImageDlg::onModeActivated( int theMode ) { - bool anIsManual = theMode == Manual; + 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++ ) { - myRefImageWg->setVisible( !anIsManual ); - - myPointXDegMap[ aPointType ]->setVisible( anIsManual ); - myPointYDegMap[ aPointType ]->setVisible( anIsManual ); - myPointXMinMap[ aPointType ]->setVisible( anIsManual ); - myPointYMinMap[ aPointType ]->setVisible( anIsManual ); - myPointXSecMap[ aPointType ]->setVisible( anIsManual ); - myPointYSecMap[ aPointType ]->setVisible( anIsManual ); - - myRefPointXMap[ aPointType ]->setVisible( !anIsManual ); - myRefPointYMap[ aPointType ]->setVisible( !anIsManual ); + 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 anIter( myLambertLabels ); while( anIter.hasNext() ) - anIter.next()->setVisible( anIsManual ); + anIter.next()->setVisible( anIsManualLambert ); + + emit modeActivated( theMode ); } void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName ) @@ -546,3 +633,133 @@ void HYDROGUI_ImportImageDlg::onPointCoordChanged( int 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 ); + } +} diff --git a/src/HYDROGUI/HYDROGUI_ImportImageDlg.h b/src/HYDROGUI/HYDROGUI_ImportImageDlg.h index 284f2999..c49bdac0 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageDlg.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageDlg.h @@ -41,10 +41,24 @@ class HYDROGUI_ImportImageDlg : public HYDROGUI_InputPanel Q_OBJECT public: - enum TransformationMode { Manual = 0, RefImage }; + enum TransformationMode { ManualLambert = 0, ManualCartesian, RefImage }; public: - typedef QPair< QPoint, QPointF > TransformationData; + struct TransformationData + { + QPoint ImagePoint; + QPointF LambertPoint; + QPointF CartesianPoint; + + TransformationData() {} + + TransformationData( const QPoint& theImagePoint, + const QPointF& theLambertPoint, + const QPointF& theCartesianPoint ) : + ImagePoint( theImagePoint ), + LambertPoint( theLambertPoint ), + CartesianPoint( theCartesianPoint ) {} + }; typedef QMap< int, TransformationData > TransformationDataMap; typedef QPair< QString, TransformationDataMap > PrsPointData; @@ -66,6 +80,7 @@ public: void setImageSize( const QSize& theSize, const bool theIsRefImage = false ); + void setTransformationMode( const int theMode ); int getTransformationMode() const; void setTransformationDataMap( const TransformationDataMap& theMap, @@ -74,6 +89,8 @@ public: bool getTransformationDataMap( TransformationDataMap& theMap, const bool theIsRefImage = false ) const; + QString getRefImageName() const; + void setPrsPointDataList( const PrsPointDataList& theList ); void initializePointSelection(); @@ -85,6 +102,16 @@ protected slots: void onPointBtnToggled( bool ); void onPointCoordChanged( int ); + void onLambertCoordChanged(); + void onLambertCoordChanged( const int thePointType ); + + void onCartesianCoordChanged(); + void onCartesianCoordChanged( const int thePointType ); + +private: + void blockSignalsLambert( const bool theState ); + void blockSignalsCartesian( const bool theState ); + signals: void createPreview( QImage ); void activatePointSelection( int ); @@ -92,6 +119,7 @@ signals: int thePointType, bool theIsY, int theValue ); + void modeActivated( int ); void refImageActivated( const QString& ); private: @@ -102,9 +130,8 @@ private: QLineEdit* myImageName; QGroupBox* myTransformGroup; - QButtonGroup* myModeGroup; - QWidget* myRefImageWg; + QButtonGroup* myModeGroup; QComboBox* myRefImage; QList myLambertLabels; @@ -119,10 +146,15 @@ private: QMap myPointXSecMap; QMap myPointYSecMap; + QMap myCartPointXMap; + QMap myCartPointYMap; + QMap myRefPointXMap; QMap myRefPointYMap; PrsPointDataList myPrsPointDataList; + + bool myIsInitialized; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx index 13fc3a79..5f73b4b0 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.cxx @@ -30,6 +30,7 @@ #include "HYDROGUI_UpdateFlags.h" #include +#include #include @@ -73,10 +74,17 @@ void HYDROGUI_ImportImageOp::startOperation() { QImage anImage = myEditedObject->Image(); + int aTransformationMode = myEditedObject->TrsfMode(); + if( aTransformationMode == HYDROGUI_ImportImageDlg::RefImage ) + aTransformationMode = HYDROGUI_ImportImageDlg::ManualCartesian; + aPanel->setTransformationMode( aTransformationMode ); + QPoint aPointA1, aPointB1, aPointC1; QPointF aPointA2, aPointB2, aPointC2; + QPointF aPointA3, aPointB3, aPointC3; myEditedObject->TrsfPoints( aPointA1, aPointB1, aPointC1, - aPointA2, aPointB2, aPointC2 ); + aPointA2, aPointB2, aPointC2, + aPointA3, aPointB3, aPointC3 ); onCreatePreview( anImage ); @@ -95,12 +103,12 @@ void HYDROGUI_ImportImageOp::startOperation() HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap; aDataMap[ HYDROGUI_PrsImage::PointA ] = - HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2 ); + HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2, aPointA3 ); aDataMap[ HYDROGUI_PrsImage::PointB ] = - HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2 ); + HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2, aPointB3 ); aDataMap[ HYDROGUI_PrsImage::PointC ] = - HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2 ); - ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap ); + HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2, aPointC3 ); + aPanel->setTransformationDataMap( aDataMap ); } } @@ -117,22 +125,24 @@ void HYDROGUI_ImportImageOp::startOperation() QPoint aPointA1, aPointB1, aPointC1; QPointF aPointA2, aPointB2, aPointC2; + QPointF aPointA3, aPointB3, aPointC3; anImageObj->TrsfPoints( aPointA1, aPointB1, aPointC1, - aPointA2, aPointB2, aPointC2 ); + aPointA2, aPointB2, aPointC2, + aPointA3, aPointB3, aPointC3 ); HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap; aDataMap[ HYDROGUI_PrsImage::PointA ] = - HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2 ); + HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2, aPointA3 ); aDataMap[ HYDROGUI_PrsImage::PointB ] = - HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2 ); + HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2, aPointB3 ); aDataMap[ HYDROGUI_PrsImage::PointC ] = - HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2 ); + HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2, aPointC3 ); HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap ); aPrsPointDataList.append( aPrsPointData ); } } - ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setPrsPointDataList( aPrsPointDataList ); + aPanel->setPrsPointDataList( aPrsPointDataList ); } void HYDROGUI_ImportImageOp::abortOperation() @@ -158,6 +168,8 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const this, SLOT( onActivatePointSelection( int ) ) ); connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ), this, SLOT( onPointCoordChanged( bool, int, bool, int ) ) ); + connect( aPanel, SIGNAL( modeActivated( int ) ), + this, SLOT( onModeActivated( int ) ) ); connect( aPanel, SIGNAL( refImageActivated( const QString& ) ), this, SLOT( onRefImageActivated( const QString& ) ) ); return aPanel; @@ -183,7 +195,8 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, } } - bool anIsRefImage = aPanel->getTransformationMode() == HYDROGUI_ImportImageDlg::RefImage; + int aTransformationMode = aPanel->getTransformationMode(); + bool anIsRefImage = aTransformationMode == HYDROGUI_ImportImageDlg::RefImage; HYDROGUI_ImportImageDlg::TransformationDataMap aMap; if( !aPanel->getTransformationDataMap( aMap ) ) @@ -193,60 +206,65 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, if( anIsRefImage && !aPanel->getTransformationDataMap( aRefMap, true ) ) return false; - QPoint aPointA1 = aMap[ HYDROGUI_PrsImage::PointA ].first; - QPoint aPointB1 = aMap[ HYDROGUI_PrsImage::PointB ].first; - QPoint aPointC1 = aMap[ HYDROGUI_PrsImage::PointC ].first; + QPoint aPointA = aMap[ HYDROGUI_PrsImage::PointA ].ImagePoint; + QPoint aPointB = aMap[ HYDROGUI_PrsImage::PointB ].ImagePoint; + QPoint aPointC = aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint; + + QPointF aLPointA = aMap[ HYDROGUI_PrsImage::PointA ].LambertPoint; + QPointF aLPointB = aMap[ HYDROGUI_PrsImage::PointB ].LambertPoint; + QPointF aLPointC = aMap[ HYDROGUI_PrsImage::PointC ].LambertPoint; - QPointF aPointA2 = aMap[ HYDROGUI_PrsImage::PointA ].second; - QPointF aPointB2 = aMap[ HYDROGUI_PrsImage::PointB ].second; - QPointF aPointC2 = aMap[ HYDROGUI_PrsImage::PointC ].second; + QPointF aCPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint; + QPointF aCPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint; + QPointF aCPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint; - QPoint aPointA3, aPointB3, aPointC3; + QPoint aRefPointA, aRefPointB, aRefPointC; if( anIsRefImage ) { - aPointA3 = aRefMap[ HYDROGUI_PrsImage::PointA ].first; - aPointB3 = aRefMap[ HYDROGUI_PrsImage::PointB ].first; - aPointC3 = aRefMap[ HYDROGUI_PrsImage::PointC ].first; + aRefPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint; + aRefPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint; + aRefPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint; } - int xa1 = aPointA1.x(); - int ya1 = aPointA1.y(); - int xb1 = aPointB1.x(); - int yb1 = aPointB1.y(); - int xc1 = aPointC1.x(); - int yc1 = aPointC1.y(); - - double xa2 = aPointA2.x(); - double ya2 = aPointA2.y(); - double xb2 = aPointB2.x(); - double yb2 = aPointB2.y(); - double xc2 = aPointC2.x(); - double yc2 = aPointC2.y(); - - int xa3 = aPointA3.x(); - int ya3 = aPointA3.y(); - int xb3 = aPointB3.x(); - int yb3 = aPointB3.y(); - int xc3 = aPointC3.x(); - int yc3 = aPointC3.y(); + int xa = aPointA.x(); + int ya = aPointA.y(); + int xb = aPointB.x(); + int yb = aPointB.y(); + int xc = aPointC.x(); + int yc = aPointC.y(); + + double xca = aCPointA.x(); + double yca = aCPointA.y(); + double xcb = aCPointB.x(); + double ycb = aCPointB.y(); + double xcc = aCPointC.x(); + double ycc = aCPointC.y(); + + int xra = aRefPointA.x(); + int yra = aRefPointA.y(); + int xrb = aRefPointB.x(); + int yrb = aRefPointB.y(); + int xrc = aRefPointC.x(); + int yrc = aRefPointC.y(); // first, check that three input points don't belong to a single line - if( ( yb1 - ya1 ) * ( xc1 - xa1 ) == ( yc1 - ya1 ) * ( xb1 - xa1 ) ) + if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) ) { theErrorMsg = tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ); return false; } // the same check for the reference points - if( anIsRefImage && ( ( yb3 - ya3 ) * ( xc3 - xa3 ) == ( yc3 - ya3 ) * ( xb3 - xa3 ) ) ) + if( anIsRefImage && + ( ( yrb - yra ) * ( xrc - xra ) == ( yrc - yra ) * ( xrb - xra ) ) ) { theErrorMsg = tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ); return false; } - QTransform aTransform1( xa1, ya1, 1, xb1, yb1, 1, xc1, yc1, 1 ); - QTransform aTransform2( xa2, ya2, 1, xb2, yb2, 1, xc2, yc2, 1 ); - QTransform aTransform3( xa3, ya3, 1, xb3, yb3, 1, xc3, yc3, 1 ); + QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 ); + QTransform aTransform2( xca, yca, 1, xcb, ycb, 1, xcc, ycc, 1 ); + QTransform aTransform3( xra, yra, 1, xrb, yrb, 1, xrc, yrc, 1 ); bool anIsInvertible = false; QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible ); @@ -278,13 +296,32 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags, if( anIsRefImage ) { - aPointA2 = QPointF( aTransform.map( aPointA1 ) ); - aPointB2 = QPointF( aTransform.map( aPointB1 ) ); - aPointC2 = QPointF( aTransform.map( aPointC1 ) ); + aCPointA = QPointF( aTransform.map( aPointA ) ); + aCPointB = QPointF( aTransform.map( aPointB ) ); + aCPointC = QPointF( aTransform.map( aPointC ) ); + + // compute Lambert93 points + xca = aCPointA.x(); + yca = aCPointA.y(); + xcb = aCPointB.x(); + ycb = aCPointB.y(); + xcc = aCPointC.x(); + ycc = aCPointC.y(); + + double xla = 0, yla = 0, xlb = 0, ylb = 0, xlc = 0, ylc = 0; + HYDROData_Lambert93::toGeo( xca, yca, yla, xla ); + HYDROData_Lambert93::toGeo( xcb, ycb, ylb, xlb ); + HYDROData_Lambert93::toGeo( xcc, ycc, ylc, xlc ); + + aLPointA = QPointF( xla * 3600.0, yla * 3600.0 ); // convert degrees to seconds + aLPointB = QPointF( xlb * 3600.0, ylb * 3600.0 ); // convert degrees to seconds + aLPointC = QPointF( xlc * 3600.0, ylc * 3600.0 ); // convert degrees to seconds } - anImageObj->SetTrsfPoints( aPointA1, aPointB1, aPointC1, - aPointA2, aPointB2, aPointC2 ); + anImageObj->SetTrsfMode( aTransformationMode ); + anImageObj->SetTrsfPoints( aPointA, aPointB, aPointC, + aLPointA, aLPointB, aLPointC, + aCPointA, aCPointB, aCPointC ); if( !myIsEdit ) { @@ -401,6 +438,20 @@ void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef, myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue ); } +void HYDROGUI_ImportImageOp::onModeActivated( int theMode ) +{ + HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel(); + + QString aRefImageName; + if( theMode == HYDROGUI_ImportImageDlg::RefImage ) + { + aRefImageName = aPanel->getRefImageName(); + if( aRefImageName.isEmpty() ) + return; // do nothing in this case to avoid visual moving of preview prs + } + onRefImageActivated( aRefImageName ); +} + void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName ) { myRefTransform.reset(); @@ -490,7 +541,7 @@ void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage ) const HYDROGUI_PrsImage::TransformationPoint& aTransformationPoint = anIter.value(); const QPoint& aPoint = aTransformationPoint.Point; - HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF() ); + HYDROGUI_ImportImageDlg::TransformationData aData( aPoint, QPointF(), QPointF() ); aDataMap[ aPointType ] = aData; } diff --git a/src/HYDROGUI/HYDROGUI_ImportImageOp.h b/src/HYDROGUI/HYDROGUI_ImportImageOp.h index 67be1e10..5a94c44c 100644 --- a/src/HYDROGUI/HYDROGUI_ImportImageOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportImageOp.h @@ -56,6 +56,7 @@ protected slots: void onCreatePreview( QImage ); void onActivatePointSelection( int ); void onPointCoordChanged( bool, int, bool, int ); + void onModeActivated( int ); void onRefImageActivated( const QString& ); void onLastViewClosed( SUIT_ViewManager* ); diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 81b8786f..43e1b1ec 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -37,6 +37,7 @@ #include "HYDROGUI_Shape.h" #include +#include #include @@ -729,6 +730,7 @@ void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow ) void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent ) { + /* ouv: currently unused if( GraphicsView_ViewPort* aViewPort = qobject_cast( sender() ) ) { SUIT_ViewManager* aViewManager = 0; @@ -758,8 +760,8 @@ void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent ) int aXDeg = 0, aYDeg = 0; int aXMin = 0, aYMin = 0; double aXSec = 0, aYSec = 0; - HYDROGUI_Tool::DoubleToLambert( aMouseX, aXDeg, aXMin, aXSec ); - HYDROGUI_Tool::DoubleToLambert( aMouseY, aYDeg, aYMin, aYSec ); + HYDROData_Lambert93::secToDMS( aMouseX, aXDeg, aXMin, aXSec ); + HYDROData_Lambert93::secToDMS( aMouseY, aYDeg, aYMin, aYSec ); QString aDegSymbol( QChar( 0x00B0 ) ); QString aXStr = QString( "%1%2 %3' %4\"" ).arg( aXDeg ).arg( aDegSymbol ).arg( aXMin ).arg( aXSec ); @@ -770,6 +772,7 @@ void HYDROGUI_Module::onViewPortMouseEvent( QGraphicsSceneMouseEvent* theEvent ) else if( aRole == VMR_TransformImage ) aViewPort->setViewLabelText( QString( "X: %1\nY: %2" ).arg( (int)aMouseX ).arg( (int)aMouseY ) ); } + */ } void HYDROGUI_Module::updateGV( const bool theIsInit, diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index ac76bb18..27d50dcb 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -134,29 +134,6 @@ Handle(TCollection_HExtendedString) HYDROGUI_Tool::ToHExtString( const QString& return new TCollection_HExtendedString( ToExtString( src ) ); } -void HYDROGUI_Tool::LambertToDouble( const int theDegrees, - const int theMinutes, - const double theSeconds, - double& theCoord ) -{ - // ouv: check the case of negative degrees - theCoord = theDegrees * 3600 + theMinutes * 60 + theSeconds; -} - -void HYDROGUI_Tool::DoubleToLambert( const double theCoord, - int& theDegrees, - int& theMinutes, - double& theSeconds ) -{ - // ouv: check the case of negative degrees - theDegrees = int( theCoord / 3600 ); - - double aRemainder = theCoord - theDegrees * 3600; - theMinutes = int( aRemainder / 60 ); - - theSeconds = aRemainder - theMinutes * 60; -} - bool HYDROGUI_Tool::IsEqual( const Handle(HYDROData_Object)& theObj1, const Handle(HYDROData_Object)& theObj2 ) { diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index cb77fb75..fc60e3b5 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -88,22 +88,6 @@ public: */ static Handle(TCollection_HExtendedString) ToHExtString( const QString& ); - /** - * \brief Encode the Lambert93 coordinates to the absolute double value - */ - static void LambertToDouble( const int theDegrees, - const int theMinutes, - const double theSeconds, - double& theCoord ); - - /** - * \brief Decode the Lambert93 coordinates from the absolute double value - */ - static void DoubleToLambert( const double theCoord, - int& theDegrees, - int& theMinutes, - double& theSeconds ); - /** * \brief Check that the specified objects are equal. * \param theObj1 first object diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index d25a7c59..2a584178 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -229,7 +229,7 @@ file cannot be correctly imported for a Bathymetry definition. BY_REFERENCE_IMAGE - By reference image + Choose points on the reference image FILE_NAME @@ -244,16 +244,16 @@ file cannot be correctly imported for a Bathymetry definition. Import image from file - MANUALLY - Manually + MANUALLY_CARTESIAN + Manually input Cartesian coordinates - NAME - Name + MANUALLY_LAMBERT93 + Manually input Lambert93 coordinates - REFERENCE_IMAGE - Reference image + NAME + Name TRANSFORM_IMAGE -- 2.39.2