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"
35 #include "SMESH_Actor.h"
36 #include "SMESH_TypeFilter.hxx"
37 #include "SMDS_Mesh.hxx"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_Session.h"
42 #include "SALOME_ListIO.hxx"
44 #include "utilities.h"
47 #include <qapplication.h>
48 #include <qbuttongroup.h>
49 #include <qgroupbox.h>
51 #include <qlineedit.h>
52 #include <qpushbutton.h>
53 #include <qradiobutton.h>
59 //=================================================================================
60 // class : SMESHGUI_RenumberingDlg()
62 //=================================================================================
63 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const char* name,
64 const int unit, bool modal, WFlags fl)
65 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
66 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
67 mySMESHGUI( theModule ),
68 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
73 setName("SMESHGUI_RenumberingDlg");
77 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
80 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_NODES")));
81 setCaption(tr("SMESH_RENUMBERING_NODES_TITLE" ));
84 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_ELEMENTS")));
85 setCaption(tr("SMESH_RENUMBERING_ELEMENTS_TITLE" ));
88 setSizeGripEnabled(TRUE);
89 SMESHGUI_RenumberingDlgLayout = new QGridLayout(this);
90 SMESHGUI_RenumberingDlgLayout->setSpacing(6);
91 SMESHGUI_RenumberingDlgLayout->setMargin(11);
93 /***************************************************************/
94 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
96 GroupConstructors->setTitle(tr("SMESH_NODES" ));
98 GroupConstructors->setTitle(tr("SMESH_ELEMENTS" ));
99 GroupConstructors->setExclusive(TRUE);
100 GroupConstructors->setColumnLayout(0, Qt::Vertical);
101 GroupConstructors->layout()->setSpacing(0);
102 GroupConstructors->layout()->setMargin(0);
103 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
104 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
105 GroupConstructorsLayout->setSpacing(6);
106 GroupConstructorsLayout->setMargin(11);
107 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
108 Constructor1->setText(tr("" ));
109 Constructor1->setPixmap(image0);
110 Constructor1->setChecked(TRUE);
111 Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth()));
112 Constructor1->setMinimumSize(QSize(50, 0));
113 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
114 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
115 GroupConstructorsLayout->addItem(spacer, 0, 1);
116 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors, 0, 0);
118 /***************************************************************/
119 GroupButtons = new QGroupBox(this, "GroupButtons");
120 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
121 GroupButtons->setTitle(tr("" ));
122 GroupButtons->setColumnLayout(0, Qt::Vertical);
123 GroupButtons->layout()->setSpacing(0);
124 GroupButtons->layout()->setMargin(0);
125 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
126 GroupButtonsLayout->setAlignment(Qt::AlignTop);
127 GroupButtonsLayout->setSpacing(6);
128 GroupButtonsLayout->setMargin(11);
129 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
130 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
131 buttonCancel->setAutoDefault(TRUE);
132 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
133 buttonApply = new QPushButton(GroupButtons, "buttonApply");
134 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
135 buttonApply->setAutoDefault(TRUE);
136 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
137 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
138 GroupButtonsLayout->addItem(spacer_9, 0, 2);
139 buttonOk = new QPushButton(GroupButtons, "buttonOk");
140 buttonOk->setText(tr("SMESH_BUT_OK" ));
141 buttonOk->setAutoDefault(TRUE);
142 buttonOk->setDefault(TRUE);
143 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
144 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons, 2, 0);
146 /***************************************************************/
147 GroupMesh = new QGroupBox(this, "GroupMesh");
148 GroupMesh->setTitle(tr("SMESH_RENUMBERING" ));
149 GroupMesh->setMinimumSize(QSize(0, 0));
150 GroupMesh->setFrameShape(QGroupBox::Box);
151 GroupMesh->setFrameShadow(QGroupBox::Sunken);
152 GroupMesh->setColumnLayout(0, Qt::Vertical);
153 GroupMesh->layout()->setSpacing(0);
154 GroupMesh->layout()->setMargin(0);
155 GroupMeshLayout = new QGridLayout(GroupMesh->layout());
156 GroupMeshLayout->setAlignment(Qt::AlignTop);
157 GroupMeshLayout->setSpacing(6);
158 GroupMeshLayout->setMargin(11);
159 TextLabelMesh = new QLabel(GroupMesh, "TextLabelMesh");
160 TextLabelMesh->setText(tr("SMESH_MESH"));
161 TextLabelMesh->setMinimumSize(QSize(50, 0));
162 TextLabelMesh->setFrameShape(QLabel::NoFrame);
163 TextLabelMesh->setFrameShadow(QLabel::Plain);
164 GroupMeshLayout->addWidget(TextLabelMesh, 0, 0);
165 SelectButton = new QPushButton(GroupMesh, "SelectButton");
166 SelectButton->setText(tr("" ));
167 SelectButton->setPixmap(image1);
168 SelectButton->setToggleButton(FALSE);
169 GroupMeshLayout->addWidget(SelectButton, 0, 1);
170 LineEditMesh = new QLineEdit(GroupMesh, "LineEditMesh");
171 LineEditMesh->setReadOnly(true);
172 GroupMeshLayout->addWidget(LineEditMesh, 0, 2);
173 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh, 1, 0);
175 Init(); /* Initialisations */
178 //=================================================================================
179 // function : ~SMESHGUI_RenumberingDlg()
180 // purpose : Destroys the object and frees any allocated resources
181 //=================================================================================
182 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
184 // no need to delete child widgets, Qt does it all for us
187 //=================================================================================
190 //=================================================================================
191 void SMESHGUI_RenumberingDlg::Init()
195 Constructor1->setChecked(TRUE);
196 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
198 myMesh = SMESH::SMESH_Mesh::_nil();
200 myMeshFilter = new SMESH_TypeFilter (MESH);
202 /* signals and slots connections */
203 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
204 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
205 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
206 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
208 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
209 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
210 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
211 /* to close dialog if study change */
212 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
214 /* Move widget on the botton right corner of main widget */
216 mySMESHGUI->DefineDlgPosition(this, x, y);
218 this->show(); /* displays Dialog */
220 myEditCurrentArgument = LineEditMesh;
221 LineEditMesh->setFocus();
222 mySelectionMgr->clearFilters();
223 mySelectionMgr->installFilter(myMeshFilter);
225 SelectionIntoArgument();
228 //=================================================================================
229 // function : ConstructorsClicked()
230 // purpose : Radio button management
231 //=================================================================================
232 void SMESHGUI_RenumberingDlg::ConstructorsClicked (int)
236 //=================================================================================
237 // function : ClickOnApply()
239 //=================================================================================
240 void SMESHGUI_RenumberingDlg::ClickOnApply()
242 if (mySMESHGUI->isActiveStudyLocked())
245 if (!myMesh->_is_nil())
249 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
250 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
251 bool isUnitsLabeled = false;
253 if (myUnit == 0 && anActor) {
254 isUnitsLabeled = anActor->GetPointsLabeled();
255 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
257 else if (myUnit == 1 && anActor) {
258 isUnitsLabeled = anActor->GetCellsLabeled();
259 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
262 QApplication::setOverrideCursor(Qt::waitCursor);
264 aMeshEditor->RenumberNodes();
265 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
267 else if (myUnit == 1) {
268 aMeshEditor->RenumberElements();
269 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
271 QApplication::restoreOverrideCursor();
277 //mySelectionMgr->clearSelected();
282 //=================================================================================
283 // function : ClickOnOk()
285 //=================================================================================
286 void SMESHGUI_RenumberingDlg::ClickOnOk()
292 //=================================================================================
293 // function : ClickOnCancel()
295 //=================================================================================
296 void SMESHGUI_RenumberingDlg::ClickOnCancel()
298 //mySelectionMgr->clearSelected();
299 mySelectionMgr->clearFilters();
300 disconnect(mySelectionMgr, 0, this, 0);
301 mySMESHGUI->ResetState();
305 //=================================================================================
306 // function : SelectionIntoArgument()
307 // purpose : Called when selection as changed or other case
308 //=================================================================================
309 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
311 if (!GroupButtons->isEnabled()) // inactive
314 QString aString = "";
317 mySelectionMgr->selectedObjects(aList);
318 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
320 if (myEditCurrentArgument == LineEditMesh) {
323 myMesh = SMESH::SMESH_Mesh::_nil();
326 Handle(SALOME_InteractiveObject) IO = aList.First();
327 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
328 if (myMesh->_is_nil())
333 myEditCurrentArgument->setText(aString);
335 bool isEnabled = (!myMesh->_is_nil());
336 buttonOk->setEnabled(isEnabled);
337 buttonApply->setEnabled(isEnabled);
340 //=================================================================================
341 // function : SetEditCurrentArgument()
343 //=================================================================================
344 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
346 QPushButton* send = (QPushButton*)sender();
347 switch (myConstructorId)
349 case 0: /* default constructor */
351 if(send == SelectButton) {
352 LineEditMesh->setFocus();
353 myEditCurrentArgument = LineEditMesh;
355 SelectionIntoArgument();
361 //=================================================================================
362 // function : DeactivateActiveDialog()
364 //=================================================================================
365 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
367 if (GroupConstructors->isEnabled()) {
368 GroupConstructors->setEnabled(false);
369 GroupMesh->setEnabled(false);
370 GroupButtons->setEnabled(false);
371 mySMESHGUI->ResetState();
372 mySMESHGUI->SetActiveDialogBox(0);
376 //=================================================================================
377 // function : ActivateThisDialog()
379 //=================================================================================
380 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
382 /* Emit a signal to deactivate the active dialog */
383 mySMESHGUI->EmitSignalDeactivateDialog();
384 GroupConstructors->setEnabled(true);
385 GroupMesh->setEnabled(true);
386 GroupButtons->setEnabled(true);
388 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
389 SelectionIntoArgument();
392 //=================================================================================
393 // function : enterEvent()
395 //=================================================================================
396 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
398 if (GroupConstructors->isEnabled())
400 ActivateThisDialog();
403 //=================================================================================
404 // function : closeEvent()
406 //=================================================================================
407 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
409 /* same than click on cancel button */
410 this->ClickOnCancel();
413 //=======================================================================
414 //function : hideEvent
415 //purpose : caused by ESC key
416 //=======================================================================
417 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)