1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_DeleteGroupDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_DeleteGroupDlg.h"
31 #include "SMESH_TypeFilter.hxx"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
35 #include "QAD_Desktop.h"
36 #include "SALOME_Selection.h"
37 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include <qpushbutton.h>
42 #include <qgroupbox.h>
46 #include <qmessagebox.h>
48 #include "SALOMEconfig.h"
49 #include CORBA_SERVER_HEADER(SMESH_Mesh)
55 Class : SMESHGUI_DeleteGroupDlg
56 Description : Delete groups and their contents
59 //=======================================================================
60 // name : SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg
61 // Purpose : Constructor
62 //=======================================================================
63 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg( QWidget* theParent,
64 SALOME_Selection* theSelection )
65 : QDialog( theParent, "SMESHGUI_DeleteGroupDlg", false,
66 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
68 setCaption( tr( "CAPTION" ) );
70 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
72 QFrame* aMainFrame = createMainFrame ( this );
73 QFrame* aBtnFrame = createButtonFrame( this );
75 aDlgLay->addWidget( aMainFrame );
76 aDlgLay->addWidget( aBtnFrame );
78 aDlgLay->setStretchFactor( aMainFrame, 1 );
80 Init( theSelection ) ;
83 //=======================================================================
84 // name : SMESHGUI_DeleteGroupDlg::createMainFrame
85 // Purpose : Create frame containing dialog's input fields
86 //=======================================================================
87 QFrame* SMESHGUI_DeleteGroupDlg::createMainFrame( QWidget* theParent )
89 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, tr( "SELECTED_GROUPS" ), theParent );
91 myListBox = new QListBox( aMainGrp );
92 myListBox->setMinimumHeight( 100 );
93 myListBox->setSelectionMode( QListBox::NoSelection );
94 myListBox->setRowMode( QListBox::FitToWidth );
99 //=======================================================================
100 // name : SMESHGUI_DeleteGroupDlg::createButtonFrame
101 // Purpose : Create frame containing buttons
102 //=======================================================================
103 QFrame* SMESHGUI_DeleteGroupDlg::createButtonFrame( QWidget* theParent )
105 QFrame* aFrame = new QFrame( theParent );
106 aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
108 myOkBtn = new QPushButton( tr( "SMESH_BUT_OK" ), aFrame );
109 myApplyBtn = new QPushButton( tr( "SMESH_BUT_APPLY" ), aFrame );
110 myCloseBtn = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aFrame );
112 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
114 QHBoxLayout* aLay = new QHBoxLayout( aFrame, MARGIN, SPACING );
116 aLay->addWidget( myOkBtn );
117 aLay->addWidget( myApplyBtn );
118 aLay->addItem( aSpacer);
119 aLay->addWidget( myCloseBtn );
121 // connect signals and slots
122 connect( myOkBtn, SIGNAL( clicked() ), SLOT( onOk() ) );
123 connect( myCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) ) ;
124 connect( myApplyBtn, SIGNAL( clicked() ), SLOT( onApply() ) );
129 //=======================================================================
130 // name : SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg
131 // Purpose : Destructor
132 //=======================================================================
133 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
137 //=======================================================================
138 // name : SMESHGUI_DeleteGroupDlg::Init
139 // Purpose : Init dialog fields, connect signals and slots, show dialog
140 //=======================================================================
141 void SMESHGUI_DeleteGroupDlg::Init( SALOME_Selection* theSelection )
143 myBlockSelection = false;
144 mySelection = theSelection;
145 SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
146 aSMESHGUI->SetActiveDialogBox( ( QDialog* )this ) ;
148 // selection and SMESHGUI
149 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
150 connect( aSMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
151 connect( aSMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
154 aSMESHGUI->DefineDlgPosition( this, x, y );
158 // set selection mode
159 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection, true );
160 mySelection->AddFilter( new SMESH_TypeFilter( GROUP ) );
166 //=======================================================================
167 // name : SMESHGUI_DeleteGroupDlg::isValid
168 // Purpose : Verify validity of input data
169 //=======================================================================
170 bool SMESHGUI_DeleteGroupDlg::isValid()
172 if ( myListBox->count() == 0 )
174 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
175 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "NO_SELECTED_GROUPS" ), QMessageBox::Ok );
179 return !SMESHGUI::GetSMESHGUI()->ActiveStudyLocked();
182 //=======================================================================
183 // name : SMESHGUI_DeleteGroupDlg::onApply
184 // Purpose : SLOT called when "Apply" button pressed.
185 //=======================================================================
186 bool SMESHGUI_DeleteGroupDlg::onApply()
191 myBlockSelection = true;
193 QValueList<SMESH::SMESH_GroupBase_var>::iterator anIter;
194 for ( anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter )
196 SMESH::SMESH_Mesh_ptr aMesh = (*anIter)->GetMesh();
197 if ( !aMesh->_is_nil() )
198 aMesh->RemoveGroupWithContents( *anIter );
203 mySelection->ClearIObjects();
205 SMESHGUI::GetSMESHGUI()->GetActiveStudy()->updateObjBrowser( true );
207 myBlockSelection = false;
211 //=======================================================================
212 // name : SMESHGUI_DeleteGroupDlg::onOk
213 // Purpose : SLOT called when "Ok" button pressed.
214 //=======================================================================
215 void SMESHGUI_DeleteGroupDlg::onOk()
221 //=======================================================================
222 // name : SMESHGUI_DeleteGroupDlg::onClose
223 // Purpose : SLOT called when "Close" button pressed. Close dialog
224 //=======================================================================
225 void SMESHGUI_DeleteGroupDlg::onClose()
227 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
228 disconnect( mySelection, 0, this, 0 );
229 disconnect( SMESHGUI::GetSMESHGUI(), 0, this, 0 );
230 SMESHGUI::GetSMESHGUI()->ResetState() ;
231 mySelection->ClearFilters();
235 //=======================================================================
236 // name : SMESHGUI_DeleteGroupDlg::onSelectionDone
237 // Purpose : SLOT called when selection changed
238 //=======================================================================
239 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
241 if ( myBlockSelection )
247 const SALOME_ListIO& aListIO = mySelection->StoredIObjects();
248 SALOME_ListIteratorOfListIO anIter( aListIO );
249 for( ; anIter.More(); anIter.Next() )
251 SMESH::SMESH_GroupBase_var aGroup =
252 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>( anIter.Value() );
253 if ( !aGroup->_is_nil() )
255 aNames.append( aGroup->GetName() );
256 myListGrp.append( aGroup );
261 myListBox->insertStringList( aNames );
264 //=======================================================================
265 // name : SMESHGUI_DeleteGroupDlg::onDeactivate
266 // Purpose : SLOT called when dialog must be deativated
267 //=======================================================================
268 void SMESHGUI_DeleteGroupDlg::onDeactivate()
270 mySelection->ClearFilters();
274 //=======================================================================
275 // name : SMESHGUI_DeleteGroupDlg::enterEvent
276 // Purpose : Event filter
277 //=======================================================================
278 void SMESHGUI_DeleteGroupDlg::enterEvent( QEvent* )
280 SMESHGUI::GetSMESHGUI()->EmitSignalDeactivateDialog() ;
282 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection, true );
283 mySelection->AddFilter( new SMESH_TypeFilter( GROUP ) );
287 //=================================================================================
288 // function : closeEvent()
290 //=================================================================================
291 void SMESHGUI_DeleteGroupDlg::closeEvent( QCloseEvent* )