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
00027
00028 #include "SMESHGUI_DuplicateNodesDlg.h"
00029
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033
00034 #include <SMESH_TypeFilter.hxx>
00035
00036
00037 #include <SUIT_Session.h>
00038 #include <SUIT_ResourceMgr.h>
00039 #include <SUIT_Desktop.h>
00040 #include <SUIT_MessageBox.h>
00041 #include <SUIT_OverrideCursor.h>
00042
00043 #include <LightApp_Application.h>
00044 #include <LightApp_SelectionMgr.h>
00045
00046 #include <SalomeApp_Tools.h>
00047
00048 #include <SVTK_ViewWindow.h>
00049 #include <SALOME_ListIO.hxx>
00050 #include <SALOME_ListIteratorOfListIO.hxx>
00051
00052
00053 #include <QApplication>
00054 #include <QButtonGroup>
00055 #include <QGroupBox>
00056 #include <QLabel>
00057 #include <QLineEdit>
00058 #include <QPushButton>
00059 #include <QRadioButton>
00060 #include <QCheckBox>
00061 #include <QHBoxLayout>
00062 #include <QVBoxLayout>
00063 #include <QKeyEvent>
00064
00065 #include <utilities.h>
00066
00067
00068 #include <SALOMEconfig.h>
00069 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00070
00071 #define SPACING 6
00072 #define MARGIN 11
00073
00080 class BusyLocker
00081 {
00082 public:
00084 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
00086 ~BusyLocker() { myBusy = false; }
00087 private:
00088 bool& myBusy;
00089 };
00090
00095 SMESHGUI_DuplicateNodesDlg::SMESHGUI_DuplicateNodesDlg( SMESHGUI* theModule )
00096 : QDialog( SMESH::GetDesktop( theModule ) ),
00097 mySMESHGUI( theModule ),
00098 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
00099 {
00100
00101 setModal(false);
00102 setAttribute(Qt::WA_DeleteOnClose, true);
00103 setWindowTitle(tr("SMESH_DUPLICATE_TITLE"));
00104 setSizeGripEnabled(true);
00105
00106
00107 SUIT_ResourceMgr* aResMgr = SMESH::GetResourceMgr( mySMESHGUI );
00108 QPixmap iconWithoutElem (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_NODES")));
00109 QPixmap iconWithElem (aResMgr->loadPixmap("SMESH", tr("ICON_SMESH_DUPLICATE_NODES_WITH_ELEM")));
00110 QPixmap iconSelect (aResMgr->loadPixmap("SMESH", tr("ICON_SELECT")));
00111
00112
00113 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
00114 aMainLayout->setSpacing(SPACING);
00115 aMainLayout->setMargin(MARGIN);
00116
00117
00118 QGroupBox* aConstructorsBox = new QGroupBox(tr("DUPLICATION_MODE"), this);
00119 myGroupConstructors = new QButtonGroup(this);
00120 QHBoxLayout* aConstructorsBoxLayout = new QHBoxLayout(aConstructorsBox);
00121 aConstructorsBoxLayout->setSpacing(SPACING);
00122 aConstructorsBoxLayout->setMargin(MARGIN);
00123
00124 QRadioButton* aRadioButton1 = new QRadioButton(aConstructorsBox);
00125 aRadioButton1->setIcon(iconWithoutElem);
00126 QRadioButton* aRadioButton2 = new QRadioButton(aConstructorsBox);
00127 aRadioButton2->setIcon(iconWithElem);
00128
00129 aConstructorsBoxLayout->addWidget(aRadioButton1);
00130 aConstructorsBoxLayout->addWidget(aRadioButton2);
00131 myGroupConstructors->addButton(aRadioButton1, 0);
00132 myGroupConstructors->addButton(aRadioButton2, 1);
00133
00134
00135 myGroupArguments = new QGroupBox(this);
00136 QGridLayout* aGroupArgumentsLayout = new QGridLayout(myGroupArguments);
00137 aGroupArgumentsLayout->setSpacing(SPACING);
00138 aGroupArgumentsLayout->setMargin(MARGIN);
00139
00140 myTextLabel1 = new QLabel(myGroupArguments);
00141 mySelectButton1 = new QPushButton(myGroupArguments);
00142 mySelectButton1->setIcon(iconSelect);
00143 myLineEdit1 = new QLineEdit(myGroupArguments);
00144 myLineEdit1->setReadOnly(true);
00145
00146 myTextLabel2 = new QLabel(myGroupArguments);
00147 mySelectButton2 = new QPushButton(myGroupArguments);
00148 mySelectButton2->setIcon(iconSelect);
00149 myLineEdit2 = new QLineEdit(myGroupArguments);
00150 myLineEdit2->setReadOnly(true);
00151
00152 myTextLabel3 = new QLabel(myGroupArguments);
00153 mySelectButton3 = new QPushButton(myGroupArguments);
00154 mySelectButton3->setIcon(iconSelect);
00155 myLineEdit3 = new QLineEdit(myGroupArguments);
00156 myLineEdit3->setReadOnly(true);
00157
00158 myCheckBoxNewGroup = new QCheckBox(tr("CONSTRUCT_NEW_GROUP_NODES"), myGroupArguments);
00159
00160 aGroupArgumentsLayout->addWidget(myTextLabel1, 0, 0);
00161 aGroupArgumentsLayout->addWidget(mySelectButton1, 0, 1);
00162 aGroupArgumentsLayout->addWidget(myLineEdit1, 0, 2);
00163 aGroupArgumentsLayout->addWidget(myTextLabel2, 1, 0);
00164 aGroupArgumentsLayout->addWidget(mySelectButton2, 1, 1);
00165 aGroupArgumentsLayout->addWidget(myLineEdit2, 1, 2);
00166 aGroupArgumentsLayout->addWidget(myTextLabel3, 2, 0);
00167 aGroupArgumentsLayout->addWidget(mySelectButton3, 2, 1);
00168 aGroupArgumentsLayout->addWidget(myLineEdit3, 2, 2);
00169 aGroupArgumentsLayout->addWidget(myCheckBoxNewGroup, 3, 0);
00170 aGroupArgumentsLayout->setRowStretch(4, 1);
00171
00172
00173 QGroupBox* aGroupButtons = new QGroupBox(this);
00174 QHBoxLayout* aGroupButtonsLayout = new QHBoxLayout(aGroupButtons);
00175 aGroupButtonsLayout->setSpacing(SPACING);
00176 aGroupButtonsLayout->setMargin(MARGIN);
00177
00178 myButtonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGroupButtons);
00179 myButtonOk->setAutoDefault(true);
00180 myButtonOk->setDefault(true);
00181 myButtonApply = new QPushButton(tr("SMESH_BUT_APPLY"), aGroupButtons);
00182 myButtonApply->setAutoDefault(true);
00183 myButtonClose = new QPushButton(tr("SMESH_BUT_CLOSE"), aGroupButtons);
00184 myButtonClose->setAutoDefault(true);
00185 myButtonHelp = new QPushButton(tr("SMESH_BUT_HELP"), aGroupButtons);
00186 myButtonHelp->setAutoDefault(true);
00187
00188 aGroupButtonsLayout->addWidget(myButtonOk);
00189 aGroupButtonsLayout->addSpacing(10);
00190 aGroupButtonsLayout->addWidget(myButtonApply);
00191 aGroupButtonsLayout->addSpacing(10);
00192 aGroupButtonsLayout->addStretch();
00193 aGroupButtonsLayout->addWidget(myButtonClose);
00194 aGroupButtonsLayout->addWidget(myButtonHelp);
00195
00196
00197 aMainLayout->addWidget(aConstructorsBox);
00198 aMainLayout->addWidget(myGroupArguments);
00199 aMainLayout->addWidget(aGroupButtons);
00200
00201
00202 Init();
00203
00204
00205 myHelpFileName = "double_nodes_page.html";
00206
00207
00208 connect(myGroupConstructors, SIGNAL(buttonClicked(int)), SLOT(onConstructorsClicked(int)));
00209
00210 connect(mySelectButton1, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
00211 connect(mySelectButton2, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
00212 connect(mySelectButton3, SIGNAL (clicked()), this, SLOT(onEditCurrentArgument()));
00213
00214 connect(myButtonOk, SIGNAL(clicked()), this, SLOT(onOk()));
00215 connect(myButtonClose, SIGNAL(clicked()), this, SLOT(onClose()));
00216 connect(myButtonApply, SIGNAL(clicked()), this, SLOT(onApply()));
00217 connect(myButtonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
00218
00219 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionChanged()));
00220
00221 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(onDeactivate()));
00222 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(onClose()));
00223 }
00224
00228 SMESHGUI_DuplicateNodesDlg::~SMESHGUI_DuplicateNodesDlg()
00229 {
00230 }
00231
00235 void SMESHGUI_DuplicateNodesDlg::Init()
00236 {
00237 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00238 myCheckBoxNewGroup->setChecked(true);
00239
00240
00241 myBusy = false;
00242 myCurrentLineEdit = myLineEdit1;
00243
00244 myGroups1.clear();
00245 myGroups2.clear();
00246 myGroups3.clear();
00247
00248
00249 mySelectionMgr->installFilter(new SMESH_TypeFilter(GROUP));
00250 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00251 aViewWindow->SetSelectionMode(ActorSelection);
00252
00253
00254 int operationMode = myGroupConstructors->checkedId();
00255 if (operationMode < 0) {
00256
00257 operationMode = 0;
00258 myGroupConstructors->button(0)->setChecked(true);
00259 }
00260 onConstructorsClicked(operationMode);
00261 }
00262
00267 void SMESHGUI_DuplicateNodesDlg::onConstructorsClicked (int constructorId)
00268 {
00269
00270 myLineEdit1->clear();
00271 myLineEdit2->clear();
00272 myLineEdit3->clear();
00273
00274 myGroups1.clear();
00275 myGroups2.clear();
00276 myGroups3.clear();
00277
00278
00279 myCurrentLineEdit = myLineEdit1;
00280 myCurrentLineEdit->setFocus();
00281
00282 switch (constructorId) {
00283 case 0:
00284 {
00285
00286 myGroupArguments->setTitle(tr("DUPLICATION_WITHOUT_ELEMS"));
00287 myTextLabel1->setText(tr("GROUP_NODES_TO_DUPLICATE"));
00288 myTextLabel2->setText(tr("GROUP_NODES_TO_REPLACE"));
00289
00290
00291 myCheckBoxNewGroup->setText(tr("CONSTRUCT_NEW_GROUP_NODES"));
00292
00293
00294 myTextLabel3->hide();
00295 mySelectButton3->hide();
00296 myLineEdit3->hide();
00297
00298 break;
00299 }
00300 case 1:
00301 {
00302
00303 myGroupArguments->setTitle(tr("DUPLICATION_WITH_ELEMS"));
00304 myTextLabel1->setText(tr("GROUP_ELEMS_TO_DUPLICATE"));
00305 myTextLabel2->setText(tr("GROUP_NODES_NOT_DUPLICATE"));
00306 myTextLabel3->setText(tr("GROUP_ELEMS_TO_REPLACE"));
00307
00308
00309 myCheckBoxNewGroup->setText(tr("CONSTRUCT_NEW_GROUP_ELEMENTS"));
00310
00311
00312 myTextLabel3->show();
00313 mySelectButton3->show();
00314 myLineEdit3->show();
00315
00316 break;
00317 }
00318 }
00319
00320
00321 onSelectionChanged();
00322 }
00323
00327 bool SMESHGUI_DuplicateNodesDlg::onApply()
00328 {
00329 if ( mySMESHGUI->isActiveStudyLocked() || !isValid() )
00330 return false;
00331
00332 BusyLocker lock( myBusy );
00333
00334 bool toCreateGroup = myCheckBoxNewGroup->isChecked();
00335 int operationMode = myGroupConstructors->checkedId();
00336
00337
00338 bool result = false;
00339 SUIT_OverrideCursor aWaitCursor;
00340
00341 try {
00342 SMESH::SMESH_Mesh_var aMesh = myGroups1[0]->GetMesh();
00343 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
00344
00345 if ( operationMode == 0 ) {
00346 SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
00347 g1->length( myGroups1.count() );
00348 for ( int i = 0; i < myGroups1.count(); i++ )
00349 g1[i] = myGroups1[i];
00350 SMESH::ListOfGroups_var g2 = new SMESH::ListOfGroups();
00351 g2->length( myGroups2.count() );
00352 for ( int i = 0; i < myGroups2.count(); i++ )
00353 g2[i] = myGroups2[i];
00354
00355 if ( toCreateGroup ) {
00356 SMESH::SMESH_GroupBase_var aNewGroup =
00357 aMeshEditor->DoubleNodeGroupsNew( g1.in(), g2.in() );
00358 result = !CORBA::is_nil( aNewGroup );
00359 }
00360 else {
00361 result = aMeshEditor->DoubleNodeGroups( g1.in(), g2.in() );
00362 }
00363 }
00364 else {
00365 SMESH::ListOfGroups_var g1 = new SMESH::ListOfGroups();
00366 g1->length( myGroups1.count() );
00367 for ( int i = 0; i < myGroups1.count(); i++ )
00368 g1[i] = myGroups1[i];
00369 SMESH::ListOfGroups_var g2 = new SMESH::ListOfGroups();
00370 g2->length( myGroups2.count() );
00371 for ( int i = 0; i < myGroups2.count(); i++ )
00372 g2[i] = myGroups2[i];
00373 SMESH::ListOfGroups_var g3 = new SMESH::ListOfGroups();
00374 g3->length( myGroups3.count() );
00375
00376 for ( int i = 0; i < myGroups3.count(); i++ )
00377 g3[i] = myGroups3[i];
00378 if ( toCreateGroup ) {
00379 SMESH::SMESH_GroupBase_ptr aNewGroup =
00380 aMeshEditor->DoubleNodeElemGroupsNew( g1.in(), g2.in(), g3.in() );
00381 result = !CORBA::is_nil( aNewGroup );
00382 }
00383 else {
00384 result = aMeshEditor->DoubleNodeElemGroups( g1.in(), g2.in(), g3.in() );
00385 }
00386 }
00387 }
00388 catch (const SALOME::SALOME_Exception& S_ex) {
00389 SalomeApp_Tools::QtCatchCorbaException(S_ex);
00390 }
00391 catch ( const std::exception& exc ) {
00392 INFOS( "Follow exception was cought:\n\t" << exc.what() );
00393 }
00394 catch (...){
00395 INFOS( "Unknown exception was cought !!!" );
00396 }
00397
00398 if (!result) {
00399 SUIT_MessageBox::warning(this,
00400 tr("SMESH_WRN_WARNING"),
00401 tr("SMESH_OPERATION_FAILED"));
00402 return false;
00403 }
00404
00405
00406 mySelectionMgr->clearSelected();
00407 SMESH::UpdateView();
00408 SMESHGUI::Modified();
00409 mySMESHGUI->updateObjBrowser(true);
00410
00411
00412 Init();
00413
00414 return true;
00415 }
00416
00420 void SMESHGUI_DuplicateNodesDlg::onOk()
00421 {
00422 if (onApply())
00423 onClose();
00424 }
00425
00429 void SMESHGUI_DuplicateNodesDlg::onClose()
00430 {
00431 disconnect(mySelectionMgr, 0, this, 0);
00432 disconnect(mySMESHGUI, 0, this, 0);
00433 mySMESHGUI->ResetState();
00434 mySelectionMgr->clearFilters();
00435 reject();
00436 }
00437
00441 void SMESHGUI_DuplicateNodesDlg::onSelectionChanged()
00442 {
00443 if ( myBusy || !isEnabled() ) return;
00444
00445 int operationMode = myGroupConstructors->checkedId();
00446
00447 SALOME_ListIO aList;
00448 mySelectionMgr->selectedObjects( aList );
00449
00450
00451 QList<SMESH::SMESH_GroupBase_var> aGroups;
00452
00453 SALOME_ListIteratorOfListIO anIter ( aList );
00454 bool ok = true;
00455 for ( ; anIter.More() && ok; anIter.Next()) {
00456 SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>( anIter.Value() );
00457
00458 ok = !CORBA::is_nil( aGroup );
00459
00460 if ( ok ) {
00461 SMESH::SMESH_Mesh_var aMesh1;
00462 if ( !aGroups.isEmpty() ) aMesh1 = aGroups[0]->GetMesh();
00463 SMESH::SMESH_Mesh_var aMesh2 = aGroup->GetMesh();
00464 ok = CORBA::is_nil( aMesh1 ) || aMesh1->_is_equivalent( aMesh2 );
00465 }
00466
00467 if ( ok ) {
00468 SMESH::ElementType aGroupType = aGroup->GetType();
00469 if ( operationMode == 0 ) {
00470 ok = ( myCurrentLineEdit == myLineEdit1 && aGroupType == SMESH::NODE ) ||
00471 ( myCurrentLineEdit == myLineEdit2 && aGroupType != SMESH::NODE );
00472 }
00473 else {
00474 ok = ( myCurrentLineEdit == myLineEdit1 && ( aGroupType == SMESH::EDGE ||
00475 aGroupType == SMESH::FACE ) ) ||
00476 ( myCurrentLineEdit == myLineEdit2 && aGroupType == SMESH::NODE ) ||
00477 ( myCurrentLineEdit == myLineEdit3 && aGroupType != SMESH::NODE );
00478 }
00479 }
00480 if ( ok ) aGroups << aGroup;
00481 }
00482
00483
00484 myCurrentLineEdit->clear();
00485
00486 if ( ok && !aGroups.isEmpty() ) {
00487 if ( myCurrentLineEdit == myLineEdit1 ) myGroups1 = aGroups;
00488 else if ( myCurrentLineEdit == myLineEdit2 ) myGroups2 = aGroups;
00489 else if ( myCurrentLineEdit == myLineEdit3 ) myGroups3 = aGroups;
00490 myCurrentLineEdit->setText( aGroups.count() == 1 ? aGroups[0]->GetName() :
00491 QObject::tr( "SMESH_OBJECTS_SELECTED" ).arg( aGroups.count() ) );
00492 }
00493 else {
00494 if ( myCurrentLineEdit == myLineEdit1 ) myGroups1.clear();
00495 else if ( myCurrentLineEdit == myLineEdit2 ) myGroups2.clear();
00496 else if ( myCurrentLineEdit == myLineEdit3 ) myGroups3.clear();
00497 myCurrentLineEdit->clear();
00498 }
00499
00500
00501 bool isDataValid = isValid();
00502 myButtonOk->setEnabled( isDataValid );
00503 myButtonApply->setEnabled( isDataValid );
00504 }
00505
00509 void SMESHGUI_DuplicateNodesDlg::onEditCurrentArgument()
00510 {
00511 QPushButton* send = (QPushButton*)sender();
00512
00513
00514 if (send == mySelectButton1) {
00515 myCurrentLineEdit = myLineEdit1;
00516 }
00517 else if (send == mySelectButton2) {
00518 myCurrentLineEdit = myLineEdit2;
00519 }
00520 else if (send == mySelectButton3) {
00521 myCurrentLineEdit = myLineEdit3;
00522 }
00523
00524 myCurrentLineEdit->setFocus();
00525 onSelectionChanged();
00526 }
00527
00532 bool SMESHGUI_DuplicateNodesDlg::isValid()
00533 {
00534 return myGroupConstructors->checkedId() == 1 ?
00535 ( !myGroups1.isEmpty() && !myGroups3.isEmpty() ) :
00536 ( !myGroups1.isEmpty() );
00537 }
00538
00539
00543 void SMESHGUI_DuplicateNodesDlg::onDeactivate()
00544 {
00545 if (isEnabled()) {
00546 mySelectionMgr->clearFilters();
00547 setEnabled(false);
00548 mySMESHGUI->ResetState();
00549 mySMESHGUI->SetActiveDialogBox(0);
00550 }
00551 }
00552
00558 void SMESHGUI_DuplicateNodesDlg::enterEvent (QEvent*)
00559 {
00560 if ( !isEnabled() ) {
00561 mySMESHGUI->EmitSignalDeactivateDialog();
00562 setEnabled(true);
00563 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00564
00565
00566 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00567 aViewWindow->SetSelectionMode(ActorSelection);
00568 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
00569 }
00570 }
00571
00576 void SMESHGUI_DuplicateNodesDlg::closeEvent (QCloseEvent*)
00577 {
00578 onClose();
00579 }
00580
00585 void SMESHGUI_DuplicateNodesDlg::keyPressEvent( QKeyEvent* e )
00586 {
00587 QDialog::keyPressEvent( e );
00588 if ( e->isAccepted() )
00589 return;
00590
00591 if ( e->key() == Qt::Key_F1 ) {
00592 e->accept();
00593 onHelp();
00594 }
00595 }
00596
00600 void SMESHGUI_DuplicateNodesDlg::onHelp()
00601 {
00602 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00603 if (app)
00604 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00605 else {
00606 QString platform;
00607 #ifdef WIN32
00608 platform = "winapplication";
00609 #else
00610 platform = "application";
00611 #endif
00612 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00613 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00614 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00615 platform)).
00616 arg(myHelpFileName));
00617 }
00618 }