1 // Copyright (C) 2007-2010 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_RemoveNodesDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
28 #include "SMESHGUI_RemoveNodesDlg.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_RemoveNodesDlg()
79 //=================================================================================
80 SMESHGUI_RemoveNodesDlg
81 ::SMESHGUI_RemoveNodesDlg(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_NODES_TITLE"));
92 setSizeGripEnabled(true);
94 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
95 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
97 QVBoxLayout* SMESHGUI_RemoveNodesDlgLayout = new QVBoxLayout(this);
98 SMESHGUI_RemoveNodesDlgLayout->setSpacing(SPACING);
99 SMESHGUI_RemoveNodesDlgLayout->setMargin(MARGIN);
101 /***************************************************************/
102 GroupConstructors = new QGroupBox(tr("SMESH_NODES"), 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_NODES"), GroupC1);
122 SelectButtonC1A1 = new QPushButton(GroupC1);
123 SelectButtonC1A1->setIcon(image1);
124 LineEditC1A1 = new QLineEdit(GroupC1);
125 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
126 QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupC1 );
127 connect(filterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
129 GroupC1Layout->addWidget(TextLabelC1A1);
130 GroupC1Layout->addWidget(SelectButtonC1A1);
131 GroupC1Layout->addWidget(LineEditC1A1);
132 GroupC1Layout->addWidget(filterBtn );
134 /***************************************************************/
135 GroupButtons = new QGroupBox(this);
136 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
137 GroupButtonsLayout->setSpacing(SPACING);
138 GroupButtonsLayout->setMargin(MARGIN);
140 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
141 buttonOk->setAutoDefault(true);
142 buttonOk->setDefault(true);
143 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
144 buttonApply->setAutoDefault(true);
145 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
146 buttonCancel->setAutoDefault(true);
147 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
148 buttonHelp->setAutoDefault(true);
150 GroupButtonsLayout->addWidget(buttonOk);
151 GroupButtonsLayout->addSpacing(10);
152 GroupButtonsLayout->addWidget(buttonApply);
153 GroupButtonsLayout->addSpacing(10);
154 GroupButtonsLayout->addStretch();
155 GroupButtonsLayout->addWidget(buttonCancel);
156 GroupButtonsLayout->addWidget(buttonHelp);
158 /***************************************************************/
159 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupConstructors);
160 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1);
161 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons);
163 myHelpFileName = "removing_nodes_and_elements_page.html#removing_nodes_anchor";
165 Init(); /* Initialisations */
168 //=================================================================================
169 // function : ~SMESHGUI_RemoveNodesDlg()
170 // purpose : Destroys the object and frees any allocated resources
171 //=================================================================================
172 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
175 myFilterDlg->setParent( 0 );
181 //=================================================================================
184 //=================================================================================
185 void SMESHGUI_RemoveNodesDlg::Init()
188 Constructor1->setChecked(true);
189 myEditCurrentArgument = LineEditC1A1;
192 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
196 /* signals and slots connections */
197 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
198 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
199 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
200 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
202 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
203 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
204 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
205 /* to close dialog if study change */
206 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
207 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
208 SLOT(onTextChange(const QString&)));
210 SMESH::SetPointRepresentation(true);
212 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
213 aViewWindow->SetSelectionMode(NodeSelection);
215 SelectionIntoArgument();
218 //=================================================================================
219 // function : ClickOnApply()
221 //=================================================================================
222 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
224 if (mySMESHGUI->isActiveStudyLocked())
228 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
229 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
230 anArrayOfIdeces->length(aListId.count());
231 for (int i = 0; i < aListId.count(); i++)
232 anArrayOfIdeces[i] = aListId[ i ].toInt();
234 bool aResult = false;
236 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
237 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout());
238 } catch (const SALOME::SALOME_Exception& S_ex) {
239 SalomeApp_Tools::QtCatchCorbaException(S_ex);
240 myEditCurrentArgument->clear();
242 myEditCurrentArgument->clear();
246 myEditCurrentArgument->clear();
247 mySelector->ClearIndex();
249 SMESHGUI::Modified();
252 SMESH::SetPointRepresentation(true);
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
266 //=================================================================================
267 // function : ClickOnCancel()
269 //=================================================================================
270 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
272 //mySelectionMgr->clearSelected();
273 if (SMESH::GetCurrentVtkView()) {
274 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
275 SMESH::SetPointRepresentation(false);
277 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
278 aViewWindow->SetSelectionMode(ActorSelection);
279 disconnect(mySelectionMgr, 0, this, 0);
280 mySelectionMgr->clearFilters();
281 mySMESHGUI->ResetState();
285 //=================================================================================
286 // function : ClickOnHelp()
288 //=================================================================================
289 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
291 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
293 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
297 platform = "winapplication";
299 platform = "application";
301 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
302 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
303 arg(app->resourceMgr()->stringValue("ExternalBrowser",
305 arg(myHelpFileName));
309 //=======================================================================
310 //function : onTextChange
312 //=======================================================================
313 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
320 buttonOk->setEnabled(false);
321 buttonApply->setEnabled(false);
323 // hilight entered nodes
325 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
326 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
328 TColStd_MapOfInteger newIndices;
330 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
331 for (int i = 0; i < aListId.count(); i++) {
332 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
333 newIndices.Add(aNode->GetID());
338 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
339 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
340 aViewWindow->highlight(anIO,true,true);
345 buttonOk->setEnabled(true);
346 buttonApply->setEnabled(true);
352 //=================================================================================
353 // function : SelectionIntoArgument()
354 // purpose : Called when selection as changed or other case
355 //=================================================================================
356 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
366 myEditCurrentArgument->setText("");
369 if (!GroupButtons->isEnabled()) // inactive
372 buttonOk->setEnabled(false);
373 buttonApply->setEnabled(false);
377 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
379 int nbSel = aList.Extent();
383 Handle(SALOME_InteractiveObject) anIO = aList.First();
384 myMesh = SMESH::GetMeshByIO(anIO);
385 if (myMesh->_is_nil())
388 myActor = SMESH::FindActorByEntry(anIO->getEntry());
392 // get selected nodes
394 QString aString = "";
395 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
399 myEditCurrentArgument->setText(aString);
406 buttonOk->setEnabled(true);
407 buttonApply->setEnabled(true);
410 //=================================================================================
411 // function : SetEditCurrentArgument()
413 //=================================================================================
414 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
416 QPushButton* send = (QPushButton*)sender();
417 switch (myConstructorId) {
418 case 0: /* default constructor */
420 if(send == SelectButtonC1A1) {
421 LineEditC1A1->setFocus();
422 myEditCurrentArgument = LineEditC1A1;
424 SelectionIntoArgument();
430 //=================================================================================
431 // function : DeactivateActiveDialog()
433 //=================================================================================
434 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
436 if (GroupConstructors->isEnabled()) {
437 GroupConstructors->setEnabled(false);
438 GroupC1->setEnabled(false);
439 GroupButtons->setEnabled(false);
440 mySMESHGUI->ResetState(); // ??
441 mySMESHGUI->SetActiveDialogBox(0); // ??
445 //=================================================================================
446 // function : ActivateThisDialog()
448 //=================================================================================
449 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
451 /* Emit a signal to deactivate the active dialog */
452 mySMESHGUI->EmitSignalDeactivateDialog();
454 GroupConstructors->setEnabled(true);
455 GroupC1->setEnabled(true);
456 GroupButtons->setEnabled(true);
458 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
460 SMESH::SetPointRepresentation(true);
461 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
462 aViewWindow->SetSelectionMode(NodeSelection);
464 SelectionIntoArgument(); // ??
467 //=================================================================================
468 // function : enterEvent()
470 //=================================================================================
471 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent*)
473 if (!GroupConstructors->isEnabled())
474 ActivateThisDialog();
477 //=================================================================================
478 // function : closeEvent()
480 //=================================================================================
481 void SMESHGUI_RemoveNodesDlg::closeEvent(QCloseEvent*)
483 /* same than click on cancel button */
487 //=======================================================================
488 //function : hideEvent
489 //purpose : caused by ESC key
490 //=======================================================================
491 void SMESHGUI_RemoveNodesDlg::hideEvent( QHideEvent* )
497 //=================================================================================
498 // function : keyPressEvent()
500 //=================================================================================
501 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
503 QDialog::keyPressEvent( e );
504 if ( e->isAccepted() )
507 if ( e->key() == Qt::Key_F1 ) {
513 //=================================================================================
514 // function : setFilters()
515 // purpose : SLOT. Called when "Filter" button pressed.
516 //=================================================================================
517 void SMESHGUI_RemoveNodesDlg::setFilters()
519 if(myMesh->_is_nil()) {
520 SUIT_MessageBox::critical(this,
522 tr("NO_MESH_SELECTED"));
526 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::NODE );
528 myFilterDlg->SetSelection();
529 myFilterDlg->SetMesh( myMesh );
530 myFilterDlg->SetSourceWg( LineEditC1A1 );