Salome HOME
0022308: EDF 2572 SMESH: Can't import a file with a non ascii character in the path
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_GroupOpDlg.cxx
index 44cdfdf94b337e51c4b1ac53d06e50379d15b709..a61be035aea4e9c0c3d127479f2131a1e27fc25d 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
 // File   : SMESHGUI_GroupOpDlg.cxx
 // Author : Sergey LITONIN, Open CASCADE S.A.S.
@@ -44,6 +45,9 @@
 #include <SVTK_ViewWindow.h>
 #include <SALOME_ListIO.hxx>
 
+// SALOME KERNEL includes
+#include <SALOMEDSClient_SObject.hxx>
+
 // Qt includes
 #include <QHBoxLayout>
 #include <QVBoxLayout>
@@ -74,7 +78,8 @@
 SMESHGUI_GroupOpDlg::SMESHGUI_GroupOpDlg( SMESHGUI* theModule )
   : QDialog( SMESH::GetDesktop( theModule ) ),
     mySMESHGUI( theModule ),
-    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+    mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+    myIsApplyAndClose( false )
 {
   setModal(false);
 
@@ -131,7 +136,7 @@ QWidget* SMESHGUI_GroupOpDlg::createMainFrame( QWidget* theParent )
   QLabel* aColorLab = new QLabel(tr( "SMESH_CHECK_COLOR" ), aColorBox );
   myColorBtn = new QtxColorButton(aColorBox);
   myColorBtn->setSizePolicy( QSizePolicy::MinimumExpanding, 
-                            myColorBtn->sizePolicy().verticalPolicy() );
+                             myColorBtn->sizePolicy().verticalPolicy() );
 
   aColorBoxLayout->addWidget(aColorLab);
   aColorBoxLayout->addWidget(myColorBtn);
@@ -199,7 +204,7 @@ QWidget* SMESHGUI_GroupOpDlg::createButtonFrame (QWidget* theParent)
 
   // connect signals and slots
   connect(myOkBtn,    SIGNAL(clicked()), SLOT(onOk()));
-  connect(myCloseBtn, SIGNAL(clicked()), SLOT(onClose()));
+  connect(myCloseBtn, SIGNAL(clicked()), SLOT(reject()));
   connect(myApplyBtn, SIGNAL(clicked()), SLOT(onApply()));
   connect(myHelpBtn,  SIGNAL(clicked()), SLOT(onHelp()));
 
@@ -223,12 +228,12 @@ void SMESHGUI_GroupOpDlg::Init()
   // selection and SMESHGUI
   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(ClickOnClose()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
 
   // set selection mode
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
-  mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
+  mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
 }
 
 /*!
@@ -242,7 +247,7 @@ bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theL
   if ( theListGrp.isEmpty() )
   {
     SUIT_MessageBox::information( this, tr("SMESH_INSUFFICIENT_DATA"),
-                                 tr("INCORRECT_ARGUMENTS") );
+                                  tr("INCORRECT_ARGUMENTS") );
     return false;
   }
 
@@ -289,14 +294,14 @@ bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theL
   if ( aMeshId == -1 )
   {
     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
-                                tr("DIFF_MESHES"));
+                                 tr("DIFF_MESHES"));
     return false;
   }
 
   if ( aGrpType == -1 ) 
   {
     SUIT_MessageBox::information(this, tr("SMESH_INSUFFICIENT_DATA"),
-                                tr("DIFF_TYPES"));
+                                 tr("DIFF_TYPES"));
     return false;
   }
 
@@ -308,14 +313,16 @@ bool SMESHGUI_GroupOpDlg::isValid( const QList<SMESH::SMESH_GroupBase_var>& theL
 */
 void SMESHGUI_GroupOpDlg::onOk()
 {
+  setIsApplyAndClose( true );
   if ( onApply() )
-    onClose();
+    reject();
+  setIsApplyAndClose( false );
 }
 
 /*!
-  \brief SLOT called when "Close" button pressed closes dialog
+  \brief SLOT called when dialog is closed
 */
-void SMESHGUI_GroupOpDlg::onClose()
+void SMESHGUI_GroupOpDlg::reject()
 {
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
@@ -324,7 +331,7 @@ void SMESHGUI_GroupOpDlg::onClose()
   mySMESHGUI->ResetState();
   mySelectionMgr->clearFilters();
   reset();
-  reject();
+  QDialog::reject();
 }
 
 /*!
@@ -343,10 +350,10 @@ void SMESHGUI_GroupOpDlg::onHelp()
     platform = "application";
 #endif
     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
-                            tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
-                            arg(app->resourceMgr()->stringValue("ExternalBrowser",
-                                                                platform)).
-                            arg(myHelpFileName));
+                             tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                             arg(app->resourceMgr()->stringValue("ExternalBrowser",
+                                                                 platform)).
+                             arg(myHelpFileName));
   }
 }
 
@@ -457,15 +464,7 @@ void SMESHGUI_GroupOpDlg::enterEvent(QEvent*)
   setEnabled(true);
   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
     aViewWindow->SetSelectionMode(ActorSelection);
-  mySelectionMgr->installFilter(new SMESH_TypeFilter (GROUP));
-}
-
-/*!
-  \brief Provides reaction on close event, closes the dialog box
-*/
-void SMESHGUI_GroupOpDlg::closeEvent(QCloseEvent*)
-{
-  onClose();
+  mySelectionMgr->installFilter(new SMESH_TypeFilter (SMESH::GROUP));
 }
 
 /*!
@@ -524,6 +523,28 @@ bool SMESHGUI_GroupOpDlg::onApply()
   return false;
 }
 
+/*!
+  \brief Set value of the flag indicating that the dialog is
+  accepted by Apply & Close button
+  \param theFlag value of the flag
+  \sa isApplyAndClose()
+*/
+void SMESHGUI_GroupOpDlg::setIsApplyAndClose( const bool theFlag )
+{
+  myIsApplyAndClose = theFlag;
+}
+
+/*!
+  \brief Get value of the flag indicating that the dialog is
+  accepted by Apply & Close button
+  \return value of the flag
+  \sa setApplyAndClose()
+*/
+bool SMESHGUI_GroupOpDlg::isApplyAndClose() const
+{
+  return myIsApplyAndClose;
+}
+
 // === === === === === === === === === === === === === === === === === === === === === 
 
 /*!
@@ -585,6 +606,7 @@ bool SMESHGUI_UnionGroupsDlg::onApply()
   QString aName = getName();
   
   bool aRes = false;
+  QStringList anEntryList;
   try
   {
     SMESH::ListOfGroups_var aList = convert( myGroups );
@@ -593,6 +615,8 @@ bool SMESHGUI_UnionGroupsDlg::onApply()
     if ( !CORBA::is_nil( aNewGrp ) )
     {
       aNewGrp->SetColor(  getColor() );
+      if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
+        anEntryList.append( aSObject->GetID().c_str() );
       aRes = true;
     }
   }
@@ -603,14 +627,18 @@ bool SMESHGUI_UnionGroupsDlg::onApply()
 
   if ( aRes ) 
   {
+    SMESHGUI::Modified();
     getSMESHGUI()->updateObjBrowser(true);
     reset();
+    if( LightApp_Application* anApp =
+        dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
+      anApp->browseObjects( anEntryList, isApplyAndClose() );
     return true;
   } 
   else 
   {
     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
-                             tr("SMESH_OPERATION_FAILED"));
+                              tr("SMESH_OPERATION_FAILED"));
     return false;
   }
 }
@@ -687,6 +715,7 @@ bool SMESHGUI_IntersectGroupsDlg::onApply()
   QString aName = getName();
   
   bool aRes = false;
+  QStringList anEntryList;
   try
   {
     SMESH::ListOfGroups_var aList = convert( myGroups );
@@ -695,6 +724,8 @@ bool SMESHGUI_IntersectGroupsDlg::onApply()
     if ( !CORBA::is_nil( aNewGrp ) )
     {
       aNewGrp->SetColor(  getColor() );
+      if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
+        anEntryList.append( aSObject->GetID().c_str() );
       aRes = true;
     }
   }
@@ -705,14 +736,18 @@ bool SMESHGUI_IntersectGroupsDlg::onApply()
 
   if ( aRes ) 
   {
+    SMESHGUI::Modified();
     getSMESHGUI()->updateObjBrowser(true);
     reset();
+    if( LightApp_Application* anApp =
+        dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
+      anApp->browseObjects( anEntryList, isApplyAndClose() );
     return true;
   } 
   else 
   {
     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
-                             tr("SMESH_OPERATION_FAILED"));
+                              tr("SMESH_OPERATION_FAILED"));
     return false;
   }
 }
@@ -852,6 +887,7 @@ bool SMESHGUI_CutGroupsDlg::onApply()
   QString aName = getName();
   
   bool aRes = false;
+  QStringList anEntryList;
   try
   {
     SMESH::ListOfGroups_var aList1 = convert( myGroups1 );
@@ -861,6 +897,8 @@ bool SMESHGUI_CutGroupsDlg::onApply()
     if ( !CORBA::is_nil( aNewGrp ) )
     {
       aNewGrp->SetColor(  getColor() );
+      if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
+        anEntryList.append( aSObject->GetID().c_str() );
       aRes = true;
     }
   }
@@ -871,14 +909,18 @@ bool SMESHGUI_CutGroupsDlg::onApply()
 
   if ( aRes ) 
   {
+    SMESHGUI::Modified();
     getSMESHGUI()->updateObjBrowser(true);
     reset();
+    if( LightApp_Application* anApp =
+        dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
+      anApp->browseObjects( anEntryList, isApplyAndClose() );
     return true;
   } 
   else 
   {
     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
-                             tr("SMESH_OPERATION_FAILED"));
+                              tr("SMESH_OPERATION_FAILED"));
     return false;
   }
 }
@@ -913,7 +955,7 @@ SMESHGUI_DimGroupDlg::SMESHGUI_DimGroupDlg( SMESHGUI* theModule )
 : SMESHGUI_GroupOpDlg( theModule )
 {
   setWindowTitle( tr( "CREATE_GROUP_OF_UNDERLYING_ELEMS" ) );
-  setHelpFileName( "creating_groups_page.html#gui_create_dim_group" );
+  setHelpFileName( "group_of_underlying_elements_page.html" );
 
   QGroupBox* anArgGrp = getArgGrp();
 
@@ -1003,6 +1045,7 @@ bool SMESHGUI_DimGroupDlg::onApply()
   QString aName = getName();
   
   bool aRes = false;
+  QStringList anEntryList;
   try
   {
     SMESH::ListOfGroups_var aList = convert( myGroups );
@@ -1012,6 +1055,8 @@ bool SMESHGUI_DimGroupDlg::onApply()
     if ( !CORBA::is_nil( aNewGrp ) )
     {
       aNewGrp->SetColor(  getColor() );
+      if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( aNewGrp ) )
+        anEntryList.append( aSObject->GetID().c_str() );
       aRes = true;
     }
   }
@@ -1022,14 +1067,18 @@ bool SMESHGUI_DimGroupDlg::onApply()
 
   if ( aRes ) 
   {
+    SMESHGUI::Modified();
     getSMESHGUI()->updateObjBrowser(true);
     reset();
+    if( LightApp_Application* anApp =
+        dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
+      anApp->browseObjects( anEntryList, isApplyAndClose() );
     return true;
   } 
   else 
   {
     SUIT_MessageBox::critical(this, tr("SMESH_ERROR"),
-                             tr("SMESH_OPERATION_FAILED"));
+                              tr("SMESH_OPERATION_FAILED"));
     return false;
   }
 }