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_CommonDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_CommonDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
52 //=================================================================================
53 // class : GeometryGUI_CommonDlg()
54 // purpose : Constructs a GeometryGUI_CommonDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 GeometryGUI_CommonDlg::GeometryGUI_CommonDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
60 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
62 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_COMMON")));
63 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
66 setName( "GeometryGUI_CommonDlg" );
68 setCaption( tr( "GEOM_COMMON_TITLE" ) );
69 setSizeGripEnabled( TRUE );
71 GeometryGUI_CommonDlgLayout = new QGridLayout( this );
72 GeometryGUI_CommonDlgLayout->setSpacing( 6 );
73 GeometryGUI_CommonDlgLayout->setMargin( 11 );
75 /***************************************************************/
76 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
77 GroupConstructors->setTitle( tr( "GEOM_COMMON" ) );
78 GroupConstructors->setExclusive( TRUE );
79 GroupConstructors->setColumnLayout(0, Qt::Vertical );
80 GroupConstructors->layout()->setSpacing( 0 );
81 GroupConstructors->layout()->setMargin( 0 );
82 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
83 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
84 GroupConstructorsLayout->setSpacing( 6 );
85 GroupConstructorsLayout->setMargin( 11 );
86 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
87 GroupConstructorsLayout->addItem( spacer, 0, 1 );
88 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
89 Constructor1->setText( tr( "" ) );
90 Constructor1->setPixmap( image0 );
91 Constructor1->setChecked( TRUE );
92 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
93 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
94 GeometryGUI_CommonDlgLayout->addWidget( GroupConstructors, 0, 0 );
96 /***************************************************************/
97 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
98 GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS" ) );
99 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
100 GroupConstructor1->layout()->setSpacing( 0 );
101 GroupConstructor1->layout()->setMargin( 0 );
102 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
103 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
104 GroupConstructor1Layout->setSpacing( 6 );
105 GroupConstructor1Layout->setMargin( 11 );
106 LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
107 LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
108 GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
109 LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
110 LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
111 GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
112 SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
113 SelectButtonC1A1Shape->setText( tr( "" ) );
114 SelectButtonC1A1Shape->setPixmap( image1 );
115 GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
116 SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
117 SelectButtonC1A2Shape->setText( tr( "" ) );
118 SelectButtonC1A2Shape->setPixmap( image1 );
119 GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
120 TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
121 TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I" ).arg("2") );
122 TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
123 TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
124 TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
125 GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
126 TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
127 TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I" ).arg("1") );
128 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
129 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
130 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
131 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
132 GeometryGUI_CommonDlgLayout->addWidget( GroupConstructor1, 1, 0 );
134 /***************************************************************/
135 GroupButtons = new QGroupBox( this, "GroupButtons" );
136 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
137 GroupButtons->setTitle( tr( "" ) );
138 GroupButtons->setColumnLayout(0, Qt::Vertical );
139 GroupButtons->layout()->setSpacing( 0 );
140 GroupButtons->layout()->setMargin( 0 );
141 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
142 GroupButtonsLayout->setAlignment( Qt::AlignTop );
143 GroupButtonsLayout->setSpacing( 6 );
144 GroupButtonsLayout->setMargin( 11 );
145 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
146 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
147 buttonCancel->setAutoDefault( TRUE );
148 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
149 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
150 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
151 buttonApply->setAutoDefault( TRUE );
152 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
153 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
154 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
155 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
156 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
157 buttonOk->setAutoDefault( TRUE );
158 buttonOk->setDefault( TRUE );
159 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
160 GeometryGUI_CommonDlgLayout->addWidget( GroupButtons, 2, 0 );
167 //=================================================================================
168 // function : ~GeometryGUI_CommonDlg()
169 // purpose : Destroys the object and frees any allocated resources
170 //=================================================================================
171 GeometryGUI_CommonDlg::~GeometryGUI_CommonDlg()
173 /* no need to delete child widgets, Qt does it all for us */
174 this->destroy(TRUE, TRUE) ;
179 //=================================================================================
182 //=================================================================================
183 void GeometryGUI_CommonDlg::Init( SALOME_Selection* Sel )
188 myConstructorId = 0 ;
190 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
192 GroupConstructor1->show();
193 myConstructorId = 0 ;
194 myEditCurrentArgument = LineEditC1A1Shape ;
195 Constructor1->setChecked( TRUE );
196 myOkShape1 = myOkShape2 = false ;
198 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
200 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
201 myGeom = GEOM::GEOM_Gen::_narrow(comp);
203 // TODO previous selection into argument
205 /* signals and slots connections */
206 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
207 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
208 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
209 connect( GroupConstructors, SIGNAL(clicked(int) ), 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_CommonDlg::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_CommonDlg::ClickOnOk()
262 this->ClickOnApply() ;
263 this->ClickOnCancel() ;
268 //=================================================================================
269 // function : ClickOnApply()
271 //=================================================================================
272 void GeometryGUI_CommonDlg::ClickOnApply()
274 switch(myConstructorId)
278 if(myOkShape1 && myOkShape2) {
279 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 1 ) ;
290 //=================================================================================
291 // function : ClickOnCancel()
293 //=================================================================================
294 void GeometryGUI_CommonDlg::ClickOnCancel()
296 myGeomGUI->EraseSimulationShape() ;
297 disconnect( mySelection, 0, this, 0 );
298 myGeomGUI->ResetState() ;
305 //=================================================================================
306 // function : SelectionIntoArgument()
307 // purpose : Called when selection has changed
308 //=================================================================================
309 void GeometryGUI_CommonDlg::SelectionIntoArgument()
311 myEditCurrentArgument->setText("") ;
312 QString aString = ""; /* name of future selection */
314 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
316 switch (myConstructorId)
320 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
323 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
334 Standard_Boolean testResult ;
335 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
336 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
339 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
340 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
344 LineEditC1A1Shape->setText(aString) ;
347 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
348 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
352 LineEditC1A2Shape->setText(aString) ;
358 //=================================================================================
359 // function : SetEditCurrentArgument()
361 //=================================================================================
362 void GeometryGUI_CommonDlg::SetEditCurrentArgument()
364 QPushButton* send = (QPushButton*)sender();
365 switch (myConstructorId)
367 case 0: /* default constructor */
369 if( send == SelectButtonC1A1Shape ) {
370 LineEditC1A1Shape->setFocus() ;
371 myEditCurrentArgument = LineEditC1A1Shape ;
373 else if(send == SelectButtonC1A2Shape) {
374 LineEditC1A2Shape->setFocus() ;
375 myEditCurrentArgument = LineEditC1A2Shape;
377 SelectionIntoArgument() ;
386 //=================================================================================
387 // function : LineEditReturnPressed()
389 //=================================================================================
390 void GeometryGUI_CommonDlg::LineEditReturnPressed()
392 QLineEdit* send = (QLineEdit*)sender();
393 if( send == LineEditC1A1Shape )
394 myEditCurrentArgument = LineEditC1A1Shape ;
395 else if ( send == LineEditC1A2Shape )
396 myEditCurrentArgument = LineEditC1A2Shape ;
400 /* User name of object input management */
401 /* If successfull the selection is changed and signal emitted... */
402 /* so SelectionIntoArgument() is automatically called. */
403 const QString objectUserName = myEditCurrentArgument->text() ;
404 QWidget* thisWidget = (QWidget*)this ;
405 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
406 myEditCurrentArgument->setText( objectUserName ) ;
413 //=================================================================================
414 // function : DeactivateActiveDialog()
416 //=================================================================================
417 void GeometryGUI_CommonDlg::DeactivateActiveDialog()
419 if ( GroupConstructors->isEnabled() ) {
420 GroupConstructors->setEnabled(false) ;
421 GroupConstructor1->setEnabled(false) ;
422 GroupButtons->setEnabled(false) ;
423 disconnect( mySelection, 0, this, 0 );
424 myGeomGUI->EraseSimulationShape() ;
431 //=================================================================================
432 // function : closeEvent()
434 //=================================================================================
435 void GeometryGUI_CommonDlg::closeEvent( QCloseEvent* e )
437 this->ClickOnCancel() ; /* same than click on cancel button */
441 //=================================================================================
442 // function : enterEvent()
443 // purpose : when mouse enter onto the QWidget
444 //=================================================================================
445 void GeometryGUI_CommonDlg::enterEvent( QEvent * )
447 if ( GroupConstructors->isEnabled() )
449 ActivateThisDialog() ;
454 //=================================================================================
455 // function : ActivateThisDialog()
457 //=================================================================================
458 void GeometryGUI_CommonDlg::ActivateThisDialog()
460 /* Emit a signal to deactivate any active dialog */
461 myGeomGUI->EmitSignalDeactivateDialog() ;
462 GroupConstructors->setEnabled(true) ;
463 GroupConstructor1->setEnabled(true) ;
464 GroupButtons->setEnabled(true) ;
465 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );