1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_BuildCompoundDlg.cxx
24 // 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 <SalomeApp_Notebook.h>
43 #include <SUIT_OverrideCursor.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <SALOME_ListIO.hxx>
50 #include <QApplication>
54 #include <QPushButton>
55 #include <QRadioButton>
56 #include <QHBoxLayout>
57 #include <QVBoxLayout>
58 #include <QGridLayout>
62 #include <QButtonGroup>
70 //=================================================================================
71 // name : SMESHGUI_BuildCompoundDlg
73 //=================================================================================
74 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule )
75 : QDialog(SMESH::GetDesktop(theModule)),
76 SMESHGUI_Helper(theModule),
77 mySMESHGUI(theModule),
78 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
81 setAttribute(Qt::WA_DeleteOnClose, true);
82 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
84 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
85 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
86 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
88 setSizeGripEnabled(true);
90 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
91 aTopLayout->setSpacing(SPACING);
92 aTopLayout->setMargin(MARGIN);
94 /***************************************************************/
95 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
96 QButtonGroup* ButtonGroup = new QButtonGroup(this);
97 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
98 GroupConstructorsLayout->setSpacing(SPACING);
99 GroupConstructorsLayout->setMargin(MARGIN);
101 Constructor1 = new QRadioButton(GroupConstructors);
102 Constructor1->setIcon(image0);
103 Constructor1->setChecked(true);
104 GroupConstructorsLayout->addWidget(Constructor1);
105 ButtonGroup->addButton(Constructor1, 0);
107 /***************************************************************/
108 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
109 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
110 GroupNameLayout->setSpacing(SPACING);
111 GroupNameLayout->setMargin(MARGIN);
113 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
114 LineEditName = new QLineEdit(GroupName);
116 GroupNameLayout->addWidget(TextLabelName);
117 GroupNameLayout->addWidget(LineEditName);
119 /***************************************************************/
120 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
121 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
122 GroupArgsLayout->setSpacing(SPACING);
123 GroupArgsLayout->setMargin(MARGIN);
125 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
126 SelectButton = new QPushButton(GroupArgs);
127 SelectButton->setIcon(image1);
128 SelectButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
129 LineEditMeshes = new QLineEdit(GroupArgs);
130 LineEditMeshes->setReadOnly(true);
132 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
133 ComboBoxUnion = new QComboBox(GroupArgs);
135 CheckBoxCommon = new QCheckBox(tr("CREATE_COMMON_GROUPS"), GroupArgs);
137 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
139 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
140 TextLabelTol->setAlignment(Qt::AlignCenter);
141 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
142 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, 6);
144 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
145 GroupArgsLayout->addWidget(SelectButton, 0, 1);
146 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
147 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
148 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
149 GroupArgsLayout->addWidget(CheckBoxCommon, 2, 0, 1, 4);
150 GroupArgsLayout->addWidget(CheckBoxMerge, 3, 0, 1, 4);
151 GroupArgsLayout->addWidget(TextLabelTol, 4, 0, 1, 2);
152 GroupArgsLayout->addWidget(SpinBoxTol, 4, 2, 1, 2);
154 /***************************************************************/
155 GroupButtons = new QGroupBox(this);
156 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
157 GroupButtonsLayout->setSpacing(SPACING);
158 GroupButtonsLayout->setMargin(MARGIN);
160 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
161 buttonOk->setAutoDefault(true);
162 buttonOk->setDefault(true);
163 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
164 buttonApply->setAutoDefault(true);
165 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
166 buttonCancel->setAutoDefault(true);
167 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
168 buttonHelp->setAutoDefault(true);
170 GroupButtonsLayout->addWidget(buttonOk);
171 GroupButtonsLayout->addSpacing(10);
172 GroupButtonsLayout->addWidget(buttonApply);
173 GroupButtonsLayout->addSpacing(10);
174 GroupButtonsLayout->addStretch();
175 GroupButtonsLayout->addWidget(buttonCancel);
176 GroupButtonsLayout->addWidget(buttonHelp);
178 /***************************************************************/
179 aTopLayout->addWidget(GroupConstructors);
180 aTopLayout->addWidget(GroupName);
181 aTopLayout->addWidget(GroupArgs);
182 aTopLayout->addWidget(GroupButtons);
184 myHelpFileName = "building_compounds_page.html";
186 Init(); // Initialisations
189 //=================================================================================
190 // function : ~SMESHGUI_BuildCompoundDlg()
191 // purpose : Destroys the object and frees any allocated resources
192 //=================================================================================
193 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
197 //=================================================================================
200 //=================================================================================
201 void SMESHGUI_BuildCompoundDlg::Init()
203 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
205 myMesh = SMESH::SMESH_Mesh::_nil();
207 myMeshFilter = new SMESH_TypeFilter (MESH);
209 myMeshArray = new SMESH::mesh_array();
211 // signals and slots connections
212 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
213 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
214 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
215 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
217 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
219 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
221 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
223 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
224 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
226 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
227 LineEditMeshes->setFocus();
229 ComboBoxUnion->addItem(tr("UNITE"));
230 ComboBoxUnion->addItem(tr("RENAME"));
231 ComboBoxUnion->setCurrentIndex(0);
233 CheckBoxMerge->setChecked(false);
235 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
236 SpinBoxTol->SetValue(1e-05);
238 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
240 mySelectionMgr->clearFilters();
241 mySelectionMgr->installFilter(myMeshFilter);
243 SelectionIntoArgument();
246 //=================================================================================
247 // function : GetDefaultName()
249 //=================================================================================
250 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
254 // collect all object names of SMESH component
255 SalomeApp_Study* appStudy =
256 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
257 if ( !appStudy ) return aName;
258 _PTR(Study) aStudy = appStudy->studyDS();
260 std::set<std::string> aSet;
261 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
263 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
265 for (it->InitEx(true); it->More(); it->Next()) {
267 aSet.insert(obj->GetName());
271 // build a unique name
273 bool isUnique = false;
275 aName = theOperation + "_" + QString::number(++aNumber);
276 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
282 //=================================================================================
283 // function : ClickOnApply()
285 //=================================================================================
286 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
288 if (mySMESHGUI->isActiveStudyLocked())
294 SMESH::SMESH_Mesh_var aCompoundMesh;
296 if (!myMesh->_is_nil()) {
298 SUIT_OverrideCursor aWaitCursor;
300 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
301 // concatenate meshes
302 if(CheckBoxCommon->isChecked())
303 aCompoundMesh = aSMESHGen->ConcatenateWithGroups(myMeshArray,
304 !(ComboBoxUnion->currentIndex()),
305 CheckBoxMerge->isChecked(),
306 SpinBoxTol->GetValue());
308 aCompoundMesh = aSMESHGen->Concatenate(myMeshArray,
309 !(ComboBoxUnion->currentIndex()),
310 CheckBoxMerge->isChecked(),
311 SpinBoxTol->GetValue());
313 if( CheckBoxMerge->isChecked() )
314 getNotebook()->setParameters( aCompoundMesh, 1, SpinBoxTol );
316 SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text() );
317 mySMESHGUI->updateObjBrowser();
322 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
324 // IPAL21468 Compound is hidden after creation.
325 if ( SMESHGUI::automaticUpdate() ) {
326 mySelectionMgr->clearSelected();
329 _PTR(SObject) aSO = SMESH::FindSObject(aCompoundMesh.in());
330 if ( SMESH_Actor* anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str()) )
331 SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
339 //=================================================================================
340 // function : ClickOnOk()
342 //=================================================================================
343 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
349 //=================================================================================
350 // function : ClickOnCancel()
352 //=================================================================================
353 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
355 //mySelectionMgr->clearSelected();
356 mySelectionMgr->clearFilters();
357 disconnect(mySelectionMgr, 0, this, 0);
358 mySMESHGUI->ResetState();
362 //=================================================================================
363 // function : ClickOnHelp()
365 //=================================================================================
366 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
368 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
370 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
372 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
373 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
374 arg(app->resourceMgr()->stringValue("ExternalBrowser",
376 arg(myHelpFileName));
380 //=================================================================================
381 // function : SelectionIntoArgument()
382 // purpose : Called when selection as changed or other case
383 //=================================================================================
384 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
386 if (!GroupButtons->isEnabled()) // inactive
389 QString aString = "";
392 mySelectionMgr->selectedObjects(aList);
393 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
396 myMeshArray->length(nbSel);
397 for (int i = 0; nbSel != 0; i++, nbSel--) {
398 Handle(SALOME_InteractiveObject) IO = aList.First();
400 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
401 myMeshArray[i] = myMesh;
405 myMesh = SMESH::SMESH_Mesh::_nil();
409 LineEditMeshes->setText(aString);
411 bool isEnabled = (!myMesh->_is_nil());
412 buttonOk->setEnabled(isEnabled);
413 buttonApply->setEnabled(isEnabled);
416 //=================================================================================
417 // function : DeactivateActiveDialog()
419 //=================================================================================
420 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
422 if (GroupConstructors->isEnabled()) {
423 GroupConstructors->setEnabled(false);
424 GroupName->setEnabled(false);
425 GroupArgs->setEnabled(false);
426 GroupButtons->setEnabled(false);
427 mySMESHGUI->ResetState();
428 mySMESHGUI->SetActiveDialogBox(0);
432 //=================================================================================
433 // function : ActivateThisDialog()
435 //=================================================================================
436 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
438 /* Emit a signal to deactivate the active dialog */
439 mySMESHGUI->EmitSignalDeactivateDialog();
440 GroupConstructors->setEnabled(true);
441 GroupName->setEnabled(true);
442 GroupArgs->setEnabled(true);
443 GroupButtons->setEnabled(true);
445 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
446 SelectionIntoArgument();
449 //=================================================================================
450 // function : enterEvent()
452 //=================================================================================
453 void SMESHGUI_BuildCompoundDlg::enterEvent( QEvent* )
455 if (GroupConstructors->isEnabled())
457 ActivateThisDialog();
460 //=================================================================================
461 // function : closeEvent()
463 //=================================================================================
464 void SMESHGUI_BuildCompoundDlg::closeEvent( QCloseEvent* )
466 /* same than click on cancel button */
470 //=======================================================================
471 //function : hideEvent
472 //purpose : caused by ESC key
473 //=======================================================================
474 void SMESHGUI_BuildCompoundDlg::hideEvent( QHideEvent* )
481 //=================================================================================
482 // function : keyPressEvent()
484 //=================================================================================
485 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
487 QDialog::keyPressEvent( e );
488 if ( e->isAccepted() )
491 if ( e->key() == Qt::Key_F1 ) {
498 //=================================================================================
499 // function : onSelectMerge()
501 //=================================================================================
502 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
505 TextLabelTol->setEnabled(toMerge);
506 SpinBoxTol->setEnabled(toMerge);
508 SpinBoxTol->SetValue(1e-05);
511 //=================================================================================
512 // function : isValid
514 //=================================================================================
515 bool SMESHGUI_BuildCompoundDlg::isValid()
517 if( CheckBoxMerge->isChecked() )
518 return checkParameters( true, 1, SpinBoxTol );