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_BuildCompoundDlg.cxx
25 // Author : Alexander KOVALEV, Open CASCADE S.A.S.
28 #include "SMESHGUI_BuildCompoundDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_VTKUtils.h"
35 #include <SMESH_TypeFilter.hxx>
37 // SALOME GUI includes
38 #include <SUIT_Desktop.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_MessageBox.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SalomeApp_Study.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 mySMESHGUI(theModule),
77 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
80 setAttribute(Qt::WA_DeleteOnClose, true);
81 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
83 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
84 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
85 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
87 setSizeGripEnabled(true);
89 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
90 aTopLayout->setSpacing(SPACING);
91 aTopLayout->setMargin(MARGIN);
93 /***************************************************************/
94 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
95 QButtonGroup* ButtonGroup = new QButtonGroup(this);
96 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
97 GroupConstructorsLayout->setSpacing(SPACING);
98 GroupConstructorsLayout->setMargin(MARGIN);
100 Constructor1 = new QRadioButton(GroupConstructors);
101 Constructor1->setIcon(image0);
102 Constructor1->setChecked(true);
103 GroupConstructorsLayout->addWidget(Constructor1);
104 ButtonGroup->addButton(Constructor1, 0);
106 /***************************************************************/
107 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
108 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
109 GroupNameLayout->setSpacing(SPACING);
110 GroupNameLayout->setMargin(MARGIN);
112 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
113 LineEditName = new QLineEdit(GroupName);
115 GroupNameLayout->addWidget(TextLabelName);
116 GroupNameLayout->addWidget(LineEditName);
118 /***************************************************************/
119 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
120 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
121 GroupArgsLayout->setSpacing(SPACING);
122 GroupArgsLayout->setMargin(MARGIN);
124 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
125 SelectButton = new QPushButton(GroupArgs);
126 SelectButton->setIcon(image1);
127 SelectButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
128 LineEditMeshes = new QLineEdit(GroupArgs);
129 LineEditMeshes->setReadOnly(true);
131 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
132 ComboBoxUnion = new QComboBox(GroupArgs);
134 CheckBoxCommon = new QCheckBox(tr("CREATE_COMMON_GROUPS"), GroupArgs);
136 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
138 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
139 TextLabelTol->setAlignment(Qt::AlignCenter);
140 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
141 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision" );
143 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
144 GroupArgsLayout->addWidget(SelectButton, 0, 1);
145 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
146 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
147 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
148 GroupArgsLayout->addWidget(CheckBoxCommon, 2, 0, 1, 4);
149 GroupArgsLayout->addWidget(CheckBoxMerge, 3, 0, 1, 4);
150 GroupArgsLayout->addWidget(TextLabelTol, 4, 0, 1, 2);
151 GroupArgsLayout->addWidget(SpinBoxTol, 4, 2, 1, 2);
153 /***************************************************************/
154 GroupButtons = new QGroupBox(this);
155 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
156 GroupButtonsLayout->setSpacing(SPACING);
157 GroupButtonsLayout->setMargin(MARGIN);
159 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
160 buttonOk->setAutoDefault(true);
161 buttonOk->setDefault(true);
162 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
163 buttonApply->setAutoDefault(true);
164 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
165 buttonCancel->setAutoDefault(true);
166 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
167 buttonHelp->setAutoDefault(true);
169 GroupButtonsLayout->addWidget(buttonOk);
170 GroupButtonsLayout->addSpacing(10);
171 GroupButtonsLayout->addWidget(buttonApply);
172 GroupButtonsLayout->addSpacing(10);
173 GroupButtonsLayout->addStretch();
174 GroupButtonsLayout->addWidget(buttonCancel);
175 GroupButtonsLayout->addWidget(buttonHelp);
177 /***************************************************************/
178 aTopLayout->addWidget(GroupConstructors);
179 aTopLayout->addWidget(GroupName);
180 aTopLayout->addWidget(GroupArgs);
181 aTopLayout->addWidget(GroupButtons);
183 myHelpFileName = "building_compounds_page.html";
185 Init(); // Initialisations
188 //=================================================================================
189 // function : ~SMESHGUI_BuildCompoundDlg()
190 // purpose : Destroys the object and frees any allocated resources
191 //=================================================================================
192 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
196 //=================================================================================
199 //=================================================================================
200 void SMESHGUI_BuildCompoundDlg::Init()
202 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
204 myMesh = SMESH::SMESH_Mesh::_nil();
206 myMeshFilter = new SMESH_TypeFilter (MESH);
208 myMeshArray = new SMESH::mesh_array();
210 // signals and slots connections
211 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
212 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
213 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
214 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
216 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
218 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
220 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
222 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
223 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
225 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
226 LineEditMeshes->setFocus();
228 ComboBoxUnion->addItem(tr("UNITE"));
229 ComboBoxUnion->addItem(tr("RENAME"));
230 ComboBoxUnion->setCurrentIndex(0);
232 CheckBoxMerge->setChecked(false);
234 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
235 SpinBoxTol->SetValue(1e-05);
237 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
239 mySelectionMgr->clearFilters();
240 mySelectionMgr->installFilter(myMeshFilter);
242 SelectionIntoArgument();
245 //=================================================================================
246 // function : GetDefaultName()
248 //=================================================================================
249 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
253 // collect all object names of SMESH component
254 SalomeApp_Study* appStudy =
255 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
256 if ( !appStudy ) return aName;
257 _PTR(Study) aStudy = appStudy->studyDS();
259 std::set<std::string> aSet;
260 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
262 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
264 for (it->InitEx(true); it->More(); it->Next()) {
266 aSet.insert(obj->GetName());
270 // build a unique name
272 bool isUnique = false;
274 aName = theOperation + "_" + QString::number(++aNumber);
275 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
281 //=================================================================================
282 // function : ClickOnApply()
284 //=================================================================================
285 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
287 if (mySMESHGUI->isActiveStudyLocked())
293 SMESH::SMESH_Mesh_var aCompoundMesh;
295 if (!myMesh->_is_nil()) {
296 QStringList aParameters;
297 aParameters << (CheckBoxMerge->isChecked() ? SpinBoxTol->text() : QString(" "));
299 SUIT_OverrideCursor aWaitCursor;
301 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
302 // concatenate meshes
303 if(CheckBoxCommon->isChecked())
304 aCompoundMesh = aSMESHGen->ConcatenateWithGroups(myMeshArray,
305 !(ComboBoxUnion->currentIndex()),
306 CheckBoxMerge->isChecked(),
307 SpinBoxTol->GetValue());
309 aCompoundMesh = aSMESHGen->Concatenate(myMeshArray,
310 !(ComboBoxUnion->currentIndex()),
311 CheckBoxMerge->isChecked(),
312 SpinBoxTol->GetValue());
314 aCompoundMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
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()
519 if(CheckBoxMerge->isChecked())
520 ok = SpinBoxTol->isValid( msg, true );
523 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
524 if ( !msg.isEmpty() )
526 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );