2 // File : GeometryGUI_PartitionDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_PartitionDlg.h"
12 #include "GeometryGUI.h"
13 #include "QAD_Application.h"
14 #include "QAD_Desktop.h"
15 #include "utilities.h"
17 #include <qbuttongroup.h>
18 #include <qgroupbox.h>
20 #include <qlineedit.h>
21 #include <qpushbutton.h>
22 #include <qradiobutton.h>
27 #define MIN_EDIT_SIZE 150
29 //=================================================================================
30 // class : GeometryGUI_PartitionDlg()
31 // purpose : Constructs a GeometryGUI_PartitionDlg which is a child of 'parent', with the
32 // name 'name' and widget flags set to 'f'.
33 // The dialog will by default be modeless, unless you set 'modal' to
34 // TRUE to construct a modal dialog.
35 //=================================================================================
36 GeometryGUI_PartitionDlg::GeometryGUI_PartitionDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
37 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
39 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PARTITION")));
40 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
41 // QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PARTITION_KEEP_FACES")));
44 setName( "GeometryGUI_PartitionDlg" );
45 setCaption( tr( "GEOM_PARTITION_TITLE" ) );
46 setSizeGripEnabled( TRUE );
47 QGridLayout* GeometryGUI_PartitionDlgLayout = new QGridLayout( this );
48 GeometryGUI_PartitionDlgLayout->setSpacing( 6 );
49 GeometryGUI_PartitionDlgLayout->setMargin( 11 );
51 /***************************************************************/
52 /* Constructor group */
53 /***************************************************************/
54 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
55 GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
56 GroupConstructors->setColumnLayout(0, Qt::Vertical );
57 GroupConstructors->layout()->setSpacing( 0 );
58 GroupConstructors->layout()->setMargin( 0 );
59 QGridLayout* GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
60 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
61 GroupConstructorsLayout->setSpacing( 6 );
62 GroupConstructorsLayout->setMargin( 11 );
64 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
65 Constructor1->setPixmap( image0 );
66 Constructor1->setChecked( TRUE );
67 Constructor1->setMinimumSize( QSize( 50, 0 ) );
68 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
69 GroupConstructorsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 0 );
71 GeometryGUI_PartitionDlgLayout->addWidget( GroupConstructors, 0, 0 );
73 /***************************************************************/
75 /***************************************************************/
76 /* Shapes and Tools */
77 GroupC1 = new QGroupBox( this, "GroupC1" );
78 GroupC1->setTitle( tr( "GEOM_PARTITION" ) );
79 GroupC1->setColumnLayout(0, Qt::Vertical );
80 GroupC1->layout()->setSpacing( 0 );
81 GroupC1->layout()->setMargin( 0 );
82 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
83 GroupC1Layout->setAlignment( Qt::AlignTop );
84 GroupC1Layout->setSpacing( 6 );
85 GroupC1Layout->setMargin( 11 );
87 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
88 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
89 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
90 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
91 SelectButtonC1A1->setPixmap( image1 );
92 SelectButtonC1A1->setToggleButton( FALSE );
93 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
94 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
95 LineEditC1A1->setMinimumSize(MIN_EDIT_SIZE, 0);
96 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
98 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
99 TextLabelC1A2->setText( tr( "GEOM_TOOL_OBJECT" ) );
100 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
101 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
102 SelectButtonC1A2->setPixmap( image1 );
103 SelectButtonC1A2->setToggleButton( FALSE );
104 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
105 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
106 LineEditC1A2->setMinimumSize(MIN_EDIT_SIZE, 0);
107 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
110 TextLabelComboBox1 = new QLabel( GroupC1, "TextLabelComboBox1" );
111 TextLabelComboBox1->setText( tr( "RECONSTRUCTION_LIMIT") );
112 GroupC1Layout->addWidget( TextLabelComboBox1, 2, 0 );
113 ComboBox1 = new QComboBox( FALSE, GroupC1, "ComboBox1" );
114 ComboBox1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
115 ComboBox1->setMinimumSize(MIN_EDIT_SIZE, 0);
116 GroupC1Layout->addWidget( ComboBox1, 2, 2 );
118 GeometryGUI_PartitionDlgLayout->addWidget( GroupC1, 1, 0 );
120 /***************************************************************/
121 /* Result suppresion */
122 /***************************************************************/
123 GroupC2 = new QGroupBox( this, "GroupC2" );
124 GroupC2->setTitle( tr( "SUPPRESS_RESULT") );
125 GroupC2->setColumnLayout(0, Qt::Vertical );
126 GroupC2->layout()->setSpacing( 0 );
127 GroupC2->layout()->setMargin( 0 );
128 QGridLayout* GroupC2Layout = new QGridLayout( GroupC2->layout() );
129 GroupC2Layout->setAlignment( Qt::AlignTop );
130 GroupC2Layout->setSpacing( 6 );
131 GroupC2Layout->setMargin( 11 );
133 TextLabelC2A1 = new QLabel( GroupC2, "TextLabelC2A1" );
134 TextLabelC2A1->setText( tr( "SUPPRESS_RESULT_INSIDE") );
135 GroupC2Layout->addWidget( TextLabelC2A1, 0, 0 );
136 SelectButtonC2A1 = new QPushButton( GroupC2, "SelectButtonC2A1" );
137 SelectButtonC2A1->setPixmap( image1 );
138 GroupC2Layout->addWidget( SelectButtonC2A1, 0, 1 );
139 LineEditC2A1 = new QLineEdit( GroupC2, "LineEditC2A1" );
140 GroupC2Layout->addWidget( LineEditC2A1, 0, 2 );
142 TextLabelC2A2 = new QLabel( GroupC2, "TextLabelC2A2" );
143 TextLabelC2A2->setText( tr( "SUPPRESS_RESULT_OUTSIDE") );
144 GroupC2Layout->addWidget( TextLabelC2A2, 1, 0 );
145 SelectButtonC2A2 = new QPushButton( GroupC2, "SelectButtonC2A2" );
146 SelectButtonC2A2->setPixmap( image1 );
147 GroupC2Layout->addWidget( SelectButtonC2A2, 1, 1 );
148 LineEditC2A2 = new QLineEdit( GroupC2, "LineEditC2A2" );
149 GroupC2Layout->addWidget( LineEditC2A2, 1, 2 );
151 GeometryGUI_PartitionDlgLayout->addWidget( GroupC2, 2, 0 );
153 /***************************************************************/
154 /* <OK>, <Apply>, <Cancel> buttons */
155 /***************************************************************/
156 GroupButtons = new QGroupBox( this, "GroupButtons" );
157 GroupButtons->setColumnLayout(0, Qt::Vertical );
158 GroupButtons->layout()->setSpacing( 0 );
159 GroupButtons->layout()->setMargin( 0 );
160 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
161 GroupButtonsLayout->setAlignment( Qt::AlignTop );
162 GroupButtonsLayout->setSpacing( 6 );
163 GroupButtonsLayout->setMargin( 11 );
165 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
166 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
167 buttonOk->setAutoDefault( TRUE );
168 buttonOk->setDefault( TRUE );
169 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
171 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
172 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
173 buttonApply->setAutoDefault( TRUE );
174 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
176 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
178 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
179 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
180 buttonCancel->setAutoDefault( TRUE );
181 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
183 GeometryGUI_PartitionDlgLayout->addWidget( GroupButtons, 3, 0 );
185 /***************************************************************/
186 Init(Sel) ; /* Initialisations */
190 //=================================================================================
191 // function : ~GeometryGUI_PartitionDlg()
192 // purpose : Destroys the object and frees any allocated resources
193 //=================================================================================
194 GeometryGUI_PartitionDlg::~GeometryGUI_PartitionDlg()
196 // no need to delete child widgets, Qt does it all for us
201 //=================================================================================
204 //=================================================================================
205 void GeometryGUI_PartitionDlg::Init( SALOME_Selection* Sel )
207 myEditCurrentArgument = LineEditC1A1 ;
209 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
210 myOkListShapes = myOkListTools = myOkKeepShape = myOkRemoveShape = false ;
212 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
214 /* type for sub shape selection */
215 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_SHAPE" ) );
216 // ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_SOLID" ) );
217 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_SHELL" ) );
218 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_FACE" ) );
219 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_WIRE" ) );
220 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_EDGE" ) );
221 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_VERTEX" ) );
223 /* Current item is 'Shape' */
224 ComboBox1->setCurrentItem(0);
225 myLimit = ComboBox1->currentItem();
227 /* Filter definitions */
228 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
229 myGeom = GEOM::GEOM_Gen::_narrow(comp);
231 /* signals and slots connections */
232 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
233 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
234 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
235 // connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
236 connect( ComboBox1, SIGNAL( activated(int) ), this, SLOT( ComboTextChanged() ) );
238 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
239 connect( SelectButtonC1A2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
241 connect( SelectButtonC2A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
242 connect( SelectButtonC2A2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
244 connect( LineEditC1A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
245 connect( LineEditC1A2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
246 connect( LineEditC2A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
247 connect( LineEditC2A2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
249 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
250 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
251 /* to close dialog if study change */
252 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
254 /* Move widget on the botton right corner of main widget */
256 myGeomGUI->DefineDlgPosition( this, x, y ) ;
258 this->show() ; /* displays Dialog */
264 //=================================================================================
265 // function : ClickOnOk()
267 //=================================================================================
268 void GeometryGUI_PartitionDlg::ClickOnOk()
270 this->ClickOnApply() ;
271 this->ClickOnCancel() ;
276 //=================================================================================
277 // function : ClickOnApply()
279 //=================================================================================
280 void GeometryGUI_PartitionDlg::ClickOnApply()
282 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
283 if (myOkListShapes || myOkListTools || myOkKeepShape || myOkRemoveShape)
285 GEOM::shape_type limit;
287 case 0: limit = GEOM::SHAPE ; break;
288 case 1: limit = GEOM::SOLID ; break;
289 case 2: limit = GEOM::SHELL ; break;
290 case 3: limit = GEOM::FACE ; break;
291 case 4: limit = GEOM::WIRE ; break;
292 case 5: limit = GEOM::EDGE ; break;
293 case 6: limit = GEOM::VERTEX; break;
294 default:limit = GEOM::SHAPE;
296 myGeomGUI->MakePartitionAndDisplay (myListShapes,
308 //=================================================================================
309 // function : ClickOnCancel()
311 //=================================================================================
312 void GeometryGUI_PartitionDlg::ClickOnCancel()
314 myGeomGUI->EraseSimulationShape() ;
315 disconnect( mySelection, 0, this, 0 );
316 myGeomGUI->ResetState() ;
322 //=================================================================================
323 // function : ConstructorsClicked()
325 //=================================================================================
326 // void GeometryGUI_PartitionDlg::ConstructorsClicked(int constructorId)
331 //=================================================================================
332 // function : SelectionIntoArgument()
333 // purpose : Called when selection as changed or other case
334 //=================================================================================
335 void GeometryGUI_PartitionDlg::SelectionIntoArgument()
337 myEditCurrentArgument->setText("") ;
338 QString aString = ""; /* name of selection */
339 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
342 if ( myEditCurrentArgument == LineEditC1A1 ) {
343 myOkListShapes = false ;
345 else if ( myEditCurrentArgument == LineEditC1A2 ) {
346 myOkListTools = false ;
348 else if ( myEditCurrentArgument == LineEditC2A1 ) {
349 myOkListTools = false ;
351 else if ( myEditCurrentArgument == LineEditC2A2 ) {
352 myOkListTools = false ;
357 if ( myEditCurrentArgument == LineEditC1A1 ) {
358 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
359 myEditCurrentArgument->setText(aString) ;
360 myOkListShapes = true ;
362 else if ( myEditCurrentArgument == LineEditC1A2 ) {
363 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListTools) ;
364 myEditCurrentArgument->setText(aString) ;
365 myOkListTools = true ;
367 else if ( myEditCurrentArgument == LineEditC2A1 ) {
368 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListRemoveInside) ;
369 myEditCurrentArgument->setText(aString) ;
370 myOkKeepShape = true ;
372 else if ( myEditCurrentArgument == LineEditC2A2 ) {
373 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListKeepInside) ;
374 myEditCurrentArgument->setText(aString) ;
375 myOkRemoveShape = true ;
382 //=================================================================================
383 // function : SetEditCurrentArgument()
385 //=================================================================================
386 void GeometryGUI_PartitionDlg::SetEditCurrentArgument()
388 QPushButton* send = (QPushButton*)sender();
390 if (send == SelectButtonC1A1) {
391 LineEditC1A1->setFocus() ;
392 myEditCurrentArgument = LineEditC1A1 ;
394 else if(send == SelectButtonC1A2) {
395 LineEditC1A2->setFocus() ;
396 myEditCurrentArgument = LineEditC1A2 ;
398 else if(send == SelectButtonC2A1) {
399 LineEditC2A1->setFocus() ;
400 myEditCurrentArgument = LineEditC2A1 ;
402 else if(send == SelectButtonC2A2) {
403 LineEditC2A2->setFocus() ;
404 myEditCurrentArgument = LineEditC2A2 ;
406 SelectionIntoArgument() ;
411 //=================================================================================
412 // function : LineEditReturnPressed()
414 //=================================================================================
415 void GeometryGUI_PartitionDlg::LineEditReturnPressed()
417 QLineEdit* send = (QLineEdit*)sender();
418 if( send == LineEditC1A1 )
419 myEditCurrentArgument = LineEditC1A1 ;
420 else if ( send == LineEditC1A2 )
421 myEditCurrentArgument = LineEditC1A2 ;
422 else if ( send == LineEditC2A1 )
423 myEditCurrentArgument = LineEditC2A1 ;
424 else if ( send == LineEditC2A2 )
425 myEditCurrentArgument = LineEditC2A2 ;
429 /* User name of object input management */
430 /* If successfull the selection is changed and signal emitted... */
431 /* so SelectionIntoArgument() is automatically called. */
432 const QString objectUserName = myEditCurrentArgument->text() ;
433 QWidget* thisWidget = (QWidget*)this ;
434 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
435 myEditCurrentArgument->setText( objectUserName ) ;
441 //=================================================================================
442 // function : DeactivateActiveDialog()
444 //=================================================================================
446 void GeometryGUI_PartitionDlg::DeactivateActiveDialog()
448 if ( GroupConstructors->isEnabled() ) {
449 GroupConstructors->setEnabled(false) ;
450 GroupC1->setEnabled(false) ;
451 GroupC2->setEnabled(false) ;
452 GroupButtons->setEnabled(false) ;
458 //=================================================================================
459 // function : ActivateThisDialog()
461 //=================================================================================
462 void GeometryGUI_PartitionDlg::ActivateThisDialog()
464 /* Emit a signal to deactivate the active dialog */
465 myGeomGUI->EmitSignalDeactivateDialog() ;
466 GroupConstructors->setEnabled(true) ;
467 GroupC1->setEnabled(true) ;
468 GroupC2->setEnabled(true) ;
469 GroupButtons->setEnabled(true) ;
474 //=================================================================================
475 // function : enterEvent()
477 //=================================================================================
478 void GeometryGUI_PartitionDlg::enterEvent(QEvent* e)
480 if ( GroupConstructors->isEnabled() )
482 ActivateThisDialog() ;
487 //=================================================================================
488 // function : closeEvent()
490 //=================================================================================
491 void GeometryGUI_PartitionDlg::closeEvent( QCloseEvent* e )
493 /* same than click on cancel button */
494 this->ClickOnCancel() ;
498 //=======================================================================
499 //function : ComboTextChanged
501 //=======================================================================
503 void GeometryGUI_PartitionDlg::ComboTextChanged()
506 myLimit = ComboBox1->currentItem();
507 GroupC2->setEnabled( ComboBox1->currentItem() < 3 );