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_GroupOpDlg.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_ResourceMgr.h>
00038 #include <SUIT_Desktop.h>
00039 #include <SUIT_Session.h>
00040 #include <SUIT_MessageBox.h>
00041
00042 #include <LightApp_Application.h>
00043 #include <LightApp_SelectionMgr.h>
00044 #include <SVTK_Selection.h>
00045 #include <SVTK_ViewWindow.h>
00046 #include <SALOME_ListIO.hxx>
00047
00048
00049 #include <SALOMEDSClient_SObject.hxx>
00050
00051
00052 #include <QHBoxLayout>
00053 #include <QVBoxLayout>
00054 #include <QGridLayout>
00055 #include <QPushButton>
00056 #include <QGroupBox>
00057 #include <QLabel>
00058 #include <QLineEdit>
00059 #include <QKeyEvent>
00060 #include <QListWidget>
00061 #include <QButtonGroup>
00062 #include <SALOME_ListIteratorOfListIO.hxx>
00063 #include <QComboBox>
00064 #include <QtxColorButton.h>
00065
00066 #define SPACING 6
00067 #define MARGIN 11
00068
00078 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
00079 : QDialog( SMESH::GetDesktop( theModule ) ),
00080 mySMESHGUI( theModule ),
00081 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
00082 myIsApplyAndClose( false )
00083 {
00084 setModal(false);
00085
00086 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
00087
00088 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
00089 aDlgLay->setMargin(MARGIN);
00090 aDlgLay->setSpacing(SPACING);
00091
00092 QWidget* aMainFrame = createMainFrame (this);
00093 QWidget* aBtnFrame = createButtonFrame(this);
00094
00095 aDlgLay->addWidget(aMainFrame);
00096 aDlgLay->addWidget(aBtnFrame);
00097
00098 Init();
00099 }
00100
00106 QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
00107 {
00108 QWidget* aMainGrp = new QWidget(theParent);
00109 QVBoxLayout* aLay = new QVBoxLayout(aMainGrp);
00110 aLay->setMargin(0);
00111 aLay->setSpacing(SPACING);
00112
00113
00114 QGroupBox* aNameGrp = new QGroupBox(tr("NAME"), aMainGrp);
00115 QHBoxLayout* aNameGrpLayout = new QHBoxLayout(aNameGrp);
00116 aNameGrpLayout->setMargin(MARGIN);
00117 aNameGrpLayout->setSpacing(SPACING);
00118
00119 QLabel* aNameLab = new QLabel(tr("RESULT_NAME"), aNameGrp);
00120 myNameEdit = new QLineEdit(aNameGrp);
00121
00122 aNameGrpLayout->addWidget(aNameLab);
00123 aNameGrpLayout->addWidget(myNameEdit);
00124
00125
00126 myArgGrp = new QGroupBox(tr("ARGUMENTS"), aMainGrp);
00127
00128
00129
00130
00131 QGroupBox* aColorBox = new QGroupBox(tr( "SMESH_SET_COLOR" ), this);
00132 QHBoxLayout* aColorBoxLayout = new QHBoxLayout(aColorBox);
00133 aColorBoxLayout->setMargin(MARGIN);
00134 aColorBoxLayout->setSpacing(SPACING);
00135
00136 QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
00137 myColorBtn = new QtxColorButton(aColorBox);
00138 myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding,
00139 myColorBtn->sizePolicy().verticalPolicy() );
00140
00141 aColorBoxLayout->addWidget(aColorLab);
00142 aColorBoxLayout->addWidget(myColorBtn);
00143
00144
00145 aLay->addWidget( aNameGrp );
00146 aLay->addWidget( myArgGrp );
00147 aLay->addWidget( aColorBox );
00148
00149 return aMainGrp;
00150 }
00151
00156 QGroupBox* SMESHGUI_GroupOpDlg::getArgGrp() const
00157 {
00158 return myArgGrp;
00159 }
00160
00165 void SMESHGUI_GroupOpDlg::setHelpFileName( const QString& theFName )
00166 {
00167 myHelpFileName = theFName;
00168 }
00169
00174 SMESHGUI* SMESHGUI_GroupOpDlg::getSMESHGUI() const
00175 {
00176 return mySMESHGUI;
00177 }
00178
00184 QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
00185 {
00186 QGroupBox* aFrame = new QGroupBox(theParent);
00187
00188 myOkBtn = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aFrame);
00189 myApplyBtn = new QPushButton(tr("SMESH_BUT_APPLY"), aFrame);
00190 myCloseBtn = new QPushButton(tr("SMESH_BUT_CLOSE"), aFrame);
00191 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP"), aFrame);
00192
00193 QHBoxLayout* aLay = new QHBoxLayout(aFrame);
00194 aLay->setMargin(MARGIN);
00195 aLay->setSpacing(SPACING);
00196
00197 aLay->addWidget(myOkBtn);
00198 aLay->addSpacing(10);
00199 aLay->addWidget(myApplyBtn);
00200 aLay->addSpacing(10);
00201 aLay->addStretch();
00202 aLay->addWidget(myCloseBtn);
00203 aLay->addWidget(myHelpBtn);
00204
00205
00206 connect(myOkBtn, SIGNAL(clicked()), SLOT(onOk()));
00207 connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
00208 connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
00209 connect(myHelpBtn, SIGNAL(clicked()), SLOT(onHelp()));
00210
00211 return aFrame;
00212 }
00213
00217 SMESHGUI_GroupOpDlg::~SMESHGUI_GroupOpDlg()
00218 {
00219 }
00220
00224 void SMESHGUI_GroupOpDlg::Init()
00225 {
00226 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
00227
00228
00229 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
00230 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
00231 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnClose()));
00232
00233
00234 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00235 aViewWindow->SetSelectionMode(ActorSelection);
00236 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
00237 }
00238
00245 bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theListGrp )
00246 {
00247 if ( theListGrp.isEmpty() )
00248 {
00249 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
00250 tr("INCORRECT_ARGUMENTS") );
00251 return false;
00252 }
00253
00254 int aMeshId = -1, aGrpType = -1;
00255 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter;
00256 for ( anIter = theListGrp.begin(); anIter != theListGrp.end(); ++anIter )
00257 {
00258 SMESH::SMESH_GroupBase_var aGrp = *anIter;
00259 if ( CORBA::is_nil( aGrp ) )
00260 continue;
00261
00262 SMESH::SMESH_Mesh_var aMesh = aGrp->GetMesh();
00263 if ( CORBA::is_nil( aMesh ) )
00264 continue;
00265
00266
00267 int aCurrId = aMesh->GetId();
00268 if ( aMeshId == -1 )
00269 aMeshId = aCurrId;
00270 else
00271 {
00272 if ( aMeshId != aCurrId )
00273 {
00274 aMeshId = -1;
00275 break;
00276 }
00277 }
00278
00279
00280 int aCurrType = aGrp->GetType();
00281 if ( aGrpType == -1 )
00282 aGrpType = aCurrType;
00283 else
00284 {
00285 if ( aGrpType != aCurrType )
00286 {
00287 aGrpType = -1;
00288 break;
00289 }
00290 }
00291
00292 }
00293
00294 if ( aMeshId == -1 )
00295 {
00296 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00297 tr("DIFF_MESHES"));
00298 return false;
00299 }
00300
00301 if ( aGrpType == -1 )
00302 {
00303 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00304 tr("DIFF_TYPES"));
00305 return false;
00306 }
00307
00308 return true;
00309 }
00310
00314 void SMESHGUI_GroupOpDlg::onOk()
00315 {
00316 setIsApplyAndClose( true );
00317 if ( onApply() )
00318 onClose();
00319 setIsApplyAndClose( false );
00320 }
00321
00325 void SMESHGUI_GroupOpDlg::onClose()
00326 {
00327 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00328 aViewWindow->SetSelectionMode(ActorSelection);
00329 disconnect( mySelectionMgr, 0, this, 0 );
00330 disconnect( mySMESHGUI, 0, this, 0 );
00331 mySMESHGUI->ResetState();
00332 mySelectionMgr->clearFilters();
00333 reset();
00334 reject();
00335 }
00336
00340 void SMESHGUI_GroupOpDlg::onHelp()
00341 {
00342 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
00343 if (app)
00344 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
00345 else {
00346 QString platform;
00347 #ifdef WIN32
00348 platform = "winapplication";
00349 #else
00350 platform = "application";
00351 #endif
00352 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
00353 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00354 arg(app->resourceMgr()->stringValue("ExternalBrowser",
00355 platform)).
00356 arg(myHelpFileName));
00357 }
00358 }
00359
00366 bool SMESHGUI_GroupOpDlg::getSelectedGroups( QList<SMESH::SMESH_GroupBase_var>& theOutList,
00367 QStringList& theOutNames )
00368 {
00369 theOutList.clear();
00370
00371 theOutList.clear();
00372 theOutNames.clear();
00373
00374 SALOME_ListIO aListIO;
00375 mySelectionMgr->selectedObjects( aListIO );
00376 SALOME_ListIteratorOfListIO anIter ( aListIO );
00377 for ( ; anIter.More(); anIter.Next())
00378 {
00379 SMESH::SMESH_GroupBase_var aGroup =
00380 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Value());
00381 if ( !aGroup->_is_nil())
00382 {
00383 theOutList.append( aGroup );
00384 theOutNames.append( aGroup->GetName() );
00385 }
00386 }
00387
00388 return theOutList.count() > 0;
00389 }
00390
00396 SMESH::ListOfGroups* SMESHGUI_GroupOpDlg::convert(
00397 const QList<SMESH::SMESH_GroupBase_var>& theIn )
00398 {
00399 SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
00400 aList->length( theIn.count() );
00401
00402 QList<SMESH::SMESH_GroupBase_var>::const_iterator anIter = theIn.begin();
00403 for ( int i = 0; anIter != theIn.end(); ++anIter, ++i )
00404 aList[ i ] = *anIter;
00405
00406 return aList._retn();
00407 }
00408
00413 SALOMEDS::Color SMESHGUI_GroupOpDlg::getColor() const
00414 {
00415 QColor aQColor = myColorBtn->color();
00416
00417 SALOMEDS::Color aColor;
00418 aColor.R = (float)aQColor.red() / 255.0;
00419 aColor.G = (float)aQColor.green() / 255.0;
00420 aColor.B = (float)aQColor.blue() / 255.0;
00421
00422 return aColor;
00423 }
00424
00430 void SMESHGUI_GroupOpDlg::onSelectionDone()
00431 {
00432 }
00433
00438 void SMESHGUI_GroupOpDlg::setVisible( bool visible )
00439 {
00440 if ( visible )
00441 {
00442 onSelectionDone();
00443 resize( minimumSizeHint().width(), sizeHint().height() );
00444 }
00445 QDialog::setVisible( visible );
00446 }
00447
00451 void SMESHGUI_GroupOpDlg::onDeactivate()
00452 {
00453 setEnabled(false);
00454 mySelectionMgr->clearFilters();
00455 }
00456
00461 void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
00462 {
00463 mySMESHGUI->EmitSignalDeactivateDialog();
00464 setEnabled(true);
00465 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
00466 aViewWindow->SetSelectionMode(ActorSelection);
00467 mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
00468 }
00469
00473 void SMESHGUI_GroupOpDlg::closeEvent(QCloseEvent*)
00474 {
00475 onClose();
00476 }
00477
00483 void SMESHGUI_GroupOpDlg::reset()
00484 {
00485 myNameEdit->setText("");
00486 myNameEdit->setFocus();
00487 }
00488
00494 QString SMESHGUI_GroupOpDlg::getName() const
00495 {
00496 return myNameEdit->text();
00497 }
00498
00504 void SMESHGUI_GroupOpDlg::setName( const QString& theName )
00505 {
00506 myNameEdit->setText( theName );
00507 }
00508
00513 void SMESHGUI_GroupOpDlg::keyPressEvent( QKeyEvent* e )
00514 {
00515 QDialog::keyPressEvent( e );
00516 if ( e->isAccepted() )
00517 return;
00518
00519 if ( e->key() == Qt::Key_F1 ) {
00520 e->accept();
00521 onHelp();
00522 }
00523 }
00524
00529 bool SMESHGUI_GroupOpDlg::onApply()
00530 {
00531 return false;
00532 }
00533
00540 void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
00541 {
00542 myIsApplyAndClose = theFlag;
00543 }
00544
00551 bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
00552 {
00553 return myIsApplyAndClose;
00554 }
00555
00556
00557
00562 SMESHGUI_UnionGroupsDlg::SMESHGUI_UnionGroupsDlg( SMESHGUI* theModule )
00563 : SMESHGUI_GroupOpDlg( theModule )
00564 {
00565 setWindowTitle(tr("UNION_OF_GROUPS"));
00566 setHelpFileName( "using_operations_on_groups_page.html#union_anchor" );
00567
00568 QGroupBox* anArgGrp = getArgGrp();
00569 myListWg = new QListWidget( anArgGrp );
00570
00571 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
00572 aLay->addWidget( myListWg );
00573 }
00574
00578 SMESHGUI_UnionGroupsDlg::~SMESHGUI_UnionGroupsDlg()
00579 {
00580 }
00581
00586 void SMESHGUI_UnionGroupsDlg::reset()
00587 {
00588 SMESHGUI_GroupOpDlg::reset();
00589 myListWg->clear();
00590 myGroups.clear();
00591 }
00592
00597 bool SMESHGUI_UnionGroupsDlg::onApply()
00598 {
00599 if ( getSMESHGUI()->isActiveStudyLocked())
00600 return false;
00601
00602
00603 if ( getName() == "" )
00604 {
00605 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00606 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
00607 return false;
00608 }
00609
00610 if ( !isValid( myGroups ) )
00611 return false;
00612
00613 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
00614 QString aName = getName();
00615
00616 bool aRes = false;
00617 QStringList anEntryList;
00618 try
00619 {
00620 SMESH::ListOfGroups_var aList = convert( myGroups );
00621 SMESH::SMESH_Group_var aNewGrp =
00622 aMesh->UnionListOfGroups( aList, aName.toLatin1().constData() );
00623 if ( !CORBA::is_nil( aNewGrp ) )
00624 {
00625 aNewGrp->SetColor( getColor() );
00626 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
00627 anEntryList.append( aSObject->GetID().c_str() );
00628 aRes = true;
00629 }
00630 }
00631 catch( ... )
00632 {
00633 aRes = false;
00634 }
00635
00636 if ( aRes )
00637 {
00638 SMESHGUI::Modified();
00639 getSMESHGUI()->updateObjBrowser(true);
00640 reset();
00641 if( LightApp_Application* anApp =
00642 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
00643 anApp->browseObjects( anEntryList, isApplyAndClose() );
00644 return true;
00645 }
00646 else
00647 {
00648 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
00649 tr("SMESH_OPERATION_FAILED"));
00650 return false;
00651 }
00652 }
00653
00657 void SMESHGUI_UnionGroupsDlg::onSelectionDone()
00658 {
00659 QStringList aNames;
00660 getSelectedGroups( myGroups, aNames );
00661 myListWg->clear();
00662 myListWg->addItems( aNames );
00663 }
00664
00665
00666
00671 SMESHGUI_IntersectGroupsDlg::SMESHGUI_IntersectGroupsDlg( SMESHGUI* theModule )
00672 : SMESHGUI_GroupOpDlg( theModule )
00673 {
00674 setWindowTitle(tr("INTERSECTION_OF_GROUPS"));
00675 setHelpFileName( "using_operations_on_groups_page.html#intersection_anchor" );
00676
00677 QGroupBox* anArgGrp = getArgGrp();
00678 myListWg = new QListWidget( anArgGrp );
00679
00680 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
00681 aLay->addWidget( myListWg );
00682 }
00683
00687 SMESHGUI_IntersectGroupsDlg::~SMESHGUI_IntersectGroupsDlg()
00688 {
00689 }
00690
00695 void SMESHGUI_IntersectGroupsDlg::reset()
00696 {
00697 SMESHGUI_GroupOpDlg::reset();
00698 myListWg->clear();
00699 myGroups.clear();
00700 }
00701
00706 bool SMESHGUI_IntersectGroupsDlg::onApply()
00707 {
00708 if ( getSMESHGUI()->isActiveStudyLocked())
00709 return false;
00710
00711
00712 if ( getName() == "" )
00713 {
00714 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00715 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
00716 return false;
00717 }
00718
00719 if ( !isValid( myGroups ) )
00720 return false;
00721
00722 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
00723 QString aName = getName();
00724
00725 bool aRes = false;
00726 QStringList anEntryList;
00727 try
00728 {
00729 SMESH::ListOfGroups_var aList = convert( myGroups );
00730 SMESH::SMESH_Group_var aNewGrp =
00731 aMesh->IntersectListOfGroups( aList, aName.toLatin1().constData() );
00732 if ( !CORBA::is_nil( aNewGrp ) )
00733 {
00734 aNewGrp->SetColor( getColor() );
00735 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
00736 anEntryList.append( aSObject->GetID().c_str() );
00737 aRes = true;
00738 }
00739 }
00740 catch( ... )
00741 {
00742 aRes = false;
00743 }
00744
00745 if ( aRes )
00746 {
00747 SMESHGUI::Modified();
00748 getSMESHGUI()->updateObjBrowser(true);
00749 reset();
00750 if( LightApp_Application* anApp =
00751 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
00752 anApp->browseObjects( anEntryList, isApplyAndClose() );
00753 return true;
00754 }
00755 else
00756 {
00757 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
00758 tr("SMESH_OPERATION_FAILED"));
00759 return false;
00760 }
00761 }
00762
00766 void SMESHGUI_IntersectGroupsDlg::onSelectionDone()
00767 {
00768 QStringList aNames;
00769 getSelectedGroups( myGroups, aNames );
00770 myListWg->clear();
00771 myListWg->addItems( aNames );
00772 }
00773
00774
00775
00780 SMESHGUI_CutGroupsDlg::SMESHGUI_CutGroupsDlg( SMESHGUI* theModule )
00781 : SMESHGUI_GroupOpDlg( theModule )
00782 {
00783 setWindowTitle(tr("CUT_OF_GROUPS"));
00784 setHelpFileName( "using_operations_on_groups_page.html#cut_anchor" );
00785
00786 QGroupBox* anArgGrp = getArgGrp();
00787
00788 QPixmap aPix (SMESH::GetResourceMgr( getSMESHGUI() )->loadPixmap("SMESH", tr("ICON_SELECT")));
00789
00790
00791 QFrame* aFrame1 = new QFrame( anArgGrp );
00792 QLabel* aLbl1 = new QLabel( tr("MAIN_OBJECT"), aFrame1 );
00793 aLbl1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00794 myBtn1 = new QPushButton( aFrame1 );
00795 myBtn1->setIcon(aPix);
00796 myListWg1 = new QListWidget( aFrame1 );
00797
00798 QGridLayout* aLay1 = new QGridLayout( aFrame1 );
00799 aLay1->setSpacing( SPACING );
00800 aLay1->addWidget( aLbl1, 0, 0 );
00801 aLay1->addWidget( myBtn1, 0, 1 );
00802 aLay1->addWidget( myListWg1, 1, 0, 1, 2 );
00803
00804
00805
00806
00807
00808 QFrame* aFrame2 = new QFrame( anArgGrp );
00809 QLabel* aLbl2 = new QLabel( tr("TOOL_OBJECT"), aFrame2 );
00810 aLbl2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00811 myBtn2 = new QPushButton( aFrame2 );
00812 myBtn2->setIcon(aPix);
00813 myListWg2 = new QListWidget( aFrame2 );
00814
00815 QGridLayout* aLay2 = new QGridLayout( aFrame2 );
00816 aLay2->setSpacing( SPACING );
00817 aLay2->addWidget( aLbl2, 0, 0 );
00818 aLay2->addWidget( myBtn2, 0, 1 );
00819 aLay2->addWidget( myListWg2, 1, 0, 1, 2 );
00820
00821
00822
00823
00824
00825 QButtonGroup* aGrp = new QButtonGroup( anArgGrp );
00826 aGrp->addButton( myBtn1, 0 );
00827 aGrp->addButton( myBtn2, 1 );
00828 myBtn1->setCheckable( true );
00829 myBtn2->setCheckable( true );
00830 aGrp->setExclusive( true );
00831 myBtn1->setChecked( true );
00832
00833
00834 QHBoxLayout* aLay = new QHBoxLayout( anArgGrp );
00835 aLay->setSpacing( SPACING );
00836 aLay->addWidget( aFrame1 );
00837 aLay->addWidget( aFrame2 );
00838 }
00839
00843 SMESHGUI_CutGroupsDlg::~SMESHGUI_CutGroupsDlg()
00844 {
00845 }
00846
00851 void SMESHGUI_CutGroupsDlg::reset()
00852 {
00853 SMESHGUI_GroupOpDlg::reset();
00854
00855 myListWg1->clear();
00856 myGroups1.clear();
00857
00858 myListWg2->clear();
00859 myGroups2.clear();
00860 }
00861
00866 bool SMESHGUI_CutGroupsDlg::onApply()
00867 {
00868 if ( getSMESHGUI()->isActiveStudyLocked())
00869 return false;
00870
00871
00872 if ( getName() == "" )
00873 {
00874 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
00875 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
00876 return false;
00877 }
00878
00879 if ( myGroups1.isEmpty() || myGroups2.isEmpty() )
00880 {
00881 SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
00882 SMESHGUI_GroupOpDlg::tr("INCORRECT_ARGUMENTS") );
00883 return false;
00884 }
00885
00886 QList<SMESH::SMESH_GroupBase_var> aGroups = myGroups1;
00887 QList<SMESH::SMESH_GroupBase_var>::iterator anIter;
00888 for ( anIter = myGroups2.begin(); anIter != myGroups2.end(); ++anIter )
00889 aGroups.append( *anIter );
00890
00891 if ( !isValid( aGroups ) )
00892 return false;
00893
00894 SMESH::SMESH_Mesh_var aMesh = myGroups1.first()->GetMesh();
00895 QString aName = getName();
00896
00897 bool aRes = false;
00898 QStringList anEntryList;
00899 try
00900 {
00901 SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
00902 SMESH::ListOfGroups_var aList2 = convert( myGroups2 );
00903 SMESH::SMESH_Group_var aNewGrp =
00904 aMesh->CutListOfGroups( aList1, aList2, aName.toLatin1().constData() );
00905 if ( !CORBA::is_nil( aNewGrp ) )
00906 {
00907 aNewGrp->SetColor( getColor() );
00908 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
00909 anEntryList.append( aSObject->GetID().c_str() );
00910 aRes = true;
00911 }
00912 }
00913 catch( ... )
00914 {
00915 aRes = false;
00916 }
00917
00918 if ( aRes )
00919 {
00920 SMESHGUI::Modified();
00921 getSMESHGUI()->updateObjBrowser(true);
00922 reset();
00923 if( LightApp_Application* anApp =
00924 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
00925 anApp->browseObjects( anEntryList, isApplyAndClose() );
00926 return true;
00927 }
00928 else
00929 {
00930 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
00931 tr("SMESH_OPERATION_FAILED"));
00932 return false;
00933 }
00934 }
00935
00939 void SMESHGUI_CutGroupsDlg::onSelectionDone()
00940 {
00941 QStringList aNames;
00942 if ( myBtn2->isChecked() )
00943 {
00944 getSelectedGroups( myGroups2, aNames );
00945 myListWg2->clear();
00946 myListWg2->addItems( aNames );
00947 }
00948 else
00949 {
00950 getSelectedGroups( myGroups1, aNames );
00951 myListWg1->clear();
00952 myListWg1->addItems( aNames );
00953 }
00954 }
00955
00956
00957
00962 SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
00963 : SMESHGUI_GroupOpDlg( theModule )
00964 {
00965 setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
00966 setHelpFileName( "creating_groups_page.html#gui_create_dim_group" );
00967
00968 QGroupBox* anArgGrp = getArgGrp();
00969
00970 QLabel* aLbl = new QLabel( tr( "ELEMENTS_TYPE" ), anArgGrp );
00971
00972 myCombo = new QComboBox( anArgGrp );
00973 static QStringList anItems;
00974 if ( anItems.isEmpty() )
00975 {
00976 anItems.append( tr( "NODE" ) );
00977 anItems.append( tr( "EDGE" ) );
00978 anItems.append( tr( "FACE" ) );
00979 anItems.append( tr( "VOLUME" ) );
00980 }
00981 myCombo->addItems( anItems );
00982 myCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00983
00984 myListWg = new QListWidget( anArgGrp );
00985
00986
00987 QGridLayout* aLay = new QGridLayout( anArgGrp );
00988 aLay->setSpacing( SPACING );
00989 aLay->addWidget( aLbl, 0, 0 );
00990 aLay->addWidget( myCombo, 0, 1 );
00991 aLay->addWidget( myListWg, 1, 0, 1, 2 );
00992 }
00993
00997 SMESHGUI_DimGroupDlg::~SMESHGUI_DimGroupDlg()
00998 {
00999 }
01000
01005 void SMESHGUI_DimGroupDlg::reset()
01006 {
01007 SMESHGUI_GroupOpDlg::reset();
01008 myListWg->clear();
01009 myGroups.clear();
01010 }
01011
01017 SMESH::ElementType SMESHGUI_DimGroupDlg::getElementType() const
01018 {
01019 return (SMESH::ElementType)( myCombo->currentIndex() + 1 );
01020 }
01021
01027 void SMESHGUI_DimGroupDlg::setElementType( const SMESH::ElementType& theElemType )
01028 {
01029 myCombo->setCurrentIndex( theElemType - 1 );
01030 }
01031
01036 bool SMESHGUI_DimGroupDlg::onApply()
01037 {
01038 if ( getSMESHGUI()->isActiveStudyLocked())
01039 return false;
01040
01041
01042 if ( getName() == "" )
01043 {
01044 SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
01045 SMESHGUI_GroupOpDlg::tr("EMPTY_NAME"));
01046 return false;
01047 }
01048
01049 if ( !isValid( myGroups ) )
01050 return false;
01051
01052 SMESH::SMESH_Mesh_var aMesh = myGroups.first()->GetMesh();
01053 QString aName = getName();
01054
01055 bool aRes = false;
01056 QStringList anEntryList;
01057 try
01058 {
01059 SMESH::ListOfGroups_var aList = convert( myGroups );
01060 SMESH::ElementType anElemType = getElementType();
01061 SMESH::SMESH_Group_var aNewGrp =
01062 aMesh->CreateDimGroup( aList, anElemType, aName.toLatin1().constData() );
01063 if ( !CORBA::is_nil( aNewGrp ) )
01064 {
01065 aNewGrp->SetColor( getColor() );
01066 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
01067 anEntryList.append( aSObject->GetID().c_str() );
01068 aRes = true;
01069 }
01070 }
01071 catch( ... )
01072 {
01073 aRes = false;
01074 }
01075
01076 if ( aRes )
01077 {
01078 SMESHGUI::Modified();
01079 getSMESHGUI()->updateObjBrowser(true);
01080 reset();
01081 if( LightApp_Application* anApp =
01082 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
01083 anApp->browseObjects( anEntryList, isApplyAndClose() );
01084 return true;
01085 }
01086 else
01087 {
01088 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
01089 tr("SMESH_OPERATION_FAILED"));
01090 return false;
01091 }
01092 }
01093
01097 void SMESHGUI_DimGroupDlg::onSelectionDone()
01098 {
01099 QStringList aNames;
01100 getSelectedGroups( myGroups, aNames );
01101 myListWg->clear();
01102 myListWg->addItems( aNames );
01103 }
01104
01105