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
22 // File : SMESHGUI_RenumberingDlg.cxx
23 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_RenumberingDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
33 #include <SMESH_Actor.h>
34 #include <SMESH_TypeFilter.hxx>
36 // SALOME GUI includes
37 #include <SUIT_Desktop.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_MessageBox.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
45 #include <SALOME_ListIO.hxx>
48 #include <QApplication>
52 #include <QPushButton>
53 #include <QRadioButton>
54 #include <QVBoxLayout>
55 #include <QHBoxLayout>
59 #include <SALOMEconfig.h>
60 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
65 //=================================================================================
66 // class : SMESHGUI_RenumberingDlg()
68 //=================================================================================
69 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const int unit)
70 : QDialog( SMESH::GetDesktop( theModule ) ),
71 mySMESHGUI( theModule ),
72 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
77 setAttribute(Qt::WA_DeleteOnClose, true);
78 setWindowTitle(unit == 0 ?
79 tr("SMESH_RENUMBERING_NODES_TITLE") :
80 tr("SMESH_RENUMBERING_ELEMENTS_TITLE"));
81 setSizeGripEnabled(true);
83 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( mySMESHGUI );
84 QPixmap image0(resMgr->loadPixmap("SMESH", unit == 0 ?
85 tr("ICON_DLG_RENUMBERING_NODES") :
86 tr("ICON_DLG_RENUMBERING_ELEMENTS")));
87 QPixmap image1(resMgr->loadPixmap("SMESH",tr("ICON_SELECT")));
89 QVBoxLayout* SMESHGUI_RenumberingDlgLayout = new QVBoxLayout(this);
90 SMESHGUI_RenumberingDlgLayout->setSpacing(SPACING);
91 SMESHGUI_RenumberingDlgLayout->setMargin(MARGIN);
93 /***************************************************************/
94 QGroupBox* GroupConstructors = new QGroupBox(unit == 0 ?
98 myHelpFileName = unit == 0 ?
99 "renumbering_nodes_and_elements_page.html#renumbering_nodes_anchor" :
100 "renumbering_nodes_and_elements_page.html#renumbering_elements_anchor";
102 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
103 GroupConstructorsLayout->setSpacing(SPACING);
104 GroupConstructorsLayout->setMargin(MARGIN);
106 Constructor1 = new QRadioButton(GroupConstructors);
107 Constructor1->setIcon(image0);
108 Constructor1->setChecked(true);
110 GroupConstructorsLayout->addWidget(Constructor1);
111 GroupConstructorsLayout->addStretch();
113 /***************************************************************/
114 GroupMesh = new QGroupBox(tr("SMESH_RENUMBERING"), this);
115 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
116 GroupMeshLayout->setMargin(MARGIN);
117 GroupMeshLayout->setSpacing(SPACING);
119 TextLabelMesh = new QLabel(tr("SMESH_MESH"), GroupMesh);
120 SelectButton = new QPushButton(GroupMesh);
121 SelectButton->setIcon(image1);
122 LineEditMesh = new QLineEdit(GroupMesh);
123 LineEditMesh->setReadOnly(true);
125 GroupMeshLayout->addWidget(TextLabelMesh);
126 GroupMeshLayout->addWidget(SelectButton);
127 GroupMeshLayout->addWidget(LineEditMesh);
129 /***************************************************************/
130 GroupButtons = new QGroupBox(this);
131 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
132 GroupButtonsLayout->setSpacing(SPACING);
133 GroupButtonsLayout->setMargin(MARGIN);
135 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
136 buttonOk->setAutoDefault(true);
137 buttonOk->setDefault(true);
138 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
139 buttonApply->setAutoDefault(true);
140 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
141 buttonCancel->setAutoDefault(true);
142 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
143 buttonHelp->setAutoDefault(true);
145 GroupButtonsLayout->addWidget(buttonOk);
146 GroupButtonsLayout->addSpacing(10);
147 GroupButtonsLayout->addWidget(buttonApply);
148 GroupButtonsLayout->addSpacing(10);
149 GroupButtonsLayout->addStretch();
150 GroupButtonsLayout->addWidget(buttonCancel);
151 GroupButtonsLayout->addWidget(buttonHelp);
153 /***************************************************************/
154 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors);
155 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh);
156 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons);
158 Init(); /* Initialisations */
161 //=================================================================================
162 // function : ~SMESHGUI_RenumberingDlg()
163 // purpose : Destroys the object and frees any allocated resources
164 //=================================================================================
165 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
169 //=================================================================================
172 //=================================================================================
173 void SMESHGUI_RenumberingDlg::Init()
176 Constructor1->setChecked(true);
177 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
179 myMesh = SMESH::SMESH_Mesh::_nil();
181 myMeshFilter = new SMESH_TypeFilter (MESH);
183 /* signals and slots connections */
184 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
185 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
186 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
187 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
189 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
190 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
191 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
192 /* to close dialog if study change */
193 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
195 myEditCurrentArgument = LineEditMesh;
196 LineEditMesh->setFocus();
197 mySelectionMgr->clearFilters();
198 mySelectionMgr->installFilter(myMeshFilter);
200 SelectionIntoArgument();
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 void SMESHGUI_RenumberingDlg::ClickOnApply()
209 if (mySMESHGUI->isActiveStudyLocked())
212 if (!myMesh->_is_nil()) {
214 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
215 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
216 bool isUnitsLabeled = false;
218 if (myUnit == 0 && anActor) {
219 isUnitsLabeled = anActor->GetPointsLabeled();
220 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
222 else if (myUnit == 1 && anActor) {
223 isUnitsLabeled = anActor->GetCellsLabeled();
224 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
227 QApplication::setOverrideCursor(Qt::WaitCursor);
229 aMeshEditor->RenumberNodes();
230 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
232 else if (myUnit == 1) {
233 aMeshEditor->RenumberElements();
234 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
236 QApplication::restoreOverrideCursor();
241 //mySelectionMgr->clearSelected();
246 //=================================================================================
247 // function : ClickOnOk()
249 //=================================================================================
250 void SMESHGUI_RenumberingDlg::ClickOnOk()
256 //=================================================================================
257 // function : ClickOnCancel()
259 //=================================================================================
260 void SMESHGUI_RenumberingDlg::ClickOnCancel()
262 //mySelectionMgr->clearSelected();
263 mySelectionMgr->clearFilters();
264 disconnect(mySelectionMgr, 0, this, 0);
265 mySMESHGUI->ResetState();
269 //=================================================================================
270 // function : ClickOnHelp()
272 //=================================================================================
273 void SMESHGUI_RenumberingDlg::ClickOnHelp()
275 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
277 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
281 platform = "winapplication";
283 platform = "application";
285 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
286 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
287 arg(app->resourceMgr()->stringValue("ExternalBrowser",
289 arg(myHelpFileName));
293 //=================================================================================
294 // function : SelectionIntoArgument()
295 // purpose : Called when selection as changed or other case
296 //=================================================================================
297 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
299 if (!GroupButtons->isEnabled()) // inactive
302 QString aString = "";
305 mySelectionMgr->selectedObjects(aList);
306 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
308 if (myEditCurrentArgument == LineEditMesh) {
311 myMesh = SMESH::SMESH_Mesh::_nil();
314 Handle(SALOME_InteractiveObject) IO = aList.First();
315 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
316 if (myMesh->_is_nil())
321 myEditCurrentArgument->setText(aString);
323 bool isEnabled = (!myMesh->_is_nil());
324 buttonOk->setEnabled(isEnabled);
325 buttonApply->setEnabled(isEnabled);
328 //=================================================================================
329 // function : SetEditCurrentArgument()
331 //=================================================================================
332 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
334 QPushButton* send = (QPushButton*)sender();
335 switch (myConstructorId)
337 case 0: /* default constructor */
339 if(send == SelectButton) {
340 LineEditMesh->setFocus();
341 myEditCurrentArgument = LineEditMesh;
343 SelectionIntoArgument();
349 //=================================================================================
350 // function : DeactivateActiveDialog()
352 //=================================================================================
353 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
355 if (GroupConstructors->isEnabled()) {
356 GroupConstructors->setEnabled(false);
357 GroupMesh->setEnabled(false);
358 GroupButtons->setEnabled(false);
359 mySMESHGUI->ResetState();
360 mySMESHGUI->SetActiveDialogBox(0);
364 //=================================================================================
365 // function : ActivateThisDialog()
367 //=================================================================================
368 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
370 /* Emit a signal to deactivate the active dialog */
371 mySMESHGUI->EmitSignalDeactivateDialog();
372 GroupConstructors->setEnabled(true);
373 GroupMesh->setEnabled(true);
374 GroupButtons->setEnabled(true);
376 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
377 SelectionIntoArgument();
380 //=================================================================================
381 // function : enterEvent()
383 //=================================================================================
384 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
386 if (GroupConstructors->isEnabled())
388 ActivateThisDialog();
391 //=================================================================================
392 // function : closeEvent()
394 //=================================================================================
395 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
397 /* same than click on cancel button */
401 //=======================================================================
402 //function : hideEvent
403 //purpose : caused by ESC key
404 //=======================================================================
405 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)
411 //=================================================================================
412 // function : keyPressEvent()
414 //=================================================================================
415 void SMESHGUI_RenumberingDlg::keyPressEvent( QKeyEvent* e )
417 QDialog::keyPressEvent( e );
418 if ( e->isAccepted() )
421 if ( e->key() == Qt::Key_F1 ) {