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
24 // File : SMESHGUI_BuildCompoundDlg.cxx
25 // Author : Alexander KOVALEV
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 #include "SUIT_Desktop.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_MessageBox.h"
40 #include "SalomeApp_Study.h"
42 #include "LightApp_Application.h"
44 #include "SALOME_ListIO.hxx"
46 #include "utilities.h"
49 #include <qapplication.h>
50 #include <qbuttongroup.h>
51 #include <qgroupbox.h>
53 #include <qlineedit.h>
54 #include <qpushbutton.h>
55 #include <qradiobutton.h>
58 #include <qcheckbox.h>
59 #include <qcombobox.h>
60 #include <qsizepolicy.h>
66 //=================================================================================
67 // name : SMESHGUI_BuildCompoundDlg
69 //=================================================================================
70 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule,
74 : QDialog(SMESH::GetDesktop(theModule), "SMESHGUI_BuildCompoundDlg", false, WStyle_Customize |
75 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
76 mySMESHGUI(theModule),
77 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
80 setCaption(tr(title));
82 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
83 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr(icon)));
84 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
86 setSizeGripEnabled(TRUE);
87 SMESHGUI_BuildCompoundDlgLayout = new QGridLayout (this);
88 SMESHGUI_BuildCompoundDlgLayout->setSpacing(6);
89 SMESHGUI_BuildCompoundDlgLayout->setMargin(11);
91 /***************************************************************/
92 GroupConstructors = new QButtonGroup (this, "GroupConstructors");
93 GroupConstructors->setTitle(tr("COMPOUND" ));
94 GroupConstructors->setExclusive(TRUE);
95 GroupConstructors->setColumnLayout(0, Qt::Vertical);
96 GroupConstructors->layout()->setSpacing(0);
97 GroupConstructors->layout()->setMargin(0);
98 GroupConstructorsLayout = new QGridLayout (GroupConstructors->layout());
99 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
100 GroupConstructorsLayout->setSpacing(6);
101 GroupConstructorsLayout->setMargin(11);
102 Constructor1 = new QRadioButton (GroupConstructors, "Constructor1");
103 Constructor1->setText(tr(""));
104 Constructor1->setPixmap(image0);
105 Constructor1->setChecked(TRUE);
106 GroupConstructorsLayout->addWidget(Constructor1, 0, 0);
107 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupConstructors, 0, 0);
109 /***************************************************************/
110 GroupName = new QGroupBox (this, "GroupName");
111 GroupName->setTitle(tr("RESULT_NAME" ));
112 GroupName->setColumnLayout(0, Qt::Vertical);
113 GroupName->layout()->setSpacing(0);
114 GroupName->layout()->setMargin(0);
115 GroupNameLayout = new QGridLayout (GroupName->layout());
116 GroupNameLayout->setAlignment(Qt::AlignTop);
117 GroupNameLayout->setSpacing(6);
118 GroupNameLayout->setMargin(11);
119 TextLabelName = new QLabel (GroupName, "TextLabelName");
120 TextLabelName->setText(tr("SMESH_NAME"));
121 GroupNameLayout->addWidget(TextLabelName, 0, 0);
122 LineEditName = new QLineEdit (GroupName, "LineEditName");
123 GroupNameLayout->addWidget(LineEditName, 0, 1);
124 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupName, 1, 0);
126 /***************************************************************/
127 GroupArgs = new QGroupBox (this, "GroupArgs");
128 GroupArgs->setTitle(tr("SMESH_ARGUMENTS" ));
129 GroupArgs->setColumnLayout(0, Qt::Vertical);
130 GroupArgs->layout()->setSpacing(0);
131 GroupArgs->layout()->setMargin(0);
132 GroupArgsLayout = new QGridLayout (GroupArgs->layout());
133 GroupArgsLayout->setAlignment(Qt::AlignTop);
134 GroupArgsLayout->setSpacing(6);
135 GroupArgsLayout->setMargin(11);
137 TextLabelMeshes = new QLabel (GroupArgs, "TextLabelMeshes");
138 TextLabelMeshes->setText(tr("MESHES"));
139 TextLabelMeshes->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
140 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
141 SelectButton = new QPushButton (GroupArgs, "SelectButton");
142 SelectButton->setText(tr(""));
143 SelectButton->setPixmap(image1);
144 SelectButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
145 GroupArgsLayout->addWidget(SelectButton, 0, 1);
146 LineEditMeshes = new QLineEdit (GroupArgs, "LineEditMeshes");
147 LineEditMeshes->setReadOnly(true);
148 GroupArgsLayout->addMultiCellWidget(LineEditMeshes, 0, 0, 2, 3);
150 TextLabelUnion = new QLabel (GroupArgs, "TextLabelUnion");
151 TextLabelUnion->setText(tr("PROCESSING_IDENTICAL_GROUPS"));
152 TextLabelUnion->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
153 GroupArgsLayout->addMultiCellWidget(TextLabelUnion, 1, 1, 0, 2);
154 ComboBoxUnion = new QComboBox(GroupArgs, "ComboBoxUnion");
155 GroupArgsLayout->addMultiCellWidget(ComboBoxUnion, 1, 1, 3, 3);
157 CheckBoxMerge = new QCheckBox(GroupArgs, "CheckBoxMerge");
158 CheckBoxMerge->setText(tr("MERGE_NODES_AND_ELEMENTS" ));
159 GroupArgsLayout->addMultiCellWidget(CheckBoxMerge, 2, 2, 0, 3);
161 TextLabelTol = new QLabel (GroupArgs, "TextLabelTol");
162 TextLabelTol->setText(tr("SMESH_TOLERANCE"));
163 TextLabelTol->setAlignment(Qt::AlignCenter);
164 GroupArgsLayout->addMultiCellWidget(TextLabelTol, 3, 3, 0, 1);
165 SpinBoxTol = new SMESHGUI_SpinBox (GroupArgs, "SpinBoxTol");
166 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.1, 6);
167 GroupArgsLayout->addMultiCellWidget(SpinBoxTol, 3, 3, 2, 3);
169 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupArgs, 2, 0);
171 /***************************************************************/
172 GroupButtons = new QGroupBox (this, "GroupButtons");
173 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
174 GroupButtons->setTitle(tr("" ));
175 GroupButtons->setColumnLayout(0, Qt::Vertical);
176 GroupButtons->layout()->setSpacing(0);
177 GroupButtons->layout()->setMargin(0);
178 GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
179 GroupButtonsLayout->setAlignment(Qt::AlignTop);
180 GroupButtonsLayout->setSpacing(6);
181 GroupButtonsLayout->setMargin(11);
182 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
183 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
184 buttonHelp->setAutoDefault(TRUE);
185 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
186 buttonCancel = new QPushButton (GroupButtons, "buttonCancel");
187 buttonCancel->setText(tr("SMESH_BUT_CLOSE" ));
188 buttonCancel->setAutoDefault(TRUE);
189 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
190 buttonApply = new QPushButton (GroupButtons, "buttonApply");
191 buttonApply->setText(tr("SMESH_BUT_APPLY" ));
192 buttonApply->setAutoDefault(TRUE);
193 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
194 QSpacerItem* spacer_9 = new QSpacerItem (20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
195 GroupButtonsLayout->addItem(spacer_9, 0, 2);
196 buttonOk = new QPushButton (GroupButtons, "buttonOk");
197 buttonOk->setText(tr("SMESH_BUT_OK" ));
198 buttonOk->setAutoDefault(TRUE);
199 buttonOk->setDefault(TRUE);
200 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
201 SMESHGUI_BuildCompoundDlgLayout->addWidget(GroupButtons, 3, 0);
203 myHelpFileName = "build_compound.htm";
205 Init(); // Initialisations
208 //=================================================================================
209 // function : ~SMESHGUI_BuildCompoundDlg()
210 // purpose : Destroys the object and frees any allocated resources
211 //=================================================================================
212 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
214 // no need to delete child widgets, Qt does it all for us
217 //=================================================================================
220 //=================================================================================
221 void SMESHGUI_BuildCompoundDlg::Init()
225 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
227 myMesh = SMESH::SMESH_Mesh::_nil();
229 myMeshFilter = new SMESH_TypeFilter (MESH);
231 myMeshArray = new SMESH::mesh_array();
233 // signals and slots connections
234 connect(buttonOk , SIGNAL(clicked()), this, SLOT(ClickOnOk()));
235 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
236 connect(buttonApply , SIGNAL(clicked()), this, SLOT(ClickOnApply()));
237 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
239 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
241 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
243 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
245 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
246 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()) , this, SLOT(ClickOnCancel()));
248 this->show(); // displays Dialog
250 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
251 LineEditMeshes->setFocus();
253 ComboBoxUnion->insertItem(tr("UNITE"));
254 ComboBoxUnion->insertItem(tr("RENAME"));
255 ComboBoxUnion->setCurrentItem(0);
257 CheckBoxMerge->setChecked(false);
259 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
260 SpinBoxTol->SetValue(1e-05);
262 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
264 mySelectionMgr->clearFilters();
265 mySelectionMgr->installFilter(myMeshFilter);
267 SelectionIntoArgument();
270 //=================================================================================
271 // function : GetDefaultName()
273 //=================================================================================
274 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
278 // collect all object names of SMESH component
279 SalomeApp_Study* appStudy =
280 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
281 if ( !appStudy ) return aName;
282 _PTR(Study) aStudy = appStudy->studyDS();
284 std::set<std::string> aSet;
285 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
287 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
289 for (it->InitEx(true); it->More(); it->Next()) {
291 aSet.insert(obj->GetName());
295 // build a unique name
297 bool isUnique = false;
299 aName = theOperation + "_" + QString::number(++aNumber);
300 isUnique = (aSet.count(aName.latin1()) == 0);
306 //=================================================================================
307 // function : ClickOnApply()
309 //=================================================================================
310 void SMESHGUI_BuildCompoundDlg::ClickOnApply()
312 if (!myMesh->_is_nil()) {
314 QApplication::setOverrideCursor(Qt::waitCursor);
316 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
317 // concatenate meshes
318 SMESH::SMESH_Mesh_var aCompoundMesh =
319 aSMESHGen->Concatenate(myMeshArray,
320 !(ComboBoxUnion->currentItem()),
321 CheckBoxMerge->isChecked(),
322 SpinBoxTol->GetValue());
324 SMESH::SetName( SMESH::FindSObject( aCompoundMesh ), LineEditName->text().latin1() );
325 QApplication::restoreOverrideCursor();
326 mySMESHGUI->updateObjBrowser();
330 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
332 //mySelectionMgr->clearSelected();
337 //=================================================================================
338 // function : ClickOnOk()
340 //=================================================================================
341 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
347 //=================================================================================
348 // function : ClickOnCancel()
350 //=================================================================================
351 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
353 //mySelectionMgr->clearSelected();
354 mySelectionMgr->clearFilters();
355 disconnect(mySelectionMgr, 0, this, 0);
356 mySMESHGUI->ResetState();
360 //=================================================================================
361 // function : ClickOnHelp()
363 //=================================================================================
364 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
366 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
368 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
370 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
371 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
372 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
373 QObject::tr("BUT_OK"));
377 //=================================================================================
378 // function : SelectionIntoArgument()
379 // purpose : Called when selection as changed or other case
380 //=================================================================================
381 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
383 if (!GroupButtons->isEnabled()) // inactive
386 QString aString = "";
389 mySelectionMgr->selectedObjects(aList);
390 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
393 myMeshArray->length(nbSel);
394 for (int i = 0; nbSel != 0; i++, nbSel--) {
395 Handle(SALOME_InteractiveObject) IO = aList.First();
397 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
398 myMeshArray[i] = myMesh;
402 myMesh = SMESH::SMESH_Mesh::_nil();
406 LineEditMeshes->setText(aString);
408 bool isEnabled = (!myMesh->_is_nil());
409 buttonOk->setEnabled(isEnabled);
410 buttonApply->setEnabled(isEnabled);
413 //=================================================================================
414 // function : DeactivateActiveDialog()
416 //=================================================================================
417 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
419 if (GroupConstructors->isEnabled()) {
420 GroupConstructors->setEnabled(false);
421 GroupName->setEnabled(false);
422 GroupArgs->setEnabled(false);
423 GroupButtons->setEnabled(false);
424 mySMESHGUI->ResetState();
425 mySMESHGUI->SetActiveDialogBox(0);
429 //=================================================================================
430 // function : ActivateThisDialog()
432 //=================================================================================
433 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
435 /* Emit a signal to deactivate the active dialog */
436 mySMESHGUI->EmitSignalDeactivateDialog();
437 GroupConstructors->setEnabled(true);
438 GroupName->setEnabled(true);
439 GroupArgs->setEnabled(true);
440 GroupButtons->setEnabled(true);
442 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
443 SelectionIntoArgument();
446 //=================================================================================
447 // function : enterEvent()
449 //=================================================================================
450 void SMESHGUI_BuildCompoundDlg::enterEvent(QEvent* e)
452 if (GroupConstructors->isEnabled())
454 ActivateThisDialog();
457 //=================================================================================
458 // function : closeEvent()
460 //=================================================================================
461 void SMESHGUI_BuildCompoundDlg::closeEvent(QCloseEvent* e)
463 /* same than click on cancel button */
464 this->ClickOnCancel();
467 //=======================================================================
468 //function : hideEvent
469 //purpose : caused by ESC key
470 //=======================================================================
471 void SMESHGUI_BuildCompoundDlg::hideEvent (QHideEvent * e)
478 //=================================================================================
479 // function : keyPressEvent()
481 //=================================================================================
482 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
484 QDialog::keyPressEvent( e );
485 if ( e->isAccepted() )
488 if ( e->key() == Key_F1 )
496 //=================================================================================
497 // function : onSelectMerge()
499 //=================================================================================
500 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
502 TextLabelTol->setEnabled(toMerge);
503 SpinBoxTol->setEnabled(toMerge);