Salome HOME
HYDROGUI_Wizard has been refactored and now uses QStackedWidget instead of QWizard.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DeleteOp.cxx
index 83372230525666d4519d3f2fb188997e1ff0568a..704fa4e34d8b55b88748fa0e440cb34c39cf03f4 100644 (file)
 
 #include "HYDROGUI_DeleteOp.h"
 
-#include "HYDROGUI_DataModel.h"
 #include "HYDROGUI_Module.h"
-#include "HYDROGUI_Operations.h"
+#include "HYDROGUI_Tool.h"
 #include "HYDROGUI_UpdateFlags.h"
 
-#include <HYDROData_Iterator.h>
 #include <HYDROData_Object.h>
 
 #include <LightApp_Application.h>
-#include <LightApp_DataOwner.h>
 
 #include <SUIT_Desktop.h>
 #include <SUIT_MessageBox.h>
-#include <SUIT_SelectionMgr.h>
 
 HYDROGUI_DeleteOp::HYDROGUI_DeleteOp( HYDROGUI_Module* theModule )
 : HYDROGUI_Operation( theModule )
@@ -51,17 +47,40 @@ void HYDROGUI_DeleteOp::startOperation()
 {
   HYDROGUI_Operation::startOperation();
 
-  HYDROGUI_DataModel* aModel = module()->getDataModel();
+  HYDROData_SequenceOfObjects aFullSeq; // selected objects with their back-references
+  QStringList aFullNames;
 
-  SUIT_SelectionMgr* aSelectionMgr = selectionMgr();
-  SUIT_DataOwnerPtrList anOwners;
-  aSelectionMgr->selected( anOwners );
-
-  if( !anOwners.isEmpty() )
+  HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
+  if( !aSeq.IsEmpty() )
   {
+    for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
+    {
+      Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
+      if( !anObject.IsNull() )
+      {
+        aFullSeq.Append( anObject );
+        aFullNames.append( anObject->GetName() );
+
+        // collect the back-references
+        ObjectKind aKind = anObject->GetKind();
+        if( aKind == KIND_IMAGE || aKind == KIND_POLYLINE )
+        {
+          HYDROData_SequenceOfObjects anObjects;
+          QStringList aNames;
+          HYDROGUI_Tool::GetObjectBackReferences( module(), anObject, anObjects, aNames );
+          aFullSeq.Append( anObjects );
+          aFullNames.append( aNames );
+        }
+      }
+    }
+
+    aFullNames.removeDuplicates();
+    aFullNames.sort();
+
+    QString aList = aFullNames.join( "\n" );
     int anAnswer = SUIT_MessageBox::question( module()->getApp()->desktop(),
                                               tr( "DELETE_OBJECTS" ),
-                                              tr( "CONFIRM_DELETION" ),
+                                              tr( "CONFIRM_DELETION" ).arg( aList ),
                                               QMessageBox::Yes | QMessageBox::No,
                                               QMessageBox::No );
     if( anAnswer == QMessageBox::No )
@@ -71,16 +90,15 @@ void HYDROGUI_DeleteOp::startOperation()
     }
   }
 
-  foreach( SUIT_DataOwner* aSUITOwner, anOwners )
+  startDocOperation();
+  for( Standard_Integer anIndex = 1, aLength = aFullSeq.Length(); anIndex <= aLength; anIndex++ )
   {
-    if( LightApp_DataOwner* anOwner = dynamic_cast<LightApp_DataOwner*>( aSUITOwner ) )
-    {
-      Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() );
-      if( !anObject.IsNull() )
-        anObject->Remove();
-    }
+    Handle(HYDROData_Entity) anObject = aFullSeq.Value( anIndex );
+    if( !anObject.IsNull() && !anObject->IsRemoved() )
+      anObject->Remove();
   }
+  commitDocOperation();
 
-  module()->update( UF_Model | UF_Viewer );
+  module()->update( UF_Model | UF_Viewer | UF_OCCViewer );
   commit();
 }