1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_RemoveNodesDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
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"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_TypeFilter.hxx>
38 #include <SMESH_Actor.h>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GUI includes
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
49 #include <SalomeApp_Tools.h>
51 #include <SVTK_Selector.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
57 #include <TColStd_MapOfInteger.hxx>
63 #include <QPushButton>
64 #include <QRadioButton>
65 #include <QVBoxLayout>
66 #include <QHBoxLayout>
68 #include <QButtonGroup>
71 #include <SALOMEconfig.h>
72 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
77 //=================================================================================
78 // class : SMESHGUI_RemoveNodesDlg()
80 //=================================================================================
81 SMESHGUI_RemoveNodesDlg
82 ::SMESHGUI_RemoveNodesDlg(SMESHGUI* theModule)
83 : QDialog(SMESH::GetDesktop(theModule)),
84 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
85 mySelector(SMESH::GetViewWindow(theModule)->GetSelector()),
86 mySMESHGUI(theModule),
91 setAttribute( Qt::WA_DeleteOnClose, true );
92 setWindowTitle(tr("SMESH_REMOVE_NODES_TITLE"));
93 setSizeGripEnabled(true);
95 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_REM_NODE")));
96 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
98 QVBoxLayout* SMESHGUI_RemoveNodesDlgLayout = new QVBoxLayout(this);
99 SMESHGUI_RemoveNodesDlgLayout->setSpacing(SPACING);
100 SMESHGUI_RemoveNodesDlgLayout->setMargin(MARGIN);
102 /***************************************************************/
103 GroupConstructors = new QGroupBox(tr("SMESH_NODES"), this);
104 QButtonGroup* ButtonGroup = new QButtonGroup(this);
105 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
106 GroupConstructorsLayout->setSpacing(SPACING);
107 GroupConstructorsLayout->setMargin(MARGIN);
109 Constructor1 = new QRadioButton(GroupConstructors);
110 Constructor1->setIcon(image0);
111 Constructor1->setChecked(true);
113 GroupConstructorsLayout->addWidget(Constructor1);
114 ButtonGroup->addButton(Constructor1, 0);
116 /***************************************************************/
117 GroupC1 = new QGroupBox(tr("SMESH_REMOVE"), this);
118 QHBoxLayout* GroupC1Layout = new QHBoxLayout(GroupC1);
119 GroupC1Layout->setSpacing(SPACING);
120 GroupC1Layout->setMargin(MARGIN);
122 TextLabelC1A1 = new QLabel(tr("SMESH_ID_NODES"), GroupC1);
123 SelectButtonC1A1 = new QPushButton(GroupC1);
124 SelectButtonC1A1->setIcon(image1);
125 LineEditC1A1 = new QLineEdit(GroupC1);
126 LineEditC1A1->setValidator(new SMESHGUI_IdValidator(this));
127 LineEditC1A1->setMaxLength(-1);
128 QPushButton* filterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupC1 );
129 connect(filterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
131 GroupC1Layout->addWidget(TextLabelC1A1);
132 GroupC1Layout->addWidget(SelectButtonC1A1);
133 GroupC1Layout->addWidget(LineEditC1A1);
134 GroupC1Layout->addWidget(filterBtn );
136 /***************************************************************/
137 GroupButtons = new QGroupBox(this);
138 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
139 GroupButtonsLayout->setSpacing(SPACING);
140 GroupButtonsLayout->setMargin(MARGIN);
142 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
143 buttonOk->setAutoDefault(true);
144 buttonOk->setDefault(true);
145 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
146 buttonApply->setAutoDefault(true);
147 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
148 buttonCancel->setAutoDefault(true);
149 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
150 buttonHelp->setAutoDefault(true);
152 GroupButtonsLayout->addWidget(buttonOk);
153 GroupButtonsLayout->addSpacing(10);
154 GroupButtonsLayout->addWidget(buttonApply);
155 GroupButtonsLayout->addSpacing(10);
156 GroupButtonsLayout->addStretch();
157 GroupButtonsLayout->addWidget(buttonCancel);
158 GroupButtonsLayout->addWidget(buttonHelp);
160 /***************************************************************/
161 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupConstructors);
162 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupC1);
163 SMESHGUI_RemoveNodesDlgLayout->addWidget(GroupButtons);
165 myHelpFileName = "removing_nodes_and_elements.html#removing-nodes-anchor";
167 Init(); /* Initialisations */
170 //=================================================================================
171 // function : ~SMESHGUI_RemoveNodesDlg()
172 // purpose : Destroys the object and frees any allocated resources
173 //=================================================================================
174 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
177 myFilterDlg->setParent( 0 );
183 //=================================================================================
186 //=================================================================================
187 void SMESHGUI_RemoveNodesDlg::Init()
190 Constructor1->setChecked(true);
191 myEditCurrentArgument = LineEditC1A1;
194 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
198 /* signals and slots connections */
199 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
200 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
201 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
202 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
204 connect(SelectButtonC1A1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
205 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
206 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
207 /* to close dialog if study change */
208 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
209 connect(mySMESHGUI, SIGNAL (SignalActivatedViewManager()), this, SLOT(onOpenView()));
210 connect(mySMESHGUI, SIGNAL (SignalCloseView()), this, SLOT(onCloseView()));
211 connect(myEditCurrentArgument, SIGNAL(textChanged(const QString&)),
212 this, SLOT (onTextChange(const QString&)));
214 SMESH::SetPointRepresentation(true);
216 mySelectionMgr->clearFilters();
217 mySelectionMgr->installFilter( new SMESH_TypeFilter( SMESH::IDSOURCE ));
219 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
220 aViewWindow->SetSelectionMode(NodeSelection);
222 //SelectionIntoArgument();
223 mySelectionMgr->setSelectedObjects( SALOME_ListIO() );
226 //=================================================================================
227 // function : ClickOnApply()
229 //=================================================================================
230 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
232 if (SMESHGUI::isStudyLocked())
236 QStringList aListId = myEditCurrentArgument->text().split(" ", QString::SkipEmptyParts);
237 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
238 anArrayOfIdeces->length(aListId.count());
239 for (int i = 0; i < aListId.count(); i++)
240 anArrayOfIdeces[i] = aListId[ i ].toInt();
242 bool aResult = false;
244 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
245 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.in());
246 } catch (const SALOME::SALOME_Exception& S_ex) {
247 SalomeApp_Tools::QtCatchCorbaException(S_ex);
248 myEditCurrentArgument->clear();
250 myEditCurrentArgument->clear();
254 myEditCurrentArgument->clear();
255 mySelector->ClearIndex();
257 SMESHGUI::Modified();
260 SMESH::SetPointRepresentation(true);
264 //=================================================================================
265 // function : ClickOnOk()
267 //=================================================================================
268 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
274 //=================================================================================
275 // function : reject()
277 //=================================================================================
278 void SMESHGUI_RemoveNodesDlg::reject()
280 //mySelectionMgr->clearSelected();
281 if (SMESH::GetCurrentVtkView()) {
282 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
283 SMESH::SetPointRepresentation(false);
285 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
286 aViewWindow->SetSelectionMode(ActorSelection);
287 disconnect(mySelectionMgr, 0, this, 0);
288 mySelectionMgr->clearFilters();
289 mySMESHGUI->ResetState();
294 //=================================================================================
295 // function : onOpenView()
297 //=================================================================================
298 void SMESHGUI_RemoveNodesDlg::onOpenView()
301 SMESH::SetPointRepresentation(false);
304 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
305 ActivateThisDialog();
309 //=================================================================================
310 // function : onCloseView()
312 //=================================================================================
313 void SMESHGUI_RemoveNodesDlg::onCloseView()
315 DeactivateActiveDialog();
319 //=================================================================================
320 // function : ClickOnHelp()
322 //=================================================================================
323 void SMESHGUI_RemoveNodesDlg::ClickOnHelp()
325 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
327 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
331 platform = "winapplication";
333 platform = "application";
335 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
336 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
337 arg(app->resourceMgr()->stringValue("ExternalBrowser",
339 arg(myHelpFileName));
343 //=======================================================================
344 //function : onTextChange
346 //=======================================================================
347 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
354 // highlight entered nodes
356 if(SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh()){
357 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
359 TColStd_MapOfInteger newIndices;
361 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
362 for (int i = 0; i < aListId.count(); i++) {
363 if (const SMDS_MeshNode *aNode = aMesh->FindNode(aListId[i].toInt())) {
364 newIndices.Add(aNode->GetID());
369 mySelector->AddOrRemoveIndex(anIO,newIndices,false);
370 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
371 aViewWindow->highlight(anIO,true,true);
379 //=================================================================================
380 // function : SelectionIntoArgument()
381 // purpose : Called when selection as changed or other case
382 //=================================================================================
383 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
385 if (myBusy) return; // busy
386 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
387 if (!GroupButtons->isEnabled()) return; // inactive
395 myEditCurrentArgument->setText("");
400 mySelectionMgr->selectedObjects(aList);
402 int nbSel = aList.Extent();
405 Handle(SALOME_InteractiveObject) anIO = aList.First();
406 myMesh = SMESH::GetMeshByIO(anIO);
408 if (!myMesh->_is_nil()) {
410 myActor = SMESH::FindActorByEntry(anIO->getEntry());
413 // get selected nodes
414 QString aString = "";
415 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelector,anIO,aString);
418 myEditCurrentArgument->setText(aString);
423 myNbOkNodes = nbNodes;
424 } // if (nbNodes > 0)
426 } // if (!myMesh->_is_nil())
432 //=================================================================================
433 // function : SetEditCurrentArgument()
435 //=================================================================================
436 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
438 QPushButton* send = (QPushButton*)sender();
439 switch (myConstructorId) {
440 case 0: /* default constructor */
442 if(send == SelectButtonC1A1) {
443 LineEditC1A1->setFocus();
444 myEditCurrentArgument = LineEditC1A1;
446 SelectionIntoArgument();
452 //=================================================================================
453 // function : DeactivateActiveDialog()
455 //=================================================================================
456 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
458 if (GroupConstructors->isEnabled()) {
459 GroupConstructors->setEnabled(false);
460 GroupC1->setEnabled(false);
461 GroupButtons->setEnabled(false);
462 mySMESHGUI->ResetState(); // ??
463 mySMESHGUI->SetActiveDialogBox(0); // ??
467 //=================================================================================
468 // function : ActivateThisDialog()
470 //=================================================================================
471 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
473 /* Emit a signal to deactivate the active dialog */
474 mySMESHGUI->EmitSignalDeactivateDialog();
476 GroupConstructors->setEnabled(true);
477 GroupC1->setEnabled(true);
478 GroupButtons->setEnabled(true);
480 mySMESHGUI->SetActiveDialogBox((QDialog*)this); // ??
482 mySelectionMgr->clearFilters();
483 mySelectionMgr->installFilter( new SMESH_TypeFilter( SMESH::IDSOURCE ));
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 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
500 if ( aViewWindow && !mySelector) {
501 mySelector = aViewWindow->GetSelector();
503 ActivateThisDialog();
507 //=================================================================================
508 // function : keyPressEvent()
510 //=================================================================================
511 void SMESHGUI_RemoveNodesDlg::keyPressEvent( QKeyEvent* e )
513 QDialog::keyPressEvent( e );
514 if ( e->isAccepted() )
517 if ( e->key() == Qt::Key_F1 ) {
523 //=================================================================================
524 // function : setFilters()
525 // purpose : SLOT. Called when "Filter" button pressed.
526 //=================================================================================
527 void SMESHGUI_RemoveNodesDlg::setFilters()
529 if(myMesh->_is_nil()) {
530 SUIT_MessageBox::critical(this,
532 tr("NO_MESH_SELECTED"));
536 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::NODE );
538 myFilterDlg->SetSelection();
539 myFilterDlg->SetMesh( myMesh );
540 myFilterDlg->SetSourceWg( LineEditC1A1 );
545 //=================================================================================
546 // function : updateButtons
547 // purpose : enable / disable control buttons
548 //=================================================================================
549 void SMESHGUI_RemoveNodesDlg::updateButtons()
551 buttonOk->setEnabled(myNbOkNodes > 0);
552 buttonApply->setEnabled(myNbOkNodes > 0);