#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 )
{
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_Object) 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 )
}
}
- 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_Object) anObject = aFullSeq.Value( anIndex );
+ if( !anObject.IsNull() && !anObject->IsRemoved() )
+ anObject->Remove();
}
+ commitDocOperation();
module()->update( UF_Model | UF_Viewer );
commit();