Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / RepairGUI / RepairGUI_GlueDlg.cxx
index d723e1e80329e4154dc5183aecfc535f49586b11..a9d20a4ac4246f9436fbf9a6923978bdd2428201 100644 (file)
@@ -1,6 +1,6 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 //  This library is free software; you can redistribute it and/or
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+// GEOM RepairGUI : GUI for Geometry component
+// File   : RepairGUI_GlueDlg.cxx
+// Author : Lucien PIGNOLONI, Open CASCADE S.A.S. 
 //
-//
-//  File   : RepairGUI_GlueDlg.cxx
-//  Author : Lucien PIGNOLONI
-//  Module : GEOM
-//  $Header$
-
-#include "OCCViewer_ViewModel.h"
-
 #include "RepairGUI_GlueDlg.h"
-#include "DlgRef_1Sel_Ext.h"
-#include "GEOMImpl_Types.hxx"
-
-#include "QtxDblSpinBox.h"
-#include "SalomeApp_Application.h"
-#include "LightApp_SelectionMgr.h"
-#include "SalomeApp_Study.h"
-#include "SalomeApp_Tools.h"
 
-#include "SUIT_Session.h"
-#include "SUIT_MessageBox.h"
-#include "SUIT_OverrideCursor.h"
-
-#include "SALOME_ListIteratorOfListIO.hxx"
+#include <DlgRef.h>
+#include <GeometryGUI.h>
+#include <GEOMBase.h>
+#include <QtxDoubleSpinBox.h>
+
+#include <SalomeApp_Application.h>
+#include <SalomeApp_Notebook.h>
+#include <LightApp_SelectionMgr.h>
+#include <SalomeApp_Study.h>
+#include <SalomeApp_Tools.h>
+#include <SUIT_Session.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_OverrideCursor.h>
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_ViewManager.h>
+#include <OCCViewer_ViewModel.h>
+#include <SALOME_ListIteratorOfListIO.hxx>
+
+#include <GEOMImpl_Types.hxx>
 
 #include <TCollection_AsciiString.hxx>
 
-#include <qapplication.h>
-#include <qlabel.h>
-#include <qcheckbox.h>
-#include <qhbox.h>
-#include <qgrid.h>
-
-using namespace std;
-
 #define DEFAULT_TOLERANCE_VALUE 1e-07
 
 //=================================================================================
