1 // Copyright (C) 2007-2010 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();
249 //=================================================================================
250 // function : ClickOnOk()
252 //=================================================================================
253 void SMESHGUI_RenumberingDlg::ClickOnOk()
259 //=================================================================================
260 // function : ClickOnCancel()
262 //=================================================================================
263 void SMESHGUI_RenumberingDlg::ClickOnCancel()
265 //mySelectionMgr->clearSelected();
266 mySelectionMgr->clearFilters();
267 disconnect(mySelectionMgr, 0, this, 0);
268 mySMESHGUI->ResetState();
272 //=================================================================================
273 // function : ClickOnHelp()
275 //=================================================================================
276 void SMESHGUI_RenumberingDlg::ClickOnHelp()
278 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
280 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
284 platform = "winapplication";
286 platform = "application";
288 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
289 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
290 arg(app->resourceMgr()->stringValue("ExternalBrowser",
292 arg(myHelpFileName));
296 //=================================================================================
297 // function : SelectionIntoArgument()
298 // purpose : Called when selection as changed or other case
299 //=================================================================================
300 void SMESHGUI_RenumberingDlg::SelectionIntoArgument()
302 if (!GroupButtons->isEnabled()) // inactive
305 QString aString = "";
308 mySelectionMgr->selectedObjects(aList);
309 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
311 if (myEditCurrentArgument == LineEditMesh) {
314 myMesh = SMESH::SMESH_Mesh::_nil();
317 Handle(SALOME_InteractiveObject) IO = aList.First();
318 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
319 if (myMesh->_is_nil())
324 myEditCurrentArgument->setText(aString);
326 bool isEnabled = (!myMesh->_is_nil());
327 buttonOk->setEnabled(isEnabled);
328 buttonApply->setEnabled(isEnabled);
331 //=================================================================================
332 // function : SetEditCurrentArgument()
334 //=================================================================================
335 void SMESHGUI_RenumberingDlg::SetEditCurrentArgument()
337 QPushButton* send = (QPushButton*)sender();
338 switch (myConstructorId)
340 case 0: /* default constructor */
342 if(send == SelectButton) {
343 LineEditMesh->setFocus();
344 myEditCurrentArgument = LineEditMesh;
346 SelectionIntoArgument();
352 //=================================================================================
353 // function : DeactivateActiveDialog()
355 //=================================================================================
356 void SMESHGUI_RenumberingDlg::DeactivateActiveDialog()
358 if (GroupConstructors->isEnabled()) {
359 GroupConstructors->setEnabled(false);
360 GroupMesh->setEnabled(false);
361 GroupButtons->setEnabled(false);
362 mySMESHGUI->ResetState();
363 mySMESHGUI->SetActiveDialogBox(0);
367 //=================================================================================
368 // function : ActivateThisDialog()
370 //=================================================================================
371 void SMESHGUI_RenumberingDlg::ActivateThisDialog()
373 /* Emit a signal to deactivate the active dialog */
374 mySMESHGUI->EmitSignalDeactivateDialog();
375 GroupConstructors->setEnabled(true);
376 GroupMesh->setEnabled(true);
377 GroupButtons->setEnabled(true);
379 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
380 SelectionIntoArgument();
383 //=================================================================================
384 // function : enterEvent()
386 //=================================================================================
387 void SMESHGUI_RenumberingDlg::enterEvent(QEvent* e)
389 if (GroupConstructors->isEnabled())
391 ActivateThisDialog();
394 //=================================================================================
395 // function : closeEvent()
397 //=================================================================================
398 void SMESHGUI_RenumberingDlg::closeEvent(QCloseEvent* e)
400 /* same than click on cancel button */
404 //=======================================================================
405 //function : hideEvent
406 //purpose : caused by ESC key
407 //=======================================================================
408 void SMESHGUI_RenumberingDlg::hideEvent (QHideEvent * e)
414 //=================================================================================
415 // function : keyPressEvent()
417 //=================================================================================
418 void SMESHGUI_RenumberingDlg::keyPressEvent( QKeyEvent* e )
420 QDialog::keyPressEvent( e );
421 if ( e->isAccepted() )
424 if ( e->key() == Qt::Key_F1 ) {