Back to index

salome-geom  6.5.0
RepairGUI_ShapeProcessDlg.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_ShapeProcessDlg.cxx
00025 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
00026 
00027 #include "RepairGUI_ShapeProcessDlg.h"
00028 
00029 #include <DlgRef.h>
00030 #include <GeometryGUI.h>
00031 #include <GEOMBase.h>
00032 #include <GEOMImpl_Types.hxx>
00033 
00034 #include <SalomeApp_Application.h>
00035 #include <SalomeApp_DoubleSpinBox.h>
00036 #include <SalomeApp_IntSpinBox.h>
00037 #include <LightApp_SelectionMgr.h>
00038 #include <SUIT_Session.h>
00039 #include <SUIT_ResourceMgr.h>
00040 #include <SUIT_MessageBox.h>
00041 #include <SALOME_ListIteratorOfListIO.hxx>
00042 #include <SALOME_ListIO.hxx>
00043 
00044 #include <Basics_Utils.hxx>
00045 
00046 #include <TCollection_AsciiString.hxx>
00047 #include <TColStd_MapOfInteger.hxx>
00048 
00049 #include <QListWidget>
00050 #include <QStackedLayout>
00051 
00052 //=================================================================================
00053 // class    : RepairGUI_ShapeProcessDlg()
00054 // purpose  : Constructs a RepairGUI_ShapeProcessDlg  which is a child of 'parent', with the
00055 //            name 'name' and widget flags set to 'f'.
00056 //            The dialog will by default be modeless, unless you set 'modal' to
00057 //            TRUE to construct a modal dialog.
00058 //=================================================================================
00059 RepairGUI_ShapeProcessDlg::RepairGUI_ShapeProcessDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
00060                                                       bool modal )
00061   : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
00062 {
00063   setHelpFileName( "shape_processing_operation_page.html" );
00064   init();
00065 }
00066 
00067 //=================================================================================
00068 // function : ~RepairGUI_ShapeProcessDlg()
00069 // purpose  : Destroys the object and frees any allocated resources
00070 //=================================================================================
00071 RepairGUI_ShapeProcessDlg::~RepairGUI_ShapeProcessDlg()
00072 {
00073 }
00074 
00075 //=================================================================================
00076 // function : Init()
00077 // purpose  :
00078 //=================================================================================
00079 void RepairGUI_ShapeProcessDlg::init()
00080 {
00081   //myGeomGUI->SetState( 0 );
00082 
00083   initParamsValues();
00084   initSelection();
00085         
00086   setWindowTitle( tr( "GEOM_SHAPEPROCESS_TITLE" ) );
00087 
00088   mainFrame()->GroupConstructors->hide();
00089   
00090   // select widget on the top 
00091   mySelectWdgt = new DlgRef_1Sel( centralWidget() );
00092   mySelectWdgt->GroupBox1->setTitle( tr( "GEOM_SHAPE" ) );
00093   mySelectWdgt->TextLabel1->setText( tr( "GEOM_SELECTED_OBJECTS" ) );
00094   mySelectWdgt->PushButton1->setIcon( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
00095   mySelectWdgt->LineEdit1->setReadOnly( true );
00096 
00097   // layout the two group boxes in the middle, add a list of operations
00098   QGroupBox* anOperGr = new QGroupBox( tr( "GEOM_OPERATIONS" ), centralWidget() );
00099 
00100   // operations list widget
00101   myOpList = new QListWidget( anOperGr );
00102   myOpList->setSortingEnabled( false );
00103   myOpList->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) );
00104 
00105   QVBoxLayout* aOperLay = new QVBoxLayout( anOperGr );
00106   aOperLay->setMargin( 9 );
00107   aOperLay->addWidget( myOpList );
00108 
00109   QGroupBox* aParamsGr = new QGroupBox( tr( "GEOM_PARAMETERS" ), centralWidget() );
00110 
00111   // add a widget stack to the parameters group box
00112   QStackedLayout* aStack = new QStackedLayout( aParamsGr );
00113 
00114   // continueties values..
00115   QStringList aContinueties = QString( "C0,G1,C1,G2,C2,C3,CN" ).split( "," );
00116 
00117   // fill in the widgets
00118   for ( int i = 0; i < myOpLst.count(); i++ ) {
00119     QListWidgetItem* item = new QListWidgetItem( myOpLst[i] );
00120     item->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
00121     item->setCheckState( Qt::Unchecked );
00122     myOpList->addItem( item );
00123 
00124     QWidget* w;
00125     if ( myOpLst[i] == "FixShape" ) {
00126       // FixShape
00127       w = new QWidget( aParamsGr );
00128       QGridLayout* aLay = new QGridLayout( w );
00129       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00130       
00131       myFixShapeTol3D = new SalomeApp_DoubleSpinBox( w );
00132       initSpinBox( myFixShapeTol3D, 0., 100., 1e-7, "len_tol_precision" );
00133       myFixShapeMaxTol3D = new SalomeApp_DoubleSpinBox( w );
00134       initSpinBox( myFixShapeMaxTol3D, 0., 100., 1e-7, "len_tol_precision" );      
00135       
00136       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
00137       aLay->addWidget( myFixShapeTol3D, 0, 1 );
00138       aLay->addWidget( new QLabel( tr( "GEOM_MAX_3D_TOLERANCE" ), w ), 1, 0 );
00139       aLay->addWidget( myFixShapeMaxTol3D, 1, 1 );
00140       aLay->setRowStretch( aLay->rowCount(), 5 );
00141     }
00142     else if ( myOpLst[i] == "FixFaceSize" ) {
00143       // FixFaceSize  
00144       w = new QWidget( aParamsGr );
00145       QGridLayout* aLay = new QGridLayout( w );
00146       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00147       
00148       myFixFaceSizeTol = new SalomeApp_DoubleSpinBox( w );
00149       initSpinBox( myFixFaceSizeTol, 0., 100., 1e-7, "len_tol_precision" );      
00150       
00151       aLay->addWidget( new QLabel( tr( "GEOM_TOLERANCE" ), w ), 0, 0 );
00152       aLay->addWidget( myFixFaceSizeTol, 0, 1 );
00153       aLay->setRowStretch( aLay->rowCount(), 5 );
00154     }
00155     else if ( myOpLst[i] == "DropSmallEdges" ) {
00156       // DropSmallEdges
00157       w = new QWidget( aParamsGr );
00158       QGridLayout* aLay = new QGridLayout( w );
00159       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00160       
00161       myDropSmallEdgesTol3D = new SalomeApp_DoubleSpinBox( w );
00162       initSpinBox( myDropSmallEdgesTol3D, 0., 100., 1e-7, "len_tol_precision" );
00163   
00164       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
00165       aLay->addWidget( myDropSmallEdgesTol3D, 0, 1 );
00166       aLay->setRowStretch( aLay->rowCount(), 5 );
00167     }
00168     else if ( myOpLst[i] == "SplitAngle" ) {
00169       // SplitAngle
00170       w = new QWidget( aParamsGr );
00171       QGridLayout* aLay = new QGridLayout( w );
00172       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00173       
00174       mySplitAngleAngle = new SalomeApp_DoubleSpinBox( w );
00175       initSpinBox( mySplitAngleAngle, 0, 360, 1, "angle_precision" );      
00176       mySplitAngleMaxTol = new SalomeApp_DoubleSpinBox( w );
00177       initSpinBox( mySplitAngleMaxTol, 0., 100., 1e-7, "ang_tol_precision" );      
00178       
00179       aLay->addWidget( new QLabel( tr( "GEOM_ANGLE_1" ), w ), 0, 0 );
00180       aLay->addWidget( mySplitAngleAngle, 0, 1 );
00181       aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 1, 0 );
00182       aLay->addWidget( mySplitAngleMaxTol, 1, 1 );
00183       aLay->setRowStretch( aLay->rowCount(), 5 );
00184     }
00185     else if ( myOpLst[i] == "SplitClosedFaces" ) {
00186       // SplitClosedFaces
00187       w = new QWidget( aParamsGr );
00188       QGridLayout* aLay = new QGridLayout( w );
00189       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00190       
00191       mySplitClosedFacesNum = new SalomeApp_IntSpinBox( w );
00192   
00193       aLay->addWidget( new QLabel( tr( "GEOM_NUM_SPLIT_POINTS" ), w ), 0, 0 );
00194       aLay->addWidget( mySplitClosedFacesNum, 0, 1 );
00195       aLay->setRowStretch( aLay->rowCount(), 5 );
00196     }      
00197     else if ( myOpLst[i] == "SplitContinuity" ) {
00198       // SplitContinuity
00199       w = new QWidget( aParamsGr );
00200       QGridLayout* aLay = new QGridLayout( w );
00201       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00202 
00203       mySplitContTol3D = new SalomeApp_DoubleSpinBox( w );
00204       initSpinBox( mySplitContTol3D, 0., 100., 1e-7, "len_tol_precision" );
00205       mySplitContSurfCont = new QComboBox( w );
00206       mySplitContSurfCont->addItems( aContinueties );
00207       mySplitContCurvCont = new QComboBox( w );
00208       mySplitContCurvCont->addItems( aContinueties );
00209       
00210       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
00211       aLay->addWidget( mySplitContTol3D, 0, 1 );
00212       aLay->addWidget( new QLabel( tr( "GEOM_SURFACE_CONTINUTY" ), w ), 1, 0 );
00213       aLay->addWidget( mySplitContSurfCont, 1, 1 );
00214       aLay->addWidget( new QLabel( tr( "GEOM_CURVE_CONTINUTY" ), w ), 2, 0 );
00215       aLay->addWidget( mySplitContCurvCont, 2, 1 );
00216       aLay->setRowStretch( aLay->rowCount(), 5 );
00217     }
00218     else if ( myOpLst[i] == "BSplineRestriction" ) {
00219       // BSplineRestriction
00220       w = new QWidget( aParamsGr );
00221       QGridLayout* aLay = new QGridLayout( w );
00222       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00223 
00224       myBSplineSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
00225       myBSpline3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
00226       myBSpline2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
00227 
00228       myBSplineTol3D = new SalomeApp_DoubleSpinBox( w );
00229       initSpinBox( myBSplineTol3D, 0., 100., 1e-7, "len_tol_precision" );
00230       
00231       myBSplineTol2D = new SalomeApp_DoubleSpinBox( w );
00232       initSpinBox( myBSplineTol2D, 0., 100., 1e-7, "param_tol_precision" );      
00233 
00234       myBSplineDegree = new SalomeApp_IntSpinBox( w );
00235       myBSplineSegments = new SalomeApp_IntSpinBox( w );
00236       myBSpline2DCont = new QComboBox( w );
00237       myBSpline2DCont->addItems( aContinueties );
00238       myBSpline3DCont = new QComboBox( w );
00239       myBSpline3DCont->addItems( aContinueties );
00240       
00241       myBSplineSurfModeChk->setChecked( true );
00242       myBSpline3DCurveChk->setChecked( true );
00243       myBSpline2DCurveChk->setChecked( true );
00244 
00245       aLay->addWidget( myBSplineSurfModeChk, 0, 0 );
00246       aLay->addWidget( myBSpline3DCurveChk,  1, 0 );
00247       aLay->addWidget( myBSpline2DCurveChk,  2, 0 );
00248       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 3, 0 );
00249       aLay->addWidget( myBSplineTol3D, 3, 1 );
00250       aLay->addWidget( new QLabel( tr( "GEOM_2D_TOLERANCE" ), w ), 4, 0 );
00251       aLay->addWidget( myBSplineTol2D, 4, 1 );
00252       aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_DEGREE" ), w ), 5, 0 );
00253       aLay->addWidget( myBSplineDegree, 5, 1 );
00254       aLay->addWidget( new QLabel( tr( "GEOM_REQUIRED_NUM_SEGMENTS" ), w ), 6, 0 );
00255       aLay->addWidget( myBSplineSegments, 6, 1 );
00256       aLay->addWidget( new QLabel( tr( "GEOM_3D_CONTINUTY" ), w ), 7, 0 );
00257       aLay->addWidget( myBSpline3DCont, 7, 1 );
00258       aLay->addWidget( new QLabel( tr( "GEOM_2D_CONTINUTY" ), w ), 8, 0 );
00259       aLay->addWidget( myBSpline2DCont, 8, 1 );
00260       aLay->setRowStretch( aLay->rowCount(), 5 );
00261     }
00262     else if ( myOpLst[i] == "ToBezier" ) {
00263       // ToBezier
00264       w = new QWidget( aParamsGr );
00265       QGridLayout* aLay = new QGridLayout( w );
00266       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00267 
00268       myToBezierSurfModeChk = new QCheckBox( tr("GEOM_SURFACE_MODE"), w );
00269       myToBezier3DCurveChk = new QCheckBox( tr("GEOM_3D_CURVE_MODE"), w );
00270       myToBezier2DCurveChk = new QCheckBox( tr("GEOM_2D_CURVE_MODE"), w );
00271   
00272       myToBezierMaxTol = new SalomeApp_DoubleSpinBox( w );
00273       initSpinBox( myToBezierMaxTol, 0., 100., 1e-7, "len_tol_precision" );            
00274 
00275       aLay->addWidget( myToBezierSurfModeChk, 0, 0 );
00276       aLay->addWidget( myToBezier3DCurveChk, 1, 0 );
00277       aLay->addWidget( myToBezier2DCurveChk, 2, 0 );
00278       aLay->addWidget( new QLabel( tr( "GEOM_MAX_TOLERANCE" ), w ), 3, 0 );
00279       aLay->addWidget( myToBezierMaxTol, 3, 1 );
00280       aLay->setRowStretch( aLay->rowCount(), 5 );
00281     }
00282     else if ( myOpLst[i] == "SameParameter" ) {
00283       // SameParameter
00284       w = new QWidget( aParamsGr );
00285       QGridLayout* aLay = new QGridLayout( w );
00286       aLay->setMargin( 9 ); aLay->setSpacing( 6 );
00287 
00288       mySameParameterTol3D = new SalomeApp_DoubleSpinBox( w );
00289       initSpinBox( mySameParameterTol3D, 0., 100., 1e-7, "len_tol_precision" );            
00290       
00291       aLay->addWidget( new QLabel( tr( "GEOM_3D_TOLERANCE" ), w ), 0, 0 );
00292       aLay->addWidget( mySameParameterTol3D, 0, 1 );
00293       aLay->setRowStretch( aLay->rowCount(), 5 );
00294     }
00295     else {
00296       w = new QWidget( aParamsGr ); // dumb widget
00297     }
00298     aStack->insertWidget( i, w );
00299   }
00300 
00301   QGridLayout* layout = new QGridLayout( centralWidget() );
00302   layout->setMargin( 0 ); layout->setSpacing( 6 );
00303   layout->addWidget( mySelectWdgt, 0, 0, 1, 2 );
00304   layout->addWidget( anOperGr,     1, 0 );
00305   layout->addWidget( aParamsGr,    1, 1 );
00306 
00307   // signals and slots connections
00308   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( onOk() ) );
00309   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( onApply() ) );
00310 
00311   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
00312            SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
00313 
00314   connect( mySelectWdgt->PushButton1, SIGNAL( clicked() ),       this, SLOT( selectClicked() ) );
00315   connect( mySelectWdgt->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( lineEditReturnPressed() ) );
00316 
00317   connect( myToBezierSurfModeChk,     SIGNAL( toggled( bool ) ), this, SLOT( advOptionToggled( bool ) ) );
00318 
00319   connect( myOpList, SIGNAL( currentRowChanged( int ) ), aStack, SLOT( setCurrentIndex( int ) ) );
00320 
00321   adjustSize();
00322   loadDefaults(); // init dialog fields with values from resource file
00323   //myOpList->setCurrentRow( myOpList->findItem( 0 );
00324   reset();
00325 
00326   initName( tr( "PROCESS_SHAPE_NEW_OBJ_NAME" ) );
00327   selectionChanged();
00328 }
00329 
00330 //=================================================================================
00331 // function : onOk()
00332 // purpose  : Same than click on apply but close this dialog.
00333 //=================================================================================
00334 void RepairGUI_ShapeProcessDlg::onOk()
00335 {
00336   setIsApplyAndClose( true );
00337   if ( onApply() )
00338     ClickOnCancel();
00339 }
00340 
00341 //=================================================================================
00342 // function : onApply()
00343 // purpose  :
00344 //=================================================================================
00345 bool RepairGUI_ShapeProcessDlg::onApply()
00346 {
00347   if ( !onAccept() )
00348     return false;
00349 
00350   initName();
00351 
00352   reset();
00353   initSelection();
00354   
00355   return true;
00356 }
00357 
00358 
00359 //=================================================================================
00360 // function : selectionChanged()
00361 // purpose  : Called when selection as changed or other case
00362 //          : used only by SelectButtonC1A1 (LineEditC1A1)
00363 //=================================================================================
00364 void RepairGUI_ShapeProcessDlg::selectionChanged()
00365 {
00366   reset();
00367         
00368   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
00369   SALOME_ListIO aSelList;
00370   aSelMgr->selectedObjects(aSelList);
00371 
00372   int i = 0;
00373   myObjects->length(aSelList.Extent());
00374   for (SALOME_ListIteratorOfListIO anIt (aSelList); anIt.More(); anIt.Next()) {
00375     GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIt.Value() );
00376     if ( !CORBA::is_nil( aSelectedObject ) )
00377       myObjects[i++] = aSelectedObject;
00378   }
00379   myObjects->length( i );
00380   if ( i == 1 )
00381     mySelectWdgt->LineEdit1->setText( GEOMBase::GetName( myObjects[0] ) );
00382   else if ( i > 0 )
00383     mySelectWdgt->LineEdit1->setText( QString::number( i ) + "_" + tr( "GEOM_OBJECTS" ) );
00384 }
00385 
00386 
00387 //=================================================================================
00388 // function : selectClicked()
00389 // purpose  :
00390 //=================================================================================
00391 void RepairGUI_ShapeProcessDlg::selectClicked()
00392 {
00393   myEditCurrentArgument = mySelectWdgt->LineEdit1;
00394   mySelectWdgt->LineEdit1->setFocus();
00395   selectionChanged();
00396 }
00397 
00398 
00399 //=================================================================================
00400 // function : lineEditReturnPressed()
00401 // purpose  :
00402 //=================================================================================
00403 void RepairGUI_ShapeProcessDlg::lineEditReturnPressed()
00404 {
00405   GEOMBase_Skeleton::LineEditReturnPressed();
00406 }
00407 
00408 
00409 //=================================================================================
00410 // function : activate()
00411 // purpose  :
00412 //=================================================================================
00413 void RepairGUI_ShapeProcessDlg::activate()
00414 {
00415   GEOMBase_Skeleton::ActivateThisDialog();
00416   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication( ) ))->selectionMgr(),
00417            SIGNAL( currentSelectionChanged() ), this, SLOT( selectionChanged() ) );
00418         
00419   reset();
00420   //myGeomGUI->SetState( 0 );
00421   initSelection();
00422 }
00423 
00424 
00425 //=================================================================================
00426 // function : enterEvent()
00427 // purpose  : Mouse enter onto the dialog to activate it
00428 //=================================================================================
00429 void RepairGUI_ShapeProcessDlg::enterEvent( QEvent* )
00430 {
00431   if ( !mainFrame()->GroupBoxName->isEnabled() )
00432     activate();
00433 }
00434 
00435 
00436 //=================================================================================
00437 // function : reset()
00438 // purpose  : Completely reset the state of method including local context
00439 //=================================================================================
00440 void RepairGUI_ShapeProcessDlg::reset()
00441 {
00442   myObjects = new GEOM::ListOfGO();
00443   myObjects->length( 0 );       
00444   mySelectWdgt->LineEdit1->setText( "" );
00445 }
00446 
00447 
00448 //=================================================================================
00449 // function : get_convert
00450 // purpose  : conversion of angle values to radians (non-angle values are not converted)
00451 //=================================================================================
00452 const char* get_convert( const char* theParam, const QString& theValue )
00453 {
00454   if ( !strcmp( theParam, "SplitAngle.Angle" ) ) {
00455     double doubleValue = theValue.toDouble() * M_PI / 180.;
00456     return CORBA::string_dup( QString::number( doubleValue ).toLatin1().constData() );
00457   }
00458   return CORBA::string_dup( theValue.toLatin1().constData() );
00459 }
00460 
00461 //=================================================================================
00462 // function : set_convert
00463 // purpose  : conversion of angle values to degrees (non-angle values are not converted)
00464 //=================================================================================
00465 QString set_convert( const char* theParam, const char* theValue )
00466 {
00467   if ( !strcmp( theParam, "SplitAngle.Angle" ) ) {
00468     Kernel_Utils::Localizer loc;
00469     double doubleValue = atof( theValue ) * 180. / M_PI;
00470     return QString::number( doubleValue );
00471   }
00472   return QString( theValue );
00473 }
00474 
00475 //=================================================================================
00476 // function : loadDefaults()
00477 // purpose  : initialize "values"-fields with default values retrieved from IHealingOperations
00478 //=================================================================================
00479 void RepairGUI_ShapeProcessDlg::loadDefaults()
00480 {
00481   GEOM::GEOM_IHealingOperations_var anOp = myGeomGUI->GetGeomGen()->GetIHealingOperations( getStudyId() );
00482   GEOM::string_array_var anOperators, aParams, aValues;
00483   anOp->GetShapeProcessParameters( anOperators, aParams, aValues );
00484 
00485   // check the default items-operators
00486   for ( int i = 0; i < anOperators->length(); i++ ) {
00487     //MESSAGE("-->"<<(const char*)anOperators[i]);
00488     QList<QListWidgetItem*> items = myOpList->findItems ( (const char*)anOperators[i], Qt::MatchFixedString );
00489     if ( items.count() ) 
00490       ( items[0] )->setCheckState( Qt::Checked );
00491   }
00492 
00493   // Retrieve default parameters for ALL operators
00494   for ( int i = 0; i < myOpList->count(); i++ ) {
00495     CORBA::String_var anOperator = CORBA::string_dup( myOpList->item( i )->text().toLatin1().constData() );
00496     anOp->GetOperatorParameters( anOperator.in(), aParams, aValues );
00497 
00498     // set default values of parameters
00499     if ( aParams->length() != aValues->length() )
00500       continue;
00501 
00502     for ( int j = 0; j < aParams->length(); j++ ) {
00503       QWidget* aCtrl = getControl( (const char*)aParams[j] );
00504       setValue( aCtrl, set_convert( (const char*)aParams[j], aValues[j] ) );
00505     }
00506   }
00507 }
00508 
00509 //=================================================================================
00510 // function : setValue()
00511 // purpose  : set value in the proper way
00512 //=================================================================================
00513 void RepairGUI_ShapeProcessDlg::setValue( QWidget* theControl, const QString& theValue )
00514 {
00515   if ( theControl && !theValue.isNull() ) {
00516     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ) )
00517       qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->setValue( theValue.toDouble() );
00518     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ) )
00519       qobject_cast<SalomeApp_IntSpinBox*>( theControl )->setValue( theValue.toInt() );
00520     else if ( qobject_cast<QComboBox*>( theControl ) )
00521       qobject_cast<QComboBox*>( theControl )->setEditText( theValue );
00522     else if ( qobject_cast<QCheckBox*>( theControl ) )
00523       qobject_cast<QCheckBox*>( theControl )->setChecked( theValue.toInt() != 0 );
00524   }
00525 }
00526 
00527 //=================================================================================
00528 // function : getValue()
00529 // purpose  : get value in the proper way
00530 //=================================================================================
00531 QString RepairGUI_ShapeProcessDlg::getValue( QWidget* theControl ) const
00532 {
00533   if ( theControl ) {
00534     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ) )
00535       return QString::number( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->value() );
00536     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ) )
00537       return QString::number( qobject_cast<SalomeApp_IntSpinBox*>( theControl )->value() );
00538     else if ( qobject_cast<QComboBox*>( theControl ) )
00539       return qobject_cast<QComboBox*>( theControl )->currentText();
00540     else if ( qobject_cast<QCheckBox*>( theControl ) )
00541       return qobject_cast<QCheckBox*>( theControl )->isChecked() ? "1" : "0";
00542   }   
00543   return 0;
00544 }
00545 
00546 //=================================================================================
00547 // function : getText()
00548 // purpose  : get text in the proper way
00549 //=================================================================================
00550 QString RepairGUI_ShapeProcessDlg::getText( QWidget* theControl ) const
00551 {
00552   if ( theControl ) {
00553     if ( qobject_cast<SalomeApp_DoubleSpinBox*>( theControl ) )
00554       return qobject_cast<SalomeApp_DoubleSpinBox*>( theControl )->text();
00555     else if ( qobject_cast<SalomeApp_IntSpinBox*>( theControl ) )
00556       return qobject_cast<SalomeApp_IntSpinBox*>( theControl )->text();
00557   }   
00558   return QString::null;
00559 }
00560 
00561 //=================================================================================
00562 // function : createOperation
00563 // purpose  :
00564 //=================================================================================
00565 GEOM::GEOM_IOperations_ptr RepairGUI_ShapeProcessDlg::createOperation()
00566 {
00567   return getGeomEngine()->GetIHealingOperations( getStudyId() );
00568 }
00569 
00570 //=================================================================================
00571 // function : isValid
00572 // purpose  :
00573 //=================================================================================
00574 bool RepairGUI_ShapeProcessDlg::isValid( QString& msg )
00575 {
00576   bool ok = true;
00577   QMapIterator<QString,QStringList> aMapIter( myValMap );
00578   while( aMapIter.hasNext() ) {
00579     aMapIter.next();
00580     const QStringList& aList = aMapIter.value();
00581     QListIterator<QString> aListIter( aList );
00582     while( aListIter.hasNext() ) {
00583       const QString& aParam = aListIter.next();
00584       QWidget* aControl = getControl( aParam );
00585       if ( qobject_cast<SalomeApp_DoubleSpinBox*>( aControl ) )
00586         ok = qobject_cast<SalomeApp_DoubleSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
00587       else if ( qobject_cast<SalomeApp_IntSpinBox*>( aControl ) )
00588         ok = qobject_cast<SalomeApp_IntSpinBox*>( aControl )->isValid( msg, !IsPreview() ) && ok;
00589     }
00590   }
00591 
00592   bool error = false;
00593   GEOM::string_array_var anOperators = getActiveOperators();
00594   if ( !myObjects->length() ) {
00595     msg += tr( "ERROR_NO_OBJECTS" );
00596     error = true;
00597   }
00598   if ( !anOperators->length() ) {
00599     if ( error ) 
00600       msg += "\n";
00601     msg += tr( "ERROR_NO_OPERATORS" );
00602     error = true;
00603   }
00604   return !error && ok;
00605 }
00606 
00607 //=================================================================================
00608 // function : execute
00609 // purpose  :
00610 //=================================================================================
00611 bool RepairGUI_ShapeProcessDlg::execute( ObjectList& objects )
00612 {
00613   GEOM::string_array_var anOperators = getActiveOperators();
00614   GEOM::string_array_var aParams = getParameters( anOperators );
00615   GEOM::string_array_var aValues = getValues( aParams );
00616 
00617   /*//-- check --
00618   int z;
00619         MESSAGE("Objects : ");
00620         for ( z = 0; z < myObjects->length(); z++ )
00621                 MESSAGE(myObjects[z]->GetName() << " ");
00622         MESSAGE("\nOperators : ");
00623         for ( z = 0; z < anOperators->length(); z++ )
00624                 MESSAGE(anOperators[z] << " ");
00625         MESSAGE("\nParameters : ");
00626         for ( z = 0; z < aParams->length(); z++ )
00627                 MESSAGE(aParams[z] << " ");
00628         MESSAGE("\nValues : ");
00629         for ( z = 0; z < aValues->length(); z ++ )
00630                 MESSAGE(aValues[z] << " ");
00631         MESSAGE("\n");
00632   */// -----------
00633 
00634   QStringList anErrorObjNames;
00635   for ( int i = 0; i < myObjects->length(); i++ ) {
00636     GEOM::GEOM_Object_var obj = myObjects[i];
00637     GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
00638     GEOM::GEOM_Object_var anObj = anOper->ProcessShape( obj, anOperators, aParams, aValues );
00639     if ( anObj->_is_nil() )
00640       anErrorObjNames << GEOMBase::GetName( obj );
00641     else
00642     {
00643       if ( !IsPreview() )
00644       {
00645         QStringList aParameters;
00646 
00647         for ( int i = 0; i < anOperators->length(); i++ )
00648           aParameters << QString( anOperators[i] );
00649 
00650         for ( int i = 0; i < aParams->length(); i++ )
00651           aParameters << QString( aParams[i] );
00652 
00653         aParameters << getTexts( aParams );
00654         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
00655       }
00656       objects.push_back( anObj._retn() );
00657     }
00658   }
00659 
00660   if ( !anErrorObjNames.empty() )
00661     MESSAGE( "ERRORS occured while processing the following objects: " << anErrorObjNames.join( " " ).toLatin1().data() );
00662     
00663   return anErrorObjNames.size() < myObjects->length(); // true if at least one object was OK, false if ALL objects were nil after Healing.
00664 }
00665 
00666 //=================================================================================
00667 // function : getActiveOperators
00668 // purpose  :
00669 //=================================================================================
00670 GEOM::string_array* RepairGUI_ShapeProcessDlg::getActiveOperators()
00671 {
00672   GEOM::string_array_var anOperators = new GEOM::string_array();
00673   QStringList aCheckedList;
00674 
00675   for ( int i = 0; i < myOpList->count(); i++ ) {
00676     if ( myOpList->item( i )->checkState() == Qt::Checked )
00677       aCheckedList << myOpList->item( i )->text();
00678   }
00679 
00680   anOperators->length( aCheckedList.count() );
00681 
00682   for ( int i = 0; i < aCheckedList.count(); i++ )
00683     anOperators[i] = CORBA::string_dup( aCheckedList[i].toLatin1().constData() );
00684                  
00685   return anOperators._retn();
00686 }
00687 
00688 //=================================================================================
00689 // function : getcontrol
00690 // purpose  :
00691 //=================================================================================
00692 QWidget* RepairGUI_ShapeProcessDlg::getControl( const QString& theParam )
00693 {
00694   if ( theParam == "SplitAngle.Angle" )                           return mySplitAngleAngle;
00695   else if ( theParam == "SplitAngle.MaxTolerance" )               return mySplitAngleMaxTol;
00696   else if ( theParam == "SplitClosedFaces.NbSplitPoints" )        return mySplitClosedFacesNum;
00697   else if ( theParam == "FixFaceSize.Tolerance" )                 return myFixFaceSizeTol;
00698   else if ( theParam == "DropSmallEdges.Tolerance3d" )            return myDropSmallEdgesTol3D;
00699   else if ( theParam == "BSplineRestriction.SurfaceMode" )        return myBSplineSurfModeChk;
00700   else if ( theParam == "BSplineRestriction.Curve3dMode" )        return myBSpline3DCurveChk;
00701   else if ( theParam == "BSplineRestriction.Curve2dMode" )        return myBSpline2DCurveChk;
00702   else if ( theParam == "BSplineRestriction.Tolerance3d" )        return myBSplineTol3D;
00703   else if ( theParam == "BSplineRestriction.Tolerance2d" )        return myBSplineTol2D;
00704   else if ( theParam == "BSplineRestriction.RequiredDegree" )     return myBSplineDegree;
00705   else if ( theParam == "BSplineRestriction.RequiredNbSegments" ) return myBSplineSegments;
00706   else if ( theParam == "BSplineRestriction.Continuity3d" )       return myBSpline3DCont;
00707   else if ( theParam == "BSplineRestriction.Continuity2d" )       return myBSpline2DCont;
00708   else if ( theParam == "SplitContinuity.Tolerance3d" )           return mySplitContTol3D;
00709   else if ( theParam == "SplitContinuity.SurfaceContinuity" )     return mySplitContSurfCont;
00710   else if ( theParam == "SplitContinuity.CurveContinuity" )       return mySplitContCurvCont;
00711   else if ( theParam == "ToBezier.SurfaceMode" )                  return myToBezierSurfModeChk;
00712   else if ( theParam == "ToBezier.Curve3dMode" )                  return myToBezier3DCurveChk;
00713   else if ( theParam == "ToBezier.Curve2dMode" )                  return myToBezier2DCurveChk;
00714   else if ( theParam == "ToBezier.MaxTolerance" )                 return myToBezierMaxTol;
00715   else if ( theParam == "SameParameter.Tolerance3d" )             return mySameParameterTol3D;
00716   else if ( theParam == "FixShape.Tolerance3d" )                  return myFixShapeTol3D;
00717   else if ( theParam == "FixShape.MaxTolerance3d" )               return myFixShapeMaxTol3D;
00718   return 0;
00719 }
00720 
00721 //=================================================================================
00722 // function : getParameters
00723 // purpose  :
00724 //=================================================================================
00725 void RepairGUI_ShapeProcessDlg::initParamsValues()
00726 {
00727   if ( myOpLst.count() )
00728     return;  // already filled
00729 
00730   myOpLst << "FixShape";
00731   myValMap["FixShape"] << "FixShape.Tolerance3d";
00732   myValMap["FixShape"] << "FixShape.MaxTolerance3d";
00733 
00734   myOpLst << "FixFaceSize";
00735   myValMap["FixFaceSize"] << "FixFaceSize.Tolerance";
00736 
00737   myOpLst << "DropSmallEdges";
00738   myValMap["DropSmallEdges"] << "DropSmallEdges.Tolerance3d";
00739 
00740   myOpLst << "SplitAngle";
00741   myValMap["SplitAngle"] << "SplitAngle.Angle";
00742   myValMap["SplitAngle"] << "SplitAngle.MaxTolerance";
00743 
00744   myOpLst << "SplitClosedFaces";
00745   myValMap["SplitClosedFaces"] << "SplitClosedFaces.NbSplitPoints";
00746 
00747   myOpLst << "SplitContinuity";
00748   myValMap["SplitContinuity"] << "SplitContinuity.Tolerance3d";
00749   myValMap["SplitContinuity"] << "SplitContinuity.SurfaceContinuity";
00750   myValMap["SplitContinuity"] << "SplitContinuity.CurveContinuity";
00751 
00752   myOpLst << "BSplineRestriction";
00753   myValMap["BSplineRestriction"] << "BSplineRestriction.SurfaceMode";
00754   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve3dMode";
00755   myValMap["BSplineRestriction"] << "BSplineRestriction.Curve2dMode";
00756   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance3d";
00757   myValMap["BSplineRestriction"] << "BSplineRestriction.Tolerance2d";
00758   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredDegree";
00759   myValMap["BSplineRestriction"] << "BSplineRestriction.RequiredNbSegments";
00760   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity3d";
00761   myValMap["BSplineRestriction"] << "BSplineRestriction.Continuity2d";
00762 
00763   myOpLst << "ToBezier";
00764   myValMap["ToBezier"] << "ToBezier.SurfaceMode";
00765   myValMap["ToBezier"] << "ToBezier.Curve3dMode";
00766   myValMap["ToBezier"] << "ToBezier.Curve2dMode";
00767   myValMap["ToBezier"] << "ToBezier.MaxTolerance";
00768 
00769   myOpLst << "SameParameter";
00770   myValMap["SameParameter"] << "SameParameter.Tolerance3d";
00771 }
00772 
00773 //=================================================================================
00774 // function : getParameters
00775 // purpose  :
00776 //=================================================================================
00777 GEOM::string_array* RepairGUI_ShapeProcessDlg::getParameters( const GEOM::string_array& theOperators )
00778 {
00779   GEOM::string_array_var aParams = new GEOM::string_array();
00780   int i = 0, j = 0;
00781 
00782   // calculate the length of parameters
00783   for ( i = 0, j = 0; i < theOperators.length(); i++ )
00784     j += myValMap[ QString( theOperators[i] ) ].size();
00785   
00786   // set the new length of paremeters
00787   aParams->length( j );
00788 
00789   // fill the parameters
00790   for ( i = 0, j = 0; i < theOperators.length(); i++ ) {
00791     QStringList aValLst = myValMap[ QString( theOperators[i] ) ];
00792     for ( QStringList::Iterator it = aValLst.begin(); it != aValLst.end(); ++it )
00793       aParams[j++] = CORBA::string_dup( (*it).toLatin1().constData() );
00794   }
00795 
00796   return aParams._retn();
00797 }
00798 
00799 
00800 //=================================================================================
00801 // function : getValues
00802 // purpose  :
00803 //=================================================================================
00804 GEOM::string_array* RepairGUI_ShapeProcessDlg::getValues( const GEOM::string_array& theParams )
00805 {
00806   GEOM::string_array_var aValues = new GEOM::string_array();
00807   aValues->length( theParams.length() );
00808     
00809   for ( int i = 0; i < theParams.length(); i++ ) {
00810     QWidget* aCtrl = getControl( (const char*)theParams[i] );
00811     if ( aCtrl )
00812       aValues[i] = get_convert( (const char*)theParams[i], getValue( aCtrl ) );
00813   }
00814     
00815   return aValues._retn();
00816 }
00817 
00818 //=================================================================================
00819 // function : getTexts
00820 // purpose  :
00821 //=================================================================================
00822 QStringList RepairGUI_ShapeProcessDlg::getTexts( const GEOM::string_array& theParams )
00823 {
00824   QStringList aTexts;
00825     
00826   for ( int i = 0; i < theParams.length(); i++ ) {
00827     QWidget* aCtrl = getControl( (const char*)theParams[i] );
00828     if ( aCtrl )
00829     {
00830       QString aText = getText( aCtrl );
00831       if( !aText.isNull() )
00832         aTexts.append( aText );
00833     }
00834   }
00835     
00836   return aTexts;
00837 }
00838 
00839 //=================================================================================
00840 // function : initSelection
00841 // purpose  : set selection of ALL shape types except vertexes
00842 //=================================================================================
00843 void RepairGUI_ShapeProcessDlg::initSelection()
00844 {
00845   TColStd_MapOfInteger aTypes;
00846   aTypes.Add( GEOM_COMPOUND );
00847   aTypes.Add( GEOM_SOLID );
00848   aTypes.Add( GEOM_SHELL );
00849   aTypes.Add( GEOM_FACE );
00850   aTypes.Add( GEOM_WIRE );
00851   aTypes.Add( GEOM_EDGE );
00852   globalSelection( aTypes );
00853 }
00854 
00855 //=================================================================================
00856 // function : advOptionToggled
00857 // purpose  : this slot is used to warn the user about possible consequences
00858 //            of enabling some advanced options
00859 //=================================================================================
00860 void RepairGUI_ShapeProcessDlg::advOptionToggled( bool on )
00861 {
00862   QAbstractButton* btn = (QAbstractButton*)sender();
00863   if ( on && btn->isCheckable() &&
00864        SUIT_MessageBox::warning( this,
00865                                  tr( "GEOM_WRN_WARNING" ), tr( "TIME_CONSUMING" ),
00866                                  SUIT_MessageBox::Yes | SUIT_MessageBox::No ) == SUIT_MessageBox::No )
00867     btn->toggle();
00868 }