@@ -63,75 +58,75 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-RepairGUI_GlueDlg::RepairGUI_GlueDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
-                                     const char* name, bool modal, WFlags fl)
-: GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
-                    WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-  myCurrConstrId( -1 )
+RepairGUI_GlueDlg::RepairGUI_GlueDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
+                                      bool modal )
+  : GEOMBase_Skeleton( theGeometryGUI, parent, modal ),
+    myCurrConstrId( -1 )
 {
-  QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES")));
-  QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_GLUE_FACES2")));
-  QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
+  QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES" ) ) );
+  QPixmap image2( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_GLUE_FACES2" )  ));
+  QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
 
-  setCaption(tr("GEOM_GLUE_TITLE"));
+  setWindowTitle( tr( "GEOM_GLUE_TITLE" ) );
 
   /***************************************************************/
-  GroupConstructors->setTitle(tr("GEOM_GLUE_TITLE"));
-  RadioButton1->setPixmap(image0);
-  RadioButton2->setPixmap(image2);
-  //RadioButton2->close(TRUE);
-  RadioButton3->close(TRUE);
-
-  GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
-  GroupPoints->GroupBox1->setTitle(tr("GEOM_GLUE"));
-  GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
-  GroupPoints->PushButton1->setPixmap(image1);
+  mainFrame()->GroupConstructors->setTitle( tr( "GEOM_GLUE_TITLE" ) );
+  mainFrame()->RadioButton1->setIcon( image0 );
+  mainFrame()->RadioButton2->setIcon( image2 );
+  mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
+  mainFrame()->RadioButton3->close();
+
+  GroupPoints = new DlgRef_1SelExt( centralWidget() );
+  GroupPoints->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
+  GroupPoints->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
+  GroupPoints->PushButton1->setIcon( image1 );
   GroupPoints->LineEdit1->setReadOnly( true );
   
-  int aWidth = GroupPoints->TextLabel1->sizeHint().width() + 
-               GroupPoints->PushButton1->sizeHint().width() + 
-               GroupPoints->getGroupBoxLayout()->spacing();
-
-  Layout1->addWidget(GroupPoints, 2, 0);
-
-  QHBox* aHBox = new QHBox( GroupPoints->GroupBox1 );
-  aHBox->setSpacing( 5 );
-  
-  (new QLabel( tr( "GEOM_TOLERANCE" ), aHBox ))->setFixedWidth( aWidth );
-  myTolEdt = new QtxDblSpinBox( 0, 100, 1e-7, aHBox );
-  myTolEdt->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
-  myTolEdt->setPrecision( 10 );
+  QLabel* aTolLab = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints->Box );
+  myTolEdt = new SalomeApp_DoubleSpinBox( 0.0, 100.0, DEFAULT_TOLERANCE_VALUE, 7, 7, GroupPoints->Box );
   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
-  GroupPoints->getGroupBoxLayout()->addWidget( aHBox, 3, 0 );
+
+  QGridLayout* boxLayout = new QGridLayout( GroupPoints->Box );
+  boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
+  boxLayout->addWidget( aTolLab,  0, 0 );
+  boxLayout->addWidget( myTolEdt, 0, 2 );
   /***************************************************************/
 
-  GroupPoints2 = new DlgRef_1Sel_Ext(this, "GroupPoints2");
-  GroupPoints2->GroupBox1->setTitle(tr("GEOM_GLUE"));
-  GroupPoints2->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
-  GroupPoints2->PushButton1->setPixmap(image1);
+  GroupPoints2 = new DlgRef_1SelExt( centralWidget() );
+  GroupPoints2->GroupBox1->setTitle( tr( "GEOM_GLUE" ) );
+  GroupPoints2->TextLabel1->setText( tr( "GEOM_SELECTED_SHAPE" ) );
+  GroupPoints2->PushButton1->setIcon( image1 );
   GroupPoints2->LineEdit1->setReadOnly( true );
-  Layout1->addWidget(GroupPoints2, 2, 0);
 
-  QGrid* aGrid = new QGrid( 2, Qt::Horizontal, GroupPoints2->GroupBox1 );
-  aGrid->setSpacing( 5 );
-  (new QLabel( tr( "GEOM_TOLERANCE" ), aGrid ))->setFixedWidth( aWidth );;
-  myTolEdt2 = new QtxDblSpinBox( 0, 100, 1e-7, aGrid );
-  myTolEdt2->setPrecision( 10 );
+  QLabel* aTolLab2 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints2->Box );
+  myTolEdt2 = new SalomeApp_DoubleSpinBox( GroupPoints2->Box );
+  initSpinBox( myTolEdt2, 0, 100, 1e-7, 7 );
   myTolEdt2->setValue( DEFAULT_TOLERANCE_VALUE );
-  myTolEdt2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
-  (new QLabel( tr( "GLUE_FACES" ), aGrid ))->setFixedWidth( aWidth );;
-  myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ), aGrid );
-  myDetectBtn->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
-  mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), aGrid );
-  GroupPoints2->getGroupBoxLayout()->addWidget( aGrid, 3, 0 );
+
+  myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GLUE_FACES" ) ), 
+                                GroupPoints2->Box );
+  mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), GroupPoints2->Box );
+
+  boxLayout = new QGridLayout( GroupPoints2->Box );
+  boxLayout->setMargin( 0 ); boxLayout->setSpacing( 6 );
+  boxLayout->addWidget( aTolLab2,    0, 0 );
+  boxLayout->addWidget( myTolEdt2,   0, 2 );
+  boxLayout->addWidget( myDetectBtn, 1, 0, 1, 3 );
+  boxLayout->addWidget( mySubShapesChk, 2, 0, 1, 3 );
+
+  QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
+  layout->setMargin( 0 ); layout->setSpacing( 6 );
+  layout->addWidget( GroupPoints );
+  layout->addWidget( GroupPoints2 );
+
   /***************************************************************/
 
-  setHelpFileName("glue_faces_operation_page.html");
+  setHelpFileName( "glue_faces_operation_page.html" );
   
   // Disable second way of gluing if OCC viewer is not active one
