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_CutDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_CutDlg.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_CutDlg()
55 // purpose : Constructs a GeometryGUI_CutDlg 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_CutDlg::GeometryGUI_CutDlg( 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_CUT")));
64 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
67 setName( "GeometryGUI_CutDlg" );
69 setCaption( tr( "GEOM_CUT_TITLE" ) );
70 setSizeGripEnabled( TRUE );
72 GeometryGUI_CutDlgLayout = new QGridLayout( this );
73 GeometryGUI_CutDlgLayout->setSpacing( 6 );
74 GeometryGUI_CutDlgLayout->setMargin( 11 );
76 /***************************************************************/
77 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
78 GroupConstructors->setTitle( tr( "GEOM_CUT" ) );
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_CutDlgLayout->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_TOOL_OBJECT" ) );
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_MAIN_OBJECT" ) );
129 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
130 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
131 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
132 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
133 GeometryGUI_CutDlgLayout->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_CutDlgLayout->addWidget( GroupButtons, 2, 0 );
168 //=================================================================================
169 // function : ~GeometryGUI_CutDlg()
170 // purpose : Destroys the object and frees any allocated resources
171 //=================================================================================
172 GeometryGUI_CutDlg::~GeometryGUI_CutDlg()
174 /* no need to delete child widgets, Qt does it all for us */
175 this->destroy(TRUE, TRUE) ;
180 //=================================================================================
183 //=================================================================================
184 void GeometryGUI_CutDlg::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) ) );
211 connect( SelectButtonC1A1Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
212 connect( SelectButtonC1A2Shape, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
214 connect( LineEditC1A1Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
215 connect( LineEditC1A2Shape, SIGNAL ( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
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_CutDlg::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_CutDlg::ClickOnOk()
263 this->ClickOnApply() ;
264 this->ClickOnCancel() ;
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 void GeometryGUI_CutDlg::ClickOnApply()
275 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
276 switch(myConstructorId)
280 if(myOkShape1 && myOkShape2) {
281 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 2 ) ;
292 //=================================================================================
293 // function : ClickOnCancel()
295 //=================================================================================
296 void GeometryGUI_CutDlg::ClickOnCancel()
298 disconnect( mySelection, 0, this, 0 );
299 myGeomGUI->ResetState() ;
306 //=================================================================================
307 // function : SelectionIntoArgument()
308 // purpose : Called when selection has changed
309 //=================================================================================
310 void GeometryGUI_CutDlg::SelectionIntoArgument()
312 myEditCurrentArgument->setText("") ;
313 QString aString = ""; /* name of selection */
315 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
317 switch (myConstructorId)
321 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
324 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
335 Standard_Boolean testResult ;
336 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
338 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
341 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
342 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
346 LineEditC1A1Shape->setText(aString) ;
349 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
350 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
354 LineEditC1A2Shape->setText(aString) ;
362 //=================================================================================
363 // function : SetEditCurrentArgument()
365 //=================================================================================
366 void GeometryGUI_CutDlg::SetEditCurrentArgument()
368 QPushButton* send = (QPushButton*)sender();
370 switch (myConstructorId)
372 case 0: /* default constructor */
374 if( send == SelectButtonC1A1Shape ) {
375 LineEditC1A1Shape->setFocus() ;
376 myEditCurrentArgument = LineEditC1A1Shape ;
378 else if(send == SelectButtonC1A2Shape) {
379 LineEditC1A2Shape->setFocus() ;
380 myEditCurrentArgument = LineEditC1A2Shape;
382 SelectionIntoArgument() ;
391 //=================================================================================
392 // function : LineEditReturnPressed()
394 //=================================================================================
395 void GeometryGUI_CutDlg::LineEditReturnPressed()
397 QLineEdit* send = (QLineEdit*)sender();
398 if( send == LineEditC1A1Shape )
399 myEditCurrentArgument = LineEditC1A1Shape ;
400 else if ( send == LineEditC1A2Shape )
401 myEditCurrentArgument = LineEditC1A2Shape ;
405 /* User name of object input management */
406 /* If successfull the selection is changed and signal emitted... */
407 /* so SelectionIntoArgument() is automatically called. */
408 const QString objectUserName = myEditCurrentArgument->text() ;
409 QWidget* thisWidget = (QWidget*)this ;
410 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
411 myEditCurrentArgument->setText( objectUserName ) ;
418 //=================================================================================
419 // function : DeactivateActiveDialog()
421 //=================================================================================
422 void GeometryGUI_CutDlg::DeactivateActiveDialog()
424 if ( GroupConstructors->isEnabled() ) {
426 GroupConstructors->setEnabled(false) ;
427 GroupConstructor1->setEnabled(false) ;
428 GroupButtons->setEnabled(false) ;
429 disconnect( mySelection, 0, this, 0 );
436 //=================================================================================
437 // function : closeEvent()
439 //=================================================================================
440 void GeometryGUI_CutDlg::closeEvent( QCloseEvent* e )
442 this->ClickOnCancel() ; /* same than click on cancel button */
446 //=================================================================================
447 // function : enterEvent()
448 // purpose : when mouse enter onto the QWidget
449 //=================================================================================
450 void GeometryGUI_CutDlg::enterEvent( QEvent * )
452 if ( GroupConstructors->isEnabled() )
454 ActivateThisDialog() ;
459 //=================================================================================
460 // function : ActivateThisDialog()
462 //=================================================================================
463 void GeometryGUI_CutDlg::ActivateThisDialog()
465 /* Emit a signal to deactivate any active dialog */
466 myGeomGUI->EmitSignalDeactivateDialog() ;
467 GroupConstructors->setEnabled(true) ;
468 GroupConstructor1->setEnabled(true) ;
469 GroupButtons->setEnabled(true) ;
470 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );