]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Image positioning by two points.
authoradv <adv@opencascade.com>
Fri, 1 Nov 2013 11:49:34 +0000 (11:49 +0000)
committeradv <adv@opencascade.com>
Fri, 1 Nov 2013 11:49:34 +0000 (11:49 +0000)
src/HYDROData/HYDROData_Image.cxx
src/HYDROData/HYDROData_Image.h
src/HYDROGUI/HYDROGUI_ImportImageDlg.cxx
src/HYDROGUI/HYDROGUI_ImportImageDlg.h
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/HYDROGUI_Module.cxx
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index ca01c6555c646d0b7083e3a118b7a871688941f8..ae6b08042693fc987ca8885b86ef58a9771f056b 100644 (file)
@@ -21,6 +21,8 @@
 
 static const Standard_GUID GUID_MUST_BE_UPDATED("80f2bb81-3873-4631-8ddd-940d2119f000");
 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
+static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
+static const Standard_GUID GUID_HAS_GLOBAL_POINTS("330D0E81-742D-4ea3-92D4-484877CFA7C1");
 
 #define PYTHON_IMAGE_ID "KIND_IMAGE"
 
@@ -58,62 +60,45 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject
     aResList << QString( "" );
     aResList << QString( "%1.LoadImage( \"%2\" );" )
                 .arg( anImageName ).arg( aFilePath );
-
-    // Dump transformation matrix for image
     aResList << QString( "" );
 
-    QTransform aTrsf = Trsf();
-
-    aResList << QString( "trsf = QTransform( %1, %2, %3," )
-                .arg( aTrsf.m11() ).arg( aTrsf.m12() ).arg( aTrsf.m13() );
-    aResList << QString( "                   %1, %2, %3," )
-                .arg( aTrsf.m21() ).arg( aTrsf.m22() ).arg( aTrsf.m23() );
-    aResList << QString( "                   %1, %2, %3 );" )
-                .arg( aTrsf.m31() ).arg( aTrsf.m32() ).arg( aTrsf.m33() );
-
-    aResList << QString( "%1.SetTrsf( trsf );" ).arg( anImageName );
-
     // Dump transformation points for image
-    aResList << QString( "" );
-
-    QPoint aPointA, aPointB, aPointC;
-    QPointF aLambertPointA, aLambertPointB, aLambertPointC;
-    QPointF aCartesianPointA, aCartesianPointB, aCartesianPointC;
-    TrsfPoints( aPointA, aPointB, aPointC,
-                aLambertPointA, aLambertPointB, aLambertPointC,
-                aCartesianPointA, aCartesianPointB, aCartesianPointC );
-
-    aResList << QString( "pa = QPoint( %1, %2 );" )
-                .arg( aPointA.x() ).arg( aPointA.y() );
-
-    aResList << QString( "pb = QPoint( %1, %2 );" )
-                .arg( aPointB.x() ).arg( aPointB.y() );
 
-    aResList << QString( "pc = QPoint( %1, %2 );" )
-                .arg( aPointC.x() ).arg( aPointC.y() );
-
-    aResList << QString( "lpa = QPointF( %1, %2 );" )
-                .arg( aLambertPointA.x() ).arg( aLambertPointA.y() );
-
-    aResList << QString( "lpb = QPointF( %1, %2 );" )
-                .arg( aLambertPointB.x() ).arg( aLambertPointB.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() );
+    QString aGap = QString().fill( ' ', anImageName.size() + 16 );
 
-    aResList << QString( "cpb = QPointF( %1, %2 );" )
-                .arg( aCartesianPointB.x() ).arg( aCartesianPointB.y() );
+    bool anIsByTwoPoints = IsByTwoPoints();
 
-    aResList << QString( "cpc = QPointF( %1, %2 );" )
-                .arg( aCartesianPointC.x() ).arg( aCartesianPointC.y() );
+    QPoint aLocalPointA, aLocalPointB, aLocalPointC;
+    if ( GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC ) )
+    {
+      aResList << QString( "%1.SetLocalPoints( QPoint( %2, %3 )," )
+                  .arg( anImageName ).arg( aLocalPointA.x() ).arg( aLocalPointA.y() );
+      aResList << QString( aGap             + "QPoint( %1, %2 )," )
+                  .arg( aLocalPointB.x() ).arg( aLocalPointB.y() );
+      aResList << QString( aGap             + "QPoint( %1, %2 ) );" )
+                  .arg( aLocalPointC.x() ).arg( aLocalPointC.y() );
+      aResList << QString( "" );
+    }
 
-    QString aGap = QString().fill( ' ', anImageName.size() + 16 );
-    aResList << QString( "%1.SetTrsfPoints( pa,  pb,  pc," ).arg( anImageName );
-    aResList << QString( aGap            + "lpa, lpb, lpc," );
-    aResList << QString( aGap            + "cpa, cpb, cpc );" );
+    HYDROData_Image::TransformationMode aTransformationMode;
+    QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
+    if ( GetGlobalPoints( aTransformationMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
+    {
+      aResList << QString( "%1.SetGlobalPoints( %2," )
+                  .arg( anImageName ).arg( aTransformationMode );
+      aResList << QString( aGap             +  "QPointF( %1, %2 )," )
+                  .arg( aTrsfPointA.x() ).arg( aTrsfPointA.y() );
+      aResList << QString( aGap             +  "QPointF( %1, %2 )," )
+                  .arg( aTrsfPointB.x() ).arg( aTrsfPointB.y() );
+      aResList << QString( aGap             +  "QPointF( %1, %2 ) );" )
+                  .arg( aTrsfPointC.x() ).arg( aTrsfPointC.y() );
+
+      if ( aTransformationMode == ReferenceImage )
+      {
+        Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage();
+        setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" );
+      }
+    }
   }
   else
   {
@@ -323,81 +308,284 @@ QTransform HYDROData_Image::Trsf() const
   return aTrsf;
 }
 
-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)
+void HYDROData_Image::UpdateTrsf()
 {
-  Handle(TDataStd_RealArray) anArray;
-  if (!myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
-    anArray = TDataStd_RealArray::Set(myLab.FindChild(DataTag_TrsfPoints), 1, 18);
+  QPoint aPointA, aPointB, aPointC;
+  if ( !GetLocalPoints( aPointA, aPointB, aPointC ) )
+    return;
+
+  TransformationMode aTrsfMode;
+  QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
+  if ( !GetGlobalPoints( aTrsfMode, aTrsfPointA, aTrsfPointB, aTrsfPointC ) )
+    return;
+
+  QTransform aRefTransform;
+  Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
+
+  bool anIsRefImage = aTrsfMode == ReferenceImage;
+  if ( anIsRefImage )
+  {
+    if ( aRefImage.IsNull() )
+      return;
+
+    aRefTransform = aRefImage->Trsf();
   }
-  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& thePointA,
-                                 QPoint& thePointB,
-                                 QPoint& thePointC,
-                                 QPointF& theLambertPointA,
-                                 QPointF& theLambertPointB,
-                                 QPointF& theLambertPointC,
-                                 QPointF& theCartesianPointA,
-                                 QPointF& theCartesianPointB,
-                                 QPointF& theCartesianPointC) const
+
+  // generate third points if needed
+  if ( IsByTwoPoints() )
+  {
+    aPointC = generateThirdPoint( aPointA, aPointB, true ).toPoint();
+    aTrsfPointC = generateThirdPoint( aTrsfPointA, aTrsfPointB, anIsRefImage );
+  }
+
+  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 xta = aTrsfPointA.x();
+  double yta = aTrsfPointA.y();
+  double xtb = aTrsfPointB.x();
+  double ytb = aTrsfPointB.y();
+  double xtc = aTrsfPointC.x();
+  double ytc = aTrsfPointC.y();
+
+  // first, check that three input points don't belong to a single line
+  if( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
+    return;
+
+  // the same check for the reference points
+  if( anIsRefImage && ( ( ytb - yta ) * ( xtc - xta ) == ( ytc - yta ) * ( xtb - xta ) ) )
+    return;
+
+  QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
+  QTransform aTransform2( xta, yta, 1, xtb, ytb, 1, xtc, ytc, 1 );
+
+  bool anIsInvertible = false;
+  QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
+  if( !anIsInvertible )
+    return;
+
+  QTransform aResTransform;
+  if( anIsRefImage )
+    aResTransform = aTransform1Inverted * aTransform2 * aRefTransform;
+  else
+    aResTransform = aTransform1Inverted * aTransform2;
+
+  SetTrsf( aResTransform );
+}
+
+bool HYDROData_Image::IsByTwoPoints() const
+{
+  if ( !HasLocalPoints() || !HasGlobalPoints() )
+    return false;
+
+  QPoint aPointA, aPointB, aPointC;
+  GetLocalPoints( aPointA, aPointB, aPointC );
+
+  return aPointC.x() < 0 && aPointC.y() < 0; 
+}
+
+void HYDROData_Image::SetLocalPoints( const QPoint& thePointA,
+                                      const QPoint& thePointB,
+                                      const QPoint& thePointC )
+{
+  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->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() );
+
+  TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_LOCAL_POINTS );
+
+  UpdateTrsf();
+}
+
+bool HYDROData_Image::GetLocalPoints( QPoint& thePointA,
+                                      QPoint& thePointB,
+                                      QPoint& thePointC ) const
+{
+  if ( !HasLocalPoints() )
+    return false;
+
+  Handle(TDataStd_RealArray) anArray;
+  myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
+
+  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();
+
+  return true;
+}
+
+bool HYDROData_Image::HasLocalPoints() const
 {
+  TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
+  if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_LOCAL_POINTS ) )
+    return false;
+
   Handle(TDataStd_RealArray) anArray;
-  if (myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray)) {
-    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) );
+  return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
+}
+
+
+void HYDROData_Image::SetGlobalPoints( const TransformationMode& theMode,
+                                       const QPointF&            thePointA,
+                                       const QPointF&            thePointB,
+                                       const QPointF&            thePointC )
+{
+  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->SetValue( 7,  thePointA.x() );
+  anArray->SetValue( 8,  thePointA.y() );
+  anArray->SetValue( 9,  thePointB.x() );
+  anArray->SetValue( 10, thePointB.y() );
+  anArray->SetValue( 11, thePointC.x() );
+  anArray->SetValue( 12, thePointC.y() );
+  
+  SetTrsfMode( theMode );
+
+  TDataStd_UAttribute::Set( myLab.FindChild( DataTag_TrsfPoints ), GUID_HAS_GLOBAL_POINTS );
+
+  UpdateTrsf();
+
+  /*
+  if( anIsRefImage )
+  {
+    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
   }
+  */
 }
 
-bool HYDROData_Image::HasTrsfPoints() const
+bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
+                                       QPointF&            thePointA,
+                                       QPointF&            thePointB,
+                                       QPointF&            thePointC ) const
 {
+  if ( !HasGlobalPoints() )
+    return false;
+
+  theMode = GetTrsfMode();
+
   Handle(TDataStd_RealArray) anArray;
-  return myLab.FindChild(DataTag_TrsfPoints).FindAttribute(TDataStd_RealArray::GetID(), anArray);
+  myLab.FindChild( DataTag_TrsfPoints ).FindAttribute( TDataStd_RealArray::GetID(), anArray );
+
+  thePointA = QPointF( anArray->Value( 7  ), anArray->Value( 8  ) );
+  thePointB = QPointF( anArray->Value( 9  ), anArray->Value( 10 ) );
+  thePointC = QPointF( anArray->Value( 11 ), anArray->Value( 12 ) );
+
+  return true;
 }
 
-void HYDROData_Image::SetTrsfMode(const int theMode)
+bool HYDROData_Image::HasGlobalPoints() const
 {
-  TDataStd_Integer::Set(myLab.FindChild(DataTag_TrsfMode), theMode);
+  TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
+  if ( aLabel.IsNull() || !aLabel.IsAttribute( GUID_HAS_GLOBAL_POINTS ) )
+    return false;
+
+  Handle(TDataStd_RealArray) anArray;
+  return aLabel.FindAttribute( TDataStd_RealArray::GetID(), anArray );
 }
 
