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>
41 #include <SUIT_OverrideCursor.h>
43 #include <LightApp_Application.h>
44 #include <LightApp_SelectionMgr.h>
46 #include <SALOME_ListIO.hxx>
49 #include <QApplication>
53 #include <QPushButton>
54 #include <QRadioButton>
55 #include <QVBoxLayout>
56 #include <QHBoxLayout>
58 #include <QButtonGroup>
61 #include <SALOMEconfig.h>
62 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
67 //=================================================================================
68 // class : SMESHGUI_RenumberingDlg()
70 //=================================================================================
71 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const int unit)
72 : QDialog( SMESH::GetDesktop( theModule ) ),
73 mySMESHGUI( theModule ),
74 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
79 setAttribute(Qt::WA_DeleteOnClose, true);
80 setWindowTitle(unit == 0 ?
81 tr("SMESH_RENUMBERING_NODES_TITLE") :
82 tr("SMESH_RENUMBERING_ELEMENTS_TITLE"));
83 setSizeGripEnabled(true);
85 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( mySMESHGUI );
86 QPixmap image0(resMgr->loadPixmap("SMESH", unit == 0 ?
87 tr("ICON_DLG_RENUMBERING_NODES") :
88 tr("ICON_DLG_RENUMBERING_ELEMENTS")));
89 QPixmap image1(resMgr->loadPixmap("SMESH",tr("ICON_SELECT")));
91 QVBoxLayout* SMESHGUI_RenumberingDlgLayout = new QVBoxLayout(this);
92 SMESHGUI_RenumberingDlgLayout->setSpacing(SPACING);
93 SMESHGUI_RenumberingDlgLayout->setMargin(MARGIN);
95 /***************************************************************/
96 GroupConstructors = new QGroupBox(unit == 0 ?
100 myHelpFileName = unit == 0 ?
101 "renumbering_nodes_and_elements_page.html#renumbering_nodes_anchor" :
102 "renumbering_nodes_and_elements_page.html#renumbering_elements_anchor";
104 QButtonGroup* ButtonGroup = new QButtonGroup(this);
105 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
106 GroupConstructorsLayout->setSpacing(SPACING);
107 GroupConstructorsLayout->setMargin(MARGIN);
109 Constructor1 = new QRadioButton(GroupConstructors);
110 Constructor1->setIcon(image0);
111 Constructor1->setChecked(true);
113 GroupConstructorsLayout->addWidget(Constructor1);
114 ButtonGroup->addButton(Constructor1, 0);
116 /***************************************************************/
117 GroupMesh = new QGroupBox(tr("SMESH_RENUMBERING"), this);
118 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
119 GroupMeshLayout->setMargin(MARGIN);
120 GroupMeshLayout->setSpacing(SPACING);
122 TextLabelMesh = new QLabel(tr("SMESH_MESH"), GroupMesh);
123 SelectButton = new QPushButton(GroupMesh);
124 SelectButton->setIcon(image1);
125 LineEditMesh = new QLineEdit(GroupMesh);
126 LineEditMesh->setReadOnly(true);
128 GroupMeshLayout->addWidget(TextLabelMesh);
129 GroupMeshLayout->addWidget(SelectButton);
130 GroupMeshLayout->addWidget(LineEditMesh);
132 /***************************************************************/
133 GroupButtons = new QGroupBox(this);
134 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
135 GroupButtonsLayout->setSpacing(SPACING);
136 GroupButtonsLayout->setMargin(MARGIN);
138 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
139 buttonOk->setAutoDefault(true);
140 buttonOk->setDefault(true);
141 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
142 buttonApply->setAutoDefault(true);
143 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
144 buttonCancel->setAutoDefault(true);
145 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
146 buttonHelp->setAutoDefault(true);
148 GroupButtonsLayout->addWidget(buttonOk);
149 GroupButtonsLayout->addSpacing(10);
150 GroupButtonsLayout->addWidget(buttonApply);
151 GroupButtonsLayout->addSpacing(10);
152 GroupButtonsLayout->addStretch();
153 GroupButtonsLayout->addWidget(buttonCancel);
154 GroupButtonsLayout->addWidget(buttonHelp);
156 /***************************************************************/
157 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors);
158 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh);
159 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons);
161 Init(); /* Initialisations */
164 //=================================================================================
165 // function : ~SMESHGUI_RenumberingDlg()
166 // purpose : Destroys the object and frees any allocated resources
167 //=================================================================================
168 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
172 //=================================================================================
175 //=================================================================================
176 void SMESHGUI_RenumberingDlg::Init()
179 Constructor1->setChecked(true);
180 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
182 myMesh = SMESH::SMESH_Mesh::_nil();
184 myMeshFilter = new SMESH_TypeFilter (MESH);
186 /* signals and slots connections */
187 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
188 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
189 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
190 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
192 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
193 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
194 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
195 /* to close dialog if study change */
196 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
198 myEditCurrentArgument = LineEditMesh;
199 LineEditMesh->setFocus();
200 mySelectionMgr->clearFilters();
201 mySelectionMgr->installFilter(myMeshFilter);
203 SelectionIntoArgument();
206 //=================================================================================
207 // function : ClickOnApply()
209 //=================================================================================
210 void SMESHGUI_RenumberingDlg::ClickOnApply()
212 if (mySMESHGUI->isActiveStudyLocked())
215 if (!myMesh->_is_nil()) {
217 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
218 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
219 bool isUnitsLabeled = false;
221 if (myUnit == 0 && anActor) {
222 isUnitsLabeled = anActor->GetPointsLabeled();
223 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
225 else if (myUnit == 1 && anActor) {
226 isUnitsLabeled = anActor->GetCellsLabeled();
227 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
230 SUIT_OverrideCursor aWaitCursor;
232 aMeshEditor->RenumberNodes();
233 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
235 else if (myUnit == 1) {
236 aMeshEditor->RenumberElements();
237 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
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 ) {