00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "SMESHGUI_BuildCompoundDlg.h"
00027
00028 #include "SMESHGUI.h"
00029 #include "SMESHGUI_Utils.h"
00030 #include "SMESHGUI_SpinBox.h"
00031 #include "SMESHGUI_VTKUtils.h"
00032
00033 #include <SMESH_TypeFilter.hxx>
00034
00035
00036 #include <SUIT_Desktop.h>
00037 #include <SUIT_Session.h>
00038 #include <SUIT_MessageBox.h>
00039 #include <SUIT_ResourceMgr.h>
00040 #include <SalomeApp_Study.h>
00041 #include <SUIT_OverrideCursor.h>
00042
00043 #include <LightApp_Application.h>
00044 #include <LightApp_SelectionMgr.h>
00045 #include <SALOME_ListIO.hxx>
00046
00047
00048 #include <QApplication>
00049 #include <QGroupBox>
00050 #include <QLabel>
00051 #include <QLineEdit>
00052 #include <QPushButton>
00053 #include <QRadioButton>
00054 #include <QHBoxLayout>
00055 #include <QVBoxLayout>
00056 #include <QGridLayout>
00057 #include <QCheckBox>
00058 #include <QComboBox>
00059 #include <QKeyEvent>
00060 #include <QButtonGroup>
00061
00062
00063 #include <set>
00064
00065 #define SPACING 6
00066 #define MARGIN 11
00067
00068
00069
00070 #define WITHGENERICOBJ
00071
00072
00073
00074
00075
00076 SMESHGUI_BuildCompoundDlg::SMESHGUI_BuildCompoundDlg( SMESHGUI* theModule )
00077 : QDialog(SMESH::GetDesktop(theModule)),
00078 mySMESHGUI(theModule),
00079 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
00080 myIsApplyAndClose( false )
00081 {
00082 setModal(false);
00083 setAttribute(Qt::WA_DeleteOnClose, true);
00084 setWindowTitle(tr("SMESH_BUILD_COMPOUND_TITLE"));
00085
00086 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00087 QPixmap image0 (aResMgr->loadPixmap("SMESH", tr("ICON_DLG_BUILD_COMPOUND_MESH")));
00088 QPixmap image1 (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
00089
00090 setSizeGripEnabled(true);
00091
00092 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
00093 aTopLayout->setSpacing(SPACING);
00094 aTopLayout->setMargin(MARGIN);
00095
00096
00097 GroupConstructors = new QGroupBox(tr("COMPOUND"), this);
00098 QButtonGroup* ButtonGroup = new QButtonGroup(this);
00099 QHBoxLayout* GroupConstructorsLayout = new QHBoxLayout(GroupConstructors);
00100 GroupConstructorsLayout->setSpacing(SPACING);
00101 GroupConstructorsLayout->setMargin(MARGIN);
00102
00103 Constructor1 = new QRadioButton(GroupConstructors);
00104 Constructor1->setIcon(image0);
00105 Constructor1->setChecked(true);
00106 GroupConstructorsLayout->addWidget(Constructor1);
00107 ButtonGroup->addButton(Constructor1, 0);
00108
00109
00110 GroupName = new QGroupBox(tr("RESULT_NAME"), this);
00111 QHBoxLayout* GroupNameLayout = new QHBoxLayout(GroupName);
00112 GroupNameLayout->setSpacing(SPACING);
00113 GroupNameLayout->setMargin(MARGIN);
00114
00115 TextLabelName = new QLabel(tr("SMESH_NAME"), GroupName);
00116 LineEditName = new QLineEdit(GroupName);
00117
00118 GroupNameLayout->addWidget(TextLabelName);
00119 GroupNameLayout->addWidget(LineEditName);
00120
00121
00122 GroupArgs = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
00123 QGridLayout* GroupArgsLayout = new QGridLayout(GroupArgs);
00124 GroupArgsLayout->setSpacing(SPACING);
00125 GroupArgsLayout->setMargin(MARGIN);
00126
00127 TextLabelMeshes = new QLabel(tr("MESHES"), GroupArgs);
00128 SelectButton = new QPushButton(GroupArgs);
00129 SelectButton->setIcon(image1);
00130 SelectButton->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
00131 LineEditMeshes = new QLineEdit(GroupArgs);
00132 LineEditMeshes->setReadOnly(true);
00133
00134 TextLabelUnion = new QLabel(tr("PROCESSING_IDENTICAL_GROUPS"), GroupArgs);
00135 ComboBoxUnion = new QComboBox(GroupArgs);
00136
00137 CheckBoxCommon = new QCheckBox(tr("CREATE_COMMON_GROUPS"), GroupArgs);
00138
00139 CheckBoxMerge = new QCheckBox(tr("MERGE_NODES_AND_ELEMENTS"), GroupArgs);
00140
00141 TextLabelTol = new QLabel(tr("SMESH_TOLERANCE"), GroupArgs);
00142 TextLabelTol->setAlignment(Qt::AlignCenter);
00143 SpinBoxTol = new SMESHGUI_SpinBox(GroupArgs);
00144 SpinBoxTol->RangeStepAndValidator(0.0, COORD_MAX, 0.00001, "len_tol_precision" );
00145
00146 GroupArgsLayout->addWidget(TextLabelMeshes, 0, 0);
00147 GroupArgsLayout->addWidget(SelectButton, 0, 1);
00148 GroupArgsLayout->addWidget(LineEditMeshes, 0, 2, 1, 2);
00149 GroupArgsLayout->addWidget(TextLabelUnion, 1, 0, 1, 3);
00150 GroupArgsLayout->addWidget(ComboBoxUnion, 1, 3);
00151 GroupArgsLayout->addWidget(CheckBoxCommon, 2, 0, 1, 4);
00152 GroupArgsLayout->addWidget(CheckBoxMerge, 3, 0, 1, 4);
00153 GroupArgsLayout->addWidget(TextLabelTol, 4, 0, 1, 2);
00154 GroupArgsLayout->addWidget(SpinBoxTol, 4, 2, 1, 2);
00155
00156
00157 GroupButtons = new QGroupBox(this);
00158 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00159 GroupButtonsLayout->setSpacing(SPACING);
00160 GroupButtonsLayout->setMargin(MARGIN);
00161
00162 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00163 buttonOk->setAutoDefault(true);
00164 buttonOk->setDefault(true);
00165 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00166 buttonApply->setAutoDefault(true);
00167 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00168 buttonCancel->setAutoDefault(true);
00169 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00170 buttonHelp->setAutoDefault(true);
00171
00172 GroupButtonsLayout->addWidget(buttonOk);
00173 GroupButtonsLayout->addSpacing(10);
00174 GroupButtonsLayout->addWidget(buttonApply);
00175 GroupButtonsLayout->addSpacing(10);
00176 GroupButtonsLayout->addStretch();
00177 GroupButtonsLayout->addWidget(buttonCancel);
00178 GroupButtonsLayout->addWidget(buttonHelp);
00179
00180
00181 aTopLayout->addWidget(GroupConstructors);
00182 aTopLayout->addWidget(GroupName);
00183 aTopLayout->addWidget(GroupArgs);
00184 aTopLayout->addWidget(GroupButtons);
00185
00186 myHelpFileName = "building_compounds_page.html";
00187
00188 Init();
00189 }
00190
00191
00192
00193
00194
00195 SMESHGUI_BuildCompoundDlg::~SMESHGUI_BuildCompoundDlg()
00196 {
00197 }
00198
00199
00200
00201
00202
00203 void SMESHGUI_BuildCompoundDlg::Init()
00204 {
00205 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00206
00207 myMesh = SMESH::SMESH_Mesh::_nil();
00208
00209 myMeshFilter = new SMESH_TypeFilter (MESH);
00210
00211 myMeshArray = new SMESH::mesh_array();
00212
00213
00214 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00215 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00216 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00217 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00218
00219 connect(SelectButton, SIGNAL(clicked()), this, SLOT(SelectionIntoArgument()));
00220
00221 connect(CheckBoxMerge, SIGNAL(toggled(bool)), this, SLOT(onSelectMerge(bool)));
00222
00223 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
00224
00225 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
00226 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
00227
00228 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
00229 LineEditMeshes->setFocus();
00230
00231 ComboBoxUnion->addItem(tr("UNITE"));
00232 ComboBoxUnion->addItem(tr("RENAME"));
00233 ComboBoxUnion->setCurrentIndex(0);
00234
00235 CheckBoxMerge->setChecked(false);
00236
00237 TextLabelTol->setEnabled(CheckBoxMerge->isChecked());
00238 SpinBoxTol->SetValue(1e-05);
00239
00240 SpinBoxTol->setEnabled(CheckBoxMerge->isChecked());
00241
00242 mySelectionMgr->clearFilters();
00243 mySelectionMgr->installFilter(myMeshFilter);
00244
00245 SelectionIntoArgument();
00246 }
00247
00248
00249
00250
00251
00252 QString SMESHGUI_BuildCompoundDlg::GetDefaultName(const QString& theOperation)
00253 {
00254 QString aName = "";
00255
00256
00257 SalomeApp_Study* appStudy =
00258 dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
00259 if ( !appStudy ) return aName;
00260 _PTR(Study) aStudy = appStudy->studyDS();
00261
00262 std::set<std::string> aSet;
00263 _PTR(SComponent) aMeshCompo (aStudy->FindComponent("SMESH"));
00264 if (aMeshCompo) {
00265 _PTR(ChildIterator) it (aStudy->NewChildIterator(aMeshCompo));
00266 _PTR(SObject) obj;
00267 for (it->InitEx(true); it->More(); it->Next()) {
00268 obj = it->Value();
00269 aSet.insert(obj->GetName());
00270 }
00271 }
00272
00273
00274 int aNumber = 0;
00275 bool isUnique = false;
00276 while (!isUnique) {
00277 aName = theOperation + "_" + QString::number(++aNumber);
00278 isUnique = (aSet.count(aName.toLatin1().data()) == 0);
00279 }
00280
00281 return aName;
00282 }
00283
00284
00285
00286
00287
00288 bool SMESHGUI_BuildCompoundDlg::ClickOnApply()
00289 {
00290 if (mySMESHGUI->isActiveStudyLocked())
00291 return false;
00292
00293 if (!isValid())
00294 return false;
00295
00296 SMESH::SMESH_Mesh_var aCompoundMesh;
00297
00298 if (!myMesh->_is_nil()) {
00299 QStringList aParameters;
00300 aParameters << (CheckBoxMerge->isChecked() ? SpinBoxTol->text() : QString(" "));
00301 QStringList anEntryList;
00302 try {
00303 SUIT_OverrideCursor aWaitCursor;
00304
00305 SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
00306
00307 if(CheckBoxCommon->isChecked())
00308 aCompoundMesh = aSMESHGen->ConcatenateWithGroups(myMeshArray,
00309 !(ComboBoxUnion->currentIndex()),
00310 CheckBoxMerge->isChecked(),
00311 SpinBoxTol->GetValue());
00312 else
00313 aCompoundMesh = aSMESHGen->Concatenate(myMeshArray,
00314 !(ComboBoxUnion->currentIndex()),
00315 CheckBoxMerge->isChecked(),
00316 SpinBoxTol->GetValue());
00317
00318 aCompoundMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
00319
00320 _PTR(SObject) aSO = SMESH::FindSObject( aCompoundMesh );
00321 if( aSO ) {
00322 SMESH::SetName( aSO, LineEditName->text() );
00323 anEntryList.append( aSO->GetID().c_str() );
00324 }
00325 mySMESHGUI->updateObjBrowser();
00326 } catch(...) {
00327 return false;
00328 }
00329
00330 LineEditName->setText(GetDefaultName(tr("COMPOUND_MESH")));
00331
00332
00333 if ( SMESHGUI::automaticUpdate() ) {
00334 mySelectionMgr->clearSelected();
00335 SMESH::UpdateView();
00336
00337 _PTR(SObject) aSO = SMESH::FindSObject(aCompoundMesh.in());
00338 if ( SMESH_Actor* anActor = SMESH::CreateActor(aSO->GetStudy(), aSO->GetID().c_str()) )
00339 SMESH::DisplayActor(SMESH::GetActiveWindow(), anActor);
00340 }
00341
00342 if( LightApp_Application* anApp =
00343 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
00344 anApp->browseObjects( anEntryList, isApplyAndClose() );
00345
00346 SMESHGUI::Modified();
00347
00348 #ifdef WITHGENERICOBJ
00349
00350
00351
00352 if (!CORBA::is_nil(aCompoundMesh))
00353 aCompoundMesh->UnRegister();
00354 #endif
00355
00356 return true;
00357 }
00358 return false;
00359 }
00360
00361
00362
00363
00364
00365 void SMESHGUI_BuildCompoundDlg::ClickOnOk()
00366 {
00367 setIsApplyAndClose( true );
00368 if (ClickOnApply())
00369 ClickOnCancel();
00370 }
00371
00372
00373
00374
00375
00376 void SMESHGUI_BuildCompoundDlg::ClickOnCancel()
00377 {
00378
00379 mySelectionMgr->clearFilters();
00380 disconnect(mySelectionMgr, 0, this, 0);
00381 mySMESHGUI->ResetState();
00382 reject();
00383 }
00384
00385
00386
00387
00388
00389 void SMESHGUI_BuildCompoundDlg::ClickOnHelp()
00390 {
00391 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00392 if (app)
00393 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00394 else {
00395 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00396 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00397 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00398 "application")).
00399 arg(myHelpFileName));
00400 }
00401 }
00402
00403
00404
00405
00406
00407 void SMESHGUI_BuildCompoundDlg::SelectionIntoArgument()
00408 {
00409 if (!GroupButtons->isEnabled())
00410 return;
00411
00412 QString aString = "";
00413
00414 SALOME_ListIO aList;
00415 mySelectionMgr->selectedObjects(aList);
00416 int nbSel = SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aString);
00417
00418 if (nbSel != 0) {
00419 myMeshArray->length(nbSel);
00420 for (int i = 0; nbSel != 0; i++, nbSel--) {
00421 Handle(SALOME_InteractiveObject) IO = aList.First();
00422 aList.RemoveFirst();
00423 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
00424 myMeshArray[i] = myMesh;
00425 }
00426 }
00427 else {
00428 myMesh = SMESH::SMESH_Mesh::_nil();
00429 aString = "";
00430 }
00431
00432 LineEditMeshes->setText(aString);
00433
00434 bool isEnabled = (!myMesh->_is_nil());
00435 buttonOk->setEnabled(isEnabled);
00436 buttonApply->setEnabled(isEnabled);
00437 }
00438
00439
00440
00441
00442
00443 void SMESHGUI_BuildCompoundDlg::DeactivateActiveDialog()
00444 {
00445 if (GroupConstructors->isEnabled()) {
00446 GroupConstructors->setEnabled(false);
00447 GroupName->setEnabled(false);
00448 GroupArgs->setEnabled(false);
00449 GroupButtons->setEnabled(false);
00450 mySMESHGUI->ResetState();
00451 mySMESHGUI->SetActiveDialogBox(0);
00452 }
00453 }
00454
00455
00456
00457
00458
00459 void SMESHGUI_BuildCompoundDlg::ActivateThisDialog()
00460 {
00461
00462 mySMESHGUI->EmitSignalDeactivateDialog();
00463 GroupConstructors->setEnabled(true);
00464 GroupName->setEnabled(true);
00465 GroupArgs->setEnabled(true);
00466 GroupButtons->setEnabled(true);
00467
00468 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00469 SelectionIntoArgument();
00470 }
00471
00472
00473
00474
00475
00476 void SMESHGUI_BuildCompoundDlg::enterEvent( QEvent* )
00477 {
00478 if (GroupConstructors->isEnabled())
00479 return;
00480 ActivateThisDialog();
00481 }
00482
00483
00484
00485
00486
00487 void SMESHGUI_BuildCompoundDlg::closeEvent( QCloseEvent* )
00488 {
00489
00490 ClickOnCancel();
00491 }
00492
00493
00494
00495
00496
00497 void SMESHGUI_BuildCompoundDlg::hideEvent( QHideEvent* )
00498 {
00499 if (!isMinimized())
00500 ClickOnCancel();
00501 }
00502
00503
00504
00505
00506
00507
00508 void SMESHGUI_BuildCompoundDlg::keyPressEvent( QKeyEvent* e )
00509 {
00510 QDialog::keyPressEvent( e );
00511 if ( e->isAccepted() )
00512 return;
00513
00514 if ( e->key() == Qt::Key_F1 ) {
00515 e->accept();
00516 ClickOnHelp();
00517 }
00518 }
00519
00520
00521
00522
00523
00524
00525 void SMESHGUI_BuildCompoundDlg::onSelectMerge(bool toMerge)
00526 {
00527 TextLabelTol->setEnabled(toMerge);
00528 SpinBoxTol->setEnabled(toMerge);
00529 if(!toMerge)
00530 SpinBoxTol->SetValue(1e-05);
00531 }
00532
00533
00534
00535
00536
00537 bool SMESHGUI_BuildCompoundDlg::isValid()
00538 {
00539 QString msg;
00540 bool ok=true;
00541 if(CheckBoxMerge->isChecked())
00542 ok = SpinBoxTol->isValid( msg, true );
00543
00544 if( !ok ) {
00545 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
00546 if ( !msg.isEmpty() )
00547 str += "\n" + msg;
00548 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
00549 return false;
00550 }
00551 return true;
00552 }
00553
00554
00555
00556
00557
00558
00559 void SMESHGUI_BuildCompoundDlg::setIsApplyAndClose( const bool theFlag )
00560 {
00561 myIsApplyAndClose = theFlag;
00562 }
00563
00564
00565
00566
00567
00568
00569 bool SMESHGUI_BuildCompoundDlg::isApplyAndClose() const
00570 {
00571 return myIsApplyAndClose;
00572 }