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_PartitionDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_PartitionDlg.h"
32 #include "GeometryGUI.h"
33 #include "QAD_Application.h"
34 #include "QAD_Desktop.h"
35 #include "utilities.h"
37 #include <qbuttongroup.h>
38 #include <qgroupbox.h>
40 #include <qlineedit.h>
41 #include <qpushbutton.h>
42 #include <qradiobutton.h>
47 #define MIN_EDIT_SIZE 150
49 //=================================================================================
50 // class : GeometryGUI_PartitionDlg()
51 // purpose : Constructs a GeometryGUI_PartitionDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // TRUE to construct a modal dialog.
55 //=================================================================================
56 GeometryGUI_PartitionDlg::GeometryGUI_PartitionDlg( QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl )
57 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
59 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PARTITION")));
60 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
61 // QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_PARTITION_KEEP_FACES")));
64 setName( "GeometryGUI_PartitionDlg" );
65 setCaption( tr( "GEOM_PARTITION_TITLE" ) );
66 setSizeGripEnabled( TRUE );
67 QGridLayout* GeometryGUI_PartitionDlgLayout = new QGridLayout( this );
68 GeometryGUI_PartitionDlgLayout->setSpacing( 6 );
69 GeometryGUI_PartitionDlgLayout->setMargin( 11 );
71 /***************************************************************/
72 /* Constructor group */
73 /***************************************************************/
74 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
75 GroupConstructors->setTitle( tr( "GEOM_PARTITION" ) );
76 GroupConstructors->setColumnLayout(0, Qt::Vertical );
77 GroupConstructors->layout()->setSpacing( 0 );
78 GroupConstructors->layout()->setMargin( 0 );
79 QGridLayout* GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
80 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
81 GroupConstructorsLayout->setSpacing( 6 );
82 GroupConstructorsLayout->setMargin( 11 );
84 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
85 Constructor1->setPixmap( image0 );
86 Constructor1->setChecked( TRUE );
87 Constructor1->setMinimumSize( QSize( 50, 0 ) );
88 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
89 GroupConstructorsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 1, 0 );
91 GeometryGUI_PartitionDlgLayout->addWidget( GroupConstructors, 0, 0 );
93 /***************************************************************/
95 /***************************************************************/
96 /* Shapes and Tools */
97 GroupC1 = new QGroupBox( this, "GroupC1" );
98 GroupC1->setTitle( tr( "GEOM_PARTITION" ) );
99 GroupC1->setColumnLayout(0, Qt::Vertical );
100 GroupC1->layout()->setSpacing( 0 );
101 GroupC1->layout()->setMargin( 0 );
102 QGridLayout* GroupC1Layout = new QGridLayout( GroupC1->layout() );
103 GroupC1Layout->setAlignment( Qt::AlignTop );
104 GroupC1Layout->setSpacing( 6 );
105 GroupC1Layout->setMargin( 11 );
107 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
108 TextLabelC1A1->setText( tr( "GEOM_OBJECTS" ) );
109 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
110 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
111 SelectButtonC1A1->setPixmap( image1 );
112 SelectButtonC1A1->setToggleButton( FALSE );
113 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
114 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
115 LineEditC1A1->setMinimumSize(MIN_EDIT_SIZE, 0);
116 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
118 TextLabelC1A2 = new QLabel( GroupC1, "TextLabelC1A2" );
119 TextLabelC1A2->setText( tr( "GEOM_TOOL_OBJECT" ) );
120 GroupC1Layout->addWidget( TextLabelC1A2, 1, 0 );
121 SelectButtonC1A2 = new QPushButton( GroupC1, "SelectButtonC1A2" );
122 SelectButtonC1A2->setPixmap( image1 );
123 SelectButtonC1A2->setToggleButton( FALSE );
124 GroupC1Layout->addWidget( SelectButtonC1A2, 1, 1 );
125 LineEditC1A2 = new QLineEdit( GroupC1, "LineEditC1A2" );
126 LineEditC1A2->setMinimumSize(MIN_EDIT_SIZE, 0);
127 GroupC1Layout->addWidget( LineEditC1A2, 1, 2 );
130 TextLabelComboBox1 = new QLabel( GroupC1, "TextLabelComboBox1" );
131 TextLabelComboBox1->setText( tr( "RECONSTRUCTION_LIMIT") );
132 GroupC1Layout->addWidget( TextLabelComboBox1, 2, 0 );
133 ComboBox1 = new QComboBox( FALSE, GroupC1, "ComboBox1" );
134 ComboBox1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) );
135 ComboBox1->setMinimumSize(MIN_EDIT_SIZE, 0);
136 GroupC1Layout->addWidget( ComboBox1, 2, 2 );
138 GeometryGUI_PartitionDlgLayout->addWidget( GroupC1, 1, 0 );
140 /***************************************************************/
141 /* Result suppresion */
142 /***************************************************************/
143 GroupC2 = new QGroupBox( this, "GroupC2" );
144 GroupC2->setTitle( tr( "SUPPRESS_RESULT") );
145 GroupC2->setColumnLayout(0, Qt::Vertical );
146 GroupC2->layout()->setSpacing( 0 );
147 GroupC2->layout()->setMargin( 0 );
148 QGridLayout* GroupC2Layout = new QGridLayout( GroupC2->layout() );
149 GroupC2Layout->setAlignment( Qt::AlignTop );
150 GroupC2Layout->setSpacing( 6 );
151 GroupC2Layout->setMargin( 11 );
153 TextLabelC2A1 = new QLabel( GroupC2, "TextLabelC2A1" );
154 TextLabelC2A1->setText( tr( "SUPPRESS_RESULT_INSIDE") );
155 GroupC2Layout->addWidget( TextLabelC2A1, 0, 0 );
156 SelectButtonC2A1 = new QPushButton( GroupC2, "SelectButtonC2A1" );
157 SelectButtonC2A1->setPixmap( image1 );
158 GroupC2Layout->addWidget( SelectButtonC2A1, 0, 1 );
159 LineEditC2A1 = new QLineEdit( GroupC2, "LineEditC2A1" );
160 GroupC2Layout->addWidget( LineEditC2A1, 0, 2 );
162 TextLabelC2A2 = new QLabel( GroupC2, "TextLabelC2A2" );
163 TextLabelC2A2->setText( tr( "SUPPRESS_RESULT_OUTSIDE") );
164 GroupC2Layout->addWidget( TextLabelC2A2, 1, 0 );
165 SelectButtonC2A2 = new QPushButton( GroupC2, "SelectButtonC2A2" );
166 SelectButtonC2A2->setPixmap( image1 );
167 GroupC2Layout->addWidget( SelectButtonC2A2, 1, 1 );
168 LineEditC2A2 = new QLineEdit( GroupC2, "LineEditC2A2" );
169 GroupC2Layout->addWidget( LineEditC2A2, 1, 2 );
171 GeometryGUI_PartitionDlgLayout->addWidget( GroupC2, 2, 0 );
173 /***************************************************************/
174 /* <OK>, <Apply>, <Cancel> buttons */
175 /***************************************************************/
176 GroupButtons = new QGroupBox( this, "GroupButtons" );
177 GroupButtons->setColumnLayout(0, Qt::Vertical );
178 GroupButtons->layout()->setSpacing( 0 );
179 GroupButtons->layout()->setMargin( 0 );
180 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
181 GroupButtonsLayout->setAlignment( Qt::AlignTop );
182 GroupButtonsLayout->setSpacing( 6 );
183 GroupButtonsLayout->setMargin( 11 );
185 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
186 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
187 buttonOk->setAutoDefault( TRUE );
188 buttonOk->setDefault( TRUE );
189 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
191 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
192 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
193 buttonApply->setAutoDefault( TRUE );
194 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
196 GroupButtonsLayout->addItem( new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 2 );
198 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
199 buttonCancel->setText( tr( "GEOM_BUT_CLOSE" ) );
200 buttonCancel->setAutoDefault( TRUE );
201 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
203 GeometryGUI_PartitionDlgLayout->addWidget( GroupButtons, 3, 0 );
205 /***************************************************************/
206 Init(Sel) ; /* Initialisations */
210 //=================================================================================
211 // function : ~GeometryGUI_PartitionDlg()
212 // purpose : Destroys the object and frees any allocated resources
213 //=================================================================================
214 GeometryGUI_PartitionDlg::~GeometryGUI_PartitionDlg()
216 // no need to delete child widgets, Qt does it all for us
221 //=================================================================================
224 //=================================================================================
225 void GeometryGUI_PartitionDlg::Init( SALOME_Selection* Sel )
227 myEditCurrentArgument = LineEditC1A1 ;
229 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
230 myOkListShapes = myOkListTools = myOkKeepShape = myOkRemoveShape = false ;
232 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
234 /* type for sub shape selection */
235 // ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_SHAPE" ) );
236 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_SOLID" ) );
237 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_SHELL" ) );
238 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_FACE" ) );
239 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_WIRE" ) );
240 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_EDGE" ) );
241 ComboBox1->insertItem( tr( "RECONSTRUCTION_LIMIT_VERTEX" ) );
243 /* Current item is 'Shape' */
244 ComboBox1->setCurrentItem(0);
245 myLimit = ComboBox1->currentItem();
247 /* Filter definitions */
248 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
249 myGeom = GEOM::GEOM_Gen::_narrow(comp);
251 /* signals and slots connections */
252 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
253 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
254 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
255 // connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
256 connect( ComboBox1, SIGNAL( activated(int) ), this, SLOT( ComboTextChanged() ) );
258 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
259 connect( SelectButtonC1A2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
261 connect( SelectButtonC2A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
262 connect( SelectButtonC2A2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
264 connect( LineEditC1A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
265 connect( LineEditC1A2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
266 connect( LineEditC2A1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
267 connect( LineEditC2A2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ) ;
269 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
270 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
271 /* to close dialog if study change */
272 connect( myGeomGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
274 /* Move widget on the botton right corner of main widget */
276 myGeomGUI->DefineDlgPosition( this, x, y ) ;
278 this->show() ; /* displays Dialog */
284 //=================================================================================
285 // function : ClickOnOk()
287 //=================================================================================
288 void GeometryGUI_PartitionDlg::ClickOnOk()
290 this->ClickOnApply() ;
291 this->ClickOnCancel() ;
296 //=================================================================================
297 // function : ClickOnApply()
299 //=================================================================================
300 void GeometryGUI_PartitionDlg::ClickOnApply()
302 myGeomGUI->GetDesktop()->putInfo( tr("") ) ;
303 if (myOkListShapes || myOkListTools || myOkKeepShape || myOkRemoveShape)
305 GEOM::shape_type limit;
307 // case 0: limit = GEOM::SOLID ; break;
308 case 0: limit = GEOM::SHAPE ; break;
309 case 1: limit = GEOM::SHELL ; break;
310 case 2: limit = GEOM::FACE ; break;
311 case 3: limit = GEOM::WIRE ; break;
312 case 4: limit = GEOM::EDGE ; break;
313 case 5: limit = GEOM::VERTEX; break;
314 default:limit = GEOM::SHAPE;
316 myGeomGUI->MakePartitionAndDisplay (myListShapes,
328 //=================================================================================
329 // function : ClickOnCancel()
331 //=================================================================================
332 void GeometryGUI_PartitionDlg::ClickOnCancel()
334 myGeomGUI->EraseSimulationShape() ;
335 disconnect( mySelection, 0, this, 0 );
336 myGeomGUI->ResetState() ;
342 //=================================================================================
343 // function : ConstructorsClicked()
345 //=================================================================================
346 // void GeometryGUI_PartitionDlg::ConstructorsClicked(int constructorId)
351 //=================================================================================
352 // function : SelectionIntoArgument()
353 // purpose : Called when selection as changed or other case
354 //=================================================================================
355 void GeometryGUI_PartitionDlg::SelectionIntoArgument()
357 myEditCurrentArgument->setText("") ;
358 QString aString = ""; /* name of selection */
359 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
362 if ( myEditCurrentArgument == LineEditC1A1 ) {
363 myOkListShapes = false ;
365 else if ( myEditCurrentArgument == LineEditC1A2 ) {
366 myOkListTools = false ;
368 else if ( myEditCurrentArgument == LineEditC2A1 ) {
369 myOkListTools = false ;
371 else if ( myEditCurrentArgument == LineEditC2A2 ) {
372 myOkListTools = false ;
377 if ( myEditCurrentArgument == LineEditC1A1 ) {
378 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes) ;
379 myEditCurrentArgument->setText(aString) ;
380 myOkListShapes = true ;
382 else if ( myEditCurrentArgument == LineEditC1A2 ) {
383 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListTools) ;
384 myEditCurrentArgument->setText(aString) ;
385 myOkListTools = true ;
387 else if ( myEditCurrentArgument == LineEditC2A1 ) {
388 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListRemoveInside) ;
389 myEditCurrentArgument->setText(aString) ;
390 myOkKeepShape = true ;
392 else if ( myEditCurrentArgument == LineEditC2A2 ) {
393 myGeomGUI->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListKeepInside) ;
394 myEditCurrentArgument->setText(aString) ;
395 myOkRemoveShape = true ;
402 //=================================================================================
403 // function : SetEditCurrentArgument()
405 //=================================================================================
406 void GeometryGUI_PartitionDlg::SetEditCurrentArgument()
408 QPushButton* send = (QPushButton*)sender();
410 if (send == SelectButtonC1A1) {
411 LineEditC1A1->setFocus() ;
412 myEditCurrentArgument = LineEditC1A1 ;
414 else if(send == SelectButtonC1A2) {
415 LineEditC1A2->setFocus() ;
416 myEditCurrentArgument = LineEditC1A2 ;
418 else if(send == SelectButtonC2A1) {
419 LineEditC2A1->setFocus() ;
420 myEditCurrentArgument = LineEditC2A1 ;
422 else if(send == SelectButtonC2A2) {
423 LineEditC2A2->setFocus() ;
424 myEditCurrentArgument = LineEditC2A2 ;
426 SelectionIntoArgument() ;
431 //=================================================================================
432 // function : LineEditReturnPressed()
434 //=================================================================================
435 void GeometryGUI_PartitionDlg::LineEditReturnPressed()
437 QLineEdit* send = (QLineEdit*)sender();
438 if( send == LineEditC1A1 )
439 myEditCurrentArgument = LineEditC1A1 ;
440 else if ( send == LineEditC1A2 )
441 myEditCurrentArgument = LineEditC1A2 ;
442 else if ( send == LineEditC2A1 )
443 myEditCurrentArgument = LineEditC2A1 ;
444 else if ( send == LineEditC2A2 )
445 myEditCurrentArgument = LineEditC2A2 ;
449 /* User name of object input management */
450 /* If successfull the selection is changed and signal emitted... */
451 /* so SelectionIntoArgument() is automatically called. */
452 const QString objectUserName = myEditCurrentArgument->text() ;
453 QWidget* thisWidget = (QWidget*)this ;
454 if( myGeomGUI->SelectionByNameInDialogs( thisWidget, objectUserName, mySelection ) ) {
455 myEditCurrentArgument->setText( objectUserName ) ;
461 //=================================================================================
462 // function : DeactivateActiveDialog()
464 //=================================================================================
466 void GeometryGUI_PartitionDlg::DeactivateActiveDialog()
468 if ( GroupConstructors->isEnabled() ) {
469 GroupConstructors->setEnabled(false) ;
470 GroupC1->setEnabled(false) ;
471 GroupC2->setEnabled(false) ;
472 GroupButtons->setEnabled(false) ;
478 //=================================================================================
479 // function : ActivateThisDialog()
481 //=================================================================================
482 void GeometryGUI_PartitionDlg::ActivateThisDialog()
484 /* Emit a signal to deactivate the active dialog */
485 myGeomGUI->EmitSignalDeactivateDialog() ;
486 GroupConstructors->setEnabled(true) ;
487 GroupC1->setEnabled(true) ;
488 GroupC2->setEnabled(true) ;
489 GroupButtons->setEnabled(true) ;
494 //=================================================================================
495 // function : enterEvent()
497 //=================================================================================
498 void GeometryGUI_PartitionDlg::enterEvent(QEvent* e)
500 if ( GroupConstructors->isEnabled() )
502 ActivateThisDialog() ;
507 //=================================================================================
508 // function : closeEvent()
510 //=================================================================================
511 void GeometryGUI_PartitionDlg::closeEvent( QCloseEvent* e )
513 /* same than click on cancel button */
514 this->ClickOnCancel() ;
518 //=======================================================================
519 //function : ComboTextChanged
521 //=======================================================================
523 void GeometryGUI_PartitionDlg::ComboTextChanged()
526 myLimit = ComboBox1->currentItem();
527 GroupC2->setEnabled( ComboBox1->currentItem() < 3 );