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>
66 //=================================================================================
67 // name : SMESHGUI_BuildCompoundDlg
69 //=================================================================================
70 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule )
71 : QDialog(SMESH::GetDesktop(theModule)),
72 mySMESHGUI(theModule),
73 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
76 setAttribute(Qt::WA_DeleteOnClose, true);
77 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
79 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
80 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
81 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
83 setSizeGripEnabled(true);
85 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
86 aTopLayout->setSpacing(SPACING);
87 aTopLayout->setMargin(MARGIN);
89 /***************************************************************/
90 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
91 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
92 GroupConstructorsLayout->setSpacing(SPACING);
93 GroupConstructorsLayout->setMargin(MARGIN);
95 Constructor1 = new QRadioButton(GroupConstructors);
96 Constructor1->setIcon(image0);
97 Constructor1->setChecked(true);
98 GroupConstructorsLayout->addWidget(Constructor1);
99 GroupConstructorsLayout->addStretch();
101 /***************************************************************/
102 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
103 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
104 GroupNameLayout->setSpacing(SPACING);
105 GroupNameLayout->setMargin(MARGIN);
107 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
108 LineEditName = new QLineEdit(GroupName);
110 GroupNameLayout->addWidget(TextLabelName);
111 GroupNameLayout->addWidget(LineEditName);
113 /***************************************************************/
114 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
115 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
116 GroupArgsLayout->setSpacing(SPACING);
117 GroupArgsLayout->setMargin(MARGIN);
119 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
120 SelectButton = new QPushButton(GroupArgs);
121 SelectButton->setIcon(image1);
122 LineEditMeshes = new QLineEdit(GroupArgs);
123 LineEditMeshes->setReadOnly(true);
125 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
126 ComboBoxUnion = new QComboBox(GroupArgs);
128 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
130 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
131 TextLabelTol->setAlignment(Qt::AlignCenter);
132 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
133 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
135 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
136 GroupArgsLayout->addWidget(SelectButton, 0, 1);
137 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
138 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
139 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
140 GroupArgsLayout->addWidget(CheckBoxMerge, 2, 0, 1, 4);
141 GroupArgsLayout->addWidget(TextLabelTol, 3, 0, 1, 2);
142 GroupArgsLayout->addWidget(SpinBoxTol, 3, 2, 1, 2);
144 /***************************************************************/
145 GroupButtons = new QGroupBox(this);
146 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
147 GroupButtonsLayout->setSpacing(SPACING);
148 GroupButtonsLayout->setMargin(MARGIN);
150 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
151 buttonOk->setAutoDefault(true);
152 buttonOk->setDefault(true);
153 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
154 buttonApply->setAutoDefault(true);
155 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
156 buttonCancel->setAutoDefault(true);
157 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
158 buttonHelp->setAutoDefault(true);
160 GroupButtonsLayout->addWidget(buttonOk);
161 GroupButtonsLayout->addSpacing(10);
162 GroupButtonsLayout->addWidget(buttonApply);
163 GroupButtonsLayout->addSpacing(10);
164 GroupButtonsLayout->addStretch();
165 GroupButtonsLayout->addWidget(buttonCancel);
166 GroupButtonsLayout->addWidget(buttonHelp);
168 /***************************************************************/
169 aTopLayout->addWidget(GroupConstructors);
170 aTopLayout->addWidget(GroupName);
171 aTopLayout->addWidget(GroupArgs);
172 aTopLayout->addWidget(GroupButtons);
174 myHelpFileName = "building_compounds_page.html";
176 Init(); // Initialisations
179 //=================================================================================
180 // function : ~SMESHGUI_BuildCompoundDlg()
181 // purpose : Destroys the object and frees any allocated resources
182 //=================================================================================
183 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
187 //=================================================================================
190 //=================================================================================
191 void SMESHGUI_BuildCompoundDlg::Init()
193 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
195 myMesh = SMESH::SMESH_Mesh::_nil();
197 myMeshFilter = new SMESH_TypeFilter (MESH);
199 myMeshArray = new SMESH::mesh_array();
201 // signals and slots connections
202 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
203 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
204 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
205 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
207 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
209 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
211 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
213 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
214 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
216 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
217 LineEditMeshes->setFocus();
219 ComboBoxUnion->addItem(tr("UNITE"));
220 ComboBoxUnion->addItem(tr("RENAME"));
221 ComboBoxUnion->setCurrentIndex(0);
223 CheckBoxMerge->setChecked(false);
225 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
226 SpinBoxTol->SetValue(1e-05);
228 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
230 mySelectionMgr->clearFilters();
231 mySelectionMgr->installFilter(myMeshFilter);
233 SelectionIntoArgument();
236 //=================================================================================
237 // function : GetDefaultName()
239 //=================================================================================
240 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
244 // collect all object names of SMESH component
245 SalomeApp_Study* appStudy =
246 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
247 if ( !appStudy ) return aName;
248 _PTR(Study) aStudy = appStudy->studyDS();
250 std::set<std::string> aSet;
251 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
253 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
255 for (it->InitEx(true); it->More(); it->Next()) {
257 aSet.insert(obj->GetName());
261 // build a unique name
263 bool isUnique = false;
265 aName = theOperation + "_" + QString::number(++aNumber);
266 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
272 //=================================================================================
273 // function : ClickOnApply()
275 //=================================================================================
276 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
278 if (mySMESHGUI->isActiveStudyLocked())
280 if (!myMesh->_is_nil()) {
282 QApplication::setOverrideCursor(Qt::WaitCursor);
284 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
285 // concatenate meshes
286 SMESH::SMESH_Mesh_var aCompoundMesh =
287 aSMESHGen->Concatenate(myMeshArray,
288 !(ComboBoxUnion->currentIndex()),
289 CheckBoxMerge->isChecked(),
290 SpinBoxTol->GetValue());
292 SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text() );
293 QApplication::restoreOverrideCursor();
294 mySMESHGUI->updateObjBrowser();
299 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
301 //mySelectionMgr->clearSelected();
308 //=================================================================================
309 // function : ClickOnOk()
311 //=================================================================================
312 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
318 //=================================================================================
319 // function : ClickOnCancel()
321 //=================================================================================
322 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
324 //mySelectionMgr->clearSelected();
325 mySelectionMgr->clearFilters();
326 disconnect(mySelectionMgr, 0, this, 0);
327 mySMESHGUI->ResetState();
331 //=================================================================================
332 // function : ClickOnHelp()
334 //=================================================================================
335 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
337 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
339 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
341 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
342 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
343 arg(app->resourceMgr()->stringValue("ExternalBrowser",
345 arg(myHelpFileName));
349 //=================================================================================
350 // function : SelectionIntoArgument()
351 // purpose : Called when selection as changed or other case
352 //=================================================================================
353 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
355 if (!GroupButtons->isEnabled()) // inactive
358 QString aString = "";
361 mySelectionMgr->selectedObjects(aList);
362 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
365 myMeshArray->length(nbSel);
366 for (int i = 0; nbSel != 0; i++, nbSel--) {
367 Handle(SALOME_InteractiveObject) IO = aList.First();
369 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
370 myMeshArray[i] = myMesh;
374 myMesh = SMESH::SMESH_Mesh::_nil();
378 LineEditMeshes->setText(aString);
380 bool isEnabled = (!myMesh->_is_nil());
381 buttonOk->setEnabled(isEnabled);
382 buttonApply->setEnabled(isEnabled);
385 //=================================================================================
386 // function : DeactivateActiveDialog()
388 //=================================================================================
389 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
391 if (GroupConstructors->isEnabled()) {
392 GroupConstructors->setEnabled(false);
393 GroupName->setEnabled(false);
394 GroupArgs->setEnabled(false);
395 GroupButtons->setEnabled(false);
396 mySMESHGUI->ResetState();
397 mySMESHGUI->SetActiveDialogBox(0);
401 //=================================================================================
402 // function : ActivateThisDialog()
404 //=================================================================================
405 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
407 /* Emit a signal to deactivate the active dialog */
408 mySMESHGUI->EmitSignalDeactivateDialog();
409 GroupConstructors->setEnabled(true);
410 GroupName->setEnabled(true);
411 GroupArgs->setEnabled(true);
412 GroupButtons->setEnabled(true);
414 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
415 SelectionIntoArgument();
418 //=================================================================================
419 // function : enterEvent()
421 //=================================================================================
422 void SMESHGUI_BuildCompoundDlg::enterEvent( QEvent* )
424 if (GroupConstructors->isEnabled())
426 ActivateThisDialog();
429 //=================================================================================
430 // function : closeEvent()
432 //=================================================================================
433 void SMESHGUI_BuildCompoundDlg::closeEvent( QCloseEvent* )
435 /* same than click on cancel button */
439 //=======================================================================
440 //function : hideEvent
441 //purpose : caused by ESC key
442 //=======================================================================
443 void SMESHGUI_BuildCompoundDlg::hideEvent( QHideEvent* )
450 //=================================================================================
451 // function : keyPressEvent()
453 //=================================================================================
454 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
456 QDialog::keyPressEvent( e );
457 if ( e->isAccepted() )
460 if ( e->key() == Qt::Key_F1 ) {
467 //=================================================================================
468 // function : onSelectMerge()
470 //=================================================================================
471 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
473 TextLabelTol->setEnabled(toMerge);
474 SpinBoxTol->setEnabled(toMerge);