1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_DeleteOp.h"
21 #include "HYDROGUI_DeleteDlg.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Tool.h"
24 #include "HYDROGUI_UpdateFlags.h"
26 #include <HYDROData_Object.h>
28 #include <LightApp_Application.h>
30 #include <SUIT_Desktop.h>
31 #include <SUIT_MessageBox.h>
33 HYDROGUI_DeleteOp::HYDROGUI_DeleteOp( HYDROGUI_Module* theModule )
34 : HYDROGUI_Operation( theModule )
36 setName( tr( "DELETE" ) );
39 HYDROGUI_DeleteOp::~HYDROGUI_DeleteOp()
43 void HYDROGUI_DeleteOp::startOperation()
45 HYDROGUI_Operation::startOperation();
47 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
54 bool anIsCanRemove = true;
56 QStringList anObjNames;
57 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
59 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
60 if( anObject.IsNull() )
63 if ( !anObject->CanRemove() )
65 anIsCanRemove = false;
69 anObjNames.append( anObject->GetName() );
74 SUIT_MessageBox::critical( module()->getApp()->desktop(),
75 tr( "DELETE_OBJECTS" ), tr( "DELETE_OBJECTS_IMPOSIBLE" ) );
80 anObjNames.removeDuplicates();
82 // check the back-references
83 QMap<QString,HYDROData_SequenceOfObjects> aBackObjects =
84 HYDROGUI_Tool::GetObjectsBackReferences( module(), anObjNames );
86 QMap<QString,HYDROData_SequenceOfObjects>::const_iterator anIt = aBackObjects.begin(),
87 aLast = aBackObjects.end();
89 for ( ; anIt != aLast; anIt++ ) {
91 HYDROData_SequenceOfObjects::Iterator anIter( anIt.value() );
92 for ( ; anIter.More(); anIter.Next() )
94 Handle(HYDROData_Entity) anEntity = anIter.Value();
95 if ( anEntity.IsNull() )
97 aSeqList.append( QString( tr( "DELETE_OBJECT_NAME" ) ).arg( anEntity->GetName() ) );
99 aRefList.append( QString( tr( "DELETE_OBJECT_IS_USED_FOR" ) ).arg( anIt.key() )
100 .arg( aSeqList.join( ", " ) ) );
103 //QString aNamesList = anObjNames.join( "\n" );
104 if ( !aBackObjects.isEmpty() )
106 SUIT_MessageBox::critical( module()->getApp()->desktop(),
107 tr( "DELETE_OBJECTS" ),
108 tr( "DELETED_OBJECTS_HAS_BACKREFERENCES" ).arg( aRefList.join( "\n" ) ) );
113 HYDROGUI_DeleteDlg aDeleteDlg( module()->getApp()->desktop() );
114 aDeleteDlg.setObjectsToRemove( anObjNames );
115 if ( aDeleteDlg.exec() != HYDROGUI_DeleteDlg::Accepted )
123 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
125 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
127 if ( !anObject.IsNull() && !anObject->IsRemoved() ) {
129 module()->setObjectRemoved( anObject );
133 commitDocOperation();
135 module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer );