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>
27 #include <HYDROData_Document.h>
29 #include <LightApp_Application.h>
31 #include <SUIT_Desktop.h>
32 #include <SUIT_MessageBox.h>
36 HYDROGUI_DeleteOp::HYDROGUI_DeleteOp( HYDROGUI_Module* theModule )
37 : HYDROGUI_Operation( theModule )
39 setName( tr( "DELETE" ) );
42 HYDROGUI_DeleteOp::~HYDROGUI_DeleteOp()
46 void HYDROGUI_DeleteOp::startOperation()
48 HYDROGUI_Operation::startOperation();
50 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
57 bool anIsCanRemove = true;
59 QStringList anObjNames;
60 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
62 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
63 if( anObject.IsNull() )
66 if ( !anObject->CanRemove() )
68 anIsCanRemove = false;
72 anObjNames.append( anObject->GetName() );
77 SUIT_MessageBox::critical( module()->getApp()->desktop(),
78 tr( "DELETE_OBJECTS" ), tr( "DELETE_OBJECTS_IMPOSIBLE" ) );
83 anObjNames.removeDuplicates();
85 // check the back-references
86 QMap<QString,HYDROData_SequenceOfObjects> aBackObjects =
87 HYDROGUI_Tool::GetObjectsBackReferences( module(), anObjNames );
89 QMap<QString,HYDROData_SequenceOfObjects>::const_iterator anIt = aBackObjects.begin(),
90 aLast = aBackObjects.end();
92 for ( ; anIt != aLast; anIt++ ) {
94 HYDROData_SequenceOfObjects::Iterator anIter( anIt.value() );
95 for ( ; anIter.More(); anIter.Next() )
97 Handle(HYDROData_Entity) anEntity = anIter.Value();
98 if ( anEntity.IsNull() )
100 aSeqList.append( QString( tr( "DELETE_OBJECT_NAME" ) ).arg( anEntity->GetName() ) );
102 aRefList.append( QString( tr( "DELETE_OBJECT_IS_USED_FOR" ) ).arg( anIt.key() )
103 .arg( aSeqList.join( ", " ) ) );
106 //QString aNamesList = anObjNames.join( "\n" );
107 if ( !aBackObjects.isEmpty() )
109 SUIT_MessageBox::critical( module()->getApp()->desktop(),
110 tr( "DELETE_OBJECTS" ),
111 tr( "DELETED_OBJECTS_HAS_BACKREFERENCES" ).arg( aRefList.join( "\n" ) ) );
118 HYDROGUI_DeleteDlg aDeleteDlg( module()->getApp()->desktop() );
119 aDeleteDlg.setObjectsToRemove( anObjNames );
120 if ( aDeleteDlg.exec() != HYDROGUI_DeleteDlg::Accepted )
125 QStringList aTableNames =
126 HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_STRICKLER_TABLE, false );
127 aTableNames += anObjNames;
128 if ( aTableNames.toSet().size() == anObjNames.size() ) {
129 aWarningMsg = tr("DELETE_LAST_TABLE_WRN");
133 if ( !aWarningMsg.isEmpty() ) {
134 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
135 tr("WARNING"), aWarningMsg,
136 QMessageBox::Yes | QMessageBox::No,
138 if ( anAnswer != QMessageBox::Yes ) {
146 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
148 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
150 if ( !anObject.IsNull() && !anObject->IsRemoved() ) {
152 module()->setObjectRemoved( anObject );
156 commitDocOperation();
158 module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer );