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_BuildCompoundDlg.cxx
23 // Author : Alexander KOVALEV, Open CASCADE S.A.S.
27 #include "SMESHGUI_BuildCompoundDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_SpinBox.h"
32 #include "SMESHGUI_VTKUtils.h"
34 #include <SMESH_TypeFilter.hxx>
36 // SALOME GUI includes
37 #include <SUIT_Desktop.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SalomeApp_Study.h>
42 #include <LightApp_Application.h>
43 #include <LightApp_SelectionMgr.h>
44 #include <SALOME_ListIO.hxx>
47 #include <QApplication>
51 #include <QPushButton>
52 #include <QRadioButton>
53 #include <QHBoxLayout>
54 #include <QVBoxLayout>
55 #include <QGridLayout>
59 #include <QButtonGroup>
67 //=================================================================================
68 // name : SMESHGUI_BuildCompoundDlg
70 //=================================================================================
71 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule )
72 : QDialog(SMESH::GetDesktop(theModule)),
73 mySMESHGUI(theModule),
74 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
77 setAttribute(Qt::WA_DeleteOnClose, true);
78 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
80 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
81 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
82 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
84 setSizeGripEnabled(true);
86 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
87 aTopLayout->setSpacing(SPACING);
88 aTopLayout->setMargin(MARGIN);
90 /***************************************************************/
91 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
92 QButtonGroup* ButtonGroup = new QButtonGroup(this);
93 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
94 GroupConstructorsLayout->setSpacing(SPACING);
95 GroupConstructorsLayout->setMargin(MARGIN);
97 Constructor1 = new QRadioButton(GroupConstructors);
98 Constructor1->setIcon(image0);
99 Constructor1->setChecked(true);
100 GroupConstructorsLayout->addWidget(Constructor1);
101 ButtonGroup->addButton(Constructor1, 0);
103 /***************************************************************/
104 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
105 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
106 GroupNameLayout->setSpacing(SPACING);
107 GroupNameLayout->setMargin(MARGIN);
109 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
110 LineEditName = new QLineEdit(GroupName);
112 GroupNameLayout->addWidget(TextLabelName);
113 GroupNameLayout->addWidget(LineEditName);
115 /***************************************************************/
116 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
117 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
118 GroupArgsLayout->setSpacing(SPACING);
119 GroupArgsLayout->setMargin(MARGIN);
121 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
122 SelectButton = new QPushButton(GroupArgs);
123 SelectButton->setIcon(image1);
124 LineEditMeshes = new QLineEdit(GroupArgs);
125 LineEditMeshes->setReadOnly(true);
127 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
128 ComboBoxUnion = new QComboBox(GroupArgs);
130 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
132 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
133 TextLabelTol->setAlignment(Qt::AlignCenter);
134 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
135 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
137 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
138 GroupArgsLayout->addWidget(SelectButton, 0, 1);
139 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
140 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
141 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
142 GroupArgsLayout->addWidget(CheckBoxMerge, 2, 0, 1, 4);
143 GroupArgsLayout->addWidget(TextLabelTol, 3, 0, 1, 2);
144 GroupArgsLayout->addWidget(SpinBoxTol, 3, 2, 1, 2);
146 /***************************************************************/
147 GroupButtons = new QGroupBox(this);
148 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
149 GroupButtonsLayout->setSpacing(SPACING);
150 GroupButtonsLayout->setMargin(MARGIN);
152 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
153 buttonOk->setAutoDefault(true);
154 buttonOk->setDefault(true);
155 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
156 buttonApply->setAutoDefault(true);
157 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
158 buttonCancel->setAutoDefault(true);
159 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
160 buttonHelp->setAutoDefault(true);
162 GroupButtonsLayout->addWidget(buttonOk);
163 GroupButtonsLayout->addSpacing(10);
164 GroupButtonsLayout->addWidget(buttonApply);
165 GroupButtonsLayout->addSpacing(10);
166 GroupButtonsLayout->addStretch();
167 GroupButtonsLayout->addWidget(buttonCancel);
168 GroupButtonsLayout->addWidget(buttonHelp);
170 /***************************************************************/
171 aTopLayout->addWidget(GroupConstructors);
172 aTopLayout->addWidget(GroupName);
173 aTopLayout->addWidget(GroupArgs);
174 aTopLayout->addWidget(GroupButtons);
176 myHelpFileName = "building_compounds_page.html";
178 Init(); // Initialisations
181 //=================================================================================
182 // function : ~SMESHGUI_BuildCompoundDlg()
183 // purpose : Destroys the object and frees any allocated resources
184 //=================================================================================
185 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
189 //=================================================================================
192 //=================================================================================
193 void SMESHGUI_BuildCompoundDlg::Init()
195 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
197 myMesh = SMESH::SMESH_Mesh::_nil();
199 myMeshFilter = new SMESH_TypeFilter (MESH);
201 myMeshArray = new SMESH::mesh_array();
203 // signals and slots connections
204 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
205 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
206 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
207 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
209 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
211 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
213 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
215 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
216 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
218 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
219 LineEditMeshes->setFocus();
221 ComboBoxUnion->addItem(tr("UNITE"));
222 ComboBoxUnion->addItem(tr("RENAME"));
223 ComboBoxUnion->setCurrentIndex(0);
225 CheckBoxMerge->setChecked(false);
227 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
228 SpinBoxTol->SetValue(1e-05);
230 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
232 mySelectionMgr->clearFilters();
233 mySelectionMgr->installFilter(myMeshFilter);
235 SelectionIntoArgument();
238 //=================================================================================
239 // function : GetDefaultName()
241 //=================================================================================
242 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
246 // collect all object names of SMESH component
247 SalomeApp_Study* appStudy =
248 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
249 if ( !appStudy ) return aName;
250 _PTR(Study) aStudy = appStudy->studyDS();
252 std::set<std::string> aSet;
253 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
255 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
257 for (it->InitEx(true); it->More(); it->Next()) {
259 aSet.insert(obj->GetName());
263 // build a unique name
265 bool isUnique = false;
267 aName = theOperation + "_" + QString::number(++aNumber);
268 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
274 //=================================================================================
275 // function : ClickOnApply()
277 //=================================================================================
278 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
280 if (mySMESHGUI->isActiveStudyLocked())
282 if (!myMesh->_is_nil()) {
284 QApplication::setOverrideCursor(Qt::WaitCursor);
286 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
287 // concatenate meshes
288 SMESH::SMESH_Mesh_var aCompoundMesh =
289 aSMESHGen->Concatenate(myMeshArray,
290 !(ComboBoxUnion->currentIndex()),
291 CheckBoxMerge->isChecked(),
292 SpinBoxTol->GetValue());
294 SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text() );
295 QApplication::restoreOverrideCursor();
296 mySMESHGUI->updateObjBrowser();
301 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
303 //mySelectionMgr->clearSelected();
310 //=================================================================================
311 // function : ClickOnOk()
313 //=================================================================================
314 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
320 //=================================================================================
321 // function : ClickOnCancel()
323 //=================================================================================
324 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
326 //mySelectionMgr->clearSelected();
327 mySelectionMgr->clearFilters();
328 disconnect(mySelectionMgr, 0, this, 0);
329 mySMESHGUI->ResetState();
333 //=================================================================================
334 // function : ClickOnHelp()
336 //=================================================================================
337 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
339 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
341 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
343 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
344 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
345 arg(app->resourceMgr()->stringValue("ExternalBrowser",
347 arg(myHelpFileName));
351 //=================================================================================
352 // function : SelectionIntoArgument()
353 // purpose : Called when selection as changed or other case
354 //=================================================================================
355 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
357 if (!GroupButtons->isEnabled()) // inactive
360 QString aString = "";
363 mySelectionMgr->selectedObjects(aList);
364 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
367 myMeshArray->length(nbSel);
368 for (int i = 0; nbSel != 0; i++, nbSel--) {
369 Handle(SALOME_InteractiveObject) IO = aList.First();
371 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
372 myMeshArray[i] = myMesh;
376 myMesh = SMESH::SMESH_Mesh::_nil();
380 LineEditMeshes->setText(aString);
382 bool isEnabled = (!myMesh->_is_nil());
383 buttonOk->setEnabled(isEnabled);
384 buttonApply->setEnabled(isEnabled);
387 //=================================================================================
388 // function : DeactivateActiveDialog()
390 //=================================================================================
391 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
393 if (GroupConstructors->isEnabled()) {
394 GroupConstructors->setEnabled(false);
395 GroupName->setEnabled(false);
396 GroupArgs->setEnabled(false);
397 GroupButtons->setEnabled(false);
398 mySMESHGUI->ResetState();
399 mySMESHGUI->SetActiveDialogBox(0);
403 //=================================================================================
404 // function : ActivateThisDialog()
406 //=================================================================================
407 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
409 /* Emit a signal to deactivate the active dialog */
410 mySMESHGUI->EmitSignalDeactivateDialog();
411 GroupConstructors->setEnabled(true);
412 GroupName->setEnabled(true);
413 GroupArgs->setEnabled(true);
414 GroupButtons->setEnabled(true);
416 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
417 SelectionIntoArgument();
420 //=================================================================================
421 // function : enterEvent()
423 //=================================================================================
424 void SMESHGUI_BuildCompoundDlg::enterEvent( QEvent* )
426 if (GroupConstructors->isEnabled())
428 ActivateThisDialog();
431 //=================================================================================
432 // function : closeEvent()
434 //=================================================================================
435 void SMESHGUI_BuildCompoundDlg::closeEvent( QCloseEvent* )
437 /* same than click on cancel button */
441 //=======================================================================
442 //function : hideEvent
443 //purpose : caused by ESC key
444 //=======================================================================
445 void SMESHGUI_BuildCompoundDlg::hideEvent( QHideEvent* )
452 //=================================================================================
453 // function : keyPressEvent()
455 //=================================================================================
456 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
458 QDialog::keyPressEvent( e );
459 if ( e->isAccepted() )
462 if ( e->key() == Qt::Key_F1 ) {
469 //=================================================================================
470 // function : onSelectMerge()
472 //=================================================================================
473 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
475 TextLabelTol->setEnabled(toMerge);
476 SpinBoxTol->setEnabled(toMerge);