1 // Copyright (C) 2007-2008 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.
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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_RemoveElementsDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_RemoveElementsDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
34 #include "SMESHGUI_FilterDlg.h"
36 #include <SMESH_Actor.h>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SalomeApp_Tools.h>
49 #include <SVTK_Selector.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
55 #include <TColStd_MapOfInteger.hxx>
61 #include <QPushButton>
62 #include <QRadioButton>
63 #include <QVBoxLayout>
64 #include <QHBoxLayout>
66 #include <QButtonGroup>
69 #include <SALOMEconfig.h>
70 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
75 //=================================================================================
76 // class : SMESHGUI_RemoveElementsDlg()
78 //=================================================================================
79 SMESHGUI_RemoveElementsDlg
80 ::SMESHGUI_RemoveElementsDlg(SMESHGUI* theModule)
81 : QDialog(SMESH::GetDesktop(theModule)),
82 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
83 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
84 mySMESHGUI(theModule),
89 setAttribute( Qt::WA_DeleteOnClose, true );
90 setWindowTitle(tr("SMESH_REMOVE_ELEMENTS_TITLE"));
91 setSizeGripEnabled(true);
93 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_ELEMENT")));
94 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
96 QVBoxLayout* SMESHGUI_RemoveElementsDlgLayout = new QVBoxLayout(this);
97 SMESHGUI_RemoveElementsDlgLayout->setSpacing(SPACING);
98 SMESHGUI_RemoveElementsDlgLayout->setMargin(MARGIN);
100 /***************************************************************/
101 GroupConstructors = new QGroupBox(tr("SMESH_ELEMENTS"), this);
102 QButtonGroup* ButtonGroup = new QButtonGroup(this);
103 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
104 GroupConstructorsLayout->setSpacing(SPACING);
105 GroupConstructorsLayout->setMargin(MARGIN);
107 Constructor1 = new QRadioButton(GroupConstructors);
108 Constructor1->setIcon(image0);
109 Constructor1->setChecked(true);
111 GroupConstructorsLayout->addWidget(Constructor1);
112 ButtonGroup->addButton(Constructor1, 0);
114 /***************************************************************/
115 GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
116 QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
117 GroupC1Layout->setSpacing(SPACING);
118 GroupC1Layout->setMargin(MARGIN);
120 TextLabelC1A1 = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupC1);
121 SelectButtonC1A1 = new QPushButton(GroupC1);
122 SelectButtonC1A1->setIcon(image1);
123 LineEditC1A1 = new QLineEdit(GroupC1);
124 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
125 QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupC1 );
126 connect(filterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
128 GroupC1Layout->addWidget(TextLabelC1A1);
129 GroupC1Layout->addWidget(SelectButtonC1A1);
130 GroupC1Layout->addWidget(LineEditC1A1);
131 GroupC1Layout->addWidget(filterBtn );
133 /***************************************************************/
134 GroupButtons = new QGroupBox(this);
135 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
136 GroupButtonsLayout->setSpacing(SPACING);
137 GroupButtonsLayout->setMargin(MARGIN);
139 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
140 buttonOk->setAutoDefault(true);
141 buttonOk->setDefault(true);
142 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
143 buttonApply->setAutoDefault(true);
144 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
145 buttonCancel->setAutoDefault(true);
146 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
147 buttonHelp->setAutoDefault(true);
149 GroupButtonsLayout->addWidget(buttonOk);
150 GroupButtonsLayout->addSpacing(10);
151 GroupButtonsLayout->addWidget(buttonApply);
152 GroupButtonsLayout->addSpacing(10);
153 GroupButtonsLayout->addStretch();
154 GroupButtonsLayout->addWidget(buttonCancel);
155 GroupButtonsLayout->addWidget(buttonHelp);
157 /***************************************************************/
158 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupConstructors);
159 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupC1);
160 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupButtons);
162 myHelpFileName = "removing_nodes_and_elements_page.html#removing_elements_anchor";
164 Init(); /* Initialisations */
167 //=================================================================================
168 // function : ~SMESHGUI_RemoveElementsDlg()
169 // purpose : Destroys the object and frees any allocated resources
170 //=================================================================================
171 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
174 myFilterDlg->setParent( 0 );
180 //=================================================================================
183 //=================================================================================
184 void SMESHGUI_RemoveElementsDlg::Init()
187 Constructor1->setChecked(true);
188 myEditCurrentArgument = LineEditC1A1;
191 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
195 /* signals and slots connections */
196 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
197 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
198 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
199 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
201 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
202 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
203 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
204 /* to close dialog if study change */
205 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
206 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
207 SLOT(onTextChange(const QString&)));
209 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
210 aViewWindow->SetSelectionMode(CellSelection);
212 SelectionIntoArgument();
215 //=================================================================================
216 // function : ClickOnApply()
218 //=================================================================================
219 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
221 if (mySMESHGUI->isActiveStudyLocked())
224 if (myNbOkElements) {
225 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
226 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
227 anArrayOfIdeces->length(aListId.count());
228 for (int i = 0; i < aListId.count(); i++)
229 anArrayOfIdeces[i] = aListId[ i ].toInt();
231 bool aResult = false;
233 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
234 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.inout());
235 } catch (const SALOME::SALOME_Exception& S_ex) {
236 SalomeApp_Tools::QtCatchCorbaException(S_ex);
237 myEditCurrentArgument->clear();
239 myEditCurrentArgument->clear();
243 myEditCurrentArgument->clear();
244 mySelector->ClearIndex();
250 //=================================================================================
251 // function : ClickOnOk()
253 //=================================================================================
254 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
260 //=================================================================================
261 // function : ClickOnCancel()
263 //=================================================================================
264 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
266 if (SMESH::GetCurrentVtkView())
267 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
268 //mySelectionMgr->clearSelected();
269 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
270 aViewWindow->SetSelectionMode(ActorSelection);
271 disconnect(mySelectionMgr, 0, this, 0);
272 mySelectionMgr->clearFilters();
273 mySMESHGUI->ResetState();
277 //=================================================================================
278 // function : ClickOnHelp()
280 //=================================================================================
281 void SMESHGUI_RemoveElementsDlg::ClickOnHelp()
283 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
285 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
289 platform = "winapplication";
291 platform = "application";
293 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
294 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
295 arg(app->resourceMgr()->stringValue("ExternalBrowser",
297 arg(myHelpFileName));
301 //=======================================================================
302 //function : onTextChange
304 //=======================================================================
305 void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
312 buttonOk->setEnabled(false);
313 buttonApply->setEnabled(false);
315 // hilight entered elements
317 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
318 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
320 TColStd_MapOfInteger newIndices;
322 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
323 for (int i = 0; i < aListId.count(); i++) {
324 if(const SMDS_MeshElement *anElem = aMesh->FindElement(aListId[i].toInt())) {
325 newIndices.Add(anElem->GetID());
330 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
331 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
332 aViewWindow->highlight(anIO,true,true);
336 if (myNbOkElements) {
337 buttonOk->setEnabled(true);
338 buttonApply->setEnabled(true);
344 //=================================================================================
345 // function : SelectionIntoArgument()
346 // purpose : Called when selection as changed or other case
347 //=================================================================================
348 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
354 myNbOkElements = false;
358 myEditCurrentArgument->setText("");
361 if (!GroupButtons->isEnabled()) // inactive
364 buttonOk->setEnabled(false);
365 buttonApply->setEnabled(false);
370 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
372 int nbSel = aList.Extent();
376 Handle(SALOME_InteractiveObject) anIO = aList.First();
377 myMesh = SMESH::GetMeshByIO(anIO);
378 if (myMesh->_is_nil())
381 myActor = SMESH::FindActorByEntry(anIO->getEntry());
385 // get selected nodes
386 QString aString = "";
387 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aString);
391 myEditCurrentArgument->setText(aString);
396 myNbOkElements = nbElems;
398 buttonOk->setEnabled(true);
399 buttonApply->setEnabled(true);
402 //=================================================================================
403 // function : SetEditCurrentArgument()
405 //=================================================================================
406 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
408 QPushButton* send = (QPushButton*)sender();
409 switch (myConstructorId) {
410 case 0: /* default constructor */
412 if(send == SelectButtonC1A1) {
413 LineEditC1A1->setFocus();
414 myEditCurrentArgument = LineEditC1A1;
416 SelectionIntoArgument();
422 //=================================================================================
423 // function : DeactivateActiveDialog()
425 //=================================================================================
426 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
428 if (GroupConstructors->isEnabled()) {
429 GroupConstructors->setEnabled(false);
430 GroupC1->setEnabled(false);
431 GroupButtons->setEnabled(false);
432 mySMESHGUI->ResetState(); // ??
433 mySMESHGUI->SetActiveDialogBox(0); // ??
437 //=================================================================================
438 // function : ActivateThisDialog()
440 //=================================================================================
441 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
443 /* Emit a signal to deactivate the active dialog */
444 mySMESHGUI->EmitSignalDeactivateDialog();
446 GroupConstructors->setEnabled(true);
447 GroupC1->setEnabled(true);
448 GroupButtons->setEnabled(true);
450 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
452 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
453 aViewWindow->SetSelectionMode(CellSelection);
455 SelectionIntoArgument(); // ??
458 //=================================================================================
459 // function : enterEvent()
461 //=================================================================================
462 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent*)
464 if (!GroupConstructors->isEnabled())
465 ActivateThisDialog();
468 //=================================================================================
469 // function : closeEvent()
471 //=================================================================================
472 void SMESHGUI_RemoveElementsDlg::closeEvent(QCloseEvent*)
474 /* same than click on cancel button */
478 //=======================================================================
479 //function : hideEvent
480 //purpose : caused by ESC key
481 //=======================================================================
482 void SMESHGUI_RemoveElementsDlg::hideEvent( QHideEvent* )
488 //=================================================================================
489 // function : keyPressEvent()
491 //=================================================================================
492 void SMESHGUI_RemoveElementsDlg::keyPressEvent( QKeyEvent* e )
494 QDialog::keyPressEvent( e );
495 if ( e->isAccepted() )
498 if ( e->key() == Qt::Key_F1 ) {
504 //=================================================================================
505 // function : setFilters()
506 // purpose : SLOT. Called when "Filter" button pressed.
507 //=================================================================================
508 void SMESHGUI_RemoveElementsDlg::setFilters()
510 if(myMesh->_is_nil()) {
511 SUIT_MessageBox::critical(this,
513 tr("NO_MESH_SELECTED"));
517 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
519 myFilterDlg->SetSelection();
520 myFilterDlg->SetMesh( myMesh );
521 myFilterDlg->SetSourceWg( LineEditC1A1 );