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 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_RemoveElementsDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_RemoveElementsDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_OverrideCursor.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <SalomeApp_Tools.h>
51 #include <SVTK_Selector.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
57 #include <TColStd_MapOfInteger.hxx>
63 #include <QPushButton>
64 #include <QRadioButton>
65 #include <QVBoxLayout>
66 #include <QHBoxLayout>
68 #include <QButtonGroup>
71 #include <SALOMEconfig.h>
72 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
77 //=================================================================================
78 // class : SMESHGUI_RemoveElementsDlg()
80 //=================================================================================
81 SMESHGUI_RemoveElementsDlg
82 ::SMESHGUI_RemoveElementsDlg(SMESHGUI* theModule)
83 : QDialog(SMESH::GetDesktop(theModule)),
84 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
85 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
86 mySMESHGUI(theModule),
91 setAttribute( Qt::WA_DeleteOnClose, true );
92 setWindowTitle(tr("SMESH_REMOVE_ELEMENTS_TITLE"));
93 setSizeGripEnabled(true);
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_ELEMENT")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
98 QVBoxLayout* SMESHGUI_RemoveElementsDlgLayout = new QVBoxLayout(this);
99 SMESHGUI_RemoveElementsDlgLayout->setSpacing(SPACING);
100 SMESHGUI_RemoveElementsDlgLayout->setMargin(MARGIN);
102 /***************************************************************/
103 GroupConstructors = new QGroupBox(tr("SMESH_ELEMENTS"), this);
104 QButtonGroup* ButtonGroup = new QButtonGroup(this);
105 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
106 GroupConstructorsLayout->setSpacing(SPACING);
107 GroupConstructorsLayout->setMargin(MARGIN);
109 Constructor1 = new QRadioButton(GroupConstructors);
110 Constructor1->setIcon(image0);
111 Constructor1->setChecked(true);
113 GroupConstructorsLayout->addWidget(Constructor1);
114 ButtonGroup->addButton(Constructor1, 0);
116 /***************************************************************/
117 GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
118 QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
119 GroupC1Layout->setSpacing(SPACING);
120 GroupC1Layout->setMargin(MARGIN);
122 TextLabelC1A1 = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupC1);
123 SelectButtonC1A1 = new QPushButton(GroupC1);
124 SelectButtonC1A1->setIcon(image1);
125 LineEditC1A1 = new QLineEdit(GroupC1);
126 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
127 LineEditC1A1->setMaxLength(-1);
128 QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupC1 );
129 connect(filterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
131 GroupC1Layout->addWidget(TextLabelC1A1);
132 GroupC1Layout->addWidget(SelectButtonC1A1);
133 GroupC1Layout->addWidget(LineEditC1A1);
134 GroupC1Layout->addWidget(filterBtn );
136 /***************************************************************/
137 GroupButtons = new QGroupBox(this);
138 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
139 GroupButtonsLayout->setSpacing(SPACING);
140 GroupButtonsLayout->setMargin(MARGIN);
142 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
143 buttonOk->setAutoDefault(true);
144 buttonOk->setDefault(true);
145 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
146 buttonApply->setAutoDefault(true);
147 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
148 buttonCancel->setAutoDefault(true);
149 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
150 buttonHelp->setAutoDefault(true);
152 GroupButtonsLayout->addWidget(buttonOk);
153 GroupButtonsLayout->addSpacing(10);
154 GroupButtonsLayout->addWidget(buttonApply);
155 GroupButtonsLayout->addSpacing(10);
156 GroupButtonsLayout->addStretch();
157 GroupButtonsLayout->addWidget(buttonCancel);
158 GroupButtonsLayout->addWidget(buttonHelp);
160 /***************************************************************/
161 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupConstructors);
162 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupC1);
163 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupButtons);
165 myHelpFileName = "removing_nodes_and_elements.html#removing-elements-anchor";
167 Init(); /* Initialisations */
170 //=================================================================================
171 // function : ~SMESHGUI_RemoveElementsDlg()
172 // purpose : Destroys the object and frees any allocated resources
173 //=================================================================================
174 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
177 myFilterDlg->setParent( 0 );
183 //=================================================================================
186 //=================================================================================
187 void SMESHGUI_RemoveElementsDlg::Init()
190 Constructor1->setChecked(true);
191 myEditCurrentArgument = LineEditC1A1;
194 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
198 /* signals and slots connections */
199 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
200 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
201 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
202 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
204 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
205 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
206 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
207 /* to close dialog if study change */
208 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
209 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
210 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
211 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
212 SLOT(onTextChange(const QString&)));
214 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
215 aViewWindow->SetSelectionMode(CellSelection);
217 SelectionIntoArgument();
220 //=================================================================================
221 // function : ClickOnApply()
223 //=================================================================================
224 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
226 if (SMESHGUI::isStudyLocked())
231 SUIT_OverrideCursor wc;
233 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
234 SMESH::smIdType_array_var anArrayOfIdeces = new SMESH::smIdType_array;
235 anArrayOfIdeces->length(aListId.count());
236 for (int i = 0; i < aListId.count(); i++)
237 anArrayOfIdeces[i] = aListId[ i ].toInt();
239 bool aResult = false;
242 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
243 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.in());
245 if ( myActor && myMesh->NbElements() == 0 )
246 myActor->SetRepresentation(SMESH_Actor::ePoint);
248 } catch (const SALOME::SALOME_Exception& S_ex) {
249 SalomeApp_Tools::QtCatchCorbaException(S_ex);
253 myEditCurrentArgument->clear();
255 mySelector->ClearIndex();
256 SMESH::UpdateView( /*withChildrenOfSelected=*/true );
257 SMESHGUI::Modified();
262 //=================================================================================
263 // function : ClickOnOk()
265 //=================================================================================
266 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
272 //=================================================================================
273 // function : reject()
275 //=================================================================================
276 void SMESHGUI_RemoveElementsDlg::reject()
278 if (SMESH::GetCurrentVtkView())
279 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
280 //mySelectionMgr->clearSelected();
281 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
282 aViewWindow->SetSelectionMode(ActorSelection);
283 disconnect(mySelectionMgr, 0, this, 0);
284 mySelectionMgr->clearFilters();
285 mySMESHGUI->ResetState();
289 //=================================================================================
290 // function : onOpenView()
292 //=================================================================================
293 void SMESHGUI_RemoveElementsDlg::onOpenView()
296 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
297 ActivateThisDialog();
301 //=================================================================================
302 // function : onCloseView()
304 //=================================================================================
305 void SMESHGUI_RemoveElementsDlg::onCloseView()
307 DeactivateActiveDialog();
311 //=================================================================================
312 // function : ClickOnHelp()
314 //=================================================================================
315 void SMESHGUI_RemoveElementsDlg::ClickOnHelp()
317 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
319 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
323 platform = "winapplication";
325 platform = "application";
327 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
328 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
329 arg(app->resourceMgr()->stringValue("ExternalBrowser",
331 arg(myHelpFileName));
335 //=======================================================================
336 //function : onTextChange
338 //=======================================================================
339 void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
346 // highlight entered elements
348 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
349 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
351 SVTK_TVtkIDsMap newIndices;
353 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
354 for (int i = 0; i < aListId.count(); i++) {
355 if(const SMDS_MeshElement *anElem = aMesh->FindElement(aListId[i].toInt())) {
356 newIndices.Add(anElem->GetID());
361 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
362 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
363 aViewWindow->highlight(anIO,true,true);
368 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
369 myNbOkElements = aListId.count();
376 //=================================================================================
377 // function : SelectionIntoArgument()
378 // purpose : Called when selection as changed or other case
379 //=================================================================================
380 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
382 if (myBusy) return; // busy
383 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
384 if (!GroupButtons->isEnabled()) return; // inactive
392 myEditCurrentArgument->setText("");
398 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
400 int nbSel = aList.Extent();
403 Handle(SALOME_InteractiveObject) anIO = aList.First();
404 myMesh = SMESH::GetMeshByIO(anIO);
406 if (!myMesh->_is_nil()) {
408 myActor = SMESH::FindActorByEntry(anIO->getEntry());
411 // get selected elements
412 QString aString = "";
413 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aString);
416 myEditCurrentArgument->setText(aString);
421 myNbOkElements = nbElems;
422 } // if (nbElems > 0)
424 } // if (!myMesh->_is_nil())
425 } // if (nbSel == 1) {
430 //=================================================================================
431 // function : SetEditCurrentArgument()
433 //=================================================================================
434 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
436 QPushButton* send = (QPushButton*)sender();
437 switch (myConstructorId) {
438 case 0: /* default constructor */
440 if(send == SelectButtonC1A1) {
441 LineEditC1A1->setFocus();
442 myEditCurrentArgument = LineEditC1A1;
444 SelectionIntoArgument();
450 //=================================================================================
451 // function : DeactivateActiveDialog()
453 //=================================================================================
454 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
456 if (GroupConstructors->isEnabled()) {
457 GroupConstructors->setEnabled(false);
458 GroupC1->setEnabled(false);
459 GroupButtons->setEnabled(false);
460 mySMESHGUI->ResetState(); // ??
461 mySMESHGUI->SetActiveDialogBox(0); // ??
465 //=================================================================================
466 // function : ActivateThisDialog()
468 //=================================================================================
469 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
471 /* Emit a signal to deactivate the active dialog */
472 mySMESHGUI->EmitSignalDeactivateDialog();
474 GroupConstructors->setEnabled(true);
475 GroupC1->setEnabled(true);
476 GroupButtons->setEnabled(true);
478 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
480 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
481 aViewWindow->SetSelectionMode(CellSelection);
483 SelectionIntoArgument(); // ??
486 //=================================================================================
487 // function : enterEvent()
489 //=================================================================================
490 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent*)
492 if (!GroupConstructors->isEnabled()) {
493 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
494 if ( aViewWindow && !mySelector) {
495 mySelector = aViewWindow->GetSelector();
497 ActivateThisDialog();
501 //=================================================================================
502 // function : keyPressEvent()
504 //=================================================================================
505 void SMESHGUI_RemoveElementsDlg::keyPressEvent( QKeyEvent* e )
507 QDialog::keyPressEvent( e );
508 if ( e->isAccepted() )
511 if ( e->key() == Qt::Key_F1 ) {
517 //=================================================================================
518 // function : setFilters()
519 // purpose : SLOT. Called when "Filter" button pressed.
520 //=================================================================================
521 void SMESHGUI_RemoveElementsDlg::setFilters()
523 if(myMesh->_is_nil()) {
524 SUIT_MessageBox::critical(this,
526 tr("NO_MESH_SELECTED"));
530 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
533 if ( myMesh->NbEdges() ) types << SMESH::EDGE;
534 if ( myMesh->NbFaces() ) types << SMESH::FACE;
535 if ( myMesh->NbVolumes() ) types << SMESH::VOLUME;
536 if ( myMesh->NbBalls() ) types << SMESH::BALL;
537 if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D;
538 if ( types.count() > 1 ) types << SMESH::ALL;
540 myFilterDlg->Init( types );
541 myFilterDlg->SetSelection();
542 myFilterDlg->SetMesh( myMesh );
543 myFilterDlg->SetSourceWg( LineEditC1A1 );
548 //=================================================================================
549 // function : updateButtons
550 // purpose : enable / disable control buttons
551 //=================================================================================
552 void SMESHGUI_RemoveElementsDlg::updateButtons()
554 buttonOk->setEnabled(myNbOkElements > 0);
555 buttonApply->setEnabled(myNbOkElements > 0);