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_Session.h"
41 #include "SALOME_ListIO.hxx"
43 #include "utilities.h"
46 #include <qapplication.h>
47 #include <qbuttongroup.h>
48 #include <qgroupbox.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qradiobutton.h>
58 //=================================================================================
59 // class : SMESHGUI_RenumberingDlg()
61 //=================================================================================
62 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg (QWidget* parent, const char* name,
63 SalomeApp_SelectionMgr* Sel,
64 const int unit, bool modal, WFlags fl)
65 : QDialog(parent, name, modal, WStyle_Customize | WStyle_NormalBorder |
66 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose)
71 setName("SMESHGUI_RenumberingDlg");
75 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
78 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_NODES")));
79 setCaption(tr("SMESH_RENUMBERING_NODES_TITLE" ));
82 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_ELEMENTS")));
83 setCaption(tr("SMESH_RENUMBERING_ELEMENTS_TITLE" ));
86 setSizeGripEnabled(TRUE);
87 SMESHGUI_RenumberingDlgLayout = new QGridLayout(this);
88 SMESHGUI_RenumberingDlgLayout->setSpacing(6);
89 SMESHGUI_RenumberingDlgLayout->setMargin(11);
91 /***************************************************************/
92 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
94 GroupConstructors->setTitle(tr("SMESH_NODES" ));
96 GroupConstructors->setTitle(tr("SMESH_ELEMENTS" ));
97 GroupConstructors->setExclusive(TRUE);
98 GroupConstructors->setColumnLayout(0, Qt::Vertical);
99 GroupConstructors->layout()->setSpacing(0);
100 GroupConstructors->layout()->setMargin(0);
101 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
102 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
103 GroupConstructorsLayout->setSpacing(6);
104 GroupConstructorsLayout->setMargin(11);
105 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
106 Constructor1->setText(tr("" ));
107 Constructor1->setPixmap(image0);
108 Constructor1->setChecked(TRUE);
109 Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth()));
110 Constructor1->setMinimumSize(QSize(50, 0));
111 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
112 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
113 GroupConstructorsLayout->addItem(spacer, 0, 1);
114 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors, 0, 0);
116 /***************************************************************/
117 GroupButtons = new QGroupBox(this, "GroupButtons");
118 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
119 GroupButtons->setTitle(tr("" ));
120 GroupButtons->setColumnLayout(0, Qt::Vertical);
121 GroupButtons->layout()->setSpacing(0);
122 GroupButtons->layout()->setMargin(0);
123 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
124 GroupButtonsLayout->setAlignment(Qt::AlignTop);
125 GroupButtonsLayout->setSpacing(6);
126 GroupButtonsLayout->setMargin(11);
127 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
128 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
129 buttonCancel->setAutoDefault(TRUE);
130 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
131 buttonApply = new QPushButton(GroupButtons, "buttonApply");
132 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
133 buttonApply->setAutoDefault(TRUE);
134 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
135 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
136 GroupButtonsLayout->addItem(spacer_9, 0, 2);
137 buttonOk = new QPushButton(GroupButtons, "buttonOk");
138 buttonOk->setText(tr("SMESH_BUT_OK" ));
139 buttonOk->setAutoDefault(TRUE);
140 buttonOk->setDefault(TRUE);
141 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
142 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons, 2, 0);
144 /***************************************************************/
145 GroupMesh = new QGroupBox(this, "GroupMesh");
146 GroupMesh->setTitle(tr("SMESH_RENUMBERING" ));
147 GroupMesh->setMinimumSize(QSize(0, 0));
148 GroupMesh->setFrameShape(QGroupBox::Box);
149 GroupMesh->setFrameShadow(QGroupBox::Sunken);
150 GroupMesh->setColumnLayout(0, Qt::Vertical);
151 GroupMesh->layout()->setSpacing(0);
152 GroupMesh->layout()->setMargin(0);
153 GroupMeshLayout = new QGridLayout(GroupMesh->layout());
154 GroupMeshLayout->setAlignment(Qt::AlignTop);
155 GroupMeshLayout->setSpacing(6);
156 GroupMeshLayout->setMargin(11);
157 TextLabelMesh = new QLabel(GroupMesh, "TextLabelMesh");
158 TextLabelMesh->setText(tr("SMESH_MESH"));
159 TextLabelMesh->setMinimumSize(QSize(50, 0));
160 TextLabelMesh->setFrameShape(QLabel::NoFrame);
161 TextLabelMesh->setFrameShadow(QLabel::Plain);
162 GroupMeshLayout->addWidget(TextLabelMesh, 0, 0);
163 SelectButton = new QPushButton(GroupMesh, "SelectButton");
164 SelectButton->setText(tr("" ));
165 SelectButton->setPixmap(image1);
166 SelectButton->setToggleButton(FALSE);
167 GroupMeshLayout->addWidget(SelectButton, 0, 1);
168 LineEditMesh = new QLineEdit(GroupMesh, "LineEditMesh");
169 LineEditMesh->setReadOnly(true);
170 GroupMeshLayout->addWidget(LineEditMesh, 0, 2);
171 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh, 1, 0);
173 Init(Sel); /* Initialisations */
176 //=================================================================================
177 // function : ~SMESHGUI_RenumberingDlg()
178 // purpose : Destroys the object and frees any allocated resources
179 //=================================================================================
180 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
182 // no need to delete child widgets, Qt does it all for us
185 //=================================================================================
188 //=================================================================================
189 void SMESHGUI_RenumberingDlg::Init (SalomeApp_SelectionMgr* Sel)
193 Constructor1->setChecked(TRUE);
194 mySelectionMgr = Sel;
195 mySMESHGUI = SMESHGUI::GetSMESHGUI();
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)