-int HYDROData_Image::TrsfMode() const
+void HYDROData_Image::SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
+                                          const QPointF&                 thePointA,
+                                          const QPointF&                 thePointB,
+                                          const QPointF&                 thePointC )
 {
-  Handle(TDataStd_Integer) aMode;
-  if(myLab.FindChild(DataTag_TrsfMode).FindAttribute(TDataStd_Integer::GetID(), aMode))
-    return aMode->Get();
-  return 0;
+  SetTrsfReferenceImage( theRefImage );
+  SetGlobalPoints( ReferenceImage, thePointA, thePointB, thePointC );
+
+  UpdateTrsf();
+}
+
+bool HYDROData_Image::GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
+                                          QPointF&                 thePointA,
+                                          QPointF&                 thePointB,
+                                          QPointF&                 thePointC ) const
+{
+  if ( !HasReferencePoints() )
+    return false;
+
+  theRefImage = GetTrsfReferenceImage();
+
+  TransformationMode aMode;
+  GetGlobalPoints( aMode, thePointA, thePointB, thePointC );
+
+  return true;
+}
+
+bool HYDROData_Image::HasReferencePoints() const
+{
+  if ( !HasGlobalPoints() )
+    return false;
+
+  Handle(HYDROData_Image) aRefImage = GetTrsfReferenceImage();
+  if ( aRefImage.IsNull() )
+    return false;
+
+  TransformationMode aTrsfMode = GetTrsfMode();
+  if ( aTrsfMode != ReferenceImage )
+    return false;
+
+  return true;
+}
+
+void HYDROData_Image::SetTrsfMode( const TransformationMode& theMode )
+{
+  TDataStd_Integer::Set( myLab.FindChild( DataTag_TrsfMode ), (int)theMode );
+}
+
+HYDROData_Image::TransformationMode HYDROData_Image::GetTrsfMode() const
+{
+  TransformationMode aResMode = ManualLambert;
+
+  TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );
+  if ( !aLabel.IsNull() )
+  {
+    Handle(TDataStd_Integer) aMode;
+    if ( myLab.FindChild( DataTag_TrsfMode ).FindAttribute( TDataStd_Integer::GetID(), aMode ) )
+      aResMode = (TransformationMode)aMode->Get();
+  }
+
+  return aResMode;
+}
+
+void HYDROData_Image::SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage )
+{
+  SetReferenceObject( theRefImage, DataTag_TrsfImage );
+}
+
+Handle(HYDROData_Image) HYDROData_Image::GetTrsfReferenceImage() const
+{
+  return Handle(HYDROData_Image)::DownCast( GetReferenceObject( DataTag_TrsfImage ) );
 }
 
 void HYDROData_Image::AppendReference( const Handle(HYDROData_Entity)& theReferenced )
@@ -489,3 +677,28 @@ bool HYDROData_Image::IsSelfSplitted() const
 {
   return myLab.IsAttribute(GUID_SELF_SPLITTED);
 }
+
+QPointF HYDROData_Image::generateThirdPoint( const QPointF& thePointA,
+                                             const QPointF& thePointB,
+                                             const bool&    theIsLocal ) const
+{
+  // Rotate vector to 90 degrees : clockwise - for local
+  //                               anticlockwise - for global
+  const double aTheta = theIsLocal ? -M_PI_2 : M_PI_2;
+
+  QPointF aResPoint;
+
+  // Move to (0,0) for correct rotation
+  double x = thePointB.x() - thePointA.x();
+  double y = thePointB.y() - thePointA.y();
+
+  aResPoint.setX( x * cos( aTheta ) - y * sin( aTheta ) );
+  aResPoint.setY( x * sin( aTheta ) + y * cos( aTheta ) );
+
+  // Move back to origin position
+  aResPoint.setX( aResPoint.x() + thePointA.x() );
+  aResPoint.setY( aResPoint.y() + thePointA.y() );
+
+  return aResPoint;
+}
+
index 382cd817c4853c8c78277d8c327dfeaae682f194..da11061653ac0ce1bc57058881cca94dcba29538 100644 (file)
@@ -17,6 +17,16 @@ DEFINE_STANDARD_HANDLE(HYDROData_Image, HYDROData_Entity)
  */
 class HYDROData_Image : public HYDROData_Entity
 {
+
+public:
+
+  enum TransformationMode
+  {
+    ManualLambert = 0,
+    ManualCartesian,
+    ReferenceImage
+  };
+
 protected:
   /**
    * Enumeration of tags corresponding to the persistent object parameters.
@@ -24,10 +34,11 @@ protected:
   enum DataTag
   {
     DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
-    DataTag_Operator,    ///< name of the operator that must be executed for image update
-    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
+    DataTag_Operator,        ///< name of the operator that must be executed for image update
+    DataTag_TrsfMode,        ///< transformation mode (0 - Lambert93, 1 - Cartesian, 2 - on other Image)
+    DataTag_TrsfPoints,      ///< image transformation points 
+    DataTag_TrsfImage,      ///< reference transformation image
+    DataTag_FilePath         ///< image imported file path
   };
 
 public:
@@ -99,63 +110,129 @@ public:
   HYDRODATA_EXPORT QTransform Trsf() const;
 
   /**
-   * Stores the image transformation points (3 input + 3 output)
-   * \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
+   * Updates the matrix of transformation in accordance with reference points.
+   * \param theTrsf new transformation
+   */
+  HYDRODATA_EXPORT void UpdateTrsf();
+
+
+  /**
+   * Returns true if transformation is done by two points only
+   */
+  HYDRODATA_EXPORT bool IsByTwoPoints() const;
+
+
+  /**
+   * Stores the transformation points in local cs of image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   */
+  HYDRODATA_EXPORT void SetLocalPoints( const QPoint& thePointA,
+                                        const QPoint& thePointB,
+                                        const QPoint& thePointC = QPoint( INT_MIN, INT_MIN ) );
+
+  /**
+   * Returns the transformation points in local cs of image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   * \return true if all parameters has been set before
+   */
+  HYDRODATA_EXPORT bool GetLocalPoints( QPoint& thePointA,
+                                        QPoint& thePointB,
+                                        QPoint& thePointC ) const;
+
+  /**
+   * Returns true if local points has been set before
+   */
+  HYDRODATA_EXPORT bool HasLocalPoints() const;
+
+
+  /**
+   * Stores the transformation points in global cs
+   * \param theMode transformation mode
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   */
+  HYDRODATA_EXPORT void SetGlobalPoints( const TransformationMode& theMode,
+                                         const QPointF&            thePointA,
+                                         const QPointF&            thePointB,
+                                         const QPointF&            thePointC = QPoint( INT_MIN, INT_MIN ) );
+
+  /**
+   * Returns the transformation points in global cs
+   * \param theMode transformation mode
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   * \return true if all parameters has been set before
+   */
+  HYDRODATA_EXPORT bool GetGlobalPoints( TransformationMode& theMode,
+                                         QPointF&            thePointA,
+                                         QPointF&            thePointB,
+                                         QPointF&            thePointC ) const;
+
+  /**
+   * Returns true if global points has been set before
    */
-  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);
+  HYDRODATA_EXPORT bool HasGlobalPoints() const;
+
 
   /**
-   * Returns the image transformation points (3 input + 3 output)
-   * \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
+   * Stores the transformation points in reference image local cs
+   * \param theRefImage reference image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
    */
