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_SectionDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_SectionDlg.h"
32 #include "GeometryGUI.h"
34 #include "QAD_Application.h"
35 #include "QAD_Desktop.h"
36 #include "utilities.h"
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
53 //=================================================================================
54 // class : GeometryGUI_SectionDlg()
55 // purpose : Constructs a GeometryGUI_SectionDlg which is a child of 'parent', with the
56 // name 'name' and widget flags set to 'f'.
57 // The dialog will by default be modeless, unless you set 'modal' to
58 // TRUE to construct a modal dialog.
59 //=================================================================================
60 GeometryGUI_SectionDlg::GeometryGUI_SectionDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
63 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_SECTION")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_SectionDlg" );
69 setCaption( tr( "GEOM_SECTION_TITLE" ) );
70 setSizeGripEnabled( TRUE );
71 GeometryGUI_SectionDlgLayout = new QGridLayout( this );
72 GeometryGUI_SectionDlgLayout->setSpacing( 6 );
73 GeometryGUI_SectionDlgLayout->setMargin( 11 );
75 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
76 GroupConstructors->setTitle( tr( "GEOM_SECTION" ) );
77 GroupConstructors->setExclusive( TRUE );
78 GroupConstructors->setColumnLayout(0, Qt::Vertical );
79 GroupConstructors->layout()->setSpacing( 0 );
80 GroupConstructors->layout()->setMargin( 0 );
81 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
82 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
83 GroupConstructorsLayout->setSpacing( 6 );
84 GroupConstructorsLayout->setMargin( 11 );
85 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
86 GroupConstructorsLayout->addItem( spacer, 0, 1 );
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 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
93 GeometryGUI_SectionDlgLayout->addWidget( GroupConstructors, 0, 0 );
95 /***************************************************************/
96 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
97 GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS" ) );
98 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
99 GroupConstructor1->layout()->setSpacing( 0 );
100 GroupConstructor1->layout()->setMargin( 0 );
101 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
102 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
103 GroupConstructor1Layout->setSpacing( 6 );
104 GroupConstructor1Layout->setMargin( 11 );
105 LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
106 LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
107 GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
108 LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
109 LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
110 GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
111 SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
112 SelectButtonC1A1Shape->setText( tr( "" ) );
113 SelectButtonC1A1Shape->setPixmap( image1 );
114 GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
115 SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
116 SelectButtonC1A2Shape->setText( tr( "" ) );
117 SelectButtonC1A2Shape->setPixmap( image1 );
118 GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
119 TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
120 TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I" ).arg("2") );
121 TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
122 TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
123 TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
124 GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
125 TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
126 TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I" ).arg("1") );
127 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
128 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
129 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
130 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
131 GeometryGUI_SectionDlgLayout->addWidget( GroupConstructor1, 1, 0 );
133 /***************************************************************/
134 GroupButtons = new QGroupBox( this, "GroupButtons" );
135 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
136 GroupButtons->setTitle( tr( "" ) );
137 GroupButtons->setColumnLayout(0, Qt::Vertical );
138 GroupButtons->layout()->setSpacing( 0 );
139 GroupButtons->layout()->setMargin( 0 );
140 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
141 GroupButtonsLayout->setAlignment( Qt::AlignTop );
142 GroupButtonsLayout->setSpacing( 6 );
143 GroupButtonsLayout->setMargin( 11 );
144 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
145 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
146 buttonCancel->setAutoDefault( TRUE );
147 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
148 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
149 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
150 buttonApply->setAutoDefault( TRUE );
151 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
152 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
153 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
154 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
155 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
156 buttonOk->setAutoDefault( TRUE );
157 buttonOk->setDefault( TRUE );
158 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
159 GeometryGUI_SectionDlgLayout->addWidget( GroupButtons, 2, 0 );
166 //=================================================================================
167 // function : ~GeometryGUI_SectionDlg()
168 // purpose : Destroys the object and frees any allocated resources
169 //=================================================================================
170 GeometryGUI_SectionDlg::~GeometryGUI_SectionDlg()
172 /* no need to delete child widgets, Qt does it all for us */
173 this->destroy(TRUE, TRUE) ;
178 //=================================================================================
181 //=================================================================================
182 void GeometryGUI_SectionDlg::Init( SALOME_Selection* Sel )
187 myConstructorId = 0 ;
189 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
191 GroupConstructor1->show();
192 myConstructorId = 0 ;
193 myEditCurrentArgument = LineEditC1A1Shape ;
194 Constructor1->setChecked( TRUE );
195 myOkShape1 = myOkShape2 = false ;
197 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
199 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
200 myGeom = GEOM::GEOM_Gen::_narrow(comp);
202 // TODO previous selection into argument ?
204 /* signals and slots connections */
205 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
206 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
207 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
209 connect( GroupConstructors, SIGNAL(clicked(int) ),this, SLOT( ConstructorsClicked(int) ) );
210 connect( SelectButtonC1A1Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
211 connect( SelectButtonC1A2Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
213 connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
214 connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
216 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
217 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
218 /* to close dialog if study change */
219 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
221 /* Move widget on the botton right corner of main widget */
223 myGeomGUI->DefineDlgPosition( this, x, y ) ;
225 this->show() ; /* Displays Dialog */
232 //=================================================================================
233 // function : ConstructorsClicked()
234 // purpose : Radio button management
235 //=================================================================================
236 void GeometryGUI_SectionDlg::ConstructorsClicked(int constructorId)
238 GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
240 switch (constructorId)
244 GroupConstructor1->show();
245 myConstructorId = constructorId ;
246 myEditCurrentArgument = LineEditC1A1Shape ;
247 LineEditC1A2Shape->setText(tr("")) ;
248 Constructor1->setChecked( TRUE );
249 myOkShape1 = myOkShape2 = false ;
256 //=================================================================================
257 // function : ClickOnOk()
259 //=================================================================================
260 void GeometryGUI_SectionDlg::ClickOnOk()
262 this->ClickOnApply() ;
263 this->ClickOnCancel() ;
268 //=================================================================================
269 // function : ClickOnApply()
271 //=================================================================================
272 void GeometryGUI_SectionDlg::ClickOnApply()
274 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
275 switch(myConstructorId)
279 if(myOkShape1 && myOkShape2) {
280 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1, myGeomShape2, 4 ) ;
290 //=================================================================================
291 // function : ClickOnCancel()
293 //=================================================================================
294 void GeometryGUI_SectionDlg::ClickOnCancel()
296 disconnect( mySelection, 0, this, 0 );
297 myGeomGUI->ResetState() ;
304 //=================================================================================
305 // function : SelectionIntoArgument()
306 // purpose : Called when selection has changed
307 //=================================================================================
308 void GeometryGUI_SectionDlg::SelectionIntoArgument()
310 myEditCurrentArgument->setText("") ;
311 QString aString = ""; /* future the name of selection */
313 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
315 switch (myConstructorId)
319 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
322 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
333 Standard_Boolean testResult ;
334 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
335 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
338 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
339 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
343 LineEditC1A1Shape->setText(aString) ;
346 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
347 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
351 LineEditC1A2Shape->setText(aString) ;
360 //=================================================================================
361 // function : SetEditCurrentArgument()
363 //=================================================================================
364 void GeometryGUI_SectionDlg::SetEditCurrentArgument()
366 QPushButton* send = (QPushButton*)sender();
368 switch (myConstructorId)
370 case 0: /* default constructor */
372 if( send == SelectButtonC1A1Shape ) {
373 LineEditC1A1Shape->setFocus() ;
374 myEditCurrentArgument = LineEditC1A1Shape ;
376 else if(send == SelectButtonC1A2Shape) {
377 LineEditC1A2Shape->setFocus() ;
378 myEditCurrentArgument = LineEditC1A2Shape;
380 SelectionIntoArgument() ;
389 //=================================================================================
390 // function : LineEditReturnPressed()
392 //=================================================================================
393 void GeometryGUI_SectionDlg::LineEditReturnPressed()
395 QLineEdit* send = (QLineEdit*)sender();
396 if( send == LineEditC1A1Shape )
397 myEditCurrentArgument = LineEditC1A1Shape ;
398 else if ( send == LineEditC1A2Shape )
399 myEditCurrentArgument = LineEditC1A2Shape ;
403 /* User name of object input management */
404 /* If successfull the selection is changed and signal emitted... */
405 /* so SelectionIntoArgument() is automatically called. */
406 const QString objectUserName = myEditCurrentArgument->text() ;
407 QWidget* thisWidget = (QWidget*)this ;
408 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
409 myEditCurrentArgument->setText( objectUserName ) ;
416 //=================================================================================
417 // function : DeactivateActiveDialog()
419 //=================================================================================
420 void GeometryGUI_SectionDlg::DeactivateActiveDialog()
422 if ( GroupConstructors->isEnabled() ) {
424 GroupConstructors->setEnabled(false) ;
425 GroupConstructor1->setEnabled(false) ;
426 GroupButtons->setEnabled(false) ;
427 disconnect( mySelection, 0, this, 0 );
428 myGeomGUI->EraseSimulationShape() ;
435 //=================================================================================
436 // function : closeEvent()
438 //=================================================================================
439 void GeometryGUI_SectionDlg::closeEvent( QCloseEvent* e )
441 this->ClickOnCancel() ; /* same than click on cancel button */
445 //=================================================================================
446 // function : enterEvent()
447 // purpose : when mouse enter onto the QWidget
448 //=================================================================================
449 void GeometryGUI_SectionDlg::enterEvent( QEvent * )
451 if ( GroupConstructors->isEnabled() )
453 ActivateThisDialog() ;
458 //=================================================================================
459 // function : ActivateThisDialog()
461 //=================================================================================
462 void GeometryGUI_SectionDlg::ActivateThisDialog()
464 /* Emit a signal to deactivate any active dialog */
465 myGeomGUI->EmitSignalDeactivateDialog() ;
466 GroupConstructors->setEnabled(true) ;
467 GroupConstructor1->setEnabled(true) ;
468 GroupButtons->setEnabled(true) ;
469 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );