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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
64 //=================================================================================
65 // class : SMESHGUI_RenumberingDlg()
67 //=================================================================================
68 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const char* name,
69 const int unit, bool modal, WFlags fl)
70 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
71 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
72 mySMESHGUI( theModule ),
73 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
78 setName("SMESHGUI_RenumberingDlg");
82 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_SELECT")));
85 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_NODES")));
86 setCaption(tr("SMESH_RENUMBERING_NODES_TITLE" ));
89 image0 = QPixmap(SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH",tr("ICON_DLG_RENUMBERING_ELEMENTS")));
90 setCaption(tr("SMESH_RENUMBERING_ELEMENTS_TITLE" ));
93 setSizeGripEnabled(TRUE);
94 SMESHGUI_RenumberingDlgLayout = new QGridLayout(this);
95 SMESHGUI_RenumberingDlgLayout->setSpacing(6);
96 SMESHGUI_RenumberingDlgLayout->setMargin(11);
98 /***************************************************************/
99 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
101 GroupConstructors->setTitle(tr("SMESH_NODES" ));
102 myHelpFileName = "renumbering_nodes_and_elements_page.html#renumbering_nodes_anchor";
104 else if (unit == 1) {
105 GroupConstructors->setTitle(tr("SMESH_ELEMENTS" ));
106 myHelpFileName = "renumbering_nodes_and_elements_page.html#renumbering_elements_anchor";
108 GroupConstructors->setExclusive(TRUE);
109 GroupConstructors->setColumnLayout(0, Qt::Vertical);
110 GroupConstructors->layout()->setSpacing(0);
111 GroupConstructors->layout()->setMargin(0);
112 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
113 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
114 GroupConstructorsLayout->setSpacing(6);
115 GroupConstructorsLayout->setMargin(11);
116 Constructor1 = new QRadioButton(GroupConstructors, "Constructor1");
117 Constructor1->setText(tr("" ));
118 Constructor1->setPixmap(image0);
119 Constructor1->setChecked(TRUE);
120 Constructor1->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)1, (QSizePolicy::SizeType)0, Constructor1->sizePolicy().hasHeightForWidth()));
121 Constructor1->setMinimumSize(QSize(50, 0));
122 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
123 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
124 GroupConstructorsLayout->addItem(spacer, 0, 1);
125 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors, 0, 0);
127 /***************************************************************/
128 GroupButtons = new QGroupBox(this, "GroupButtons");
129 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
130 GroupButtons->setTitle(tr("" ));
131 GroupButtons->setColumnLayout(0, Qt::Vertical);
132 GroupButtons->layout()->setSpacing(0);
133 GroupButtons->layout()->setMargin(0);
134 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
135 GroupButtonsLayout->setAlignment(Qt::AlignTop);
136 GroupButtonsLayout->setSpacing(6);
137 GroupButtonsLayout->setMargin(11);
138 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
139 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
140 buttonHelp->setAutoDefault(TRUE);
141 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
142 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
143 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
144 buttonCancel->setAutoDefault(TRUE);
145 GroupButtonsLayout->addWidget(buttonCancel, 0, 1);
146 buttonApply = new QPushButton(GroupButtons, "buttonApply");
147 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
148 buttonApply->setAutoDefault(TRUE);
149 GroupButtonsLayout->addWidget(buttonApply, 0, 0);
150 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
151 GroupButtonsLayout->addItem(spacer_9, 0, 3);
152 buttonOk = new QPushButton(GroupButtons, "buttonOk");
153 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
154 buttonOk->setAutoDefault(TRUE);
155 buttonOk->setDefault(TRUE);
156 GroupButtonsLayout->addWidget(buttonOk, 0, 2);
157 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons, 2, 0);
159 /***************************************************************/
160 GroupMesh = new QGroupBox(this, "GroupMesh");
161 GroupMesh->setTitle(tr("SMESH_RENUMBERING" ));
162 GroupMesh->setMinimumSize(QSize(0, 0));
163 GroupMesh->setFrameShape(QGroupBox::Box);
164 GroupMesh->setFrameShadow(QGroupBox::Sunken);
165 GroupMesh->setColumnLayout(0, Qt::Vertical);
166 GroupMesh->layout()->setSpacing(0);
167 GroupMesh->layout()->setMargin(0);
168 GroupMeshLayout = new QGridLayout(GroupMesh->layout());
169 GroupMeshLayout->setAlignment(Qt::AlignTop);
170 GroupMeshLayout->setSpacing(6);
171 GroupMeshLayout->setMargin(11);
172 TextLabelMesh = new QLabel(GroupMesh, "TextLabelMesh");
173 TextLabelMesh->setText(tr("SMESH_MESH"));
174 TextLabelMesh->setMinimumSize(QSize(50, 0));
175 TextLabelMesh->setFrameShape(QLabel::NoFrame);
176 TextLabelMesh->setFrameShadow(QLabel::Plain);
177 GroupMeshLayout->addWidget(TextLabelMesh, 0, 0);
178 SelectButton = new QPushButton(GroupMesh, "SelectButton");
179 SelectButton->setText(tr("" ));
180 SelectButton->setPixmap(image1);
181 SelectButton->setToggleButton(FALSE);
182 GroupMeshLayout->addWidget(SelectButton, 0, 1);
183 LineEditMesh = new QLineEdit(GroupMesh, "LineEditMesh");
184 LineEditMesh->setReadOnly(true);
185 GroupMeshLayout->addWidget(LineEditMesh, 0, 2);
186 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh, 1, 0);
188 Init(); /* Initialisations */
191 //=================================================================================
192 // function : ~SMESHGUI_RenumberingDlg()
193 // purpose : Destroys the object and frees any allocated resources
194 //=================================================================================
195 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
197 // no need to delete child widgets, Qt does it all for us
200 //=================================================================================
203 //=================================================================================
204 void SMESHGUI_RenumberingDlg::Init()
208 Constructor1->setChecked(TRUE);
209 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
211 myMesh = SMESH::SMESH_Mesh::_nil();
213 myMeshFilter = new SMESH_TypeFilter (MESH);
215 /* signals and slots connections */
216 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
217 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
218 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
219 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
220 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
222 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
223 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
224 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
225 /* to close dialog if study change */
226 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
228 this->show(); /* displays Dialog */
230 myEditCurrentArgument = LineEditMesh;
231 LineEditMesh->setFocus();
232 mySelectionMgr->clearFilters();
233 mySelectionMgr->installFilter(myMeshFilter);
235 SelectionIntoArgument();
238 //=================================================================================
239 // function : ConstructorsClicked()
240 // purpose : Radio button management
241 //=================================================================================
242 void SMESHGUI_RenumberingDlg::ConstructorsClicked (int)
246 //=================================================================================
247 // function : ClickOnApply()
249 //=================================================================================
250 void SMESHGUI_RenumberingDlg::ClickOnApply()
252 if (mySMESHGUI->isActiveStudyLocked())
255 if (!myMesh->_is_nil())
259 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
260 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
261 bool isUnitsLabeled = false;
263 if (myUnit == 0 && anActor) {
264 isUnitsLabeled = anActor->GetPointsLabeled();
265 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
267 else if (myUnit == 1 && anActor) {
268 isUnitsLabeled = anActor->GetCellsLabeled();
269 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
272 QApplication::setOverrideCursor(Qt::waitCursor);
274 aMeshEditor->RenumberNodes();
275 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
277 else if (myUnit == 1) {
278 aMeshEditor->RenumberElements();
279 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
281 QApplication::restoreOverrideCursor();
287 //mySelectionMgr->clearSelected();
292 //=================================================================================
293 // function : ClickOnOk()
295 //=================================================================================
296 void SMESHGUI_RenumberingDlg::ClickOnOk()
302 //=================================================================================
303 // function : ClickOnCancel()
305 //=================================================================================
306 void SMESHGUI_RenumberingDlg::ClickOnCancel()
308 //mySelectionMgr->clearSelected();
309 mySelectionMgr->clearFilters();
310 disconnect(mySelectionMgr, 0, this, 0);
311 mySMESHGUI->ResetState();
315 //=================================================================================
316 // function : ClickOnHelp()
318 //=================================================================================
319 void SMESHGUI_RenumberingDlg::ClickOnHelp()
321 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
323 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
327 platform = "winapplication";
329 platform = "application";
331 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
332 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
333 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
334 QObject::tr("BUT_OK"));
338 //=================================================================================
339 // function : SelectionIntoArgument()
340 // purpose : Called when selection as changed or other case
341 //=================================================================================
342 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
344 if (!GroupButtons->isEnabled()) // inactive
347 QString aString = "";
350 mySelectionMgr->selectedObjects(aList);
351 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
353 if (myEditCurrentArgument == LineEditMesh) {
356 myMesh = SMESH::SMESH_Mesh::_nil();
359 Handle(SALOME_InteractiveObject) IO = aList.First();
360 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
361 if (myMesh->_is_nil())
366 myEditCurrentArgument->setText(aString);
368 bool isEnabled = (!myMesh->_is_nil());
369 buttonOk->setEnabled(isEnabled);
370 buttonApply->setEnabled(isEnabled);
373 //=================================================================================
374 // function : SetEditCurrentArgument()
376 //=================================================================================
377 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
379 QPushButton* send = (QPushButton*)sender();
380 switch (myConstructorId)
382 case 0: /* default constructor */
384 if(send == SelectButton) {
385 LineEditMesh->setFocus();
386 myEditCurrentArgument = LineEditMesh;
388 SelectionIntoArgument();
394 //=================================================================================
395 // function : DeactivateActiveDialog()
397 //=================================================================================
398 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
400 if (GroupConstructors->isEnabled()) {
401 GroupConstructors->setEnabled(false);
402 GroupMesh->setEnabled(false);
403 GroupButtons->setEnabled(false);
404 mySMESHGUI->ResetState();
405 mySMESHGUI->SetActiveDialogBox(0);
409 //=================================================================================
410 // function : ActivateThisDialog()
412 //=================================================================================
413 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
415 /* Emit a signal to deactivate the active dialog */
416 mySMESHGUI->EmitSignalDeactivateDialog();
417 GroupConstructors->setEnabled(true);
418 GroupMesh->setEnabled(true);
419 GroupButtons->setEnabled(true);
421 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
422 SelectionIntoArgument();
425 //=================================================================================
426 // function : enterEvent()
428 //=================================================================================
429 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
431 if (GroupConstructors->isEnabled())
433 ActivateThisDialog();
436 //=================================================================================
437 // function : closeEvent()
439 //=================================================================================
440 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
442 /* same than click on cancel button */
443 this->ClickOnCancel();
446 //=======================================================================
447 //function : hideEvent
448 //purpose : caused by ESC key
449 //=======================================================================
450 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)
456 //=================================================================================
457 // function : keyPressEvent()
459 //=================================================================================
460 void SMESHGUI_RenumberingDlg::keyPressEvent( QKeyEvent* e )
462 QDialog::keyPressEvent( e );
463 if ( e->isAccepted() )
466 if ( e->key() == Key_F1 )