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())
249 bool aResult = false;
252 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
253 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
254 bool isUnitsLabeled = false;
256 if (myUnit == 0 && anActor) {
257 isUnitsLabeled = anActor->GetPointsLabeled();
258 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
260 else if (myUnit == 1 && anActor) {
261 isUnitsLabeled = anActor->GetCellsLabeled();
262 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
265 QApplication::setOverrideCursor(Qt::waitCursor);
267 aMeshEditor->RenumberNodes();
268 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
270 else if (myUnit == 1) {
271 aMeshEditor->RenumberElements();
272 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
274 QApplication::restoreOverrideCursor();
280 mySelection->ClearIObjects();
285 //=================================================================================
286 // function : ClickOnOk()
288 //=================================================================================
289 void SMESHGUI_RenumberingDlg::ClickOnOk()
296 //=================================================================================
297 // function : ClickOnCancel()
299 //=================================================================================
300 void SMESHGUI_RenumberingDlg::ClickOnCancel()
302 mySelection->ClearIObjects();
303 mySelection->ClearFilters();
304 disconnect( mySelection, 0, this, 0 );
305 mySMESHGUI->ResetState() ;
310 //=================================================================================
311 // function : SelectionIntoArgument()
312 // purpose : Called when selection as changed or other case
313 //=================================================================================
314 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
316 if ( !GroupButtons->isEnabled() ) // inactive
319 QString aString = "";
321 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelection, aString) ;
323 if ( myEditCurrentArgument == LineEditMesh ) {
326 myMesh = SMESH::SMESH_Mesh::_nil();
330 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject() ;
331 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
332 if( myMesh->_is_nil() )
337 myEditCurrentArgument->setText(aString) ;
339 bool isEnabled = (!myMesh->_is_nil());
340 buttonOk->setEnabled( isEnabled );
341 buttonApply->setEnabled( isEnabled );
345 //=================================================================================
346 // function : SetEditCurrentArgument()
348 //=================================================================================
349 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
351 QPushButton* send = (QPushButton*)sender();
352 switch (myConstructorId)
354 case 0: /* default constructor */
356 if(send == SelectButton) {
357 LineEditMesh->setFocus() ;
358 myEditCurrentArgument = LineEditMesh;
360 SelectionIntoArgument() ;
366 //=================================================================================
367 // function : DeactivateActiveDialog()
369 //=================================================================================
370 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
372 if ( GroupConstructors->isEnabled() ) {
373 GroupConstructors->setEnabled(false) ;
374 GroupMesh->setEnabled(false) ;
375 GroupButtons->setEnabled(false) ;
376 mySMESHGUI->ResetState() ;
377 mySMESHGUI->SetActiveDialogBox(0) ;
382 //=================================================================================
383 // function : ActivateThisDialog()
385 //=================================================================================
386 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
388 /* Emit a signal to deactivate the active dialog */
389 mySMESHGUI->EmitSignalDeactivateDialog() ;
390 GroupConstructors->setEnabled(true) ;
391 GroupMesh->setEnabled(true) ;
392 GroupButtons->setEnabled(true) ;
394 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
395 SelectionIntoArgument();
399 //=================================================================================
400 // function : enterEvent()
402 //=================================================================================
403 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
405 if ( GroupConstructors->isEnabled() )
407 ActivateThisDialog() ;
411 //=================================================================================
412 // function : closeEvent()
414 //=================================================================================
415 void SMESHGUI_RenumberingDlg::closeEvent( QCloseEvent* e )
417 /* same than click on cancel button */
418 this->ClickOnCancel() ;
422 //=======================================================================
423 //function : hideEvent
424 //purpose : caused by ESC key
425 //=======================================================================
427 void SMESHGUI_RenumberingDlg::hideEvent ( QHideEvent * e )
429 if ( !isMinimized() )