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"
20 #include "HYDROGUI_DataModel.h"
21 #include "HYDROGUI_DeleteDlg.h"
22 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_Tool.h"
24 #include "HYDROGUI_Tool2.h"
25 #include "HYDROGUI_UpdateFlags.h"
26 #include "HYDROGUI_ProfileOp.h"
28 #include <HYDROData_Object.h>
29 #include <HYDROData_Document.h>
31 #include <LightApp_Application.h>
33 #include <SUIT_Desktop.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_Study.h>
39 HYDROGUI_DeleteOp::HYDROGUI_DeleteOp( HYDROGUI_Module* theModule )
40 : HYDROGUI_Operation( theModule )
42 setName( tr( "DELETE" ) );
45 HYDROGUI_DeleteOp::~HYDROGUI_DeleteOp()
49 void HYDROGUI_DeleteOp::startOperation()
51 QList<SUIT_Operation*> operations = study()->operations();
52 int n = operations.size();
55 SUIT_Operation* anOtherOp = operations[n-2];
56 HYDROGUI_ProfileOp* aProfileOp = dynamic_cast<HYDROGUI_ProfileOp*>( anOtherOp );
59 aProfileOp->deleteSelected();
65 HYDROGUI_Operation::startOperation();
67 HYDROData_SequenceOfObjects aSeq = HYDROGUI_Tool::GetSelectedObjects( module() );
74 bool anIsCanRemove = true;
76 QStringList anObjNames;
77 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
79 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
80 if( anObject.IsNull() )
83 if ( !anObject->CanRemove() )
85 anIsCanRemove = false;
89 anObjNames.append( anObject->GetName() );
94 SUIT_MessageBox::critical( module()->getApp()->desktop(),
95 tr( "DELETE_OBJECTS" ), tr( "DELETE_OBJECTS_IMPOSIBLE" ) );
100 anObjNames.removeDuplicates();
102 // check the back-references
103 QMap<QString,HYDROData_SequenceOfObjects> aBackObjects =
104 HYDROGUI_Tool::GetObjectsBackReferences( doc(), anObjNames );
106 QMap<QString,HYDROData_SequenceOfObjects>::const_iterator anIt = aBackObjects.begin(),
107 aLast = aBackObjects.end();
108 QStringList aRefList;
109 for ( ; anIt != aLast; anIt++ ) {
110 QStringList aSeqList;
111 HYDROData_SequenceOfObjects::Iterator anIter( anIt.value() );
112 for ( ; anIter.More(); anIter.Next() )
114 Handle(HYDROData_Entity) anEntity = anIter.Value();
115 if ( anEntity.IsNull() )
117 aSeqList.append( QString( tr( "DELETE_OBJECT_NAME" ) ).arg( anEntity->GetName() ) );
119 aRefList.append( QString( tr( "DELETE_OBJECT_IS_USED_FOR" ) ).arg( anIt.key() )
120 .arg( aSeqList.join( ", " ) ) );
123 //QString aNamesList = anObjNames.join( "\n" );
124 if ( !aBackObjects.isEmpty() )
126 SUIT_MessageBox::critical( module()->getApp()->desktop(),
127 tr( "DELETE_OBJECTS" ),
128 tr( "DELETED_OBJECTS_HAS_BACKREFERENCES" ).arg( aRefList.join( "\n" ) ) );
135 HYDROGUI_DeleteDlg aDeleteDlg( module()->getApp()->desktop() );
136 aDeleteDlg.setObjectsToRemove( anObjNames );
137 bool isLastStricklerRemoved = false;
138 if ( aDeleteDlg.exec() != HYDROGUI_DeleteDlg::Accepted )
145 QStringList aTableNames =
146 HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_STRICKLER_TABLE, false );
147 aTableNames += anObjNames;
148 if ( aTableNames.toSet().size() == anObjNames.size() )
150 aWarningMsg = tr("DELETE_LAST_TABLE_WRN");
151 isLastStricklerRemoved = true;
155 if ( !aWarningMsg.isEmpty() ) {
156 int anAnswer = SUIT_MessageBox::warning( module()->getApp()->desktop(),
157 tr("WARNING"), aWarningMsg,
158 QMessageBox::Yes | QMessageBox::No,
160 if ( anAnswer != QMessageBox::Yes ) {
168 for( Standard_Integer anIndex = 1, aLength = aSeq.Length(); anIndex <= aLength; anIndex++ )
170 Handle(HYDROData_Entity) anObject = aSeq.Value( anIndex );
172 if ( !anObject.IsNull() && !anObject->IsRemoved() ) {
174 module()->setObjectRemoved( anObject );
178 if( isLastStricklerRemoved )
180 HYDROGUI_DataModel* aModel = dynamic_cast<HYDROGUI_DataModel*>( module()->dataModel() );
181 aModel->createDefaultStricklerTable( doc(), 0 );
184 commitDocOperation();
186 module()->update( UF_Model | UF_Viewer | UF_OCCViewer | UF_VTKViewer );
189 module()->enableLCMActions();