Back to index

salome-geom  6.5.0
RepairGUI_SewingDlg.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_SewingDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 //
00027 #include "RepairGUI_SewingDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 #include <SalomeApp_DoubleSpinBox.h>
00033 
00034 #include <SalomeApp_Application.h>
00035 #include <LightApp_SelectionMgr.h>
00036 #include <SUIT_Session.h>
00037 #include <SUIT_MessageBox.h>
00038 #include <SUIT_ResourceMgr.h>
00039 
00040 #include <GEOMImpl_Types.hxx>
00041 
00042 #include <TopAbs.hxx>
00043 #include <TColStd_MapOfInteger.hxx>
00044 
00045 #define DEFAULT_TOLERANCE_VALUE 1e-07
00046 
00047 //=================================================================================
00048 // class    : RepairGUI_SewingDlg()
00049 // purpose  : Constructs a RepairGUI_SewingDlg  which is a child of 'parent', with the
00050 //            name 'name' and widget flags set to 'f'.
00051 //            The dialog will by default be modeless, unless you set 'modal' to
00052 //            TRUE to construct a modal dialog.
00053 //=================================================================================
00054 RepairGUI_SewingDlg::RepairGUI_SewingDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00055                                           bool modal )
00056   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
00057 {
00058   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_SEWING" ) ) );
00059   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00060 
00061   setWindowTitle( tr( "GEOM_SEWING_TITLE" ) );
00062 
00063   /***************************************************************/
00064   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SEWING_TITLE" ) );
00065   mainFrame()->RadioButton1->setIcon( image0 );
00066   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
00067   mainFrame()->RadioButton2->close();
00068   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
00069   mainFrame()->RadioButton3->close();
00070 
00071   GroupPoints = new DlgRef_1SelExt( centralWidget() );
00072   GroupPoints->GroupBox1->setTitle( tr( "GEOM_SEWING" ) );
00073   GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
00074   GroupPoints->PushButton1->setIcon( image1 );
00075   GroupPoints->LineEdit1->setReadOnly( true );
00076 
00077   QGridLayout* aLay = new QGridLayout( GroupPoints->Box );
00078   aLay->setMargin( 0 ); aLay->setSpacing( 6 );
00079   myTolEdt = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
00080   initSpinBox( myTolEdt, 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, "len_tol_precision" );
00081   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
00082   QLabel* aLbl1 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
00083   myFreeBoundBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GEOM_FREE_BOUNDARIES" ) ), 
00084                                     GroupPoints->Box );
00085   aLay->addWidget( aLbl1,          0, 0 );
00086   aLay->addWidget( myTolEdt,       0, 1 );
00087   aLay->addWidget( myFreeBoundBtn, 1, 0, 1, 2 );
00088 
00089   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
00090   layout->setMargin( 0 ); layout->setSpacing( 6 );
00091   layout->addWidget( GroupPoints );
00092   /***************************************************************/
00093 
00094   setHelpFileName( "sewing_operation_page.html" );
00095 
00096   Init();
00097 }
00098 
00099 
00100 //=================================================================================
00101 // function : ~RepairGUI_SewingDlg()
00102 // purpose  : Destroys the object and frees any allocated resources
00103 //=================================================================================
00104 RepairGUI_SewingDlg::~RepairGUI_SewingDlg()
00105 {
00106 }
00107 
00108 
00109 //=================================================================================
00110 // function : Init()
00111 // purpose  :
00112 //=================================================================================
00113 void RepairGUI_SewingDlg::Init()
00114 {
00115   /* init variables */
00116   myEditCurrentArgument = GroupPoints->LineEdit1;
00117 
00118   myObject = GEOM::GEOM_Object::_nil();
00119 
00120   //myGeomGUI->SetState( 0 );
00121   initSelection();
00122 
00123   myClosed = -1;
00124   myOpen = -1;
00125         
00126   /* signals and slots connections */
00127   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
00128   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
00129 
00130   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
00131   connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
00132 
00133   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00134            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00135 
00136   connect( myFreeBoundBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
00137 
00138   initName( tr( "SEWING_NEW_OBJ_NAME" ) );
00139   resize(100,100);
00140   SelectionIntoArgument();
00141 }
00142 
00143 
00144 //=================================================================================
00145 // function : ClickOnOk()
00146 // purpose  : Same than click on apply but close this dialog.
00147 //=================================================================================
00148 void RepairGUI_SewingDlg::ClickOnOk()
00149 {
00150   setIsApplyAndClose( true );
00151   if ( ClickOnApply() )
00152     ClickOnCancel();
00153 }
00154 
00155 //=================================================================================
00156 // function : ClickOnApply()
00157 // purpose  :
00158 //=================================================================================
00159 bool RepairGUI_SewingDlg::ClickOnApply()
00160 {
00161   if ( !onAccept() )
00162         return false;
00163 
00164   initName();
00165 
00166   GroupPoints->LineEdit1->setText( "" );
00167   myObject = GEOM::GEOM_Object::_nil();
00168 
00169   initSelection();
00170 
00171   return true;
00172 }
00173 
00174 
00175 //=================================================================================
00176 // function : SelectionIntoArgument()
00177 // purpose  : Called when selection
00178 //=================================================================================
00179 void RepairGUI_SewingDlg::SelectionIntoArgument()
00180 {
00181   erasePreview();
00182   myEditCurrentArgument->setText( "" );
00183   myObject = GEOM::GEOM_Object::_nil();
00184 
00185   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00186   SALOME_ListIO aSelList;
00187   aSelMgr->selectedObjects(aSelList);
00188 
00189   if ( aSelList.Extent() == 1 ) {
00190     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
00191     myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
00192     if ( !CORBA::is_nil( myObject ) )
00193       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
00194   }
00195 }
00196 
00197 //=================================================================================
00198 // function : SetEditCurrentArgument()
00199 // purpose  :
00200 //=================================================================================
00201 void RepairGUI_SewingDlg::SetEditCurrentArgument()
00202 {
00203   const QObject* send = sender();
00204   if ( send == GroupPoints->PushButton1 ) {
00205     myEditCurrentArgument->setFocus();
00206     SelectionIntoArgument();
00207   }
00208 }
00209 
00210 
00211 //=================================================================================
00212 // function : LineEditReturnPressed()
00213 // purpose  :
00214 //=================================================================================
00215 void RepairGUI_SewingDlg::LineEditReturnPressed()
00216 {
00217   const QObject* send = sender();
00218   if( send == GroupPoints->LineEdit1 ) {
00219     myEditCurrentArgument = GroupPoints->LineEdit1;
00220     GEOMBase_Skeleton::LineEditReturnPressed();
00221   }
00222 }
00223 
00224 
00225 //=================================================================================
00226 // function : ActivateThisDialog()
00227 // purpose  :
00228 //=================================================================================
00229 void RepairGUI_SewingDlg::ActivateThisDialog()
00230 {
00231   GEOMBase_Skeleton::ActivateThisDialog();
00232   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
00233            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
00234 
00235   GroupPoints->LineEdit1->setText( "" );
00236   myObject = GEOM::GEOM_Object::_nil();
00237 
00238   myClosed = -1;
00239   myOpen = -1;
00240 
00241   //myGeomGUI->SetState( 0 );
00242   initSelection();
00243 }
00244 
00245 
00246 //=================================================================================
00247 // function : enterEvent()
00248 // purpose  : Mouse enter onto the dialog to activate it
00249 //=================================================================================
00250 void RepairGUI_SewingDlg::enterEvent( QEvent* )
00251 {
00252   if ( !mainFrame()->GroupConstructors->isEnabled() )
00253     ActivateThisDialog();
00254 }
00255 
00256 
00257 //=================================================================================
00258 // function : createOperation
00259 // purpose  :
00260 //=================================================================================
00261 GEOM::GEOM_IOperations_ptr RepairGUI_SewingDlg::createOperation()
00262 {
00263   return getGeomEngine()->GetIHealingOperations( getStudyId() );
00264 }
00265 
00266 //=================================================================================
00267 // function : isValid
00268 // purpose  :
00269 //=================================================================================
00270 bool RepairGUI_SewingDlg::isValid( QString& msg )
00271 {
00272   myClosed = -1;
00273   bool ok = myTolEdt->isValid( msg, !IsPreview() );
00274   return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. ) && ok;
00275 }
00276 
00277 //=================================================================================
00278 // function : execute
00279 // purpose  :
00280 //=================================================================================
00281 bool RepairGUI_SewingDlg::execute( ObjectList& objects )
00282 {
00283   bool aResult = false;
00284   GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
00285 
00286   if ( IsPreview() ) { // called from onDetect(): detect free boundary edges, highlight them (add to objects), display message dialog
00287     GEOM::ListOfGO_var aClosed, anOpen;
00288 
00289     aResult = anOper->GetFreeBoundary( myObject, aClosed, anOpen );
00290 
00291     if ( aResult ) {
00292       myClosed = aClosed->length();
00293       myOpen = anOpen->length();
00294       int i;
00295       for ( i = 0; i < myClosed; i++ )
00296         objects.push_back( aClosed[i]._retn() );
00297       for ( i = 0; i < myOpen; i++ )
00298         objects.push_back( anOpen[i]._retn() );
00299     }
00300     else
00301       myClosed = -1;
00302   }
00303   else {
00304     GEOM::GEOM_Object_var anObj = anOper->Sew( myObject, myTolEdt->value() );
00305     aResult = !anObj->_is_nil();
00306     if ( aResult )
00307     {
00308       if ( !IsPreview() )
00309       {
00310         QStringList aParameters;
00311         aParameters << myTolEdt->text();
00312         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00313       }
00314       objects.push_back( anObj._retn() );
00315     }
00316   }
00317 
00318   return aResult;
00319 }
00320 
00321 //=================================================================================
00322 // function : initSelection
00323 // purpose  :
00324 //=================================================================================
00325 void RepairGUI_SewingDlg::initSelection()
00326 {
00327   TColStd_MapOfInteger aTypes;
00328   aTypes.Add( GEOM_SHELL );
00329   aTypes.Add( GEOM_SOLID );
00330   aTypes.Add( GEOM_COMPOUND );
00331   globalSelection( aTypes );
00332 }
00333 
00334 //=================================================================================
00335 // function : onDetect
00336 // purpose  :
00337 //=================================================================================
00338 void RepairGUI_SewingDlg::onDetect()
00339 {
00340   displayPreview( true, false, true, true, 3 );
00341 
00342   // field myClosed,myOpen is initialized in execute() method, called by displayPreview().
00343   QString msg;
00344   if ( myClosed != -1 )
00345     msg = tr( "GEOM_FREE_BOUNDS_MSG" ).arg( myClosed + myOpen ).arg( myClosed ).arg( myOpen );
00346   else
00347     msg = tr( "GEOM_FREE_BOUNDS_ERROR" );
00348   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg );
00349 }