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 <SUIT_OverrideCursor.h>
44 #include <LightApp_Application.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <SALOME_ListIO.hxx>
49 #include <QApplication>
53 #include <QPushButton>
54 #include <QRadioButton>
55 #include <QHBoxLayout>
56 #include <QVBoxLayout>
57 #include <QGridLayout>
61 #include <QButtonGroup>
69 //=================================================================================
70 // name : SMESHGUI_BuildCompoundDlg
72 //=================================================================================
73 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule )
74 : QDialog(SMESH::GetDesktop(theModule)),
75 mySMESHGUI(theModule),
76 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
79 setAttribute(Qt::WA_DeleteOnClose, true);
80 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
82 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
83 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
84 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
86 setSizeGripEnabled(true);
88 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
89 aTopLayout->setSpacing(SPACING);
90 aTopLayout->setMargin(MARGIN);
92 /***************************************************************/
93 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
94 QButtonGroup* ButtonGroup = new QButtonGroup(this);
95 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
96 GroupConstructorsLayout->setSpacing(SPACING);
97 GroupConstructorsLayout->setMargin(MARGIN);
99 Constructor1 = new QRadioButton(GroupConstructors);
100 Constructor1->setIcon(image0);
101 Constructor1->setChecked(true);
102 GroupConstructorsLayout->addWidget(Constructor1);
103 ButtonGroup->addButton(Constructor1, 0);
105 /***************************************************************/
106 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
107 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
108 GroupNameLayout->setSpacing(SPACING);
109 GroupNameLayout->setMargin(MARGIN);
111 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
112 LineEditName = new QLineEdit(GroupName);
114 GroupNameLayout->addWidget(TextLabelName);
115 GroupNameLayout->addWidget(LineEditName);
117 /***************************************************************/
118 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
119 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
120 GroupArgsLayout->setSpacing(SPACING);
121 GroupArgsLayout->setMargin(MARGIN);
123 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
124 SelectButton = new QPushButton(GroupArgs);
125 SelectButton->setIcon(image1);
126 LineEditMeshes = new QLineEdit(GroupArgs);
127 LineEditMeshes->setReadOnly(true);
129 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
130 ComboBoxUnion = new QComboBox(GroupArgs);
132 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
134 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
135 TextLabelTol->setAlignment(Qt::AlignCenter);
136 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
137 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, 6);
139 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
140 GroupArgsLayout->addWidget(SelectButton, 0, 1);
141 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
142 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
143 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
144 GroupArgsLayout->addWidget(CheckBoxMerge, 2, 0, 1, 4);
145 GroupArgsLayout->addWidget(TextLabelTol, 3, 0, 1, 2);
146 GroupArgsLayout->addWidget(SpinBoxTol, 3, 2, 1, 2);
148 /***************************************************************/
149 GroupButtons = new QGroupBox(this);
150 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
151 GroupButtonsLayout->setSpacing(SPACING);
152 GroupButtonsLayout->setMargin(MARGIN);
154 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
155 buttonOk->setAutoDefault(true);
156 buttonOk->setDefault(true);
157 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
158 buttonApply->setAutoDefault(true);
159 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
160 buttonCancel->setAutoDefault(true);
161 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
162 buttonHelp->setAutoDefault(true);
164 GroupButtonsLayout->addWidget(buttonOk);
165 GroupButtonsLayout->addSpacing(10);
166 GroupButtonsLayout->addWidget(buttonApply);
167 GroupButtonsLayout->addSpacing(10);
168 GroupButtonsLayout->addStretch();
169 GroupButtonsLayout->addWidget(buttonCancel);
170 GroupButtonsLayout->addWidget(buttonHelp);
172 /***************************************************************/
173 aTopLayout->addWidget(GroupConstructors);
174 aTopLayout->addWidget(GroupName);
175 aTopLayout->addWidget(GroupArgs);
176 aTopLayout->addWidget(GroupButtons);
178 myHelpFileName = "building_compounds_page.html";
180 Init(); // Initialisations
183 //=================================================================================
184 // function : ~SMESHGUI_BuildCompoundDlg()
185 // purpose : Destroys the object and frees any allocated resources
186 //=================================================================================
187 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
191 //=================================================================================
194 //=================================================================================
195 void SMESHGUI_BuildCompoundDlg::Init()
197 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
199 myMesh = SMESH::SMESH_Mesh::_nil();
201 myMeshFilter = new SMESH_TypeFilter (MESH);
203 myMeshArray = new SMESH::mesh_array();
205 // signals and slots connections
206 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
207 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
208 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
209 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
211 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
213 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
215 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
217 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
218 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
220 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
221 LineEditMeshes->setFocus();
223 ComboBoxUnion->addItem(tr("UNITE"));
224 ComboBoxUnion->addItem(tr("RENAME"));
225 ComboBoxUnion->setCurrentIndex(0);
227 CheckBoxMerge->setChecked(false);
229 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
230 SpinBoxTol->SetValue(1e-05);
232 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
234 mySelectionMgr->clearFilters();
235 mySelectionMgr->installFilter(myMeshFilter);
237 SelectionIntoArgument();
240 //=================================================================================
241 // function : GetDefaultName()
243 //=================================================================================
244 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
248 // collect all object names of SMESH component
249 SalomeApp_Study* appStudy =
250 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
251 if ( !appStudy ) return aName;
252 _PTR(Study) aStudy = appStudy->studyDS();
254 std::set<std::string> aSet;
255 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
257 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
259 for (it->InitEx(true); it->More(); it->Next()) {
261 aSet.insert(obj->GetName());
265 // build a unique name
267 bool isUnique = false;
269 aName = theOperation + "_" + QString::number(++aNumber);
270 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
276 //=================================================================================
277 // function : ClickOnApply()
279 //=================================================================================
280 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
282 if (mySMESHGUI->isActiveStudyLocked())
284 if (!myMesh->_is_nil()) {
286 SUIT_OverrideCursor aWaitCursor;
288 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
289 // concatenate meshes
290 SMESH::SMESH_Mesh_var aCompoundMesh =
291 aSMESHGen->Concatenate(myMeshArray,
292 !(ComboBoxUnion->currentIndex()),
293 CheckBoxMerge->isChecked(),
294 SpinBoxTol->GetValue());
296 SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text() );
297 mySMESHGUI->updateObjBrowser();
302 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
304 //mySelectionMgr->clearSelected();
311 //=================================================================================
312 // function : ClickOnOk()
314 //=================================================================================
315 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
321 //=================================================================================
322 // function : ClickOnCancel()
324 //=================================================================================
325 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
327 //mySelectionMgr->clearSelected();
328 mySelectionMgr->clearFilters();
329 disconnect(mySelectionMgr, 0, this, 0);
330 mySMESHGUI->ResetState();
334 //=================================================================================
335 // function : ClickOnHelp()
337 //=================================================================================
338 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
340 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
342 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
344 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
345 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
346 arg(app->resourceMgr()->stringValue("ExternalBrowser",
348 arg(myHelpFileName));
352 //=================================================================================
353 // function : SelectionIntoArgument()
354 // purpose : Called when selection as changed or other case
355 //=================================================================================
356 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
358 if (!GroupButtons->isEnabled()) // inactive
361 QString aString = "";
364 mySelectionMgr->selectedObjects(aList);
365 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
368 myMeshArray->length(nbSel);
369 for (int i = 0; nbSel != 0; i++, nbSel--) {
370 Handle(SALOME_InteractiveObject) IO = aList.First();
372 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
373 myMeshArray[i] = myMesh;
377 myMesh = SMESH::SMESH_Mesh::_nil();
381 LineEditMeshes->setText(aString);
383 bool isEnabled = (!myMesh->_is_nil());
384 buttonOk->setEnabled(isEnabled);
385 buttonApply->setEnabled(isEnabled);
388 //=================================================================================
389 // function : DeactivateActiveDialog()
391 //=================================================================================
392 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
394 if (GroupConstructors->isEnabled()) {
395 GroupConstructors->setEnabled(false);
396 GroupName->setEnabled(false);
397 GroupArgs->setEnabled(false);
398 GroupButtons->setEnabled(false);
399 mySMESHGUI->ResetState();
400 mySMESHGUI->SetActiveDialogBox(0);
404 //=================================================================================
405 // function : ActivateThisDialog()
407 //=================================================================================
408 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
410 /* Emit a signal to deactivate the active dialog */
411 mySMESHGUI->EmitSignalDeactivateDialog();
412 GroupConstructors->setEnabled(true);
413 GroupName->setEnabled(true);
414 GroupArgs->setEnabled(true);
415 GroupButtons->setEnabled(true);
417 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
418 SelectionIntoArgument();
421 //=================================================================================
422 // function : enterEvent()
424 //=================================================================================
425 void SMESHGUI_BuildCompoundDlg::enterEvent( QEvent* )
427 if (GroupConstructors->isEnabled())
429 ActivateThisDialog();
432 //=================================================================================
433 // function : closeEvent()
435 //=================================================================================
436 void SMESHGUI_BuildCompoundDlg::closeEvent( QCloseEvent* )
438 /* same than click on cancel button */
442 //=======================================================================
443 //function : hideEvent
444 //purpose : caused by ESC key
445 //=======================================================================
446 void SMESHGUI_BuildCompoundDlg::hideEvent( QHideEvent* )
453 //=================================================================================
454 // function : keyPressEvent()
456 //=================================================================================
457 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
459 QDialog::keyPressEvent( e );
460 if ( e->isAccepted() )
463 if ( e->key() == Qt::Key_F1 ) {
470 //=================================================================================
471 // function : onSelectMerge()
473 //=================================================================================
474 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
476 TextLabelTol->setEnabled(toMerge);
477 SpinBoxTol->setEnabled(toMerge);