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_RemoveNodesDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_RemoveNodesDlg.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_RemoveNodesDlg()
78 //=================================================================================
79 SMESHGUI_RemoveNodesDlg
80 ::SMESHGUI_RemoveNodesDlg(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_NODES_TITLE"));
91 setSizeGripEnabled(true);
93 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
94 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
96 QVBoxLayout* SMESHGUI_RemoveNodesDlgLayout = new QVBoxLayout(this);
97 SMESHGUI_RemoveNodesDlgLayout->setSpacing(SPACING);
98 SMESHGUI_RemoveNodesDlgLayout->setMargin(MARGIN);
100 /***************************************************************/
101 GroupConstructors = new QGroupBox(tr("SMESH_NODES"), 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_NODES"), 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_RemoveNodesDlgLayout->addWidget(GroupConstructors);
159 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1);
160 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons);
162 myHelpFileName = "removing_nodes_and_elements_page.html#removing_nodes_anchor";
164 Init(); /* Initialisations */
167 //=================================================================================
168 // function : ~SMESHGUI_RemoveNodesDlg()
169 // purpose : Destroys the object and frees any allocated resources
170 //=================================================================================
171 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
174 myFilterDlg->setParent( 0 );
180 //=================================================================================
183 //=================================================================================
184 void SMESHGUI_RemoveNodesDlg::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 SMESH::SetPointRepresentation(true);
211 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
212 aViewWindow->SetSelectionMode(NodeSelection);
214 SelectionIntoArgument();
217 //=================================================================================
218 // function : ClickOnApply()
220 //=================================================================================
221 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
223 if (mySMESHGUI->isActiveStudyLocked())
227 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
228 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
229 anArrayOfIdeces->length(aListId.count());
230 for (int i = 0; i < aListId.count(); i++)
231 anArrayOfIdeces[i] = aListId[ i ].toInt();
233 bool aResult = false;
235 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
236 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout());
237 } catch (const SALOME::SALOME_Exception& S_ex) {
238 SalomeApp_Tools::QtCatchCorbaException(S_ex);
239 myEditCurrentArgument->clear();
241 myEditCurrentArgument->clear();
245 myEditCurrentArgument->clear();
246 mySelector->ClearIndex();
250 SMESH::SetPointRepresentation(true);
254 //=================================================================================
255 // function : ClickOnOk()
257 //=================================================================================
258 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
264 //=================================================================================
265 // function : ClickOnCancel()
267 //=================================================================================
268 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
270 //mySelectionMgr->clearSelected();
271 if (SMESH::GetCurrentVtkView()) {
272 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
273 SMESH::SetPointRepresentation(false);
275 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
276 aViewWindow->SetSelectionMode(ActorSelection);
277 disconnect(mySelectionMgr, 0, this, 0);
278 mySelectionMgr->clearFilters();
279 mySMESHGUI->ResetState();
283 //=================================================================================
284 // function : ClickOnHelp()
286 //=================================================================================
287 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
289 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
291 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
295 platform = "winapplication";
297 platform = "application";
299 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
300 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
301 arg(app->resourceMgr()->stringValue("ExternalBrowser",
303 arg(myHelpFileName));
307 //=======================================================================
308 //function : onTextChange
310 //=======================================================================
311 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
318 buttonOk->setEnabled(false);
319 buttonApply->setEnabled(false);
321 // hilight entered nodes
323 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
324 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
326 TColStd_MapOfInteger newIndices;
328 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
329 for (int i = 0; i < aListId.count(); i++) {
330 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
331 newIndices.Add(aNode->GetID());
336 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
337 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
338 aViewWindow->highlight(anIO,true,true);
343 buttonOk->setEnabled(true);
344 buttonApply->setEnabled(true);
350 //=================================================================================
351 // function : SelectionIntoArgument()
352 // purpose : Called when selection as changed or other case
353 //=================================================================================
354 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
364 myEditCurrentArgument->setText("");
367 if (!GroupButtons->isEnabled()) // inactive
370 buttonOk->setEnabled(false);
371 buttonApply->setEnabled(false);
375 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
377 int nbSel = aList.Extent();
381 Handle(SALOME_InteractiveObject) anIO = aList.First();
382 myMesh = SMESH::GetMeshByIO(anIO);
383 if (myMesh->_is_nil())
386 myActor = SMESH::FindActorByEntry(anIO->getEntry());
390 // get selected nodes
392 QString aString = "";
393 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
397 myEditCurrentArgument->setText(aString);
404 buttonOk->setEnabled(true);
405 buttonApply->setEnabled(true);
408 //=================================================================================
409 // function : SetEditCurrentArgument()
411 //=================================================================================
412 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
414 QPushButton* send = (QPushButton*)sender();
415 switch (myConstructorId) {
416 case 0: /* default constructor */
418 if(send == SelectButtonC1A1) {
419 LineEditC1A1->setFocus();
420 myEditCurrentArgument = LineEditC1A1;
422 SelectionIntoArgument();
428 //=================================================================================
429 // function : DeactivateActiveDialog()
431 //=================================================================================
432 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
434 if (GroupConstructors->isEnabled()) {
435 GroupConstructors->setEnabled(false);
436 GroupC1->setEnabled(false);
437 GroupButtons->setEnabled(false);
438 mySMESHGUI->ResetState(); // ??
439 mySMESHGUI->SetActiveDialogBox(0); // ??
443 //=================================================================================
444 // function : ActivateThisDialog()
446 //=================================================================================
447 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
449 /* Emit a signal to deactivate the active dialog */
450 mySMESHGUI->EmitSignalDeactivateDialog();
452 GroupConstructors->setEnabled(true);
453 GroupC1->setEnabled(true);
454 GroupButtons->setEnabled(true);
456 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
458 SMESH::SetPointRepresentation(true);
459 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
460 aViewWindow->SetSelectionMode(NodeSelection);
462 SelectionIntoArgument(); // ??
465 //=================================================================================
466 // function : enterEvent()
468 //=================================================================================
469 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent*)
471 if (!GroupConstructors->isEnabled())
472 ActivateThisDialog();
475 //=================================================================================
476 // function : closeEvent()
478 //=================================================================================
479 void SMESHGUI_RemoveNodesDlg::closeEvent(QCloseEvent*)
481 /* same than click on cancel button */
485 //=======================================================================
486 //function : hideEvent
487 //purpose : caused by ESC key
488 //=======================================================================
489 void SMESHGUI_RemoveNodesDlg::hideEvent( QHideEvent* )
495 //=================================================================================
496 // function : keyPressEvent()
498 //=================================================================================
499 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
501 QDialog::keyPressEvent( e );
502 if ( e->isAccepted() )
505 if ( e->key() == Qt::Key_F1 ) {
511 //=================================================================================
512 // function : setFilters()
513 // purpose : SLOT. Called when "Filter" button pressed.
514 //=================================================================================
515 void SMESHGUI_RemoveNodesDlg::setFilters()
517 if(myMesh->_is_nil()) {
518 SUIT_MessageBox::critical(this,
520 tr("NO_MESH_SELECTED"));
524 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::NODE );
526 myFilterDlg->SetSelection();
527 myFilterDlg->SetMesh( myMesh );
528 myFilterDlg->SetSourceWg( LineEditC1A1 );