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_RemoveElementsDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "SMESHGUI_RemoveElementsDlg.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_RemoveElementsDlg()
76 //=================================================================================
77 SMESHGUI_RemoveElementsDlg
78 ::SMESHGUI_RemoveElementsDlg(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_ELEMENT")));
91 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
93 QVBoxLayout* SMESHGUI_RemoveElementsDlgLayout = new QVBoxLayout(this);
94 SMESHGUI_RemoveElementsDlgLayout->setSpacing(SPACING);
95 SMESHGUI_RemoveElementsDlgLayout->setMargin(MARGIN);
97 /***************************************************************/
98 GroupConstructors = new QGroupBox(tr("SMESH_ELEMENTS"), 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_ELEMENTS"), 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_RemoveElementsDlgLayout->addWidget(GroupConstructors);
152 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupC1);
153 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupButtons);
155 myHelpFileName = "removing_nodes_and_elements_page.html#removing_elements_anchor";
157 Init(); /* Initialisations */
160 //=================================================================================
161 // function : ~SMESHGUI_RemoveElementsDlg()
162 // purpose : Destroys the object and frees any allocated resources
163 //=================================================================================
164 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
168 //=================================================================================
171 //=================================================================================
172 void SMESHGUI_RemoveElementsDlg::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 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
198 aViewWindow->SetSelectionMode(CellSelection);
200 SelectionIntoArgument();
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
209 if (mySMESHGUI->isActiveStudyLocked())
212 if (myNbOkElements) {
213 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
214 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
215 anArrayOfIdeces->length(aListId.count());
216 for (int i = 0; i < aListId.count(); i++)
217 anArrayOfIdeces[i] = aListId[ i ].toInt();
219 bool aResult = false;
221 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
222 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.inout());
223 } catch (const SALOME::SALOME_Exception& S_ex) {
224 SalomeApp_Tools::QtCatchCorbaException(S_ex);
225 myEditCurrentArgument->clear();
227 myEditCurrentArgument->clear();
231 myEditCurrentArgument->clear();
232 mySelector->ClearIndex();
238 //=================================================================================
239 // function : ClickOnOk()
241 //=================================================================================
242 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
248 //=================================================================================
249 // function : ClickOnCancel()
251 //=================================================================================
252 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
254 //mySelectionMgr->clearSelected();
255 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
256 aViewWindow->SetSelectionMode(ActorSelection);
257 disconnect(mySelectionMgr, 0, this, 0);
258 mySMESHGUI->ResetState();
262 //=================================================================================
263 // function : ClickOnHelp()
265 //=================================================================================
266 void SMESHGUI_RemoveElementsDlg::ClickOnHelp()
268 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
270 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
274 platform = "winapplication";
276 platform = "application";
278 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
279 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
280 arg(app->resourceMgr()->stringValue("ExternalBrowser",
282 arg(myHelpFileName));
286 //=======================================================================
287 //function : onTextChange
289 //=======================================================================
290 void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
297 buttonOk->setEnabled(false);
298 buttonApply->setEnabled(false);
300 // hilight entered elements
302 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
303 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
305 TColStd_MapOfInteger newIndices;
307 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
308 for (int i = 0; i < aListId.count(); i++) {
309 if(const SMDS_MeshElement *anElem = aMesh->FindElement(aListId[i].toInt())) {
310 newIndices.Add(anElem->GetID());
315 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
316 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
317 aViewWindow->highlight(anIO,true,true);
321 if (myNbOkElements) {
322 buttonOk->setEnabled(true);
323 buttonApply->setEnabled(true);
329 //=================================================================================
330 // function : SelectionIntoArgument()
331 // purpose : Called when selection as changed or other case
332 //=================================================================================
333 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
339 myNbOkElements = false;
343 myEditCurrentArgument->setText("");
346 if (!GroupButtons->isEnabled()) // inactive
349 buttonOk->setEnabled(false);
350 buttonApply->setEnabled(false);
355 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
357 int nbSel = aList.Extent();
361 Handle(SALOME_InteractiveObject) anIO = aList.First();
362 myMesh = SMESH::GetMeshByIO(anIO);
363 if (myMesh->_is_nil())
366 myActor = SMESH::FindActorByEntry(anIO->getEntry());
370 // get selected nodes
371 QString aString = "";
372 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aString);
376 myEditCurrentArgument->setText(aString);
381 myNbOkElements = nbElems;
383 buttonOk->setEnabled(true);
384 buttonApply->setEnabled(true);
387 //=================================================================================
388 // function : SetEditCurrentArgument()
390 //=================================================================================
391 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
393 QPushButton* send = (QPushButton*)sender();
394 switch (myConstructorId) {
395 case 0: /* default constructor */
397 if(send == SelectButtonC1A1) {
398 LineEditC1A1->setFocus();
399 myEditCurrentArgument = LineEditC1A1;
401 SelectionIntoArgument();
407 //=================================================================================
408 // function : DeactivateActiveDialog()
410 //=================================================================================
411 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
413 if (GroupConstructors->isEnabled()) {
414 GroupConstructors->setEnabled(false);
415 GroupC1->setEnabled(false);
416 GroupButtons->setEnabled(false);
417 mySMESHGUI->ResetState(); // ??
418 mySMESHGUI->SetActiveDialogBox(0); // ??
422 //=================================================================================
423 // function : ActivateThisDialog()
425 //=================================================================================
426 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
428 /* Emit a signal to deactivate the active dialog */
429 mySMESHGUI->EmitSignalDeactivateDialog();
431 GroupConstructors->setEnabled(true);
432 GroupC1->setEnabled(true);
433 GroupButtons->setEnabled(true);
435 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
437 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
438 aViewWindow->SetSelectionMode(CellSelection);
440 SelectionIntoArgument(); // ??
443 //=================================================================================
444 // function : enterEvent()
446 //=================================================================================
447 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent*)
449 if (!GroupConstructors->isEnabled())
450 ActivateThisDialog();
453 //=================================================================================
454 // function : closeEvent()
456 //=================================================================================
457 void SMESHGUI_RemoveElementsDlg::closeEvent(QCloseEvent*)
459 /* same than click on cancel button */
463 //=======================================================================
464 //function : hideEvent
465 //purpose : caused by ESC key
466 //=======================================================================
467 void SMESHGUI_RemoveElementsDlg::hideEvent( QHideEvent* )
473 //=================================================================================
474 // function : keyPressEvent()
476 //=================================================================================
477 void SMESHGUI_RemoveElementsDlg::keyPressEvent( QKeyEvent* e )
479 QDialog::keyPressEvent( e );
480 if ( e->isAccepted() )
483 if ( e->key() == Qt::Key_F1 ) {