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
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 "LightApp_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#remove_a_node";
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 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
316 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
320 platform = "winapplication";
322 platform = "application";
324 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
325 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
326 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
327 QObject::tr("BUT_OK"));
331 //=======================================================================
332 //function : onTextChange
334 //=======================================================================
335 void SMESHGUI_RemoveNodesDlg::onTextChange (const QString& theNewText)
342 buttonOk->setEnabled(false);
343 buttonApply->setEnabled(false);
345 // hilight entered nodes
347 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
348 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
350 TColStd_MapOfInteger newIndices;
352 QStringList aListId = QStringList::split(" ", theNewText, false);
353 for (int i = 0; i < aListId.count(); i++) {
354 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
355 newIndices.Add(aNode->GetID());
360 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
361 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
362 aViewWindow->highlight(anIO,true,true);
367 buttonOk->setEnabled(true);
368 buttonApply->setEnabled(true);
374 //=================================================================================
375 // function : SelectionIntoArgument()
376 // purpose : Called when selection as changed or other case
377 //=================================================================================
378 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
388 myEditCurrentArgument->setText("");
391 if (!GroupButtons->isEnabled()) // inactive
394 buttonOk->setEnabled(false);
395 buttonApply->setEnabled(false);
399 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
401 int nbSel = aList.Extent();
405 Handle(SALOME_InteractiveObject) anIO = aList.First();
406 myMesh = SMESH::GetMeshByIO(anIO);
407 if (myMesh->_is_nil())
410 myActor = SMESH::FindActorByEntry(anIO->getEntry());
414 // get selected nodes
416 QString aString = "";
417 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
421 myEditCurrentArgument->setText(aString);
428 buttonOk->setEnabled(true);
429 buttonApply->setEnabled(true);
432 //=================================================================================
433 // function : SetEditCurrentArgument()
435 //=================================================================================
436 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
438 QPushButton* send = (QPushButton*)sender();
439 switch (myConstructorId)
441 case 0: /* default constructor */
443 if(send == SelectButtonC1A1) {
444 LineEditC1A1->setFocus();
445 myEditCurrentArgument = LineEditC1A1;
447 SelectionIntoArgument();
454 //=================================================================================
455 // function : DeactivateActiveDialog()
457 //=================================================================================
458 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
460 if (GroupConstructors->isEnabled()) {
461 GroupConstructors->setEnabled(false);
462 GroupC1->setEnabled(false);
463 GroupButtons->setEnabled(false);
464 mySMESHGUI->ResetState(); // ??
465 mySMESHGUI->SetActiveDialogBox(0); // ??
469 //=================================================================================
470 // function : ActivateThisDialog()
472 //=================================================================================
473 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
475 /* Emit a signal to deactivate the active dialog */
476 mySMESHGUI->EmitSignalDeactivateDialog();
478 GroupConstructors->setEnabled(true);
479 GroupC1->setEnabled(true);
480 GroupButtons->setEnabled(true);
482 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
484 SMESH::SetPointRepresentation(true);
485 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
486 aViewWindow->SetSelectionMode(NodeSelection);
488 SelectionIntoArgument(); // ??
491 //=================================================================================
492 // function : enterEvent()
494 //=================================================================================
495 void SMESHGUI_RemoveNodesDlg::enterEvent (QEvent*)
497 if (!GroupConstructors->isEnabled())
498 ActivateThisDialog();
501 //=================================================================================
502 // function : closeEvent()
504 //=================================================================================
505 void SMESHGUI_RemoveNodesDlg::closeEvent (QCloseEvent*)
507 /* same than click on cancel button */
508 this->ClickOnCancel();
512 //=======================================================================
513 //function : hideEvent
514 //purpose : caused by ESC key
515 //=======================================================================
516 void SMESHGUI_RemoveNodesDlg::hideEvent (QHideEvent * e)
522 //=================================================================================
523 // function : keyPressEvent()
525 //=================================================================================
526 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
528 QDialog::keyPressEvent( e );
529 if ( e->isAccepted() )
532 if ( e->key() == Key_F1 )