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
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 #include "SUIT_Desktop.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_MessageBox.h"
39 #include "SalomeApp_Study.h"
41 #include "LightApp_Application.h"
43 #include "SALOME_ListIO.hxx"
45 #include "utilities.h"
48 #include <qapplication.h>
49 #include <qbuttongroup.h>
50 #include <qgroupbox.h>
52 #include <qlineedit.h>
53 #include <qpushbutton.h>
54 #include <qradiobutton.h>
57 #include <qcheckbox.h>
58 #include <qcombobox.h>
59 #include <qsizepolicy.h>
65 //=================================================================================
66 // name : SMESHGUI_BuildCompoundDlg
68 //=================================================================================
69 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule)
70 : QDialog(SMESH::GetDesktop(theModule), "SMESHGUI_BuildCompoundDlg", false, WStyle_Customize |
71 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
72 mySMESHGUI(theModule),
73 mySelectionMgr(SMESH::GetSelectionMgr(theModule))
75 setCaption(tr("SMESH_BUILD_COMPOUND_TITLE"));
77 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
78 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
79 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
81 setSizeGripEnabled(TRUE);
82 SMESHGUI_BuildCompoundDlgLayout = new QGridLayout (this);
83 SMESHGUI_BuildCompoundDlgLayout->setSpacing(6);
84 SMESHGUI_BuildCompoundDlgLayout->setMargin(11);
86 /***************************************************************/
87 GroupConstructors = new QButtonGroup (this, "GroupConstructors");
88 GroupConstructors->setTitle(tr("COMPOUND" ));
89 GroupConstructors->setExclusive(TRUE);
90 GroupConstructors->setColumnLayout(0, Qt::Vertical);
91 GroupConstructors->layout()->setSpacing(0);
92 GroupConstructors->layout()->setMargin(0);
93 GroupConstructorsLayout = new QGridLayout (GroupConstructors->layout());
94 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
95 GroupConstructorsLayout->setSpacing(6);
96 GroupConstructorsLayout->setMargin(11);
97 Constructor1 = new QRadioButton (GroupConstructors, "Constructor1");
98 Constructor1->setText(tr(""));
99 Constructor1->setPixmap(image0);
100 Constructor1->setChecked(TRUE);
101 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
102 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupConstructors, 0, 0);
104 /***************************************************************/
105 GroupName = new QGroupBox (this, "GroupName");
106 GroupName->setTitle(tr("RESULT_NAME" ));
107 GroupName->setColumnLayout(0, Qt::Vertical);
108 GroupName->layout()->setSpacing(0);
109 GroupName->layout()->setMargin(0);
110 GroupNameLayout = new QGridLayout (GroupName->layout());
111 GroupNameLayout->setAlignment(Qt::AlignTop);
112 GroupNameLayout->setSpacing(6);
113 GroupNameLayout->setMargin(11);
114 TextLabelName = new QLabel (GroupName, "TextLabelName");
115 TextLabelName->setText(tr("SMESH_NAME"));
116 GroupNameLayout->addWidget(TextLabelName, 0, 0);
117 LineEditName = new QLineEdit (GroupName, "LineEditName");
118 GroupNameLayout->addWidget(LineEditName, 0, 1);
119 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupName, 1, 0);
121 /***************************************************************/
122 GroupArgs = new QGroupBox (this, "GroupArgs");
123 GroupArgs->setTitle(tr("SMESH_ARGUMENTS" ));
124 GroupArgs->setColumnLayout(0, Qt::Vertical);
125 GroupArgs->layout()->setSpacing(0);
126 GroupArgs->layout()->setMargin(0);
127 GroupArgsLayout = new QGridLayout (GroupArgs->layout());
128 GroupArgsLayout->setAlignment(Qt::AlignTop);
129 GroupArgsLayout->setSpacing(6);
130 GroupArgsLayout->setMargin(11);
132 TextLabelMeshes = new QLabel (GroupArgs, "TextLabelMeshes");
133 TextLabelMeshes->setText(tr("MESHES"));
134 TextLabelMeshes->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
135 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
136 SelectButton = new QPushButton (GroupArgs, "SelectButton");
137 SelectButton->setText(tr(""));
138 SelectButton->setPixmap(image1);
139 SelectButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
140 GroupArgsLayout->addWidget(SelectButton, 0, 1);
141 LineEditMeshes = new QLineEdit (GroupArgs, "LineEditMeshes");
142 LineEditMeshes->setReadOnly(true);
143 GroupArgsLayout->addMultiCellWidget(LineEditMeshes, 0, 0, 2, 3);
145 TextLabelUnion = new QLabel (GroupArgs, "TextLabelUnion");
146 TextLabelUnion->setText(tr("PROCESSING_IDENTICAL_GROUPS"));
147 TextLabelUnion->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
148 GroupArgsLayout->addMultiCellWidget(TextLabelUnion, 1, 1, 0, 2);
149 ComboBoxUnion = new QComboBox(GroupArgs, "ComboBoxUnion");
150 GroupArgsLayout->addMultiCellWidget(ComboBoxUnion, 1, 1, 3, 3);
152 CheckBoxCommon = new QCheckBox(GroupArgs, "CheckBoxCommon");
153 CheckBoxCommon->setText(tr("CREATE_COMMON_GROUPS" ));
154 GroupArgsLayout->addMultiCellWidget(CheckBoxCommon, 2, 2, 0, 3);
156 CheckBoxMerge = new QCheckBox(GroupArgs, "CheckBoxMerge");
157 CheckBoxMerge->setText(tr("MERGE_NODES_AND_ELEMENTS" ));
158 GroupArgsLayout->addMultiCellWidget(CheckBoxMerge, 3, 3, 0, 3);
160 TextLabelTol = new QLabel (GroupArgs, "TextLabelTol");
161 TextLabelTol->setText(tr("SMESH_TOLERANCE"));
162 TextLabelTol->setAlignment(Qt::AlignCenter);
163 GroupArgsLayout->addMultiCellWidget(TextLabelTol, 4, 4, 0, 1);
164 SpinBoxTol = new SMESHGUI_SpinBox (GroupArgs, "SpinBoxTol");
165 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
166 GroupArgsLayout->addMultiCellWidget(SpinBoxTol, 4, 4, 2, 3);
168 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupArgs, 2, 0);
170 /***************************************************************/
171 GroupButtons = new QGroupBox (this, "GroupButtons");
172 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
173 GroupButtons->setTitle(tr("" ));
174 GroupButtons->setColumnLayout(0, Qt::Vertical);
175 GroupButtons->layout()->setSpacing(0);
176 GroupButtons->layout()->setMargin(0);
177 GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
178 GroupButtonsLayout->setAlignment(Qt::AlignTop);
179 GroupButtonsLayout->setSpacing(6);
180 GroupButtonsLayout->setMargin(11);
181 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
182 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
183 buttonHelp->setAutoDefault(TRUE);
184 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
185 buttonCancel = new QPushButton (GroupButtons, "buttonCancel");
186 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
187 buttonCancel->setAutoDefault(TRUE);
188 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
189 buttonApply = new QPushButton (GroupButtons, "buttonApply");
190 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
191 buttonApply->setAutoDefault(TRUE);
192 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
193 QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
194 GroupButtonsLayout->addItem(spacer_9, 0, 2);
195 buttonOk = new QPushButton (GroupButtons, "buttonOk");
196 buttonOk->setText(tr("SMESH_BUT_APPLY_AND_CLOSE" ));
197 buttonOk->setAutoDefault(TRUE);
198 buttonOk->setDefault(TRUE);
199 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
200 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupButtons, 3, 0);
202 myHelpFileName = "building_compounds_page.html";
204 Init(); // Initialisations
207 //=================================================================================
208 // function : ~SMESHGUI_BuildCompoundDlg()
209 // purpose : Destroys the object and frees any allocated resources
210 //=================================================================================
211 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
213 // no need to delete child widgets, Qt does it all for us
216 //=================================================================================
219 //=================================================================================
220 void SMESHGUI_BuildCompoundDlg::Init()
224 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
226 myMesh = SMESH::SMESH_Mesh::_nil();
228 myMeshFilter = new SMESH_TypeFilter (MESH);
230 myMeshArray = new SMESH::mesh_array();
232 // signals and slots connections
233 connect(buttonOk , SIGNAL(clicked()), this, SLOT(ClickOnOk()));
234 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
235 connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
236 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
238 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
240 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
242 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
244 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
245 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()) , this, SLOT(ClickOnCancel()));
247 this->show(); // displays Dialog
249 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
250 LineEditMeshes->setFocus();
252 ComboBoxUnion->insertItem(tr("UNITE"));
253 ComboBoxUnion->insertItem(tr("RENAME"));
254 ComboBoxUnion->setCurrentItem(0);
256 CheckBoxMerge->setChecked(false);
258 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
259 SpinBoxTol->SetValue(1e-05);
261 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
263 mySelectionMgr->clearFilters();
264 mySelectionMgr->installFilter(myMeshFilter);
266 SelectionIntoArgument();
269 //=================================================================================
270 // function : GetDefaultName()
272 //=================================================================================
273 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
277 // collect all object names of SMESH component
278 SalomeApp_Study* appStudy =
279 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
280 if ( !appStudy ) return aName;
281 _PTR(Study) aStudy = appStudy->studyDS();
283 std::set<std::string> aSet;
284 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
286 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
288 for (it->InitEx(true); it->More(); it->Next()) {
290 aSet.insert(obj->GetName());
294 // build a unique name
296 bool isUnique = false;
298 aName = theOperation + "_" + QString::number(++aNumber);
299 isUnique = (aSet.count(aName.latin1()) == 0);
305 //=================================================================================
306 // function : ClickOnApply()
308 //=================================================================================
309 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
311 if (mySMESHGUI->isActiveStudyLocked())
313 if (!myMesh->_is_nil()) {
315 QApplication::setOverrideCursor(Qt::waitCursor);
317 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
318 // concatenate meshes
319 SMESH::SMESH_Mesh_var aCompoundMesh;
320 if(CheckBoxCommon->isChecked())
321 aCompoundMesh = aSMESHGen->ConcatenateWithGroups(myMeshArray,
322 !(ComboBoxUnion->currentItem()),
323 CheckBoxMerge->isChecked(),
324 SpinBoxTol->GetValue());
326 aCompoundMesh = aSMESHGen->Concatenate(myMeshArray,
327 !(ComboBoxUnion->currentItem()),
328 CheckBoxMerge->isChecked(),
329 SpinBoxTol->GetValue());
331 SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text().latin1() );
332 QApplication::restoreOverrideCursor();
333 mySMESHGUI->updateObjBrowser();
338 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
340 //mySelectionMgr->clearSelected();
347 //=================================================================================
348 // function : ClickOnOk()
350 //=================================================================================
351 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
357 //=================================================================================
358 // function : ClickOnCancel()
360 //=================================================================================
361 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
363 //mySelectionMgr->clearSelected();
364 mySelectionMgr->clearFilters();
365 disconnect(mySelectionMgr, 0, this, 0);
366 mySMESHGUI->ResetState();
370 //=================================================================================
371 // function : ClickOnHelp()
373 //=================================================================================
374 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
376 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
378 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
380 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
381 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
382 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
383 QObject::tr("BUT_OK"));
387 //=================================================================================
388 // function : SelectionIntoArgument()
389 // purpose : Called when selection as changed or other case
390 //=================================================================================
391 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
393 if (!GroupButtons->isEnabled()) // inactive
396 QString aString = "";
399 mySelectionMgr->selectedObjects(aList);
400 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
403 myMeshArray->length(nbSel);
404 for (int i = 0; nbSel != 0; i++, nbSel--) {
405 Handle(SALOME_InteractiveObject) IO = aList.First();
407 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
408 myMeshArray[i] = myMesh;
412 myMesh = SMESH::SMESH_Mesh::_nil();
416 LineEditMeshes->setText(aString);
418 bool isEnabled = (!myMesh->_is_nil());
419 buttonOk->setEnabled(isEnabled);
420 buttonApply->setEnabled(isEnabled);
423 //=================================================================================
424 // function : DeactivateActiveDialog()
426 //=================================================================================
427 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
429 if (GroupConstructors->isEnabled()) {
430 GroupConstructors->setEnabled(false);
431 GroupName->setEnabled(false);
432 GroupArgs->setEnabled(false);
433 GroupButtons->setEnabled(false);
434 mySMESHGUI->ResetState();
435 mySMESHGUI->SetActiveDialogBox(0);
439 //=================================================================================
440 // function : ActivateThisDialog()
442 //=================================================================================
443 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
445 /* Emit a signal to deactivate the active dialog */
446 mySMESHGUI->EmitSignalDeactivateDialog();
447 GroupConstructors->setEnabled(true);
448 GroupName->setEnabled(true);
449 GroupArgs->setEnabled(true);
450 GroupButtons->setEnabled(true);
452 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
453 SelectionIntoArgument();
456 //=================================================================================
457 // function : enterEvent()
459 //=================================================================================
460 void SMESHGUI_BuildCompoundDlg::enterEvent(QEvent* e)
462 if (GroupConstructors->isEnabled())
464 ActivateThisDialog();
467 //=================================================================================
468 // function : closeEvent()
470 //=================================================================================
471 void SMESHGUI_BuildCompoundDlg::closeEvent(QCloseEvent* e)
473 /* same than click on cancel button */
474 this->ClickOnCancel();
477 //=======================================================================
478 //function : hideEvent
479 //purpose : caused by ESC key
480 //=======================================================================
481 void SMESHGUI_BuildCompoundDlg::hideEvent (QHideEvent * e)
488 //=================================================================================
489 // function : keyPressEvent()
491 //=================================================================================
492 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
494 QDialog::keyPressEvent( e );
495 if ( e->isAccepted() )
498 if ( e->key() == Key_F1 )
506 //=================================================================================
507 // function : onSelectMerge()
509 //=================================================================================
510 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
512 TextLabelTol->setEnabled(toMerge);
513 SpinBoxTol->setEnabled(toMerge);