-  HYDRODATA_EXPORT void TrsfPoints(QPoint& thePointA,
-                                   QPoint& thePointB,
-                                   QPoint& thePointC,
-                                   QPointF& theLambertPointA,
-                                   QPointF& theLambertPointB,
-                                   QPointF& theLambertPointC,
-                                   QPointF& theCartesianPointA,
-                                   QPointF& theCartesianPointB,
-                                   QPointF& theCartesianPointC) const;
+  HYDRODATA_EXPORT void SetReferencePoints( const Handle(HYDROData_Image)& theRefImage,
+                                            const QPointF&                 thePointA,
+                                            const QPointF&                 thePointB,
+                                            const QPointF&                 thePointC = QPoint( INT_MIN, INT_MIN ) );
 
   /**
-   * Returns true if the image has stored transformation points
+   * Returns the transformation points in reference image local cs
+   * \param theRefImage reference image
+   * \param thePointA point A
+   * \param thePointB point B
+   * \param thePointC point C
+   * \return true if all parameters has been set correctly
    */
-  HYDRODATA_EXPORT bool HasTrsfPoints() const;
+  HYDRODATA_EXPORT bool GetReferencePoints( Handle(HYDROData_Image)& theRefImage,
+                                            QPointF&                 thePointA,
+                                            QPointF&                 thePointB,
+                                            QPointF&                 thePointC ) const;
 
   /**
-   * Stores the transformation mode (0 - Lambert93, 1 - Cartesian)
+   * Returns true if reference points has been set before
    */
-  HYDRODATA_EXPORT void SetTrsfMode(const int theMode);
+  HYDRODATA_EXPORT bool HasReferencePoints() const;
+
 
   /**
-   * Returns the transformation mode (0 - Lambert93, 1 - Cartesian)
+   * Stores the reference image for transformation
+   * \param theRefImage reference image
    */
-  HYDRODATA_EXPORT int TrsfMode() const;
+  HYDRODATA_EXPORT void SetTrsfReferenceImage( const Handle(HYDROData_Image)& theRefImage );
+
+  /**
+   * Returns the reference image for transformation
+   */
+  HYDRODATA_EXPORT Handle(HYDROData_Image) GetTrsfReferenceImage() const;
+
+
+  /**
+   * Stores the transformation mode
+   */
+  HYDRODATA_EXPORT void SetTrsfMode( const TransformationMode& theMode );
+
+  /**
+   * Returns the transformation mode
+   */
+  HYDRODATA_EXPORT TransformationMode GetTrsfMode() const;
+
 
   /**
    * Returns the number of referenced objects
@@ -244,6 +321,12 @@ public:
    */
   HYDRODATA_EXPORT bool IsSelfSplitted() const;
 
+private:
+
+  QPointF generateThirdPoint( const QPointF& thePointA,
+                              const QPointF& thePointB,
+                              const bool&    theIsLocal ) const;
+
 protected:
 
   friend class HYDROData_Iterator;
index f326790d17f0ed1de013aab808ba1fa03554bed3..7186d96e26ac3bac4fa238da812d353231de77cf 100644 (file)
@@ -26,6 +26,7 @@
 #include "HYDROGUI_Tool.h"
 
 #include <HYDROData_Lambert93.h>
+#include <HYDROData_Image.h>
 
 #include <SUIT_FileDlg.h>
 #include <SUIT_ResourceMgr.h>
@@ -102,9 +103,9 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   QRadioButton* aRefImageBtn = new QRadioButton( tr( "BY_REFERENCE_IMAGE" ), myTransformGroup );
 
   myModeGroup = new QButtonGroup( myTransformGroup );
-  myModeGroup->addButton( aManualCartesianBtn, ManualCartesian );
-  myModeGroup->addButton( aManualLambertBtn, ManualLambert );
-  myModeGroup->addButton( aRefImageBtn, RefImage );
+  myModeGroup->addButton( aManualCartesianBtn, HYDROData_Image::ManualCartesian );
+  myModeGroup->addButton( aManualLambertBtn, HYDROData_Image::ManualLambert );
+  myModeGroup->addButton( aRefImageBtn, HYDROData_Image::ReferenceImage );
 
   myRefImage = new QComboBox( myTransformGroup );
 
@@ -302,7 +303,7 @@ HYDROGUI_ImportImageDlg::HYDROGUI_ImportImageDlg( HYDROGUI_Module* theModule, co
   connect( myRefImage, SIGNAL( activated( const QString& ) ),
            this, SLOT( onRefImageActivated( const QString& ) ) );
 
-  setTransformationMode( ManualLambert );
+  setTransformationMode( HYDROData_Image::ManualLambert );
 
   setMinimumWidth( 350 );
 }
@@ -351,7 +352,7 @@ void HYDROGUI_ImportImageDlg::reset()
   myTransformGroup->setEnabled( false );
   myRefImage->clear();
 
-  setTransformationMode( ManualLambert );
+  setTransformationMode( HYDROData_Image::ManualLambert );
 
   myPrsPointDataList.clear();
 
@@ -368,6 +369,16 @@ QString HYDROGUI_ImportImageDlg::getImageName() const
   return myImageName->text();
 }
 
+void HYDROGUI_ImportImageDlg::setRefImageName( const QString& theName )
+{
+  myRefImage->setCurrentIndex( myRefImage->findText( theName ) );
+}
+
+QString HYDROGUI_ImportImageDlg::getRefImageName() const
+{
+  return myRefImage->currentText();
+}
+
 QString HYDROGUI_ImportImageDlg::getFileName() const
 {
   return myFileName->text();
@@ -405,6 +416,16 @@ int HYDROGUI_ImportImageDlg::getTransformationMode() const
   return myModeGroup->checkedId();
 }
 
