1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_RemoveNodesDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "SMESHGUI_RemoveNodesDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_Actor.h"
37 #include "SMDS_Mesh.hxx"
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"
46 #include "SVTK_Selector.h"
47 #include "SVTK_ViewModel.h"
48 #include "SVTK_ViewWindow.h"
49 #include "SALOME_ListIO.hxx"
51 #include "utilities.h"
54 #include <TColStd_MapOfInteger.hxx>
55 #include <TColStd_IndexedMapOfInteger.hxx>
58 #include <qbuttongroup.h>
59 #include <qgroupbox.h>
61 #include <qlineedit.h>
62 #include <qpushbutton.h>
63 #include <qradiobutton.h>
67 #include <qwhatsthis.h>
73 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
75 //=================================================================================
76 // class : SMESHGUI_RemoveNodesDlg()
78 //=================================================================================
79 SMESHGUI_RemoveNodesDlg
80 ::SMESHGUI_RemoveNodesDlg(SMESHGUI* theModule,
84 : QDialog(SMESH::GetDesktop(theModule),
87 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
88 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
89 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
90 mySMESHGUI(theModule),
93 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
94 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
97 setName("SMESHGUI_RemoveNodesDlg");
99 setCaption(tr("SMESH_REMOVE_NODES_TITLE" ));
100 setSizeGripEnabled(TRUE);
101 SMESHGUI_RemoveNodesDlgLayout = new QGridLayout(this);
102 SMESHGUI_RemoveNodesDlgLayout->setSpacing(6);
103 SMESHGUI_RemoveNodesDlgLayout->setMargin(11);
105 /***************************************************************/
106 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
107 GroupConstructors->setTitle(tr("SMESH_NODES" ));
108 GroupConstructors->setExclusive(TRUE);
109 GroupConstructors->setColumnLayout(0, Qt::Vertical);
110 GroupConstructors->layout()->setSpacing(0);
111 GroupConstructors->layout()->setMargin(0);
112 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
113 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
114 GroupConstructorsLayout->setSpacing(6);
115 GroupConstructorsLayout->setMargin(11);
116 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
117 Constructor1->setText(tr("" ));
118 Constructor1->setPixmap(image0);
119 Constructor1->setChecked(TRUE);
120 Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth()));
121 Constructor1->setMinimumSize(QSize(50, 0));
122 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
123 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
124 GroupConstructorsLayout->addItem(spacer, 0, 1);
125 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupConstructors, 0, 0);
127 /***************************************************************/
128 GroupButtons = new QGroupBox(this, "GroupButtons");
129 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
130 GroupButtons->setTitle(tr("" ));
131 GroupButtons->setColumnLayout(0, Qt::Vertical);
132 GroupButtons->layout()->setSpacing(0);
133 GroupButtons->layout()->setMargin(0);
134 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
135 GroupButtonsLayout->setAlignment(Qt::AlignTop);
136 GroupButtonsLayout->setSpacing(6);
137 GroupButtonsLayout->setMargin(11);
138 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
139 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
140 buttonHelp->setAutoDefault(TRUE);
141 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
142 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
143 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
144 buttonCancel->setAutoDefault(TRUE);
145 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
146 buttonApply = new QPushButton(GroupButtons, "buttonApply");
147 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
148 buttonApply->setAutoDefault(TRUE);
149 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
150 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
151 GroupButtonsLayout->addItem(spacer_9, 0, 2);
152 buttonOk = new QPushButton(GroupButtons, "buttonOk");
153 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
154 buttonOk->setAutoDefault(TRUE);
155 buttonOk->setDefault(TRUE);
156 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
157 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons, 2, 0);
159 /***************************************************************/
160 GroupC1 = new QGroupBox(this, "GroupC1");
161 GroupC1->setTitle(tr("SMESH_REMOVE" ));
162 GroupC1->setMinimumSize(QSize(0, 0));
163 GroupC1->setFrameShape(QGroupBox::Box);
164 GroupC1->setFrameShadow(QGroupBox::Sunken);
165 GroupC1->setColumnLayout(0, Qt::Vertical);
166 GroupC1->layout()->setSpacing(0);
167 GroupC1->layout()->setMargin(0);
168 GroupC1Layout = new QGridLayout(GroupC1->layout());
169 GroupC1Layout->setAlignment(Qt::AlignTop);
170 GroupC1Layout->setSpacing(6);
171 GroupC1Layout->setMargin(11);
172 TextLabelC1A1 = new QLabel(GroupC1, "TextLabelC1A1");
173 TextLabelC1A1->setText(tr("SMESH_ID_NODES" ));
174 TextLabelC1A1->setMinimumSize(QSize(50, 0));
175 TextLabelC1A1->setFrameShape(QLabel::NoFrame);
176 TextLabelC1A1->setFrameShadow(QLabel::Plain);
177 GroupC1Layout->addWidget(TextLabelC1A1, 0, 0);
178 SelectButtonC1A1 = new QPushButton(GroupC1, "SelectButtonC1A1");
179 SelectButtonC1A1->setText(tr("" ));
180 SelectButtonC1A1->setPixmap(image1);
181 SelectButtonC1A1->setToggleButton(FALSE);
182 GroupC1Layout->addWidget(SelectButtonC1A1, 0, 1);
183 LineEditC1A1 = new QLineEdit(GroupC1, "LineEditC1A1");
184 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
185 GroupC1Layout->addWidget(LineEditC1A1, 0, 2);
186 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1, 1, 0);
188 myHelpFileName = "removing_nodes_and_elements_page.html#removing_nodes_anchor";
190 Init(); /* Initialisations */
193 //=================================================================================
194 // function : ~SMESHGUI_RemoveNodesDlg()
195 // purpose : Destroys the object and frees any allocated resources
196 //=================================================================================
197 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
199 // no need to delete child widgets, Qt does it all for us
202 //=================================================================================
205 //=================================================================================
206 void SMESHGUI_RemoveNodesDlg::Init()
210 Constructor1->setChecked(TRUE);
211 myEditCurrentArgument = LineEditC1A1;
214 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
218 /* signals and slots connections */
219 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
220 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
221 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
222 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
223 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
225 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
226 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
227 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
228 /* to close dialog if study change */
229 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
230 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
231 SLOT(onTextChange(const QString&)));
233 this->show(); /* displays Dialog */
235 SMESH::SetPointRepresentation(true);
237 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
238 aViewWindow->SetSelectionMode(NodeSelection);
240 SelectionIntoArgument();
243 //=================================================================================
244 // function : ConstructorsClicked()
245 // purpose : Radio button management
246 //=================================================================================
247 void SMESHGUI_RemoveNodesDlg::ConstructorsClicked (int)
251 //=================================================================================
252 // function : ClickOnApply()
254 //=================================================================================
255 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
257 if (mySMESHGUI->isActiveStudyLocked())
261 QStringList aListId = QStringList::split(" ", myEditCurrentArgument->text(), false);
262 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
263 anArrayOfIdeces->length(aListId.count());
264 for (int i = 0; i < aListId.count(); i++)
265 anArrayOfIdeces[i] = aListId[ i ].toInt();
267 bool aResult = false;
269 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
270 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout());
275 myEditCurrentArgument->clear();
276 mySelector->ClearIndex();
280 SMESH::SetPointRepresentation(true);
284 //=================================================================================
285 // function : ClickOnOk()
287 //=================================================================================
288 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
294 //=================================================================================
295 // function : ClickOnCancel()
297 //=================================================================================
298 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
300 //mySelectionMgr->clearSelected();
301 SMESH::SetPointRepresentation(false);
302 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
303 aViewWindow->SetSelectionMode(ActorSelection);
304 disconnect(mySelectionMgr, 0, this, 0);
305 mySMESHGUI->ResetState();
309 //=================================================================================
310 // function : ClickOnHelp()
312 //=================================================================================
313 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
315 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
317 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
321 platform = "winapplication";
323 platform = "application";
325 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
326 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
327 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
328 QObject::tr("BUT_OK"));
332 //=======================================================================
333 //function : onTextChange
335 //=======================================================================
336 void SMESHGUI_RemoveNodesDlg::onTextChange (const QString& theNewText)
343 buttonOk->setEnabled(false);
344 buttonApply->setEnabled(false);
346 // hilight entered nodes
348 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
349 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
351 TColStd_MapOfInteger newIndices;
353 QStringList aListId = QStringList::split(" ", theNewText, false);
354 for (int i = 0; i < aListId.count(); i++) {
355 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
356 newIndices.Add(aNode->GetID());
361 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
362 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
363 aViewWindow->highlight(anIO,true,true);
368 buttonOk->setEnabled(true);
369 buttonApply->setEnabled(true);
375 //=================================================================================
376 // function : SelectionIntoArgument()
377 // purpose : Called when selection as changed or other case
378 //=================================================================================
379 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
389 myEditCurrentArgument->setText("");
392 if (!GroupButtons->isEnabled()) // inactive
395 buttonOk->setEnabled(false);
396 buttonApply->setEnabled(false);
400 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
402 int nbSel = aList.Extent();
406 Handle(SALOME_InteractiveObject) anIO = aList.First();
407 myMesh = SMESH::GetMeshByIO(anIO);
408 if (myMesh->_is_nil())
411 myActor = SMESH::FindActorByEntry(anIO->getEntry());
415 // get selected nodes
417 QString aString = "";
418 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
422 myEditCurrentArgument->setText(aString);
429 buttonOk->setEnabled(true);
430 buttonApply->setEnabled(true);
433 //=================================================================================
434 // function : SetEditCurrentArgument()
436 //=================================================================================
437 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
439 QPushButton* send = (QPushButton*)sender();
440 switch (myConstructorId)
442 case 0: /* default constructor */
444 if(send == SelectButtonC1A1) {
445 LineEditC1A1->setFocus();
446 myEditCurrentArgument = LineEditC1A1;
448 SelectionIntoArgument();
455 //=================================================================================
456 // function : DeactivateActiveDialog()
458 //=================================================================================
459 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
461 if (GroupConstructors->isEnabled()) {
462 GroupConstructors->setEnabled(false);
463 GroupC1->setEnabled(false);
464 GroupButtons->setEnabled(false);
465 mySMESHGUI->ResetState(); // ??
466 mySMESHGUI->SetActiveDialogBox(0); // ??
470 //=================================================================================
471 // function : ActivateThisDialog()
473 //=================================================================================
474 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
476 /* Emit a signal to deactivate the active dialog */
477 mySMESHGUI->EmitSignalDeactivateDialog();
479 GroupConstructors->setEnabled(true);
480 GroupC1->setEnabled(true);
481 GroupButtons->setEnabled(true);
483 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
485 SMESH::SetPointRepresentation(true);
486 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
487 aViewWindow->SetSelectionMode(NodeSelection);
489 SelectionIntoArgument(); // ??
492 //=================================================================================
493 // function : enterEvent()
495 //=================================================================================
496 void SMESHGUI_RemoveNodesDlg::enterEvent (QEvent*)
498 if (!GroupConstructors->isEnabled())
499 ActivateThisDialog();
502 //=================================================================================
503 // function : closeEvent()
505 //=================================================================================
506 void SMESHGUI_RemoveNodesDlg::closeEvent (QCloseEvent*)
508 /* same than click on cancel button */
509 this->ClickOnCancel();
513 //=======================================================================
514 //function : hideEvent
515 //purpose : caused by ESC key
516 //=======================================================================
517 void SMESHGUI_RemoveNodesDlg::hideEvent (QHideEvent * e)
523 //=================================================================================
524 // function : keyPressEvent()
526 //=================================================================================
527 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
529 QDialog::keyPressEvent( e );
530 if ( e->isAccepted() )
533 if ( e->key() == Key_F1 )