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"
36 #include "SMESH_Actor.h"
37 #include "SMDS_Mesh.hxx"
39 #include "QAD_Application.h"
40 #include "QAD_Desktop.h"
41 #include "QAD_MessageBox.h"
42 #include "utilities.h"
45 #include <qbuttongroup.h>
46 #include <qgroupbox.h>
48 #include <qlineedit.h>
49 #include <qpushbutton.h>
50 #include <qradiobutton.h>
54 #include <qwhatsthis.h>
60 //=================================================================================
61 // class : SMESHGUI_RemoveNodesDlg()
63 //=================================================================================
64 SMESHGUI_RemoveNodesDlg::SMESHGUI_RemoveNodesDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
65 bool modal, WFlags fl )
66 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
67 Qt::WDestructiveClose),
70 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_REM_NODE")));
71 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
74 setName( "SMESHGUI_RemoveNodesDlg" );
76 setCaption( tr( "SMESH_REMOVE_NODES_TITLE" ) );
77 setSizeGripEnabled( TRUE );
78 SMESHGUI_RemoveNodesDlgLayout = new QGridLayout( this );
79 SMESHGUI_RemoveNodesDlgLayout->setSpacing( 6 );
80 SMESHGUI_RemoveNodesDlgLayout->setMargin( 11 );
82 /***************************************************************/
83 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
84 GroupConstructors->setTitle( tr( "SMESH_NODES" ) );
85 GroupConstructors->setExclusive( TRUE );
86 GroupConstructors->setColumnLayout(0, Qt::Vertical );
87 GroupConstructors->layout()->setSpacing( 0 );
88 GroupConstructors->layout()->setMargin( 0 );
89 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
90 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
91 GroupConstructorsLayout->setSpacing( 6 );
92 GroupConstructorsLayout->setMargin( 11 );
93 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
94 Constructor1->setText( tr( "" ) );
95 Constructor1->setPixmap( image0 );
96 Constructor1->setChecked( TRUE );
97 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
98 Constructor1->setMinimumSize( QSize( 50, 0 ) );
99 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
100 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
101 GroupConstructorsLayout->addItem( spacer, 0, 1 );
102 SMESHGUI_RemoveNodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
104 /***************************************************************/
105 GroupButtons = new QGroupBox( this, "GroupButtons" );
106 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
107 GroupButtons->setTitle( tr( "" ) );
108 GroupButtons->setColumnLayout(0, Qt::Vertical );
109 GroupButtons->layout()->setSpacing( 0 );
110 GroupButtons->layout()->setMargin( 0 );
111 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
112 GroupButtonsLayout->setAlignment( Qt::AlignTop );
113 GroupButtonsLayout->setSpacing( 6 );
114 GroupButtonsLayout->setMargin( 11 );
115 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
116 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
117 buttonCancel->setAutoDefault( TRUE );
118 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
119 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
120 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
121 buttonApply->setAutoDefault( TRUE );
122 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
123 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
124 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
125 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
126 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
127 buttonOk->setAutoDefault( TRUE );
128 buttonOk->setDefault( TRUE );
129 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
130 SMESHGUI_RemoveNodesDlgLayout->addWidget( GroupButtons, 2, 0 );
132 /***************************************************************/
133 GroupC1 = new QGroupBox( this, "GroupC1" );
134 GroupC1->setTitle( tr( "SMESH_REMOVE" ) );
135 GroupC1->setMinimumSize( QSize( 0, 0 ) );
136 GroupC1->setFrameShape( QGroupBox::Box );
137 GroupC1->setFrameShadow( QGroupBox::Sunken );
138 GroupC1->setColumnLayout(0, Qt::Vertical );
139 GroupC1->layout()->setSpacing( 0 );
140 GroupC1->layout()->setMargin( 0 );
141 GroupC1Layout = new QGridLayout( GroupC1->layout() );
142 GroupC1Layout->setAlignment( Qt::AlignTop );
143 GroupC1Layout->setSpacing( 6 );
144 GroupC1Layout->setMargin( 11 );
145 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
146 TextLabelC1A1->setText( tr( "SMESH_ID_NODES" ) );
147 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
148 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
149 TextLabelC1A1->setFrameShadow( QLabel::Plain );
150 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
151 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
152 SelectButtonC1A1->setText( tr( "" ) );
153 SelectButtonC1A1->setPixmap( image1 );
154 SelectButtonC1A1->setToggleButton( FALSE );
155 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
156 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
157 LineEditC1A1->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
158 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
159 SMESHGUI_RemoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
161 Init(Sel) ; /* Initialisations */
164 //=================================================================================
165 // function : ~SMESHGUI_RemoveNodesDlg()
166 // purpose : Destroys the object and frees any allocated resources
167 //=================================================================================
168 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
170 // no need to delete child widgets, Qt does it all for us
174 //=================================================================================
177 //=================================================================================
178 void SMESHGUI_RemoveNodesDlg::Init( SALOME_Selection* Sel )
183 myConstructorId = 0 ;
184 Constructor1->setChecked( TRUE );
185 myEditCurrentArgument = LineEditC1A1 ;
189 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
190 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
192 /* signals and slots connections */
193 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
194 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
195 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
196 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
198 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
199 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
200 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
201 /* to close dialog if study change */
202 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
203 connect( myEditCurrentArgument, SIGNAL( textChanged( const QString& )),
204 SLOT( onTextChange( const QString& )));
206 /* Move widget on the botton right corner of main widget */
208 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
210 this->show() ; /* displays Dialog */
212 SMESH::SetPointRepresentation(true);
213 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
215 SelectionIntoArgument();
220 //=================================================================================
221 // function : ConstructorsClicked()
222 // purpose : Radio button management
223 //=================================================================================
224 void SMESHGUI_RemoveNodesDlg::ConstructorsClicked(int constructorId)
230 //=================================================================================
231 // function : ClickOnApply()
233 //=================================================================================
234 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
236 if (mySMESHGUI->ActiveStudyLocked())
241 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
242 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
243 anArrayOfIdeces->length( aListId.count() );
244 for ( int i = 0; i < aListId.count(); i++ )
245 anArrayOfIdeces[i] = aListId[ i ].toInt();
247 bool aResult = false;
250 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
251 aResult = aMeshEditor->RemoveNodes(anArrayOfIdeces.inout()) ;
259 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
260 mySelection->ClearIObjects();
262 mySelection->AddIObject( anIO, false );
265 SMESH::SetPointRepresentation(true);
269 //=================================================================================
270 // function : ClickOnOk()
272 //=================================================================================
273 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
275 this->ClickOnApply() ;
276 this->ClickOnCancel() ;
282 //=================================================================================
283 // function : ClickOnCancel()
285 //=================================================================================
286 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
288 mySelection->ClearIObjects();
289 SMESH::SetPointRepresentation(false);
290 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
291 disconnect( mySelection, 0, this, 0 );
292 mySMESHGUI->ResetState() ;
297 //=======================================================================
298 //function : onTextChange
300 //=======================================================================
302 void SMESHGUI_RemoveNodesDlg::onTextChange(const QString& theNewText)
304 if ( myBusy ) return;
309 buttonOk->setEnabled( false );
310 buttonApply->setEnabled( false );
312 // hilight entered nodes
313 SMDS_Mesh* aMesh = 0;
315 aMesh = myActor->GetObject()->GetMesh();
318 mySelection->ClearIObjects();
319 mySelection->AddIObject( myActor->getIO() );
321 QStringList aListId = QStringList::split( " ", theNewText, false);
322 for ( int i = 0; i < aListId.count(); i++ ) {
323 const SMDS_MeshNode * n = aMesh->FindNode( aListId[ i ].toInt() );
325 if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
326 mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
332 buttonOk->setEnabled( true );
333 buttonApply->setEnabled( true );
340 //=================================================================================
341 // function : SelectionIntoArgument()
342 // purpose : Called when selection as changed or other case
343 //=================================================================================
344 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
346 if ( myBusy ) return;
354 myEditCurrentArgument->setText( "" );
357 if ( !GroupButtons->isEnabled() ) // inactive
360 buttonOk->setEnabled( false );
361 buttonApply->setEnabled( false );
365 int nbSel = mySelection->IObjectCount();
369 myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
370 if ( myMesh->_is_nil() )
373 myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
377 // get selected nodes
379 QString aString = "";
380 int nbNodes = SMESH::GetNameOfSelectedNodes(mySelection, aString) ;
384 myEditCurrentArgument->setText( aString );
391 buttonOk->setEnabled( true );
392 buttonApply->setEnabled( true );
396 //=================================================================================
397 // function : SetEditCurrentArgument()
399 //=================================================================================
400 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
402 QPushButton* send = (QPushButton*)sender();
403 switch (myConstructorId)
405 case 0: /* default constructor */
407 if(send == SelectButtonC1A1) {
408 LineEditC1A1->setFocus() ;
409 myEditCurrentArgument = LineEditC1A1;
411 SelectionIntoArgument() ;
418 //=================================================================================
419 // function : DeactivateActiveDialog()
421 //=================================================================================
422 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
424 if ( GroupConstructors->isEnabled() ) {
425 GroupConstructors->setEnabled(false) ;
426 GroupC1->setEnabled(false) ;
427 GroupButtons->setEnabled(false) ;
428 mySMESHGUI->ResetState() ;
429 mySMESHGUI->SetActiveDialogBox(0) ;
435 //=================================================================================
436 // function : ActivateThisDialog()
438 //=================================================================================
439 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
441 /* Emit a signal to deactivate the active dialog */
442 mySMESHGUI->EmitSignalDeactivateDialog() ;
443 GroupConstructors->setEnabled(true) ;
444 GroupC1->setEnabled(true) ;
445 GroupButtons->setEnabled(true) ;
447 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
449 SMESH::SetPointRepresentation(true);
450 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
452 SelectionIntoArgument();
456 //=================================================================================
457 // function : enterEvent()
459 //=================================================================================
460 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent* e)
462 if ( GroupConstructors->isEnabled() )
464 ActivateThisDialog() ;
469 //=================================================================================
470 // function : closeEvent()
472 //=================================================================================
473 void SMESHGUI_RemoveNodesDlg::closeEvent( QCloseEvent* e )
475 /* same than click on cancel button */
476 this->ClickOnCancel() ;
481 //=======================================================================
482 //function : hideEvent
483 //purpose : caused by ESC key
484 //=======================================================================
486 void SMESHGUI_RemoveNodesDlg::hideEvent ( QHideEvent * e )
488 if ( !isMinimized() )