Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RemoveNodesDlg.cxx
1 using namespace std;
2 //  File      : SMESHGUI_RemoveNodesDlg.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_RemoveNodesDlg.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_RemoveNodesDlg()
36 // purpose  : 
37 //=================================================================================
38 SMESHGUI_RemoveNodesDlg::SMESHGUI_RemoveNodesDlg( 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( "SMESHGUI",tr("ICON_DLG_REM_NODE")));
43     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESHGUI",tr("ICON_SELECT")));
44
45     if ( !name )
46         setName( "SMESHGUI_RemoveNodesDlg" );
47     resize( 303, 185 ); 
48     setCaption( tr( "SMESH_REMOVE_NODES_TITLE"  ) );
49     setSizeGripEnabled( TRUE );
50     SMESHGUI_RemoveNodesDlgLayout = new QGridLayout( this ); 
51     SMESHGUI_RemoveNodesDlgLayout->setSpacing( 6 );
52     SMESHGUI_RemoveNodesDlgLayout->setMargin( 11 );
53
54     /***************************************************************/
55     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
56     GroupConstructors->setTitle( tr( "SMESH_NODES"  ) );
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_RemoveNodesDlgLayout->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_RemoveNodesDlgLayout->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_NODES"  ) );
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_RemoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
131
132     Init(Sel) ; /* Initialisations */
133 }
134
135 //=================================================================================
136 // function : ~SMESHGUI_RemoveNodesDlg()
137 // purpose  : Destroys the object and frees any allocated resources
138 //=================================================================================
139 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
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_RemoveNodesDlg::Init( SALOME_Selection* Sel )
150 {
151
152   GroupC1->show();
153   myConstructorId = 0 ;
154   Constructor1->setChecked( TRUE );
155   myEditCurrentArgument = LineEditC1A1 ;        
156   mySelection = Sel;  
157   this->myOkNodes = 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   SelectionIntoArgument();
180   return ;
181 }
182
183
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose  : Radio button management
187 //=================================================================================
188 void SMESHGUI_RemoveNodesDlg::ConstructorsClicked(int constructorId)
189 {
190   return ;
191 }
192
193
194 //=================================================================================
195 // function : ClickOnApply()
196 // purpose  :
197 //=================================================================================
198 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
199 {
200   switch(myConstructorId)
201     { 
202     case 0 :
203       { 
204         if(myOkNodes) {   
205           mySMESHGUI->EraseSimulationActors();
206           mySMESHGUI->RemoveNodes( myMesh, myMapIndex ) ;
207           mySMESHGUI->ViewNodes();
208           mySelection->ClearIObjects();
209         }
210         break ;
211       }
212     }
213   return ;
214 }
215
216 //=================================================================================
217 // function : ClickOnOk()
218 // purpose  :
219 //=================================================================================
220 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
221 {
222   this->ClickOnApply() ;
223   this->ClickOnCancel() ;
224
225   return ;
226 }
227
228         
229 //=================================================================================
230 // function : ClickOnCancel()
231 // purpose  :
232 //=================================================================================
233 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
234 {
235   QAD_Application::getDesktop()->SetSelectionMode( 4 );
236   disconnect( mySelection, 0, this, 0 );
237   mySMESHGUI->ResetState() ;
238   mySMESHGUI->EraseSimulationActors();
239   reject() ;
240   return ;
241 }
242
243
244 //=================================================================================
245 // function : SelectionIntoArgument()
246 // purpose  : Called when selection as changed or other case
247 //=================================================================================
248 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
249 {
250   myEditCurrentArgument->setText("") ;
251   myOkNodes = false;
252   QString aString = "";
253
254   int nbSel = mySelection->IObjectCount();
255   if(nbSel != 1)
256     return ;
257
258   int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
259   if(nbNodes < 1)
260     return ;
261   
262   if ( mySelection->SelectionMode() != 1 ){
263     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
264                             tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
265     return;
266   }
267
268   myEditCurrentArgument->setText(aString) ;
269   Standard_Boolean res;
270   myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
271   if (!res)
272     return ;
273
274   mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
275
276   myOkNodes = true ;
277   return ;
278 }
279
280
281 //=================================================================================
282 // function : SetEditCurrentArgument()
283 // purpose  :
284 //=================================================================================
285 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
286 {
287   QPushButton* send = (QPushButton*)sender();
288   switch (myConstructorId)
289     {
290     case 0: /* default constructor */
291       { 
292         if(send == SelectButtonC1A1) {
293           LineEditC1A1->setFocus() ;
294           myEditCurrentArgument = LineEditC1A1;
295         }
296         SelectionIntoArgument() ;
297         break;
298       }
299     }
300   return ;
301 }
302
303 //=================================================================================
304 // function : DeactivateActiveDialog()
305 // purpose  :
306 //=================================================================================
307 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
308 {
309   if ( GroupConstructors->isEnabled() ) {
310     GroupConstructors->setEnabled(false) ;
311     GroupC1->setEnabled(false) ;
312     GroupButtons->setEnabled(false) ;
313     mySMESHGUI->EraseSimulationActors() ;
314     mySMESHGUI->ResetState() ;    
315     mySMESHGUI->SetActiveDialogBox(0) ;
316   }
317   return ;
318 }
319
320
321 //=================================================================================
322 // function : ActivateThisDialog()
323 // purpose  :
324 //=================================================================================
325 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
326 {
327   /* Emit a signal to deactivate the active dialog */
328   mySMESHGUI->EmitSignalDeactivateDialog() ;   
329   GroupConstructors->setEnabled(true) ;
330   GroupC1->setEnabled(true) ;
331   GroupButtons->setEnabled(true) ;
332   
333   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
334   return ;
335 }
336
337
338 //=================================================================================
339 // function : enterEvent()
340 // purpose  :
341 //=================================================================================
342 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent* e)
343 {
344   if ( GroupConstructors->isEnabled() )
345     return ;  
346   ActivateThisDialog() ;
347   return ;
348 }
349
350
351 //=================================================================================
352 // function : closeEvent()
353 // purpose  :
354 //=================================================================================
355 void SMESHGUI_RemoveNodesDlg::closeEvent( QCloseEvent* e )
356 {
357   /* same than click on cancel button */
358   this->ClickOnCancel() ;
359   return ;
360 }
361
362