X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_DeleteOp.cxx;h=da2cd3739a300c4b2c0dc1001bc9544ca57c5c91;hb=a1431f03eac1d1aed4203d0568d987c41ce939b3;hp=83372230525666d4519d3f2fb188997e1ff0568a;hpb=94f079c9197f9655e023e5047feffea452b4a1fe;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx index 83372230..da2cd373 100644 --- a/src/HYDROGUI/HYDROGUI_DeleteOp.cxx +++ b/src/HYDROGUI/HYDROGUI_DeleteOp.cxx @@ -22,20 +22,16 @@ #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 #include #include -#include #include #include -#include HYDROGUI_DeleteOp::HYDROGUI_DeleteOp( HYDROGUI_Module* theModule ) : HYDROGUI_Operation( theModule ) @@ -51,36 +47,77 @@ void HYDROGUI_DeleteOp::startOperation() { HYDROGUI_Operation::startOperation(); - HYDROGUI_DataModel* aModel = module()->getDataModel(); + HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() ); + if( aSeq.IsEmpty() ) + { + abort(); + return; + } - SUIT_SelectionMgr* aSelectionMgr = selectionMgr(); - SUIT_DataOwnerPtrList anOwners; - aSelectionMgr->selected( anOwners ); + bool anIsCanRemove = true; - if( !anOwners.isEmpty() ) + QStringList anObjNames; + for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) { - int anAnswer = SUIT_MessageBox::question( module()->getApp()->desktop(), - tr( "DELETE_OBJECTS" ), - tr( "CONFIRM_DELETION" ), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No ); - if( anAnswer == QMessageBox::No ) + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); + if( anObject.IsNull() ) + continue; + + if ( !anObject->CanRemove() ) { - abort(); - return; + anIsCanRemove = false; + break; } + + anObjNames.append( anObject->GetName() ); } - foreach( SUIT_DataOwner* aSUITOwner, anOwners ) + if ( !anIsCanRemove ) { - if( LightApp_DataOwner* anOwner = dynamic_cast( aSUITOwner ) ) - { - Handle(HYDROData_Object) anObject = aModel->objectByEntry( anOwner->entry() ); - if( !anObject.IsNull() ) - anObject->Remove(); - } + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "DELETE_OBJECTS" ), tr( "DELETE_OBJECTS_IMPOSIBLE" ) ); + abort(); + return; } - module()->update( UF_Model | UF_Viewer ); + anObjNames.removeDuplicates(); + anObjNames.sort(); + + // check the back-references + QMap aBackObjects = + HYDROGUI_Tool::GetObjectsBackReferences( module(), anObjNames ); + + if ( !aBackObjects.isEmpty() ) + { + SUIT_MessageBox::critical( module()->getApp()->desktop(), + tr( "DELETE_OBJECTS" ), tr( "DELETED_OBJECTS_HAS_BACKREFERENCES" ) ); + abort(); + return; + } + + QString aNamesList = anObjNames.join( "\n" ); + int anAnswer = SUIT_MessageBox::question( module()->getApp()->desktop(), + tr( "DELETE_OBJECTS" ), + tr( "CONFIRM_DELETION" ).arg( aNamesList ), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No ); + if( anAnswer == QMessageBox::No ) + { + abort(); + return; + } + + startDocOperation(); + + for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ ) + { + Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex ); + if ( !anObject.IsNull() && !anObject->IsRemoved() ) + anObject->Remove(); + } + + commitDocOperation(); + + module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer ); commit(); }