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