Salome HOME
Join BR-D5-38-2003
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 922b55bc7f1fd8f556858395b4dde6292adc96c4..8be5d69b22f4829d594f9c42bdf664b5c1f281b0 100644 (file)
@@ -81,8 +81,9 @@
 
 #include "SalomeApp_Tools.h"
 #include "SalomeApp_Study.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"
@@ -287,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
@@ -296,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();
@@ -320,6 +327,7 @@ namespace{
                }
              }
            }
+           toCreateGroups = fd->IsChecked();
            delete fd;
          }
        if ( !aFilename.isEmpty() ) {
@@ -331,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:
@@ -1062,6 +1070,10 @@ 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 );
 
@@ -1143,6 +1155,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
       SALOME_ListIO l;
       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+      aSel->selectedObjects( l );
       aSel->setSelectedObjects( l );
       break;
     }
@@ -1166,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 );
@@ -1747,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
@@ -2885,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 );
 
@@ -3016,11 +2998,54 @@ void SMESHGUI::createPreferences()
 
 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
 {
-  if( sect=="SMESH" )
+  if( sect=="SMESH" ){
+    float sbX1,sbY1,sbW,sbH;
+    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){
+       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){
+       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){
+       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){
+       sbY1=0.01;
+       sbH=0.12;
+       aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_y", sbY1);
+       aResourceMgr->setValue("SMESH", "scalar_bar_horizontal_height",sbH);
+      }
+    }
+  }
 }
 
 //================================================================================
@@ -3104,6 +3129,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 )