1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHGUI_DeleteGroupDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_DeleteGroupDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
33 #include <SMESH_TypeFilter.hxx>
35 // SALOME GUI includes
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_OverrideCursor.h>
42 #include <SalomeApp_Study.h>
43 #include <LightApp_Application.h>
44 #include <LightApp_SelectionMgr.h>
46 #include <SALOME_ListIO.hxx>
48 #include <SVTK_Selection.h>
49 #include <SVTK_ViewWindow.h>
52 #include <QHBoxLayout>
53 #include <QVBoxLayout>
54 #include <QPushButton>
56 #include <QListWidget>
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Mesh)
67 * Class : SMESHGUI_DeleteGroupDlg
68 * Description : Delete groups and their contents
71 //=================================================================================
72 // function : SMESHGUI_DeleteGroupDlg()
73 // purpose : Constructor
74 //=================================================================================
75 SMESHGUI_DeleteGroupDlg::SMESHGUI_DeleteGroupDlg (SMESHGUI* theModule):
76 QDialog(SMESH::GetDesktop(theModule)),
77 mySMESHGUI(theModule),
78 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
81 setWindowTitle(tr("CAPTION"));
83 QVBoxLayout* aDlgLay = new QVBoxLayout(this);
84 aDlgLay->setMargin(MARGIN);
85 aDlgLay->setSpacing(SPACING);
87 QWidget* aMainFrame = createMainFrame (this);
88 QWidget* aBtnFrame = createButtonFrame(this);
90 aDlgLay->addWidget(aMainFrame);
91 aDlgLay->addWidget(aBtnFrame);
93 myHelpFileName = "deleting_groups.html";
98 //=================================================================================
99 // function : createMainFrame()
100 // purpose : Create frame containing dialog's input fields
101 //=================================================================================
102 QWidget* SMESHGUI_DeleteGroupDlg::createMainFrame (QWidget* theParent)
104 QGroupBox* aMainGrp =
105 new QGroupBox(tr("SELECTED_GROUPS"), theParent);
106 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
107 aLay->setMargin(MARGIN);
108 aLay->setSpacing(SPACING);
110 myListBox = new QListWidget(aMainGrp);
111 myListBox->setMinimumSize(150, 100);
112 myListBox->setSelectionMode(QListWidget::NoSelection);
113 //myListBox->setRowMode(QListBox::FitToWidth);
114 myListBox->setFlow(QListWidget::LeftToRight);
115 myListBox->setWrapping(true);
117 aLay->addWidget(myListBox);
122 //=================================================================================
123 // function : createButtonFrame()
124 // purpose : Create frame containing buttons
125 //=================================================================================
126 QWidget* SMESHGUI_DeleteGroupDlg::createButtonFrame (QWidget* theParent)
128 QGroupBox* aFrame = new QGroupBox(theParent);
130 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
131 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
132 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
133 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
135 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
136 aLay->setMargin(MARGIN);
137 aLay->setSpacing(SPACING);
139 aLay->addWidget(myOkBtn);
140 aLay->addSpacing(10);
141 aLay->addWidget(myApplyBtn);
142 aLay->addSpacing(10);
144 aLay->addWidget(myCloseBtn);
145 aLay->addWidget(myHelpBtn);
147 // connect signals and slots
148 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
149 connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
150 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
151 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
156 //=================================================================================
157 // name : ~SMESHGUI_DeleteGroupDlg()
158 // Purpose : Destructor
159 //=================================================================================
160 SMESHGUI_DeleteGroupDlg::~SMESHGUI_DeleteGroupDlg()
164 //=================================================================================
166 // purpose : Init dialog fields, connect signals and slots, show dialog
167 //=================================================================================
168 void SMESHGUI_DeleteGroupDlg::Init ()
170 myBlockSelection = false;
171 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
173 // selection and SMESHGUI
174 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
175 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
176 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
178 // set selection mode
179 mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::GROUP));
180 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
181 aViewWindow->SetSelectionMode(ActorSelection);
185 //=================================================================================
186 // function : isValid()
187 // purpose : Verify validity of input data
188 //=================================================================================
189 bool SMESHGUI_DeleteGroupDlg::isValid()
191 if (myListBox->count() == 0) {
192 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
193 tr("NO_SELECTED_GROUPS"));
197 return !SMESHGUI::isStudyLocked();
200 //=================================================================================
201 // function : onApply()
202 // purpose : SLOT called when "Apply" button pressed.
203 //=================================================================================
204 bool SMESHGUI_DeleteGroupDlg::onApply()
209 SUIT_OverrideCursor wc;
211 myBlockSelection = true;
213 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
214 for (anIter = myListGrp.begin(); anIter != myListGrp.end(); ++anIter) {
215 SMESH::SMESH_Mesh_var aMesh = (*anIter)->GetMesh();
216 if (!aMesh->_is_nil())
217 aMesh->RemoveGroupWithContents(*anIter);
222 mySelectionMgr->clearSelected();
224 /** Erase graphical objects **/
225 SALOME_ListIteratorOfListIO anIterIO (myListGrpIO);
226 for ( ; anIterIO.More(); anIterIO.Next())
227 SMESH::RemoveVisualObjectWithActors( anIterIO.Value()->getEntry(), /*fromAllViews=*/true );
230 SMESHGUI::Modified();
231 mySMESHGUI->updateObjBrowser(true);
233 myBlockSelection = false;
237 //=================================================================================
239 // purpose : SLOT called when "Ok" button pressed.
240 //=================================================================================
241 void SMESHGUI_DeleteGroupDlg::onOk()
247 //=================================================================================
248 // function : reject()
249 // purpose : SLOT called when "Close" button pressed. Close dialog
250 //=================================================================================
251 void SMESHGUI_DeleteGroupDlg::reject()
253 if (SMESH::GetCurrentVtkView()) {
254 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
256 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
257 aViewWindow->SetSelectionMode(ActorSelection);
258 disconnect(mySelectionMgr, 0, this, 0);
259 //disconnect(mySMESHGUI, 0, this, 0);
260 //mySMESHGUI->ResetState();
261 mySelectionMgr->clearFilters();
262 mySMESHGUI->ResetState();
266 //=================================================================================
267 // function : onHelp()
269 //=================================================================================
270 void SMESHGUI_DeleteGroupDlg::onHelp()
272 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
274 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
278 platform = "winapplication";
280 platform = "application";
282 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
283 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
284 arg(app->resourceMgr()->stringValue("ExternalBrowser",
286 arg(myHelpFileName));
290 //=================================================================================
291 // function : onSelectionDone()
292 // purpose : SLOT called when selection changed
293 //=================================================================================
294 void SMESHGUI_DeleteGroupDlg::onSelectionDone()
296 if (myBlockSelection)
303 SALOME_ListIO aListIO;
304 mySelectionMgr->selectedObjects(aListIO);
305 SALOME_ListIteratorOfListIO anIter (aListIO);
306 for ( ; anIter.More(); anIter.Next()) {
307 SMESH::SMESH_GroupBase_var aGroup =
308 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
309 if (!aGroup->_is_nil()) {
310 aNames.append(aGroup->GetName());
311 myListGrp.append(aGroup);
312 myListGrpIO.Append( anIter.Value() );
317 myListBox->addItems(aNames);
320 //=================================================================================
321 // function : onDeactivate()
322 // purpose : SLOT called when dialog must be deactivated
323 //=================================================================================
324 void SMESHGUI_DeleteGroupDlg::onDeactivate()
326 mySelectionMgr->clearFilters();
330 //=================================================================================
331 // function : enterEvent()
332 // purpose : Event filter
333 //=================================================================================
334 void SMESHGUI_DeleteGroupDlg::enterEvent (QEvent*)
336 mySMESHGUI->EmitSignalDeactivateDialog();
338 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
339 aViewWindow->SetSelectionMode(ActorSelection);
340 mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
343 //=================================================================================
344 // function : keyPressEvent()
346 //=================================================================================
347 void SMESHGUI_DeleteGroupDlg::keyPressEvent( QKeyEvent* e )
349 QDialog::keyPressEvent( e );
350 if ( e->isAccepted() )
353 if ( e->key() == Qt::Key_F1 ) {