+void HYDROGUI_ImportImageDlg::setByTwoPoints( const bool theIsByTwoPoints )
+{
+  myPointCEnabler->setChecked( !theIsByTwoPoints );
+}
+
+bool HYDROGUI_ImportImageDlg::isByTwoPoints() const
+{
+  return !myPointCEnabler->isChecked();
+}
+
 void HYDROGUI_ImportImageDlg::setTransformationDataMap( const TransformationDataMap& theMap,
                                                         const bool theIsOnlyInput,
                                                         const bool theIsRefImage )
@@ -496,18 +517,13 @@ bool HYDROGUI_ImportImageDlg::getTransformationDataMap( TransformationDataMap& t
   return true;
 }
 
-QString HYDROGUI_ImportImageDlg::getRefImageName() const
-{
-  return myRefImage->currentText();
-}
-
 void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theList )
 {
   myPrsPointDataList = theList;
 
   if( !myPrsPointDataList.isEmpty() )
   {
-    myModeGroup->button( RefImage )->setEnabled( true );
+    myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( true );
 
     myRefImage->clear();
     myRefImage->addItem( "" ); // first empty item
@@ -517,7 +533,7 @@ void HYDROGUI_ImportImageDlg::setPrsPointDataList( const PrsPointDataList& theLi
       myRefImage->addItem( anIter.next().first );
   }
   else
-    myModeGroup->button( RefImage )->setEnabled( false );
+    myModeGroup->button( HYDROData_Image::ReferenceImage )->setEnabled( false );
 }
 
 void HYDROGUI_ImportImageDlg::initializePointSelection()
@@ -584,6 +600,38 @@ void HYDROGUI_ImportImageDlg::initializePointSelection()
   blockSignalsCartesian( false );
 }
 
+HYDROGUI_ImportImageDlg::TransformationData HYDROGUI_ImportImageDlg::ComputeTrsfData(
+  const int      theMode,
+  const QPoint&  theLocalPoint,
+  const QPointF& theGlobalPoint )
+{
+  TransformationData aResTrsfData;
+  aResTrsfData.ImagePoint = theLocalPoint;
+
+  double arx = theGlobalPoint.x();
+  double ary = theGlobalPoint.y();
+  if ( theMode == HYDROData_Image::ManualLambert )
+  {
+    // Lambert to Cartesian
+    double aXCart = 0, aYCart = 0;
+    HYDROData_Lambert93::toXY( arx, ary, aXCart, aYCart );
+
+    aResTrsfData.LambertPoint = theGlobalPoint;
+    aResTrsfData.CartesianPoint = QPointF( aXCart, aYCart );
+  }
+  else if ( theMode == HYDROData_Image::ManualCartesian )
+  {
+    // Cartesian to Lambert
+    double aLonDeg = 0, aLatDeg = 0;
+    HYDROData_Lambert93::toGeo( arx, ary, aLatDeg, aLonDeg );
+
+    aResTrsfData.CartesianPoint = theGlobalPoint;
+    aResTrsfData.LambertPoint = QPointF( aLonDeg, aLatDeg );
+  }
+
+  return aResTrsfData;
+}
+
 void HYDROGUI_ImportImageDlg::onBrowse()
 {
   QString aFilter( tr( "IMAGE_FILTER" ) );
@@ -603,9 +651,9 @@ void HYDROGUI_ImportImageDlg::onBrowse()
 
 void HYDROGUI_ImportImageDlg::onModeActivated( int theMode )
 {
-  bool anIsManualLambert = theMode == ManualLambert;
-  bool anIsManualCartesian = theMode == ManualCartesian;
-  bool anIsRefImage = theMode == RefImage;
+  bool anIsManualLambert = theMode == HYDROData_Image::ManualLambert;
+  bool anIsManualCartesian = theMode == HYDROData_Image::ManualCartesian;
+  bool anIsRefImage = theMode == HYDROData_Image::ReferenceImage;
 
   myRefImage->setEnabled( anIsRefImage );
 
index 8823389061318ba782c955bbc0b022c5d158648c..3473fdfb89352a94fb21dcf89266895067b08430 100644 (file)
@@ -41,9 +41,6 @@ class HYDROGUI_ImportImageDlg : public HYDROGUI_InputPanel
 {
   Q_OBJECT
 
-public:
-  enum TransformationMode { ManualLambert = 0, ManualCartesian, RefImage };
-
 public:
   struct TransformationData
   {
@@ -53,6 +50,9 @@ public:
 
     TransformationData() {}
 
+    TransformationData( const QPoint& theImagePoint ) :
+      ImagePoint( theImagePoint ) {}
+
     TransformationData( const QPoint& theImagePoint,
                         const QPointF& theLambertPoint,
                         const QPointF& theCartesianPoint ) :
@@ -76,6 +76,9 @@ public:
   void                       setImageName( const QString& theName );
   QString                    getImageName() const;
 
+  void                       setRefImageName( const QString& theName );
+  QString                    getRefImageName() const;
+
   QString                    getFileName() const;
 
   void                       setImageSize( const QSize& theSize,
@@ -84,18 +87,25 @@ public:
   void                       setTransformationMode( const int theMode );
   int                        getTransformationMode() const;
 
+  void                       setByTwoPoints( const bool theIsByTwoPoints );
+  bool                       isByTwoPoints() const;
+
   void                       setTransformationDataMap( const TransformationDataMap& theMap,
                                                        const bool theIsOnlyInput = false,
                                                        const bool theIsRefImage = false );
   bool                       getTransformationDataMap( TransformationDataMap& theMap,
                                                        const bool theIsRefImage = false ) const;
 
-  QString                    getRefImageName() const;
-
   void                       setPrsPointDataList( const PrsPointDataList& theList );
 
   void                       initializePointSelection();
 
+public:
+
+  static TransformationData  ComputeTrsfData( const int      theMode,
+                                              const QPoint&  theLocalPoint,
+                                              const QPointF& theGlobalPoint );
+
 protected slots:
   void                       onBrowse();
   void                       onModeActivated( int );
index dabeaad10cc3f0a3c3b3b2f484b93fbb96cde800..ca37f4a5fc8e7eb6643c2da40af972d2814b9f36 100644 (file)
@@ -31,8 +31,8 @@
 
 #include <HYDROData_Iterator.h>
 #include <HYDROData_Lambert93.h>
-
 #include <HYDROData_OperationsFactory.h>
+#include <HYDROData_Tool.h>
 
 #include <GraphicsView_ViewManager.h>
 #include <GraphicsView_ViewPort.h>
@@ -73,24 +73,18 @@ void HYDROGUI_ImportImageOp::startOperation()
   aPanel->reset();
   aPanel->setIsEdit( myIsEdit );
 
+  QString aRefImageName;
+
   if( myIsEdit )
   {
     myEditedObject = Handle(HYDROData_Image)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
     if( !myEditedObject.IsNull() )
     {
       QImage anImage = myEditedObject->Image();
+      bool anIsByTwoPoints = myEditedObject->IsByTwoPoints();
 
-      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,
-                                  aPointA3, aPointB3, aPointC3 );
+      QPoint aLocalPointA, aLocalPointB, aLocalPointC;
+      myEditedObject->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
 
       onCreatePreview( anImage );
 
@@ -100,21 +94,66 @@ void HYDROGUI_ImportImageOp::startOperation()
           myPreviewPrs->getTransformationPointMap();
         if( !aPointMap.isEmpty() )
         {
-          aPointMap[ HYDROGUI_PrsImage::PointA ].Point = aPointA1;
-          aPointMap[ HYDROGUI_PrsImage::PointB ].Point = aPointB1;
-          aPointMap[ HYDROGUI_PrsImage::PointC ].Point = aPointC1;
+          aPointMap[ HYDROGUI_PrsImage::PointA ].Point = aLocalPointA;
+          aPointMap[ HYDROGUI_PrsImage::PointB ].Point = aLocalPointB;
+          if ( !anIsByTwoPoints )
+            aPointMap[ HYDROGUI_PrsImage::PointC ].Point = aLocalPointC;
+
           myPreviewPrs->setTransformationPointMap( aPointMap );
         }
       }
 
+      HYDROData_Image::TransformationMode aTrsfMode;
+      QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
+      myEditedObject->GetGlobalPoints( aTrsfMode,
+                                       aTrsfPointA, aTrsfPointB, aTrsfPointC );
+
       HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
-      aDataMap[ HYDROGUI_PrsImage::PointA ] =
-        HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2, aPointA3 );
+      aDataMap[ HYDROGUI_PrsImage::PointA ] = 
+        HYDROGUI_ImportImageDlg::ComputeTrsfData( aTrsfMode, aLocalPointA, aTrsfPointA );
       aDataMap[ HYDROGUI_PrsImage::PointB ] =
-        HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2, aPointB3 );
-      aDataMap[ HYDROGUI_PrsImage::PointC ] =
-        HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2, aPointC3 );
+        HYDROGUI_ImportImageDlg::ComputeTrsfData( aTrsfMode, aLocalPointB, aTrsfPointB );
+      if ( !anIsByTwoPoints )
+        aDataMap[ HYDROGUI_PrsImage::PointC ] =
+          HYDROGUI_ImportImageDlg::ComputeTrsfData( aTrsfMode, aLocalPointC, aTrsfPointC );
+
+      aPanel->setTransformationMode( aTrsfMode );
       aPanel->setTransformationDataMap( aDataMap );
+      aPanel->setByTwoPoints( anIsByTwoPoints );
+
+      // Set points on reference image
+      if ( aTrsfMode = HYDROData_Image::ReferenceImage )
+      {
+        Handle(HYDROData_Image) aRefImage = myEditedObject->GetTrsfReferenceImage();
+        if ( !aRefImage.IsNull() )
+        {
+          aRefImageName = aRefImage->GetName();
+
+          onRefImageActivated( aRefImageName );
+          if( myRefPreviewPrs )
+          {
+            HYDROGUI_PrsImage::TransformationPointMap aRefPointMap =
+              myRefPreviewPrs->getTransformationPointMap();
+            if( !aRefPointMap.isEmpty() )
+            {
+              aRefPointMap[ HYDROGUI_PrsImage::PointA ].Point = aTrsfPointA.toPoint();
+              aRefPointMap[ HYDROGUI_PrsImage::PointB ].Point = aTrsfPointB.toPoint();
+              if ( !anIsByTwoPoints )
+                aRefPointMap[ HYDROGUI_PrsImage::PointC ].Point = aTrsfPointC.toPoint();
+
+              myRefPreviewPrs->setTransformationPointMap( aRefPointMap );
+            }
+          }
+
+          HYDROGUI_ImportImageDlg::TransformationDataMap aRefDataMap;
+          aRefDataMap[ HYDROGUI_PrsImage::PointA ] = HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointA.toPoint() );
+          aRefDataMap[ HYDROGUI_PrsImage::PointB ] = HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointB.toPoint() );
+          if ( !anIsByTwoPoints )
+            aRefDataMap[ HYDROGUI_PrsImage::PointC ] = HYDROGUI_ImportImageDlg::TransformationData( aTrsfPointC.toPoint() );
+
+          aPanel->setTransformationDataMap( aRefDataMap, true, true );
+        }
+      }
     }
   }
 
@@ -129,26 +168,29 @@ void HYDROGUI_ImportImageOp::startOperation()
       if( myIsEdit && IsEqual( anImageObj, myEditedObject ) )
         continue;
 
-      QPoint aPointA1, aPointB1, aPointC1;
-      QPointF aPointA2, aPointB2, aPointC2;
-      QPointF aPointA3, aPointB3, aPointC3;
-      anImageObj->TrsfPoints( aPointA1, aPointB1, aPointC1,
-                              aPointA2, aPointB2, aPointC2,
-                              aPointA3, aPointB3, aPointC3 );
+      QPoint aLocalPointA, aLocalPointB, aLocalPointC;
+      anImageObj->GetLocalPoints( aLocalPointA, aLocalPointB, aLocalPointC );
+      
+      HYDROData_Image::TransformationMode aImgTrsfMode;
+      QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC;
+      anImageObj->GetGlobalPoints( aImgTrsfMode,
+                                   aTrsfPointA, aTrsfPointB, aTrsfPointC );
 
       HYDROGUI_ImportImageDlg::TransformationDataMap aDataMap;
-      aDataMap[ HYDROGUI_PrsImage::PointA ] =
-        HYDROGUI_ImportImageDlg::TransformationData( aPointA1, aPointA2, aPointA3 );
+      aDataMap[ HYDROGUI_PrsImage::PointA ] = 
+        HYDROGUI_ImportImageDlg::ComputeTrsfData( aImgTrsfMode, aLocalPointA, aTrsfPointA );
       aDataMap[ HYDROGUI_PrsImage::PointB ] =
-        HYDROGUI_ImportImageDlg::TransformationData( aPointB1, aPointB2, aPointB3 );
+        HYDROGUI_ImportImageDlg::ComputeTrsfData( aImgTrsfMode, aLocalPointB, aTrsfPointB );
       aDataMap[ HYDROGUI_PrsImage::PointC ] =
-        HYDROGUI_ImportImageDlg::TransformationData( aPointC1, aPointC2, aPointC3 );
+        HYDROGUI_ImportImageDlg::ComputeTrsfData( aImgTrsfMode, aLocalPointC, aTrsfPointC );
 
       HYDROGUI_ImportImageDlg::PrsPointData aPrsPointData( anImageObj->GetName(), aDataMap );
       aPrsPointDataList.append( aPrsPointData );
     }
   }
+
   aPanel->setPrsPointDataList( aPrsPointDataList );
+  aPanel->setRefImageName( aRefImageName );
 }
 
 void HYDROGUI_ImportImageOp::abortOperation()
@@ -181,6 +223,57 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
   return aPanel;
 }
 
+bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA,
+                                          const QPointF& thePointB,
+                                          const QPointF& thePointC,
+                                          const bool     theIsByTwoPoints,
+                                          const QString& theLineErrMsg,
+                                          const QString& thePoinErrMsg,
+                                          QString&       theErrorMsg,
+                                          const bool     theIsToCheckInvertibles ) const
+{
+  double xa = thePointA.x();
+  double ya = thePointA.y();
+  double xb = thePointB.x();
+  double yb = thePointB.y();
+  double xc = thePointC.x();
+  double yc = thePointC.y();
+
+  if ( !theIsByTwoPoints )
+  {
+    // check that three input points don't belong to a single line
+    if ( ValuesEquals( ( yb - ya ) * ( xc - xa ), ( yc - ya ) * ( xb - xa ) ) )
+    {
+      theErrorMsg = theLineErrMsg;
+      return false;
+    }
+  }
+  else 
+  {
+    // check that two points are not identical
+    if ( ValuesEquals( xa, ya ) && ValuesEquals( xb, yb ) )
+    {
+      theErrorMsg = thePoinErrMsg;
+      return false;
+    }
+  }
+
+  if ( theIsToCheckInvertibles )
+  {
+    QTransform aTransform1( xa, ya, 1, xb, yb, 1, xc, yc, 1 );
+
+    bool anIsInvertible = false;
+    QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
+    if( !anIsInvertible )
+    {
+      theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
+      return false;
+    }
+  }
+
+  return true;
+}
+
 bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
                                            QString& theErrorMsg )
 {
@@ -201,90 +294,76 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
     }
   }
 
-  int aTransformationMode = aPanel->getTransformationMode();
-  bool anIsRefImage = aTransformationMode == HYDROGUI_ImportImageDlg::RefImage;
-
   HYDROGUI_ImportImageDlg::TransformationDataMap aMap;
   if( !aPanel->getTransformationDataMap( aMap ) )
     return false;
 
-  HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
-  if( anIsRefImage && !aPanel->getTransformationDataMap( aRefMap, true ) )
-    return false;
+  bool anIsByTwoPoints = aPanel->isByTwoPoints();
 
   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;
+  QPoint aPointC = anIsByTwoPoints ? QPoint( INT_MIN, INT_MIN ) :
+                                     aMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
+
+  // first, we check correctness of image points
+  if ( !checkPoints( aPointA, aPointB, aPointC, anIsByTwoPoints, 
+                     tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
+                     tr( "POINTS_A_B_ARE_IDENTICAL" ),
+                     theErrorMsg, true ) )
+    return false;
 
-  QPointF aCPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
-  QPointF aCPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
-  QPointF aCPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
+  Handle(HYDROData_Image) aRefImageObj;
+  QPointF aTrsfPointA, aTrsfPointB, aTrsfPointC( INT_MIN, INT_MIN );
 
-  QPoint aRefPointA, aRefPointB, aRefPointC;
-  if( anIsRefImage )
+  HYDROData_Image::TransformationMode aTransformationMode = 
+    (HYDROData_Image::TransformationMode)aPanel->getTransformationMode();
+  if ( aTransformationMode == HYDROData_Image::ReferenceImage )
   {
-    aRefPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
-    aRefPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
-    aRefPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
-  }
+    QString aRefImageName = aPanel->getRefImageName();
+    if( aRefImageName.isEmpty() )
+    {
+      theErrorMsg = tr( "REFERENCE_IMAGE_IS_NOT_SELECTED" );
+      return false;
+    }
 
-  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( ( yb - ya ) * ( xc - xa ) == ( yc - ya ) * ( xb - xa ) )
-  {
-    theErrorMsg = tr( "POINTS_A_B_C_BELONG_TO_SINGLE_LINE" );
-    return false;
-  }
+    HYDROGUI_ImportImageDlg::TransformationDataMap aRefMap;
+    if( !aPanel->getTransformationDataMap( aRefMap, true ) )
+      return false;
 
-  // the same check for the reference points
-  if( anIsRefImage &&
-      ( ( yrb - yra ) * ( xrc - xra ) == ( yrc - yra ) * ( xrb - xra ) ) )
-  {
-    theErrorMsg = tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" );
-    return false;
-  }
+    aRefImageObj = Handle(HYDROData_Image)::DownCast(
+      HYDROGUI_Tool::FindObjectByName( module(), aRefImageName, KIND_IMAGE ) );
+    if( aRefImageObj.IsNull() )
+      return false;
 
-  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 );
+    aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
+    aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
+    if ( !anIsByTwoPoints )
+      aTrsfPointC = aRefMap[ HYDROGUI_PrsImage::PointC ].ImagePoint;
 
-  bool anIsInvertible = false;
-  QTransform aTransform1Inverted = aTransform1.inverted( &anIsInvertible );
-  if( !anIsInvertible )
-  {
-    theErrorMsg = tr( "TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED" );
-    return false;
+    // the same check of correctness for the reference points
+    if ( !checkPoints( aTrsfPointA, aTrsfPointB, aTrsfPointC, anIsByTwoPoints, 
+                       tr( "REFERENCE_POINTS_A_B_C_BELONG_TO_SINGLE_LINE" ),
+                       tr( "REFERENCE_POINTS_A_B_ARE_IDENTICAL" ),
+                       theErrorMsg, false ) )
+      return false;
   }
