1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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.
26 #include "SMESHGUI_BuildCompoundDlg.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_VTKUtils.h"
33 #include <SMESH_TypeFilter.hxx>
35 // SALOME GUI includes
36 #include <SUIT_Desktop.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SalomeApp_Study.h>
41 #include <SUIT_OverrideCursor.h>
43 #include <LightApp_Application.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <SALOME_ListIO.hxx>
48 #include <QApplication>
52 #include <QPushButton>
53 #include <QRadioButton>
54 #include <QHBoxLayout>
55 #include <QVBoxLayout>
56 #include <QGridLayout>
60 #include <QButtonGroup>
68 //=================================================================================
69 // name : SMESHGUI_BuildCompoundDlg
71 //=================================================================================
72 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule )
73 : QDialog(SMESH::GetDesktop(theModule)),
74 mySMESHGUI(theModule),
75 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
76 myIsApplyAndClose( false )
79 setAttribute(Qt::WA_DeleteOnClose, true);
80 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
82 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
83 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
84 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
86 setSizeGripEnabled(true);
88 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
89 aTopLayout->setSpacing(SPACING);
90 aTopLayout->setMargin(MARGIN);
92 /***************************************************************/
93 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
94 QButtonGroup* ButtonGroup = new QButtonGroup(this);
95 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
96 GroupConstructorsLayout->setSpacing(SPACING);
97 GroupConstructorsLayout->setMargin(MARGIN);
99 Constructor1 = new QRadioButton(GroupConstructors);
100 Constructor1->setIcon(image0);
101 Constructor1->setChecked(true);
102 GroupConstructorsLayout->addWidget(Constructor1);
103 ButtonGroup->addButton(Constructor1, 0);
105 /***************************************************************/
106 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
107 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
108 GroupNameLayout->setSpacing(SPACING);
109 GroupNameLayout->setMargin(MARGIN);
111 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
112 LineEditName = new QLineEdit(GroupName);
114 GroupNameLayout->addWidget(TextLabelName);
115 GroupNameLayout->addWidget(LineEditName);
117 /***************************************************************/
118 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
119 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
120 GroupArgsLayout->setSpacing(SPACING);
121 GroupArgsLayout->setMargin(MARGIN);
123 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
124 SelectButton = new QPushButton(GroupArgs);
125 SelectButton->setIcon(image1);
126 SelectButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
127 LineEditMeshes = new QLineEdit(GroupArgs);
128 LineEditMeshes->setReadOnly(true);
130 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
131 ComboBoxUnion = new QComboBox(GroupArgs);
133 CheckBoxCommon = new QCheckBox(tr("CREATE_COMMON_GROUPS"), GroupArgs);
135 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
137 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
138 TextLabelTol->setAlignment(Qt::AlignCenter);
139 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
140 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision" );
142 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
143 GroupArgsLayout->addWidget(SelectButton, 0, 1);
144 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
145 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
146 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
147 GroupArgsLayout->addWidget(CheckBoxCommon, 2, 0, 1, 4);
148 GroupArgsLayout->addWidget(CheckBoxMerge, 3, 0, 1, 4);
149 GroupArgsLayout->addWidget(TextLabelTol, 4, 0, 1, 2);
150 GroupArgsLayout->addWidget(SpinBoxTol, 4, 2, 1, 2);
152 /***************************************************************/
153 GroupButtons = new QGroupBox(this);
154 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
155 GroupButtonsLayout->setSpacing(SPACING);
156 GroupButtonsLayout->setMargin(MARGIN);
158 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
159 buttonOk->setAutoDefault(true);
160 buttonOk->setDefault(true);
161 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
162 buttonApply->setAutoDefault(true);
163 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
164 buttonCancel->setAutoDefault(true);
165 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
166 buttonHelp->setAutoDefault(true);
168 GroupButtonsLayout->addWidget(buttonOk);
169 GroupButtonsLayout->addSpacing(10);
170 GroupButtonsLayout->addWidget(buttonApply);
171 GroupButtonsLayout->addSpacing(10);
172 GroupButtonsLayout->addStretch();
173 GroupButtonsLayout->addWidget(buttonCancel);
174 GroupButtonsLayout->addWidget(buttonHelp);
176 /***************************************************************/
177 aTopLayout->addWidget(GroupConstructors);
178 aTopLayout->addWidget(GroupName);
179 aTopLayout->addWidget(GroupArgs);
180 aTopLayout->addWidget(GroupButtons);
182 myHelpFileName = "building_compounds_page.html";
184 Init(); // Initialisations
187 //=================================================================================
188 // function : ~SMESHGUI_BuildCompoundDlg()
189 // purpose : Destroys the object and frees any allocated resources
190 //=================================================================================
191 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
195 //=================================================================================
198 //=================================================================================
199 void SMESHGUI_BuildCompoundDlg::Init()
201 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
203 myMesh = SMESH::SMESH_IDSource::_nil();
205 myMeshFilter = new SMESH_TypeFilter (SMESH::IDSOURCE);
207 myMeshArray = new SMESH::ListOfIDSources();
209 // signals and slots connections
210 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
211 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
212 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
213 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
215 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
217 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
219 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
221 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
222 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
224 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
225 LineEditMeshes->setFocus();
227 ComboBoxUnion->addItem(tr("UNITE"));
228 ComboBoxUnion->addItem(tr("RENAME"));
229 ComboBoxUnion->setCurrentIndex(0);
231 CheckBoxMerge->setChecked(true);
233 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
234 SpinBoxTol->SetValue(1e-05);
236 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
238 mySelectionMgr->clearFilters();
239 mySelectionMgr->installFilter(myMeshFilter);
241 SelectionIntoArgument();
244 //=================================================================================
245 // function : GetDefaultName()
247 //=================================================================================
248 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
252 // collect all object names of SMESH component
253 SalomeApp_Study* appStudy =
254 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
255 if ( !appStudy ) return aName;
256 _PTR(Study) aStudy = appStudy->studyDS();
258 std::set<std::string> aSet;
259 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
261 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
263 for (it->InitEx(true); it->More(); it->Next()) {
265 aSet.insert(obj->GetName());
269 // build a unique name
271 bool isUnique = false;
273 aName = theOperation + "_" + QString::number(++aNumber);
274 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
280 //=================================================================================
281 // function : ClickOnApply()
283 //=================================================================================
284 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
286 if (mySMESHGUI->isActiveStudyLocked())
292 SMESH::SMESH_Mesh_var aMesh;
294 if (!myMesh->_is_nil())
296 QStringList aParameters;
297 aParameters << (CheckBoxMerge->isChecked() ? SpinBoxTol->text() : QString(" "));
299 QStringList anEntryList;
301 SUIT_OverrideCursor aWaitCursor;
303 aMesh = myMeshArray[0]->GetMesh();
304 aMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
306 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
307 // concatenate meshes
308 if(CheckBoxCommon->isChecked())
309 aMesh = aSMESHGen->ConcatenateWithGroups(myMeshArray,
310 !(ComboBoxUnion->currentIndex()),
311 CheckBoxMerge->isChecked(),
312 SpinBoxTol->GetValue());
314 aMesh = aSMESHGen->Concatenate(myMeshArray,
315 !(ComboBoxUnion->currentIndex()),
316 CheckBoxMerge->isChecked(),
317 SpinBoxTol->GetValue());
319 _PTR(SObject) aSO = SMESH::FindSObject( aMesh );
321 SMESH::SetName( aSO, LineEditName->text() );
322 anEntryList.append( aSO->GetID().c_str() );
324 mySMESHGUI->updateObjBrowser();
329 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
331 // IPAL21468 Compound is hidden after creation.
332 if ( SMESHGUI::automaticUpdate() ) {
333 mySelectionMgr->clearSelected();
336 _PTR(SObject) aSO = SMESH::FindSObject(aMesh.in());
337 if ( SMESH_Actor* anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str()) ) {
338 SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
343 if( LightApp_Application* anApp =
344 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
345 anApp->browseObjects( anEntryList, isApplyAndClose() );
347 SMESHGUI::Modified();
354 //=================================================================================
355 // function : ClickOnOk()
357 //=================================================================================
358 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
360 setIsApplyAndClose( true );
365 //=================================================================================
366 // function : reject()
368 //=================================================================================
369 void SMESHGUI_BuildCompoundDlg::reject()
371 //mySelectionMgr->clearSelected();
372 mySelectionMgr->clearFilters();
373 disconnect(mySelectionMgr, 0, this, 0);
374 mySMESHGUI->ResetState();
378 //=================================================================================
379 // function : ClickOnHelp()
381 //=================================================================================
382 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
384 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
386 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
388 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
389 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
390 arg(app->resourceMgr()->stringValue("ExternalBrowser",
392 arg(myHelpFileName));
396 //=================================================================================
397 // function : SelectionIntoArgument()
398 // purpose : Called when selection as changed or other case
399 //=================================================================================
400 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
402 if (!GroupButtons->isEnabled()) // inactive
405 QString aString = "";
408 mySelectionMgr->selectedObjects(aList);
409 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
412 myMeshArray->length(nbSel);
413 for (int i = 0; nbSel != 0; i++, nbSel--) {
414 Handle(SALOME_InteractiveObject) IO = aList.First();
416 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
417 myMeshArray[i] = myMesh;
421 myMesh = SMESH::SMESH_IDSource::_nil();
425 LineEditMeshes->setText(aString);
427 bool isEnabled = (!myMesh->_is_nil());
428 buttonOk->setEnabled(isEnabled);
429 buttonApply->setEnabled(isEnabled);
432 //=================================================================================
433 // function : DeactivateActiveDialog()
435 //=================================================================================
436 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
438 if (GroupConstructors->isEnabled()) {
439 GroupConstructors->setEnabled(false);
440 GroupName->setEnabled(false);
441 GroupArgs->setEnabled(false);
442 GroupButtons->setEnabled(false);
443 mySMESHGUI->ResetState();
444 mySMESHGUI->SetActiveDialogBox(0);
448 //=================================================================================
449 // function : ActivateThisDialog()
451 //=================================================================================
452 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
454 /* Emit a signal to deactivate the active dialog */
455 mySMESHGUI->EmitSignalDeactivateDialog();
456 GroupConstructors->setEnabled(true);
457 GroupName->setEnabled(true);
458 GroupArgs->setEnabled(true);
459 GroupButtons->setEnabled(true);
461 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
462 SelectionIntoArgument();
465 //=================================================================================
466 // function : enterEvent()
468 //=================================================================================
469 void SMESHGUI_BuildCompoundDlg::enterEvent( QEvent* )
471 if (GroupConstructors->isEnabled())
473 ActivateThisDialog();
476 //=================================================================================
477 // function : keyPressEvent()
479 //=================================================================================
480 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
482 QDialog::keyPressEvent( e );
483 if ( e->isAccepted() )
486 if ( e->key() == Qt::Key_F1 ) {
493 //=================================================================================
494 // function : onSelectMerge()
496 //=================================================================================
497 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
499 TextLabelTol->setEnabled(toMerge);
500 SpinBoxTol->setEnabled(toMerge);
502 SpinBoxTol->SetValue(1e-05);
505 //=================================================================================
506 // function : isValid
508 //=================================================================================
509 bool SMESHGUI_BuildCompoundDlg::isValid()
513 if(CheckBoxMerge->isChecked())
514 ok = SpinBoxTol->isValid( msg, true );
517 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
518 if ( !msg.isEmpty() )
520 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
526 //================================================================
527 // function : setIsApplyAndClose
528 // Purpose : Set value of the flag indicating that the dialog is
529 // accepted by Apply & Close button
530 //================================================================
531 void SMESHGUI_BuildCompoundDlg::setIsApplyAndClose( const bool theFlag )
533 myIsApplyAndClose = theFlag;
536 //================================================================
537 // function : isApplyAndClose
538 // Purpose : Get value of the flag indicating that the dialog is
539 // accepted by Apply & Close button
540 //================================================================
541 bool SMESHGUI_BuildCompoundDlg::isApplyAndClose() const
543 return myIsApplyAndClose;