1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GeometryGUI_ArchimedeDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "GeometryGUI_ArchimedeDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "QAD_Tools.h"
36 #include "utilities.h"
38 #include "SALOME_InteractiveObject.hxx"
40 #include <qbuttongroup.h>
41 #include <qgroupbox.h>
43 #include <qlineedit.h>
44 #include <qpushbutton.h>
45 #include <qradiobutton.h>
49 #include <qvalidator.h>
50 #include <qwhatsthis.h>
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 )
64 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_ARCHIMEDE")));
65 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
68 setName( "GeometryGUI_ArchimedeDlg" );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
189 GeometryGUI_ArchimedeDlgLayout->addWidget( GroupC1, 1, 0 );
190 /***************************************************************/
192 Init(Sel) ; /* Initialisations */
194 /* Move widget on the botton right corner of main widget */
195 QAD_Tools::alignWidget(this, parent, AlignBottom | AlignRight);
201 //=================================================================================
202 // function : ~GeometryGUI_ArchimedeDlg()
203 // purpose : Destroys the object and frees any allocated resources
204 //=================================================================================
205 GeometryGUI_ArchimedeDlg::~GeometryGUI_ArchimedeDlg()
207 // no need to delete child widgets, Qt does it all for us
211 //=================================================================================
214 //=================================================================================
215 void GeometryGUI_ArchimedeDlg::Init( SALOME_Selection* Sel )
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 ) ;
228 myConstructorId = 0 ;
229 Constructor1->setChecked( TRUE );
230 myEditCurrentArgument = LineEditC1A1 ;
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") ;
240 myOkWeight = myOkWaterDensity = myOkMeshingDeflection = true ;
243 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
244 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
246 /* Filter definitions */
247 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
248 myGeom = GEOM::GEOM_Gen::_narrow(comp);
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) ) );
256 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
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&) ) ) ;
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() ) );
272 //=================================================================================
273 // function : ConstructorsClicked()
274 // purpose : Radio button management
275 //=================================================================================
276 void GeometryGUI_ArchimedeDlg::ConstructorsClicked(int constructorId)
282 //=================================================================================
283 // function : ClickOnOk()
285 //=================================================================================
286 void GeometryGUI_ArchimedeDlg::ClickOnOk()
288 this->ClickOnApply() ;
289 this->ClickOnCancel() ;
295 //=================================================================================
296 // function : ClickOnApply()
298 //=================================================================================
299 void GeometryGUI_ArchimedeDlg::ClickOnApply()
301 switch(myConstructorId)
305 if(myOkIO && myOkWeight && myOkWaterDensity && myOkMeshingDeflection ) {
306 myGeomGUI->Archimede( myIO, myWeight, myWaterDensity, myMeshingDeflection );
316 //=================================================================================
317 // function : ClickOnCancel()
319 //=================================================================================
320 void GeometryGUI_ArchimedeDlg::ClickOnCancel()
322 myGeomGUI->ResetState() ;
328 //=================================================================================
329 // function : SelectionIntoArgument()
330 // purpose : Called when selection as changed or other case
331 //=================================================================================
332 void GeometryGUI_ArchimedeDlg::SelectionIntoArgument()
334 myEditCurrentArgument->setText("") ;
335 QString aString = "";
337 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
339 myEditCurrentArgument->setText("") ;
343 myEditCurrentArgument->setText(aString) ;
344 myIO = mySelection->firstIObject();
351 //=================================================================================
352 // function : SetEditCurrentArgument()
354 //=================================================================================
355 void GeometryGUI_ArchimedeDlg::SetEditCurrentArgument()
357 QPushButton* send = (QPushButton*)sender();
358 switch (myConstructorId)
360 case 0: /* default constructor */
362 if(send == SelectButtonC1A1) {
363 LineEditC1A1->setFocus() ;
364 myEditCurrentArgument = LineEditC1A1;
366 SelectionIntoArgument() ;
374 //=================================================================================
375 // function : TextChangedInLineEdit()
377 //=================================================================================
378 void GeometryGUI_ArchimedeDlg::TextChangedInLineEdit(const QString& newText)
380 QLineEdit* send = (QLineEdit*)sender();
381 QString newT = strdup(newText) ;
384 if(send == LineEditC1A2) {
385 if( myVa->validate(newT, i) == myVa->Acceptable ) {
386 this->myWeight = newText.toFloat() ;
393 else if(send == LineEditC1A3) {
394 if( myVb->validate(newT, i) == myVb->Acceptable ) {
395 this->myWaterDensity = newText.toFloat() ;
396 myOkWaterDensity = true ;
399 myOkWaterDensity = false ;
402 else if(send == LineEditC1A4) {
403 if( myVc->validate(newT, i) == myVc->Acceptable ) {
404 this->myMeshingDeflection = newText.toFloat() ;
405 myOkMeshingDeflection = true ;
408 myOkMeshingDeflection = false ;
416 //=================================================================================
417 // function : DeactivateActiveDialog()
419 //=================================================================================
420 void GeometryGUI_ArchimedeDlg::DeactivateActiveDialog()
422 if ( GroupConstructors->isEnabled() ) {
423 GroupConstructors->setEnabled(false) ;
424 GroupC1->setEnabled(false) ;
425 GroupButtons->setEnabled(false) ;
431 //=================================================================================
432 // function : ActivateThisDialog()
434 //=================================================================================
435 void GeometryGUI_ArchimedeDlg::ActivateThisDialog()
437 /* Emit a signal to deactivate the active dialog */
438 myGeomGUI->EmitSignalDeactivateDialog() ;
439 GroupConstructors->setEnabled(true) ;
440 GroupC1->setEnabled(true) ;
441 GroupButtons->setEnabled(true) ;
446 //=================================================================================
447 // function : enterEvent()
449 //=================================================================================
450 void GeometryGUI_ArchimedeDlg::enterEvent(QEvent* e)
452 if ( GroupConstructors->isEnabled() )
454 ActivateThisDialog() ;
459 //=================================================================================
460 // function : closeEvent()
462 //=================================================================================
463 void GeometryGUI_ArchimedeDlg::closeEvent( QCloseEvent* e )
465 /* same than click on cancel button */
466 this->ClickOnCancel() ;