-
-  QTransform aTransform;
-  if( anIsRefImage )
-    aTransform = aTransform1Inverted * aTransform3 * myRefTransform;
   else
-    aTransform = aTransform1Inverted * aTransform2;
+  {
+    if ( aTransformationMode == HYDROData_Image::ManualLambert )
+    {
+      aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].LambertPoint;
+      aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].LambertPoint;
+      if ( !anIsByTwoPoints )
+        aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].LambertPoint;
+    }
+    else
+    {
+      aTrsfPointA = aMap[ HYDROGUI_PrsImage::PointA ].CartesianPoint;
+      aTrsfPointB = aMap[ HYDROGUI_PrsImage::PointB ].CartesianPoint;
+      if ( !anIsByTwoPoints )
+        aTrsfPointC = aMap[ HYDROGUI_PrsImage::PointC ].CartesianPoint;
+    }
+  }
 
   Handle(HYDROData_Image) anImageObj;
   if( myIsEdit )
@@ -296,38 +375,19 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
     return false;
 
   anImageObj->SetName( anImageName );
-
   anImageObj->SetImage( myImage );
-  anImageObj->SetTrsf( aTransform );
+  anImageObj->SetLocalPoints( aPointA, aPointB, aPointC );
 
-  if( anIsRefImage )
+  if ( aTransformationMode == HYDROData_Image::ReferenceImage )
   {
-    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->SetReferencePoints( aRefImageObj,
+                                    aTrsfPointA, aTrsfPointB, aTrsfPointC );
+  }
+  else
+  {
+    anImageObj->SetGlobalPoints( aTransformationMode,
+                                 aTrsfPointA, aTrsfPointB, aTrsfPointC );
   }
-
-  anImageObj->SetTrsfMode( aTransformationMode );
-  anImageObj->SetTrsfPoints( aPointA, aPointB, aPointC,
-                             aLPointA, aLPointB, aLPointC,
-                             aCPointA, aCPointB, aCPointC );
 
   if( !myIsEdit )
   {
@@ -449,7 +509,7 @@ void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
 
   QString aRefImageName;
-  if( theMode == HYDROGUI_ImportImageDlg::RefImage )
+  if( theMode == HYDROData_Image::ReferenceImage )
   {
     aRefImageName = aPanel->getRefImageName();
     if( aRefImageName.isEmpty() )
@@ -467,7 +527,6 @@ void HYDROGUI_ImportImageOp::onModeActivated( int theMode )
 
 void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
 {
-  myRefTransform.reset();
   GraphicsView_ViewPort* aViewPort = 0;
 
   LightApp_Application* anApp = module()->getApp();
@@ -522,7 +581,6 @@ void HYDROGUI_ImportImageOp::onRefImageActivated( const QString& theName )
   if( !anImageObj.IsNull() )
   {
     anImage = anImageObj->Image();
-    myRefTransform = anImageObj->Trsf();
 
     myRefPreviewPrs = new HYDROGUI_PrsImage( anImageObj );
     myRefPreviewPrs->setImage( anImage );
@@ -615,7 +673,7 @@ void HYDROGUI_ImportImageOp::closeView( GraphicsView_ViewManager* &aViewMgr )
                 this, SLOT( onLastViewClosed( SUIT_ViewManager* ) ) );
 
     // Nullify appropriate presentation pointer
-    HYDROGUI_PrsImage* aPrs;
+    HYDROGUI_PrsImage* aPrs = 0;
     switch ( module()->getViewManagerRole( aViewMgr ) )
     {
       case HYDROGUI_Module::VMR_ReferenceImage:
index 2a3ada8fc5cd9ca010fc4719f2e8f678c02abdc0..ad45664edab7f1b025326372048b95cc786f8cf8 100644 (file)
@@ -69,6 +69,15 @@ private:
   void                       closePreview();
   void                       closeView( GraphicsView_ViewManager* &aViewMgr );
 
+  bool                       checkPoints( const QPointF& thePointA,
+                                          const QPointF& thePointB,
+                                          const QPointF& thePointC,
+                                          const bool     theIsByTwoPoints,
+                                          const QString& theLineErrMsg,
+                                          const QString& thePoinErrMsg,
+                                          QString&       theErrorMsg,
+                                          const bool     theIsToCheckInvertibles ) const;
+
 private:
   bool                       myIsEdit;
   Handle(HYDROData_Image)    myEditedObject;
@@ -81,7 +90,6 @@ private:
   HYDROGUI_PrsImage*         myRefPreviewPrs;      //!< The reference image presentation
 
   QImage                     myImage;              //!< The loaded image to import
-  QTransform                 myRefTransform;       //!< The loaded image transformation
 
   int                        myPointType;
 };
index 32edca357e3bdeac0404669be8cbcc336a24bdc0..ff3959f267518b6b619f3cc291fb039f2afd1913 100644 (file)
@@ -228,7 +228,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
         Handle(HYDROData_Image) anImage = Handle(HYDROData_Image)::DownCast( anObject );
         if( !anImage.IsNull() )
         {
-          anIsImportedImage = anImage->HasTrsfPoints() && !anImage->IsSelfSplitted();
+          anIsImportedImage = anImage->HasLocalPoints() && !anImage->IsSelfSplitted();
           anIsCompositeImage = anImage->NbReferences() > 0;
           if( HYDROData_OperationsFactory* aFactory = HYDROData_OperationsFactory::Factory() )
           {
index 27f2979243879d75ef568f3f88180cec1909a260..356f537c745b159d5ec3ca51ccccaa75c749007b 100644 (file)
@@ -300,17 +300,29 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <translation>Transform image</translation>
     </message>
     <message>
-      <source>POINTS_A_B_C_BELONG_TO_SINGLE_LINE</source>
-      <translation>Points A, B, C belong to a single line.</translation>
+      <source>POINTS_A_B_ARE_IDENTICAL</source>
+      <translation>Points A, B are identical.</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>
+      <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_IMAGE</source>
       <translation>Reference image</translation>
     </message>
+    <message>
+      <source>REFERENCE_IMAGE_IS_NOT_SELECTED</source>
+      <translation>Reference image is not selected.</translation>
+    </message>
+    <message>
+      <source>REFERENCE_POINTS_A_B_ARE_IDENTICAL</source>
+      <translation>Reference points A, B are identical.</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>