]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Refs #156 - cross-dependence of images - check and error or filter BR_hydro_v_0_6
authornds <nds@opencascade.com>
Fri, 20 Dec 2013 12:39:59 +0000 (12:39 +0000)
committernds <nds@opencascade.com>
Fri, 20 Dec 2013 12:39:59 +0000 (12:39 +0000)
src/HYDROGUI/HYDROGUI_ImportImageOp.cxx
src/HYDROGUI/HYDROGUI_ImportImageOp.h
src/HYDROGUI/resources/HYDROGUI_msg_en.ts

index f7f0fcf452e69b7665a13fceaaec1f900e3c0a34..06836f638f52c697baa5436b02043b12b9f631b9 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <STD_TabDesktop.h>
 #include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
 #include <QtxWorkstack.h>
 #include <QApplication>
 #include <QFileInfo>
@@ -399,6 +400,9 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
     if( aRefImageObj.IsNull() )
       return false;
 
+    else if ( !isReferenceCorrect() )
+      aRefImageObj->RemoveAllReferences();
+
     aTrsfPointA = aRefMap[ HYDROGUI_PrsImage::PointA ].ImagePoint;
     aTrsfPointB = aRefMap[ HYDROGUI_PrsImage::PointB ].ImagePoint;
     if ( !anIsByTwoPoints )
@@ -472,6 +476,53 @@ bool HYDROGUI_ImportImageOp::processApply( int& theUpdateFlags,
   return true;
 }
 
+bool HYDROGUI_ImportImageOp::isReferenceCorrect() const
+{
+  bool isCorrect = true;
+
+  if( myIsEdit && !myEditedObject.IsNull() )
+  {
+    HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+    Handle(HYDROData_Image) aRefImageObj = Handle(HYDROData_Image)::DownCast(
+      HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRefImageName(), KIND_IMAGE ) );
+    if( !aRefImageObj.IsNull() )
+    {
+      bool isFoundEdited = false;
+      HYDROData_SequenceOfObjects aRefSeq = aRefImageObj->GetAllReferenceObjects();
+      for ( int i = 1, n = aRefSeq.Length(); i <= n && !isFoundEdited; ++i )
+      {
+        Handle(HYDROData_Entity) anObject = aRefSeq.Value( i );
+        isFoundEdited = anObject->GetName() == myEditedObject->GetName();
+      }
+      isCorrect = !isFoundEdited;
+    }
+  }
+  return isCorrect;
+}
+
+void HYDROGUI_ImportImageOp::onApply()
+{
+  HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
+
+  bool aCanApply = isReferenceCorrect();
+  if ( !aCanApply && !myEditedObject.IsNull() )
+  {
+    Handle(HYDROData_Image) aRefImageObj = Handle(HYDROData_Image)::DownCast(
+      HYDROGUI_Tool::FindObjectByName( module(), aPanel->getRefImageName(), KIND_IMAGE ) );
+    if ( !aRefImageObj.IsNull() )
+      aCanApply = SUIT_MessageBox::question( module()->getApp()->desktop(),
+                    tr( "CORRECT_INPUT_DATA" ), tr( "CONFIRM_REMOVE_REFERENCE_FROM_IMAGE" ).
+                    arg( aRefImageObj->GetName() ).arg( myEditedObject->GetName() ),
+                    QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) == QMessageBox::Yes;
+  }
+  if ( aCanApply )
+    HYDROGUI_Operation::onApply();
+  else {
+    aPanel->setRefImageName( "" );
+    onRefImageActivated( aPanel->getRefImageName() );
+  }
+}
+
 void HYDROGUI_ImportImageOp::onCreatePreview( QImage theImage )
 {
   HYDROGUI_ImportImageDlg* aPanel = (HYDROGUI_ImportImageDlg*)inputPanel();
index e14249d55265e67247bdbb5790bc04b3582a04a1..5a7e858f89db5605cd1665d1e680e6e6bf076278 100644 (file)
@@ -50,8 +50,11 @@ protected:
   virtual HYDROGUI_InputPanel* createInputPanel() const;
 
   virtual bool               processApply( int& theUpdateFlags, QString& theErrorMsg );
+  bool                       isReferenceCorrect() const;
 
 protected slots:
+  virtual void               onApply();
+
   void                       onCreatePreview( QImage );
   void                       onActivatePointSelection( int );
   void                       onPointCoordChanged( bool, int, bool, int );
index 7b28a0386b4562c13931cccb67f7a72c72c272b2..6b4abbd943dd618593bb0048e5146c144aeafee5 100644 (file)
@@ -544,6 +544,15 @@ file cannot be correctly imported for a Bathymetry definition.</translation>
       <source>TRANSFORMATION_MATRIX_CANNOT_BE_COMPUTED</source>
       <translation>Transformation matrix cannot be computed.</translation>
     </message>
+    <message>
+      <source>CORRECT_INPUT_DATA</source>
+      <translation>Correct input data</translation>
+    </message>
+    <message>
+      <source>CONFIRM_REMOVE_REFERENCE_FROM_IMAGE</source>
+      <translation>The image "%1" has a reference to the current object.
+Would you like to remove all references from the image?</translation>
+    </message>
   </context>
   
   <context>