-  if (SUIT_Session::session()->activeApplication()->desktop()->activeWindow()->getViewManager()->getType() 
-      != OCCViewer_Viewer::Type())
-    RadioButton2->setEnabled(false);
+  if ( myGeomGUI->getApp()->desktop()->activeWindow()->getViewManager()->getType()
+       != OCCViewer_Viewer::Type() )
+    mainFrame()->RadioButton2->setEnabled( false );
 
   Init();
 }
@@ -160,27 +155,30 @@ void RepairGUI_GlueDlg::Init()
   //myGeomGUI->SetState( 0 );
   //globalSelection( GEOM_COMPOUND );
 
+  mainFrame()->GroupBoxPublish->show();
+
   /* signals and slots connections */
-  connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
-  connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
-  connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
+  connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
+  connect( buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
+
+  connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
 
-  connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-  connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+  connect( GroupPoints->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
+  connect( GroupPoints->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
 
-  connect(GroupPoints2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-  connect(GroupPoints2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+  connect( GroupPoints2->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
+  connect( GroupPoints2->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
   connect( myTolEdt2, SIGNAL( valueChanged( double ) ), this, SLOT( onTolerChanged( double ) ) );
   connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
 
-  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
-          SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) );
+  connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+          this, SLOT( SelectionIntoArgument() ) );
 
-  connect(myDetectBtn, SIGNAL(clicked()), this, SLOT(onDetect()));
+  connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
 
   initName( tr( "GLUE_NEW_OBJ_NAME" ) );
 
-  ConstructorsClicked(0);
+  ConstructorsClicked( 0 );
   
   activateSelection();
   updateButtonState();
@@ -196,58 +194,48 @@ void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
   if ( myCurrConstrId == constructorId )
     return;
   
-  disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
+  disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
   
-  switch ( constructorId )
-    {
-    case 0:
-      {
-        GroupPoints2->hide();
-        resize( 0, 0 );
-        GroupPoints->show();
-        GroupPoints->LineEdit1->setText( "" );
-        myEditCurrentArgument = GroupPoints->LineEdit1;
-        
-        if ( myCurrConstrId >= 0 ) // i.e. it is not initialisation
-        {
-          // copy tolerance from previous tolerance field
-          myTolEdt->setValue( myTolEdt2->value() );
-        }
-          
-        break;
-      }
-    case 1:
-      {
-        GroupPoints->hide();
-        resize(0, 0);
-        GroupPoints2->show();
-        GroupPoints->LineEdit1->setText("");
-        myEditCurrentArgument = GroupPoints2->LineEdit1;
-        
-        if ( myCurrConstrId >= 0 ) // i.e. it is not initialisation
-        {
-          // copy tolerance from previous tolerance field
-          myTolEdt2->setValue( myTolEdt->value() );
-          mySubShapesChk->setChecked( false );
-          clearTemporary();
-        }
+  switch ( constructorId ) {
+  case 0:
+    GroupPoints2->hide();
+    GroupPoints->show();
+    GroupPoints->LineEdit1->setText( "" );
+    myEditCurrentArgument = GroupPoints->LineEdit1;
+    
+    if ( myCurrConstrId >= 0 ) {
+      // i.e. it is not initialisation
+      // copy tolerance from previous tolerance field
+      myTolEdt->setValue( myTolEdt2->value() );
+    }
+    break;
+  case 1:
+    GroupPoints->hide();
+    GroupPoints2->show();
+    GroupPoints->LineEdit1->setText( "" );
+    myEditCurrentArgument = GroupPoints2->LineEdit1;
         
-        break;
-      }
+    if ( myCurrConstrId >= 0 ) {
+      // i.e. it is not initialisation
+      // copy tolerance from previous tolerance field
+      myTolEdt2->setValue( myTolEdt->value() );
+      mySubShapesChk->setChecked( false );
+      clearTemporary();
     }
+    break;
+  }
     
-    myCurrConstrId = constructorId;
+  myCurrConstrId = constructorId;
 
   myEditCurrentArgument->setFocus();
 
-  connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+  connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+          this, SLOT( SelectionIntoArgument() ) );
 
   qApp->processEvents();
   updateGeometry();
-  QSize aSize = minimumSizeHint();
-  resize( width(), aSize.height() );
-  
+  resize( minimumSizeHint() );
+
   displayPreview();
   updateButtonState();
   activateSelection();
@@ -300,11 +288,15 @@ void RepairGUI_GlueDlg::SelectionIntoArgument()
   }
   
   erasePreview();
-  myEditCurrentArgument->setText("");
+  myEditCurrentArgument->setText( "" );
   myObject = GEOM::GEOM_Object::_nil();
 
-  if ( IObjectCount() == 1 ) {
-    Handle(SALOME_InteractiveObject) anIO = firstIObject();
+  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+  SALOME_ListIO aSelList;
+  aSelMgr->selectedObjects(aSelList);
+
+  if ( aSelList.Extent() == 1 ) {
+    Handle(SALOME_InteractiveObject) anIO = aSelList.First();
     Standard_Boolean aRes;
     myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
     if ( aRes )
@@ -334,11 +326,11 @@ void RepairGUI_GlueDlg::SetEditCurrentArgument()
 void RepairGUI_GlueDlg::LineEditReturnPressed()
 {
   const QObject* send = sender();
-  if( send == GroupPoints->LineEdit1 ) {
+  if ( send == GroupPoints->LineEdit1 ) {
     myEditCurrentArgument = GroupPoints->LineEdit1;
     GEOMBase_Skeleton::LineEditReturnPressed();
   }
-  else if( send == GroupPoints2->LineEdit1 ) {
+  else if ( send == GroupPoints2->LineEdit1 ) {
     myEditCurrentArgument = GroupPoints2->LineEdit1;
     GEOMBase_Skeleton::LineEditReturnPressed();
   }
@@ -352,8 +344,8 @@ void RepairGUI_GlueDlg::LineEditReturnPressed()
 void RepairGUI_GlueDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
-  connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+  connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), 
+          this, SLOT( SelectionIntoArgument() ) );
 
   //GroupPoints->LineEdit1->setText("");
   //GroupPoints2->LineEdit1->setText("");
@@ -369,22 +361,12 @@ void RepairGUI_GlueDlg::ActivateThisDialog()
 // function : enterEvent()
 // purpose  : Mouse enter onto the dialog to activate it
 //=================================================================================
-void RepairGUI_GlueDlg::enterEvent(QEvent* e)
+void RepairGUI_GlueDlg::enterEvent( QEvent* )
 {
-  if ( !GroupConstructors->isEnabled() )
+  if ( !mainFrame()->GroupConstructors->isEnabled() )
     ActivateThisDialog();
 }
 
-//=================================================================================
-// function : closeEvent()
-// purpose  :
-//=================================================================================
-void RepairGUI_GlueDlg::closeEvent(QCloseEvent* e)
-{
-  //myGeomGUI->SetState( -1 );
-  GEOMBase_Skeleton::closeEvent( e );
-}
-
 
 //=================================================================================
 // function : createOperation
@@ -401,7 +383,20 @@ GEOM::GEOM_IOperations_ptr RepairGUI_GlueDlg::createOperation()
 //=================================================================================
 bool RepairGUI_GlueDlg::isValid( QString& msg )
 {
-  return !myObject->_is_nil() && ( IsPreview() || myTolEdt->value() > 0. );
+  bool ok = true;
+  double v = 0;
+  switch ( getConstructorId() )
+  {
+  case 0:
+    v = myTolEdt->value();
+    ok = myTolEdt->isValid( msg, !IsPreview() );
+    break;
+  case 1:
+    v = myTolEdt2->value(); 
+    ok = myTolEdt2->isValid( msg, !IsPreview() );
+    break;
+  }
+  return !myObject->_is_nil() && ( IsPreview() || v > 0. ) && ok;
 }
 
 //=================================================================================
@@ -413,24 +408,25 @@ bool RepairGUI_GlueDlg::execute( ObjectList& objects )
   bool aResult = false;
   objects.clear();
 
-  switch ( getConstructorId() )
-  {
+  GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
+  switch ( getConstructorId() ) {
   case 0:
     {
-      GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
-        ( getOperation() )->MakeGlueFaces( myObject, myTolEdt2->value(), true );
+      GEOM::GEOM_Object_var anObj = anOper->MakeGlueFaces( myObject, myTolEdt->value(), true );
       aResult = !anObj->_is_nil();
-      if ( aResult )
+      if ( aResult && !IsPreview() )
+      {
+        myNoteBook->setParameters(anObj, 1, myTolEdt);
         objects.push_back( anObj._retn() );
+      }
       break;
     }
   case 1:
     {
-      if ( IsPreview() )
-      {
+      if ( IsPreview() ) {
         // if this method is used for displaying preview then we must detect glue faces only
         ObjectList::iterator anIter;
-        for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter)
+        for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
           objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
         return myTmpObjs.size() ? true : false;
       } // IsPreview
@@ -440,33 +436,39 @@ bool RepairGUI_GlueDlg::execute( ObjectList& objects )
       QMap<QString, char> selected;
 
       // Get names of selected objects
-      SALOME_ListIteratorOfListIO it ( selectedIO() );
+      LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+      SALOME_ListIO aSelList;
+      aSelMgr->selectedObjects(aSelList);
+
+      SALOME_ListIteratorOfListIO it (aSelList);
       for (; it.More(); it.Next()) 
-        selected.insert( it.Value()->getName(), 0 );
+        selected.insert(it.Value()->getName(), 0);
 
       // Iterate through result and select objects with names from selection
       // ObjectList toRemoveFromEnggine;
       ObjectList toGlue;
       ObjectList::iterator anIter;
-      for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter) 
-      {
+      for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter ) {
         if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*anIter) ) )
-          toGlue.push_back(*anIter);
+          toGlue.push_back( *anIter );
       }
-
+      
       // make glue faces
       GEOM::ListOfGO_var aListForGlue = new GEOM::ListOfGO();
       aListForGlue->length( toGlue.size() );
       ObjectList::iterator anIter3 = toGlue.begin();
       for ( int i = 0; anIter3 != toGlue.end(); ++anIter3, ++i )
         aListForGlue[ i ] = *anIter3;
-      GEOM::GEOM_Object_var anObj = GEOM::GEOM_IShapesOperations::_narrow
-        ( getOperation() )->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
+      GEOM::GEOM_Object_var anObj = anOper->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
 
       aResult = !anObj->_is_nil();
 
       if ( aResult )
+      {
+       if ( !IsPreview() )
+          myNoteBook->setParameters(anObj, 1, myTolEdt2);
         objects.push_back( anObj._retn() );
+      }
 
       // Remove from engine useless objects
       clearTemporary();
@@ -480,6 +482,23 @@ bool RepairGUI_GlueDlg::execute( ObjectList& objects )
   return aResult;
 }
 
+//=================================================================================
+// function : restoreSubShapes
+// purpose  :
+//=================================================================================
+void RepairGUI_GlueDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
+                                          SALOMEDS::SObject_ptr theSObject )
+{
+  if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
+    GEOM::find_shape_method aFindMethod = GEOM::FSM_GetInPlace;
+    if ( getConstructorId() == 0 ) // MakeGlueFaces
+      aFindMethod = GEOM::FSM_GetInPlaceByHistory;
+
+    // empty list of arguments means that all arguments should be restored
+    getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
+                                        aFindMethod, /*theInheritFirstArg=*/true );
+  }
+}
 
 //================================================================
 // Function : clearShapeBufferLocal
@@ -498,7 +517,7 @@ void RepairGUI_GlueDlg::clearShapeBufferLocal( GEOM::GEOM_Object_ptr theObj )
     return;
 
   _PTR(Study) aStudy = getStudy()->studyDS();
-  _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR.in() ) ) );
+  _PTR(SObject) aSObj ( aStudy->FindObjectIOR( std::string( IOR.in() ) ) );
   if ( !aSObj )
     return;
 
@@ -527,91 +546,71 @@ bool RepairGUI_GlueDlg::onAcceptLocal()
   _PTR(Study) aStudy = getStudy()->studyDS();
 
   bool aLocked = aStudy->GetProperties()->IsLocked();
-  if ( aLocked ) 
-  {
+  if ( aLocked ) {
     MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked");
-    SUIT_MessageBox::warn1 ( (QWidget*)(SUIT_Session::session()->activeApplication()->desktop()),
-      QObject::tr("WRN_WARNING"), QObject::tr("WRN_STUDY_LOCKED"), QObject::tr("BUT_OK") );
+    SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "WRN_STUDY_LOCKED" ), tr( "BUT_OK" ) );
     return false;
   }
 
   QString msg;
-  if ( !isValid( msg ) ) 
-  {
+  if ( !isValid( msg ) ) {
     showError( msg );
     return false;
   }
 
   erasePreview( false );
 
-  try 
-  {
-    if ( openCommand() ) 
-    {
+  try {
+    if ( openCommand() ) {
       SUIT_OverrideCursor wc;
-
-      SUIT_Session::session()->activeApplication()->putInfo( "" );
+      
+      myGeomGUI->getApp()->putInfo( "" );
       ObjectList objects;
       
-      if ( !execute( objects ) ) 
-      { 
+      if ( !execute( objects ) ) { 
         wc.suspend();
         abortCommand();
         showError();
       }
-      else 
-      {
+      else {
         const int nbObjs = objects.size();
-        bool withChildren = false;
-        for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) 
-        {
-          QString aName("");
-          if ( nbObjs > 1 )
-          {
-            aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName(   getPrefix( *it ) );
+        for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
+          QString aName = getNewObjectName();
+          if ( nbObjs > 1 ) {
+            if ( aName.isEmpty() )
+              aName = getPrefix( *it );
+            aName = GEOMBase::GetDefaultName( aName );
           }
-          else 
-          {
-            aName = getNewObjectName();
+          else {
             // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
             if ( aName.isEmpty() )
               aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
           }
-          addInStudy( *it, aName.latin1() );
-          withChildren = false;
+          addInStudy( *it, aName.toLatin1().data() );
           display( *it, false );
         }
-
-        if ( nbObjs ) 
-        {
+       
+        if ( nbObjs ) {
           commitCommand();
           updateObjBrowser();
-          SUIT_Session::session()->activeApplication()->putInfo( QObject::tr("GEOM_PRP_DONE") );
+          myGeomGUI->getApp()->putInfo( QObject::tr("GEOM_PRP_DONE") );
         }
-        else 
-        {
+        else {
           abortCommand();
         }
 
         // JFA 28.12.2004 BEGIN // To enable warnings
-        if ( !getOperation()->_is_nil() ) 
-        {
-          if ( !getOperation()->IsDone() ) 
-          {
-            wc.suspend();
-           QString msgw = QObject::tr( getOperation()->GetErrorCode() );
-            SUIT_MessageBox::warn1((QWidget*)(SUIT_Session::session()->activeApplication()->desktop()),
-                                  QObject::tr( "WRN_WARNING" ), 
-                                  msgw, 
-                                  QObject::tr( "BUT_OK" ));
-          }
+       GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
+        if ( !CORBA::is_nil(anOper) && !anOper->IsDone() ) {
+         wc.suspend();
+         QString msgw = QObject::tr( anOper->GetErrorCode() );
+         SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
         }
         // JFA 28.12.2004 END
       }
     }
   }
-  catch( const SALOME::SALOME_Exception& e ) 
-  {
+  catch( const SALOME::SALOME_Exception& e ) {
     SalomeApp_Tools::QtCatchCorbaException( e );
     abortCommand();
   }
@@ -637,25 +636,27 @@ void RepairGUI_GlueDlg::onDetect()
     return;
   }
 
-  GEOM::ListOfGO_var aList = GEOM::GEOM_IShapesOperations::_narrow
-    ( getOperation() )->GetGlueFaces( myObject, myTolEdt2->value() );
+  buttonOk()->setEnabled( false );
+  buttonApply()->setEnabled( false );
+  globalSelection( GEOM_ALLSHAPES );
+
+  GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
+  GEOM::ListOfGO_var aList = anOper->GetGlueFaces( myObject, myTolEdt2->value() );
   
-  for (int i = 0, n = aList->length(); i < n; i++
+  for ( int i = 0, n = aList->length(); i < n; i++ 
     myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
   
-  if ( myTmpObjs.size() > 0  )
-  {
+  if ( myTmpObjs.size() > 0  ) {
     msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
     mySubShapesChk->setChecked( true );
   }
-  else
-  {
+  else {
     msg = tr( "THERE_ARE_NO_FACES_FOR_GLUING" );
   }
   
-  connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-          SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) ) ;
-  SUIT_MessageBox::info1( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, "Close" );
+  connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+          this, SLOT( SelectionIntoArgument() ) ) ;
+  SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
   updateButtonState();
   activateSelection();
 }
@@ -666,33 +667,32 @@ void RepairGUI_GlueDlg::onDetect()
 //=================================================================================
 void RepairGUI_GlueDlg::activateSelection()
 {
-  erasePreview(false);
+  erasePreview( false );
   
   int anId = getConstructorId();
-  if ( anId == 0 )  // Case of whole gluing
-  {
-    disconnect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-               SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) ) ;
+  if ( anId == 0 )  
+    // Case of whole gluing
+    disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+               this, SLOT( SelectionIntoArgument() ) );
     
     globalSelection( GEOM_ALLSHAPES );
-    if (myObject->_is_nil()) 
+    if ( myObject->_is_nil()) 
       SelectionIntoArgument();
 
-    connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-            SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) ) ;
+    connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+             this, SLOT( SelectionIntoArgument() ) );
   } 
-  else // Second case of gluing
-  {
+  else {
+    // Second case of gluing
     if ( !mySubShapesChk->isChecked() ) 
       globalSelection( GEOM_ALLSHAPES );
-    else 
-    {
+    else {
       displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
-     disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-               SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) ) ;
+      disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+                 this, SLOT( SelectionIntoArgument() ) ) ;
       globalSelection( GEOM_PREVIEW );
-      connect( ((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
-              SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()) ) ;
+      connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+              this, SLOT( SelectionIntoArgument() ) ) ;
     } 
   }
   updateViewer();
@@ -706,20 +706,23 @@ void RepairGUI_GlueDlg::updateButtonState()
 {
   int anId = getConstructorId();
   bool hasMainObj = !myObject->_is_nil();
-  if ( anId == 0 )
-  {
-    buttonOk->setEnabled( hasMainObj );
-    buttonApply->setEnabled( hasMainObj );
+  if ( anId == 0 ) {
+    buttonOk()->setEnabled( hasMainObj );
+    buttonApply()->setEnabled( hasMainObj );
   }
   else
   {
+    LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+    SALOME_ListIO aSelList;
+    aSelMgr->selectedObjects(aSelList);
+
     bool wasSelected = false;
-    SALOME_ListIteratorOfListIO it ( selectedIO() );
+    SALOME_ListIteratorOfListIO it (aSelList);
     if (it.More() > 0)
       wasSelected = true;
     bool wasDetected = myTmpObjs.size() ? true : false;
-    buttonOk->setEnabled( hasMainObj && wasDetected && wasSelected);
-    buttonApply->setEnabled( hasMainObj && wasDetected && wasSelected);
+    buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
+    buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
     mySubShapesChk->setEnabled( hasMainObj && wasDetected );
     myDetectBtn->setEnabled( hasMainObj );
     if ( !hasMainObj || !wasDetected )
@@ -734,7 +737,7 @@ void RepairGUI_GlueDlg::updateButtonState()
 void RepairGUI_GlueDlg::clearTemporary()
 {
   ObjectList::iterator anIter;
-  for (anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter)
+  for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
     getGeomEngine()->RemoveObject(*anIter);
 
   myTmpObjs.clear();
@@ -772,42 +775,3 @@ void RepairGUI_GlueDlg::ClickOnCancel()
   clearTemporary();
   GEOMBase_Skeleton::ClickOnCancel();
 }
-
-//================================================================
-// Function : getEntry
-// Purpose  :
-//================================================================
-static string getEntry( GEOM::GEOM_Object_ptr object )
-{
-  SUIT_Session* session = SUIT_Session::session();
-  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( session->activeApplication() );
-  if ( app )
-  {
-    string IOR = app->orb()->object_to_string( object );
-    if ( IOR != "" )
-    {
-      SalomeApp_Study* study = ( SalomeApp_Study* )app->activeStudy();
-      _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
-      if ( SO )
-        return SO->GetID();
-    }
-  }
-  return "";
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-