Salome HOME
Fix for the bug #45: check and warning when the same image is used in 2 arguments.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_ImportImageOp.cxx
index 82de7403539b8b971b7840dbdd4ed93afed7f3a5..b3232d5f191a7427ec888c16deb7409316900466 100644 (file)
@@ -43,6 +43,7 @@
 #include <SUIT_Desktop.h>
 #include <QtxWorkstack.h>
 #include <QApplication>
+#include <QFileInfo>
 
 HYDROGUI_ImportImageOp::HYDROGUI_ImportImageOp( HYDROGUI_Module* theModule,
                                                 const bool theIsEdit )
@@ -270,19 +271,19 @@ HYDROGUI_InputPanel* HYDROGUI_ImportImageOp::createInputPanel() const
   connect( aPanel, SIGNAL( modeActivated( int ) ), SLOT( onModeActivated( int ) ) );
   connect( aPanel, SIGNAL( refImageActivated( const QString& ) ),
                      SLOT( onRefImageActivated( const QString& ) ) );
-  connect( aPanel, SIGNAL( setIsByTwoPoints( bool ) ), SLOT( onSetIsByTwoPoints( bool ) ) );
+  connect( aPanel, SIGNAL( setCIsUsed( bool ) ), SLOT( onSetCIsUsed( bool ) ) );
   return aPanel;
 }
 
-void HYDROGUI_ImportImageOp::onSetIsByTwoPoints( bool theIsSetByTwoPoints )
+void HYDROGUI_ImportImageOp::onSetCIsUsed( bool theCIsUsed )
 {
   if ( myPreviewPrs )
   {
-    myPreviewPrs->setIsByTwoPoints( theIsSetByTwoPoints );
+    myPreviewPrs->setIsByTwoPoints( !theCIsUsed );
   }
   if ( myRefPreviewPrs )
   {
-    myRefPreviewPrs->setIsByTwoPoints( theIsSetByTwoPoints );
+    myRefPreviewPrs->setIsByTwoPoints( !theCIsUsed );
   }
 }
 
@@ -310,30 +311,30 @@ bool HYDROGUI_ImportImageOp::checkPoints( const QPointF& thePointA,
       theErrorMsg = theLineErrMsg;
       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;
+      }
+    }
   }
   else 
   {
     // check that two points are not identical
-    if ( ValuesEquals( xa, ya ) && ValuesEquals( xb, yb ) )
+    if ( ValuesEquals( xa, xb ) && ValuesEquals( ya, 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;
 }
 
@@ -465,8 +466,7 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   if( !myIsEdit )
     module()->setObjectVisible( HYDROGUI_Tool::GetActiveGraphicsViewId( module() ), anImageObj, true );
 
-  if( myIsEdit )
-    anImageObj->Update();
+  anImageObj->Update();
 
   theUpdateFlags = UF_Model | UF_Viewer | UF_GV_Forced | UF_OCCViewer | UF_OCC_Forced;
   return true;
@@ -530,14 +530,27 @@ void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
       }
     }
 
-    QString anImageName;
-    if( myIsEdit )
+    // Set the image name in the dialog
+    QString anImageName = aPanel->getImageName().simplified();
+    // If edit mode and the name was not set yet then get from the edited object
+    if( myIsEdit && anImageName.isEmpty() )
     {
       if( !myEditedObject.IsNull() )
         anImageName = myEditedObject->GetName();
     }
-    else
-      anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
+    // If the name was not set then initialize it from the selected file name
+    if ( anImageName.isEmpty() )
+    {
+      anImageName = aPanel->getFileName();
+      if ( !anImageName.isEmpty() ) {
+          anImageName = QFileInfo( anImageName ).baseName();
+      }
+      // If no file name then generate a new image name
+      if ( anImageName.isEmpty() ) {
+        anImageName = HYDROGUI_Tool::GenerateObjectName( module(), tr( "DEFAULT_IMAGE_NAME" ) );
+      }
+    }
+
     aPanel->setImageName( anImageName );
   }
 
@@ -700,6 +713,7 @@ void HYDROGUI_ImportImageOp::onPointSelected( bool theIsRefImage )
 
   const HYDROGUI_PrsImage::TransformationPointMap& aPointMap =
     aPrs->getTransformationPointMap();
+  
   HYDROGUI_PrsImage::TransformationPointMapIterator anIter( aPointMap );
   while( anIter.hasNext() )
   {