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_RemoveElementsDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_RemoveElementsDlg.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_RemoveElementsDlg()
63 //=================================================================================
64 SMESHGUI_RemoveElementsDlg::SMESHGUI_RemoveElementsDlg( 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 )
68 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_REM_ELEMENT")));
69 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
72 setName( "SMESHGUI_RemoveElementsDlg" );
74 setCaption( tr( "SMESH_REMOVE_ELEMENTS_TITLE" ) );
75 setSizeGripEnabled( TRUE );
76 SMESHGUI_RemoveElementsDlgLayout = new QGridLayout( this );
77 SMESHGUI_RemoveElementsDlgLayout->setSpacing( 6 );
78 SMESHGUI_RemoveElementsDlgLayout->setMargin( 11 );
80 /***************************************************************/
81 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
82 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS" ) );
83 GroupConstructors->setExclusive( TRUE );
84 GroupConstructors->setColumnLayout(0, Qt::Vertical );
85 GroupConstructors->layout()->setSpacing( 0 );
86 GroupConstructors->layout()->setMargin( 0 );
87 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
88 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
89 GroupConstructorsLayout->setSpacing( 6 );
90 GroupConstructorsLayout->setMargin( 11 );
91 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
92 Constructor1->setText( tr( "" ) );
93 Constructor1->setPixmap( image0 );
94 Constructor1->setChecked( TRUE );
95 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
96 Constructor1->setMinimumSize( QSize( 50, 0 ) );
97 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
98 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
99 GroupConstructorsLayout->addItem( spacer, 0, 1 );
100 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupConstructors, 0, 0 );
102 /***************************************************************/
103 GroupButtons = new QGroupBox( this, "GroupButtons" );
104 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
105 GroupButtons->setTitle( tr( "" ) );
106 GroupButtons->setColumnLayout(0, Qt::Vertical );
107 GroupButtons->layout()->setSpacing( 0 );
108 GroupButtons->layout()->setMargin( 0 );
109 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
110 GroupButtonsLayout->setAlignment( Qt::AlignTop );
111 GroupButtonsLayout->setSpacing( 6 );
112 GroupButtonsLayout->setMargin( 11 );
113 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
114 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
115 buttonCancel->setAutoDefault( TRUE );
116 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
117 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
118 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
119 buttonApply->setAutoDefault( TRUE );
120 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
121 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
122 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
123 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
124 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
125 buttonOk->setAutoDefault( TRUE );
126 buttonOk->setDefault( TRUE );
127 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
128 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupButtons, 2, 0 );
130 /***************************************************************/
131 GroupC1 = new QGroupBox( this, "GroupC1" );
132 GroupC1->setTitle( tr( "SMESH_REMOVE" ) );
133 GroupC1->setMinimumSize( QSize( 0, 0 ) );
134 GroupC1->setFrameShape( QGroupBox::Box );
135 GroupC1->setFrameShadow( QGroupBox::Sunken );
136 GroupC1->setColumnLayout(0, Qt::Vertical );
137 GroupC1->layout()->setSpacing( 0 );
138 GroupC1->layout()->setMargin( 0 );
139 GroupC1Layout = new QGridLayout( GroupC1->layout() );
140 GroupC1Layout->setAlignment( Qt::AlignTop );
141 GroupC1Layout->setSpacing( 6 );
142 GroupC1Layout->setMargin( 11 );
143 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
144 TextLabelC1A1->setText( tr( "SMESH_ID_ELEMENTS" ) );
145 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
146 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
147 TextLabelC1A1->setFrameShadow( QLabel::Plain );
148 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
149 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
150 SelectButtonC1A1->setText( tr( "" ) );
151 SelectButtonC1A1->setPixmap( image1 );
152 SelectButtonC1A1->setToggleButton( FALSE );
153 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
154 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
155 LineEditC1A1->setValidator( new SMESHGUI_IdValidator( this, "validator" ));
156 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
157 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupC1, 1, 0 );
159 Init(Sel) ; /* Initialisations */
162 //=================================================================================
163 // function : ~SMESHGUI_RemoveElementsDlg()
164 // purpose : Destroys the object and frees any allocated resources
165 //=================================================================================
166 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
168 // no need to delete child widgets, Qt does it all for us
172 //=================================================================================
175 //=================================================================================
176 void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
180 myConstructorId = 0 ;
181 Constructor1->setChecked( TRUE );
182 myEditCurrentArgument = LineEditC1A1 ;
185 myNbOkElements = false ;
186 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
187 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
191 /* signals and slots connections */
192 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
193 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
194 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
195 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
197 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
198 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
199 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
200 /* to close dialog if study change */
201 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
202 connect( myEditCurrentArgument, SIGNAL( textChanged( const QString& )),
203 SLOT( onTextChange( const QString& )));
205 /* Move widget on the botton right corner of main widget */
207 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
209 this->show() ; /* displays Dialog */
211 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
213 SelectionIntoArgument();
217 //=================================================================================
218 // function : ConstructorsClicked()
219 // purpose : Radio button management
220 //=================================================================================
221 void SMESHGUI_RemoveElementsDlg::ConstructorsClicked(int constructorId)
227 //=================================================================================
228 // function : ClickOnApply()
230 //=================================================================================
231 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
233 if (mySMESHGUI->ActiveStudyLocked())
235 if ( myNbOkElements ) {
236 QStringList aListId = QStringList::split( " ", myEditCurrentArgument->text(), false);
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;
245 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
246 aResult = aMeshEditor->RemoveElements(anArrayOfIdeces.inout()) ;
254 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
255 mySelection->ClearIObjects();
257 mySelection->AddIObject( anIO, false );
262 //=================================================================================
263 // function : ClickOnOk()
265 //=================================================================================
266 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
268 this->ClickOnApply() ;
269 this->ClickOnCancel() ;
274 //=================================================================================
275 // function : ClickOnCancel()
277 //=================================================================================
278 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
280 mySelection->ClearIObjects();
281 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
282 disconnect( mySelection, 0, this, 0 );
283 mySMESHGUI->ResetState() ;
289 //=======================================================================
290 //function : onTextChange
292 //=======================================================================
294 void SMESHGUI_RemoveElementsDlg::onTextChange(const QString& theNewText)
296 if ( myBusy ) return;
301 buttonOk->setEnabled( false );
302 buttonApply->setEnabled( false );
304 // hilight entered elements
305 SMDS_Mesh* aMesh = 0;
307 aMesh = myActor->GetObject()->GetMesh();
310 mySelection->ClearIObjects();
311 mySelection->AddIObject( myActor->getIO() );
313 QStringList aListId = QStringList::split( " ", theNewText, false);
314 for ( int i = 0; i < aListId.count(); i++ ) {
315 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
317 if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
318 mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
323 if ( myNbOkElements ) {
324 buttonOk->setEnabled( true );
325 buttonApply->setEnabled( true );
332 //=================================================================================
333 // function : SelectionIntoArgument()
334 // purpose : Called when selection as changed or other case
335 //=================================================================================
336 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
338 if ( myBusy ) return;
342 myNbOkElements = false;
346 myEditCurrentArgument->setText( "" );
349 if ( !GroupButtons->isEnabled() ) // inactive
352 buttonOk->setEnabled( false );
353 buttonApply->setEnabled( false );
357 int nbSel = mySelection->IObjectCount();
361 myMesh = SMESH::GetMeshByIO( mySelection->firstIObject() );
362 if ( myMesh->_is_nil() )
365 myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
369 // get selected nodes
371 QString aString = "";
372 int nbElems = SMESH::GetNameOfSelectedElements(mySelection, aString) ;
376 myEditCurrentArgument->setText( aString );
381 myNbOkElements = nbElems;
383 buttonOk->setEnabled( true );
384 buttonApply->setEnabled( true );
388 //=================================================================================
389 // function : SetEditCurrentArgument()
391 //=================================================================================
392 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
394 QPushButton* send = (QPushButton*)sender();
395 switch (myConstructorId)
397 case 0: /* default constructor */
399 if(send == SelectButtonC1A1) {
400 LineEditC1A1->setFocus() ;
401 myEditCurrentArgument = LineEditC1A1;
403 SelectionIntoArgument() ;
410 //=================================================================================
411 // function : DeactivateActiveDialog()
413 //=================================================================================
414 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
416 if ( GroupConstructors->isEnabled() ) {
417 GroupConstructors->setEnabled(false) ;
418 GroupC1->setEnabled(false) ;
419 GroupButtons->setEnabled(false) ;
425 //=================================================================================
426 // function : ActivateThisDialog()
428 //=================================================================================
429 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
431 /* Emit a signal to deactivate the active dialog */
432 mySMESHGUI->EmitSignalDeactivateDialog() ;
434 GroupConstructors->setEnabled(true) ;
435 GroupC1->setEnabled(true) ;
436 GroupButtons->setEnabled(true) ;
438 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
442 //=================================================================================
443 // function : enterEvent()
445 //=================================================================================
446 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent* e)
448 if ( !GroupConstructors->isEnabled() )
449 ActivateThisDialog() ;
453 //=================================================================================
454 // function : closeEvent()
456 //=================================================================================
457 void SMESHGUI_RemoveElementsDlg::closeEvent( QCloseEvent* e )
459 /* same than click on cancel button */
460 this->ClickOnCancel() ;
464 //=======================================================================
465 //function : hideEvent
466 //purpose : caused by ESC key
467 //=======================================================================
469 void SMESHGUI_RemoveElementsDlg::hideEvent ( QHideEvent * e )
471 if ( !isMinimized() )