1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_RenumberingDlg.cxx
25 // Author : Michael ZORIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_RenumberingDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
34 #include <SMESH_Actor.h>
35 #include <SMESH_TypeFilter.hxx>
37 // SALOME GUI includes
38 #include <SUIT_Desktop.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_MessageBox.h>
42 #include <SUIT_OverrideCursor.h>
44 #include <LightApp_Application.h>
45 #include <LightApp_SelectionMgr.h>
47 #include <SALOME_ListIO.hxx>
50 #include <QApplication>
54 #include <QPushButton>
55 #include <QRadioButton>
56 #include <QVBoxLayout>
57 #include <QHBoxLayout>
59 #include <QButtonGroup>
62 #include <SALOMEconfig.h>
63 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
68 //=================================================================================
69 // class : SMESHGUI_RenumberingDlg()
71 //=================================================================================
72 SMESHGUI_RenumberingDlg::SMESHGUI_RenumberingDlg( SMESHGUI* theModule, const int unit)
73 : QDialog( SMESH::GetDesktop( theModule ) ),
74 mySMESHGUI( theModule ),
75 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
80 setAttribute(Qt::WA_DeleteOnClose, true);
81 setWindowTitle(unit == 0 ?
82 tr("SMESH_RENUMBERING_NODES_TITLE") :
83 tr("SMESH_RENUMBERING_ELEMENTS_TITLE"));
84 setSizeGripEnabled(true);
86 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( mySMESHGUI );
87 QPixmap image0(resMgr->loadPixmap("SMESH", unit == 0 ?
88 tr("ICON_DLG_RENUMBERING_NODES") :
89 tr("ICON_DLG_RENUMBERING_ELEMENTS")));
90 QPixmap image1(resMgr->loadPixmap("SMESH",tr("ICON_SELECT")));
92 QVBoxLayout* SMESHGUI_RenumberingDlgLayout = new QVBoxLayout(this);
93 SMESHGUI_RenumberingDlgLayout->setSpacing(SPACING);
94 SMESHGUI_RenumberingDlgLayout->setMargin(MARGIN);
96 /***************************************************************/
97 GroupConstructors = new QGroupBox(unit == 0 ?
101 myHelpFileName = unit == 0 ?
102 "renumbering_nodes_and_elements_page.html#renumbering_nodes_anchor" :
103 "renumbering_nodes_and_elements_page.html#renumbering_elements_anchor";
105 QButtonGroup* ButtonGroup = new QButtonGroup(this);
106 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
107 GroupConstructorsLayout->setSpacing(SPACING);
108 GroupConstructorsLayout->setMargin(MARGIN);
110 Constructor1 = new QRadioButton(GroupConstructors);
111 Constructor1->setIcon(image0);
112 Constructor1->setChecked(true);
114 GroupConstructorsLayout->addWidget(Constructor1);
115 ButtonGroup->addButton(Constructor1, 0);
117 /***************************************************************/
118 GroupMesh = new QGroupBox(tr("SMESH_RENUMBERING"), this);
119 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
120 GroupMeshLayout->setMargin(MARGIN);
121 GroupMeshLayout->setSpacing(SPACING);
123 TextLabelMesh = new QLabel(tr("SMESH_MESH"), GroupMesh);
124 SelectButton = new QPushButton(GroupMesh);
125 SelectButton->setIcon(image1);
126 LineEditMesh = new QLineEdit(GroupMesh);
127 LineEditMesh->setReadOnly(true);
129 GroupMeshLayout->addWidget(TextLabelMesh);
130 GroupMeshLayout->addWidget(SelectButton);
131 GroupMeshLayout->addWidget(LineEditMesh);
133 /***************************************************************/
134 GroupButtons = new QGroupBox(this);
135 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
136 GroupButtonsLayout->setSpacing(SPACING);
137 GroupButtonsLayout->setMargin(MARGIN);
139 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
140 buttonOk->setAutoDefault(true);
141 buttonOk->setDefault(true);
142 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
143 buttonApply->setAutoDefault(true);
144 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
145 buttonCancel->setAutoDefault(true);
146 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
147 buttonHelp->setAutoDefault(true);
149 GroupButtonsLayout->addWidget(buttonOk);
150 GroupButtonsLayout->addSpacing(10);
151 GroupButtonsLayout->addWidget(buttonApply);
152 GroupButtonsLayout->addSpacing(10);
153 GroupButtonsLayout->addStretch();
154 GroupButtonsLayout->addWidget(buttonCancel);
155 GroupButtonsLayout->addWidget(buttonHelp);
157 /***************************************************************/
158 SMESHGUI_RenumberingDlgLayout->addWidget(GroupConstructors);
159 SMESHGUI_RenumberingDlgLayout->addWidget(GroupMesh);
160 SMESHGUI_RenumberingDlgLayout->addWidget(GroupButtons);
162 Init(); /* Initialisations */
165 //=================================================================================
166 // function : ~SMESHGUI_RenumberingDlg()
167 // purpose : Destroys the object and frees any allocated resources
168 //=================================================================================
169 SMESHGUI_RenumberingDlg::~SMESHGUI_RenumberingDlg()
173 //=================================================================================
176 //=================================================================================
177 void SMESHGUI_RenumberingDlg::Init()
180 Constructor1->setChecked(true);
181 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
183 myMesh = SMESH::SMESH_Mesh::_nil();
185 myMeshFilter = new SMESH_TypeFilter (MESH);
187 /* signals and slots connections */
188 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
189 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
190 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
191 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
193 connect(SelectButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
194 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
195 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
196 /* to close dialog if study change */
197 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
199 myEditCurrentArgument = LineEditMesh;
200 LineEditMesh->setFocus();
201 mySelectionMgr->clearFilters();
202 mySelectionMgr->installFilter(myMeshFilter);
204 SelectionIntoArgument();
207 //=================================================================================
208 // function : ClickOnApply()
210 //=================================================================================
211 void SMESHGUI_RenumberingDlg::ClickOnApply()
213 if (mySMESHGUI->isActiveStudyLocked())
216 if (!myMesh->_is_nil()) {
218 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
219 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
220 bool isUnitsLabeled = false;
222 if (myUnit == 0 && anActor) {
223 isUnitsLabeled = anActor->GetPointsLabeled();
224 if (isUnitsLabeled) anActor->SetPointsLabeled(false);
226 else if (myUnit == 1 && anActor) {
227 isUnitsLabeled = anActor->GetCellsLabeled();
228 if (isUnitsLabeled) anActor->SetCellsLabeled(false);
231 SUIT_OverrideCursor aWaitCursor;
233 aMeshEditor->RenumberNodes();
234 if (isUnitsLabeled && anActor) anActor->SetPointsLabeled(true);
236 else if (myUnit == 1) {
237 aMeshEditor->RenumberElements();
238 if (isUnitsLabeled && anActor) anActor->SetCellsLabeled(true);
244 //mySelectionMgr->clearSelected();
246 SMESHGUI::Modified();
250 //=================================================================================
251 // function : ClickOnOk()
253 //=================================================================================
254 void SMESHGUI_RenumberingDlg::ClickOnOk()
260 //=================================================================================
261 // function : ClickOnCancel()
263 //=================================================================================
264 void SMESHGUI_RenumberingDlg::ClickOnCancel()
266 //mySelectionMgr->clearSelected();
267 mySelectionMgr->clearFilters();
268 disconnect(mySelectionMgr, 0, this, 0);
269 mySMESHGUI->ResetState();
273 //=================================================================================
274 // function : ClickOnHelp()
276 //=================================================================================
277 void SMESHGUI_RenumberingDlg::ClickOnHelp()
279 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
281 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
285 platform = "winapplication";
287 platform = "application";
289 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
290 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
291 arg(app->resourceMgr()->stringValue("ExternalBrowser",
293 arg(myHelpFileName));
297 //=================================================================================
298 // function : SelectionIntoArgument()
299 // purpose : Called when selection as changed or other case
300 //=================================================================================
301 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
303 if (!GroupButtons->isEnabled()) // inactive
306 QString aString = "";
309 mySelectionMgr->selectedObjects(aList);
310 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
312 if (myEditCurrentArgument == LineEditMesh) {
315 myMesh = SMESH::SMESH_Mesh::_nil();
318 Handle(SALOME_InteractiveObject) IO = aList.First();
319 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
320 if (myMesh->_is_nil())
325 myEditCurrentArgument->setText(aString);
327 bool isEnabled = (!myMesh->_is_nil());
328 buttonOk->setEnabled(isEnabled);
329 buttonApply->setEnabled(isEnabled);
332 //=================================================================================
333 // function : SetEditCurrentArgument()
335 //=================================================================================
336 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
338 QPushButton* send = (QPushButton*)sender();
339 switch (myConstructorId)
341 case 0: /* default constructor */
343 if(send == SelectButton) {
344 LineEditMesh->setFocus();
345 myEditCurrentArgument = LineEditMesh;
347 SelectionIntoArgument();
353 //=================================================================================
354 // function : DeactivateActiveDialog()
356 //=================================================================================
357 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
359 if (GroupConstructors->isEnabled()) {
360 GroupConstructors->setEnabled(false);
361 GroupMesh->setEnabled(false);
362 GroupButtons->setEnabled(false);
363 mySMESHGUI->ResetState();
364 mySMESHGUI->SetActiveDialogBox(0);
368 //=================================================================================
369 // function : ActivateThisDialog()
371 //=================================================================================
372 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
374 /* Emit a signal to deactivate the active dialog */
375 mySMESHGUI->EmitSignalDeactivateDialog();
376 GroupConstructors->setEnabled(true);
377 GroupMesh->setEnabled(true);
378 GroupButtons->setEnabled(true);
380 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
381 SelectionIntoArgument();
384 //=================================================================================
385 // function : enterEvent()
387 //=================================================================================
388 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
390 if (GroupConstructors->isEnabled())
392 ActivateThisDialog();
395 //=================================================================================
396 // function : closeEvent()
398 //=================================================================================
399 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
401 /* same than click on cancel button */
405 //=======================================================================
406 //function : hideEvent
407 //purpose : caused by ESC key
408 //=======================================================================
409 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)
415 //=================================================================================
416 // function : keyPressEvent()
418 //=================================================================================
419 void SMESHGUI_RenumberingDlg::keyPressEvent( QKeyEvent* e )
421 QDialog::keyPressEvent( e );
422 if ( e->isAccepted() )
425 if ( e->key() == Qt::Key_F1 ) {