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_RemoveNodesDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_RemoveNodesDlg.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 "SalomeApp_Application.h"
47 #include "SVTK_Selector.h"
48 #include "SVTK_ViewModel.h"
49 #include "SVTK_ViewWindow.h"
50 #include "SALOME_ListIO.hxx"
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_RemoveNodesDlg()
77 //=================================================================================
78 SMESHGUI_RemoveNodesDlg
79 ::SMESHGUI_RemoveNodesDlg(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_NODE")));
93 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
96 setName("SMESHGUI_RemoveNodesDlg");
98 setCaption(tr("SMESH_REMOVE_NODES_TITLE" ));
99 setSizeGripEnabled(TRUE);
100 SMESHGUI_RemoveNodesDlgLayout = new QGridLayout(this);
101 SMESHGUI_RemoveNodesDlgLayout->setSpacing(6);
102 SMESHGUI_RemoveNodesDlgLayout->setMargin(11);
104 /***************************************************************/
105 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
106 GroupConstructors->setTitle(tr("SMESH_NODES" ));
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_RemoveNodesDlgLayout->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_RemoveNodesDlgLayout->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_NODES" ));
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_RemoveNodesDlgLayout->addWidget(GroupC1, 1, 0);
187 myHelpFileName = "/files/removing_nodes_and_elements.htm#?";
189 Init(); /* Initialisations */
192 //=================================================================================
193 // function : ~SMESHGUI_RemoveNodesDlg()
194 // purpose : Destroys the object and frees any allocated resources
195 //=================================================================================
196 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
198 // no need to delete child widgets, Qt does it all for us
201 //=================================================================================
204 //=================================================================================
205 void SMESHGUI_RemoveNodesDlg::Init()
209 Constructor1->setChecked(TRUE);
210 myEditCurrentArgument = LineEditC1A1;
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 SMESH::SetPointRepresentation(true);
236 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
237 aViewWindow->SetSelectionMode(NodeSelection);
239 SelectionIntoArgument();
242 //=================================================================================
243 // function : ConstructorsClicked()
244 // purpose : Radio button management
245 //=================================================================================
246 void SMESHGUI_RemoveNodesDlg::ConstructorsClicked (int)
250 //=================================================================================
251 // function : ClickOnApply()
253 //=================================================================================
254 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
256 if (mySMESHGUI->isActiveStudyLocked())
260 QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false);
261 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
262 anArrayOfIdeces->length(aListId.count());
263 for (int i = 0; i < aListId.count(); i++)
264 anArrayOfIdeces[i] = aListId[ i ].toInt();
266 bool aResult = false;
268 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
269 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout());
274 myEditCurrentArgument->clear();
275 mySelector->ClearIndex();
279 SMESH::SetPointRepresentation(true);
283 //=================================================================================
284 // function : ClickOnOk()
286 //=================================================================================
287 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
293 //=================================================================================
294 // function : ClickOnCancel()
296 //=================================================================================
297 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
299 //mySelectionMgr->clearSelected();
300 SMESH::SetPointRepresentation(false);
301 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
302 aViewWindow->SetSelectionMode(ActorSelection);
303 disconnect(mySelectionMgr, 0, this, 0);
304 mySMESHGUI->ResetState();
308 //=================================================================================
309 // function : ClickOnHelp()
311 //=================================================================================
312 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
314 SalomeApp_Application* app = (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
316 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
318 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
319 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
320 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
321 QObject::tr("BUT_OK"));
325 //=======================================================================
326 //function : onTextChange
328 //=======================================================================
329 void SMESHGUI_RemoveNodesDlg::onTextChange (const QString& theNewText)
336 buttonOk->setEnabled(false);
337 buttonApply->setEnabled(false);
339 // hilight entered nodes
341 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
342 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
344 TColStd_MapOfInteger newIndices;
346 QStringList aListId = QStringList::split(" ", theNewText, false);
347 for (int i = 0; i < aListId.count(); i++) {
348 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
349 newIndices.Add(aNode->GetID());
354 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
355 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
356 aViewWindow->highlight(anIO,true,true);
361 buttonOk->setEnabled(true);
362 buttonApply->setEnabled(true);
368 //=================================================================================
369 // function : SelectionIntoArgument()
370 // purpose : Called when selection as changed or other case
371 //=================================================================================
372 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
382 myEditCurrentArgument->setText("");
385 if (!GroupButtons->isEnabled()) // inactive
388 buttonOk->setEnabled(false);
389 buttonApply->setEnabled(false);
393 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
395 int nbSel = aList.Extent();
399 Handle(SALOME_InteractiveObject) anIO = aList.First();
400 myMesh = SMESH::GetMeshByIO(anIO);
401 if (myMesh->_is_nil())
404 myActor = SMESH::FindActorByEntry(anIO->getEntry());
408 // get selected nodes
410 QString aString = "";
411 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
415 myEditCurrentArgument->setText(aString);
422 buttonOk->setEnabled(true);
423 buttonApply->setEnabled(true);
426 //=================================================================================
427 // function : SetEditCurrentArgument()
429 //=================================================================================
430 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
432 QPushButton* send = (QPushButton*)sender();
433 switch (myConstructorId)
435 case 0: /* default constructor */
437 if(send == SelectButtonC1A1) {
438 LineEditC1A1->setFocus();
439 myEditCurrentArgument = LineEditC1A1;
441 SelectionIntoArgument();
448 //=================================================================================
449 // function : DeactivateActiveDialog()
451 //=================================================================================
452 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
454 if (GroupConstructors->isEnabled()) {
455 GroupConstructors->setEnabled(false);
456 GroupC1->setEnabled(false);
457 GroupButtons->setEnabled(false);
458 mySMESHGUI->ResetState(); // ??
459 mySMESHGUI->SetActiveDialogBox(0); // ??
463 //=================================================================================
464 // function : ActivateThisDialog()
466 //=================================================================================
467 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
469 /* Emit a signal to deactivate the active dialog */
470 mySMESHGUI->EmitSignalDeactivateDialog();
472 GroupConstructors->setEnabled(true);
473 GroupC1->setEnabled(true);
474 GroupButtons->setEnabled(true);
476 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
478 SMESH::SetPointRepresentation(true);
479 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
480 aViewWindow->SetSelectionMode(NodeSelection);
482 SelectionIntoArgument(); // ??
485 //=================================================================================
486 // function : enterEvent()
488 //=================================================================================
489 void SMESHGUI_RemoveNodesDlg::enterEvent (QEvent*)
491 if (!GroupConstructors->isEnabled())
492 ActivateThisDialog();
495 //=================================================================================
496 // function : closeEvent()
498 //=================================================================================
499 void SMESHGUI_RemoveNodesDlg::closeEvent (QCloseEvent*)
501 /* same than click on cancel button */
502 this->ClickOnCancel();
506 //=======================================================================
507 //function : hideEvent
508 //purpose : caused by ESC key
509 //=======================================================================
510 void SMESHGUI_RemoveNodesDlg::hideEvent (QHideEvent * e)