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_FuseDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_FuseDlg.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>
53 //=================================================================================
54 // class : GeometryGUI_FuseDlg()
55 // purpose : Constructs a GeometryGUI_FuseDlg 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_FuseDlg::GeometryGUI_FuseDlg( 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_FUSE")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_FuseDlg" );
69 setCaption( tr( "GEOM_FUSE_TITLE" ) );
70 setSizeGripEnabled( TRUE );
72 GeometryGUI_FuseDlgLayout = new QGridLayout( this );
73 GeometryGUI_FuseDlgLayout->setSpacing( 6 );
74 GeometryGUI_FuseDlgLayout->setMargin( 11 );
76 /***************************************************************/
77 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78 GroupConstructors->setTitle( tr( "GEOM_FUSE" ) );
79 GroupConstructors->setExclusive( TRUE );
80 GroupConstructors->setColumnLayout(0, Qt::Vertical );
81 GroupConstructors->layout()->setSpacing( 0 );
82 GroupConstructors->layout()->setMargin( 0 );
83 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
84 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
85 GroupConstructorsLayout->setSpacing( 6 );
86 GroupConstructorsLayout->setMargin( 11 );
87 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
88 GroupConstructorsLayout->addItem( spacer, 0, 1 );
89 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
90 Constructor1->setText( tr( "" ) );
91 Constructor1->setPixmap( image0 );
92 Constructor1->setChecked( TRUE );
93 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
94 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
95 GeometryGUI_FuseDlgLayout->addWidget( GroupConstructors, 0, 0 );
97 /***************************************************************/
98 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
99 GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS" ) );
100 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
101 GroupConstructor1->layout()->setSpacing( 0 );
102 GroupConstructor1->layout()->setMargin( 0 );
103 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
104 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
105 GroupConstructor1Layout->setSpacing( 6 );
106 GroupConstructor1Layout->setMargin( 11 );
107 LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
108 LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
109 GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
110 LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
111 LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
112 GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
113 SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
114 SelectButtonC1A1Shape->setText( tr( "" ) );
115 SelectButtonC1A1Shape->setPixmap( image1 );
116 GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
117 SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
118 SelectButtonC1A2Shape->setText( tr( "" ) );
119 SelectButtonC1A2Shape->setPixmap( image1 );
120 GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
121 TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
122 TextLabelC1A2Shape->setText( tr( "GEOM_OBJECT_I" ).arg("2") );
123 TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
124 TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
125 TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
126 GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
127 TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
128 TextLabelC1A1Shape->setText( tr( "GEOM_OBJECT_I" ).arg("1") );
129 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
130 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
131 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
132 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
133 GeometryGUI_FuseDlgLayout->addWidget( GroupConstructor1, 1, 0 );
135 /***************************************************************/
136 GroupButtons = new QGroupBox( this, "GroupButtons" );
137 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
138 GroupButtons->setTitle( tr( "" ) );
139 GroupButtons->setColumnLayout(0, Qt::Vertical );
140 GroupButtons->layout()->setSpacing( 0 );
141 GroupButtons->layout()->setMargin( 0 );
142 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
143 GroupButtonsLayout->setAlignment( Qt::AlignTop );
144 GroupButtonsLayout->setSpacing( 6 );
145 GroupButtonsLayout->setMargin( 11 );
146 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
147 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
148 buttonCancel->setAutoDefault( TRUE );
149 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
150 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
151 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
152 buttonApply->setAutoDefault( TRUE );
153 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
154 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
155 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
156 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
157 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
158 buttonOk->setAutoDefault( TRUE );
159 buttonOk->setDefault( TRUE );
160 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
161 GeometryGUI_FuseDlgLayout->addWidget( GroupButtons, 2, 0 );
168 //=================================================================================
169 // function : ~GeometryGUI_FuseDlg()
170 // purpose : Destroys the object and frees any allocated resources
171 //=================================================================================
172 GeometryGUI_FuseDlg::~GeometryGUI_FuseDlg()
174 /* no need to delete child widgets, Qt does it all for us */
175 this->destroy(TRUE, TRUE) ;
180 //=================================================================================
183 //=================================================================================
184 void GeometryGUI_FuseDlg::Init( SALOME_Selection* Sel )
189 myConstructorId = 0 ;
191 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
193 GroupConstructor1->show();
194 myConstructorId = 0 ;
195 myEditCurrentArgument = LineEditC1A1Shape ;
196 Constructor1->setChecked( TRUE );
197 myOkShape1 = myOkShape2 = false ;
199 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
201 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
202 myGeom = GEOM::GEOM_Gen::_narrow(comp);
204 // TODO previous selection into argument ?
206 /* signals and slots connections */
207 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
208 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
209 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
210 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
212 connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
213 connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
215 connect( SelectButtonC1A1Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
216 connect( SelectButtonC1A2Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
217 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
218 connect( myGeomGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
219 /* to close dialog if study change */
220 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
222 /* Move widget on the botton right corner of main widget */
224 myGeomGUI->DefineDlgPosition( this, x, y ) ;
226 this->show() ; /* Displays Dialog */
233 //=================================================================================
234 // function : ConstructorsClicked()
235 // purpose : Radio button management
236 //=================================================================================
237 void GeometryGUI_FuseDlg::ConstructorsClicked(int constructorId)
239 GeometryGUI::GetGeometryGUI()->EraseSimulationShape() ;
241 switch (constructorId)
245 GroupConstructor1->show();
246 myConstructorId = constructorId ;
247 myEditCurrentArgument = LineEditC1A1Shape ;
248 LineEditC1A2Shape->setText(tr("")) ;
249 Constructor1->setChecked( TRUE );
250 myOkShape1 = myOkShape2 = false ;
257 //=================================================================================
258 // function : ClickOnOk()
260 //=================================================================================
261 void GeometryGUI_FuseDlg::ClickOnOk()
263 this->ClickOnApply() ;
264 this->ClickOnCancel() ;
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 void GeometryGUI_FuseDlg::ClickOnApply()
275 myGeomGUI->EraseSimulationShape() ;
276 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
278 switch(myConstructorId)
282 if(myOkShape1 && myOkShape2) {
283 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 3 ) ;
294 //=================================================================================
295 // function : ClickOnCancel()
297 //=================================================================================
298 void GeometryGUI_FuseDlg::ClickOnCancel()
300 myGeomGUI->EraseSimulationShape() ;
301 disconnect( mySelection, 0, this, 0 );
302 myGeomGUI->ResetState() ;
309 //=================================================================================
310 // function : SelectionIntoArgument()
311 // purpose : Called when selection has changed
312 //=================================================================================
313 void GeometryGUI_FuseDlg::SelectionIntoArgument()
316 myEditCurrentArgument->setText("") ; /* by default */
317 QString aString = ""; /* the name of selection */
319 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
321 switch (myConstructorId)
325 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
328 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
339 Standard_Boolean testResult ;
340 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
342 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
345 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
346 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
350 LineEditC1A1Shape->setText(aString) ;
353 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
354 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
358 LineEditC1A2Shape->setText(aString) ;
366 //=================================================================================
367 // function : SetEditCurrentArgument()
369 //=================================================================================
370 void GeometryGUI_FuseDlg::SetEditCurrentArgument()
372 QPushButton* send = (QPushButton*)sender();
374 switch (myConstructorId)
376 case 0: /* default constructor */
378 if( send == SelectButtonC1A1Shape ) {
379 LineEditC1A1Shape->setFocus() ;
380 myEditCurrentArgument = LineEditC1A1Shape ;
382 else if(send == SelectButtonC1A2Shape) {
383 LineEditC1A2Shape->setFocus() ;
384 myEditCurrentArgument = LineEditC1A2Shape;
386 SelectionIntoArgument() ;
395 //=================================================================================
396 // function : LineEditReturnPressed()
398 //=================================================================================
399 void GeometryGUI_FuseDlg::LineEditReturnPressed()
401 QLineEdit* send = (QLineEdit*)sender();
402 if( send == LineEditC1A1Shape )
403 myEditCurrentArgument = LineEditC1A1Shape ;
404 else if ( send == LineEditC1A2Shape )
405 myEditCurrentArgument = LineEditC1A2Shape ;
409 /* User name of object input management */
410 /* If successfull the selection is changed and signal emitted... */
411 /* so SelectionIntoArgument() is automatically called. */
412 const QString objectUserName = myEditCurrentArgument->text() ;
413 QWidget* thisWidget = (QWidget*)this ;
414 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
415 myEditCurrentArgument->setText( objectUserName ) ;
422 //=================================================================================
423 // function : DeactivateActiveDialog()
425 //=================================================================================
426 void GeometryGUI_FuseDlg::DeactivateActiveDialog()
428 if ( GroupConstructors->isEnabled() ) {
430 GroupConstructors->setEnabled(false) ;
431 GroupConstructor1->setEnabled(false) ;
432 GroupButtons->setEnabled(false) ;
433 disconnect( mySelection, 0, this, 0 );
440 //=================================================================================
441 // function : closeEvent()
443 //=================================================================================
444 void GeometryGUI_FuseDlg::closeEvent( QCloseEvent* e )
446 this->ClickOnCancel() ; /* same than click on cancel button */
450 //=================================================================================
451 // function : enterEvent()
452 // purpose : when mouse enter onto the QWidget
453 //=================================================================================
454 void GeometryGUI_FuseDlg::enterEvent( QEvent * )
456 if ( GroupConstructors->isEnabled() )
458 ActivateThisDialog() ;
463 //=================================================================================
464 // function : ActivateThisDialog()
466 //=================================================================================
467 void GeometryGUI_FuseDlg::ActivateThisDialog()
469 /* Emit a signal to deactivate any active dialog */
470 myGeomGUI->EmitSignalDeactivateDialog() ;
471 GroupConstructors->setEnabled(true) ;
472 GroupConstructor1->setEnabled(true) ;
473 GroupButtons->setEnabled(true) ;
475 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );