2 // File : GeometryGUI_FuseDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_FuseDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
33 //=================================================================================
34 // class : GeometryGUI_FuseDlg()
35 // purpose : Constructs a GeometryGUI_FuseDlg which is a child of 'parent', with the
36 // name 'name' and widget flags set to 'f'.
37 // The dialog will by default be modeless, unless you set 'modal' to
38 // TRUE to construct a modal dialog.
39 //=================================================================================
40 GeometryGUI_FuseDlg::GeometryGUI_FuseDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
41 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
43 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_FUSE")));
44 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
47 setName( "GeometryGUI_FuseDlg" );
49 setCaption( tr( "GEOM_FUSE_TITLE" ) );
50 setSizeGripEnabled( TRUE );
52 GeometryGUI_FuseDlgLayout = new QGridLayout( this );
53 GeometryGUI_FuseDlgLayout->setSpacing( 6 );
54 GeometryGUI_FuseDlgLayout->setMargin( 11 );
56 /***************************************************************/
57 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
58 GroupConstructors->setTitle( tr( "GEOM_FUSE" ) );
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 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
68 GroupConstructorsLayout->addItem( spacer, 0, 1 );
69 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
70 Constructor1->setText( tr( "" ) );
71 Constructor1->setPixmap( image0 );
72 Constructor1->setChecked( TRUE );
73 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
74 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
75 GeometryGUI_FuseDlgLayout->addWidget( GroupConstructors, 0, 0 );
77 /***************************************************************/
78 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
79 GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS" ) );
80 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
81 GroupConstructor1->layout()->setSpacing( 0 );
82 GroupConstructor1->layout()->setMargin( 0 );
83 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
84 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
85 GroupConstructor1Layout->setSpacing( 6 );
86 GroupConstructor1Layout->setMargin( 11 );
87 LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
88 LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
89 GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
90 LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
91 LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
92 GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
93 SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
94 SelectButtonC1A1Shape->setText( tr( "" ) );
95 SelectButtonC1A1Shape->setPixmap( image1 );
96 GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
97 SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
98 SelectButtonC1A2Shape->setText( tr( "" ) );
99 SelectButtonC1A2Shape->setPixmap( image1 );
100 GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
101 TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
102 TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I" ).arg("2") );
103 TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
104 TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
105 TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
106 GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
107 TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
108 TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I" ).arg("1") );
109 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
110 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
111 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
112 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
113 GeometryGUI_FuseDlgLayout->addWidget( GroupConstructor1, 1, 0 );
115 /***************************************************************/
116 GroupButtons = new QGroupBox( this, "GroupButtons" );
117 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
118 GroupButtons->setTitle( tr( "" ) );
119 GroupButtons->setColumnLayout(0, Qt::Vertical );
120 GroupButtons->layout()->setSpacing( 0 );
121 GroupButtons->layout()->setMargin( 0 );
122 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
123 GroupButtonsLayout->setAlignment( Qt::AlignTop );
124 GroupButtonsLayout->setSpacing( 6 );
125 GroupButtonsLayout->setMargin( 11 );
126 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
127 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
128 buttonCancel->setAutoDefault( TRUE );
129 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
130 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
131 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
132 buttonApply->setAutoDefault( TRUE );
133 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
134 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
135 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
136 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
137 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
138 buttonOk->setAutoDefault( TRUE );
139 buttonOk->setDefault( TRUE );
140 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
141 GeometryGUI_FuseDlgLayout->addWidget( GroupButtons, 2, 0 );
148 //=================================================================================
149 // function : ~GeometryGUI_FuseDlg()
150 // purpose : Destroys the object and frees any allocated resources
151 //=================================================================================
152 GeometryGUI_FuseDlg::~GeometryGUI_FuseDlg()
154 /* no need to delete child widgets, Qt does it all for us */
155 this->destroy(TRUE, TRUE) ;
160 //=================================================================================
163 //=================================================================================
164 void GeometryGUI_FuseDlg::Init( SALOME_Selection* Sel )
169 myConstructorId = 0 ;
171 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
173 GroupConstructor1->show();
174 myConstructorId = 0 ;
175 myEditCurrentArgument = LineEditC1A1Shape ;
176 Constructor1->setChecked( TRUE );
177 myOkShape1 = myOkShape2 = false ;
179 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
181 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
182 myGeom = GEOM::GEOM_Gen::_narrow(comp);
184 // TODO previous selection into argument ?
186 /* signals and slots connections */
187 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
188 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
189 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
190 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
192 connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
193 connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
195 connect( SelectButtonC1A1Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
196 connect( SelectButtonC1A2Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
197 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
198 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
199 /* to close dialog if study change */
200 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
202 /* Move widget on the botton right corner of main widget */
204 myGeomGUI->DefineDlgPosition( this, x, y ) ;
206 this->show() ; /* Displays Dialog */
213 //=================================================================================
214 // function : ConstructorsClicked()
215 // purpose : Radio button management
216 //=================================================================================
217 void GeometryGUI_FuseDlg::ConstructorsClicked(int constructorId)
219 GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
221 switch (constructorId)
225 GroupConstructor1->show();
226 myConstructorId = constructorId ;
227 myEditCurrentArgument = LineEditC1A1Shape ;
228 LineEditC1A2Shape->setText(tr("")) ;
229 Constructor1->setChecked( TRUE );
230 myOkShape1 = myOkShape2 = false ;
237 //=================================================================================
238 // function : ClickOnOk()
240 //=================================================================================
241 void GeometryGUI_FuseDlg::ClickOnOk()
243 this->ClickOnApply() ;
244 this->ClickOnCancel() ;
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 void GeometryGUI_FuseDlg::ClickOnApply()
255 myGeomGUI->EraseSimulationShape() ;
256 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
258 switch(myConstructorId)
262 if(myOkShape1 && myOkShape2) {
263 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 3 ) ;
274 //=================================================================================
275 // function : ClickOnCancel()
277 //=================================================================================
278 void GeometryGUI_FuseDlg::ClickOnCancel()
280 myGeomGUI->EraseSimulationShape() ;
281 disconnect( mySelection, 0, this, 0 );
282 myGeomGUI->ResetState() ;
289 //=================================================================================
290 // function : SelectionIntoArgument()
291 // purpose : Called when selection has changed
292 //=================================================================================
293 void GeometryGUI_FuseDlg::SelectionIntoArgument()
296 myEditCurrentArgument->setText("") ; /* by default */
297 QString aString = ""; /* the name of selection */
299 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
301 switch (myConstructorId)
305 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
308 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
319 Standard_Boolean testResult ;
320 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
322 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
325 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
326 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
330 LineEditC1A1Shape->setText(aString) ;
333 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
334 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
338 LineEditC1A2Shape->setText(aString) ;
346 //=================================================================================
347 // function : SetEditCurrentArgument()
349 //=================================================================================
350 void GeometryGUI_FuseDlg::SetEditCurrentArgument()
352 QPushButton* send = (QPushButton*)sender();
354 switch (myConstructorId)
356 case 0: /* default constructor */
358 if( send == SelectButtonC1A1Shape ) {
359 LineEditC1A1Shape->setFocus() ;
360 myEditCurrentArgument = LineEditC1A1Shape ;
362 else if(send == SelectButtonC1A2Shape) {
363 LineEditC1A2Shape->setFocus() ;
364 myEditCurrentArgument = LineEditC1A2Shape;
366 SelectionIntoArgument() ;
375 //=================================================================================
376 // function : LineEditReturnPressed()
378 //=================================================================================
379 void GeometryGUI_FuseDlg::LineEditReturnPressed()
381 QLineEdit* send = (QLineEdit*)sender();
382 if( send == LineEditC1A1Shape )
383 myEditCurrentArgument = LineEditC1A1Shape ;
384 else if ( send == LineEditC1A2Shape )
385 myEditCurrentArgument = LineEditC1A2Shape ;
389 /* User name of object input management */
390 /* If successfull the selection is changed and signal emitted... */
391 /* so SelectionIntoArgument() is automatically called. */
392 const QString objectUserName = myEditCurrentArgument->text() ;
393 QWidget* thisWidget = (QWidget*)this ;
394 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
395 myEditCurrentArgument->setText( objectUserName ) ;
402 //=================================================================================
403 // function : DeactivateActiveDialog()
405 //=================================================================================
406 void GeometryGUI_FuseDlg::DeactivateActiveDialog()
408 if ( GroupConstructors->isEnabled() ) {
410 GroupConstructors->setEnabled(false) ;
411 GroupConstructor1->setEnabled(false) ;
412 GroupButtons->setEnabled(false) ;
413 disconnect( mySelection, 0, this, 0 );
420 //=================================================================================
421 // function : closeEvent()
423 //=================================================================================
424 void GeometryGUI_FuseDlg::closeEvent( QCloseEvent* e )
426 this->ClickOnCancel() ; /* same than click on cancel button */
430 //=================================================================================
431 // function : enterEvent()
432 // purpose : when mouse enter onto the QWidget
433 //=================================================================================
434 void GeometryGUI_FuseDlg::enterEvent( QEvent * )
436 if ( GroupConstructors->isEnabled() )
438 ActivateThisDialog() ;
443 //=================================================================================
444 // function : ActivateThisDialog()
446 //=================================================================================
447 void GeometryGUI_FuseDlg::ActivateThisDialog()
449 /* Emit a signal to deactivate any active dialog */
450 myGeomGUI->EmitSignalDeactivateDialog() ;
451 GroupConstructors->setEnabled(true) ;
452 GroupConstructor1->setEnabled(true) ;
453 GroupButtons->setEnabled(true) ;
455 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );