2 // File : GeometryGUI_SuppressFacesDlg.cxx
4 // Author : Lucien PIGNOLONI
6 // Module : GeometryGUI
7 // Copyright : OPEN CASCADE
10 #include "GeometryGUI_SuppressFacesDlg.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 <qcheckbox.h>
19 #include <qgroupbox.h>
21 #include <qlineedit.h>
22 #include <qpushbutton.h>
23 #include <qradiobutton.h>
27 #include <qwhatsthis.h>
31 //=================================================================================
32 // class : GeometryGUI_SuppressFacesDlg()
33 // purpose : Constructs a GeometryGUI_SuppressFacesDlg which is a child of 'parent', with the
34 // name 'name' and widget flags set to 'f'.
35 // The dialog will by default be modeless, unless you set 'modal' to
36 // TRUE to construct a modal dialog.
37 //=================================================================================
38 GeometryGUI_SuppressFacesDlg::GeometryGUI_SuppressFacesDlg( QWidget* parent,
40 SALOME_Selection* Sel,
41 Handle (AIS_InteractiveContext) ic,
44 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
46 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SUPRESS_FACE")));
47 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
50 setName( "GeometryGUI_SuppressFacesDlg" );
52 setCaption( tr( "GEOM_SUPRESSFACE_TITLE" ) );
53 setSizeGripEnabled( TRUE );
54 GeometryGUI_SuppressFacesDlgLayout = new QGridLayout( this );
55 GeometryGUI_SuppressFacesDlgLayout->setSpacing( 6 );
56 GeometryGUI_SuppressFacesDlgLayout->setMargin( 11 );
58 /***************************************************************/
59 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
60 GroupConstructors->setTitle( tr( "GEOM_SUPRESSFACE" ) );
61 GroupConstructors->setExclusive( TRUE );
62 GroupConstructors->setColumnLayout(0, Qt::Vertical );
63 GroupConstructors->layout()->setSpacing( 0 );
64 GroupConstructors->layout()->setMargin( 0 );
65 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
66 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
67 GroupConstructorsLayout->setSpacing( 6 );
68 GroupConstructorsLayout->setMargin( 11 );
69 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
70 Constructor1->setText( tr( "" ) );
71 Constructor1->setPixmap( image0 );
72 Constructor1->setChecked( TRUE );
73 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
74 Constructor1->setMinimumSize( QSize( 50, 0 ) );
75 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
76 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
77 GroupConstructorsLayout->addItem( spacer, 0, 1 );
78 GeometryGUI_SuppressFacesDlgLayout->addWidget( GroupConstructors, 0, 0 );
80 /***************************************************************/
81 GroupC1 = new QGroupBox( this, "GroupC1" );
82 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
83 GroupC1->setMinimumSize( QSize( 0, 0 ) );
84 GroupC1->setFrameShape( QGroupBox::Box );
85 GroupC1->setFrameShadow( QGroupBox::Sunken );
86 GroupC1->setColumnLayout(0, Qt::Vertical );
87 GroupC1->layout()->setSpacing( 0 );
88 GroupC1->layout()->setMargin( 0 );
89 GroupC1Layout = new QGridLayout( GroupC1->layout() );
90 GroupC1Layout->setAlignment( Qt::AlignTop );
91 GroupC1Layout->setSpacing( 6 );
92 GroupC1Layout->setMargin( 11 );
93 Layout2 = new QHBoxLayout;
94 Layout2->setSpacing( 6 );
95 Layout2->setMargin( 0 );
96 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
97 TextLabelC1A1->setText( tr( "GEOM_MAIN_OBJECT" ) );
98 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
99 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
100 TextLabelC1A1->setFrameShadow( QLabel::Plain );
101 Layout2->addWidget( TextLabelC1A1 );
102 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
103 SelectButtonC1A1->setText( tr( "" ) );
104 SelectButtonC1A1->setPixmap( image1 );
105 SelectButtonC1A1->setToggleButton( FALSE );
106 SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
107 Layout2->addWidget( SelectButtonC1A1 );
108 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
109 LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
110 Layout2->addWidget( LineEditC1A1 );
111 GroupC1Layout->addLayout( Layout2, 0, 0 );
112 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
113 CheckBox1->setText( tr( "GEOM_SUPRESSFACE_SELECT" ) );
114 CheckBox1->setChecked( FALSE );
115 GroupC1Layout->addWidget( CheckBox1, 1, 0 );
116 GeometryGUI_SuppressFacesDlgLayout->addWidget( GroupC1, 1, 0 );
118 /***************************************************************/
119 GroupButtons = new QGroupBox( this, "GroupButtons" );
120 GroupButtons->setTitle( tr( "" ) );
121 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
122 GroupButtons->setColumnLayout(0, Qt::Vertical );
123 GroupButtons->layout()->setSpacing( 0 );
124 GroupButtons->layout()->setMargin( 0 );
125 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
126 GroupButtonsLayout->setAlignment( Qt::AlignTop );
127 GroupButtonsLayout->setSpacing( 6 );
128 GroupButtonsLayout->setMargin( 11 );
130 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
131 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
132 buttonOk->setAutoDefault( TRUE );
133 buttonOk->setDefault( TRUE );
134 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
135 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
136 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
137 buttonApply->setAutoDefault( TRUE );
138 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
139 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
140 GroupButtonsLayout->addItem( spacer_2, 0, 2 );
141 buttonClose = new QPushButton( GroupButtons, "buttonClose" );
142 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
143 buttonClose->setAutoDefault( TRUE );
144 GroupButtonsLayout->addWidget( buttonClose, 0, 3 );
145 GeometryGUI_SuppressFacesDlgLayout->addWidget( GroupButtons, 2, 0 );
147 /* Initialisations */
153 //=================================================================================
154 // function : ~GeometryGUI_SuppressFacesDlg()
155 // purpose : Destroys the object and frees any allocated resources
156 //=================================================================================
157 GeometryGUI_SuppressFacesDlg::~GeometryGUI_SuppressFacesDlg()
159 // no need to delete child widgets, Qt does it all for us
164 //=================================================================================
167 //=================================================================================
168 void GeometryGUI_SuppressFacesDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
172 myConstructorId = 0 ;
173 Constructor1->setChecked( TRUE );
174 myEditCurrentArgument = LineEditC1A1 ;
179 myUseLocalContext = false ;
181 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
183 /* Select sub shapes mode not checked */
184 CheckBox1->setChecked( FALSE );
185 myOkSelectSubMode = false ;
187 // TODO : previous selection into argument ?
189 /* Filter definitions */
190 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
191 myGeom = GEOM::GEOM_Gen::_narrow(comp);
193 /* signals and slots connections */
194 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
195 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
196 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) );
197 connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
199 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
200 connect( CheckBox1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserSelection() ));
201 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ));
202 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
203 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnClose() ));
205 /* Move widget on the botton right corner of main widget */
207 myGeomGUI->DefineDlgPosition( this, x, y ) ;
209 this->show() ; /* display Dialog */
214 //=================================================================================
215 // function : ConstructorsClicked()
216 // purpose : Radio button management
217 //=================================================================================
218 void GeometryGUI_SuppressFacesDlg::ConstructorsClicked(int constructorId)
224 //=================================================================================
225 // function : ClickOnOk()
226 // purpose : Same than click on apply but close this dialog.
227 //=================================================================================
228 void GeometryGUI_SuppressFacesDlg::ClickOnOk()
230 this->ClickOnApply() ;
238 //=================================================================================
239 // function : ClickOnApply()
241 //=================================================================================
242 void GeometryGUI_SuppressFacesDlg::ClickOnApply()
244 bool testResult = false ;
245 switch(myConstructorId)
249 if( myOkShape && myOkSelectSubMode ) {
250 testResult = myGeomGUI->OnSuppressFaces( myShape, myShapeIOR, myLocalContextId, myUseLocalContext ) ;
253 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")) ;
256 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_DONE")) ;
258 /* Reset arguments to allow a new selection */
259 this->ResetStateOfDialog() ;
268 //=================================================================================
269 // function : ClickOnClose()
271 //=================================================================================
272 void GeometryGUI_SuppressFacesDlg::ClickOnClose()
274 disconnect( mySelection, 0, this, 0 );
275 myGeomGUI->ResetState() ;
277 if(myUseLocalContext) {
278 myIC->CloseLocalContext(myLocalContextId) ;
279 this->myUseLocalContext = false ;
280 myGeomGUI->OnDisplayAll(true) ;
287 //=================================================================================
288 // function : SelectionIntoArgument()
289 // purpose : Called when selection as changed or other case
290 // : used only by SelectButtonC1A1 (LineEditC1A1)
291 //=================================================================================
292 void GeometryGUI_SuppressFacesDlg::SelectionIntoArgument()
295 /* Reset argument and local context when selection as changed */
296 this->ResetStateOfDialog() ;
298 QString aString = ""; /* name of selection */
300 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
306 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
308 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
311 if( !IO->hasEntry() ) {
312 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")) ;
316 /* Test the exact type of topology to suppress faces into */
317 if ( !S.IsNull() && ( S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND ) ) {
319 if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
320 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
321 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
322 LineEditC1A1->setText(aString) ;
328 if ( IO->hasEntry() ) {
329 SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
330 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
331 SALOMEDS::GenericAttribute_var anAttr;
332 SALOMEDS::AttributeIOR_var anIOR;
333 if ( !obj->_is_nil() ) {
334 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
335 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
336 myShapeIOR = anIOR->Value();
339 LineEditC1A1->setText(aString) ;
350 //=================================================================================
351 // function : SetEditCurrentArgument()
353 //=================================================================================
354 void GeometryGUI_SuppressFacesDlg::SetEditCurrentArgument()
356 QPushButton* send = (QPushButton*)sender();
357 switch (myConstructorId)
359 case 0: /* default constructor */
361 if(send == SelectButtonC1A1) {
362 LineEditC1A1->setFocus() ;
363 myEditCurrentArgument = LineEditC1A1;
364 SelectionIntoArgument() ;
373 //=================================================================================
374 // function : LineEditReturnPressed()
376 //=================================================================================
377 void GeometryGUI_SuppressFacesDlg::LineEditReturnPressed()
383 //=================================================================================
384 // function : DeactivateActiveDialog()
386 //=================================================================================
387 void GeometryGUI_SuppressFacesDlg::DeactivateActiveDialog()
389 if ( GroupConstructors->isEnabled() ) {
391 this->ResetStateOfDialog() ;
393 disconnect( mySelection, 0, this, 0 );
394 GroupConstructors->setEnabled(false) ;
395 GroupC1->setEnabled(false) ;
396 GroupButtons->setEnabled(false) ;
397 myGeomGUI->ResetState() ;
398 myGeomGUI->SetActiveDialogBox(0) ;
399 myGeomGUI->OnDisplayAll(true) ;
405 //=================================================================================
406 // function : ActivateThisDialog()
408 //=================================================================================
409 void GeometryGUI_SuppressFacesDlg::ActivateThisDialog()
411 /* Emit a signal to deactivate other active dialog */
412 myGeomGUI->EmitSignalDeactivateDialog() ;
413 GroupConstructors->setEnabled(true) ;
414 GroupC1->setEnabled(true) ;
415 GroupButtons->setEnabled(true) ;
416 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
417 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
422 //=================================================================================
423 // function : enterEvent()
424 // purpose : Mouse enter onto the dialog to activate it
425 //=================================================================================
426 void GeometryGUI_SuppressFacesDlg::enterEvent(QEvent* e)
428 if ( GroupConstructors->isEnabled() )
430 ActivateThisDialog() ;
435 //=================================================================================
436 // function : closeEvent()
438 //=================================================================================
439 void GeometryGUI_SuppressFacesDlg::closeEvent( QCloseEvent* e )
441 /* same than click on cancel button */
442 this->ClickOnClose() ;
447 //=================================================================================
448 // function : ActivateUserSelection()
449 // purpose : Activate selection of faces when CheckBox1->isChecked()...
450 //=================================================================================
451 void GeometryGUI_SuppressFacesDlg::ActivateUserSelection()
453 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
454 if( !this->myOkShape ) {
455 this->ResetStateOfDialog() ;
456 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")) ;
460 this->myOkSelectSubMode = CheckBox1->isChecked() ;
462 if( this->myUseLocalContext ) {
463 myIC->CloseLocalContext(myLocalContextId) ;
464 this->myUseLocalContext = false ;
465 myGeomGUI->OnDisplayAll(true) ;
468 if( myOkShape && myOkSelectSubMode ) {
469 /* local context is defined into the method : 4 = FACES sub selection */
470 myGeomGUI->PrepareSubShapeSelection( int(TopAbs_FACE), this->myLocalContextId ) ;
471 myUseLocalContext = true ;
472 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FACE")) ;
475 CheckBox1->setChecked( false );
483 //=================================================================================
484 // function : ResetStateOfDialog()
485 // purpose : Completely reset the state of method including local context
486 //=================================================================================
487 void GeometryGUI_SuppressFacesDlg::ResetStateOfDialog()
489 this->myOkShape = false ;
490 this->myEditCurrentArgument->setText("") ;
492 /* Select sub shapes mode not checked */
493 this->myOkSelectSubMode = false ;
494 this->CheckBox1->setChecked( FALSE );
496 /* Close its local contact if opened */
497 if( this->myUseLocalContext ) {
498 myIC->CloseLocalContext(this->myLocalContextId) ;
499 this->myUseLocalContext = false ;
500 myGeomGUI->OnDisplayAll(true) ;