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 this->show(); /* displays Dialog */
216 myEditCurrentArgument = LineEditMesh;
217 LineEditMesh->setFocus();
218 mySelectionMgr->clearFilters();
219 mySelectionMgr->installFilter(myMeshFilter);
221 SelectionIntoArgument();
224 //=================================================================================
225 // function : ConstructorsClicked()
226 // purpose : Radio button management
227 //=================================================================================
228 void SMESHGUI_RenumberingDlg::ConstructorsClicked (int)
232 //=================================================================================
233 // function : ClickOnApply()
235 //=================================================================================
236 void SMESHGUI_RenumberingDlg::ClickOnApply()
238 if (mySMESHGUI->isActiveStudyLocked())
241 if (!myMesh->_is_nil())
245 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
246 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
247 bool isUnitsLabeled = false;
249 if (myUnit == 0 && anActor) {
250 isUnitsLabeled = anActor->GetPointsLabeled();
251 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
253 else if (myUnit == 1 && anActor) {
254 isUnitsLabeled = anActor->GetCellsLabeled();
255 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
258 QApplication::setOverrideCursor(Qt::waitCursor);
260 aMeshEditor->RenumberNodes();
261 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
263 else if (myUnit == 1) {
264 aMeshEditor->RenumberElements();
265 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
267 QApplication::restoreOverrideCursor();
273 //mySelectionMgr->clearSelected();
278 //=================================================================================
279 // function : ClickOnOk()
281 //=================================================================================
282 void SMESHGUI_RenumberingDlg::ClickOnOk()
288 //=================================================================================
289 // function : ClickOnCancel()
291 //=================================================================================
292 void SMESHGUI_RenumberingDlg::ClickOnCancel()
294 //mySelectionMgr->clearSelected();
295 mySelectionMgr->clearFilters();
296 disconnect(mySelectionMgr, 0, this, 0);
297 mySMESHGUI->ResetState();
301 //=================================================================================
302 // function : SelectionIntoArgument()
303 // purpose : Called when selection as changed or other case
304 //=================================================================================
305 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
307 if (!GroupButtons->isEnabled()) // inactive
310 QString aString = "";
313 mySelectionMgr->selectedObjects(aList);
314 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
316 if (myEditCurrentArgument == LineEditMesh) {
319 myMesh = SMESH::SMESH_Mesh::_nil();
322 Handle(SALOME_InteractiveObject) IO = aList.First();
323 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
324 if (myMesh->_is_nil())
329 myEditCurrentArgument->setText(aString);
331 bool isEnabled = (!myMesh->_is_nil());
332 buttonOk->setEnabled(isEnabled);
333 buttonApply->setEnabled(isEnabled);
336 //=================================================================================
337 // function : SetEditCurrentArgument()
339 //=================================================================================
340 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
342 QPushButton* send = (QPushButton*)sender();
343 switch (myConstructorId)
345 case 0: /* default constructor */
347 if(send == SelectButton) {
348 LineEditMesh->setFocus();
349 myEditCurrentArgument = LineEditMesh;
351 SelectionIntoArgument();
357 //=================================================================================
358 // function : DeactivateActiveDialog()
360 //=================================================================================
361 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
363 if (GroupConstructors->isEnabled()) {
364 GroupConstructors->setEnabled(false);
365 GroupMesh->setEnabled(false);
366 GroupButtons->setEnabled(false);
367 mySMESHGUI->ResetState();
368 mySMESHGUI->SetActiveDialogBox(0);
372 //=================================================================================
373 // function : ActivateThisDialog()
375 //=================================================================================
376 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
378 /* Emit a signal to deactivate the active dialog */
379 mySMESHGUI->EmitSignalDeactivateDialog();
380 GroupConstructors->setEnabled(true);
381 GroupMesh->setEnabled(true);
382 GroupButtons->setEnabled(true);
384 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
385 SelectionIntoArgument();
388 //=================================================================================
389 // function : enterEvent()
391 //=================================================================================
392 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
394 if (GroupConstructors->isEnabled())
396 ActivateThisDialog();
399 //=================================================================================
400 // function : closeEvent()
402 //=================================================================================
403 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
405 /* same than click on cancel button */
406 this->ClickOnCancel();
409 //=======================================================================
410 //function : hideEvent
411 //purpose : caused by ESC key
412 //=======================================================================
413 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)