Salome HOME
Fix for bug PAL8377 (ExportToMed TUI vs GUI: how to set the value of the boolean...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index d71d522df5a5649643339bdb47670cc494ccf743..228689dfe14b787251eea4faddb64343cd50cde8 100644 (file)
@@ -81,9 +81,9 @@
 
 #include "SalomeApp_Tools.h"
 #include "SalomeApp_Study.h"
-#include "LightApp_NameDlg.h"
-#include "LightApp_DataOwner.h"
 #include "SalomeApp_Application.h"
+#include "SalomeApp_CheckFileDlg.h"
+#include "LightApp_DataOwner.h"
 #include "LightApp_Preferences.h"
 #include "LightApp_VTKSelector.h"
 #include "LightApp_Operation.h"
 #include <qstring.h>
 #include <qwidget.h>
 #include <qaction.h>
+#include <qinputdialog.h>
 
 // BOOST Includes
 #include <boost/shared_ptr.hpp>
@@ -184,7 +185,6 @@ namespace{
     if(!filename.isEmpty()) {
       SUIT_OverrideCursor wc;
       _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-      theComponentMesh->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
 
       try {
        SMESH::mesh_array_var aMeshes = new SMESH::mesh_array;
@@ -288,7 +288,12 @@ namespace{
 
        QString aFilename;
        SMESH::MED_VERSION aFormat;
-
+       // Init the parameter with the default value
+       bool toCreateGroups = false;
+       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+       if ( resMgr )
+         toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
+       
        if ( theCommandID != 122 && theCommandID != 125 )
          aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
        else
@@ -297,10 +302,12 @@ namespace{
            for ( QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin(); it != aFilterMap.end(); ++it )
              filters.push_back( it.key() );
 
-           SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
+           //SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
+           SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( SMESHGUI::desktop(), false, QObject::tr("SMESH_AUTO_GROUPS") ,true, true );
            fd->setCaption( aTitle );
            fd->setFilters( filters );
            fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
+           fd->SetChecked(toCreateGroups);
            bool is_ok = false;
            while(!is_ok){
              fd->exec();
@@ -321,6 +328,7 @@ namespace{
                }
              }
            }
+           toCreateGroups = fd->IsChecked();
            delete fd;
          }
        if ( !aFilename.isEmpty() ) {
@@ -332,7 +340,7 @@ namespace{
          switch ( theCommandID ) {
          case 125:
          case 122:
-           aMesh->ExportToMED( aFilename.latin1(), false, aFormat ); // currently, automatic groups are never created
+           aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat );
            break;
          case 124:
          case 121:
@@ -1063,10 +1071,6 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   if( !mgr )
     return false;
 
-  if (CORBA::is_nil(GetSMESHGen()->GetCurrentStudy())) {
-    GetSMESHGen()->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
-  }
-
   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
 
@@ -1148,6 +1152,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
       SALOME_ListIO l;
       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+      aSel->selectedObjects( l );
       aSel->setSelectedObjects( l );
       break;
     }
@@ -1788,8 +1793,10 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           {
             aName = anAttr;
             QString newName = QString(aName->Value().c_str());
-            newName = LightApp_NameDlg::getName( desktop(), newName );
-            if ( !newName.isEmpty() )
+           bool ok;
+           newName = QInputDialog::getText( tr( "Rename" ), tr( "Enter new name:" ), QLineEdit::Normal,
+                                             newName, &ok, desktop() );
+            if ( ok && !newName.isEmpty() )
             {
               //old source: aStudy->renameIObject( IObject, newName );
              aName->SetValue( newName.latin1() );
@@ -2207,7 +2214,10 @@ void SMESHGUI::createPopupItem( const int id,
   QChar lc = QtxPopupMgr::Selection::defEquality();
   QString rule = "(%1) and (%2) and (%3)";
   rule = rule.arg( QString( "%1>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() ) );
-  rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
+  if( clients.isEmpty() )
+    rule = rule.arg( QString( "true" ) );
+  else
+    rule = rule.arg( QString( "%1client in {%2}" ).arg( lc ).arg( clients ) );
   rule = rule.arg( QString( "%1type in {%2}" ).arg( lc ).arg( types ) );
   rule += theRule;
 
@@ -2807,11 +2817,16 @@ void SMESHGUI::OnGUIEvent()
 
 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
 {
+  _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
   if ( CORBA::is_nil( myComponentSMESH ) )
     {
       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
+      if ( aStudy )
+        aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
       return aGUI.myComponentSMESH;
     }
+  if ( aStudy )
+    myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
   return myComponentSMESH;
 }
 
@@ -2880,6 +2895,9 @@ void SMESHGUI::createPreferences()
   setPreferenceProperty( dispmode, "strings", modes );
   setPreferenceProperty( dispmode, "indexes", indices );
 
+  int exportgroup = addPreference( tr( "PREF_GROUP_EXPORT" ), genTab );
+  addPreference( tr( "PREF_AUTO_GROUPS" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "auto_groups" );
+  
   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );