Salome HOME
ae795cf64d5bbf84dcf977deb362d36255929069
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RemoveElementsDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_RemoveElementsDlg.cxx
3 //  Created   : Fri Jun 07 11:18:31 2002
4 //  Author    : Nicolas REJNERI
5
6 //  Project   : SALOME
7 //  Module    : SMESH
8 //  Copyright : Open CASCADE 2002
9 //  $Header$
10
11 #include "SMESHGUI_RemoveElementsDlg.h"
12
13 #include "SMESHGUI.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "QAD_MessageBox.h"
17 #include "utilities.h"
18
19 // QT Includes
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
22 #include <qlabel.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
26 #include <qlayout.h>
27 #include <qvariant.h>
28 #include <qtooltip.h>
29 #include <qwhatsthis.h>
30 #include <qimage.h>
31 #include <qpixmap.h>
32
33
34 //=================================================================================
35 // class    : SMESHGUI_RemoveElementsDlg()
36 // purpose  : 
37 //=================================================================================
38 SMESHGUI_RemoveElementsDlg::SMESHGUI_RemoveElementsDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
39                                                         bool modal, WFlags fl )
40     : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
41 {
42     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_REM_ELEMENT")));
43     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
44
45     if ( !name )
46         setName( "SMESHGUI_RemoveElementsDlg" );
47     resize( 303, 185 ); 
48     setCaption( tr( "SMESH_REMOVE_ELEMENTS_TITLE"  ) );
49     setSizeGripEnabled( TRUE );
50     SMESHGUI_RemoveElementsDlgLayout = new QGridLayout( this ); 
51     SMESHGUI_RemoveElementsDlgLayout->setSpacing( 6 );
52     SMESHGUI_RemoveElementsDlgLayout->setMargin( 11 );
53
54     /***************************************************************/
55     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
56     GroupConstructors->setTitle( tr( "SMESH_ELEMENTS"  ) );
57     GroupConstructors->setExclusive( TRUE );
58     GroupConstructors->setColumnLayout(0, Qt::Vertical );
59     GroupConstructors->layout()->setSpacing( 0 );
60     GroupConstructors->layout()->setMargin( 0 );
61     GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
62     GroupConstructorsLayout->setAlignment( Qt::AlignTop );
63     GroupConstructorsLayout->setSpacing( 6 );
64     GroupConstructorsLayout->setMargin( 11 );
65     Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
66     Constructor1->setText( tr( ""  ) );
67     Constructor1->setPixmap( image0 );
68     Constructor1->setChecked( TRUE );
69     Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
70     Constructor1->setMinimumSize( QSize( 50, 0 ) );
71     GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
72     QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
73     GroupConstructorsLayout->addItem( spacer, 0, 1 );
74     SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupConstructors, 0, 0 );
75     
76     /***************************************************************/
77     GroupButtons = new QGroupBox( this, "GroupButtons" );
78     GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
79     GroupButtons->setTitle( tr( ""  ) );
80     GroupButtons->setColumnLayout(0, Qt::Vertical );
81     GroupButtons->layout()->setSpacing( 0 );
82     GroupButtons->layout()->setMargin( 0 );
83     GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
84     GroupButtonsLayout->setAlignment( Qt::AlignTop );
85     GroupButtonsLayout->setSpacing( 6 );
86     GroupButtonsLayout->setMargin( 11 );
87     buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
88     buttonCancel->setText( tr( "SMESH_BUT_CLOSE"  ) );
89     buttonCancel->setAutoDefault( TRUE );
90     GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
91     buttonApply = new QPushButton( GroupButtons, "buttonApply" );
92     buttonApply->setText( tr( "SMESH_BUT_APPLY"  ) );
93     buttonApply->setAutoDefault( TRUE );
94     GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
95     QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
96     GroupButtonsLayout->addItem( spacer_9, 0, 2 );
97     buttonOk = new QPushButton( GroupButtons, "buttonOk" );
98     buttonOk->setText( tr( "SMESH_BUT_OK"  ) );
99     buttonOk->setAutoDefault( TRUE );
100     buttonOk->setDefault( TRUE );
101     GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
102     SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupButtons, 2, 0 );
103
104     /***************************************************************/
105     GroupC1 = new QGroupBox( this, "GroupC1" );
106     GroupC1->setTitle( tr( "SMESH_REMOVE"  ) );
107     GroupC1->setMinimumSize( QSize( 0, 0 ) );
108     GroupC1->setFrameShape( QGroupBox::Box );
109     GroupC1->setFrameShadow( QGroupBox::Sunken );
110     GroupC1->setColumnLayout(0, Qt::Vertical );
111     GroupC1->layout()->setSpacing( 0 );
112     GroupC1->layout()->setMargin( 0 );
113     GroupC1Layout = new QGridLayout( GroupC1->layout() );
114     GroupC1Layout->setAlignment( Qt::AlignTop );
115     GroupC1Layout->setSpacing( 6 );
116     GroupC1Layout->setMargin( 11 );
117     TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
118     TextLabelC1A1->setText( tr( "SMESH_ID_ELEMENTS"  ) );
119     TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
120     TextLabelC1A1->setFrameShape( QLabel::NoFrame );
121     TextLabelC1A1->setFrameShadow( QLabel::Plain );
122     GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
123     SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
124     SelectButtonC1A1->setText( tr( ""  ) );
125     SelectButtonC1A1->setPixmap( image1 );
126     SelectButtonC1A1->setToggleButton( FALSE );
127     GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
128     LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
129     GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
130     SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupC1, 1, 0 );
131
132     Init(Sel) ; /* Initialisations */
133 }
134
135 //=================================================================================
136 // function : ~SMESHGUI_RemoveElementsDlg()
137 // purpose  : Destroys the object and frees any allocated resources
138 //=================================================================================
139 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
140 {
141     // no need to delete child widgets, Qt does it all for us
142 }
143
144
145 //=================================================================================
146 // function : Init()
147 // purpose  :
148 //=================================================================================
149 void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
150 {
151
152   GroupC1->show();
153   myConstructorId = 0 ;
154   Constructor1->setChecked( TRUE );
155   myEditCurrentArgument = LineEditC1A1 ;        
156   mySelection = Sel;  
157   this->myOkElements = false ;
158   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
159   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
160
161   /* signals and slots connections */
162   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
163   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
164   connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
165   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
166
167   connect( SelectButtonC1A1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
168   connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
169   connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
170   /* to close dialog if study change */
171   connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
172
173   /* Move widget on the botton right corner of main widget */
174   int x, y ;
175   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
176   this->move( x, y ) ;
177   this->show() ; /* displays Dialog */
178
179   return ;
180 }
181
182
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose  : Radio button management
186 //=================================================================================
187 void SMESHGUI_RemoveElementsDlg::ConstructorsClicked(int constructorId)
188 {
189   return ;
190 }
191
192
193 //=================================================================================
194 // function : ClickOnApply()
195 // purpose  :
196 //=================================================================================
197 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
198 {
199   switch(myConstructorId)
200     { 
201     case 0 :
202       { 
203         if(myOkElements) {        
204           mySMESHGUI->RemoveElements( myMesh, myMapIndex ) ;
205           mySelection->ClearIObjects();
206         }
207         break ;
208       }
209     }
210   return ;
211 }
212
213 //=================================================================================
214 // function : ClickOnOk()
215 // purpose  :
216 //=================================================================================
217 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
218 {
219   this->ClickOnApply() ;
220   this->ClickOnCancel() ;
221
222   return ;
223 }
224
225 //=================================================================================
226 // function : ClickOnCancel()
227 // purpose  :
228 //=================================================================================
229 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
230 {
231   QAD_Application::getDesktop()->SetSelectionMode( 4 );
232   disconnect( mySelection, 0, this, 0 );
233   mySMESHGUI->ResetState() ;
234   reject() ;
235   return ;
236 }
237
238
239 //=================================================================================
240 // function : SelectionIntoArgument()
241 // purpose  : Called when selection as changed or other case
242 //=================================================================================
243 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
244 {
245   myEditCurrentArgument->setText("") ;
246   myOkElements = false;
247   QString aString = "";
248
249   int nbSel = mySelection->IObjectCount();
250   if(nbSel != 1)
251     return;
252
253   int nbElements = mySMESHGUI->GetNameOfSelectedElements(mySelection, aString) ;
254   if(nbElements < 1)
255     return ;
256   
257   if ( mySelection->SelectionMode() != 3 ) {
258     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
259                             tr ("SMESH_WRN_SELECTIONMODE_ELEMENTS"), tr ("SMESH_BUT_YES") );
260     return;
261   }
262
263   myEditCurrentArgument->setText(aString) ;
264   Standard_Boolean res;
265   myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
266   if (!res)
267     return ;
268
269   mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
270   myOkElements = true ;
271   return ;
272 }
273
274
275 //=================================================================================
276 // function : SetEditCurrentArgument()
277 // purpose  :
278 //=================================================================================
279 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
280 {
281   QPushButton* send = (QPushButton*)sender();
282   switch (myConstructorId)
283     {
284     case 0: /* default constructor */
285       { 
286         if(send == SelectButtonC1A1) {
287           LineEditC1A1->setFocus() ;
288           myEditCurrentArgument = LineEditC1A1;
289         }
290         SelectionIntoArgument() ;
291         break;
292       }
293     }
294   return ;
295 }
296
297 //=================================================================================
298 // function : DeactivateActiveDialog()
299 // purpose  :
300 //=================================================================================
301 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
302 {
303   if ( GroupConstructors->isEnabled() ) {
304     GroupConstructors->setEnabled(false) ;
305     GroupC1->setEnabled(false) ;
306     GroupButtons->setEnabled(false) ;
307   }
308   return ;
309 }
310
311
312 //=================================================================================
313 // function : ActivateThisDialog()
314 // purpose  :
315 //=================================================================================
316 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
317 {
318   /* Emit a signal to deactivate the active dialog */
319   mySMESHGUI->EmitSignalDeactivateDialog() ;   
320   GroupConstructors->setEnabled(true) ;
321   GroupC1->setEnabled(true) ;
322   GroupButtons->setEnabled(true) ;
323   return ;
324 }
325
326
327 //=================================================================================
328 // function : enterEvent()
329 // purpose  :
330 //=================================================================================
331 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent* e)
332 {
333   if ( GroupConstructors->isEnabled() )
334     return ;  
335   ActivateThisDialog() ;
336   return ;
337 }
338
339
340 //=================================================================================
341 // function : closeEvent()
342 // purpose  :
343 //=================================================================================
344 void SMESHGUI_RemoveElementsDlg::closeEvent( QCloseEvent* e )
345 {
346   /* same than click on cancel button */
347   this->ClickOnCancel() ;
348   return ;
349 }
350
351