Salome HOME
Additional change to fix the preview problem
[modules/geom.git] / src / RepairGUI / RepairGUI_GlueDlg.cxx
index e1f233113d8c087d77f3570d7dd215354e5ebf7b..bc6e449212e8690a4b58a7460654418b074f17ab 100644 (file)
@@ -157,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()));
@@ -237,7 +239,7 @@ void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
   updateGeometry();
   resize( minimumSizeHint() );
 
-  displayPreview();
+  processPreview();
   updateButtonState();
   activateSelection();
   SelectionIntoArgument();
@@ -250,6 +252,7 @@ void RepairGUI_GlueDlg::ConstructorsClicked( int constructorId )
 //=================================================================================
 void RepairGUI_GlueDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
@@ -428,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();
@@ -445,24 +449,23 @@ 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();
 
@@ -649,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 {
@@ -695,7 +698,7 @@ 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() ) ) ;
       globalSelection( GEOM_PREVIEW );
@@ -724,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 );
@@ -744,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();
 }