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"
41 #include "SUIT_MessageBox.h"
43 #include "LightApp_Application.h"
45 #include "SALOME_ListIO.hxx"
47 #include "utilities.h"
50 #include <qapplication.h>
51 #include <qbuttongroup.h>
52 #include <qgroupbox.h>
54 #include <qlineedit.h>
55 #include <qpushbutton.h>
56 #include <qradiobutton.h>
62 //=================================================================================
63 // class : SMESHGUI_RenumberingDlg()
65 //=================================================================================
66 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const char* name,
67 const int unit, bool modal, WFlags fl)
68 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
69 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
70 mySMESHGUI( theModule ),
71 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
76 setName("SMESHGUI_RenumberingDlg");
80 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
83 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_NODES")));
84 setCaption(tr("SMESH_RENUMBERING_NODES_TITLE" ));
87 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_ELEMENTS")));
88 setCaption(tr("SMESH_RENUMBERING_ELEMENTS_TITLE" ));
91 setSizeGripEnabled(TRUE);
92 SMESHGUI_RenumberingDlgLayout = new QGridLayout(this);
93 SMESHGUI_RenumberingDlgLayout->setSpacing(6);
94 SMESHGUI_RenumberingDlgLayout->setMargin(11);
96 /***************************************************************/
97 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
99 GroupConstructors->setTitle(tr("SMESH_NODES" ));
100 myHelpFileName = "/files/renumbering_nodes_and_elements.htm#renumber_nodes";
102 else if (unit == 1) {
103 GroupConstructors->setTitle(tr("SMESH_ELEMENTS" ));
104 myHelpFileName = "/files/renumbering_nodes_and_elements.htm#renumber_elements";
106 GroupConstructors->setExclusive(TRUE);
107 GroupConstructors->setColumnLayout(0, Qt::Vertical);
108 GroupConstructors->layout()->setSpacing(0);
109 GroupConstructors->layout()->setMargin(0);
110 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
111 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
112 GroupConstructorsLayout->setSpacing(6);
113 GroupConstructorsLayout->setMargin(11);
114 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
115 Constructor1->setText(tr("" ));
116 Constructor1->setPixmap(image0);
117 Constructor1->setChecked(TRUE);
118 Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth()));
119 Constructor1->setMinimumSize(QSize(50, 0));
120 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
121 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
122 GroupConstructorsLayout->addItem(spacer, 0, 1);
123 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors, 0, 0);
125 /***************************************************************/
126 GroupButtons = new QGroupBox(this, "GroupButtons");
127 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
128 GroupButtons->setTitle(tr("" ));
129 GroupButtons->setColumnLayout(0, Qt::Vertical);
130 GroupButtons->layout()->setSpacing(0);
131 GroupButtons->layout()->setMargin(0);
132 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
133 GroupButtonsLayout->setAlignment(Qt::AlignTop);
134 GroupButtonsLayout->setSpacing(6);
135 GroupButtonsLayout->setMargin(11);
136 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
137 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
138 buttonHelp->setAutoDefault(TRUE);
139 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
140 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
141 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
142 buttonCancel->setAutoDefault(TRUE);
143 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
144 buttonApply = new QPushButton(GroupButtons, "buttonApply");
145 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
146 buttonApply->setAutoDefault(TRUE);
147 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
148 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
149 GroupButtonsLayout->addItem(spacer_9, 0, 2);
150 buttonOk = new QPushButton(GroupButtons, "buttonOk");
151 buttonOk->setText(tr("SMESH_BUT_OK" ));
152 buttonOk->setAutoDefault(TRUE);
153 buttonOk->setDefault(TRUE);
154 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
155 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons, 2, 0);
157 /***************************************************************/
158 GroupMesh = new QGroupBox(this, "GroupMesh");
159 GroupMesh->setTitle(tr("SMESH_RENUMBERING" ));
160 GroupMesh->setMinimumSize(QSize(0, 0));
161 GroupMesh->setFrameShape(QGroupBox::Box);
162 GroupMesh->setFrameShadow(QGroupBox::Sunken);
163 GroupMesh->setColumnLayout(0, Qt::Vertical);
164 GroupMesh->layout()->setSpacing(0);
165 GroupMesh->layout()->setMargin(0);
166 GroupMeshLayout = new QGridLayout(GroupMesh->layout());
167 GroupMeshLayout->setAlignment(Qt::AlignTop);
168 GroupMeshLayout->setSpacing(6);
169 GroupMeshLayout->setMargin(11);
170 TextLabelMesh = new QLabel(GroupMesh, "TextLabelMesh");
171 TextLabelMesh->setText(tr("SMESH_MESH"));
172 TextLabelMesh->setMinimumSize(QSize(50, 0));
173 TextLabelMesh->setFrameShape(QLabel::NoFrame);
174 TextLabelMesh->setFrameShadow(QLabel::Plain);
175 GroupMeshLayout->addWidget(TextLabelMesh, 0, 0);
176 SelectButton = new QPushButton(GroupMesh, "SelectButton");
177 SelectButton->setText(tr("" ));
178 SelectButton->setPixmap(image1);
179 SelectButton->setToggleButton(FALSE);
180 GroupMeshLayout->addWidget(SelectButton, 0, 1);
181 LineEditMesh = new QLineEdit(GroupMesh, "LineEditMesh");
182 LineEditMesh->setReadOnly(true);
183 GroupMeshLayout->addWidget(LineEditMesh, 0, 2);
184 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh, 1, 0);
186 Init(); /* Initialisations */
189 //=================================================================================
190 // function : ~SMESHGUI_RenumberingDlg()
191 // purpose : Destroys the object and frees any allocated resources
192 //=================================================================================
193 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
195 // no need to delete child widgets, Qt does it all for us
198 //=================================================================================
201 //=================================================================================
202 void SMESHGUI_RenumberingDlg::Init()
206 Constructor1->setChecked(TRUE);
207 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
209 myMesh = SMESH::SMESH_Mesh::_nil();
211 myMeshFilter = new SMESH_TypeFilter (MESH);
213 /* signals and slots connections */
214 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
215 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
216 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
217 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
218 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
220 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
221 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
222 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
223 /* to close dialog if study change */
224 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
226 this->show(); /* displays Dialog */
228 myEditCurrentArgument = LineEditMesh;
229 LineEditMesh->setFocus();
230 mySelectionMgr->clearFilters();
231 mySelectionMgr->installFilter(myMeshFilter);
233 SelectionIntoArgument();
236 //=================================================================================
237 // function : ConstructorsClicked()
238 // purpose : Radio button management
239 //=================================================================================
240 void SMESHGUI_RenumberingDlg::ConstructorsClicked (int)
244 //=================================================================================
245 // function : ClickOnApply()
247 //=================================================================================
248 void SMESHGUI_RenumberingDlg::ClickOnApply()
250 if (mySMESHGUI->isActiveStudyLocked())
253 if (!myMesh->_is_nil())
257 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
258 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
259 bool isUnitsLabeled = false;
261 if (myUnit == 0 && anActor) {
262 isUnitsLabeled = anActor->GetPointsLabeled();
263 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
265 else if (myUnit == 1 && anActor) {
266 isUnitsLabeled = anActor->GetCellsLabeled();
267 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
270 QApplication::setOverrideCursor(Qt::waitCursor);
272 aMeshEditor->RenumberNodes();
273 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
275 else if (myUnit == 1) {
276 aMeshEditor->RenumberElements();
277 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
279 QApplication::restoreOverrideCursor();
285 //mySelectionMgr->clearSelected();
290 //=================================================================================
291 // function : ClickOnOk()
293 //=================================================================================
294 void SMESHGUI_RenumberingDlg::ClickOnOk()
300 //=================================================================================
301 // function : ClickOnCancel()
303 //=================================================================================
304 void SMESHGUI_RenumberingDlg::ClickOnCancel()
306 //mySelectionMgr->clearSelected();
307 mySelectionMgr->clearFilters();
308 disconnect(mySelectionMgr, 0, this, 0);
309 mySMESHGUI->ResetState();
313 //=================================================================================
314 // function : ClickOnHelp()
316 //=================================================================================
317 void SMESHGUI_RenumberingDlg::ClickOnHelp()
319 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
321 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
323 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
324 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
325 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
326 QObject::tr("BUT_OK"));
330 //=================================================================================
331 // function : SelectionIntoArgument()
332 // purpose : Called when selection as changed or other case
333 //=================================================================================
334 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
336 if (!GroupButtons->isEnabled()) // inactive
339 QString aString = "";
342 mySelectionMgr->selectedObjects(aList);
343 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
345 if (myEditCurrentArgument == LineEditMesh) {
348 myMesh = SMESH::SMESH_Mesh::_nil();
351 Handle(SALOME_InteractiveObject) IO = aList.First();
352 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
353 if (myMesh->_is_nil())
358 myEditCurrentArgument->setText(aString);
360 bool isEnabled = (!myMesh->_is_nil());
361 buttonOk->setEnabled(isEnabled);
362 buttonApply->setEnabled(isEnabled);
365 //=================================================================================
366 // function : SetEditCurrentArgument()
368 //=================================================================================
369 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
371 QPushButton* send = (QPushButton*)sender();
372 switch (myConstructorId)
374 case 0: /* default constructor */
376 if(send == SelectButton) {
377 LineEditMesh->setFocus();
378 myEditCurrentArgument = LineEditMesh;
380 SelectionIntoArgument();
386 //=================================================================================
387 // function : DeactivateActiveDialog()
389 //=================================================================================
390 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
392 if (GroupConstructors->isEnabled()) {
393 GroupConstructors->setEnabled(false);
394 GroupMesh->setEnabled(false);
395 GroupButtons->setEnabled(false);
396 mySMESHGUI->ResetState();
397 mySMESHGUI->SetActiveDialogBox(0);
401 //=================================================================================
402 // function : ActivateThisDialog()
404 //=================================================================================
405 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
407 /* Emit a signal to deactivate the active dialog */
408 mySMESHGUI->EmitSignalDeactivateDialog();
409 GroupConstructors->setEnabled(true);
410 GroupMesh->setEnabled(true);
411 GroupButtons->setEnabled(true);
413 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
414 SelectionIntoArgument();
417 //=================================================================================
418 // function : enterEvent()
420 //=================================================================================
421 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
423 if (GroupConstructors->isEnabled())
425 ActivateThisDialog();
428 //=================================================================================
429 // function : closeEvent()
431 //=================================================================================
432 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
434 /* same than click on cancel button */
435 this->ClickOnCancel();
438 //=======================================================================
439 //function : hideEvent
440 //purpose : caused by ESC key
441 //=======================================================================
442 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)