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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_RemoveElementsDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_RemoveElementsDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include "SMESH_Actor.h"
38 #include "SMDS_Mesh.hxx"
40 #include "SUIT_ResourceMgr.h"
41 #include "SUIT_Desktop.h"
42 #include "SUIT_Session.h"
43 #include "SUIT_MessageBox.h"
45 #include "SVTK_Selector.h"
46 #include "SVTK_ViewModel.h"
47 #include "SVTK_ViewWindow.h"
48 #include "SALOME_ListIO.hxx"
50 #include "SalomeApp_Tools.h"
51 #include "SalomeApp_Application.h"
52 #include "utilities.h"
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_IndexedMapOfInteger.hxx>
59 #include <qbuttongroup.h>
60 #include <qgroupbox.h>
62 #include <qlineedit.h>
63 #include <qpushbutton.h>
64 #include <qradiobutton.h>
68 #include <qwhatsthis.h>
74 //=================================================================================
75 // class : SMESHGUI_RemoveElementsDlg()
77 //=================================================================================
78 SMESHGUI_RemoveElementsDlg
79 ::SMESHGUI_RemoveElementsDlg (SMESHGUI* theModule,
83 : QDialog(SMESH::GetDesktop(theModule),
86 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
87 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
88 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
89 mySMESHGUI(theModule),
92 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_ELEMENT")));
93 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
96 setName("SMESHGUI_RemoveElementsDlg");
98 setCaption(tr("SMESH_REMOVE_ELEMENTS_TITLE"));
99 setSizeGripEnabled(TRUE);
100 SMESHGUI_RemoveElementsDlgLayout = new QGridLayout(this);
101 SMESHGUI_RemoveElementsDlgLayout->setSpacing(6);
102 SMESHGUI_RemoveElementsDlgLayout->setMargin(11);
104 /***************************************************************/
105 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
106 GroupConstructors->setTitle(tr("SMESH_ELEMENTS" ));
107 GroupConstructors->setExclusive(TRUE);
108 GroupConstructors->setColumnLayout(0, Qt::Vertical);
109 GroupConstructors->layout()->setSpacing(0);
110 GroupConstructors->layout()->setMargin(0);
111 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
112 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
113 GroupConstructorsLayout->setSpacing(6);
114 GroupConstructorsLayout->setMargin(11);
115 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
116 Constructor1->setText(tr("" ));
117 Constructor1->setPixmap(image0);
118 Constructor1->setChecked(TRUE);
119 Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth()));
120 Constructor1->setMinimumSize(QSize(50, 0));
121 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
122 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
123 GroupConstructorsLayout->addItem(spacer, 0, 1);
124 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupConstructors, 0, 0);
126 /***************************************************************/
127 GroupButtons = new QGroupBox(this, "GroupButtons");
128 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
129 GroupButtons->setTitle(tr("" ));
130 GroupButtons->setColumnLayout(0, Qt::Vertical);
131 GroupButtons->layout()->setSpacing(0);
132 GroupButtons->layout()->setMargin(0);
133 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
134 GroupButtonsLayout->setAlignment(Qt::AlignTop);
135 GroupButtonsLayout->setSpacing(6);
136 GroupButtonsLayout->setMargin(11);
137 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
138 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
139 buttonHelp->setAutoDefault(TRUE);
140 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
141 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
142 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
143 buttonCancel->setAutoDefault(TRUE);
144 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
145 buttonApply = new QPushButton(GroupButtons, "buttonApply");
146 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
147 buttonApply->setAutoDefault(TRUE);
148 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
149 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
150 GroupButtonsLayout->addItem(spacer_9, 0, 2);
151 buttonOk = new QPushButton(GroupButtons, "buttonOk");
152 buttonOk->setText(tr("SMESH_BUT_OK" ));
153 buttonOk->setAutoDefault(TRUE);
154 buttonOk->setDefault(TRUE);
155 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
156 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupButtons, 2, 0);
158 /***************************************************************/
159 GroupC1 = new QGroupBox(this, "GroupC1");
160 GroupC1->setTitle(tr("SMESH_REMOVE" ));
161 GroupC1->setMinimumSize(QSize(0, 0));
162 GroupC1->setFrameShape(QGroupBox::Box);
163 GroupC1->setFrameShadow(QGroupBox::Sunken);
164 GroupC1->setColumnLayout(0, Qt::Vertical);
165 GroupC1->layout()->setSpacing(0);
166 GroupC1->layout()->setMargin(0);
167 GroupC1Layout = new QGridLayout(GroupC1->layout());
168 GroupC1Layout->setAlignment(Qt::AlignTop);
169 GroupC1Layout->setSpacing(6);
170 GroupC1Layout->setMargin(11);
171 TextLabelC1A1 = new QLabel(GroupC1, "TextLabelC1A1");
172 TextLabelC1A1->setText(tr("SMESH_ID_ELEMENTS" ));
173 TextLabelC1A1->setMinimumSize(QSize(50, 0));
174 TextLabelC1A1->setFrameShape(QLabel::NoFrame);
175 TextLabelC1A1->setFrameShadow(QLabel::Plain);
176 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
177 SelectButtonC1A1 = new QPushButton(GroupC1, "SelectButtonC1A1");
178 SelectButtonC1A1->setText(tr("" ));
179 SelectButtonC1A1->setPixmap(image1);
180 SelectButtonC1A1->setToggleButton(FALSE);
181 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
182 LineEditC1A1 = new QLineEdit(GroupC1, "LineEditC1A1");
183 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
184 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
185 SMESHGUI_RemoveElementsDlgLayout->addWidget(GroupC1, 1, 0);
187 myHelpFileName = "/files/removing_nodes_and_elements.htm#?";
189 Init(); /* Initialisations */
192 //=================================================================================
193 // function : ~SMESHGUI_RemoveElementsDlg()
194 // purpose : Destroys the object and frees any allocated resources
195 //=================================================================================
196 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
198 // no need to delete child widgets, Qt does it all for us
201 //=================================================================================
204 //=================================================================================
205 void SMESHGUI_RemoveElementsDlg::Init()
209 Constructor1->setChecked(TRUE);
210 myEditCurrentArgument = LineEditC1A1;
212 myNbOkElements = false;
213 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
217 /* signals and slots connections */
218 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
219 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
220 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
221 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
222 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
224 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
225 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
226 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
227 /* to close dialog if study change */
228 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
229 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
230 SLOT(onTextChange(const QString&)));
232 this->show(); /* displays Dialog */
234 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
235 aViewWindow->SetSelectionMode(CellSelection);
237 SelectionIntoArgument();
240 //=================================================================================
241 // function : ConstructorsClicked()
242 // purpose : Radio button management
243 //=================================================================================
244 void SMESHGUI_RemoveElementsDlg::ConstructorsClicked (int)
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
254 if (mySMESHGUI->isActiveStudyLocked())
256 if (myNbOkElements) {
257 QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false);
258 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
259 anArrayOfIdeces->length(aListId.count());
260 for (int i = 0; i < aListId.count(); i++)
261 anArrayOfIdeces[i] = aListId[ i ].toInt();
263 bool aResult = false;
265 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
266 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.inout());
267 } catch (const SALOME::SALOME_Exception& S_ex) {
268 SalomeApp_Tools::QtCatchCorbaException(S_ex);
269 myEditCurrentArgument->clear();
271 myEditCurrentArgument->clear();
275 myEditCurrentArgument->clear();
276 mySelector->ClearIndex();
282 //=================================================================================
283 // function : ClickOnOk()
285 //=================================================================================
286 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
288 this->ClickOnApply();
289 this->ClickOnCancel();
294 //=================================================================================
295 // function : ClickOnCancel()
297 //=================================================================================
298 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
300 //mySelectionMgr->clearSelected();
301 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
302 aViewWindow->SetSelectionMode(ActorSelection);
303 disconnect(mySelectionMgr, 0, this, 0);
304 mySMESHGUI->ResetState();
309 //=================================================================================
310 // function : ClickOnHelp()
312 //=================================================================================
313 void SMESHGUI_RemoveElementsDlg::ClickOnHelp()
315 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
317 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
319 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
320 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
321 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
322 QObject::tr("BUT_OK"));
326 //=======================================================================
327 //function : onTextChange
329 //=======================================================================
330 void SMESHGUI_RemoveElementsDlg::onTextChange (const QString& theNewText)
338 buttonOk->setEnabled(false);
339 buttonApply->setEnabled(false);
341 // hilight entered elements
343 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
344 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
346 TColStd_MapOfInteger newIndices;
348 QStringList aListId = QStringList::split(" ", theNewText, false);
349 for (int i = 0; i < aListId.count(); i++) {
350 if(const SMDS_MeshElement *anElem = aMesh->FindElement(aListId[i].toInt())) {
351 newIndices.Add(anElem->GetID());
356 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
357 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
358 aViewWindow->highlight(anIO,true,true);
362 if (myNbOkElements) {
363 buttonOk->setEnabled(true);
364 buttonApply->setEnabled(true);
370 //=================================================================================
371 // function : SelectionIntoArgument()
372 // purpose : Called when selection as changed or other case
373 //=================================================================================
374 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
380 myNbOkElements = false;
384 myEditCurrentArgument->setText("");
387 if (!GroupButtons->isEnabled()) // inactive
390 buttonOk->setEnabled(false);
391 buttonApply->setEnabled(false);
396 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
398 int nbSel = aList.Extent();
402 Handle(SALOME_InteractiveObject) anIO = aList.First();
403 myMesh = SMESH::GetMeshByIO(anIO);
404 if (myMesh->_is_nil())
407 myActor = SMESH::FindActorByEntry(anIO->getEntry());
411 // get selected nodes
412 QString aString = "";
413 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,anIO,aString);
417 myEditCurrentArgument->setText(aString);
422 myNbOkElements = nbElems;
424 buttonOk->setEnabled(true);
425 buttonApply->setEnabled(true);
428 //=================================================================================
429 // function : SetEditCurrentArgument()
431 //=================================================================================
432 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
434 QPushButton* send = (QPushButton*)sender();
435 switch (myConstructorId)
437 case 0: /* default constructor */
439 if(send == SelectButtonC1A1) {
440 LineEditC1A1->setFocus();
441 myEditCurrentArgument = LineEditC1A1;
443 SelectionIntoArgument();
450 //=================================================================================
451 // function : DeactivateActiveDialog()
453 //=================================================================================
454 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
456 if (GroupConstructors->isEnabled()) {
457 GroupConstructors->setEnabled(false);
458 GroupC1->setEnabled(false);
459 GroupButtons->setEnabled(false);
460 mySMESHGUI->ResetState(); // ??
461 mySMESHGUI->SetActiveDialogBox(0); // ??
465 //=================================================================================
466 // function : ActivateThisDialog()
468 //=================================================================================
469 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
471 /* Emit a signal to deactivate the active dialog */
472 mySMESHGUI->EmitSignalDeactivateDialog();
474 GroupConstructors->setEnabled(true);
475 GroupC1->setEnabled(true);
476 GroupButtons->setEnabled(true);
478 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
480 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
481 aViewWindow->SetSelectionMode(NodeSelection);
483 SelectionIntoArgument(); // ??
486 //=================================================================================
487 // function : enterEvent()
489 //=================================================================================
490 void SMESHGUI_RemoveElementsDlg::enterEvent (QEvent*)
492 if (!GroupConstructors->isEnabled())
493 ActivateThisDialog();
496 //=================================================================================
497 // function : closeEvent()
499 //=================================================================================
500 void SMESHGUI_RemoveElementsDlg::closeEvent (QCloseEvent*)
502 /* same than click on cancel button */
503 this->ClickOnCancel();
507 //=======================================================================
508 //function : hideEvent
509 //purpose : caused by ESC key
510 //=======================================================================
511 void SMESHGUI_RemoveElementsDlg::hideEvent (QHideEvent * e)