Salome HOME
Additional change to fix the preview problem
[modules/geom.git] / src / RepairGUI / RepairGUI_GlueDlg.cxx
index 9c6bdd49e23a025a121b2119935069ee938ef814..bc6e449212e8690a4b58a7460654418b074f17ab 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -19,6 +19,7 @@
 //
 //  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. 
@@ -28,7 +29,7 @@
 #include <DlgRef.h>
 #include <GeometryGUI.h>
 #include <GEOMBase.h>
-#include <QtxDoubleSpinBox.h>
+#include <SalomeApp_DoubleSpinBox.h>
 
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
@@ -82,7 +83,8 @@ RepairGUI_GlueDlg::RepairGUI_GlueDlg( GeometryGUI* theGeometryGUI, QWidget* pare
   GroupPoints->LineEdit1->setReadOnly( true );
   
   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 = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
+  initSpinBox( myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision" );
   myTolEdt->setValue( DEFAULT_TOLERANCE_VALUE );
 
   QGridLayout* boxLayout = new QGridLayout( GroupPoints->Box );
@@ -99,11 +101,11 @@ RepairGUI_GlueDlg::RepairGUI_GlueDlg( GeometryGUI* theGeometryGUI, QWidget* pare
 
   QLabel* aTolLab2 = new QLabel( tr( "GEOM_TOLERANCE" ), GroupPoints2->Box );
   myTolEdt2 = new SalomeApp_DoubleSpinBox( GroupPoints2->Box );
-  initSpinBox( myTolEdt2, 0, 100, 1e-7, 7 );
+  initSpinBox( myTolEdt2, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision" );
   myTolEdt2->setValue( DEFAULT_TOLERANCE_VALUE );
 
   myDetectBtn = new QPushButton( tr( "GEOM_DETECT" ) + QString( " [%1]" ).arg( tr( "GLUE_FACES" ) ), 
-                                GroupPoints2->Box );
+                                 GroupPoints2->Box );
   mySubShapesChk = new QCheckBox( tr( "SELECT_FACES" ), GroupPoints2->Box );
 
   boxLayout = new QGridLayout( GroupPoints2->Box );
@@ -155,6 +157,8 @@ void RepairGUI_GlueDlg::Init()
   //globalSelection( GEOM_COMPOUND );
 
   mainFrame()->GroupBoxPublish->show();
+  //Hide preview checkbox
+  mainFrame()->CheckBoxPreview->hide();
 
   /* signals and slots connections */
   connect( buttonOk(),    SIGNAL(clicked()), this, SLOT(ClickOnOk()));
@@ -171,7 +175,7 @@ void RepairGUI_GlueDlg::Init()
   connect( mySubShapesChk, SIGNAL( stateChanged( int ) ), this, SLOT( onSubShapesChk() ) );
 
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   connect( myDetectBtn, SIGNAL( clicked() ), this, SLOT( onDetect() ) );
 
@@ -229,13 +233,13 @@ void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
   myEditCurrentArgument->setFocus();
 
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   qApp->processEvents();
   updateGeometry();
   resize( minimumSizeHint() );
 
-  displayPreview();
+  processPreview();
   updateButtonState();
   activateSelection();
   SelectionIntoArgument();
@@ -248,6 +252,7 @@ void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
 //=================================================================================
 void RepairGUI_GlueDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
@@ -296,9 +301,8 @@ void RepairGUI_GlueDlg::SelectionIntoArgument()
 
   if ( aSelList.Extent() == 1 ) {
     Handle(SALOME_InteractiveObject) anIO = aSelList.First();
-    Standard_Boolean aRes;
-    myObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
-    if ( aRes )
+    myObject = GEOMBase::ConvertIOinGEOMObject( anIO );
+    if ( !CORBA::is_nil( myObject ) )
       myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
   }
   updateButtonState();
@@ -344,7 +348,7 @@ void RepairGUI_GlueDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), 
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   //GroupPoints->LineEdit1->setText("");
   //GroupPoints2->LineEdit1->setText("");
@@ -415,8 +419,8 @@ bool RepairGUI_GlueDlg::execute( ObjectList& objects )
       aResult = !anObj->_is_nil();
       if ( aResult && !IsPreview() )
       {
-       QStringList aParameters;
-       aParameters << myTolEdt->text();
+        QStringList aParameters;
+        aParameters << myTolEdt->text();
         anObj->SetParameters(aParameters.join(":").toLatin1().constData());
 
         objects.push_back( anObj._retn() );
@@ -427,15 +431,16 @@ bool RepairGUI_GlueDlg::execute( ObjectList& objects )
     {
       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 )
-          objects.push_back( GEOM::GEOM_Object::_duplicate( *anIter ) );
-        return myTmpObjs.size() ? true : false;
+       for ( int i = 0; i < myTmpObjs.count(); i++ ) {
+         myTmpObjs[i].get()->Register(); // increment counter, since calling function will call UnRegister()
+          objects.push_back( myTmpObjs[i].copy() );
+       }
+        return !myTmpObjs.isEmpty();
       } // IsPreview
 
       // Make glue face by list.
       // Iterate through myTmpObjs and verifies where each object is currently selected or not.
-      QMap<QString, char> selected;
+      QSet<QString> selected;
 
       // Get names of selected objects
       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
@@ -444,35 +449,34 @@ bool RepairGUI_GlueDlg::execute( ObjectList& objects )
 
       SALOME_ListIteratorOfListIO it (aSelList);
       for (; it.More(); it.Next()) 
-        selected.insert(it.Value()->getName(), 0);
+        selected.insert(it.Value()->getName());
 
       // 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 ) {
-        if ( selected.contains( myGeomGUI->getApp()->orb()->object_to_string(*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 = anOper->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue, true );
+      aListForGlue->length( myTmpObjs.count() );
+      int added = 0;
+      for ( int i = 0; i < myTmpObjs.count(); i++ ) {
+       CORBA::String_var tmpior = myGeomGUI->getApp()->orb()->object_to_string(myTmpObjs[i].get());
+        if ( selected.contains( tmpior.in() ) )
+         aListForGlue[ added++ ] = myTmpObjs[i].copy();
+      }
+      aListForGlue->length( added );
+
+      GEOM::GEOM_Object_var anObj = anOper->MakeGlueFacesByList( myObject, myTolEdt2->value(), aListForGlue.in(), true );
 
       aResult = !anObj->_is_nil();
 
       if ( aResult )
       {
-       if ( !IsPreview() )
-       {
-         QStringList aParameters;
-         aParameters << myTolEdt2->text();
+        if ( !IsPreview() )
+        {
+          QStringList aParameters;
+          aParameters << myTolEdt2->text();
           anObj->SetParameters(aParameters.join(":").toLatin1().constData());
-       }
+        }
         objects.push_back( anObj._retn() );
       }
 
@@ -502,7 +506,8 @@ void RepairGUI_GlueDlg::restoreSubShapes( SALOMEDS::Study_ptr   theStudy,
 
     // empty list of arguments means that all arguments should be restored
     getGeomEngine()->RestoreSubShapesSO( theStudy, theSObject, GEOM::ListOfGO(),
-                                        aFindMethod, /*theInheritFirstArg=*/true );
+                                         aFindMethod, /*theInheritFirstArg=*/true,
+                                         mainFrame()->CheckBoxAddPrefix->isChecked() );
   }
 }
 
@@ -595,7 +600,7 @@ bool RepairGUI_GlueDlg::onAcceptLocal()
           addInStudy( *it, aName.toLatin1().data() );
           display( *it, false );
         }
-       
+        
         if ( nbObjs ) {
           commitCommand();
           updateObjBrowser();
@@ -606,11 +611,11 @@ bool RepairGUI_GlueDlg::onAcceptLocal()
         }
 
         // JFA 28.12.2004 BEGIN // To enable warnings
-       GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
+        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" ) );
+          wc.suspend();
+          QString msgw = QObject::tr( anOper->GetErrorCode() );
+          SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), msgw, tr( "BUT_OK" ) );
         }
         // JFA 28.12.2004 END
       }
