2 // File : GeometryGUI_CommonDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_CommonDlg.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>
32 //=================================================================================
33 // class : GeometryGUI_CommonDlg()
34 // purpose : Constructs a GeometryGUI_CommonDlg which is a child of 'parent', with the
35 // name 'name' and widget flags set to 'f'.
36 // The dialog will by default be modeless, unless you set 'modal' to
37 // TRUE to construct a modal dialog.
38 //=================================================================================
39 GeometryGUI_CommonDlg::GeometryGUI_CommonDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
40 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
42 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_COMMON")));
43 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
46 setName( "GeometryGUI_CommonDlg" );
48 setCaption( tr( "GEOM_COMMON_TITLE" ) );
49 setSizeGripEnabled( TRUE );
51 GeometryGUI_CommonDlgLayout = new QGridLayout( this );
52 GeometryGUI_CommonDlgLayout->setSpacing( 6 );
53 GeometryGUI_CommonDlgLayout->setMargin( 11 );
55 /***************************************************************/
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "GEOM_COMMON" ) );
58 GroupConstructors->setExclusive( TRUE );
59 GroupConstructors->setColumnLayout(0, Qt::Vertical );
60 GroupConstructors->layout()->setSpacing( 0 );
61 GroupConstructors->layout()->setMargin( 0 );
62 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
63 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
64 GroupConstructorsLayout->setSpacing( 6 );
65 GroupConstructorsLayout->setMargin( 11 );
66 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
67 GroupConstructorsLayout->addItem( spacer, 0, 1 );
68 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
69 Constructor1->setText( tr( "" ) );
70 Constructor1->setPixmap( image0 );
71 Constructor1->setChecked( TRUE );
72 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
73 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
74 GeometryGUI_CommonDlgLayout->addWidget( GroupConstructors, 0, 0 );
76 /***************************************************************/
77 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
78 GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS" ) );
79 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
80 GroupConstructor1->layout()->setSpacing( 0 );
81 GroupConstructor1->layout()->setMargin( 0 );
82 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
83 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
84 GroupConstructor1Layout->setSpacing( 6 );
85 GroupConstructor1Layout->setMargin( 11 );
86 LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
87 LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
88 GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
89 LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
90 LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
91 GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
92 SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
93 SelectButtonC1A1Shape->setText( tr( "" ) );
94 SelectButtonC1A1Shape->setPixmap( image1 );
95 GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
96 SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
97 SelectButtonC1A2Shape->setText( tr( "" ) );
98 SelectButtonC1A2Shape->setPixmap( image1 );
99 GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
100 TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
101 TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I" ).arg("2") );
102 TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
103 TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
104 TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
105 GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
106 TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
107 TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I" ).arg("1") );
108 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
109 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
110 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
111 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
112 GeometryGUI_CommonDlgLayout->addWidget( GroupConstructor1, 1, 0 );
114 /***************************************************************/
115 GroupButtons = new QGroupBox( this, "GroupButtons" );
116 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
117 GroupButtons->setTitle( tr( "" ) );
118 GroupButtons->setColumnLayout(0, Qt::Vertical );
119 GroupButtons->layout()->setSpacing( 0 );
120 GroupButtons->layout()->setMargin( 0 );
121 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
122 GroupButtonsLayout->setAlignment( Qt::AlignTop );
123 GroupButtonsLayout->setSpacing( 6 );
124 GroupButtonsLayout->setMargin( 11 );
125 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
126 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
127 buttonCancel->setAutoDefault( TRUE );
128 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
129 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
130 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
131 buttonApply->setAutoDefault( TRUE );
132 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
133 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
134 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
135 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
136 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
137 buttonOk->setAutoDefault( TRUE );
138 buttonOk->setDefault( TRUE );
139 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
140 GeometryGUI_CommonDlgLayout->addWidget( GroupButtons, 2, 0 );
147 //=================================================================================
148 // function : ~GeometryGUI_CommonDlg()
149 // purpose : Destroys the object and frees any allocated resources
150 //=================================================================================
151 GeometryGUI_CommonDlg::~GeometryGUI_CommonDlg()
153 /* no need to delete child widgets, Qt does it all for us */
154 this->destroy(TRUE, TRUE) ;
159 //=================================================================================
162 //=================================================================================
163 void GeometryGUI_CommonDlg::Init( SALOME_Selection* Sel )
168 myConstructorId = 0 ;
170 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
172 GroupConstructor1->show();
173 myConstructorId = 0 ;
174 myEditCurrentArgument = LineEditC1A1Shape ;
175 Constructor1->setChecked( TRUE );
176 myOkShape1 = myOkShape2 = false ;
178 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
180 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
181 myGeom = GEOM::GEOM_Gen::_narrow(comp);
183 // TODO previous selection into argument
185 /* signals and slots connections */
186 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
187 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
188 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
189 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
190 connect( SelectButtonC1A1Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
191 connect( SelectButtonC1A2Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
193 connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
194 connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
196 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
197 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
198 /* to close dialog if study change */
199 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
201 /* Move widget on the botton right corner of main widget */
203 myGeomGUI->DefineDlgPosition( this, x, y ) ;
205 this->show() ; /* Displays Dialog */
212 //=================================================================================
213 // function : ConstructorsClicked()
214 // purpose : Radio button management
215 //=================================================================================
216 void GeometryGUI_CommonDlg::ConstructorsClicked(int constructorId)
218 GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
220 switch (constructorId)
224 GroupConstructor1->show();
225 myConstructorId = constructorId ;
226 myEditCurrentArgument = LineEditC1A1Shape ;
227 LineEditC1A2Shape->setText(tr("")) ;
228 Constructor1->setChecked( TRUE );
229 myOkShape1 = myOkShape2 = false ;
236 //=================================================================================
237 // function : ClickOnOk()
239 //=================================================================================
240 void GeometryGUI_CommonDlg::ClickOnOk()
242 this->ClickOnApply() ;
243 this->ClickOnCancel() ;
248 //=================================================================================
249 // function : ClickOnApply()
251 //=================================================================================
252 void GeometryGUI_CommonDlg::ClickOnApply()
254 switch(myConstructorId)
258 if(myOkShape1 && myOkShape2) {
259 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 1 ) ;
270 //=================================================================================
271 // function : ClickOnCancel()
273 //=================================================================================
274 void GeometryGUI_CommonDlg::ClickOnCancel()
276 myGeomGUI->EraseSimulationShape() ;
277 disconnect( mySelection, 0, this, 0 );
278 myGeomGUI->ResetState() ;
285 //=================================================================================
286 // function : SelectionIntoArgument()
287 // purpose : Called when selection has changed
288 //=================================================================================
289 void GeometryGUI_CommonDlg::SelectionIntoArgument()
291 myEditCurrentArgument->setText("") ;
292 QString aString = ""; /* name of future selection */
294 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
296 switch (myConstructorId)
300 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
303 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
314 Standard_Boolean testResult ;
315 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
316 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
319 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
320 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
324 LineEditC1A1Shape->setText(aString) ;
327 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
328 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
332 LineEditC1A2Shape->setText(aString) ;
338 //=================================================================================
339 // function : SetEditCurrentArgument()
341 //=================================================================================
342 void GeometryGUI_CommonDlg::SetEditCurrentArgument()
344 QPushButton* send = (QPushButton*)sender();
345 switch (myConstructorId)
347 case 0: /* default constructor */
349 if( send == SelectButtonC1A1Shape ) {
350 LineEditC1A1Shape->setFocus() ;
351 myEditCurrentArgument = LineEditC1A1Shape ;
353 else if(send == SelectButtonC1A2Shape) {
354 LineEditC1A2Shape->setFocus() ;
355 myEditCurrentArgument = LineEditC1A2Shape;
357 SelectionIntoArgument() ;
366 //=================================================================================
367 // function : LineEditReturnPressed()
369 //=================================================================================
370 void GeometryGUI_CommonDlg::LineEditReturnPressed()
372 QLineEdit* send = (QLineEdit*)sender();
373 if( send == LineEditC1A1Shape )
374 myEditCurrentArgument = LineEditC1A1Shape ;
375 else if ( send == LineEditC1A2Shape )
376 myEditCurrentArgument = LineEditC1A2Shape ;
380 /* User name of object input management */
381 /* If successfull the selection is changed and signal emitted... */
382 /* so SelectionIntoArgument() is automatically called. */
383 const QString objectUserName = myEditCurrentArgument->text() ;
384 QWidget* thisWidget = (QWidget*)this ;
385 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
386 myEditCurrentArgument->setText( objectUserName ) ;
393 //=================================================================================
394 // function : DeactivateActiveDialog()
396 //=================================================================================
397 void GeometryGUI_CommonDlg::DeactivateActiveDialog()
399 if ( GroupConstructors->isEnabled() ) {
400 GroupConstructors->setEnabled(false) ;
401 GroupConstructor1->setEnabled(false) ;
402 GroupButtons->setEnabled(false) ;
403 disconnect( mySelection, 0, this, 0 );
404 myGeomGUI->EraseSimulationShape() ;
411 //=================================================================================
412 // function : closeEvent()
414 //=================================================================================
415 void GeometryGUI_CommonDlg::closeEvent( QCloseEvent* e )
417 this->ClickOnCancel() ; /* same than click on cancel button */
421 //=================================================================================
422 // function : enterEvent()
423 // purpose : when mouse enter onto the QWidget
424 //=================================================================================
425 void GeometryGUI_CommonDlg::enterEvent( QEvent * )
427 if ( GroupConstructors->isEnabled() )
429 ActivateThisDialog() ;
434 //=================================================================================
435 // function : ActivateThisDialog()
437 //=================================================================================
438 void GeometryGUI_CommonDlg::ActivateThisDialog()
440 /* Emit a signal to deactivate any active dialog */
441 myGeomGUI->EmitSignalDeactivateDialog() ;
442 GroupConstructors->setEnabled(true) ;
443 GroupConstructor1->setEnabled(true) ;
444 GroupButtons->setEnabled(true) ;
445 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );