1 // Copyright (C) 2007-2015 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>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <SalomeApp_Tools.h>
50 #include <SVTK_Selector.h>
51 #include <SVTK_ViewModel.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
56 #include <TColStd_MapOfInteger.hxx>
62 #include <QPushButton>
63 #include <QRadioButton>
64 #include <QVBoxLayout>
65 #include <QHBoxLayout>
67 #include <QButtonGroup>
70 #include <SALOMEconfig.h>
71 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
76 //=================================================================================
77 // class : SMESHGUI_RemoveElementsDlg()
79 //=================================================================================
80 SMESHGUI_RemoveElementsDlg
81 ::SMESHGUI_RemoveElementsDlg(SMESHGUI* theModule)
82 : QDialog(SMESH::GetDesktop(theModule)),
83 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
84 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
85 mySMESHGUI(theModule),
90 setAttribute( Qt::WA_DeleteOnClose, true );
91 setWindowTitle(tr("SMESH_REMOVE_ELEMENTS_TITLE"));
92 setSizeGripEnabled(true);
94 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_ELEMENT")));
95 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
97 QVBoxLayout* SMESHGUI_RemoveElementsDlgLayout = new QVBoxLayout(this);
98 SMESHGUI_RemoveElementsDlgLayout->setSpacing(SPACING);
99 SMESHGUI_RemoveElementsDlgLayout->setMargin(MARGIN);
101 /***************************************************************/
102 GroupConstructors = new QGroupBox(tr("SMESH_ELEMENTS"), this);
103 QButtonGroup* ButtonGroup = new QButtonGroup(this);
104 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
105 GroupConstructorsLayout->setSpacing(SPACING);
106 GroupConstructorsLayout->setMargin(MARGIN);
108 Constructor1 = new QRadioButton(GroupConstructors);
109 Constructor1->setIcon(image0);
110 Constructor1->setChecked(true);
112 GroupConstructorsLayout->addWidget(Constructor1);
113 ButtonGroup->addButton(Constructor1, 0);
115 /***************************************************************/
116 GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
117 QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
118 GroupC1Layout->setSpacing(SPACING);
119 GroupC1Layout->setMargin(MARGIN);
121 TextLabelC1A1 = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupC1);
122 SelectButtonC1A1 = new QPushButton(GroupC1);
123 SelectButtonC1A1->setIcon(image1);
124 LineEditC1A1 = new QLineEdit(GroupC1);
125 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
126 LineEditC1A1->setMaxLength(-1);
127 QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupC1 );
128 connect(filterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
130 GroupC1Layout->addWidget(TextLabelC1A1);
131 GroupC1Layout->addWidget(SelectButtonC1A1);
132 GroupC1Layout->addWidget(LineEditC1A1);
133 GroupC1Layout->addWidget(filterBtn );
135 /***************************************************************/
136 GroupButtons = new QGroupBox(this);
137 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
138 GroupButtonsLayout->setSpacing(SPACING);
139 GroupButtonsLayout->setMargin(MARGIN);
141 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
142 buttonOk->setAutoDefault(true);
143 buttonOk->setDefault(true);
144 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
145 buttonApply->setAutoDefault(true);
146 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
147 buttonCancel->setAutoDefault(true);
148 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
149 buttonHelp->setAutoDefault(true);
151 GroupButtonsLayout->addWidget(buttonOk);
152 GroupButtonsLayout->addSpacing(10);
153 GroupButtonsLayout->addWidget(buttonApply);
154 GroupButtonsLayout->addSpacing(10);
155 GroupButtonsLayout->addStretch();
156 GroupButtonsLayout->addWidget(buttonCancel);
157 GroupButtonsLayout->addWidget(buttonHelp);
159 /***************************************************************/
160 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupConstructors);
161 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupC1);
162 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupButtons);
164 myHelpFileName = "removing_nodes_and_elements_page.html#removing_elements_anchor";
166 Init(); /* Initialisations */
169 //=================================================================================
170 // function : ~SMESHGUI_RemoveElementsDlg()
171 // purpose : Destroys the object and frees any allocated resources
172 //=================================================================================
173 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
176 myFilterDlg->setParent( 0 );
182 //=================================================================================
185 //=================================================================================
186 void SMESHGUI_RemoveElementsDlg::Init()
189 Constructor1->setChecked(true);
190 myEditCurrentArgument = LineEditC1A1;
193 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
197 /* signals and slots connections */
198 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
199 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
200 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
201 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
203 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
204 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
205 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
206 /* to close dialog if study change */
207 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
208 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
209 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
210 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
211 SLOT(onTextChange(const QString&)));
213 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
214 aViewWindow->SetSelectionMode(CellSelection);
216 SelectionIntoArgument();
219 //=================================================================================
220 // function : ClickOnApply()
222 //=================================================================================
223 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
225 if (mySMESHGUI->isActiveStudyLocked())
228 if (myNbOkElements) {
229 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
230 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
231 anArrayOfIdeces->length(aListId.count());
232 for (int i = 0; i < aListId.count(); i++)
233 anArrayOfIdeces[i] = aListId[ i ].toInt();
235 bool aResult = false;
237 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
238 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.in());
240 if ( myActor && myMesh->NbElements() == 0 )
241 myActor->SetRepresentation(SMESH_Actor::ePoint);
243 } catch (const SALOME::SALOME_Exception& S_ex) {
244 SalomeApp_Tools::QtCatchCorbaException(S_ex);
245 myEditCurrentArgument->clear();
247 myEditCurrentArgument->clear();
251 myEditCurrentArgument->clear();
252 mySelector->ClearIndex();
254 SMESHGUI::Modified();
259 //=================================================================================
260 // function : ClickOnOk()
262 //=================================================================================
263 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
269 //=================================================================================
270 // function : reject()
272 //=================================================================================
273 void SMESHGUI_RemoveElementsDlg::reject()
275 if (SMESH::GetCurrentVtkView())
276 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
277 //mySelectionMgr->clearSelected();
278 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
279 aViewWindow->SetSelectionMode(ActorSelection);
280 disconnect(mySelectionMgr, 0, this, 0);
281 mySelectionMgr->clearFilters();
282 mySMESHGUI->ResetState();
286 //=================================================================================
287 // function : onOpenView()
289 //=================================================================================
290 void SMESHGUI_RemoveElementsDlg::onOpenView()
293 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
294 ActivateThisDialog();
298 //=================================================================================
299 // function : onCloseView()
301 //=================================================================================
302 void SMESHGUI_RemoveElementsDlg::onCloseView()
304 DeactivateActiveDialog();
308 //=================================================================================
309 // function : ClickOnHelp()
311 //=================================================================================
312 void SMESHGUI_RemoveElementsDlg::ClickOnHelp()
314 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
316 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
320 platform = "winapplication";
322 platform = "application";
324 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
325 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
326 arg(app->resourceMgr()->stringValue("ExternalBrowser",
328 arg(myHelpFileName));
332 //=======================================================================
333 //function : onTextChange
335 //=======================================================================
336 void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
343 // hilight entered elements
345 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
346 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
348 TColStd_MapOfInteger newIndices;
350 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
351 for (int i = 0; i < aListId.count(); i++) {
352 if(const SMDS_MeshElement *anElem = aMesh->FindElement(aListId[i].toInt())) {
353 newIndices.Add(anElem->GetID());
358 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
359 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
360 aViewWindow->highlight(anIO,true,true);
365 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
366 myNbOkElements = aListId.count();
373 //=================================================================================
374 // function : SelectionIntoArgument()
375 // purpose : Called when selection as changed or other case
376 //=================================================================================
377 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
379 if (myBusy) return; // busy
380 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter digl active
381 if (!GroupButtons->isEnabled()) return; // inactive
389 myEditCurrentArgument->setText("");
395 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
397 int nbSel = aList.Extent();
400 Handle(SALOME_InteractiveObject) anIO = aList.First();
401 myMesh = SMESH::GetMeshByIO(anIO);
403 if (!myMesh->_is_nil()) {
405 myActor = SMESH::FindActorByEntry(anIO->getEntry());
408 // get selected elements
409 QString aString = "";
410 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aString);
413 myEditCurrentArgument->setText(aString);
418 myNbOkElements = nbElems;
419 } // if (nbElems > 0)
421 } // if (!myMesh->_is_nil())
422 } // if (nbSel == 1) {
427 //=================================================================================
428 // function : SetEditCurrentArgument()
430 //=================================================================================
431 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
433 QPushButton* send = (QPushButton*)sender();
434 switch (myConstructorId) {
435 case 0: /* default constructor */
437 if(send == SelectButtonC1A1) {
438 LineEditC1A1->setFocus();
439 myEditCurrentArgument = LineEditC1A1;
441 SelectionIntoArgument();
447 //=================================================================================
448 // function : DeactivateActiveDialog()
450 //=================================================================================
451 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
453 if (GroupConstructors->isEnabled()) {
454 GroupConstructors->setEnabled(false);
455 GroupC1->setEnabled(false);
456 GroupButtons->setEnabled(false);
457 mySMESHGUI->ResetState(); // ??
458 mySMESHGUI->SetActiveDialogBox(0); // ??
462 //=================================================================================
463 // function : ActivateThisDialog()
465 //=================================================================================
466 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
468 /* Emit a signal to deactivate the active dialog */
469 mySMESHGUI->EmitSignalDeactivateDialog();
471 GroupConstructors->setEnabled(true);
472 GroupC1->setEnabled(true);
473 GroupButtons->setEnabled(true);
475 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
477 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
478 aViewWindow->SetSelectionMode(CellSelection);
480 SelectionIntoArgument(); // ??
483 //=================================================================================
484 // function : enterEvent()
486 //=================================================================================
487 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent*)
489 if (!GroupConstructors->isEnabled()) {
490 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
491 if ( aViewWindow && !mySelector) {
492 mySelector = aViewWindow->GetSelector();
494 ActivateThisDialog();
498 //=================================================================================
499 // function : keyPressEvent()
501 //=================================================================================
502 void SMESHGUI_RemoveElementsDlg::keyPressEvent( QKeyEvent* e )
504 QDialog::keyPressEvent( e );
505 if ( e->isAccepted() )
508 if ( e->key() == Qt::Key_F1 ) {
514 //=================================================================================
515 // function : setFilters()
516 // purpose : SLOT. Called when "Filter" button pressed.
517 //=================================================================================
518 void SMESHGUI_RemoveElementsDlg::setFilters()
520 if(myMesh->_is_nil()) {
521 SUIT_MessageBox::critical(this,
523 tr("NO_MESH_SELECTED"));
527 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
530 if ( myMesh->NbEdges() ) types << SMESH::EDGE;
531 if ( myMesh->NbFaces() ) types << SMESH::FACE;
532 if ( myMesh->NbVolumes() ) types << SMESH::VOLUME;
533 if ( myMesh->NbBalls() ) types << SMESH::BALL;
534 if ( myMesh->Nb0DElements()) types << SMESH::ELEM0D;
535 if ( types.count() > 1 ) types << SMESH::ALL;
537 myFilterDlg->Init( types );
538 myFilterDlg->SetSelection();
539 myFilterDlg->SetMesh( myMesh );
540 myFilterDlg->SetSourceWg( LineEditC1A1 );
545 //=================================================================================
546 // function : updateButtons
547 // purpose : enable / disable control buttons
548 //=================================================================================
549 void SMESHGUI_RemoveElementsDlg::updateButtons()
551 buttonOk->setEnabled(myNbOkElements > 0);
552 buttonApply->setEnabled(myNbOkElements > 0);