@@ -647,13 +652,13 @@ void RepairGUI_GlueDlg::onDetect()
   globalSelection( GEOM_ALLSHAPES );
 
   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
-  GEOM::ListOfGO_var aList = anOper->GetGlueFaces( myObject, myTolEdt2->value() );
+  GEOM::ListOfGO_var aList = anOper->GetGlueFaces( myObject.in(), myTolEdt2->value() );
   
   for ( int i = 0, n = aList->length(); i < n; i++ ) 
-    myTmpObjs.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));
+    myTmpObjs << GEOM::GeomObjPtr( aList[i].in() );
   
-  if ( myTmpObjs.size() > 0  ) {
-    msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.size() );
+  if ( !myTmpObjs.isEmpty()  ) {
+    msg = tr( "FACES_FOR_GLUING_ARE_DETECTED" ).arg( myTmpObjs.count() );
     mySubShapesChk->setChecked( true );
   }
   else {
@@ -661,7 +666,7 @@ void RepairGUI_GlueDlg::onDetect()
   }
   
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) ) ;
+           this, SLOT( SelectionIntoArgument() ) ) ;
   SUIT_MessageBox::information( this, tr( "GEOM_FREE_BOUNDS_TLT" ), msg, tr( "Close" ) );
   updateButtonState();
   activateSelection();
@@ -679,7 +684,7 @@ void RepairGUI_GlueDlg::activateSelection()
   if ( anId == 0 )  { 
     // Case of whole gluing
     disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-               this, SLOT( SelectionIntoArgument() ) );
+                this, SLOT( SelectionIntoArgument() ) );
     
     globalSelection( GEOM_ALLSHAPES );
     if ( myObject->_is_nil()) 
@@ -693,12 +698,12 @@ void RepairGUI_GlueDlg::activateSelection()
     if ( !mySubShapesChk->isChecked() ) 
       globalSelection( GEOM_ALLSHAPES );
     else {
-      displayPreview( true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
+      displayPreview( true, true, false, false, 2/*line width*/, 1/*display mode*/, Quantity_NOC_RED );
       disconnect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-                 this, SLOT( SelectionIntoArgument() ) ) ;
+                  this, SLOT( SelectionIntoArgument() ) ) ;
       globalSelection( GEOM_PREVIEW );
       connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-              this, SLOT( SelectionIntoArgument() ) ) ;
+               this, SLOT( SelectionIntoArgument() ) ) ;
     } 
   }
   updateViewer();
@@ -722,11 +727,9 @@ void RepairGUI_GlueDlg::updateButtonState()
     SALOME_ListIO aSelList;
     aSelMgr->selectedObjects(aSelList);
 
-    bool wasSelected = false;
     SALOME_ListIteratorOfListIO it (aSelList);
-    if (it.More() > 0)
-      wasSelected = true;
-    bool wasDetected = myTmpObjs.size() ? true : false;
+    bool wasSelected = it.More() > 0;
+    bool wasDetected = !myTmpObjs.isEmpty();
     buttonOk()->setEnabled( hasMainObj && wasDetected && wasSelected );
     buttonApply()->setEnabled( hasMainObj && wasDetected && wasSelected );
     mySubShapesChk->setEnabled( hasMainObj && wasDetected );
@@ -742,10 +745,6 @@ void RepairGUI_GlueDlg::updateButtonState()
 //=================================================================================
 void RepairGUI_GlueDlg::clearTemporary()
 {
-  ObjectList::iterator anIter;
-  for ( anIter = myTmpObjs.begin(); anIter != myTmpObjs.end(); ++anIter )
-    getGeomEngine()->RemoveObject(*anIter);
-
   myTmpObjs.clear();
 }