00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "SMESHGUI_CopyMeshDlg.h"
00025
00026 #include "SMESHGUI.h"
00027 #include "SMESHGUI_SpinBox.h"
00028 #include "SMESHGUI_Utils.h"
00029 #include "SMESHGUI_VTKUtils.h"
00030 #include "SMESHGUI_MeshUtils.h"
00031 #include "SMESHGUI_IdValidator.h"
00032 #include "SMESHGUI_FilterDlg.h"
00033
00034 #include <SMESH_Actor.h>
00035 #include <SMESH_TypeFilter.hxx>
00036 #include <SMDS_Mesh.hxx>
00037
00038
00039 #include <SUIT_Desktop.h>
00040 #include <SUIT_ResourceMgr.h>
00041 #include <SUIT_Session.h>
00042 #include <SUIT_MessageBox.h>
00043 #include <SUIT_OverrideCursor.h>
00044
00045 #include <LightApp_Application.h>
00046 #include <LightApp_SelectionMgr.h>
00047
00048 #include <SVTK_ViewModel.h>
00049 #include <SVTK_ViewWindow.h>
00050 #include <SALOME_ListIO.hxx>
00051
00052
00053 #include <SALOMEDSClient_SObject.hxx>
00054
00055
00056 #include <TColStd_MapOfInteger.hxx>
00057
00058
00059 #include <QApplication>
00060 #include <QButtonGroup>
00061 #include <QGroupBox>
00062 #include <QLabel>
00063 #include <QLineEdit>
00064 #include <QPushButton>
00065 #include <QRadioButton>
00066 #include <QCheckBox>
00067 #include <QHBoxLayout>
00068 #include <QVBoxLayout>
00069 #include <QGridLayout>
00070 #include <QSpinBox>
00071 #include <QKeyEvent>
00072
00073
00074 #include <SALOMEconfig.h>
00075 #include CORBA_SERVER_HEADER(SMESH_Group)
00076 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
00077
00084 namespace
00085 {
00086 class BusyLocker
00087 {
00088 public:
00090 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
00092 ~BusyLocker() { myBusy = false; }
00093 private:
00094 bool& myBusy;
00095 };
00096 }
00097
00098 #define SPACING 6
00099 #define MARGIN 11
00100
00101
00102
00103 #define WITHGENERICOBJ
00104
00105
00106
00110
00111
00112 SMESHGUI_CopyMeshDlg::SMESHGUI_CopyMeshDlg( SMESHGUI* theModule )
00113 : QDialog( SMESH::GetDesktop( theModule ) ),
00114 mySMESHGUI( theModule ),
00115 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00116 myFilterDlg(0),
00117 mySelectedObject(SMESH::SMESH_IDSource::_nil()),
00118 myIsApplyAndClose( false )
00119 {
00120 QPixmap image (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_COPY_MESH")));
00121
00122 setModal(false);
00123 setAttribute(Qt::WA_DeleteOnClose, true);
00124 setWindowTitle(tr("SMESH_COPY_MESH_TITLE"));
00125 setSizeGripEnabled(true);
00126
00127 QVBoxLayout* SMESHGUI_CopyMeshDlgLayout = new QVBoxLayout(this);
00128 SMESHGUI_CopyMeshDlgLayout->setSpacing(SPACING);
00129 SMESHGUI_CopyMeshDlgLayout->setMargin(MARGIN);
00130
00131
00132 ConstructorsBox = new QGroupBox(tr("SMESH_COPY_MESH_TITLE"), this);
00133 QButtonGroup* GroupConstructors = new QButtonGroup(this);
00134 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
00135 ConstructorsBoxLayout->setSpacing(SPACING);
00136 ConstructorsBoxLayout->setMargin(MARGIN);
00137
00138 QRadioButton* RadioButton1= new QRadioButton(ConstructorsBox);
00139 RadioButton1->setIcon(image);
00140 GroupConstructors->addButton(RadioButton1, 0);
00141
00142 ConstructorsBoxLayout->addWidget(RadioButton1);
00143 RadioButton1->setChecked(true);
00144 GroupConstructors->addButton(RadioButton1, 0);
00145
00146
00147 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
00148 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
00149 GroupArgumentsLayout->setSpacing(SPACING);
00150 GroupArgumentsLayout->setMargin(MARGIN);
00151
00152 myIdValidator = new SMESHGUI_IdValidator(this);
00153
00154
00155 myTextLabelElements = new QLabel(tr("OBJECT_NAME"), GroupArguments);
00156 myLineEditElements = new QLineEdit(GroupArguments);
00157 myLineEditElements->setValidator(myIdValidator);
00158 myLineEditElements->setMaxLength(-1);
00159 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
00160 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
00161
00162
00163 myIdSourceCheck = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
00164
00165
00166 QLabel* meshNameLabel = new QLabel(tr("NEW_NAME"), GroupArguments);
00167 myMeshNameEdit = new QLineEdit(GroupArguments);
00168
00169
00170 myCopyGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
00171 myCopyGroupsCheck->setChecked(false);
00172
00173
00174 myKeepIdsCheck = new QCheckBox(tr("SMESH_KEEP_IDS"), GroupArguments);
00175 myKeepIdsCheck->setChecked(true);
00176
00177
00178 GroupArgumentsLayout->addWidget(myTextLabelElements, 0, 0);
00179 GroupArgumentsLayout->addWidget(myLineEditElements, 0, 1, 1, 5);
00180 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 6);
00181 GroupArgumentsLayout->addWidget(myIdSourceCheck, 1, 0, 1, 6);
00182 GroupArgumentsLayout->addWidget(meshNameLabel, 2, 0);
00183 GroupArgumentsLayout->addWidget(myMeshNameEdit, 2, 1, 1, 5);
00184 GroupArgumentsLayout->addWidget(myCopyGroupsCheck, 3, 0, 1, 6);
00185 GroupArgumentsLayout->addWidget(myKeepIdsCheck, 4, 0, 1, 6);
00186
00187
00188 GroupButtons = new QGroupBox(this);
00189 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
00190 GroupButtonsLayout->setSpacing(SPACING);
00191 GroupButtonsLayout->setMargin(MARGIN);
00192
00193 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
00194 buttonOk->setAutoDefault(true);
00195 buttonOk->setDefault(true);
00196 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
00197 buttonApply->setAutoDefault(true);
00198 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
00199 buttonCancel->setAutoDefault(true);
00200 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
00201 buttonHelp->setAutoDefault(true);
00202
00203 GroupButtonsLayout->addWidget(buttonOk);
00204 GroupButtonsLayout->addSpacing(10);
00205 GroupButtonsLayout->addWidget(buttonApply);
00206 GroupButtonsLayout->addSpacing(10);
00207 GroupButtonsLayout->addStretch();
00208 GroupButtonsLayout->addWidget(buttonCancel);
00209 GroupButtonsLayout->addWidget(buttonHelp);
00210
00211
00212 SMESHGUI_CopyMeshDlgLayout->addWidget(ConstructorsBox);
00213 SMESHGUI_CopyMeshDlgLayout->addWidget(GroupArguments);
00214 SMESHGUI_CopyMeshDlgLayout->addWidget(GroupButtons);
00215
00216
00217 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00218
00219 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00220
00221
00222 myIdSourceFilter = new SMESH_TypeFilter( IDSOURCE );
00223
00224 myHelpFileName = "copy_mesh_page.html";
00225
00226 Init();
00227
00228
00229 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
00230 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
00231 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
00232 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
00233
00234 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()),
00235 this, SLOT (DeactivateActiveDialog()));
00236 connect(mySelectionMgr, SIGNAL (currentSelectionChanged()),
00237 this, SLOT (SelectionIntoArgument()));
00238 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()),
00239 this, SLOT (ClickOnCancel()));
00240
00241 connect(myLineEditElements, SIGNAL(textChanged(const QString&)),
00242 this, SLOT (onTextChange(const QString&)));
00243 connect(myIdSourceCheck, SIGNAL(toggled(bool)),
00244 this, SLOT (onSelectIdSource(bool)));
00245
00246 SelectionIntoArgument();
00247 }
00248
00249
00250
00251
00252
00253
00254 SMESHGUI_CopyMeshDlg::~SMESHGUI_CopyMeshDlg()
00255 {
00256 if ( myFilterDlg )
00257 {
00258 myFilterDlg->setParent( 0 );
00259 delete myFilterDlg; myFilterDlg = 0;
00260 }
00261 if ( myIdSourceFilter )
00262 {
00263 if ( mySelectionMgr )
00264 mySelectionMgr->removeFilter( myIdSourceFilter );
00265 delete myIdSourceFilter; myIdSourceFilter=0;
00266 }
00267 }
00268
00269
00270
00271
00272
00273 void SMESHGUI_CopyMeshDlg::Init (bool ResetControls)
00274 {
00275 myBusy = false;
00276
00277 myMeshNameEdit->setText( SMESH::UniqueMeshName("Mesh"));
00278 if ( ResetControls )
00279 {
00280 myLineEditElements->clear();
00281
00282 myNbOkElements = 0;
00283
00284 buttonOk->setEnabled(false);
00285 buttonApply->setEnabled(false);
00286
00287 myActor = 0;
00288 myMesh = SMESH::SMESH_Mesh::_nil();
00289
00290 myIdSourceCheck->setChecked(true);
00291 myCopyGroupsCheck->setChecked(false);
00292 myKeepIdsCheck->setChecked(false);
00293
00294 onSelectIdSource( myIdSourceCheck->isChecked() );
00295 }
00296 }
00297
00298
00299
00300
00301
00302
00303 bool SMESHGUI_CopyMeshDlg::ClickOnApply()
00304 {
00305 if (mySMESHGUI->isActiveStudyLocked())
00306 return false;
00307
00308 if( !isValid() )
00309 return false;
00310
00311 QStringList anEntryList;
00312 try
00313 {
00314 SUIT_OverrideCursor aWaitCursor;
00315 SMESH::SMESH_IDSource_var aPartToCopy;
00316 if ( myIdSourceCheck->isChecked())
00317 {
00318 aPartToCopy = mySelectedObject;
00319 }
00320 else
00321 {
00322 QStringList aListElementsId = myLineEditElements->text().split(" ", QString::SkipEmptyParts);
00323 SMESH::long_array_var anElementsId = new SMESH::long_array;
00324 anElementsId->length(aListElementsId.count());
00325 for (int i = 0; i < aListElementsId.count(); i++)
00326 anElementsId[i] = aListElementsId[i].toInt();
00327
00328 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
00329 aPartToCopy = aMeshEditor->MakeIDSource( anElementsId, SMESH::ALL );
00330 }
00331 QByteArray meshName = myMeshNameEdit->text().toLatin1();
00332 bool toCopyGroups = ( myCopyGroupsCheck->isChecked() );
00333 bool toKeepIDs = ( myKeepIdsCheck->isChecked() );
00334
00335 SMESH::SMESH_Gen_var gen = SMESHGUI::GetSMESHGen();
00336 SMESH::SMESH_Mesh_var newMesh =
00337 gen->CopyMesh(aPartToCopy, meshName.constData(), toCopyGroups, toKeepIDs);
00338 if( !newMesh->_is_nil() )
00339 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( newMesh ) )
00340 anEntryList.append( aSObject->GetID().c_str() );
00341 #ifdef WITHGENERICOBJ
00342
00343
00344
00345 newMesh->UnRegister();
00346 #endif
00347 } catch (...) {
00348 }
00349
00350 mySMESHGUI->updateObjBrowser(true);
00351 SMESHGUI::Modified();
00352
00353 if( LightApp_Application* anApp =
00354 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
00355 anApp->browseObjects( anEntryList, isApplyAndClose() );
00356
00357 Init(false);
00358 mySelectedObject = SMESH::SMESH_IDSource::_nil();
00359 SelectionIntoArgument();
00360
00361 return true;
00362 }
00363
00364
00365
00366
00367
00368 void SMESHGUI_CopyMeshDlg::ClickOnOk()
00369 {
00370 setIsApplyAndClose( true );
00371 if( ClickOnApply() )
00372 ClickOnCancel();
00373 }
00374
00375
00376
00377
00378
00379 void SMESHGUI_CopyMeshDlg::ClickOnCancel()
00380 {
00381 disconnect(mySelectionMgr, 0, this, 0);
00382 if ( mySelectionMgr )
00383 mySelectionMgr->removeFilter( myIdSourceFilter );
00384 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00385 aViewWindow->SetSelectionMode( ActorSelection );
00386 mySMESHGUI->ResetState();
00387 reject();
00388 }
00389
00390
00391
00392
00393
00394 void SMESHGUI_CopyMeshDlg::ClickOnHelp()
00395 {
00396 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00397 if (app)
00398 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00399 else {
00400 QString platform;
00401 #ifdef WIN32
00402 platform = "winapplication";
00403 #else
00404 platform = "application";
00405 #endif
00406 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00407 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00408 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00409 platform)).
00410 arg(myHelpFileName));
00411 }
00412 }
00413
00414
00415
00416
00417
00418
00419 void SMESHGUI_CopyMeshDlg::onTextChange (const QString& theNewText)
00420 {
00421 QLineEdit* send = (QLineEdit*)sender();
00422
00423 if (myBusy) return;
00424 BusyLocker lock( myBusy );
00425
00426
00427 myNbOkElements = 0;
00428
00429 buttonOk->setEnabled(false);
00430 buttonApply->setEnabled(false);
00431
00432
00433 SMDS_Mesh* aMesh = 0;
00434 if (myActor)
00435 aMesh = myActor->GetObject()->GetMesh();
00436
00437 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
00438 if (myActor && aMesh)
00439 {
00440 TColStd_MapOfInteger newIndices;
00441 if (send == myLineEditElements) {
00442 for (int i = 0; i < aListId.count(); i++)
00443 if ( const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt()))
00444 {
00445 newIndices.Add(e->GetID());
00446 }
00447 }
00448 myNbOkElements = newIndices.Extent();
00449
00450 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
00451 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
00452 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00453 aViewWindow->highlight( anIO, true, true );
00454 }
00455 else
00456 {
00457 myNbOkElements = aListId.count();
00458 }
00459
00460 if (myNbOkElements) {
00461 buttonOk->setEnabled(true);
00462 buttonApply->setEnabled(true);
00463 }
00464 }
00465
00466
00467
00468
00469
00470
00471 void SMESHGUI_CopyMeshDlg::SelectionIntoArgument()
00472 {
00473 if (myBusy) return;
00474 BusyLocker lock( myBusy );
00475
00476
00477 myActor = 0;
00478 QString aString = "";
00479
00480 myLineEditElements->setText(aString);
00481 myNbOkElements = 0;
00482 buttonOk->setEnabled(false);
00483 buttonApply->setEnabled(false);
00484 myFilterBtn->setEnabled(false);
00485
00486
00487 SALOME_ListIO aList;
00488 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
00489 int nbSel = aList.Extent();
00490 if (nbSel != 1)
00491 return;
00492
00493 Handle(SALOME_InteractiveObject) IO = aList.First();
00494 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
00495 if ( mySelectedObject->_is_nil() )
00496 return;
00497
00498 myMesh = SMESH::GetMeshByIO(IO);
00499 if (myMesh->_is_nil())
00500 return;
00501
00502 myActor = SMESH::FindActorByEntry(IO->getEntry());
00503 if (!myActor)
00504 myActor = SMESH::FindActorByObject(myMesh);
00505
00506 if (myIdSourceCheck->isChecked())
00507 {
00508 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
00509 if ( aString.isEmpty() ) aString = " ";
00510 }
00511 else
00512 {
00513 SMESH::GetNameOfSelectedElements( mySelector, IO, aString );
00514 myNbOkElements = aString.size();
00515 myFilterBtn->setEnabled(true);
00516 }
00517 myLineEditElements->setText( aString );
00518 bool ok = !aString.isEmpty();
00519
00520 buttonOk->setEnabled(ok);
00521 buttonApply->setEnabled(ok);
00522 }
00523
00524
00525
00526
00527
00528 void SMESHGUI_CopyMeshDlg::onSelectIdSource (bool toSelectMesh)
00529 {
00530 if (toSelectMesh)
00531 myTextLabelElements->setText(tr("OBJECT_NAME"));
00532 else
00533 myTextLabelElements->setText(tr("ELEM_IDS"));
00534
00535 if (toSelectMesh) {
00536 myLineEditElements->clear();
00537 }
00538
00539 mySelectionMgr->clearFilters();
00540 mySelectionMgr->installFilter(myIdSourceFilter);
00541 SMESH::SetPointRepresentation(false);
00542
00543 if (toSelectMesh) {
00544 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00545 aViewWindow->SetSelectionMode( ActorSelection );
00546 myLineEditElements->setReadOnly(true);
00547 myLineEditElements->setValidator(0);
00548 }
00549 else
00550 {
00551 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00552 aViewWindow->SetSelectionMode( CellSelection );
00553 myLineEditElements->setReadOnly(false);
00554 myLineEditElements->setValidator(myIdValidator);
00555 onTextChange(myLineEditElements->text());
00556 }
00557
00558 SelectionIntoArgument();
00559 }
00560
00561
00562
00563
00564
00565
00566 bool SMESHGUI_CopyMeshDlg::isValid()
00567 {
00568 if ( myIdSourceCheck->isChecked() )
00569 return !mySelectedObject->_is_nil();
00570
00571 return myNbOkElements > 0;
00572 }
00573
00574
00575
00576
00577
00578 void SMESHGUI_CopyMeshDlg::DeactivateActiveDialog()
00579 {
00580 if (ConstructorsBox->isEnabled()) {
00581 ConstructorsBox->setEnabled(false);
00582 GroupArguments->setEnabled(false);
00583 GroupButtons->setEnabled(false);
00584 mySMESHGUI->ResetState();
00585 mySMESHGUI->SetActiveDialogBox(0);
00586 if ( mySelectionMgr )
00587 mySelectionMgr->removeFilter( myIdSourceFilter );
00588 }
00589 }
00590
00591
00592
00593
00594
00595 void SMESHGUI_CopyMeshDlg::ActivateThisDialog()
00596 {
00597
00598 mySMESHGUI->EmitSignalDeactivateDialog();
00599 ConstructorsBox->setEnabled(true);
00600 GroupArguments->setEnabled(true);
00601 GroupButtons->setEnabled(true);
00602
00603 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00604
00605 onSelectIdSource( myIdSourceCheck->isChecked() );
00606
00607 SelectionIntoArgument();
00608 }
00609
00610
00611
00612
00613
00614 void SMESHGUI_CopyMeshDlg::enterEvent (QEvent*)
00615 {
00616 if (!ConstructorsBox->isEnabled())
00617 ActivateThisDialog();
00618 }
00619
00620
00621
00622
00623
00624 void SMESHGUI_CopyMeshDlg::closeEvent (QCloseEvent*)
00625 {
00626
00627 ClickOnCancel();
00628 }
00629
00630
00631
00632
00633
00634 void SMESHGUI_CopyMeshDlg::hideEvent (QHideEvent*)
00635 {
00636 if (!isMinimized())
00637 ClickOnCancel();
00638 }
00639
00640
00641
00642
00643
00644 void SMESHGUI_CopyMeshDlg::keyPressEvent( QKeyEvent* e )
00645 {
00646 QDialog::keyPressEvent( e );
00647 if ( e->isAccepted() )
00648 return;
00649
00650 if ( e->key() == Qt::Key_F1 ) {
00651 e->accept();
00652 ClickOnHelp();
00653 }
00654 }
00655
00656
00657
00658
00659
00660 void SMESHGUI_CopyMeshDlg::setFilters()
00661 {
00662 if(myMesh->_is_nil()) {
00663 SUIT_MessageBox::critical(this,
00664 tr("SMESH_ERROR"),
00665 tr("NO_MESH_SELECTED"));
00666 return;
00667 }
00668 if ( !myFilterDlg )
00669 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
00670
00671 myFilterDlg->SetSelection();
00672 myFilterDlg->SetMesh( myMesh );
00673 myFilterDlg->SetSourceWg( myLineEditElements );
00674
00675 myFilterDlg->show();
00676 }
00677
00678
00679
00680
00681
00682
00683 void SMESHGUI_CopyMeshDlg::setIsApplyAndClose( const bool theFlag )
00684 {
00685 myIsApplyAndClose = theFlag;
00686 }
00687
00688
00689
00690
00691
00692
00693 bool SMESHGUI_CopyMeshDlg::isApplyAndClose() const
00694 {
00695 return myIsApplyAndClose;
00696 }