2 // File : SMESHGUI_RemoveNodesDlg.cxx
3 // Created : Fri Jun 07 11:18:31 2002
4 // Author : Nicolas REJNERI
8 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_RemoveNodesDlg.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_RemoveNodesDlg()
37 //=================================================================================
38 SMESHGUI_RemoveNodesDlg::SMESHGUI_RemoveNodesDlg( 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_NODE")));
43 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
46 setName( "SMESHGUI_RemoveNodesDlg" );
48 setCaption( tr( "SMESH_REMOVE_NODES_TITLE" ) );
49 setSizeGripEnabled( TRUE );
50 SMESHGUI_RemoveNodesDlgLayout = new QGridLayout( this );
51 SMESHGUI_RemoveNodesDlgLayout->setSpacing( 6 );
52 SMESHGUI_RemoveNodesDlgLayout->setMargin( 11 );
54 /***************************************************************/
55 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
56 GroupConstructors->setTitle( tr( "SMESH_NODES" ) );
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_RemoveNodesDlgLayout->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_RemoveNodesDlgLayout->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_NODES" ) );
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_RemoveNodesDlgLayout->addWidget( GroupC1, 1, 0 );
132 Init(Sel) ; /* Initialisations */
135 //=================================================================================
136 // function : ~SMESHGUI_RemoveNodesDlg()
137 // purpose : Destroys the object and frees any allocated resources
138 //=================================================================================
139 SMESHGUI_RemoveNodesDlg::~SMESHGUI_RemoveNodesDlg()
141 // no need to delete child widgets, Qt does it all for us
145 //=================================================================================
148 //=================================================================================
149 void SMESHGUI_RemoveNodesDlg::Init( SALOME_Selection* Sel )
153 myConstructorId = 0 ;
154 Constructor1->setChecked( TRUE );
155 myEditCurrentArgument = LineEditC1A1 ;
157 this->myOkNodes = 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 */
179 SelectionIntoArgument();
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void SMESHGUI_RemoveNodesDlg::ConstructorsClicked(int constructorId)
194 //=================================================================================
195 // function : ClickOnApply()
197 //=================================================================================
198 void SMESHGUI_RemoveNodesDlg::ClickOnApply()
200 switch(myConstructorId)
205 mySMESHGUI->EraseSimulationActors();
206 mySMESHGUI->RemoveNodes( myMesh, myMapIndex ) ;
207 mySMESHGUI->ViewNodes();
208 mySelection->ClearIObjects();
216 //=================================================================================
217 // function : ClickOnOk()
219 //=================================================================================
220 void SMESHGUI_RemoveNodesDlg::ClickOnOk()
222 this->ClickOnApply() ;
223 this->ClickOnCancel() ;
229 //=================================================================================
230 // function : ClickOnCancel()
232 //=================================================================================
233 void SMESHGUI_RemoveNodesDlg::ClickOnCancel()
235 QAD_Application::getDesktop()->SetSelectionMode( 4 );
236 disconnect( mySelection, 0, this, 0 );
237 mySMESHGUI->ResetState() ;
238 mySMESHGUI->EraseSimulationActors();
244 //=================================================================================
245 // function : SelectionIntoArgument()
246 // purpose : Called when selection as changed or other case
247 //=================================================================================
248 void SMESHGUI_RemoveNodesDlg::SelectionIntoArgument()
250 myEditCurrentArgument->setText("") ;
252 QString aString = "";
254 int nbSel = mySelection->IObjectCount();
258 int nbNodes = mySMESHGUI->GetNameOfSelectedNodes(mySelection, aString) ;
262 if ( mySelection->SelectionMode() != 1 ){
263 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
264 tr ("SMESH_WRN_SELECTIONMODE_NODES"), tr ("SMESH_BUT_YES") );
268 myEditCurrentArgument->setText(aString) ;
269 Standard_Boolean res;
270 myMesh = mySMESHGUI->ConvertIOinMesh( mySelection->firstIObject(), res );
274 mySelection->GetIndex( mySelection->firstIObject(), myMapIndex);
281 //=================================================================================
282 // function : SetEditCurrentArgument()
284 //=================================================================================
285 void SMESHGUI_RemoveNodesDlg::SetEditCurrentArgument()
287 QPushButton* send = (QPushButton*)sender();
288 switch (myConstructorId)
290 case 0: /* default constructor */
292 if(send == SelectButtonC1A1) {
293 LineEditC1A1->setFocus() ;
294 myEditCurrentArgument = LineEditC1A1;
296 SelectionIntoArgument() ;
303 //=================================================================================
304 // function : DeactivateActiveDialog()
306 //=================================================================================
307 void SMESHGUI_RemoveNodesDlg::DeactivateActiveDialog()
309 if ( GroupConstructors->isEnabled() ) {
310 GroupConstructors->setEnabled(false) ;
311 GroupC1->setEnabled(false) ;
312 GroupButtons->setEnabled(false) ;
313 mySMESHGUI->EraseSimulationActors() ;
314 mySMESHGUI->ResetState() ;
315 mySMESHGUI->SetActiveDialogBox(0) ;
321 //=================================================================================
322 // function : ActivateThisDialog()
324 //=================================================================================
325 void SMESHGUI_RemoveNodesDlg::ActivateThisDialog()
327 /* Emit a signal to deactivate the active dialog */
328 mySMESHGUI->EmitSignalDeactivateDialog() ;
329 GroupConstructors->setEnabled(true) ;
330 GroupC1->setEnabled(true) ;
331 GroupButtons->setEnabled(true) ;
333 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
338 //=================================================================================
339 // function : enterEvent()
341 //=================================================================================
342 void SMESHGUI_RemoveNodesDlg::enterEvent(QEvent* e)
344 if ( GroupConstructors->isEnabled() )
346 ActivateThisDialog() ;
351 //=================================================================================
352 // function : closeEvent()
354 //=================================================================================
355 void SMESHGUI_RemoveNodesDlg::closeEvent( QCloseEvent* e )
357 /* same than click on cancel button */
358 this->ClickOnCancel() ;