Back to index

salome-geom  6.5.0
RepairGUI_FreeBoundDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : RepairGUI_FreeBoundDlg.cxx
00025 // Author : Sergey LITONIN, Open CASCADE S.A.S. (sergey.litonin@opencascade.com)
00026 //
00027 #include "RepairGUI_FreeBoundDlg.h"
00028 
00029 #include <GEOMBase.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOM_Displayer.h>
00032 #include <GEOMImpl_Types.hxx>
00033 
00034 #include <SalomeApp_Application.h>
00035 #include <LightApp_Application.h>
00036 #include <LightApp_SelectionMgr.h>
00037 #include <SUIT_MessageBox.h>
00038 #include <SUIT_Desktop.h>
00039 #include <SUIT_Session.h>
00040 #include <SUIT_ResourceMgr.h>
00041 
00042 #include <TColStd_MapOfInteger.hxx>
00043 
00044 #include <QLineEdit>
00045 #include <QLabel>
00046 #include <QHBoxLayout>
00047 #include <QVBoxLayout>
00048 #include <QGridLayout>
00049 #include <QGroupBox>
00050 #include <QPushButton>
00051 #include <QKeyEvent>
00052 
00053 #define SPACING 6
00054 #define MARGIN  9
00055 
00061 //=================================================================================
00062 // function : RepairGUI_FreeBoundDlg
00063 // purpose  : Constructor
00064 //=================================================================================
00065 RepairGUI_FreeBoundDlg::RepairGUI_FreeBoundDlg( GeometryGUI* theGUI, QWidget* theParent )
00066   : QDialog( theParent, 0 ),
00067     GEOMBase_Helper( dynamic_cast<SUIT_Desktop*>( theParent ) ),
00068     myGeomGUI( theGUI )
00069 {
00070   setAttribute( Qt::WA_DeleteOnClose );
00071 
00072   setWindowTitle( tr( "CAPTION" ) );
00073 
00074   QPixmap iconSelect( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00075   
00076   QGroupBox* aMainGrp = new QGroupBox( tr( "FREE_BOUND" ), this );
00077   
00078   QLabel* lab = new QLabel( tr( "GEOM_OBJECT" ), aMainGrp );
00079   QPushButton* btn = new QPushButton( aMainGrp );
00080   btn->setIcon( iconSelect );
00081   myEdit = new QLineEdit( aMainGrp );
00082   myEdit->setReadOnly( true );
00083   myEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00084 
00085   myClosedLbl = new QLabel( tr( "NUMBER_CLOSED" ), aMainGrp );
00086   myOpenLbl   = new QLabel( tr( "NUMBER_OPEN" ),   aMainGrp );
00087   myClosedLbl->setMinimumWidth( 150 );
00088   myOpenLbl->setMinimumWidth( 150 );
00089   
00090   QGridLayout* aMainGrpLayout = new QGridLayout( aMainGrp );
00091   aMainGrpLayout->setMargin( MARGIN ); aMainGrpLayout->setSpacing( SPACING );
00092   aMainGrpLayout->addWidget( lab,    0, 0 );
00093   aMainGrpLayout->addWidget( btn,    0, 1 );
00094   aMainGrpLayout->addWidget( myEdit, 0, 2 );
00095   aMainGrpLayout->addWidget( myClosedLbl, 1, 0, 1, 3 );
00096   aMainGrpLayout->addWidget( myOpenLbl,   2, 0, 1, 3 );
00097 
00098   QFrame* aFrame = new QFrame( this );
00099   aFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
00100   QPushButton* aCloseBtn = new QPushButton( tr( "GEOM_BUT_CLOSE" ), aFrame );
00101   QPushButton* aHelpBtn = new QPushButton( tr( "GEOM_BUT_HELP" ), aFrame );
00102   QHBoxLayout* aBtnLay = new QHBoxLayout( aFrame );
00103   aBtnLay->setMargin( MARGIN ); aBtnLay->setSpacing( SPACING );
00104   aBtnLay->addWidget( aCloseBtn );
00105   aBtnLay->addSpacing( SPACING ); aBtnLay->addStretch();
00106   aBtnLay->addWidget( aHelpBtn );
00107 
00108   QVBoxLayout* aLay = new QVBoxLayout( this );
00109   aLay->setSpacing( SPACING );
00110   aLay->setMargin( MARGIN );
00111   aLay->addWidget( aMainGrp );
00112   aLay->addWidget( aFrame );
00113 
00114   myHelpFileName = "using_measurement_tools_page.html#boundaries_anchor";
00115 
00116   connect( aCloseBtn, SIGNAL( clicked() ), SLOT( onClose() ) );
00117   connect( aHelpBtn,  SIGNAL( clicked() ), SLOT( onHelp() ) );
00118 
00119   Init();
00120 }
00121 
00122 //=================================================================================
00123 // function : ~RepairGUI_FreeBoundDlg
00124 // purpose  : Destructor
00125 //=================================================================================
00126 RepairGUI_FreeBoundDlg::~RepairGUI_FreeBoundDlg()
00127 {
00128 }
00129 
00130 //=================================================================================
00131 // function : onClose
00132 // purpose  : SLOT. Called when "close" button pressed. Close dialog
00133 //=================================================================================
00134 void RepairGUI_FreeBoundDlg::onClose()
00135 {
00136   globalSelection();
00137   disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
00138   myGeomGUI->SetActiveDialogBox( 0 );
00139   reject();
00140   erasePreview();
00141 }
00142 
00143 //=================================================================================
00144 // function : onHelp()
00145 // purpose  :
00146 //=================================================================================
00147 void RepairGUI_FreeBoundDlg::onHelp()
00148 {
00149   LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
00150   if ( app )
00151     app->onHelpContextModule( myGeomGUI ? app->moduleName( myGeomGUI->moduleName() ) : QString(""), myHelpFileName );
00152   else {
00153     QString platform;
00154 #ifdef WIN32
00155     platform = "winapplication";
00156 #else
00157     platform = "application";
00158 #endif
00159     SUIT_MessageBox::warning( this, 
00160                               tr( "WRN_WARNING" ), 
00161                               tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
00162                               arg( app->resourceMgr()->stringValue( "ExternalBrowser", 
00163                                                                     platform ) ).arg( myHelpFileName ) );
00164   }
00165 }
00166 
00167 //=================================================================================
00168 // function : onDeactivate
00169 // purpose  : Deactivate this dialog
00170 //=================================================================================
00171 void RepairGUI_FreeBoundDlg::onDeactivate()
00172 {
00173   setEnabled( false );
00174   globalSelection();
00175   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
00176   myGeomGUI->SetActiveDialogBox( 0 );
00177 }
00178 
00179 //=================================================================================
00180 // function : onActivate
00181 // purpose  : Activate this dialog
00182 //=================================================================================
00183 void RepairGUI_FreeBoundDlg::onActivate()
00184 {
00185   myGeomGUI->EmitSignalDeactivateDialog();
00186   setEnabled( true );
00187   myGeomGUI->SetActiveDialogBox( this );
00188   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
00189            SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
00190   activateSelection();
00191   onSelectionDone();
00192 }
00193 
00194 //=================================================================================
00195 // function : onSelectionDone
00196 // purpose  : SLOT. Called when selection changed.
00197 //=================================================================================
00198 void RepairGUI_FreeBoundDlg::onSelectionDone()
00199 {
00200   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00201   SALOME_ListIO aSelList;
00202   aSelMgr->selectedObjects(aSelList);
00203 
00204   if ( aSelList.Extent() != 1 )
00205     return;
00206 
00207   GEOM::GEOM_Object_var anObj =
00208     GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
00209 
00210   if ( !GEOMBase::IsShape( anObj ) )
00211     return;
00212   else {
00213     myObj = anObj;
00214     displayPreview( true, false, true, true, 3 );
00215   }
00216 }
00217 
00218 //=================================================================================
00219 // function : Init
00220 // purpose  : Initialize dialog fields
00221 //=================================================================================
00222 void RepairGUI_FreeBoundDlg::Init()
00223 {
00224   myNbClosed = myNbOpen = 0;
00225   myObj = GEOM::GEOM_Object::_nil();
00226 
00227   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT  ( onDeactivate() ) );
00228   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
00229            SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
00230 
00231   activateSelection();
00232   onSelectionDone();
00233 }
00234 
00235 //=================================================================================
00236 // function : enterEvent
00237 // purpose  : Activate dialog
00238 //=================================================================================
00239 void RepairGUI_FreeBoundDlg::enterEvent( QEvent* )
00240 {
00241   onActivate();
00242 }
00243 
00244 //=================================================================================
00245 // function : closeEvent
00246 // purpose  : Close dialog
00247 //=================================================================================
00248 void RepairGUI_FreeBoundDlg::closeEvent( QCloseEvent* )
00249 {
00250   onClose();
00251 }
00252 
00253 //=================================================================================
00254 // function : activateSelection
00255 // purpose  : activate selection of faces, shells, and solids
00256 //=================================================================================
00257 void RepairGUI_FreeBoundDlg::activateSelection()
00258 {
00259   TColStd_MapOfInteger aMap;
00260   aMap.Add( GEOM_FACE );
00261   aMap.Add( GEOM_SHELL );
00262   aMap.Add( GEOM_SOLID );
00263   aMap.Add( GEOM_COMPOUND );
00264   globalSelection( aMap );
00265 }
00266 
00267 //=================================================================================
00268 // function : createOperation
00269 // purpose  : Create operation
00270 //=================================================================================
00271 GEOM::GEOM_IOperations_ptr RepairGUI_FreeBoundDlg::createOperation()
00272 {
00273   return getGeomEngine()->GetIHealingOperations( getStudyId() );
00274 }
00275 
00276 //=================================================================================
00277 // function : isValid
00278 // purpose  :
00279 //=================================================================================
00280 bool RepairGUI_FreeBoundDlg::isValid( QString& )
00281 {
00282   return !myObj->_is_nil();
00283 }
00284 
00285 //=================================================================================
00286 // function : execute
00287 // purpose  : Get free boundaries
00288 //=================================================================================
00289 bool RepairGUI_FreeBoundDlg::execute( ObjectList& objects )
00290 {
00291   if ( !IsPreview() || myObj->_is_nil() )
00292     return false;
00293 
00294   GEOM::ListOfGO_var aClosed, anOpen;
00295 
00296   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
00297   bool result = anOper->GetFreeBoundary( myObj, aClosed, anOpen );
00298 
00299   if ( result ) {
00300     myNbClosed = aClosed->length();
00301     myNbOpen = anOpen->length();
00302     int i;
00303     for ( i = 0; i < myNbClosed; i++ )
00304       objects.push_back( aClosed[i]._retn() );
00305     for ( i = 0; i < myNbOpen; i++ )
00306       objects.push_back( anOpen[i]._retn() );
00307 
00308     myEdit->setText( GEOMBase::GetName( myObj ) );
00309     QString aLabelText = tr( "NUMBER_CLOSED" ) + QString( "%1" ).arg( myNbClosed );
00310     myClosedLbl->setText( aLabelText );
00311     aLabelText = tr( "NUMBER_OPEN" ) + QString( "%1" ).arg( myNbOpen );
00312     myOpenLbl->setText( aLabelText );
00313   }
00314   else {
00315     myEdit->setText( GEOMBase::GetName( myObj ) );
00316     myClosedLbl->setText( tr( "NUMBER_CLOSED" ) );
00317     myOpenLbl->setText( tr( "NUMBER_OPEN" ) );
00318   }
00319 
00320   return result;
00321 }
00322 
00323 //=================================================================================
00324 // function : keyPressEvent()
00325 // purpose  :
00326 //=================================================================================
00327 void RepairGUI_FreeBoundDlg::keyPressEvent( QKeyEvent* e )
00328 {
00329   QDialog::keyPressEvent( e );
00330   if ( e->isAccepted() )
00331     return;
00332 
00333   if ( e->key() == Qt::Key_F1 ) {
00334     e->accept();
00335     onHelp();
00336   }
00337 }