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>
57 #include <QButtonGroup>
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
66 //=================================================================================
67 // class : SMESHGUI_RenumberingDlg()
69 //=================================================================================
70 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const int unit)
71 : QDialog( SMESH::GetDesktop( theModule ) ),
72 mySMESHGUI( theModule ),
73 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
78 setAttribute(Qt::WA_DeleteOnClose, true);
79 setWindowTitle(unit == 0 ?
80 tr("SMESH_RENUMBERING_NODES_TITLE") :
81 tr("SMESH_RENUMBERING_ELEMENTS_TITLE"));
82 setSizeGripEnabled(true);
84 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( mySMESHGUI );
85 QPixmap image0(resMgr->loadPixmap("SMESH", unit == 0 ?
86 tr("ICON_DLG_RENUMBERING_NODES") :
87 tr("ICON_DLG_RENUMBERING_ELEMENTS")));
88 QPixmap image1(resMgr->loadPixmap("SMESH",tr("ICON_SELECT")));
90 QVBoxLayout* SMESHGUI_RenumberingDlgLayout = new QVBoxLayout(this);
91 SMESHGUI_RenumberingDlgLayout->setSpacing(SPACING);
92 SMESHGUI_RenumberingDlgLayout->setMargin(MARGIN);
94 /***************************************************************/
95 GroupConstructors = new QGroupBox(unit == 0 ?
99 myHelpFileName = unit == 0 ?
100 "renumbering_nodes_and_elements_page.html#renumbering_nodes_anchor" :
101 "renumbering_nodes_and_elements_page.html#renumbering_elements_anchor";
103 QButtonGroup* ButtonGroup = new QButtonGroup(this);
104 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
105 GroupConstructorsLayout->setSpacing(SPACING);
106 GroupConstructorsLayout->setMargin(MARGIN);
108 Constructor1 = new QRadioButton(GroupConstructors);
109 Constructor1->setIcon(image0);
110 Constructor1->setChecked(true);
112 GroupConstructorsLayout->addWidget(Constructor1);
113 ButtonGroup->addButton(Constructor1, 0);
115 /***************************************************************/
116 GroupMesh = new QGroupBox(tr("SMESH_RENUMBERING"), this);
117 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
118 GroupMeshLayout->setMargin(MARGIN);
119 GroupMeshLayout->setSpacing(SPACING);
121 TextLabelMesh = new QLabel(tr("SMESH_MESH"), GroupMesh);
122 SelectButton = new QPushButton(GroupMesh);
123 SelectButton->setIcon(image1);
124 LineEditMesh = new QLineEdit(GroupMesh);
125 LineEditMesh->setReadOnly(true);
127 GroupMeshLayout->addWidget(TextLabelMesh);
128 GroupMeshLayout->addWidget(SelectButton);
129 GroupMeshLayout->addWidget(LineEditMesh);
131 /***************************************************************/
132 GroupButtons = new QGroupBox(this);
133 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
134 GroupButtonsLayout->setSpacing(SPACING);
135 GroupButtonsLayout->setMargin(MARGIN);
137 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
138 buttonOk->setAutoDefault(true);
139 buttonOk->setDefault(true);
140 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
141 buttonApply->setAutoDefault(true);
142 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
143 buttonCancel->setAutoDefault(true);
144 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
145 buttonHelp->setAutoDefault(true);
147 GroupButtonsLayout->addWidget(buttonOk);
148 GroupButtonsLayout->addSpacing(10);
149 GroupButtonsLayout->addWidget(buttonApply);
150 GroupButtonsLayout->addSpacing(10);
151 GroupButtonsLayout->addStretch();
152 GroupButtonsLayout->addWidget(buttonCancel);
153 GroupButtonsLayout->addWidget(buttonHelp);
155 /***************************************************************/
156 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors);
157 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh);
158 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons);
160 Init(); /* Initialisations */
163 //=================================================================================
164 // function : ~SMESHGUI_RenumberingDlg()
165 // purpose : Destroys the object and frees any allocated resources
166 //=================================================================================
167 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
171 //=================================================================================
174 //=================================================================================
175 void SMESHGUI_RenumberingDlg::Init()
178 Constructor1->setChecked(true);
179 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
181 myMesh = SMESH::SMESH_Mesh::_nil();
183 myMeshFilter = new SMESH_TypeFilter (MESH);
185 /* signals and slots connections */
186 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
187 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
188 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
189 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
191 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
192 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
193 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
194 /* to close dialog if study change */
195 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
197 myEditCurrentArgument = LineEditMesh;
198 LineEditMesh->setFocus();
199 mySelectionMgr->clearFilters();
200 mySelectionMgr->installFilter(myMeshFilter);
202 SelectionIntoArgument();
205 //=================================================================================
206 // function : ClickOnApply()
208 //=================================================================================
209 void SMESHGUI_RenumberingDlg::ClickOnApply()
211 if (mySMESHGUI->isActiveStudyLocked())
214 if (!myMesh->_is_nil()) {
216 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
217 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
218 bool isUnitsLabeled = false;
220 if (myUnit == 0 && anActor) {
221 isUnitsLabeled = anActor->GetPointsLabeled();
222 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
224 else if (myUnit == 1 && anActor) {
225 isUnitsLabeled = anActor->GetCellsLabeled();
226 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
229 QApplication::setOverrideCursor(Qt::WaitCursor);
231 aMeshEditor->RenumberNodes();
232 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
234 else if (myUnit == 1) {
235 aMeshEditor->RenumberElements();
236 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
238 QApplication::restoreOverrideCursor();
243 //mySelectionMgr->clearSelected();
248 //=================================================================================
249 // function : ClickOnOk()
251 //=================================================================================
252 void SMESHGUI_RenumberingDlg::ClickOnOk()
258 //=================================================================================
259 // function : ClickOnCancel()
261 //=================================================================================
262 void SMESHGUI_RenumberingDlg::ClickOnCancel()
264 //mySelectionMgr->clearSelected();
265 mySelectionMgr->clearFilters();
266 disconnect(mySelectionMgr, 0, this, 0);
267 mySMESHGUI->ResetState();
271 //=================================================================================
272 // function : ClickOnHelp()
274 //=================================================================================
275 void SMESHGUI_RenumberingDlg::ClickOnHelp()
277 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
279 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
283 platform = "winapplication";
285 platform = "application";
287 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
288 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
289 arg(app->resourceMgr()->stringValue("ExternalBrowser",
291 arg(myHelpFileName));
295 //=================================================================================
296 // function : SelectionIntoArgument()
297 // purpose : Called when selection as changed or other case
298 //=================================================================================
299 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
301 if (!GroupButtons->isEnabled()) // inactive
304 QString aString = "";
307 mySelectionMgr->selectedObjects(aList);
308 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
310 if (myEditCurrentArgument == LineEditMesh) {
313 myMesh = SMESH::SMESH_Mesh::_nil();
316 Handle(SALOME_InteractiveObject) IO = aList.First();
317 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
318 if (myMesh->_is_nil())
323 myEditCurrentArgument->setText(aString);
325 bool isEnabled = (!myMesh->_is_nil());
326 buttonOk->setEnabled(isEnabled);
327 buttonApply->setEnabled(isEnabled);
330 //=================================================================================
331 // function : SetEditCurrentArgument()
333 //=================================================================================
334 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
336 QPushButton* send = (QPushButton*)sender();
337 switch (myConstructorId)
339 case 0: /* default constructor */
341 if(send == SelectButton) {
342 LineEditMesh->setFocus();
343 myEditCurrentArgument = LineEditMesh;
345 SelectionIntoArgument();
351 //=================================================================================
352 // function : DeactivateActiveDialog()
354 //=================================================================================
355 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
357 if (GroupConstructors->isEnabled()) {
358 GroupConstructors->setEnabled(false);
359 GroupMesh->setEnabled(false);
360 GroupButtons->setEnabled(false);
361 mySMESHGUI->ResetState();
362 mySMESHGUI->SetActiveDialogBox(0);
366 //=================================================================================
367 // function : ActivateThisDialog()
369 //=================================================================================
370 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
372 /* Emit a signal to deactivate the active dialog */
373 mySMESHGUI->EmitSignalDeactivateDialog();
374 GroupConstructors->setEnabled(true);
375 GroupMesh->setEnabled(true);
376 GroupButtons->setEnabled(true);
378 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
379 SelectionIntoArgument();
382 //=================================================================================
383 // function : enterEvent()
385 //=================================================================================
386 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
388 if (GroupConstructors->isEnabled())
390 ActivateThisDialog();
393 //=================================================================================
394 // function : closeEvent()
396 //=================================================================================
397 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
399 /* same than click on cancel button */
403 //=======================================================================
404 //function : hideEvent
405 //purpose : caused by ESC key
406 //=======================================================================
407 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)
413 //=================================================================================
414 // function : keyPressEvent()
416 //=================================================================================
417 void SMESHGUI_RenumberingDlg::keyPressEvent( QKeyEvent* e )
419 QDialog::keyPressEvent( e );
420 if ( e->isAccepted() )
423 if ( e->key() == Qt::Key_F1 ) {