2 // File : SMESHGUI_RemoveElementsDlg.cxx
3 // Created : Fri Jun 07 11:18:31 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_RemoveElementsDlg.h"
14 #include "QAD_Application.h"
15 #include "QAD_Desktop.h"
16 #include "QAD_MessageBox.h"
17 #include "utilities.h"
20 #include <qbuttongroup.h>
21 #include <qgroupbox.h>
23 #include <qlineedit.h>
24 #include <qpushbutton.h>
25 #include <qradiobutton.h>
29 #include <qwhatsthis.h>
34 //=================================================================================
35 // class : SMESHGUI_RemoveElementsDlg()
37 //=================================================================================
38 SMESHGUI_RemoveElementsDlg::SMESHGUI_RemoveElementsDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
39 bool modal, WFlags fl )
40 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
42 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_REM_ELEMENT")));
43 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
46 setName( "SMESHGUI_RemoveElementsDlg" );
48 setCaption( tr( "SMESH_REMOVE_ELEMENTS_TITLE" ) );
49 setSizeGripEnabled( TRUE );
50 SMESHGUI_RemoveElementsDlgLayout = new QGridLayout( this );
51 SMESHGUI_RemoveElementsDlgLayout->setSpacing( 6 );
52 SMESHGUI_RemoveElementsDlgLayout->setMargin( 11 );
54 /***************************************************************/
55 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
56 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS" ) );
57 GroupConstructors->setExclusive( TRUE );
58 GroupConstructors->setColumnLayout(0, Qt::Vertical );
59 GroupConstructors->layout()->setSpacing( 0 );
60 GroupConstructors->layout()->setMargin( 0 );
61 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
62 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
63 GroupConstructorsLayout->setSpacing( 6 );
64 GroupConstructorsLayout->setMargin( 11 );
65 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
66 Constructor1->setText( tr( "" ) );
67 Constructor1->setPixmap( image0 );
68 Constructor1->setChecked( TRUE );
69 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
70 Constructor1->setMinimumSize( QSize( 50, 0 ) );
71 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
72 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
73 GroupConstructorsLayout->addItem( spacer, 0, 1 );
74 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupConstructors, 0, 0 );
76 /***************************************************************/
77 GroupButtons = new QGroupBox( this, "GroupButtons" );
78 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
79 GroupButtons->setTitle( tr( "" ) );
80 GroupButtons->setColumnLayout(0, Qt::Vertical );
81 GroupButtons->layout()->setSpacing( 0 );
82 GroupButtons->layout()->setMargin( 0 );
83 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
84 GroupButtonsLayout->setAlignment( Qt::AlignTop );
85 GroupButtonsLayout->setSpacing( 6 );
86 GroupButtonsLayout->setMargin( 11 );
87 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
88 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
89 buttonCancel->setAutoDefault( TRUE );
90 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
91 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
92 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
93 buttonApply->setAutoDefault( TRUE );
94 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
95 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
96 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
97 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
98 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
99 buttonOk->setAutoDefault( TRUE );
100 buttonOk->setDefault( TRUE );
101 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
102 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupButtons, 2, 0 );
104 /***************************************************************/
105 GroupC1 = new QGroupBox( this, "GroupC1" );
106 GroupC1->setTitle( tr( "SMESH_REMOVE" ) );
107 GroupC1->setMinimumSize( QSize( 0, 0 ) );
108 GroupC1->setFrameShape( QGroupBox::Box );
109 GroupC1->setFrameShadow( QGroupBox::Sunken );
110 GroupC1->setColumnLayout(0, Qt::Vertical );
111 GroupC1->layout()->setSpacing( 0 );
112 GroupC1->layout()->setMargin( 0 );
113 GroupC1Layout = new QGridLayout( GroupC1->layout() );
114 GroupC1Layout->setAlignment( Qt::AlignTop );
115 GroupC1Layout->setSpacing( 6 );
116 GroupC1Layout->setMargin( 11 );
117 TextLabelC1A1 = new QLabel( GroupC1, "TextLabelC1A1" );
118 TextLabelC1A1->setText( tr( "SMESH_ID_ELEMENTS" ) );
119 TextLabelC1A1->setMinimumSize( QSize( 50, 0 ) );
120 TextLabelC1A1->setFrameShape( QLabel::NoFrame );
121 TextLabelC1A1->setFrameShadow( QLabel::Plain );
122 GroupC1Layout->addWidget( TextLabelC1A1, 0, 0 );
123 SelectButtonC1A1 = new QPushButton( GroupC1, "SelectButtonC1A1" );
124 SelectButtonC1A1->setText( tr( "" ) );
125 SelectButtonC1A1->setPixmap( image1 );
126 SelectButtonC1A1->setToggleButton( FALSE );
127 GroupC1Layout->addWidget( SelectButtonC1A1, 0, 1 );
128 LineEditC1A1 = new QLineEdit( GroupC1, "LineEditC1A1" );
129 GroupC1Layout->addWidget( LineEditC1A1, 0, 2 );
130 SMESHGUI_RemoveElementsDlgLayout->addWidget( GroupC1, 1, 0 );
132 Init(Sel) ; /* Initialisations */
135 //=================================================================================
136 // function : ~SMESHGUI_RemoveElementsDlg()
137 // purpose : Destroys the object and frees any allocated resources
138 //=================================================================================
139 SMESHGUI_RemoveElementsDlg::~SMESHGUI_RemoveElementsDlg()
141 // no need to delete child widgets, Qt does it all for us
145 //=================================================================================
148 //=================================================================================
149 void SMESHGUI_RemoveElementsDlg::Init( SALOME_Selection* Sel )
153 myConstructorId = 0 ;
154 Constructor1->setChecked( TRUE );
155 myEditCurrentArgument = LineEditC1A1 ;
157 this->myOkElements = false ;
158 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
159 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
161 /* signals and slots connections */
162 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
163 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
164 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
165 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
167 connect( SelectButtonC1A1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
168 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
169 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
170 /* to close dialog if study change */
171 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
173 /* Move widget on the botton right corner of main widget */
175 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
177 this->show() ; /* displays Dialog */
183 //=================================================================================
184 // function : ConstructorsClicked()
185 // purpose : Radio button management
186 //=================================================================================
187 void SMESHGUI_RemoveElementsDlg::ConstructorsClicked(int constructorId)
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 void SMESHGUI_RemoveElementsDlg::ClickOnApply()
199 switch(myConstructorId)
204 mySMESHGUI->RemoveElements( myMesh, myMapIndex ) ;
205 mySelection->ClearIObjects();
213 //=================================================================================
214 // function : ClickOnOk()
216 //=================================================================================
217 void SMESHGUI_RemoveElementsDlg::ClickOnOk()
219 this->ClickOnApply() ;
220 this->ClickOnCancel() ;
225 //=================================================================================
226 // function : ClickOnCancel()
228 //=================================================================================
229 void SMESHGUI_RemoveElementsDlg::ClickOnCancel()
231 QAD_Application::getDesktop()->SetSelectionMode( 4 );
232 disconnect( mySelection, 0, this, 0 );
233 mySMESHGUI->ResetState() ;
239 //=================================================================================
240 // function : SelectionIntoArgument()
241 // purpose : Called when selection as changed or other case
242 //=================================================================================
243 void SMESHGUI_RemoveElementsDlg::SelectionIntoArgument()
245 myEditCurrentArgument->setText("") ;
246 myOkElements = false;
247 QString aString = "";
249 int nbSel = mySelection->IObjectCount();
253 int nbElements = mySMESHGUI->GetNameOfSelectedElements(mySelection, aString) ;
257 if ( mySelection->SelectionMode() != 3 ) {
258 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
259 tr ("SMESH_WRN_SELECTIONMODE_ELEMENTS"), tr ("SMESH_BUT_YES") );
263 myEditCurrentArgument->setText(aString) ;
264 Standard_Boolean res;
265 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
269 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
270 myOkElements = true ;
275 //=================================================================================
276 // function : SetEditCurrentArgument()
278 //=================================================================================
279 void SMESHGUI_RemoveElementsDlg::SetEditCurrentArgument()
281 QPushButton* send = (QPushButton*)sender();
282 switch (myConstructorId)
284 case 0: /* default constructor */
286 if(send == SelectButtonC1A1) {
287 LineEditC1A1->setFocus() ;
288 myEditCurrentArgument = LineEditC1A1;
290 SelectionIntoArgument() ;
297 //=================================================================================
298 // function : DeactivateActiveDialog()
300 //=================================================================================
301 void SMESHGUI_RemoveElementsDlg::DeactivateActiveDialog()
303 if ( GroupConstructors->isEnabled() ) {
304 GroupConstructors->setEnabled(false) ;
305 GroupC1->setEnabled(false) ;
306 GroupButtons->setEnabled(false) ;
312 //=================================================================================
313 // function : ActivateThisDialog()
315 //=================================================================================
316 void SMESHGUI_RemoveElementsDlg::ActivateThisDialog()
318 /* Emit a signal to deactivate the active dialog */
319 mySMESHGUI->EmitSignalDeactivateDialog() ;
320 GroupConstructors->setEnabled(true) ;
321 GroupC1->setEnabled(true) ;
322 GroupButtons->setEnabled(true) ;
327 //=================================================================================
328 // function : enterEvent()
330 //=================================================================================
331 void SMESHGUI_RemoveElementsDlg::enterEvent(QEvent* e)
333 if ( GroupConstructors->isEnabled() )
335 ActivateThisDialog() ;
340 //=================================================================================
341 // function : closeEvent()
343 //=================================================================================
344 void SMESHGUI_RemoveElementsDlg::closeEvent( QCloseEvent* e )
346 /* same than click on cancel button */
347 this->ClickOnCancel() ;