Salome HOME
Merge from OCC_development_generic_2006
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index d71d522df5a5649643339bdb47670cc494ccf743..ecc471d991be155837d92d6a79cd40da4c39d6fd 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 "SUIT_ResourceMgr.h"
 #include "SUIT_FileDlg.h"
 #include "SUIT_Desktop.h"
-#include "SUIT_ResourceMgr.h"
 #include "SUIT_OverrideCursor.h"
 #include "SUIT_Study.h"
 #include "SUIT_Session.h"
 #include <qstring.h>
 #include <qwidget.h>
 #include <qaction.h>
+#include <qinputdialog.h>
 
 // BOOST Includes
 #include <boost/shared_ptr.hpp>
@@ -184,7 +184,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 +287,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 +301,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 +327,7 @@ namespace{
                }
              }
            }
+           toCreateGroups = fd->IsChecked();
            delete fd;
          }
        if ( !aFilename.isEmpty() ) {
@@ -332,7 +339,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:
@@ -1148,6 +1155,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
       SALOME_ListIO l;
       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+      aSel->selectedObjects( l );
       aSel->setSelectedObjects( l );
       break;
     }
@@ -1171,39 +1179,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if( theCommandID==302 )
        startOperation( myEraseAll );
 
-      SALOME_ListIteratorOfListIO anIt( sel_objects );
-      for( ; anIt.More(); anIt.Next() )
-      {
-       Handle( SALOME_InteractiveObject ) obj = anIt.Value();
-       if( obj->hasEntry() )
-       {
-         _PTR(SObject) SO = activeStudy()->studyDS()->FindObjectID( obj->getEntry() );
-         if( SO && QString( SO->GetID().c_str() ) == SO->GetFatherComponent()->GetID().c_str() )
-         { //component is selected
-           _PTR(SComponent) SC( SO->GetFatherComponent() );
-           _PTR(ChildIterator) anIter ( activeStudy()->studyDS()->NewChildIterator( SC ) );
-           anIter->InitEx( true );
-           while( anIter->More() )
-           {
-             _PTR(SObject) valSO ( anIter->Value() );
-             _PTR(SObject) refSO;
-             if( !valSO->ReferencedObject( refSO ) )
-             {
-               QString id = valSO->GetID().c_str(),
-                        comp = SC->ComponentDataType().c_str(),
-                       val = valSO->GetName().c_str();
-
-               Handle( SALOME_InteractiveObject ) new_obj =
-                 new SALOME_InteractiveObject( id.latin1(), comp.latin1(), val.latin1() );
-               to_process.Append( new_obj );
-             }
-             anIter->Next();
-           }
-           continue;
-         }
-       }
-       to_process.Append( obj );
-      }
+      extractContainers( sel_objects, to_process );
 
       if (vtkwnd) {
        SALOME_ListIteratorOfListIO It( to_process );
@@ -1752,9 +1728,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           char* sName = Hyp->GetName();
           SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
           if (aCreator)
-          {
-            aCreator->EditHypothesis(Hyp);
-          }
+            aCreator->edit( Hyp.in(), desktop() );
           else
           {
             // report error
@@ -1788,8 +1762,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 +2183,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 +2786,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 +2864,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 );
 
@@ -3011,11 +2998,67 @@ void SMESHGUI::createPreferences()
 
 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
 {
-  if( sect=="SMESH" )
+  if( sect=="SMESH" ){
+    float sbX1,sbY1,sbW,sbH;
+    std::string aWarning;
+    SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr(this);
     if( name=="selection_object_color" || name=="selection_element_color" || 
         name=="selection_width" || name=="highlight_color" || name=="highlight_width" ||
         name=="selection_precision_node" || name=="selection_precision_element" )
       SMESH::UpdateSelectionProp( this );
+    else if (name == QString("scalar_bar_vertical_x") || name == QString("scalar_bar_vertical_width")){
+      sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_x", sbX1);
+      sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_width", sbW);
+      if(sbX1+sbW > 1.0){
+       aWarning = "Origin and Size Vertical: X+Width > 1\n";   
+       sbX1=0.01;
+       sbW=0.05;
+       aResourceMgr->setValue("SMESH", "scalar_bar_vertical_x", sbX1);
+       aResourceMgr->setValue("SMESH", "scalar_bar_vertical_width", sbW);
+      }
+    }
+    else if(name == QString("scalar_bar_vertical_y") || name == QString("scalar_bar_vertical_height")){
+      sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_y", sbY1);
+      sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_vertical_height",sbH);
+      if(sbY1+sbH > 1.0){
+       aWarning = "Origin and Size Vertical: Y+Height > 1\n";
+       sbY1=0.01;
+       sbH=0.5;
+       aResourceMgr->setValue("SMESH", "scalar_bar_vertical_y", sbY1);
+       aResourceMgr->setValue("SMESH", "scalar_bar_vertical_height",sbH);
+      }
+    }
+    else if(name ==  QString("scalar_bar_horizontal_x") || name ==  QString("scalar_bar_horizontal_width")){
+      sbX1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_x", sbX1);
+      sbW = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_width", sbW);
+      if(sbX1+sbW > 1.0){
+       aWarning = "Origin and Size Horizontal: X+Width > 1\n";
+       sbX1=0.2;
+       sbW=0.6;
+       aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_x", sbX1);
+       aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_width", sbW);
+      }
+    }
+    else if(name ==  QString("scalar_bar_horizontal_y") || name ==  QString("scalar_bar_horizontal_height")){
+      sbY1 = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_y", sbY1);
+      sbH = aResourceMgr->doubleValue("SMESH", "scalar_bar_horizontal_height",sbH);
+      if(sbY1+sbH > 1.0){
+       aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
+       sbY1=0.01;
+       sbH=0.12;
+       aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
+       aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
+      }
+    }
+    
+    if(aWarning.size() != 0){
+      aWarning += "The default values are applied instead.";
+      SUIT_MessageBox::warn1(SMESHGUI::desktop(),
+                            QObject::tr("SMESH_ERR_SCALARBAR_PARAMS"),
+                            QObject::tr(aWarning.c_str()),
+                            QObject::tr("SMESH_BUT_OK"));
+    }
+  }
 }
 
 //================================================================================
@@ -3099,6 +3142,20 @@ LightApp_Operation* SMESHGUI::createOperation( const int id ) const
   return op;
 }
 
+//================================================================================
+/*!
+ * \brief Stops current operations and starts a given one
+  * \param id - The id of the operation to start
+ */
+//================================================================================
+
+void SMESHGUI::switchToOperation(int id)
+{
+  if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() )
+    activeStudy()->abortAllOperations();
+  startOperation( id );
+}
+
 LightApp_Displayer* SMESHGUI::displayer()
 {
   if( !myDisplayer )