2 // File : GeometryGUI_ArchimedeDlg.cxx
3 // Created : Mon Feb 25 11:13:13 CET 2002
4 // Author : Nicolas REJNERI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_ArchimedeDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "QAD_Tools.h"
16 #include "utilities.h"
18 #include "SALOME_InteractiveObject.hxx"
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
29 #include <qvalidator.h>
30 #include <qwhatsthis.h>
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 )
44 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_ARCHIMEDE")));
45 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
48 setName( "GeometryGUI_ArchimedeDlg" );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
169 GeometryGUI_ArchimedeDlgLayout->addWidget( GroupC1, 1, 0 );
170 /***************************************************************/
172 Init(Sel) ; /* Initialisations */
174 /* Move widget on the botton right corner of main widget */
175 QAD_Tools::alignWidget(this, parent, AlignBottom | AlignRight);
181 //=================================================================================
182 // function : ~GeometryGUI_ArchimedeDlg()
183 // purpose : Destroys the object and frees any allocated resources
184 //=================================================================================
185 GeometryGUI_ArchimedeDlg::~GeometryGUI_ArchimedeDlg()
187 // no need to delete child widgets, Qt does it all for us
191 //=================================================================================
194 //=================================================================================
195 void GeometryGUI_ArchimedeDlg::Init( SALOME_Selection* Sel )
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 ) ;
208 myConstructorId = 0 ;
209 Constructor1->setChecked( TRUE );
210 myEditCurrentArgument = LineEditC1A1 ;
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") ;
220 myOkWeight = myOkWaterDensity = myOkMeshingDeflection = true ;
223 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
224 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
226 /* Filter definitions */
227 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
228 myGeom = GEOM::GEOM_Gen::_narrow(comp);
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) ) );
236 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
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&) ) ) ;
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() ) );
252 //=================================================================================
253 // function : ConstructorsClicked()
254 // purpose : Radio button management
255 //=================================================================================
256 void GeometryGUI_ArchimedeDlg::ConstructorsClicked(int constructorId)
262 //=================================================================================
263 // function : ClickOnOk()
265 //=================================================================================
266 void GeometryGUI_ArchimedeDlg::ClickOnOk()
268 this->ClickOnApply() ;
269 this->ClickOnCancel() ;
275 //=================================================================================
276 // function : ClickOnApply()
278 //=================================================================================
279 void GeometryGUI_ArchimedeDlg::ClickOnApply()
281 switch(myConstructorId)
285 if(myOkIO && myOkWeight && myOkWaterDensity && myOkMeshingDeflection ) {
286 myGeomGUI->Archimede( myIO, myWeight, myWaterDensity, myMeshingDeflection );
296 //=================================================================================
297 // function : ClickOnCancel()
299 //=================================================================================
300 void GeometryGUI_ArchimedeDlg::ClickOnCancel()
302 myGeomGUI->ResetState() ;
308 //=================================================================================
309 // function : SelectionIntoArgument()
310 // purpose : Called when selection as changed or other case
311 //=================================================================================
312 void GeometryGUI_ArchimedeDlg::SelectionIntoArgument()
314 myEditCurrentArgument->setText("") ;
315 QString aString = "";
317 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
319 myEditCurrentArgument->setText("") ;
323 myEditCurrentArgument->setText(aString) ;
324 myIO = mySelection->firstIObject();
331 //=================================================================================
332 // function : SetEditCurrentArgument()
334 //=================================================================================
335 void GeometryGUI_ArchimedeDlg::SetEditCurrentArgument()
337 QPushButton* send = (QPushButton*)sender();
338 switch (myConstructorId)
340 case 0: /* default constructor */
342 if(send == SelectButtonC1A1) {
343 LineEditC1A1->setFocus() ;
344 myEditCurrentArgument = LineEditC1A1;
346 SelectionIntoArgument() ;
354 //=================================================================================
355 // function : TextChangedInLineEdit()
357 //=================================================================================
358 void GeometryGUI_ArchimedeDlg::TextChangedInLineEdit(const QString& newText)
360 QLineEdit* send = (QLineEdit*)sender();
361 QString newT = strdup(newText) ;
364 if(send == LineEditC1A2) {
365 if( myVa->validate(newT, i) == myVa->Acceptable ) {
366 this->myWeight = newText.toFloat() ;
373 else if(send == LineEditC1A3) {
374 if( myVb->validate(newT, i) == myVb->Acceptable ) {
375 this->myWaterDensity = newText.toFloat() ;
376 myOkWaterDensity = true ;
379 myOkWaterDensity = false ;
382 else if(send == LineEditC1A4) {
383 if( myVc->validate(newT, i) == myVc->Acceptable ) {
384 this->myMeshingDeflection = newText.toFloat() ;
385 myOkMeshingDeflection = true ;
388 myOkMeshingDeflection = false ;
396 //=================================================================================
397 // function : DeactivateActiveDialog()
399 //=================================================================================
400 void GeometryGUI_ArchimedeDlg::DeactivateActiveDialog()
402 if ( GroupConstructors->isEnabled() ) {
403 GroupConstructors->setEnabled(false) ;
404 GroupC1->setEnabled(false) ;
405 GroupButtons->setEnabled(false) ;
411 //=================================================================================
412 // function : ActivateThisDialog()
414 //=================================================================================
415 void GeometryGUI_ArchimedeDlg::ActivateThisDialog()
417 /* Emit a signal to deactivate the active dialog */
418 myGeomGUI->EmitSignalDeactivateDialog() ;
419 GroupConstructors->setEnabled(true) ;
420 GroupC1->setEnabled(true) ;
421 GroupButtons->setEnabled(true) ;
426 //=================================================================================
427 // function : enterEvent()
429 //=================================================================================
430 void GeometryGUI_ArchimedeDlg::enterEvent(QEvent* e)
432 if ( GroupConstructors->isEnabled() )
434 ActivateThisDialog() ;
439 //=================================================================================
440 // function : closeEvent()
442 //=================================================================================
443 void GeometryGUI_ArchimedeDlg::closeEvent( QCloseEvent* e )
445 /* same than click on cancel button */
446 this->ClickOnCancel() ;