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>
65 #include <QButtonGroup>
68 #include <SALOMEconfig.h>
69 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
74 //=================================================================================
75 // class : SMESHGUI_RemoveNodesDlg()
77 //=================================================================================
78 SMESHGUI_RemoveNodesDlg
79 ::SMESHGUI_RemoveNodesDlg(SMESHGUI* theModule)
80 : QDialog(SMESH::GetDesktop(theModule)),
81 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
82 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
83 mySMESHGUI(theModule),
87 setAttribute( Qt::WA_DeleteOnClose, true );
88 setWindowTitle(tr("SMESH_REMOVE_NODES_TITLE"));
89 setSizeGripEnabled(true);
91 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
92 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
94 QVBoxLayout* SMESHGUI_RemoveNodesDlgLayout = new QVBoxLayout(this);
95 SMESHGUI_RemoveNodesDlgLayout->setSpacing(SPACING);
96 SMESHGUI_RemoveNodesDlgLayout->setMargin(MARGIN);
98 /***************************************************************/
99 GroupConstructors = new QGroupBox(tr("SMESH_NODES"), this);
100 QButtonGroup* ButtonGroup = new QButtonGroup(this);
101 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
102 GroupConstructorsLayout->setSpacing(SPACING);
103 GroupConstructorsLayout->setMargin(MARGIN);
105 Constructor1 = new QRadioButton(GroupConstructors);
106 Constructor1->setIcon(image0);
107 Constructor1->setChecked(true);
109 GroupConstructorsLayout->addWidget(Constructor1);
110 ButtonGroup->addButton(Constructor1, 0);
112 /***************************************************************/
113 GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
114 QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
115 GroupC1Layout->setSpacing(SPACING);
116 GroupC1Layout->setMargin(MARGIN);
118 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
119 SelectButtonC1A1 = new QPushButton(GroupC1);
120 SelectButtonC1A1->setIcon(image1);
121 LineEditC1A1 = new QLineEdit(GroupC1);
122 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
124 GroupC1Layout->addWidget(TextLabelC1A1);
125 GroupC1Layout->addWidget(SelectButtonC1A1);
126 GroupC1Layout->addWidget(LineEditC1A1);
128 /***************************************************************/
129 GroupButtons = new QGroupBox(this);
130 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
131 GroupButtonsLayout->setSpacing(SPACING);
132 GroupButtonsLayout->setMargin(MARGIN);
134 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
135 buttonOk->setAutoDefault(true);
136 buttonOk->setDefault(true);
137 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
138 buttonApply->setAutoDefault(true);
139 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
140 buttonCancel->setAutoDefault(true);
141 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
142 buttonHelp->setAutoDefault(true);
144 GroupButtonsLayout->addWidget(buttonOk);
145 GroupButtonsLayout->addSpacing(10);
146 GroupButtonsLayout->addWidget(buttonApply);
147 GroupButtonsLayout->addSpacing(10);
148 GroupButtonsLayout->addStretch();
149 GroupButtonsLayout->addWidget(buttonCancel);
150 GroupButtonsLayout->addWidget(buttonHelp);
152 /***************************************************************/
153 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupConstructors);
154 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1);
155 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons);
157 myHelpFileName = "removing_nodes_and_elements_page.html#removing_nodes_anchor";
159 Init(); /* Initialisations */
162 //=================================================================================
163 // function : ~SMESHGUI_RemoveNodesDlg()
164 // purpose : Destroys the object and frees any allocated resources
165 //=================================================================================
166 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
170 //=================================================================================
173 //=================================================================================
174 void SMESHGUI_RemoveNodesDlg::Init()
177 Constructor1->setChecked(true);
178 myEditCurrentArgument = LineEditC1A1;
181 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
185 /* signals and slots connections */
186 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
187 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
188 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
189 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
191 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
192 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
193 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 /* to close dialog if study change */
195 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
196 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
197 SLOT(onTextChange(const QString&)));
199 SMESH::SetPointRepresentation(true);
201 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
202 aViewWindow->SetSelectionMode(NodeSelection);
204 SelectionIntoArgument();
207 //=================================================================================
208 // function : ClickOnApply()
210 //=================================================================================
211 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
213 if (mySMESHGUI->isActiveStudyLocked())
217 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
218 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
219 anArrayOfIdeces->length(aListId.count());
220 for (int i = 0; i < aListId.count(); i++)
221 anArrayOfIdeces[i] = aListId[ i ].toInt();
223 bool aResult = false;
225 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
226 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout());
227 } catch (const SALOME::SALOME_Exception& S_ex) {
228 SalomeApp_Tools::QtCatchCorbaException(S_ex);
229 myEditCurrentArgument->clear();
231 myEditCurrentArgument->clear();
235 myEditCurrentArgument->clear();
236 mySelector->ClearIndex();
240 SMESH::SetPointRepresentation(true);
244 //=================================================================================
245 // function : ClickOnOk()
247 //=================================================================================
248 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
254 //=================================================================================
255 // function : ClickOnCancel()
257 //=================================================================================
258 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
260 //mySelectionMgr->clearSelected();
261 SMESH::SetPointRepresentation(false);
262 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
263 aViewWindow->SetSelectionMode(ActorSelection);
264 disconnect(mySelectionMgr, 0, this, 0);
265 mySMESHGUI->ResetState();
269 //=================================================================================
270 // function : ClickOnHelp()
272 //=================================================================================
273 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
275 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
277 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
281 platform = "winapplication";
283 platform = "application";
285 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
286 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
287 arg(app->resourceMgr()->stringValue("ExternalBrowser",
289 arg(myHelpFileName));
293 //=======================================================================
294 //function : onTextChange
296 //=======================================================================
297 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
304 buttonOk->setEnabled(false);
305 buttonApply->setEnabled(false);
307 // hilight entered nodes
309 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
310 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
312 TColStd_MapOfInteger newIndices;
314 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
315 for (int i = 0; i < aListId.count(); i++) {
316 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
317 newIndices.Add(aNode->GetID());
322 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
323 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
324 aViewWindow->highlight(anIO,true,true);
329 buttonOk->setEnabled(true);
330 buttonApply->setEnabled(true);
336 //=================================================================================
337 // function : SelectionIntoArgument()
338 // purpose : Called when selection as changed or other case
339 //=================================================================================
340 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
350 myEditCurrentArgument->setText("");
353 if (!GroupButtons->isEnabled()) // inactive
356 buttonOk->setEnabled(false);
357 buttonApply->setEnabled(false);
361 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
363 int nbSel = aList.Extent();
367 Handle(SALOME_InteractiveObject) anIO = aList.First();
368 myMesh = SMESH::GetMeshByIO(anIO);
369 if (myMesh->_is_nil())
372 myActor = SMESH::FindActorByEntry(anIO->getEntry());
376 // get selected nodes
378 QString aString = "";
379 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
383 myEditCurrentArgument->setText(aString);
390 buttonOk->setEnabled(true);
391 buttonApply->setEnabled(true);
394 //=================================================================================
395 // function : SetEditCurrentArgument()
397 //=================================================================================
398 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
400 QPushButton* send = (QPushButton*)sender();
401 switch (myConstructorId) {
402 case 0: /* default constructor */
404 if(send == SelectButtonC1A1) {
405 LineEditC1A1->setFocus();
406 myEditCurrentArgument = LineEditC1A1;
408 SelectionIntoArgument();
414 //=================================================================================
415 // function : DeactivateActiveDialog()
417 //=================================================================================
418 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
420 if (GroupConstructors->isEnabled()) {
421 GroupConstructors->setEnabled(false);
422 GroupC1->setEnabled(false);
423 GroupButtons->setEnabled(false);
424 mySMESHGUI->ResetState(); // ??
425 mySMESHGUI->SetActiveDialogBox(0); // ??
429 //=================================================================================
430 // function : ActivateThisDialog()
432 //=================================================================================
433 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
435 /* Emit a signal to deactivate the active dialog */
436 mySMESHGUI->EmitSignalDeactivateDialog();
438 GroupConstructors->setEnabled(true);
439 GroupC1->setEnabled(true);
440 GroupButtons->setEnabled(true);
442 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
444 SMESH::SetPointRepresentation(true);
445 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
446 aViewWindow->SetSelectionMode(NodeSelection);
448 SelectionIntoArgument(); // ??
451 //=================================================================================
452 // function : enterEvent()
454 //=================================================================================
455 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent*)
457 if (!GroupConstructors->isEnabled())
458 ActivateThisDialog();
461 //=================================================================================
462 // function : closeEvent()
464 //=================================================================================
465 void SMESHGUI_RemoveNodesDlg::closeEvent(QCloseEvent*)
467 /* same than click on cancel button */
471 //=======================================================================
472 //function : hideEvent
473 //purpose : caused by ESC key
474 //=======================================================================
475 void SMESHGUI_RemoveNodesDlg::hideEvent( QHideEvent* )
481 //=================================================================================
482 // function : keyPressEvent()
484 //=================================================================================
485 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
487 QDialog::keyPressEvent( e );
488 if ( e->isAccepted() )
491 if ( e->key() == Qt::Key_F1 ) {