1 // SMESH SMESHGUI : GUI for SMESH 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 : SMESHGUI_RenumberingDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_RenumberingDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESH_Actor.h"
35 #include "SMDS_Mesh.hxx"
37 #include "QAD_Application.h"
38 #include "QAD_Desktop.h"
39 #include "QAD_MessageBox.h"
40 #include "utilities.h"
43 #include <qapplication.h>
44 #include <qbuttongroup.h>
45 #include <qgroupbox.h>
47 #include <qlineedit.h>
48 #include <qpushbutton.h>
49 #include <qradiobutton.h>
55 //=================================================================================
56 // class : SMESHGUI_RenumberingDlg()
58 //=================================================================================
59 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
60 const int unit, bool modal, WFlags fl )
61 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
62 Qt::WDestructiveClose)
67 setName( "SMESHGUI_RenumberingDlg" );
72 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
75 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_RENUMBERING_NODES")));
76 setCaption( tr( "SMESH_RENUMBERING_NODES_TITLE" ) );
79 image0 = QPixmap(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_DLG_RENUMBERING_ELEMENTS")));
80 setCaption( tr( "SMESH_RENUMBERING_ELEMENTS_TITLE" ) );
83 setSizeGripEnabled( TRUE );
84 SMESHGUI_RenumberingDlgLayout = new QGridLayout( this );
85 SMESHGUI_RenumberingDlgLayout->setSpacing( 6 );
86 SMESHGUI_RenumberingDlgLayout->setMargin( 11 );
88 /***************************************************************/
89 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
91 GroupConstructors->setTitle( tr( "SMESH_NODES" ) );
93 GroupConstructors->setTitle( tr( "SMESH_ELEMENTS" ) );
94 GroupConstructors->setExclusive( TRUE );
95 GroupConstructors->setColumnLayout(0, Qt::Vertical );
96 GroupConstructors->layout()->setSpacing( 0 );
97 GroupConstructors->layout()->setMargin( 0 );
98 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
99 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
100 GroupConstructorsLayout->setSpacing( 6 );
101 GroupConstructorsLayout->setMargin( 11 );
102 Constructor1 = new QRadioButton( GroupConstructors, "Constructor1" );
103 Constructor1->setText( tr( "" ) );
104 Constructor1->setPixmap( image0 );
105 Constructor1->setChecked( TRUE );
106 Constructor1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth() ) );
107 Constructor1->setMinimumSize( QSize( 50, 0 ) );
108 GroupConstructorsLayout->addWidget( Constructor1, 0, 0 );
109 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
110 GroupConstructorsLayout->addItem( spacer, 0, 1 );
111 SMESHGUI_RenumberingDlgLayout->addWidget( GroupConstructors, 0, 0 );
113 /***************************************************************/
114 GroupButtons = new QGroupBox( this, "GroupButtons" );
115 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
116 GroupButtons->setTitle( tr( "" ) );
117 GroupButtons->setColumnLayout(0, Qt::Vertical );
118 GroupButtons->layout()->setSpacing( 0 );
119 GroupButtons->layout()->setMargin( 0 );
120 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
121 GroupButtonsLayout->setAlignment( Qt::AlignTop );
122 GroupButtonsLayout->setSpacing( 6 );
123 GroupButtonsLayout->setMargin( 11 );
124 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
125 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
126 buttonCancel->setAutoDefault( TRUE );
127 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
128 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
129 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
130 buttonApply->setAutoDefault( TRUE );
131 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
132 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
133 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
134 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
135 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
136 buttonOk->setAutoDefault( TRUE );
137 buttonOk->setDefault( TRUE );
138 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
139 SMESHGUI_RenumberingDlgLayout->addWidget( GroupButtons, 2, 0 );
141 /***************************************************************/
142 GroupMesh = new QGroupBox( this, "GroupMesh" );
143 GroupMesh->setTitle( tr( "SMESH_RENUMBERING" ) );
144 GroupMesh->setMinimumSize( QSize( 0, 0 ) );
145 GroupMesh->setFrameShape( QGroupBox::Box );
146 GroupMesh->setFrameShadow( QGroupBox::Sunken );
147 GroupMesh->setColumnLayout(0, Qt::Vertical );
148 GroupMesh->layout()->setSpacing( 0 );
149 GroupMesh->layout()->setMargin( 0 );
150 GroupMeshLayout = new QGridLayout( GroupMesh->layout() );
151 GroupMeshLayout->setAlignment( Qt::AlignTop );
152 GroupMeshLayout->setSpacing( 6 );
153 GroupMeshLayout->setMargin( 11 );
154 TextLabelMesh = new QLabel( GroupMesh, "TextLabelMesh" );
155 TextLabelMesh->setText( tr( "SMESH_MESH" ) );
156 TextLabelMesh->setMinimumSize( QSize( 50, 0 ) );
157 TextLabelMesh->setFrameShape( QLabel::NoFrame );
158 TextLabelMesh->setFrameShadow( QLabel::Plain );
159 GroupMeshLayout->addWidget( TextLabelMesh, 0, 0 );
160 SelectButton = new QPushButton( GroupMesh, "SelectButton" );
161 SelectButton->setText( tr( "" ) );
162 SelectButton->setPixmap( image1 );
163 SelectButton->setToggleButton( FALSE );
164 GroupMeshLayout->addWidget( SelectButton, 0, 1 );
165 LineEditMesh = new QLineEdit( GroupMesh, "LineEditMesh" );
166 LineEditMesh->setReadOnly( true );
167 GroupMeshLayout->addWidget( LineEditMesh, 0, 2 );
168 SMESHGUI_RenumberingDlgLayout->addWidget( GroupMesh, 1, 0 );
170 Init(Sel) ; /* Initialisations */
173 //=================================================================================
174 // function : ~SMESHGUI_RenumberingDlg()
175 // purpose : Destroys the object and frees any allocated resources
176 //=================================================================================
177 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
179 // no need to delete child widgets, Qt does it all for us
183 //=================================================================================
186 //=================================================================================
187 void SMESHGUI_RenumberingDlg::Init( SALOME_Selection* Sel )
191 myConstructorId = 0 ;
192 Constructor1->setChecked( TRUE );
194 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
195 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
197 myMesh = SMESH::SMESH_Mesh::_nil();
199 myMeshFilter = new SMESH_TypeFilter( MESH );
201 /* signals and slots connections */
202 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
203 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
204 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
205 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
207 connect( SelectButton, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
208 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
209 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
210 /* to close dialog if study change */
211 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
213 /* Move widget on the botton right corner of main widget */
215 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
217 this->show() ; /* displays Dialog */
219 myEditCurrentArgument = LineEditMesh ;
220 LineEditMesh->setFocus();
221 mySelection->ClearFilters() ;
222 mySelection->AddFilter( myMeshFilter ) ;
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : ConstructorsClicked()
230 // purpose : Radio button management
231 //=================================================================================
232 void SMESHGUI_RenumberingDlg::ConstructorsClicked(int constructorId)
238 //=================================================================================
239 // function : ClickOnApply()
241 //=================================================================================
242 void SMESHGUI_RenumberingDlg::ClickOnApply()
244 if (mySMESHGUI->ActiveStudyLocked())
247 if ( !myMesh->_is_nil())
251 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
252 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
253 bool isUnitsLabeled = false;
255 if (myUnit == 0 && anActor) {
256 isUnitsLabeled = anActor->GetPointsLabeled();
257 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
259 else if (myUnit == 1 && anActor) {
260 isUnitsLabeled = anActor->GetCellsLabeled();
261 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
264 QApplication::setOverrideCursor(Qt::waitCursor);
266 aMeshEditor->RenumberNodes();
267 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
269 else if (myUnit == 1) {
270 aMeshEditor->RenumberElements();
271 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
273 QApplication::restoreOverrideCursor();
279 mySelection->ClearIObjects();
284 //=================================================================================
285 // function : ClickOnOk()
287 //=================================================================================
288 void SMESHGUI_RenumberingDlg::ClickOnOk()
295 //=================================================================================
296 // function : ClickOnCancel()
298 //=================================================================================
299 void SMESHGUI_RenumberingDlg::ClickOnCancel()
301 mySelection->ClearIObjects();
302 mySelection->ClearFilters();
303 disconnect( mySelection, 0, this, 0 );
304 mySMESHGUI->ResetState() ;
309 //=================================================================================
310 // function : SelectionIntoArgument()
311 // purpose : Called when selection as changed or other case
312 //=================================================================================
313 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
315 if ( !GroupButtons->isEnabled() ) // inactive
318 QString aString = "";
320 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString) ;
322 if ( myEditCurrentArgument == LineEditMesh ) {
325 myMesh = SMESH::SMESH_Mesh::_nil();
329 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
330 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
331 if( myMesh->_is_nil() )
336 myEditCurrentArgument->setText(aString) ;
338 bool isEnabled = (!myMesh->_is_nil());
339 buttonOk->setEnabled( isEnabled );
340 buttonApply->setEnabled( isEnabled );
344 //=================================================================================
345 // function : SetEditCurrentArgument()
347 //=================================================================================
348 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
350 QPushButton* send = (QPushButton*)sender();
351 switch (myConstructorId)
353 case 0: /* default constructor */
355 if(send == SelectButton) {
356 LineEditMesh->setFocus() ;
357 myEditCurrentArgument = LineEditMesh;
359 SelectionIntoArgument() ;
365 //=================================================================================
366 // function : DeactivateActiveDialog()
368 //=================================================================================
369 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
371 if ( GroupConstructors->isEnabled() ) {
372 GroupConstructors->setEnabled(false) ;
373 GroupMesh->setEnabled(false) ;
374 GroupButtons->setEnabled(false) ;
375 mySMESHGUI->ResetState() ;
376 mySMESHGUI->SetActiveDialogBox(0) ;
381 //=================================================================================
382 // function : ActivateThisDialog()
384 //=================================================================================
385 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
387 /* Emit a signal to deactivate the active dialog */
388 mySMESHGUI->EmitSignalDeactivateDialog() ;
389 GroupConstructors->setEnabled(true) ;
390 GroupMesh->setEnabled(true) ;
391 GroupButtons->setEnabled(true) ;
393 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
394 SelectionIntoArgument();
398 //=================================================================================
399 // function : enterEvent()
401 //=================================================================================
402 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
404 if ( GroupConstructors->isEnabled() )
406 ActivateThisDialog() ;
410 //=================================================================================
411 // function : closeEvent()
413 //=================================================================================
414 void SMESHGUI_RenumberingDlg::closeEvent( QCloseEvent* e )
416 /* same than click on cancel button */
417 this->ClickOnCancel() ;
421 //=======================================================================
422 //function : hideEvent
423 //purpose : caused by ESC key
424 //=======================================================================
426 void SMESHGUI_RenumberingDlg::hideEvent ( QHideEvent * e )
428 if ( !isMinimized() )