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