Salome HOME
sources v1.2c
[modules/geom.git] / src / GEOMGUI / GeometryGUI_ArchimedeDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry 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   : GeometryGUI_ArchimedeDlg.cxx
25 //  Author : Nicolas REJNERI 
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "GeometryGUI_ArchimedeDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Tools.h"
36 #include "utilities.h"
37
38 #include "SALOME_InteractiveObject.hxx"
39
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
42 #include <qlabel.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
46 #include <qlayout.h>
47 #include <qvariant.h>
48 #include <qtooltip.h>
49 #include <qvalidator.h>
50 #include <qwhatsthis.h>
51 #include <qimage.h>
52 #include <qpixmap.h>
53
54 //=================================================================================
55 // class    : GeometryGUI_ArchimedeDlg()
56 // purpose  : Constructs a GeometryGUI_ArchimedeDlg which is a child of 'parent', with the 
57 //            name 'name' and widget flags set to 'f'.
58 //            The dialog will by default be modeless, unless you set 'modal' to
59 //            TRUE to construct a modal dialog.
60 //=================================================================================
61 GeometryGUI_ArchimedeDlg::GeometryGUI_ArchimedeDlg( QWidget* parent,  const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
62   : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 {
64   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_ARCHIMEDE")));
65   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
66   
67   if ( !name )
68     setName( "GeometryGUI_ArchimedeDlg" );
69   resize( 303, 219 ); 
70   setCaption( tr( "GEOM_ARCHIMEDE_TITLE"  ) );
71   setSizeGripEnabled( TRUE );
72   GeometryGUI_ArchimedeDlgLayout = new QGridLayout( this ); 
73   GeometryGUI_ArchimedeDlgLayout->setSpacing( 6 );
74   GeometryGUI_ArchimedeDlgLayout->setMargin( 11 );
75   
76   /***************************************************************/
77   GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78   GroupConstructors->setTitle( tr( "GEOM_ARCHIMEDE"  ) );
79   GroupConstructors->setExclusive( TRUE );
80   GroupConstructors->setColumnLayout(0, Qt::Vertical );
81   GroupConstructors->layout()->setSpacing( 0 );
82   GroupConstructors->layout()->setMargin( 0 );
83   GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
84   GroupConstructorsLayout->setAlignment( Qt::AlignTop );
85   GroupConstructorsLayout->setSpacing( 6 );
86   GroupConstructorsLayout->setMargin( 11 );
87   Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
88   Constructor1->setText( tr( ""  ) );
89   Constructor1->setPixmap( image0 );
90   Constructor1->setChecked( TRUE );
91   Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
92   Constructor1->setMinimumSize( QSize( 50, 0 ) );
93   GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94   QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
95   GroupConstructorsLayout->addItem( spacer, 0, 1 );
96   GeometryGUI_ArchimedeDlgLayout->addWidget( GroupConstructors, 0, 0 );
97
98   /***************************************************************/
99   GroupButtons = new QGroupBox( this, "GroupButtons" );
100   GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) ); 
101   GroupButtons->setTitle( tr( ""  ) );
102   GroupButtons->setColumnLayout(0, Qt::Vertical );
103   GroupButtons->layout()->setSpacing( 0 );
104   GroupButtons->layout()->setMargin( 0 );
105   GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
106   GroupButtonsLayout->setAlignment( Qt::AlignTop );
107   GroupButtonsLayout->setSpacing( 6 );
108   GroupButtonsLayout->setMargin( 11 );
109   buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
110   buttonCancel->setText( tr( "GEOM_BUT_CLOSE"  ) );
111   buttonCancel->setAutoDefault( TRUE );
112   GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
113   buttonApply = new QPushButton( GroupButtons, "buttonApply" );
114   buttonApply->setText( tr( "GEOM_BUT_APPLY"  ) );
115   buttonApply->setAutoDefault( TRUE );
116   GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
117   QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
118   GroupButtonsLayout->addItem( spacer_1, 0, 2 );
119   buttonOk = new QPushButton( GroupButtons, "buttonOk" );
120   buttonOk->setText( tr( "GEOM_BUT_OK"  ) );
121   buttonOk->setAutoDefault( TRUE );
122   buttonOk->setDefault( TRUE );
123   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
124   GeometryGUI_ArchimedeDlgLayout->addWidget( GroupButtons, 2, 0 );
125   
126   GroupC1 = new QGroupBox( this, "GroupC1" );
127   GroupC1->setTitle( tr( "GEOM_ARGUMENTS"  ) );
128   GroupC1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupC1->sizePolicy().hasHeightForWidth() ) );
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   LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
137   GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
138   
139   LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
140   LineEditC1A2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2->sizePolicy().hasHeightForWidth() ) );
141   LineEditC1A2->setMinimumSize( QSize( 40, 0 ) );
142   LineEditC1A2->setMaximumSize( QSize( 32767, 32767 ) );
143   GroupC1Layout->addWidget( LineEditC1A2, 1,  2 );
144   
145   LineEditC1A3 = new QLineEdit( GroupC1, "LineEditC1A3" );
146   LineEditC1A3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A3->sizePolicy().hasHeightForWidth() ) );
147   LineEditC1A3->setMinimumSize( QSize( 40, 0 ) );
148   LineEditC1A3->setMaximumSize( QSize( 32767, 32767 ) );
149   GroupC1Layout->addWidget( LineEditC1A3, 2, 2 );
150   
151   LineEditC1A4 = new QLineEdit( GroupC1, "LineEditC1A4" );
152   LineEditC1A4->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A4->sizePolicy().hasHeightForWidth() ) );
153   LineEditC1A4->setMinimumSize( QSize( 40, 0 ) );
154   LineEditC1A4->setMaximumSize( QSize( 32767, 32767 ) );
155   GroupC1Layout->addWidget( LineEditC1A4, 3, 2 );
156   
157   SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
158   SelectButtonC1A1->setText( tr( ""  ) );
159   SelectButtonC1A1->setPixmap( image1 );
160   GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
161   TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
162   TextLabelC1A1->setText( tr( "GEOM_OBJECTS"  ) );
163   TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
164   TextLabelC1A1->setFrameShape( QLabel::NoFrame );
165   TextLabelC1A1->setFrameShadow( QLabel::Plain );
166   GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
167   
168   TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
169   TextLabelC1A2->setText( tr( "GEOM_WEIGHT"  ) );
170   TextLabelC1A2->setMinimumSize( QSize( 50, 0 ) );
171   TextLabelC1A2->setFrameShape( QLabel::NoFrame );
172   TextLabelC1A2->setFrameShadow( QLabel::Plain );
173   GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
174   
175   TextLabelC1A3 = new QLabel( GroupC1, "TextLabelC1A3" );
176   TextLabelC1A3->setText( tr( "GEOM_WATER_DENSITY"  ) );
177   TextLabelC1A3->setMinimumSize( QSize( 50, 0 ) );
178   TextLabelC1A3->setFrameShape( QLabel::NoFrame );
179   TextLabelC1A3->setFrameShadow( QLabel::Plain );
180   GroupC1Layout->addWidget( TextLabelC1A3, 2, 0 );
181   
182   TextLabelC1A4 = new QLabel( GroupC1, "TextLabelC1A4" );
183   TextLabelC1A4->setText( tr( "GEOM_MESHING_DEFLECTION"  ) );
184   TextLabelC1A4->setMinimumSize( QSize( 50, 0 ) );
185   TextLabelC1A4->setFrameShape( QLabel::NoFrame );
186   TextLabelC1A4->setFrameShadow( QLabel::Plain );
187   GroupC1Layout->addWidget( TextLabelC1A4, 3, 0 );
188   
189   GeometryGUI_ArchimedeDlgLayout->addWidget( GroupC1, 1, 0 );
190   /***************************************************************/
191   
192   Init(Sel) ; /* Initialisations */
193   
194 /* Move widget on the botton right corner of main widget */
195   QAD_Tools::alignWidget(this, parent, AlignBottom | AlignRight);
196   /* Display  Dialog */
197   this->show() ; 
198 }
199
200
201 //=================================================================================
202 // function : ~GeometryGUI_ArchimedeDlg()
203 // purpose  : Destroys the object and frees any allocated resources
204 //=================================================================================
205 GeometryGUI_ArchimedeDlg::~GeometryGUI_ArchimedeDlg()
206 {
207     // no need to delete child widgets, Qt does it all for us
208 }
209
210
211 //=================================================================================
212 // function : Init()
213 // purpose  :
214 //=================================================================================
215 void GeometryGUI_ArchimedeDlg::Init( SALOME_Selection* Sel )
216 {
217   LineEditC1A2->setMaxLength( 10 );
218   LineEditC1A3->setMaxLength( 10 );
219   LineEditC1A4->setMaxLength( 10 );
220   this->myVa = new QDoubleValidator( 0, +999999.999, 3, LineEditC1A2 ) ;
221   this->myVb = new QDoubleValidator( 0, +999999.999, 3, LineEditC1A3 ) ;
222   this->myVc = new QDoubleValidator( 0, +999999.999, 3, LineEditC1A4 ) ;
223   LineEditC1A2->setValidator( myVa ) ;
224   LineEditC1A3->setValidator( myVb ) ;
225   LineEditC1A4->setValidator( myVc ) ;
226
227   GroupC1->show();
228   myConstructorId = 0 ;
229   Constructor1->setChecked( TRUE );
230   myEditCurrentArgument = LineEditC1A1 ;        
231   mySelection = Sel;  
232
233   this->myWeight = 100.0 ;
234   LineEditC1A2->setText("100.0") ;
235   this->myWaterDensity = 1.0 ;
236   LineEditC1A3->setText("1.0") ;
237   this->myMeshingDeflection = 0.01 ;
238   LineEditC1A4->setText("0.01") ;
239
240   myOkWeight = myOkWaterDensity = myOkMeshingDeflection  = true ;
241   myOkIO = false ;
242
243   myGeomGUI = GeometryGUI::GetGeometryGUI() ;
244   myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
245
246   /* Filter definitions */
247   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
248   myGeom = GEOM::GEOM_Gen::_narrow(comp);
249
250   /* signals and slots connections */
251   connect( buttonOk, SIGNAL( clicked() ),     this, SLOT( ClickOnOk() ) );
252   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
253   connect( buttonApply, SIGNAL( clicked() ),     this, SLOT( ClickOnApply() ) );
254   connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
255
256   connect( SelectButtonC1A1, SIGNAL (clicked() ),   this, SLOT( SetEditCurrentArgument() ) ) ;
257
258   connect( LineEditC1A2, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
259   connect( LineEditC1A3, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
260   connect( LineEditC1A4, SIGNAL (textChanged(const QString&) ), this, SLOT( TextChangedInLineEdit(const QString&) ) ) ;
261
262   connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
263   /* to close dialog if study change */
264   connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ; 
265   connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
266
267   return ;
268 }
269
270
271
272 //=================================================================================
273 // function : ConstructorsClicked()
274 // purpose  : Radio button management
275 //=================================================================================
276 void GeometryGUI_ArchimedeDlg::ConstructorsClicked(int constructorId)
277 {
278   return ;
279 }
280
281
282 //=================================================================================
283 // function : ClickOnOk()
284 // purpose  :
285 //=================================================================================
286 void GeometryGUI_ArchimedeDlg::ClickOnOk()
287 {
288   this->ClickOnApply() ;
289   this->ClickOnCancel() ;
290
291   return ;
292 }
293
294
295 //=================================================================================
296 // function : ClickOnApply()
297 // purpose  :
298 //=================================================================================
299 void GeometryGUI_ArchimedeDlg::ClickOnApply()
300 {
301   switch(myConstructorId)
302     { 
303     case 0 :
304       {  
305         if(myOkIO && myOkWeight && myOkWaterDensity && myOkMeshingDeflection ) {
306           myGeomGUI->Archimede( myIO, myWeight, myWaterDensity, myMeshingDeflection );
307         }
308       }
309       break ;
310     }
311   // accept();
312   return ;
313 }
314
315
316 //=================================================================================
317 // function : ClickOnCancel()
318 // purpose  :
319 //=================================================================================
320 void GeometryGUI_ArchimedeDlg::ClickOnCancel()
321 {
322   myGeomGUI->ResetState() ;
323   reject() ;
324   return ;
325 }
326
327
328 //=================================================================================
329 // function : SelectionIntoArgument()
330 // purpose  : Called when selection as changed or other case
331 //=================================================================================
332 void GeometryGUI_ArchimedeDlg::SelectionIntoArgument()
333 {
334   myEditCurrentArgument->setText("") ;
335   QString aString = "";
336
337   int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
338   if ( nbSel != 1 ) {
339     myEditCurrentArgument->setText("") ;
340     myOkIO = false ;
341   }
342   else {
343     myEditCurrentArgument->setText(aString) ;
344     myIO = mySelection->firstIObject();
345     myOkIO = true ;
346   }
347   return ; 
348 }
349
350
351 //=================================================================================
352 // function : SetEditCurrentArgument()
353 // purpose  :
354 //=================================================================================
355 void GeometryGUI_ArchimedeDlg::SetEditCurrentArgument()
356 {
357   QPushButton* send = (QPushButton*)sender();
358   switch (myConstructorId)
359     {
360     case 0: /* default constructor */
361       { 
362         if(send == SelectButtonC1A1) {
363           LineEditC1A1->setFocus() ;
364           myEditCurrentArgument = LineEditC1A1;
365         }
366         SelectionIntoArgument() ;
367         break;
368       }
369     }
370   return ;
371 }
372
373
374 //=================================================================================
375 // function : TextChangedInLineEdit()
376 // purpose  :
377 //=================================================================================
378 void GeometryGUI_ArchimedeDlg::TextChangedInLineEdit(const QString& newText)
379 {    
380   QLineEdit* send = (QLineEdit*)sender();
381   QString newT = strdup(newText) ;
382   int i ;
383   
384   if(send == LineEditC1A2) {
385     if( myVa->validate(newT, i) == myVa->Acceptable ) { 
386       this->myWeight = newText.toFloat() ;
387       myOkWeight = true ;
388     }
389     else {
390       myOkWeight = false ;
391     }
392   }
393   else if(send == LineEditC1A3) {
394     if( myVb->validate(newT, i) == myVb->Acceptable ) { 
395       this->myWaterDensity = newText.toFloat() ;
396       myOkWaterDensity = true ;
397     }
398     else {
399       myOkWaterDensity = false ;
400     }
401   }
402   else if(send == LineEditC1A4) {
403     if( myVc->validate(newT, i) == myVc->Acceptable ) { 
404       this->myMeshingDeflection = newText.toFloat() ;
405       myOkMeshingDeflection = true ;
406     }
407     else {
408       myOkMeshingDeflection = false ;
409     }
410   }
411   
412   return ;
413 }
414
415
416 //=================================================================================
417 // function : DeactivateActiveDialog()
418 // purpose  :
419 //=================================================================================
420 void GeometryGUI_ArchimedeDlg::DeactivateActiveDialog()
421 {
422   if ( GroupConstructors->isEnabled() ) {
423     GroupConstructors->setEnabled(false) ;
424     GroupC1->setEnabled(false) ;
425     GroupButtons->setEnabled(false) ;
426   }
427   return ;
428 }
429
430
431 //=================================================================================
432 // function : ActivateThisDialog()
433 // purpose  :
434 //=================================================================================
435 void GeometryGUI_ArchimedeDlg::ActivateThisDialog()
436 {
437   /* Emit a signal to deactivate the active dialog */
438   myGeomGUI->EmitSignalDeactivateDialog() ;   
439   GroupConstructors->setEnabled(true) ;
440   GroupC1->setEnabled(true) ;
441   GroupButtons->setEnabled(true) ;
442   return ;
443 }
444
445
446 //=================================================================================
447 // function : enterEvent()
448 // purpose  :
449 //=================================================================================
450 void GeometryGUI_ArchimedeDlg::enterEvent(QEvent* e)
451 {
452   if ( GroupConstructors->isEnabled() )
453     return ;  
454   ActivateThisDialog() ;
455   return ;
456 }
457
458
459 //=================================================================================
460 // function : closeEvent()
461 // purpose  :
462 //=================================================================================
463 void GeometryGUI_ArchimedeDlg::closeEvent( QCloseEvent* e )
464 {
465   /* same than click on cancel button */
466   this->ClickOnCancel() ;
467   return ;
468 }
469
470