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
30 #include "SMESHGUI_RemoveElementsDlg.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_MessageBox.h"
36 #include "utilities.h"
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
48 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : SMESHGUI_RemoveElementsDlg()
56 //=================================================================================
57 SMESHGUI_RemoveElementsDlg::SMESHGUI_RemoveElementsDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
58 bool modal, WFlags fl )
59 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
61 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_REM_ELEMENT")));
62 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
65 setName( "SMESHGUI_RemoveElementsDlg" );
67 setCaption( tr( "SMESH_REMOVE_ELEMENTS_TITLE" ) );
68 setSizeGripEnabled( TRUE );
69 SMESHGUI_RemoveElementsDlgLayout = new QGridLayout( this );
70 SMESHGUI_RemoveElementsDlgLayout->setSpacing( 6 );
71 SMESHGUI_RemoveElementsDlgLayout->setMargin( 11 );
73 /***************************************************************/
74 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
75 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS" ) );
76 GroupConstructors->setExclusive( TRUE );
77 GroupConstructors->setColumnLayout(0, Qt::Vertical );
78 GroupConstructors->layout()->setSpacing( 0 );
79 GroupConstructors->layout()->setMargin( 0 );
80 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
81 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
82 GroupConstructorsLayout->setSpacing( 6 );
83 GroupConstructorsLayout->setMargin( 11 );
84 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
85 Constructor1->setText( tr( "" ) );
86 Constructor1->setPixmap( image0 );
87 Constructor1->setChecked( TRUE );
88 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
89 Constructor1->setMinimumSize( QSize( 50, 0 ) );
90 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
91 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
92 GroupConstructorsLayout->addItem( spacer, 0, 1 );
93 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupConstructors, 0, 0 );
95 /***************************************************************/
96 GroupButtons = new QGroupBox( this, "GroupButtons" );
97 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
98 GroupButtons->setTitle( tr( "" ) );
99 GroupButtons->setColumnLayout(0, Qt::Vertical );
100 GroupButtons->layout()->setSpacing( 0 );
101 GroupButtons->layout()->setMargin( 0 );
102 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
103 GroupButtonsLayout->setAlignment( Qt::AlignTop );
104 GroupButtonsLayout->setSpacing( 6 );
105 GroupButtonsLayout->setMargin( 11 );
106 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
107 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
108 buttonCancel->setAutoDefault( TRUE );
109 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
110 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
111 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
112 buttonApply->setAutoDefault( TRUE );
113 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
114 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
115 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
116 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
117 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
118 buttonOk->setAutoDefault( TRUE );
119 buttonOk->setDefault( TRUE );
120 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
121 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupButtons, 2, 0 );
123 /***************************************************************/
124 GroupC1 = new QGroupBox( this, "GroupC1" );
125 GroupC1->setTitle( tr( "SMESH_REMOVE" ) );
126 GroupC1->setMinimumSize( QSize( 0, 0 ) );
127 GroupC1->setFrameShape( QGroupBox::Box );
128 GroupC1->setFrameShadow( QGroupBox::Sunken );
129 GroupC1->setColumnLayout(0, Qt::Vertical );
130 GroupC1->layout()->setSpacing( 0 );
131 GroupC1->layout()->setMargin( 0 );
132 GroupC1Layout = new QGridLayout( GroupC1->layout() );
133 GroupC1Layout->setAlignment( Qt::AlignTop );
134 GroupC1Layout->setSpacing( 6 );
135 GroupC1Layout->setMargin( 11 );
136 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
137 TextLabelC1A1->setText( tr( "SMESH_ID_ELEMENTS" ) );
138 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
139 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
140 TextLabelC1A1->setFrameShadow( QLabel::Plain );
141 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
142 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
143 SelectButtonC1A1->setText( tr( "" ) );
144 SelectButtonC1A1->setPixmap( image1 );
145 SelectButtonC1A1->setToggleButton( FALSE );
146 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
147 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
148 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
149 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupC1, 1, 0 );
151 Init(Sel) ; /* Initialisations */
154 //=================================================================================
155 // function : ~SMESHGUI_RemoveElementsDlg()
156 // purpose : Destroys the object and frees any allocated resources
157 //=================================================================================
158 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
160 // no need to delete child widgets, Qt does it all for us
164 //=================================================================================
167 //=================================================================================
168 void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
172 myConstructorId = 0 ;
173 Constructor1->setChecked( TRUE );
174 myEditCurrentArgument = LineEditC1A1 ;
176 this->myOkElements = false ;
177 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
178 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
180 /* signals and slots connections */
181 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
182 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
183 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
184 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
186 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
187 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
188 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
189 /* to close dialog if study change */
190 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
192 /* Move widget on the botton right corner of main widget */
194 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
196 this->show() ; /* displays Dialog */
202 //=================================================================================
203 // function : ConstructorsClicked()
204 // purpose : Radio button management
205 //=================================================================================
206 void SMESHGUI_RemoveElementsDlg::ConstructorsClicked(int constructorId)
212 //=================================================================================
213 // function : ClickOnApply()
215 //=================================================================================
216 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
218 switch(myConstructorId)
223 mySMESHGUI->RemoveElements( myMesh, myMapIndex ) ;
224 mySelection->ClearIObjects();
232 //=================================================================================
233 // function : ClickOnOk()
235 //=================================================================================
236 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
238 this->ClickOnApply() ;
239 this->ClickOnCancel() ;
244 //=================================================================================
245 // function : ClickOnCancel()
247 //=================================================================================
248 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
250 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
251 disconnect( mySelection, 0, this, 0 );
252 mySMESHGUI->ResetState() ;
258 //=================================================================================
259 // function : SelectionIntoArgument()
260 // purpose : Called when selection as changed or other case
261 //=================================================================================
262 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
264 myEditCurrentArgument->setText("") ;
265 myOkElements = false;
266 QString aString = "";
268 int nbSel = mySelection->IObjectCount();
272 int nbElements = mySMESHGUI->GetNameOfSelectedElements(mySelection, aString) ;
276 if ( mySelection->SelectionMode() != CellSelection ) {
277 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
278 tr ("SMESH_WRN_SELECTIONMODE_ELEMENTS"), tr ("SMESH_BUT_OK") );
282 myEditCurrentArgument->setText(aString) ;
283 Standard_Boolean res;
284 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
288 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
289 myOkElements = true ;
294 //=================================================================================
295 // function : SetEditCurrentArgument()
297 //=================================================================================
298 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
300 QPushButton* send = (QPushButton*)sender();
301 switch (myConstructorId)
303 case 0: /* default constructor */
305 if(send == SelectButtonC1A1) {
306 LineEditC1A1->setFocus() ;
307 myEditCurrentArgument = LineEditC1A1;
309 SelectionIntoArgument() ;
316 //=================================================================================
317 // function : DeactivateActiveDialog()
319 //=================================================================================
320 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
322 if ( GroupConstructors->isEnabled() ) {
323 GroupConstructors->setEnabled(false) ;
324 GroupC1->setEnabled(false) ;
325 GroupButtons->setEnabled(false) ;
331 //=================================================================================
332 // function : ActivateThisDialog()
334 //=================================================================================
335 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
337 /* Emit a signal to deactivate the active dialog */
338 mySMESHGUI->EmitSignalDeactivateDialog() ;
339 GroupConstructors->setEnabled(true) ;
340 GroupC1->setEnabled(true) ;
341 GroupButtons->setEnabled(true) ;
346 //=================================================================================
347 // function : enterEvent()
349 //=================================================================================
350 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent* e)
352 if ( GroupConstructors->isEnabled() )
354 ActivateThisDialog() ;
359 //=================================================================================
360 // function : closeEvent()
362 //=================================================================================
363 void SMESHGUI_RemoveElementsDlg::closeEvent( QCloseEvent* e )
365 /* same than click on cancel button */
366 this->ClickOnCancel() ;