1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_RemoveNodesDlg.cxx
23 // 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"
35 #include <SMESH_Actor.h>
36 #include <SMDS_Mesh.hxx>
38 // SALOME GUI includes
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_Session.h>
42 #include <SUIT_MessageBox.h>
44 #include <LightApp_Application.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <SalomeApp_Tools.h>
48 #include <SVTK_Selector.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
54 #include <TColStd_MapOfInteger.hxx>
60 #include <QPushButton>
61 #include <QRadioButton>
62 #include <QVBoxLayout>
63 #include <QHBoxLayout>
67 #include <SALOMEconfig.h>
68 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
73 //=================================================================================
74 // class : SMESHGUI_RemoveNodesDlg()
76 //=================================================================================
77 SMESHGUI_RemoveNodesDlg
78 ::SMESHGUI_RemoveNodesDlg(SMESHGUI* theModule)
79 : QDialog(SMESH::GetDesktop(theModule)),
80 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
81 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
82 mySMESHGUI(theModule),
86 setAttribute( Qt::WA_DeleteOnClose, true );
87 setWindowTitle(tr("SMESH_REMOVE_NODES_TITLE"));
88 setSizeGripEnabled(true);
90 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
91 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
93 QVBoxLayout* SMESHGUI_RemoveNodesDlgLayout = new QVBoxLayout(this);
94 SMESHGUI_RemoveNodesDlgLayout->setSpacing(SPACING);
95 SMESHGUI_RemoveNodesDlgLayout->setMargin(MARGIN);
97 /***************************************************************/
98 GroupConstructors = new QGroupBox(tr("SMESH_NODES"), this);
99 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
100 GroupConstructorsLayout->setSpacing(SPACING);
101 GroupConstructorsLayout->setMargin(MARGIN);
103 Constructor1 = new QRadioButton(GroupConstructors);
104 Constructor1->setIcon(image0);
105 Constructor1->setChecked(true);
107 GroupConstructorsLayout->addWidget(Constructor1);
108 GroupConstructorsLayout->addStretch();
110 /***************************************************************/
111 GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
112 QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
113 GroupC1Layout->setSpacing(SPACING);
114 GroupC1Layout->setMargin(MARGIN);
116 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
117 SelectButtonC1A1 = new QPushButton(GroupC1);
118 SelectButtonC1A1->setIcon(image1);
119 LineEditC1A1 = new QLineEdit(GroupC1);
120 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
122 GroupC1Layout->addWidget(TextLabelC1A1);
123 GroupC1Layout->addWidget(SelectButtonC1A1);
124 GroupC1Layout->addWidget(LineEditC1A1);
126 /***************************************************************/
127 GroupButtons = new QGroupBox(this);
128 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
129 GroupButtonsLayout->setSpacing(SPACING);
130 GroupButtonsLayout->setMargin(MARGIN);
132 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
133 buttonOk->setAutoDefault(true);
134 buttonOk->setDefault(true);
135 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
136 buttonApply->setAutoDefault(true);
137 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
138 buttonCancel->setAutoDefault(true);
139 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
140 buttonHelp->setAutoDefault(true);
142 GroupButtonsLayout->addWidget(buttonOk);
143 GroupButtonsLayout->addSpacing(10);
144 GroupButtonsLayout->addWidget(buttonApply);
145 GroupButtonsLayout->addSpacing(10);
146 GroupButtonsLayout->addStretch();
147 GroupButtonsLayout->addWidget(buttonCancel);
148 GroupButtonsLayout->addWidget(buttonHelp);
150 /***************************************************************/
151 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupConstructors);
152 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1);
153 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons);
155 myHelpFileName = "removing_nodes_and_elements_page.html#removing_nodes_anchor";
157 Init(); /* Initialisations */
160 //=================================================================================
161 // function : ~SMESHGUI_RemoveNodesDlg()
162 // purpose : Destroys the object and frees any allocated resources
163 //=================================================================================
164 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
168 //=================================================================================
171 //=================================================================================
172 void SMESHGUI_RemoveNodesDlg::Init()
175 Constructor1->setChecked(true);
176 myEditCurrentArgument = LineEditC1A1;
179 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
183 /* signals and slots connections */
184 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
185 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
186 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
187 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
189 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
190 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
191 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
192 /* to close dialog if study change */
193 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
194 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
195 SLOT(onTextChange(const QString&)));
197 SMESH::SetPointRepresentation(true);
199 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
200 aViewWindow->SetSelectionMode(NodeSelection);
202 SelectionIntoArgument();
205 //=================================================================================
206 // function : ClickOnApply()
208 //=================================================================================
209 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
211 if (mySMESHGUI->isActiveStudyLocked())
215 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
216 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
217 anArrayOfIdeces->length(aListId.count());
218 for (int i = 0; i < aListId.count(); i++)
219 anArrayOfIdeces[i] = aListId[ i ].toInt();
221 bool aResult = false;
223 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
224 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout());
225 } catch (const SALOME::SALOME_Exception& S_ex) {
226 SalomeApp_Tools::QtCatchCorbaException(S_ex);
227 myEditCurrentArgument->clear();
229 myEditCurrentArgument->clear();
233 myEditCurrentArgument->clear();
234 mySelector->ClearIndex();
238 SMESH::SetPointRepresentation(true);
242 //=================================================================================
243 // function : ClickOnOk()
245 //=================================================================================
246 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
252 //=================================================================================
253 // function : ClickOnCancel()
255 //=================================================================================
256 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
258 //mySelectionMgr->clearSelected();
259 SMESH::SetPointRepresentation(false);
260 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
261 aViewWindow->SetSelectionMode(ActorSelection);
262 disconnect(mySelectionMgr, 0, this, 0);
263 mySMESHGUI->ResetState();
267 //=================================================================================
268 // function : ClickOnHelp()
270 //=================================================================================
271 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
273 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
275 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
279 platform = "winapplication";
281 platform = "application";
283 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
284 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
285 arg(app->resourceMgr()->stringValue("ExternalBrowser",
287 arg(myHelpFileName));
291 //=======================================================================
292 //function : onTextChange
294 //=======================================================================
295 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
302 buttonOk->setEnabled(false);
303 buttonApply->setEnabled(false);
305 // hilight entered nodes
307 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
308 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
310 TColStd_MapOfInteger newIndices;
312 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
313 for (int i = 0; i < aListId.count(); i++) {
314 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
315 newIndices.Add(aNode->GetID());
320 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
321 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
322 aViewWindow->highlight(anIO,true,true);
327 buttonOk->setEnabled(true);
328 buttonApply->setEnabled(true);
334 //=================================================================================
335 // function : SelectionIntoArgument()
336 // purpose : Called when selection as changed or other case
337 //=================================================================================
338 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
348 myEditCurrentArgument->setText("");
351 if (!GroupButtons->isEnabled()) // inactive
354 buttonOk->setEnabled(false);
355 buttonApply->setEnabled(false);
359 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
361 int nbSel = aList.Extent();
365 Handle(SALOME_InteractiveObject) anIO = aList.First();
366 myMesh = SMESH::GetMeshByIO(anIO);
367 if (myMesh->_is_nil())
370 myActor = SMESH::FindActorByEntry(anIO->getEntry());
374 // get selected nodes
376 QString aString = "";
377 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
381 myEditCurrentArgument->setText(aString);
388 buttonOk->setEnabled(true);
389 buttonApply->setEnabled(true);
392 //=================================================================================
393 // function : SetEditCurrentArgument()
395 //=================================================================================
396 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
398 QPushButton* send = (QPushButton*)sender();
399 switch (myConstructorId) {
400 case 0: /* default constructor */
402 if(send == SelectButtonC1A1) {
403 LineEditC1A1->setFocus();
404 myEditCurrentArgument = LineEditC1A1;
406 SelectionIntoArgument();
412 //=================================================================================
413 // function : DeactivateActiveDialog()
415 //=================================================================================
416 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
418 if (GroupConstructors->isEnabled()) {
419 GroupConstructors->setEnabled(false);
420 GroupC1->setEnabled(false);
421 GroupButtons->setEnabled(false);
422 mySMESHGUI->ResetState(); // ??
423 mySMESHGUI->SetActiveDialogBox(0); // ??
427 //=================================================================================
428 // function : ActivateThisDialog()
430 //=================================================================================
431 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
433 /* Emit a signal to deactivate the active dialog */
434 mySMESHGUI->EmitSignalDeactivateDialog();
436 GroupConstructors->setEnabled(true);
437 GroupC1->setEnabled(true);
438 GroupButtons->setEnabled(true);
440 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
442 SMESH::SetPointRepresentation(true);
443 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
444 aViewWindow->SetSelectionMode(NodeSelection);
446 SelectionIntoArgument(); // ??
449 //=================================================================================
450 // function : enterEvent()
452 //=================================================================================
453 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent*)
455 if (!GroupConstructors->isEnabled())
456 ActivateThisDialog();
459 //=================================================================================
460 // function : closeEvent()
462 //=================================================================================
463 void SMESHGUI_RemoveNodesDlg::closeEvent(QCloseEvent*)
465 /* same than click on cancel button */
469 //=======================================================================
470 //function : hideEvent
471 //purpose : caused by ESC key
472 //=======================================================================
473 void SMESHGUI_RemoveNodesDlg::hideEvent( QHideEvent* )
479 //=================================================================================
480 // function : keyPressEvent()
482 //=================================================================================
483 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
485 QDialog::keyPressEvent( e );
486 if ( e->isAccepted() )
489 if ( e->key() == Qt::Key_F1 ) {