Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupDlg.cxx
index 1aab1f908c42171e8fdb5ecdd79fa1a411e8bbad..3aa9e6abf3c1f6daab763c9a76654d10015ab1c1 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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
+// 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
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// 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
 //
 
 //  SMESH SMESHGUI : GUI for SMESH component
@@ -123,7 +123,8 @@ SMESHGUI_GroupDlg::SMESHGUI_GroupDlg( SMESHGUI* theModule,
     mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
     mySelector( SMESH::GetViewWindow( theModule )->GetSelector() ),
     myIsBusy( false ),
-    myNameChanged( false )
+    myNameChanged( false ),
+    myIsApplyAndClose( false )
 {
   initDialog( true );
   if ( !theMesh->_is_nil() )
@@ -773,6 +774,8 @@ bool SMESHGUI_GroupDlg::onApply()
   if (myName->text().trimmed().isEmpty())
     return false;
 
+  bool anIsOk = false;
+  QStringList anEntryList;
   if (myGrpTypeId == 0) { // on mesh elements
     if (!mySelectAll->isChecked() && !myElements->count())
       return false;
@@ -824,6 +827,8 @@ bool SMESHGUI_GroupDlg::onApply()
       myGroup->SetColor(aColor);
 
       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroup);
+      if( aMeshGroupSO )
+        anEntryList.append( aMeshGroupSO->GetID().c_str() );
 
       //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
       SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
@@ -895,7 +900,7 @@ bool SMESHGUI_GroupDlg::onApply()
     mySMESHGUI->updateObjBrowser(true);
     SMESH::UpdateView(); // asv: fix of BUG PAL5515
     mySelectionMgr->clearSelected();
-    return true;
+    anIsOk = true;
   }
   else if (myGrpTypeId == 1) { // on geom object
     if (CORBA::is_nil(myGroupOnGeom)) { // creation
@@ -971,6 +976,8 @@ bool SMESHGUI_GroupDlg::onApply()
       myGroupOnGeom->SetColor(aColor);
 
       _PTR(SObject) aMeshGroupSO = SMESH::FindSObject(myGroupOnGeom);
+      if( aMeshGroupSO )
+        anEntryList.append( aMeshGroupSO->GetID().c_str() );
 
       //SMESH::setFileName ( aMeshGroupSO, QString::number(myColorSpinBox->value()) );
       SMESH::setFileType ( aMeshGroupSO,"COULEURGROUP" );
@@ -1000,10 +1007,15 @@ bool SMESHGUI_GroupDlg::onApply()
     SMESHGUI::Modified();
     mySMESHGUI->updateObjBrowser(true);
     mySelectionMgr->clearSelected();
-    return true;
+    anIsOk = true;
   }
 
-  return false;
+  if( anIsOk )
+    if( LightApp_Application* anApp =
+        dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
+      myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
+
+  return anIsOk;
 }
 
 //=================================================================================
@@ -1012,8 +1024,10 @@ bool SMESHGUI_GroupDlg::onApply()
 //=================================================================================
 void SMESHGUI_GroupDlg::onOK()
 {
+  setIsApplyAndClose( true );
   if ( onApply() )
     onClose();
+  setIsApplyAndClose( false );
 }
 
 //=================================================================================
@@ -1181,17 +1195,15 @@ void SMESHGUI_GroupDlg::onObjectSelectionChanged()
       myGeomObjects->length(aNbSel);
 
       GEOM::GEOM_Object_var aGeomGroup;
-      Standard_Boolean testResult;
       int i = 0;
 
       SALOME_ListIteratorOfListIO anIt (aList);
       for (; anIt.More(); anIt.Next())
       {
-        testResult = Standard_False;
-        aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value(), testResult);
+        aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
 
         // Check if the object is a geometry group
-        if (!testResult || CORBA::is_nil(aGeomGroup))
+        if (CORBA::is_nil(aGeomGroup))
           continue;
 
         // Check if group constructed on the same shape as a mesh or on its child
@@ -1391,6 +1403,7 @@ void SMESHGUI_GroupDlg::onSelectAll()
   int selMode = mySelectionMode;
   mySelectionMode = grpNoSelection;
   setSelectionMode( selMode );
+  updateButtons();
 }
 
 //=================================================================================
@@ -1965,7 +1978,13 @@ void SMESHGUI_GroupDlg::onClose()
     restoreShowEntityMode();
   }
 
-  mySelectionMgr->clearSelected();
+  if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
+    SUIT_DataOwnerPtrList aList;
+    aList.append( new LightApp_DataOwner( myObjectToSelect ) );
+    mySelectionMgr->setSelected( aList );
+  }
+  else
+    mySelectionMgr->clearSelected();
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
   mySelectionMgr->clearFilters();
@@ -2397,3 +2416,23 @@ bool SMESHGUI_GroupDlg::IsActorVisible( SMESH_Actor* theActor )
     return aViewWindow->isVisible(theActor->getIO());
   return false;
 }
+
+//================================================================
+//function : setIsApplyAndClose
+//purpose  : Set value of the flag indicating that the dialog is
+//           accepted by Apply & Close button
+//================================================================
+void SMESHGUI_GroupDlg::setIsApplyAndClose( const bool theFlag )
+{
+  myIsApplyAndClose = theFlag;
+}
+
+//================================================================
+//function : isApplyAndClose
+//purpose  : Get value of the flag indicating that the dialog is
+//           accepted by Apply & Close button
+//================================================================
+bool SMESHGUI_GroupDlg::isApplyAndClose() const
+{
+  return myIsApplyAndClose;
+}