Salome HOME
Remove OCC_LIBS from LDFLAGS
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_RemoveNodesDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_RemoveNodesDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESHGUI_RemoveNodesDlg.h"
31
32 #include "SMESHGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_MessageBox.h"
36 #include "utilities.h"
37
38 // QT Includes
39 #include <qbuttongroup.h>
40 #include <qgroupbox.h>
41 #include <qlabel.h>
42 #include <qlineedit.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qlayout.h>
46 #include <qvariant.h>
47 #include <qtooltip.h>
48 #include <qwhatsthis.h>
49 #include <qimage.h>
50 #include <qpixmap.h>
51
52
53 //=================================================================================
54 // class    : SMESHGUI_RemoveNodesDlg()
55 // purpose  : 
56 //=================================================================================
57 SMESHGUI_RemoveNodesDlg::SMESHGUI_RemoveNodesDlg( 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 )
60 {
61     QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_REM_NODE")));
62     QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
63
64     if ( !name )
65         setName( "SMESHGUI_RemoveNodesDlg" );
66     resize( 303, 185 ); 
67     setCaption( tr( "SMESH_REMOVE_NODES_TITLE"  ) );
68     setSizeGripEnabled( TRUE );
69     SMESHGUI_RemoveNodesDlgLayout = new QGridLayout( this ); 
70     SMESHGUI_RemoveNodesDlgLayout->setSpacing( 6 );
71     SMESHGUI_RemoveNodesDlgLayout->setMargin( 11 );
72
73     /***************************************************************/
74     GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
75     GroupConstructors->setTitle( tr( "SMESH_NODES"  ) );
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_RemoveNodesDlgLayout->addWidget( GroupConstructors, 0, 0 );
94     
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_RemoveNodesDlgLayout->addWidget( GroupButtons, 2, 0 );
122
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_NODES"  ) );
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_RemoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
150
151     Init(Sel) ; /* Initialisations */
152 }
153
154 //=================================================================================
155 // function : ~SMESHGUI_RemoveNodesDlg()
156 // purpose  : Destroys the object and frees any allocated resources
157 //=================================================================================
158 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
159 {
160     // no need to delete child widgets, Qt does it all for us
161 }
162
163
164 //=================================================================================
165 // function : Init()
166 // purpose  :
167 //=================================================================================
168 void SMESHGUI_RemoveNodesDlg::Init( SALOME_Selection* Sel )
169 {
170
171   GroupC1->show();
172   myConstructorId = 0 ;
173   Constructor1->setChecked( TRUE );
174   myEditCurrentArgument = LineEditC1A1 ;        
175   mySelection = Sel;  
176   this->myOkNodes = false ;
177   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
178   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
179
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) ) );
185
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() ) ) ;
191
192   /* Move widget on the botton right corner of main widget */
193   int x, y ;
194   mySMESHGUI->DefineDlgPosition( this, x, y ) ;
195   this->move( x, y ) ;
196   this->show() ; /* displays Dialog */
197
198   SelectionIntoArgument();
199   return ;
200 }
201
202
203 //=================================================================================
204 // function : ConstructorsClicked()
205 // purpose  : Radio button management
206 //=================================================================================
207 void SMESHGUI_RemoveNodesDlg::ConstructorsClicked(int constructorId)
208 {
209   return ;
210 }
211
212
213 //=================================================================================
214 // function : ClickOnApply()
215 // purpose  :
216 //=================================================================================
217 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
218 {
219   switch(myConstructorId)
220     { 
221     case 0 :
222       { 
223         if(myOkNodes) {   
224           mySMESHGUI->EraseSimulationActors();
225           mySMESHGUI->RemoveNodes( myMesh, myMapIndex ) ;
226           mySMESHGUI->ViewNodes();
227           mySelection->ClearIObjects();
228         }
229         break ;
230       }
231     }
232   return ;
233 }
234
235 //=================================================================================
236 // function : ClickOnOk()
237 // purpose  :
238 //=================================================================================
239 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
240 {
241   this->ClickOnApply() ;
242   this->ClickOnCancel() ;
243
244   return ;
245 }
246
247         
248 //=================================================================================
249 // function : ClickOnCancel()
250 // purpose  :
251 //=================================================================================
252 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
253 {
254   QAD_Application::getDesktop()->SetSelectionMode( 4 );
255   disconnect( mySelection, 0, this, 0 );
256   mySMESHGUI->ResetState() ;
257   mySMESHGUI->EraseSimulationActors();
258   reject() ;
259   return ;
260 }
261
262
263 //=================================================================================
264 // function : SelectionIntoArgument()
265 // purpose  : Called when selection as changed or other case
266 //=================================================================================
267 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
268 {
269   myEditCurrentArgument->setText("") ;
270   myOkNodes = false;
271   QString aString = "";
272
273   int nbSel = mySelection->IObjectCount();
274   if(nbSel != 1)
275     return ;
276
277   int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
278   if(nbNodes < 1)
279     return ;
280   
281   if ( mySelection->SelectionMode() != 1 ){
282     QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
283                             tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
284     return;
285   }
286
287   myEditCurrentArgument->setText(aString) ;
288   Standard_Boolean res;
289   myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
290   if (!res)
291     return ;
292
293   mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
294
295   myOkNodes = true ;
296   return ;
297 }
298
299
300 //=================================================================================
301 // function : SetEditCurrentArgument()
302 // purpose  :
303 //=================================================================================
304 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
305 {
306   QPushButton* send = (QPushButton*)sender();
307   switch (myConstructorId)
308     {
309     case 0: /* default constructor */
310       { 
311         if(send == SelectButtonC1A1) {
312           LineEditC1A1->setFocus() ;
313           myEditCurrentArgument = LineEditC1A1;
314         }
315         SelectionIntoArgument() ;
316         break;
317       }
318     }
319   return ;
320 }
321
322 //=================================================================================
323 // function : DeactivateActiveDialog()
324 // purpose  :
325 //=================================================================================
326 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
327 {
328   if ( GroupConstructors->isEnabled() ) {
329     GroupConstructors->setEnabled(false) ;
330     GroupC1->setEnabled(false) ;
331     GroupButtons->setEnabled(false) ;
332     mySMESHGUI->EraseSimulationActors() ;
333     mySMESHGUI->ResetState() ;    
334     mySMESHGUI->SetActiveDialogBox(0) ;
335   }
336   return ;
337 }
338
339
340 //=================================================================================
341 // function : ActivateThisDialog()
342 // purpose  :
343 //=================================================================================
344 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
345 {
346   /* Emit a signal to deactivate the active dialog */
347   mySMESHGUI->EmitSignalDeactivateDialog() ;   
348   GroupConstructors->setEnabled(true) ;
349   GroupC1->setEnabled(true) ;
350   GroupButtons->setEnabled(true) ;
351   
352   mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
353   return ;
354 }
355
356
357 //=================================================================================
358 // function : enterEvent()
359 // purpose  :
360 //=================================================================================
361 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent* e)
362 {
363   if ( GroupConstructors->isEnabled() )
364     return ;  
365   ActivateThisDialog() ;
366   return ;
367 }
368
369
370 //=================================================================================
371 // function : closeEvent()
372 // purpose  :
373 //=================================================================================
374 void SMESHGUI_RemoveNodesDlg::closeEvent( QCloseEvent* e )
375 {
376   /* same than click on cancel button */
377   this->ClickOnCancel() ;
378   return ;
379 }
380
381