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_SuppressFacesDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "GeometryGUI_SuppressFacesDlg.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 <qcheckbox.h>
39 #include <qgroupbox.h>
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
43 #include <qradiobutton.h>
47 #include <qwhatsthis.h>
51 //=================================================================================
52 // class : GeometryGUI_SuppressFacesDlg()
53 // purpose : Constructs a GeometryGUI_SuppressFacesDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 GeometryGUI_SuppressFacesDlg::GeometryGUI_SuppressFacesDlg( QWidget* parent,
60 SALOME_Selection* Sel,
61 Handle (AIS_InteractiveContext) ic,
64 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
66 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_DLG_SUPRESS_FACE")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GeometryGUI",tr("ICON_SELECT")));
70 setName( "GeometryGUI_SuppressFacesDlg" );
72 setCaption( tr( "GEOM_SUPRESSFACE_TITLE" ) );
73 setSizeGripEnabled( TRUE );
74 GeometryGUI_SuppressFacesDlgLayout = new QGridLayout( this );
75 GeometryGUI_SuppressFacesDlgLayout->setSpacing( 6 );
76 GeometryGUI_SuppressFacesDlgLayout->setMargin( 11 );
78 /***************************************************************/
79 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
80 GroupConstructors->setTitle( tr( "GEOM_SUPRESSFACE" ) );
81 GroupConstructors->setExclusive( TRUE );
82 GroupConstructors->setColumnLayout(0, Qt::Vertical );
83 GroupConstructors->layout()->setSpacing( 0 );
84 GroupConstructors->layout()->setMargin( 0 );
85 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
86 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
87 GroupConstructorsLayout->setSpacing( 6 );
88 GroupConstructorsLayout->setMargin( 11 );
89 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
90 Constructor1->setText( tr( "" ) );
91 Constructor1->setPixmap( image0 );
92 Constructor1->setChecked( TRUE );
93 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
94 Constructor1->setMinimumSize( QSize( 50, 0 ) );
95 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
96 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
97 GroupConstructorsLayout->addItem( spacer, 0, 1 );
98 GeometryGUI_SuppressFacesDlgLayout->addWidget( GroupConstructors, 0, 0 );
100 /***************************************************************/
101 GroupC1 = new QGroupBox( this, "GroupC1" );
102 GroupC1->setTitle( tr( "GEOM_ARGUMENTS" ) );
103 GroupC1->setMinimumSize( QSize( 0, 0 ) );
104 GroupC1->setFrameShape( QGroupBox::Box );
105 GroupC1->setFrameShadow( QGroupBox::Sunken );
106 GroupC1->setColumnLayout(0, Qt::Vertical );
107 GroupC1->layout()->setSpacing( 0 );
108 GroupC1->layout()->setMargin( 0 );
109 GroupC1Layout = new QGridLayout( GroupC1->layout() );
110 GroupC1Layout->setAlignment( Qt::AlignTop );
111 GroupC1Layout->setSpacing( 6 );
112 GroupC1Layout->setMargin( 11 );
113 Layout2 = new QHBoxLayout;
114 Layout2->setSpacing( 6 );
115 Layout2->setMargin( 0 );
116 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
117 TextLabelC1A1->setText( tr( "GEOM_MAIN_OBJECT" ) );
118 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
119 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
120 TextLabelC1A1->setFrameShadow( QLabel::Plain );
121 Layout2->addWidget( TextLabelC1A1 );
122 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
123 SelectButtonC1A1->setText( tr( "" ) );
124 SelectButtonC1A1->setPixmap( image1 );
125 SelectButtonC1A1->setToggleButton( FALSE );
126 SelectButtonC1A1->setMaximumSize( QSize( 28, 32767 ) );
127 Layout2->addWidget( SelectButtonC1A1 );
128 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
129 LineEditC1A1->setAlignment( int( QLineEdit::AlignLeft ) );
130 Layout2->addWidget( LineEditC1A1 );
131 GroupC1Layout->addLayout( Layout2, 0, 0 );
132 CheckBox1 = new QCheckBox( GroupC1, "CheckBox1" );
133 CheckBox1->setText( tr( "GEOM_SUPRESSFACE_SELECT" ) );
134 CheckBox1->setChecked( FALSE );
135 GroupC1Layout->addWidget( CheckBox1, 1, 0 );
136 GeometryGUI_SuppressFacesDlgLayout->addWidget( GroupC1, 1, 0 );
138 /***************************************************************/
139 GroupButtons = new QGroupBox( this, "GroupButtons" );
140 GroupButtons->setTitle( tr( "" ) );
141 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)5, GroupButtons->sizePolicy().hasHeightForWidth() ) );
142 GroupButtons->setColumnLayout(0, Qt::Vertical );
143 GroupButtons->layout()->setSpacing( 0 );
144 GroupButtons->layout()->setMargin( 0 );
145 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
146 GroupButtonsLayout->setAlignment( Qt::AlignTop );
147 GroupButtonsLayout->setSpacing( 6 );
148 GroupButtonsLayout->setMargin( 11 );
150 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
151 buttonOk->setText( tr( "GEOM_BUT_OK" ) );
152 buttonOk->setAutoDefault( TRUE );
153 buttonOk->setDefault( TRUE );
154 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
155 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
156 buttonApply->setText( tr( "GEOM_BUT_APPLY" ) );
157 buttonApply->setAutoDefault( TRUE );
158 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
159 QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
160 GroupButtonsLayout->addItem( spacer_2, 0, 2 );
161 buttonClose = new QPushButton( GroupButtons, "buttonClose" );
162 buttonClose->setText( tr( "GEOM_BUT_CLOSE" ) );
163 buttonClose->setAutoDefault( TRUE );
164 GroupButtonsLayout->addWidget( buttonClose, 0, 3 );
165 GeometryGUI_SuppressFacesDlgLayout->addWidget( GroupButtons, 2, 0 );
167 /* Initialisations */
173 //=================================================================================
174 // function : ~GeometryGUI_SuppressFacesDlg()
175 // purpose : Destroys the object and frees any allocated resources
176 //=================================================================================
177 GeometryGUI_SuppressFacesDlg::~GeometryGUI_SuppressFacesDlg()
179 // no need to delete child widgets, Qt does it all for us
184 //=================================================================================
187 //=================================================================================
188 void GeometryGUI_SuppressFacesDlg::Init( SALOME_Selection* Sel, Handle (AIS_InteractiveContext) ic )
192 myConstructorId = 0 ;
193 Constructor1->setChecked( TRUE );
194 myEditCurrentArgument = LineEditC1A1 ;
199 myUseLocalContext = false ;
201 myGeomGUI = GeometryGUI::GetGeometryGUI() ;
203 /* Select sub shapes mode not checked */
204 CheckBox1->setChecked( FALSE );
205 myOkSelectSubMode = false ;
207 // TODO : previous selection into argument ?
209 /* Filter definitions */
210 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "Geometry");
211 myGeom = GEOM::GEOM_Gen::_narrow(comp);
213 /* signals and slots connections */
214 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
215 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
216 connect( buttonClose, SIGNAL( clicked() ), this, SLOT( ClickOnClose() ) );
217 connect( GroupConstructors, SIGNAL( clicked(int) ), this, SLOT( ConstructorsClicked(int) ));
219 connect( SelectButtonC1A1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ));
220 connect( CheckBox1, SIGNAL( stateChanged(int) ), this, SLOT( ActivateUserSelection() ));
221 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ));
222 connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
223 connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( ClickOnClose() ));
225 /* Move widget on the botton right corner of main widget */
227 myGeomGUI->DefineDlgPosition( this, x, y ) ;
229 this->show() ; /* display Dialog */
234 //=================================================================================
235 // function : ConstructorsClicked()
236 // purpose : Radio button management
237 //=================================================================================
238 void GeometryGUI_SuppressFacesDlg::ConstructorsClicked(int constructorId)
244 //=================================================================================
245 // function : ClickOnOk()
246 // purpose : Same than click on apply but close this dialog.
247 //=================================================================================
248 void GeometryGUI_SuppressFacesDlg::ClickOnOk()
250 this->ClickOnApply() ;
258 //=================================================================================
259 // function : ClickOnApply()
261 //=================================================================================
262 void GeometryGUI_SuppressFacesDlg::ClickOnApply()
264 bool testResult = false ;
265 switch(myConstructorId)
269 if( myOkShape && myOkSelectSubMode ) {
270 testResult = myGeomGUI->OnSuppressFaces( myShape, myShapeIOR, myLocalContextId, myUseLocalContext ) ;
273 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_ABORT")) ;
276 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_DONE")) ;
278 /* Reset arguments to allow a new selection */
279 this->ResetStateOfDialog() ;
288 //=================================================================================
289 // function : ClickOnClose()
291 //=================================================================================
292 void GeometryGUI_SuppressFacesDlg::ClickOnClose()
294 disconnect( mySelection, 0, this, 0 );
295 myGeomGUI->ResetState() ;
297 if(myUseLocalContext) {
298 myIC->CloseLocalContext(myLocalContextId) ;
299 this->myUseLocalContext = false ;
300 myGeomGUI->OnDisplayAll(true) ;
307 //=================================================================================
308 // function : SelectionIntoArgument()
309 // purpose : Called when selection as changed or other case
310 // : used only by SelectButtonC1A1 (LineEditC1A1)
311 //=================================================================================
312 void GeometryGUI_SuppressFacesDlg::SelectionIntoArgument()
315 /* Reset argument and local context when selection as changed */
316 this->ResetStateOfDialog() ;
318 QString aString = ""; /* name of selection */
320 int nbSel = myGeomGUI->GetNameOfSelectedIObjects(mySelection, aString) ;
326 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
328 if( !myGeomGUI->GetTopoFromSelection(mySelection, S) )
331 if( !IO->hasEntry() ) {
332 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY")) ;
336 /* Test the exact type of topology to suppress faces into */
337 if ( !S.IsNull() && ( S.ShapeType() == TopAbs_SOLID || S.ShapeType() == TopAbs_SHELL || S.ShapeType() == TopAbs_COMPOUND ) ) {
339 if ( IO->IsInstance(STANDARD_TYPE(GEOM_InteractiveObject)) ) {
340 Handle(GEOM_InteractiveObject) GIObject = Handle(GEOM_InteractiveObject)::DownCast( IO );
341 myShapeIOR = GIObject->getIOR(); /* the Geom IOR string of selection */
342 LineEditC1A1->setText(aString) ;
348 if ( IO->hasEntry() ) {
349 SALOMEDS::Study_var aStudy = myGeomGUI->GetActiveStudy()->getStudyDocument();
350 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IO->getEntry() );
351 SALOMEDS::GenericAttribute_var anAttr;
352 SALOMEDS::AttributeIOR_var anIOR;
353 if ( !obj->_is_nil() ) {
354 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
355 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
356 myShapeIOR = anIOR->Value();
359 LineEditC1A1->setText(aString) ;
370 //=================================================================================
371 // function : SetEditCurrentArgument()
373 //=================================================================================
374 void GeometryGUI_SuppressFacesDlg::SetEditCurrentArgument()
376 QPushButton* send = (QPushButton*)sender();
377 switch (myConstructorId)
379 case 0: /* default constructor */
381 if(send == SelectButtonC1A1) {
382 LineEditC1A1->setFocus() ;
383 myEditCurrentArgument = LineEditC1A1;
384 SelectionIntoArgument() ;
393 //=================================================================================
394 // function : LineEditReturnPressed()
396 //=================================================================================
397 void GeometryGUI_SuppressFacesDlg::LineEditReturnPressed()
403 //=================================================================================
404 // function : DeactivateActiveDialog()
406 //=================================================================================
407 void GeometryGUI_SuppressFacesDlg::DeactivateActiveDialog()
409 if ( GroupConstructors->isEnabled() ) {
411 this->ResetStateOfDialog() ;
413 disconnect( mySelection, 0, this, 0 );
414 GroupConstructors->setEnabled(false) ;
415 GroupC1->setEnabled(false) ;
416 GroupButtons->setEnabled(false) ;
417 myGeomGUI->ResetState() ;
418 myGeomGUI->SetActiveDialogBox(0) ;
419 myGeomGUI->OnDisplayAll(true) ;
425 //=================================================================================
426 // function : ActivateThisDialog()
428 //=================================================================================
429 void GeometryGUI_SuppressFacesDlg::ActivateThisDialog()
431 /* Emit a signal to deactivate other active dialog */
432 myGeomGUI->EmitSignalDeactivateDialog() ;
433 GroupConstructors->setEnabled(true) ;
434 GroupC1->setEnabled(true) ;
435 GroupButtons->setEnabled(true) ;
436 connect ( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
437 myGeomGUI->SetActiveDialogBox( (QDialog*)this ) ;
442 //=================================================================================
443 // function : enterEvent()
444 // purpose : Mouse enter onto the dialog to activate it
445 //=================================================================================
446 void GeometryGUI_SuppressFacesDlg::enterEvent(QEvent* e)
448 if ( GroupConstructors->isEnabled() )
450 ActivateThisDialog() ;
455 //=================================================================================
456 // function : closeEvent()
458 //=================================================================================
459 void GeometryGUI_SuppressFacesDlg::closeEvent( QCloseEvent* e )
461 /* same than click on cancel button */
462 this->ClickOnClose() ;
467 //=================================================================================
468 // function : ActivateUserSelection()
469 // purpose : Activate selection of faces when CheckBox1->isChecked()...
470 //=================================================================================
471 void GeometryGUI_SuppressFacesDlg::ActivateUserSelection()
473 if ( myGeomGUI->GetActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
474 if( !this->myOkShape ) {
475 this->ResetStateOfDialog() ;
476 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FIRST")) ;
480 this->myOkSelectSubMode = CheckBox1->isChecked() ;
482 if( this->myUseLocalContext ) {
483 myIC->CloseLocalContext(myLocalContextId) ;
484 this->myUseLocalContext = false ;
485 myGeomGUI->OnDisplayAll(true) ;
488 if( myOkShape && myOkSelectSubMode ) {
489 /* local context is defined into the method : 4 = FACES sub selection */
490 myGeomGUI->PrepareSubShapeSelection( int(TopAbs_FACE), this->myLocalContextId ) ;
491 myUseLocalContext = true ;
492 myGeomGUI->GetDesktop()->putInfo(tr("GEOM_PRP_SELECT_FACE")) ;
495 CheckBox1->setChecked( false );
503 //=================================================================================
504 // function : ResetStateOfDialog()
505 // purpose : Completely reset the state of method including local context
506 //=================================================================================
507 void GeometryGUI_SuppressFacesDlg::ResetStateOfDialog()
509 this->myOkShape = false ;
510 this->myEditCurrentArgument->setText("") ;
512 /* Select sub shapes mode not checked */
513 this->myOkSelectSubMode = false ;
514 this->CheckBox1->setChecked( FALSE );
516 /* Close its local contact if opened */
517 if( this->myUseLocalContext ) {
518 myIC->CloseLocalContext(this->myLocalContextId) ;
519 this->myUseLocalContext = false ;
520 myGeomGUI->OnDisplayAll(true) ;