2 // File : GeometryGUI_CutDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_CutDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
33 //=================================================================================
34 // class : GeometryGUI_CutDlg()
35 // purpose : Constructs a GeometryGUI_CutDlg which is a child of 'parent', with the
36 // name 'name' and widget flags set to 'f'.
37 // The dialog will by default be modeless, unless you set 'modal' to
38 // TRUE to construct a modal dialog.
39 //=================================================================================
40 GeometryGUI_CutDlg::GeometryGUI_CutDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
41 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
43 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_CUT")));
44 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
47 setName( "GeometryGUI_CutDlg" );
49 setCaption( tr( "GEOM_CUT_TITLE" ) );
50 setSizeGripEnabled( TRUE );
52 GeometryGUI_CutDlgLayout = new QGridLayout( this );
53 GeometryGUI_CutDlgLayout->setSpacing( 6 );
54 GeometryGUI_CutDlgLayout->setMargin( 11 );
56 /***************************************************************/
57 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
58 GroupConstructors->setTitle( tr( "GEOM_CUT" ) );
59 GroupConstructors->setExclusive( TRUE );
60 GroupConstructors->setColumnLayout(0, Qt::Vertical );
61 GroupConstructors->layout()->setSpacing( 0 );
62 GroupConstructors->layout()->setMargin( 0 );
63 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
64 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
65 GroupConstructorsLayout->setSpacing( 6 );
66 GroupConstructorsLayout->setMargin( 11 );
67 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
68 GroupConstructorsLayout->addItem( spacer, 0, 1 );
69 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
70 Constructor1->setText( tr( "" ) );
71 Constructor1->setPixmap( image0 );
72 Constructor1->setChecked( TRUE );
73 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
74 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
75 GeometryGUI_CutDlgLayout->addWidget( GroupConstructors, 0, 0 );
77 /***************************************************************/
78 GroupConstructor1 = new QGroupBox( this, "GroupConstructor1" );
79 GroupConstructor1->setTitle( tr( "GEOM_ARGUMENTS" ) );
80 GroupConstructor1->setColumnLayout(0, Qt::Vertical );
81 GroupConstructor1->layout()->setSpacing( 0 );
82 GroupConstructor1->layout()->setMargin( 0 );
83 GroupConstructor1Layout = new QGridLayout( GroupConstructor1->layout() );
84 GroupConstructor1Layout->setAlignment( Qt::AlignTop );
85 GroupConstructor1Layout->setSpacing( 6 );
86 GroupConstructor1Layout->setMargin( 11 );
87 LineEditC1A2Shape = new QLineEdit( GroupConstructor1, "LineEditC1A2Shape" );
88 LineEditC1A2Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A2Shape->sizePolicy().hasHeightForWidth() ) );
89 GroupConstructor1Layout->addWidget( LineEditC1A2Shape, 1, 2 );
90 LineEditC1A1Shape = new QLineEdit( GroupConstructor1, "LineEditC1A1Shape" );
91 LineEditC1A1Shape->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, LineEditC1A1Shape->sizePolicy().hasHeightForWidth() ) );
92 GroupConstructor1Layout->addWidget( LineEditC1A1Shape, 0, 2 );
93 SelectButtonC1A1Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A1Shape" );
94 SelectButtonC1A1Shape->setText( tr( "" ) );
95 SelectButtonC1A1Shape->setPixmap( image1 );
96 GroupConstructor1Layout->addWidget( SelectButtonC1A1Shape, 0, 1 );
97 SelectButtonC1A2Shape = new QPushButton( GroupConstructor1, "SelectButtonC1A2Shape" );
98 SelectButtonC1A2Shape->setText( tr( "" ) );
99 SelectButtonC1A2Shape->setPixmap( image1 );
100 GroupConstructor1Layout->addWidget( SelectButtonC1A2Shape, 1, 1 );
101 TextLabelC1A2Shape = new QLabel( GroupConstructor1, "TextLabelC1A2Shape" );
102 TextLabelC1A2Shape->setText( tr( "GEOM_TOOL_OBJECT" ) );
103 TextLabelC1A2Shape->setMinimumSize( QSize( 50, 0 ) );
104 TextLabelC1A2Shape->setFrameShape( QLabel::NoFrame );
105 TextLabelC1A2Shape->setFrameShadow( QLabel::Plain );
106 GroupConstructor1Layout->addWidget( TextLabelC1A2Shape, 1, 0 );
107 TextLabelC1A1Shape = new QLabel( GroupConstructor1, "TextLabelC1A1Shape" );
108 TextLabelC1A1Shape->setText( tr( "GEOM_MAIN_OBJECT" ) );
109 TextLabelC1A1Shape->setMinimumSize( QSize( 50, 0 ) );
110 TextLabelC1A1Shape->setFrameShape( QLabel::NoFrame );
111 TextLabelC1A1Shape->setFrameShadow( QLabel::Plain );
112 GroupConstructor1Layout->addWidget( TextLabelC1A1Shape, 0, 0 );
113 GeometryGUI_CutDlgLayout->addWidget( GroupConstructor1, 1, 0 );
115 /***************************************************************/
116 GroupButtons = new QGroupBox( this, "GroupButtons" );
117 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
118 GroupButtons->setTitle( tr( "" ) );
119 GroupButtons->setColumnLayout(0, Qt::Vertical );
120 GroupButtons->layout()->setSpacing( 0 );
121 GroupButtons->layout()->setMargin( 0 );
122 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
123 GroupButtonsLayout->setAlignment( Qt::AlignTop );
124 GroupButtonsLayout->setSpacing( 6 );
125 GroupButtonsLayout->setMargin( 11 );
126 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
127 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
128 buttonCancel->setAutoDefault( TRUE );
129 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
130 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
131 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
132 buttonApply->setAutoDefault( TRUE );
133 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
134 QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
135 GroupButtonsLayout->addItem( spacer_1, 0, 2 );
136 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
137 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
138 buttonOk->setAutoDefault( TRUE );
139 buttonOk->setDefault( TRUE );
140 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
141 GeometryGUI_CutDlgLayout->addWidget( GroupButtons, 2, 0 );
148 //=================================================================================
149 // function : ~GeometryGUI_CutDlg()
150 // purpose : Destroys the object and frees any allocated resources
151 //=================================================================================
152 GeometryGUI_CutDlg::~GeometryGUI_CutDlg()
154 /* no need to delete child widgets, Qt does it all for us */
155 this->destroy(TRUE, TRUE) ;
160 //=================================================================================
163 //=================================================================================
164 void GeometryGUI_CutDlg::Init( SALOME_Selection* Sel )
169 myConstructorId = 0 ;
171 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
173 GroupConstructor1->show();
174 myConstructorId = 0 ;
175 myEditCurrentArgument = LineEditC1A1Shape ;
176 Constructor1->setChecked( TRUE );
177 myOkShape1 = myOkShape2 = false ;
179 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
181 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
182 myGeom = GEOM::GEOM_Gen::_narrow(comp);
184 // TODO previous selection into argument ?
186 /* signals and slots connections */
187 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
188 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
189 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
190 connect( GroupConstructors, SIGNAL(clicked(int) ), 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_CutDlg::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_CutDlg::ClickOnOk()
243 this->ClickOnApply() ;
244 this->ClickOnCancel() ;
249 //=================================================================================
250 // function : ClickOnApply()
252 //=================================================================================
253 void GeometryGUI_CutDlg::ClickOnApply()
255 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
256 switch(myConstructorId)
260 if(myOkShape1 && myOkShape2) {
261 myGeomGUI->MakeBooleanAndDisplay(myGeomShape1 ,myGeomShape2, 2 ) ;
272 //=================================================================================
273 // function : ClickOnCancel()
275 //=================================================================================
276 void GeometryGUI_CutDlg::ClickOnCancel()
278 disconnect( mySelection, 0, this, 0 );
279 myGeomGUI->ResetState() ;
286 //=================================================================================
287 // function : SelectionIntoArgument()
288 // purpose : Called when selection has changed
289 //=================================================================================
290 void GeometryGUI_CutDlg::SelectionIntoArgument()
292 myEditCurrentArgument->setText("") ;
293 QString aString = ""; /* name of selection */
295 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
297 switch (myConstructorId)
301 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
304 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
315 Standard_Boolean testResult ;
316 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
318 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
321 if ( myEditCurrentArgument == LineEditC1A1Shape ) {
322 myGeomShape1 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
326 LineEditC1A1Shape->setText(aString) ;
329 else if ( myEditCurrentArgument == LineEditC1A2Shape ) {
330 myGeomShape2 = myGeomGUI->ConvertIOinGEOMShape(IO, testResult) ;
334 LineEditC1A2Shape->setText(aString) ;
342 //=================================================================================
343 // function : SetEditCurrentArgument()
345 //=================================================================================
346 void GeometryGUI_CutDlg::SetEditCurrentArgument()
348 QPushButton* send = (QPushButton*)sender();
350 switch (myConstructorId)
352 case 0: /* default constructor */
354 if( send == SelectButtonC1A1Shape ) {
355 LineEditC1A1Shape->setFocus() ;
356 myEditCurrentArgument = LineEditC1A1Shape ;
358 else if(send == SelectButtonC1A2Shape) {
359 LineEditC1A2Shape->setFocus() ;
360 myEditCurrentArgument = LineEditC1A2Shape;
362 SelectionIntoArgument() ;
371 //=================================================================================
372 // function : LineEditReturnPressed()
374 //=================================================================================
375 void GeometryGUI_CutDlg::LineEditReturnPressed()
377 QLineEdit* send = (QLineEdit*)sender();
378 if( send == LineEditC1A1Shape )
379 myEditCurrentArgument = LineEditC1A1Shape ;
380 else if ( send == LineEditC1A2Shape )
381 myEditCurrentArgument = LineEditC1A2Shape ;
385 /* User name of object input management */
386 /* If successfull the selection is changed and signal emitted... */
387 /* so SelectionIntoArgument() is automatically called. */
388 const QString objectUserName = myEditCurrentArgument->text() ;
389 QWidget* thisWidget = (QWidget*)this ;
390 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
391 myEditCurrentArgument->setText( objectUserName ) ;
398 //=================================================================================
399 // function : DeactivateActiveDialog()
401 //=================================================================================
402 void GeometryGUI_CutDlg::DeactivateActiveDialog()
404 if ( GroupConstructors->isEnabled() ) {
406 GroupConstructors->setEnabled(false) ;
407 GroupConstructor1->setEnabled(false) ;
408 GroupButtons->setEnabled(false) ;
409 disconnect( mySelection, 0, this, 0 );
416 //=================================================================================
417 // function : closeEvent()
419 //=================================================================================
420 void GeometryGUI_CutDlg::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_CutDlg::enterEvent( QEvent * )
432 if ( GroupConstructors->isEnabled() )
434 ActivateThisDialog() ;
439 //=================================================================================
440 // function : ActivateThisDialog()
442 //=================================================================================
443 void GeometryGUI_CutDlg::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() ) );