]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
HYDRO Feature 1: Import images (T 1.3)
authorouv <ouv@opencascade.com>
Fri, 30 Aug 2013 11:20:39 +0000 (11:20 +0000)
committerouv <ouv@opencascade.com>
Fri, 30 Aug 2013 11:20:39 +0000 (11:20 +0000)
Importing image using the reference image.

src/HYDROGUI/HYDROGUI_ExportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx
src/HYDROGUI/HYDROGUI_ImportImageDlg.h
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/HYDROGUI_PrsImage.cxx
src/HYDROGUI/HYDROGUI_PrsImage.h
src/HYDROGUI/HYDROGUI_Tool.cxx
src/HYDROGUI/HYDROGUI_Tool.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index f8b7c7e25febba6133c119a799201cba2b0d9e20..d4b3fccf7553d6f58accb439e7ec6b27a08feac6 100644 (file)
@@ -30,8 +30,7 @@
 #include <LightApp_Application.h>
 
 #include <SUIT_Desktop.h>
-
-#include <QFileDialog>
+#include <SUIT_FileDlg.h>
 
 HYDROGUI_ExportImageOp::HYDROGUI_ExportImageOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -57,8 +56,8 @@ void HYDROGUI_ExportImageOp::startOperation()
     anImage = anImage.transformed( aTransform, Qt::SmoothTransformation );
 
     QString aFilter( tr( "IMAGE_FILTER" ) );
-    QString aFileName = QFileDialog::getSaveFileName( module()->getApp()->desktop(),
-                                                      tr( "BROWSE_IMAGE_FILE" ), "", aFilter );
+    QString aFileName = SUIT_FileDlg::getFileName( module()->getApp()->desktop(),
+                                                   "", aFilter, tr( "EXPORT_IMAGE_TO_FILE" ), false );
     if( !aFileName.isEmpty() )
       anImage.save( aFileName );
   }
index aed5f97c1262d89e19a32b9bad89a95b32e8ef30..d8da72045970f14d399a9d08b5e169b717b773af 100644 (file)
 #include "HYDROGUI_PrsImage.h"
 #include "HYDROGUI_Tool.h"
 
+#include <SUIT_FileDlg.h>
 #include <SUIT_ResourceMgr.h>
 #include <SUIT_Session.h>
 
-#include <QDoubleValidator>
-#include <QFileDialog>
+#include <QtxDoubleSpinBox.h>
+#include <QtxIntSpinBox.h>
+
+#include <QButtonGroup>
+#include <QComboBox>
 #include <QGroupBox>
-#include <QIntValidator>
 #include <QLabel>
 #include <QLayout>
 #include <QLineEdit>
 #include <QPainter>
 #include <QPicture>
 #include <QPushButton>
+#include <QRadioButton>
 #include <QToolButton>
 
 HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle )
@@ -75,12 +79,8 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   anImageNameLayout->addWidget( anImageNameLabel );
   anImageNameLayout->addWidget( myImageName );
 
-  // Mapping (transform image)
-  myMappingGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ) );
-
-  QGridLayout* aMappingLayout = new QGridLayout( myMappingGroup );
-  aMappingLayout->setMargin( 5 );
-  aMappingLayout->setSpacing( 5 );
+  // Transform image
+  myTransformGroup = new QGroupBox( tr( "TRANSFORM_IMAGE" ) );
 
   // Make a pixmap for arrow
   QPixmap anArrowPixmap = aResMgr->loadPixmap( "HYDRO", tr( "ARROW_RIGHT_ICO" ) );
@@ -93,6 +93,36 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   aPainter.drawPixmap( 0, 0, anArrowPixmap );
   aPainter.end();
 
+  QRadioButton* aManualBtn = new QRadioButton( tr( "MANUALLY" ), myTransformGroup );
+  QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
+
+  myModeGroup = new QButtonGroup( myTransformGroup );
+  myModeGroup->addButton( aManualBtn, Manual );
+  myModeGroup->addButton( aRefImageBtn, RefImage );
+
+  QBoxLayout* aModeLayout = new QHBoxLayout();
+  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 );
+
+  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++ )
   {
@@ -103,76 +133,70 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
       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, myMappingGroup );
+    QPushButton* aPointBtn = new QPushButton( aPointStr, myTransformGroup );
     aPointBtn->setCheckable( true );
 
-    QLabel* aPointXLabel = new QLabel( "X", myMappingGroup );
-    QLabel* aPointYLabel = new QLabel( "Y", myMappingGroup );
-
-    QLineEdit* aPointX = new QLineEdit( myMappingGroup );
-    QLineEdit* aPointY = new QLineEdit( myMappingGroup );
+    QLabel* aPointXLabel = new QLabel( "X", myTransformGroup );
+    QLabel* aPointYLabel = new QLabel( "Y", myTransformGroup );
 
-    aPointX->setReadOnly( true );
-    aPointY->setReadOnly( true );
+    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( ">", myMappingGroup );
-    QLabel* aPointArrowLabel = new QLabel( myMappingGroup );
+    QLabel* aPointArrowLabel = new QLabel( myTransformGroup );
     aPointArrowLabel->setPicture( anArrowPicture );
 
-    QLabel* aPointXDegLabel = new QLabel( QChar( 0x00B0 ), myMappingGroup );
-    QLabel* aPointYDegLabel = new QLabel( QChar( 0x00B0 ), myMappingGroup );
-    QLabel* aPointXMinLabel = new QLabel( "'", myMappingGroup );
-    QLabel* aPointYMinLabel = new QLabel( "'", myMappingGroup );
-    QLabel* aPointXSecLabel = new QLabel( "\"", myMappingGroup );
-    QLabel* aPointYSecLabel = new QLabel( "\"", myMappingGroup );
-
-    QLineEdit* aPointXDeg = new QLineEdit( myMappingGroup );
-    QLineEdit* aPointYDeg = new QLineEdit( myMappingGroup );
-    QLineEdit* aPointXMin = new QLineEdit( myMappingGroup );
-    QLineEdit* aPointYMin = new QLineEdit( myMappingGroup );
-    QLineEdit* aPointXSec = new QLineEdit( myMappingGroup );
-    QLineEdit* aPointYSec = new QLineEdit( myMappingGroup );
-
-    QIntValidator* aXDegValidator = new QIntValidator( -180, 180, this );
-    QIntValidator* aYDegValidator = new QIntValidator( -90, 90, this );
-    QIntValidator* aMinValidator = new QIntValidator( 0, 59, this );
-    QDoubleValidator* aSecValidator = new QDoubleValidator( 0, 59.9999, 4, this );
-
-    aPointXDeg->setValidator( aXDegValidator );
-    aPointYDeg->setValidator( aYDegValidator );
-    aPointXMin->setValidator( aMinValidator );
-    aPointYMin->setValidator( aMinValidator );
-    aPointXSec->setValidator( aSecValidator );
-    aPointYSec->setValidator( aSecValidator );
-
-    int aRow = 4 * aPointType;
-    aMappingLayout->addWidget( aPointBtn,        aRow,     0, 1, 9 );
-
-    aMappingLayout->addWidget( aPointXLabel,     aRow + 1, 0 );
-    aMappingLayout->addWidget( aPointX,          aRow + 1, 1 );
-    aMappingLayout->addWidget( aPointArrowLabel, aRow + 1, 2, 2, 1 );
-    aMappingLayout->addWidget( aPointXDeg,       aRow + 1, 3 );
-    aMappingLayout->addWidget( aPointXDegLabel,  aRow + 1, 4 );
-    aMappingLayout->addWidget( aPointXMin,       aRow + 1, 5 );
-    aMappingLayout->addWidget( aPointXMinLabel,  aRow + 1, 6 );
-    aMappingLayout->addWidget( aPointXSec,       aRow + 1, 7 );
-    aMappingLayout->addWidget( aPointXSecLabel,  aRow + 1, 8 );
-
-    aMappingLayout->addWidget( aPointYLabel,     aRow + 2, 0 );
-    aMappingLayout->addWidget( aPointY,          aRow + 2, 1 );
-    aMappingLayout->addWidget( aPointYDeg,       aRow + 2, 3 );
-    aMappingLayout->addWidget( aPointYDegLabel,  aRow + 2, 4 );
-    aMappingLayout->addWidget( aPointYMin,       aRow + 2, 5 );
-    aMappingLayout->addWidget( aPointYMinLabel,  aRow + 2, 6 );
-    aMappingLayout->addWidget( aPointYSec,       aRow + 2, 7 );
-    aMappingLayout->addWidget( aPointYSecLabel,  aRow + 2, 8 );
+    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 );
+
+    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 + 2;
+    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( 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( aRefPointY,       aRow + 2, 3, 1, 6 );
 
     if( aPointType != HYDROGUI_PrsImage::PointC )
     {
-      QFrame* aLine = new QFrame( myMappingGroup );
+      QFrame* aLine = new QFrame( myTransformGroup );
       aLine->setFrameShape( QFrame::HLine );
       aLine->setFrameShadow( QFrame::Sunken );
-      aMappingLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
+      aTransformLayout->addWidget( aLine, aRow + 3, 0, 1, 9 );
     }
 
     myPointBtnMap[ aPointType ] = aPointBtn;
@@ -185,20 +209,38 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
     myPointXSecMap[ aPointType ] = aPointXSec;
     myPointYSecMap[ aPointType ] = aPointYSec;
 
+    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( aRefPointX, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
+    connect( aRefPointY, SIGNAL( valueChanged( int ) ), this, SLOT( onPointCoordChanged( int ) ) );
   }
-  aMappingLayout->setColumnStretch( 1, 1 ); // x
-  aMappingLayout->setColumnStretch( 3, 1 ); // degrees
-  aMappingLayout->setColumnStretch( 5, 1 ); // minutes
-  aMappingLayout->setColumnStretch( 7, 2 ); // seconds (double with 4 digits)
+  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( myMappingGroup );
+  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& ) ) );
+
+  onModeActivated( Manual );
+
+  setMinimumWidth( 350 );
 }
 
 HYDROGUI_ImportImageDlg::~HYDROGUI_ImportImageDlg()
@@ -209,7 +251,7 @@ void HYDROGUI_ImportImageDlg::setIsEdit( const bool theIsEdit )
 {
   myFileNameGroup->setVisible( !theIsEdit );
   myImageNameGroup->setEnabled( theIsEdit );
-  myMappingGroup->setEnabled( theIsEdit );
+  myTransformGroup->setEnabled( theIsEdit );
 }
 
 void HYDROGUI_ImportImageDlg::reset()
@@ -233,8 +275,17 @@ void HYDROGUI_ImportImageDlg::reset()
     myPointYMinMap[ aPointType ]->clear();
     myPointXSecMap[ aPointType ]->clear();
     myPointYSecMap[ aPointType ]->clear();
+
+    myRefPointXMap[ aPointType ]->clear();
+    myRefPointYMap[ aPointType ]->clear();
   }
-  myMappingGroup->setEnabled( false );
+  myTransformGroup->setEnabled( false );
+  myModeGroup->button( Manual )->setChecked( true );
+  myRefImage->clear();
+
+  onModeActivated( Manual );
+
+  myPrsPointDataList.clear();
 }
 
 void HYDROGUI_ImportImageDlg::setImageName( const QString& theName )
@@ -247,8 +298,35 @@ QString HYDROGUI_ImportImageDlg::getImageName() const
   return myImageName->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 );
+    }
+  }
+}
+
+int HYDROGUI_ImportImageDlg::getTransformationMode() const
+{
+  return myModeGroup->button( Manual )->isChecked() ? Manual : RefImage;
+}
+
 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
-                                                        const bool theIsOnlyInput )
+                                                        const bool theIsOnlyInput,
+                                                        const bool theIsRefImage )
 {
   for( int aPointType = HYDROGUI_PrsImage::PointA;
        aPointType <= HYDROGUI_PrsImage::PointC; aPointType++ )
@@ -256,10 +334,13 @@ void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationData
     if( theMap.contains( aPointType ) )
     {
       const TransformationData& aData = theMap[ aPointType ];
-      myPointXMap[ aPointType ]->setText( QString::number( aData.first.x() ) );
-      myPointYMap[ aPointType ]->setText( QString::number( aData.first.y() ) );
 
-      if( !theIsOnlyInput )
+      QtxIntSpinBox* aPointX = theIsRefImage ? myRefPointXMap[ aPointType ] : myPointXMap[ aPointType ];
+      QtxIntSpinBox* aPointY = theIsRefImage ? myRefPointYMap[ aPointType ] : myPointYMap[ aPointType ];
+      aPointX->setValue( aData.first.x() );
+      aPointY->setValue( aData.first.y() );
+
+      if( !theIsOnlyInput && !theIsRefImage )
       {
         QPointF aPoint = aData.second;
         int aXDeg = 0, aYDeg = 0;
@@ -268,18 +349,19 @@ void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationData
         HYDROGUI_Tool::DoubleToLambert( aPoint.x(), aXDeg, aXMin, aXSec );
         HYDROGUI_Tool::DoubleToLambert( aPoint.y(), aYDeg, aYMin, aYSec );
 
-        myPointXDegMap[ aPointType ]->setText( QString::number( aXDeg ) );
-        myPointYDegMap[ aPointType ]->setText( QString::number( aYDeg ) );
-        myPointXMinMap[ aPointType ]->setText( QString::number( aXMin ) );
-        myPointYMinMap[ aPointType ]->setText( QString::number( aYMin ) );
-        myPointXSecMap[ aPointType ]->setText( QString::number( aXSec ) );
-        myPointYSecMap[ aPointType ]->setText( QString::number( 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 );
       }
     }
   }
 }
 
-bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap ) const
+bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& theMap,
+                                                        const bool theIsRefImage ) const
 {
   theMap.clear();
   for( int aPointType = HYDROGUI_PrsImage::PointA;
@@ -287,16 +369,25 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t
   {
     bool anIsOk[8];
     for( int i = 0; i < 8; i++ )
-      anIsOk[ i ] = false;
+      anIsOk[ i ] = true;
 
-    int aX1 = myPointXMap[ aPointType ]->text().toInt( &anIsOk[0] );
-    int aY1 = myPointYMap[ aPointType ]->text().toInt( &anIsOk[1] );
-    int aXDeg = myPointXDegMap[ aPointType ]->text().toInt( &anIsOk[2] );
-    int aYDeg = myPointYDegMap[ aPointType ]->text().toInt( &anIsOk[3] );
-    int aXMin = myPointXMinMap[ aPointType ]->text().toInt( &anIsOk[4] );
-    int aYMin = myPointYMinMap[ aPointType ]->text().toInt( &anIsOk[5] );
-    double aXSec = myPointXSecMap[ aPointType ]->text().toDouble( &anIsOk[6] );
-    double aYSec = myPointYSecMap[ aPointType ]->text().toDouble( &anIsOk[7] );
+    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;
+    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] );
+    }
 
     for( int i = 0; i < 8; i++ )
       if( !anIsOk[ i ] )
@@ -312,37 +403,56 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t
   return true;
 }
 
+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()
 {
   myPointBtnMap[ HYDROGUI_PrsImage::PointA ]->setChecked( true );
 
   // ouv: tmp
-  myPointXDegMap[ HYDROGUI_PrsImage::PointA ]->setText( "50" );
-  myPointXMinMap[ HYDROGUI_PrsImage::PointA ]->setText( "0" );
-  myPointXSecMap[ HYDROGUI_PrsImage::PointA ]->setText( "0" );
-  myPointYDegMap[ HYDROGUI_PrsImage::PointA ]->setText( "50" );
-  myPointYMinMap[ HYDROGUI_PrsImage::PointA ]->setText( "0" );
-  myPointYSecMap[ HYDROGUI_PrsImage::PointA ]->setText( "0" );
-
-  myPointXDegMap[ HYDROGUI_PrsImage::PointB ]->setText( "50" );
-  myPointXMinMap[ HYDROGUI_PrsImage::PointB ]->setText( "1" );
-  myPointXSecMap[ HYDROGUI_PrsImage::PointB ]->setText( "0" );
-  myPointYDegMap[ HYDROGUI_PrsImage::PointB ]->setText( "50" );
-  myPointYMinMap[ HYDROGUI_PrsImage::PointB ]->setText( "0" );
-  myPointYSecMap[ HYDROGUI_PrsImage::PointB ]->setText( "0" );
-
-  myPointXDegMap[ HYDROGUI_PrsImage::PointC ]->setText( "50" );
-  myPointXMinMap[ HYDROGUI_PrsImage::PointC ]->setText( "0" );
-  myPointXSecMap[ HYDROGUI_PrsImage::PointC ]->setText( "0" );
-  myPointYDegMap[ HYDROGUI_PrsImage::PointC ]->setText( "50" );
-  myPointYMinMap[ HYDROGUI_PrsImage::PointC ]->setText( "1" );
-  myPointYSecMap[ HYDROGUI_PrsImage::PointC ]->setText( "0" );
+  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 );
 }
 
 void HYDROGUI_ImportImageDlg::onBrowse()
 {
   QString aFilter( tr( "IMAGE_FILTER" ) );
-  QString aFileName = QFileDialog::getOpenFileName( this, tr( "IMPORT_IMAGE_FROM_FILE" ), "", aFilter );
+  QString aFileName = SUIT_FileDlg::getFileName( this, "", aFilter, tr( "IMPORT_IMAGE_FROM_FILE" ), true );
   //QString aFileName = "W:/Work/HYDRO/doc/samples/1.bmp";
   if( !aFileName.isEmpty() )
   {
@@ -352,11 +462,40 @@ void HYDROGUI_ImportImageDlg::onBrowse()
       myFileName->setText( aFileName );
       emit createPreview( anImage );
       myImageNameGroup->setEnabled( true );
-      myMappingGroup->setEnabled( true );
+      myTransformGroup->setEnabled( true );
     }
   }
 }
 
+void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
+{
+  bool anIsManual = theMode == Manual;
+  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 );
+  }
+
+  QListIterator<QLabel*> anIter( myLambertLabels );
+  while( anIter.hasNext() )
+    anIter.next()->setVisible( anIsManual );
+}
+
+void HYDROGUI_ImportImageDlg::onRefImageActivated( const QString& theName )
+{
+  emit refImageActivated( theName );
+}
+
 void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
 {
   int aPointType = HYDROGUI_PrsImage::None;
@@ -379,3 +518,27 @@ void HYDROGUI_ImportImageDlg::onPointBtnToggled( bool theState )
   }
   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 );
+    }
+  }
+}
index 752a520182bc83bf16e1b7bfd9a3579db9e932ae..18e8b54c66b0f7d44808754e352ea606b9c20ad6 100644 (file)
 
 #include <QMap>
 
+class QButtonGroup;
+class QComboBox;
 class QGroupBox;
+class QLabel;
 class QLineEdit;
 
+class QtxDoubleSpinBox;
+class QtxIntSpinBox;
+
 class HYDROGUI_ImportImageDlg : public HYDROGUI_InputPanel
 {
   Q_OBJECT
 
+public:
+  enum TransformationMode { Manual = 0, RefImage };
+
 public:
   typedef QPair< QPoint, QPointF >        TransformationData;
   typedef QMap< int, TransformationData > TransformationDataMap;
 
+  typedef QPair< QString, TransformationDataMap > PrsPointData;
+  typedef QList< PrsPointData >                   PrsPointDataList;
+  typedef QListIterator< PrsPointData >           PrsPointDataListIterator;
+
 public:
   HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, const QString& theTitle );
   virtual ~HYDROGUI_ImportImageDlg();
@@ -48,19 +61,36 @@ public:
   void                       setImageName( const QString& theName );
   QString                    getImageName() const;
 
+  void                       setImageSize( const QSize& theSize,
+                                           const bool theIsRefImage = false );
+
+  int                        getTransformationMode() const;
+
   void                       setTransformationDataMap( const TransformationDataMap& theMap,
-                                                       const bool theIsOnlyInput = false );
-  bool                       getTransformationDataMap( TransformationDataMap& theMap ) const;
+                                                       const bool theIsOnlyInput = false,
+                                                       const bool theIsRefImage = false );
+  bool                       getTransformationDataMap( TransformationDataMap& theMap,
+                                                       const bool theIsRefImage = false ) const;
+
+  void                       setPrsPointDataList( const PrsPointDataList& theList );
 
   void                       initializePointSelection();
 
 protected slots:
   void                       onBrowse();
+  void                       onModeActivated( int );
+  void                       onRefImageActivated( const QString& );
   void                       onPointBtnToggled( bool );
+  void                       onPointCoordChanged( int );
 
 signals:
   void                       createPreview( QImage );
   void                       activatePointSelection( int );
+  void                       pointCoordChanged( bool theIsRef,
+                                                int thePointType,
+                                                bool theIsY,
+                                                int theValue );
+  void                       refImageActivated( const QString& );
 
 private:
   QGroupBox*                 myFileNameGroup;
@@ -69,16 +99,28 @@ private:
   QGroupBox*                 myImageNameGroup;
   QLineEdit*                 myImageName;
 
-  QGroupBox*                 myMappingGroup;
+  QGroupBox*                 myTransformGroup;
+  QButtonGroup*              myModeGroup;
+
+  QWidget*                   myRefImageWg;
+  QComboBox*                 myRefImage;
+
+  QList<QLabel*>             myLambertLabels;
+
   QMap<int, QPushButton*>    myPointBtnMap;
-  QMap<int, QLineEdit*>      myPointXMap;
-  QMap<int, QLineEdit*>      myPointYMap;
-  QMap<int, QLineEdit*>      myPointXDegMap;
-  QMap<int, QLineEdit*>      myPointYDegMap;
-  QMap<int, QLineEdit*>      myPointXMinMap;
-  QMap<int, QLineEdit*>      myPointYMinMap;
-  QMap<int, QLineEdit*>      myPointXSecMap;
-  QMap<int, QLineEdit*>      myPointYSecMap;
+  QMap<int, QtxIntSpinBox*>  myPointXMap;
+  QMap<int, QtxIntSpinBox*>  myPointYMap;
+  QMap<int, QtxIntSpinBox*>  myPointXDegMap;
+  QMap<int, QtxIntSpinBox*>  myPointYDegMap;
+  QMap<int, QtxIntSpinBox*>  myPointXMinMap;
+  QMap<int, QtxIntSpinBox*>  myPointYMinMap;
+  QMap<int, QtxDoubleSpinBox*> myPointXSecMap;
+  QMap<int, QtxDoubleSpinBox*> myPointYSecMap;
+
+  QMap<int, QtxIntSpinBox*>  myRefPointXMap;
+  QMap<int, QtxIntSpinBox*>  myRefPointYMap;
+
+  PrsPointDataList           myPrsPointDataList;
 };
 
 #endif
index c31e50843f7eee8f5b0f31b781b9b5c1ad04c98d..6f76353e86a60be6d4d1489c3dde81774878aacb 100644 (file)
@@ -29,6 +29,8 @@
 #include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
+#include <HYDROData_Iterator.h>
+
 #include <GraphicsView_ViewManager.h>
 #include <GraphicsView_ViewPort.h>
 #include <GraphicsView_Viewer.h>
@@ -44,6 +46,7 @@ HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
   myActiveViewManager( 0 ),
   myPreviewViewManager( 0 ),
   myPreviewPrs( 0 ),
+  myRefPreviewPrs( 0 ),
   myPointType( HYDROGUI_PrsImage::None )
 {
   setName( theIsEdit ? tr( "EDIT_IMPORTED_IMAGE" ) : tr( "IMPORT_IMAGE" ) );
@@ -98,6 +101,36 @@ void HYDROGUI_ImportImageOp::startOperation()
       ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap );
     }
   }
+
+  // collect information about existing images
+  HYDROGUI_ImportImageDlg::PrsPointDataList aPrsPointDataList;
+  HYDROData_Iterator anIterator( doc(), KIND_IMAGE );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast( anIterator.Current() );
+    if( !anImageObj.IsNull() )
+    {
+      if( myIsEdit && HYDROGUI_Tool::IsEqual( anImageObj, myEditedObject ) )
+        continue;
+
+      QPoint aPointA1, aPointB1, aPointC1;
+      QPointF aPointA2, aPointB2, aPointC2;
+      anImageObj->TrsfPoints( aPointA1, aPointB1, aPointC1,
+                              aPointA2, aPointB2, aPointC2 );
+
+      HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
+      aDataMap[ HYDROGUI_PrsImage::PointA ] =
+        HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2 );
+      aDataMap[ HYDROGUI_PrsImage::PointB ] =
+        HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2 );
+      aDataMap[ HYDROGUI_PrsImage::PointC ] =
+        HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2 );
+
+      HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
+      aPrsPointDataList.append( aPrsPointData );
+    }
+  }
+  ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setPrsPointDataList( aPrsPointDataList );
 }
 
 void HYDROGUI_ImportImageOp::abortOperation()
@@ -121,6 +154,10 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
            this, SLOT( onCreatePreview( QImage ) ) );
   connect( aPanel, SIGNAL( activatePointSelection( int ) ),
            this, SLOT( onActivatePointSelection( int ) ) );
+  connect( aPanel, SIGNAL( pointCoordChanged( bool, int, bool, int ) ),
+           this, SLOT( onPointCoordChanged( bool, int, bool, int ) ) );
+  connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
+           this, SLOT( onRefImageActivated( const QString& ) ) );
   return aPanel;
 }
 
@@ -149,11 +186,23 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
 
   QImage anImage = myPreviewPrs->getImage();
 
-  closePreview();
+  bool anIsRefImage = aPanel->getTransformationMode() == HYDROGUI_ImportImageDlg::RefImage;
+
+  QTransform aRefTransform;
+  if( anIsRefImage && myRefPreviewPrs )
+  {
+    Handle(HYDROData_Image) aRefImageObj =
+      Handle(HYDROData_Image)::DownCast( myRefPreviewPrs->getObject() );
+    if( !aRefImageObj.IsNull() )
+      aRefTransform = aRefImageObj->Trsf();
+  }
 
   HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
-  bool anIsOk = aPanel->getTransformationDataMap( aMap );
-  if( !anIsOk )
+  if( !aPanel->getTransformationDataMap( aMap ) )
+    return false;
+
+  HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
+  if( anIsRefImage && !aPanel->getTransformationDataMap( aRefMap, true ) )
     return false;
 
   QPoint aPointA1 = aMap[ HYDROGUI_PrsImage::PointA ].first;
@@ -164,6 +213,14 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   QPointF aPointB2 = aMap[ HYDROGUI_PrsImage::PointB ].second;
   QPointF aPointC2 = aMap[ HYDROGUI_PrsImage::PointC ].second;
 
+  QPoint aPointA3, aPointB3, aPointC3;
+  if( anIsRefImage )
+  {
+    aPointA3 = aRefMap[ HYDROGUI_PrsImage::PointA ].first;
+    aPointB3 = aRefMap[ HYDROGUI_PrsImage::PointB ].first;
+    aPointC3 = aRefMap[ HYDROGUI_PrsImage::PointC ].first;
+  }
+
   int xa1 = aPointA1.x();
   int ya1 = aPointA1.y();
   int xb1 = aPointB1.x();
@@ -178,6 +235,13 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   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();
+
   // first, check that three input points don't belong to a single line
   if( ( yb1 - ya1 ) * ( xc1 - xa1 ) == ( yc1 - ya1 ) * ( xb1 - xa1 ) )
   {
@@ -185,17 +249,31 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
     return false;
   }
 
+  // the same check for the reference points
+  if( anIsRefImage && ( ( yb3 - ya3 ) * ( xc3 - xa3 ) == ( yc3 - ya3 ) * ( xb3 - xa3 ) ) )
+  {
+    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 );
 
   bool anIsInvertible = false;
-  QTransform aTransform = aTransform1.inverted( &anIsInvertible ) * aTransform2;
+  QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
   if( !anIsInvertible )
   {
     theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
     return false;
   }
 
+  QTransform aTransform;
+  if( anIsRefImage )
+    aTransform = aTransform1Inverted * aTransform3 * aRefTransform;
+  else
+    aTransform = aTransform1Inverted * aTransform2;
+
   Handle(HYDROData_Image) anImageObj;
   if( myIsEdit )
     anImageObj = myEditedObject;
@@ -210,9 +288,19 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   anImageObj->SetImage( anImage );
   anImageObj->SetTrsf( aTransform );
 
+  if( anIsRefImage )
+  {
+    aPointA2 = QPointF( aTransform.map( aPointA1 ) );
+    aPointB2 = QPointF( aTransform.map( aPointB1 ) );
+    aPointC2 = QPointF( aTransform.map( aPointC1 ) );
+  }
+
   anImageObj->SetTrsfPoints( aPointA1, aPointB1, aPointC1,
                              aPointA2, aPointB2, aPointC2 );
 
+  // must be done after all checks and before calling SetVisible() method below
+  closePreview();
+
   anImageObj->SetVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), true );
 
   theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced;
@@ -263,23 +351,96 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
     anImageName = HYDROGUI_Tool::GenerateObjectName( module(), "Image" );
   aPanel->setImageName( anImageName );
 
+  aPanel->setImageSize( theImage.size() );
+
   aPanel->initializePointSelection();
-  onPointSelected();
+  onPointSelected( false );
 }
 
 void HYDROGUI_ImportImageOp::onActivatePointSelection( int thePointType )
 {
   myPointType = thePointType;
   if( myPreviewPrs )
-    myPreviewPrs->setTransformationPointMode( thePointType );
+    myPreviewPrs->setTransformationPointType( thePointType );
+  if( myRefPreviewPrs )
+    myRefPreviewPrs->setTransformationPointType( thePointType );
+}
+
+void HYDROGUI_ImportImageOp::onPointCoordChanged( bool theIsRef,
+                                                  int thePointType,
+                                                  bool theIsY,
+                                                  int theValue )
+{
+  if( !theIsRef && myPreviewPrs )
+    myPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
+  else if( theIsRef && myRefPreviewPrs )
+    myRefPreviewPrs->updateTransformationPoint( thePointType, theIsY, theValue );
+}
+
+void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
+{
+  GraphicsView_ViewPort* aViewPort = 0;
+  if( myPreviewViewManager )
+    if( GraphicsView_Viewer* aViewer = myPreviewViewManager->getViewer() )
+      aViewPort = aViewer->getActiveViewPort();
+
+  if( !aViewPort )
+    return;
+
+  aViewPort->removeItem( myRefPreviewPrs );
+
+  delete myRefPreviewPrs;
+  myRefPreviewPrs = 0;
+
+  QImage anImage;
+  Handle(HYDROData_Image) anImageObj = Handle(HYDROData_Image)::DownCast(
+    HYDROGUI_Tool::FindObjectByName( module(), theName, KIND_IMAGE ) );
+  if( !anImageObj.IsNull() )
+  {
+    anImage = anImageObj->Image();
+
+    myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
+    myRefPreviewPrs->setImage( anImage );
+    myRefPreviewPrs->compute();
+
+    myRefPreviewPrs->setIsTransformationPointPreview( true );
+    myRefPreviewPrs->setTransformationPointType( myPointType );
+
+    // vertically shift the reference prs relatively to the main prs
+    if( myPreviewPrs )
+    {
+      QImage anImage = myPreviewPrs->getImage();
+      myRefPreviewPrs->moveBy( 0, anImage.height() + 20 );
+    }
+
+    aViewPort->addItem( myRefPreviewPrs );
+  }
+
+  aViewPort->fitAll();
+
+  HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+
+  aPanel->setImageSize( anImage.size(), true );
+
+  aPanel->initializePointSelection();
+  onPointSelected( true );
 }
 
 void HYDROGUI_ImportImageOp::onPointSelected()
 {
+  onPointSelected( myRefPreviewPrs && myRefPreviewPrs->isSelected() );
+}
+
+void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
+{
+  HYDROGUI_PrsImage* aPrs = theIsRefImage ? myRefPreviewPrs : myPreviewPrs;
+  if( !aPrs )
+    return;
+
   HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
 
   const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
-    myPreviewPrs->getTransformationPointMap();
+    aPrs->getTransformationPointMap();
   HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
   while( anIter.hasNext() )
   {
@@ -291,7 +452,7 @@ void HYDROGUI_ImportImageOp::onPointSelected()
     aDataMap[ aPointType ] = aData;
   }
 
-  ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true );
+  ( (HYDROGUI_ImportImageDlg*)inputPanel() )->setTransformationDataMap( aDataMap, true, theIsRefImage );
 }
 
 void HYDROGUI_ImportImageOp::closePreview()
@@ -302,6 +463,12 @@ void HYDROGUI_ImportImageOp::closePreview()
     myPreviewPrs = 0;
   }
 
+  if( myRefPreviewPrs )
+  {
+    delete myRefPreviewPrs;
+    myRefPreviewPrs = 0;
+  }
+
   if( myPreviewViewManager )
   {
     module()->getApp()->removeViewManager( myPreviewViewManager ); // myPreviewViewManager is deleted here
index fa4472e2a5bf061133e0a2bbcda1df2f828c30ec..9dd9c050dd0e573abb6f1ac62a3cf01dcddd3464 100644 (file)
@@ -55,7 +55,11 @@ protected:
 protected slots:
   void                       onCreatePreview( QImage );
   void                       onActivatePointSelection( int );
+  void                       onPointCoordChanged( bool, int, bool, int );
+  void                       onRefImageActivated( const QString& );
+
   void                       onPointSelected();
+  void                       onPointSelected( bool theIsRefImage );
 
 private:
   void                       closePreview();
@@ -68,6 +72,7 @@ private:
 
   GraphicsView_ViewManager*  myPreviewViewManager;
   HYDROGUI_PrsImage*         myPreviewPrs;
+  HYDROGUI_PrsImage*         myRefPreviewPrs;
 
   int                        myPointType;
 };
index 4c749d571e9cb3645bfb4564cda42d0be0784e51..90e54cf68acdb979535f67e67adc7d1b66cfd9b4 100644 (file)
@@ -37,7 +37,7 @@ HYDROGUI_PrsImage::HYDROGUI_PrsImage( const Handle(HYDROData_Object)& theObject
   myPixmapItem( 0 ),
   myPrsImageFrame( 0 ),
   myIsTransformationPointPreview( false ),
-  myTransformationPointMode( None )
+  myTransformationPointType( None )
 {
   myTransformationPointCursor = new QCursor( Qt::CrossCursor );
 }
@@ -92,13 +92,13 @@ bool HYDROGUI_PrsImage::getIsTransformationPointPreview() const
 }
 
 //================================================================
-// Function : setTransformationPointMode
+// Function : setTransformationPointType
 // Purpose  : 
 //================================================================
-void HYDROGUI_PrsImage::setTransformationPointMode( const int theMode )
+void HYDROGUI_PrsImage::setTransformationPointType( const int thePointType )
 {
-  myTransformationPointMode = theMode;
-  if( theMode != None )
+  myTransformationPointType = thePointType;
+  if( thePointType != None )
     computeTransformationPoints();
 }
 
@@ -113,6 +113,23 @@ void HYDROGUI_PrsImage::setTransformationPointMap( const TransformationPointMap&
     computeTransformationPoints();
 }
 
+//================================================================
+// Function : updateTransformationPoint
+// Purpose  : 
+//================================================================
+void HYDROGUI_PrsImage::updateTransformationPoint( const int thePointType,
+                                                   const bool theIsY,
+                                                   const int theValue )
+{
+  if( myTransformationPointMap.find( thePointType ) != myTransformationPointMap.end() )
+  {
+    TransformationPoint& aTransformationPoint = myTransformationPointMap[ thePointType ];
+    QPoint& aPoint = aTransformationPoint.Point;
+    theIsY ? aPoint.setY( theValue ) : aPoint.setX( theValue );
+    computeTransformationPoints();
+  }
+}
+
 //================================================================
 // Function : boundingRect
 // Purpose  : 
@@ -174,7 +191,7 @@ bool HYDROGUI_PrsImage::checkHighlight( double theX, double theY, QCursor& theCu
   {
     if( myIsTransformationPointPreview )
     {
-      if( myTransformationPointMode != None )
+      if( myTransformationPointType != None )
         theCursor = *getTransformationPointCursor();
     }
     else
@@ -192,11 +209,13 @@ bool HYDROGUI_PrsImage::select( double theX, double theY, const QRectF& theRect
 {
   if( myIsTransformationPointPreview )
   {
-    if( myTransformationPointMode == None || !theRect.isEmpty() )
+    if( myTransformationPointType == None || !theRect.isEmpty() )
       return false;
 
-    TransformationPoint& aTransformationPoint = myTransformationPointMap[ myTransformationPointMode ];
-    aTransformationPoint.Point = QPoint( (int)theX, (int)theY );
+    QPoint aPos = pos().toPoint();
+
+    TransformationPoint& aTransformationPoint = myTransformationPointMap[ myTransformationPointType ];
+    aTransformationPoint.Point = QPoint( (int)theX, (int)theY ) - aPos;
     computeTransformationPoints();
     return true;
   }
index c09ad6927dd5abcac30ccea783433b6b95efac9d..3f78316c95a2883545b2e627648f92682e38eccd 100644 (file)
@@ -56,11 +56,15 @@ public:
   void                            setIsTransformationPointPreview( const bool theState );
   bool                            getIsTransformationPointPreview() const;
 
-  void                            setTransformationPointMode( const int theMode );
+  void                            setTransformationPointType( const int thePointType );
 
   void                            setTransformationPointMap( const TransformationPointMap& theMap );
   const TransformationPointMap&   getTransformationPointMap() const { return myTransformationPointMap; }
 
+  void                            updateTransformationPoint( const int thePointType,
+                                                             const bool theIsY,
+                                                             const int theValue );
+
 public:
   // from QGraphicsItem
   virtual QRectF                  boundingRect() const;
@@ -92,7 +96,7 @@ protected:
   HYDROGUI_PrsImageFrame*         myPrsImageFrame;
 
   bool                            myIsTransformationPointPreview;
-  int                             myTransformationPointMode;
+  int                             myTransformationPointType;
   TransformationPointMap          myTransformationPointMap;
 
 private:
index d98db72a4eaea477352a23a6442de3d30d7930f8..b30f5ec8372fe6bc91e4fbfde74ee7ac99246193 100644 (file)
@@ -152,6 +152,14 @@ void HYDROGUI_Tool::DoubleToLambert( const double theCoord,
   theSeconds = aRemainder - theMinutes * 60;
 }
 
+bool HYDROGUI_Tool::IsEqual( const Handle(HYDROData_Object)& theObj1,
+                             const Handle(HYDROData_Object)& theObj2 )
+{
+  if( !theObj1.IsNull() && !theObj2.IsNull() )
+    return theObj1->Label() == theObj2->Label(); //ouv: check that the names can be used here
+  return false;
+}
+
 void HYDROGUI_Tool::SetActiveViewManager( HYDROGUI_Module* theModule,
                                           SUIT_ViewManager* theViewManager )
 {
@@ -197,7 +205,7 @@ HYDROGUI_Prs* HYDROGUI_Tool::GetPresentation( const Handle(HYDROData_Object)& th
       if( HYDROGUI_Prs* aPrs = dynamic_cast<HYDROGUI_Prs*>( anIter.next() ) )
       {
         Handle(HYDROData_Object) anObj = aPrs->getObject();
-        if( !anObj.IsNull() && anObj->Label() == theObj->Label() )
+        if( IsEqual( anObj, theObj ) )
           return aPrs;
       }
     }
index e713e7d64e397db524b04d9af271f7f1481124f6..6cb51e936bd9de88e4a1e698d4432302506435ab 100644 (file)
@@ -102,6 +102,14 @@ public:
                                                    int& theMinutes,
                                                    double& theSeconds );
 
+  /**
+   * \brief Check that the specified objects are equal.
+   * \param theObj1 first object
+   * \param theObj2 second object
+   */
+  static bool                     IsEqual( const Handle(HYDROData_Object)& theObj1,
+                                           const Handle(HYDROData_Object)& theObj2 );
+
   /**
    * \brief Set the specified view manager to be active on the desktop.
    * \param theModule module
index 3792b419c1b65b1780bac6c43699b92162403a52..94b4e554317fc00674ae221f0863b73b9edb682c 100644 (file)
@@ -141,6 +141,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>ACTIVATE_POINT_C_SELECTION</source>
       <translation>Activate point C selection</translation>
     </message>
+    <message>
+      <source>BY_REFERENCE_IMAGE</source>
+      <translation>By reference image</translation>
+    </message>
     <message>
       <source>FILE_NAME</source>
       <translation>File name</translation>
@@ -153,10 +157,18 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>IMPORT_IMAGE_FROM_FILE</source>
       <translation>Import image from file</translation>
     </message>
+    <message>
+      <source>MANUALLY</source>
+      <translation>Manually</translation>
+    </message>
     <message>
       <source>NAME</source>
       <translation>Name</translation>
     </message>
+    <message>
+      <source>REFERENCE_IMAGE</source>
+      <translation>Reference image</translation>
+    </message>
     <message>
       <source>TRANSFORM_IMAGE</source>
       <translation>Transform image</translation>
@@ -181,6 +193,10 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>POINTS_A_B_C_BELONG_TO_SINGLE_LINE</source>
       <translation>Points A, B, C belong to a single line.</translation>
     </message>
+    <message>
+      <source>REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE</source>
+      <translation>Reference points A, B, C belong to a single line.</translation>
+    </message>
     <message>
       <source>TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED</source>
       <translation>Transformation matrix cannot be computed.</translation>