2 // File : GeometryGUI_SectionDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
11 #include "GeometryGUI_SectionDlg.h"
13 #include "GeometryGUI.h"
15 #include "QAD_Application.h"
16 #include "QAD_Desktop.h"
17 #include "utilities.h"
19 #include <qbuttongroup.h>
20 #include <qgroupbox.h>
22 #include <qlineedit.h>
23 #include <qpushbutton.h>
24 #include <qradiobutton.h>
28 #include <qwhatsthis.h>
34 //=================================================================================
35 // class : GeometryGUI_SectionDlg()
36 // purpose : Constructs a GeometryGUI_SectionDlg 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_SectionDlg::GeometryGUI_SectionDlg( 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_SECTION")));
45 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
48 setName( "GeometryGUI_SectionDlg" );
50 setCaption( tr( "GEOM_SECTION_TITLE" ) );
51 setSizeGripEnabled( TRUE );
52 GeometryGUI_SectionDlgLayout = new QGridLayout( this );
53 GeometryGUI_SectionDlgLayout->setSpacing( 6 );
54 GeometryGUI_SectionDlgLayout->setMargin( 11 );
56 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
57 GroupConstructors->setTitle( tr( "GEOM_SECTION" ) );
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_SectionDlgLayout->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_SectionDlgLayout->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_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
134 GroupButtonsLayout->addItem( spacer_9, 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_SectionDlgLayout->addWidget( GroupButtons, 2, 0 );
147 //=================================================================================
148 // function : ~GeometryGUI_SectionDlg()
149 // purpose : Destroys the object and frees any allocated resources
150 //=================================================================================
151 GeometryGUI_SectionDlg::~GeometryGUI_SectionDlg()
153 /* no need to delete child widgets, Qt does it all for us */
154 this->destroy(TRUE, TRUE) ;
159 //=================================================================================
162 //=================================================================================
163 void GeometryGUI_SectionDlg::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() ) );
190 connect( GroupConstructors, SIGNAL(clicked(int) ),this, SLOT( ConstructorsClicked(int) ) );
191 connect( SelectButtonC1A1Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
192 connect( SelectButtonC1A2Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
194 connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
195 connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
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_SectionDlg::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_SectionDlg::ClickOnOk()
243 this->ClickOnApply() ;
244 this->ClickOnCancel() ;
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 void GeometryGUI_SectionDlg::ClickOnApply()
255 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
256 switch(myConstructorId)
260 if(myOkShape1 && myOkShape2) {
261 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1, myGeomShape2, 4 ) ;
271 //=================================================================================
272 // function : ClickOnCancel()
274 //=================================================================================
275 void GeometryGUI_SectionDlg::ClickOnCancel()
277 disconnect( mySelection, 0, this, 0 );
278 myGeomGUI->ResetState() ;
285 //=================================================================================
286 // function : SelectionIntoArgument()
287 // purpose : Called when selection has changed
288 //=================================================================================
289 void GeometryGUI_SectionDlg::SelectionIntoArgument()
291 myEditCurrentArgument->setText("") ;
292 QString aString = ""; /* future the name of 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) ;
341 //=================================================================================
342 // function : SetEditCurrentArgument()
344 //=================================================================================
345 void GeometryGUI_SectionDlg::SetEditCurrentArgument()
347 QPushButton* send = (QPushButton*)sender();
349 switch (myConstructorId)
351 case 0: /* default constructor */
353 if( send == SelectButtonC1A1Shape ) {
354 LineEditC1A1Shape->setFocus() ;
355 myEditCurrentArgument = LineEditC1A1Shape ;
357 else if(send == SelectButtonC1A2Shape) {
358 LineEditC1A2Shape->setFocus() ;
359 myEditCurrentArgument = LineEditC1A2Shape;
361 SelectionIntoArgument() ;
370 //=================================================================================
371 // function : LineEditReturnPressed()
373 //=================================================================================
374 void GeometryGUI_SectionDlg::LineEditReturnPressed()
376 QLineEdit* send = (QLineEdit*)sender();
377 if( send == LineEditC1A1Shape )
378 myEditCurrentArgument = LineEditC1A1Shape ;
379 else if ( send == LineEditC1A2Shape )
380 myEditCurrentArgument = LineEditC1A2Shape ;
384 /* User name of object input management */
385 /* If successfull the selection is changed and signal emitted... */
386 /* so SelectionIntoArgument() is automatically called. */
387 const QString objectUserName = myEditCurrentArgument->text() ;
388 QWidget* thisWidget = (QWidget*)this ;
389 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
390 myEditCurrentArgument->setText( objectUserName ) ;
397 //=================================================================================
398 // function : DeactivateActiveDialog()
400 //=================================================================================
401 void GeometryGUI_SectionDlg::DeactivateActiveDialog()
403 if ( GroupConstructors->isEnabled() ) {
405 GroupConstructors->setEnabled(false) ;
406 GroupConstructor1->setEnabled(false) ;
407 GroupButtons->setEnabled(false) ;
408 disconnect( mySelection, 0, this, 0 );
409 myGeomGUI->EraseSimulationShape() ;
416 //=================================================================================
417 // function : closeEvent()
419 //=================================================================================
420 void GeometryGUI_SectionDlg::closeEvent( QCloseEvent* e )
422 this->ClickOnCancel() ; /* same than click on cancel button */
426 //=================================================================================
427 // function : enterEvent()
428 // purpose : when mouse enter onto the QWidget
429 //=================================================================================
430 void GeometryGUI_SectionDlg::enterEvent( QEvent * )
432 if ( GroupConstructors->isEnabled() )
434 ActivateThisDialog() ;
439 //=================================================================================
440 // function : ActivateThisDialog()
442 //=================================================================================
443 void GeometryGUI_SectionDlg::ActivateThisDialog()
445 /* Emit a signal to deactivate any active dialog */
446 myGeomGUI->EmitSignalDeactivateDialog() ;
447 GroupConstructors->setEnabled(true) ;
448 GroupConstructor1->setEnabled(true) ;
449 GroupButtons->setEnabled(true) ;
450 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );