Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 0227331c157aedf75546969f4c9d029c71ba632f..63ad64e378f4a8521affa26caa599a0ca42de93e 100644 (file)
@@ -17,7 +17,7 @@
 //  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : SMESHGUI.cxx
 //  Author : Nicolas REJNERI
@@ -26,6 +26,7 @@
 
 #include "SMESHGUI.h"
 
+#include "SMESH_Client.hxx"
 #include "SMESHGUI_NodesDlg.h"
 #include "SMESHGUI_TransparencyDlg.h"
 #include "SMESHGUI_ClippingDlg.h"
 #include "SMESHGUI_RemoveElementsDlg.h"
 #include "SMESHGUI_MeshInfosDlg.h"
 #include "SMESHGUI_StandardMeshInfosDlg.h"
+#include "SMESHGUI_WhatIsDlg.h"
 #include "SMESHGUI_Preferences_ColorDlg.h"
 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
 #include "SMESHGUI_Preferences_SelectionDlg.h"
 #include "SMESHGUI_Hypotheses.h"
 #include "SMESHGUI_MoveNodesDlg.h"
 #include "SMESHGUI_AddMeshElementDlg.h"
-#include "SMESHGUI_EditHypothesesDlg.h"
-#include "SMESHGUI_CreateHypothesesDlg.h"
+#include "SMESHGUI_AddQuadraticElementDlg.h"
 #include "SMESHGUI_FilterDlg.h"
 #include "SMESHGUI_FilterLibraryDlg.h"
 #include "SMESHGUI_SingleEditDlg.h"
 #include "SMESHGUI_RotationDlg.h"
 #include "SMESHGUI_SymmetryDlg.h"
 #include "SMESHGUI_SewingDlg.h"
-#include "SMESHGUI_MergeNodesDlg.h"
 #include "SMESHGUI_EditMeshDlg.h"
 #include "SMESHGUI_MeshPatternDlg.h"
-#include "SMESHGUI_PrecisionDlg.h"
 #include "SMESHGUI_Selection.h"
 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
+#include "SMESHGUI_ConvToQuadOp.h"
 #include "SMESHGUI_MeshOp.h"
 #include "SMESHGUI_Displayer.h"
+#include "SMESHGUI_MakeNodeAtPointDlg.h"
+#include "SMESHGUI_BuildCompoundDlg.h"
+#include "SMESHGUI_ComputeDlg.h"
 
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_GEOMGenUtils.h"
 
 #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 "SalomeApp_ImportOperation.h"
+
+#include "LightApp_DataOwner.h"
 #include "LightApp_Preferences.h"
 #include "LightApp_VTKSelector.h"
 #include "LightApp_Operation.h"
 #include "LightApp_UpdateFlags.h"
-
-#include "SalomeApp_ImportOperation.h"
+#include "LightApp_NameDlg.h"
 
 #include <SVTK_ViewWindow.h>
 #include <SVTK_ViewModel.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 "SALOMEconfig.h"
 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
+#include CORBA_SERVER_HEADER(SMESH_MeshEditor)
 
 // QT Includes
 #define         INCLUDE_MENUITEM_DEF
 #include "SALOMEDSClient_StudyBuilder.hxx"
 #include "SALOMEDSClient_SComponent.hxx"
 
+#include <Standard_ErrorHandler.hxx>
+
 using namespace std;
 
-namespace{
-  // Decalarations
+//namespace{
+  // Declarations
   //=============================================================
   void ImportMeshesFromFile(SMESH::SMESH_Gen_ptr theComponentMesh,
                            int theCommandID);
@@ -184,7 +190,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;
@@ -258,92 +263,197 @@ namespace{
       if ( !aMesh->_is_nil() ) {
        QString aFilter, aTitle = QObject::tr("Export mesh");
        QMap<QString, SMESH::MED_VERSION> aFilterMap;
+       QMap<QString, int> aFilterMapSTL;
        switch ( theCommandID ) {
        case 125:
        case 122:
-         aFilterMap.insert( QObject::tr("MED 2.1 (*.med)"), SMESH::MED_V2_1 );
-         aFilterMap.insert( QObject::tr("MED 2.2 (*.med)"), SMESH::MED_V2_2 );
+          {
+           if (aMesh->HasDuplicatedGroupNamesMED()) {
+              int aRet = SUIT_MessageBox::warn2
+                (SMESHGUI::desktop(),
+                 QObject::tr("SMESH_WRN_WARNING"),
+                 QObject::tr("SMESH_EXPORT_MED_DUPLICATED_GRP").arg(anIObject->getName()),
+                 QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
+                 0, 1, 0);
+              if (aRet)
+                return;
+            }
+            // PAL18696
+            QString v21( aMesh->GetVersionString( SMESH::MED_V2_1, 2));
+            QString v22( aMesh->GetVersionString( SMESH::MED_V2_2, 2));
+            aFilterMap.insert( QString("MED ") +  v21 + " (*.med)", SMESH::MED_V2_1 );
+            aFilterMap.insert( QString("MED ") +  v22 + " (*.med)", SMESH::MED_V2_2 );
+          }
          break;
        case 124:
        case 121:
          aFilter = QObject::tr("DAT files (*.dat)");
          break;
        case 126:
-       case 123: {
-         if(aMesh->NbPyramids()){
-           int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
-                                            QObject::tr("SMESH_WRN_WARNING"),
-                                            QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
-                                            QObject::tr("SMESH_BUT_YES"),
-                                            QObject::tr("SMESH_BUT_NO"),
-                                            0,1,0);
-           if(aRet)
+       case 123:
+          {
+            if (aMesh->NbPyramids()) {
+              int aRet = SUIT_MessageBox::warn2
+                (SMESHGUI::desktop(),
+                 QObject::tr("SMESH_WRN_WARNING"),
+                 QObject::tr("SMESH_EXPORT_UNV").arg(anIObject->getName()),
+                 QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
+                 0, 1, 0);
+              if (aRet)
+                return;
+            }
+            aFilter = QObject::tr("IDEAS files (*.unv)");
+          }
+         break;
+       case 140:
+       case 141:
+          {
+           // export STL
+           /*
+             there must be check on others mesh elements not equal triangles
+           */
+           if (aMesh->NbTriangles() < 1) {
+              SUIT_MessageBox::warn1
+                (SMESHGUI::desktop(),
+                 QObject::tr("SMESH_WRN_WARNING"),
+                 QObject::tr("SMESH_EXPORT_STL1").arg(anIObject->getName()),
+                 QObject::tr("SMESH_BUT_OK"));
              return;
-         }
-         aFilter = QObject::tr("IDEAS files (*.unv)");
+            }
+           if (!(aMesh->NbElements() - aMesh->NbTriangles())) {
+              int aRet = SUIT_MessageBox::warn2
+                (SMESHGUI::desktop(),
+                 QObject::tr("SMESH_WRN_WARNING"),
+                 QObject::tr("SMESH_EXPORT_STL2").arg(anIObject->getName()),
+                 QObject::tr("SMESH_BUT_YES"),  QObject::tr("SMESH_BUT_NO"),
+                 0, 1, 0);
+              if (aRet)
+                return;
+            }
+
+            aFilterMapSTL.insert( QObject::tr("STL ASCII  (*.stl)"), 1 ); // 1 - ASCII mode
+            aFilterMapSTL.insert( QObject::tr("STL Binary (*.stl)"), 0 ); // 0 - Binary mode
+          }
          break;
        default:
          return;
-       }}
+       }
 
        QString aFilename;
        SMESH::MED_VERSION aFormat;
+       // Init the parameter with the default value
+       bool aIsASCII_STL = true;
+       bool toCreateGroups = false;
+       SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+       if ( resMgr )
+         toCreateGroups = resMgr->booleanValue( "SMESH", "auto_groups", false );
+
+       if ( theCommandID != 122 && theCommandID != 125 && theCommandID != 140 && theCommandID != 141)
 
-       if ( theCommandID != 122 && theCommandID != 125 )
          aFilename = SUIT_FileDlg::getFileName(SMESHGUI::desktop(), "", aFilter, aTitle, false);
-       else
-         {
-           QStringList filters;
-           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 );
-           fd->setCaption( aTitle );
-           fd->setFilters( filters );
-           fd->setSelectedFilter( QObject::tr("MED 2.2 (*.med)") );
-           bool is_ok = false;
-           while(!is_ok){
-             fd->exec();
-             aFilename = fd->selectedFile();
-             aFormat = aFilterMap[fd->selectedFilter()];
-             is_ok = true;
-             if( !aFilename.isEmpty()
-                 && (aMesh->NbPolygons()>0 or aMesh->NbPolyhedrons()>0)
-                 && aFormat==SMESH::MED_V2_1){
-               int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
-                                                 QObject::tr("SMESH_WRN_WARNING"),
-                                                 QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
-                                                 QObject::tr("SMESH_BUT_YES"),
-                                                 QObject::tr("SMESH_BUT_NO"),
-                                                 0,1,0);
-               if(aRet){
-                 is_ok = false;
-               }
-             }
-           }
-           delete fd;
+
+       else if(theCommandID == 140 || theCommandID == 141) { // Export to STL
+         QStringList filters;
+          QMap<QString, int>::const_iterator it = aFilterMapSTL.begin();
+          for ( ; it != aFilterMapSTL.end(); ++it )
+            filters.push_back( it.key() );
+
+          SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
+          fd->setCaption( aTitle );
+          fd->setFilters( filters );
+          fd->setSelectedFilter( QObject::tr("STL ASCII  (*.stl)") );
+          bool is_ok = false;
+          while (!is_ok) {
+            fd->exec();
+            aFilename = fd->selectedFile();
+            aIsASCII_STL = (aFilterMapSTL[fd->selectedFilter()]) == 1 ? true: false;
+            is_ok = true;
          }
+          delete fd;
+       }
+       else {
+          QStringList filters;
+          QMap<QString, SMESH::MED_VERSION>::const_iterator it = aFilterMap.begin();
+          for ( ; it != aFilterMap.end(); ++it )
+            filters.push_back( it.key() );
+
+          //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();
+            aFilename = fd->selectedFile();
+            aFormat = aFilterMap[fd->selectedFilter()];
+            is_ok = true;
+            if ( !aFilename.isEmpty()
+                 && (aMesh->NbPolygons()>0 || aMesh->NbPolyhedrons()>0)
+                 && aFormat==SMESH::MED_V2_1) {
+              int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
+                                                QObject::tr("SMESH_WRN_WARNING"),
+                                                QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
+                                                QObject::tr("SMESH_BUT_YES"),
+                                                QObject::tr("SMESH_BUT_NO"),
+                                                0,1,0);
+              if (aRet) {
+                is_ok = false;
+              }
+            }
+          }
+          toCreateGroups = fd->IsChecked();
+          delete fd;
+        }
        if ( !aFilename.isEmpty() ) {
          // Check whether the file already exists and delete it if yes
          QFile aFile( aFilename );
          if ( aFile.exists() )
            aFile.remove();
          SUIT_OverrideCursor wc;
-         switch ( theCommandID ) {
-         case 125:
-         case 122:
-           aMesh->ExportToMED( aFilename.latin1(), false, aFormat ); // currently, automatic groups are never created
-           break;
-         case 124:
-         case 121:
-           aMesh->ExportDAT( aFilename.latin1() );
-           break;
-         case 126:
-         case 123:
-           aMesh->ExportUNV( aFilename.latin1() );
-           break;
-         default:
-           break;
+
+         try {
+           bool Renumber = false ;
+           // PAL 14172  : Check of we have to renumber or not from the preferences before export
+           if (resMgr)
+             Renumber= resMgr->booleanValue("SMESH","renumbering");
+           if (Renumber){
+             SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
+             aMeshEditor->RenumberNodes();
+             aMeshEditor->RenumberElements();
+             if ( SMESHGUI::automaticUpdate() )
+               SMESH::UpdateView();
+             }
+           switch ( theCommandID ) {
+           case 125:
+           case 122:
+             aMesh->ExportToMED( aFilename.latin1(), toCreateGroups, aFormat );
+             break;
+           case 124:
+           case 121:
+             aMesh->ExportDAT( aFilename.latin1() );
+             break;
+           case 126:
+           case 123:
+             aMesh->ExportUNV( aFilename.latin1() );
+             break;
+           case 140:
+           case 141:
+             aMesh->ExportSTL( aFilename.latin1(), aIsASCII_STL );
+             break;
+           default:
+             break;
+           }
+         }
+         catch (const SALOME::SALOME_Exception& S_ex){
+           wc.suspend();
+           SUIT_MessageBox::warn1(SMESHGUI::desktop(),
+                                   QObject::tr("SMESH_WRN_WARNING"),
+                                   QObject::tr("SMESH_EXPORT_FAILED"),
+                                   QObject::tr("SMESH_BUT_OK"));
+           wc.resume();
          }
        }
       }
@@ -395,12 +505,88 @@ namespace{
     }
   }
 
-  void SetDisplayMode(int theCommandID){
+  void AutoColor(){
+    SALOME_ListIO selected;
+    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+    if( !app )
+      return;
+
+    LightApp_SelectionMgr* aSel = app->selectionMgr();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+    if( !aSel || !appStudy )
+      return;
+
+    aSel->selectedObjects( selected );
+    if( selected.IsEmpty() )
+      return;
+
+    Handle(SALOME_InteractiveObject) anIObject = selected.First();
+
+    _PTR(Study) aStudy = appStudy->studyDS();
+    _PTR(SObject) aMainSObject( aStudy->FindObjectID( anIObject->getEntry() ) );
+    SMESH::SMESH_Mesh_var aMainObject = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
+    if( aMainObject->_is_nil() )
+      return;
+
+    aMainObject->SetAutoColor( true );
+
+    QValueList<SALOMEDS::Color> aReservedColors;
+
+    SMESH::ListOfGroups aListOfGroups = *aMainObject->GetGroups();
+    for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
+    {
+      SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
+      SALOMEDS::Color aCurrentColor = aGroupObject->GetColor();
+
+      SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
+      aGroupObject->SetColor( aColor );
+      aReservedColors.append( aColor );
+
+      _PTR(SObject) aGroupSObject = SMESH::FindSObject(aGroupObject);
+      if(SMESH_Actor *anActor = SMESH::FindActorByEntry(aGroupSObject->GetID().c_str()))
+      {
+       if( aGroupObject->GetType() == SMESH::NODE )
+         anActor->SetNodeColor( aColor.R, aColor.G, aColor.B );
+       else if( aGroupObject->GetType() == SMESH::EDGE )
+         anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B );
+       else
+         anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B );
+      }
+    }
+
+    SMESH::RepaintCurrentView();
+  }
+
+  void DisableAutoColor(){
     LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
     SALOME_ListIO selected;
     if( aSel )
       aSel->selectedObjects( selected );
 
+    if(selected.Extent()){
+      Handle(SALOME_InteractiveObject) anIObject = selected.First();
+      SMESH::SMESH_Mesh_var aMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIObject);
+      if ( !aMesh->_is_nil() ) {
+       aMesh->SetAutoColor( false );
+      }
+    }
+  }
+
+  void SetDisplayMode(int theCommandID){
+    SALOME_ListIO selected;
+    SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+    if( !app )
+      return;
+
+    LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
+    if( !aSel || !appStudy )
+      return;
+
+    _PTR(Study) aStudy = appStudy->studyDS();
+
+    aSel->selectedObjects( selected );
+
     if(selected.Extent() >= 1){
       switch(theCommandID){
       case 1134:{
@@ -435,28 +621,28 @@ namespace{
              anActor->SetRepresentation(SMESH_Actor::ePoint);
              break;
            case 1132:{
-             float color[3];
+             vtkFloatingPointType color[3];
              anActor->GetSufaceColor(color[0], color[1], color[2]);
              int c0 = int (color[0] * 255);
              int c1 = int (color[1] * 255);
              int c2 = int (color[2] * 255);
              QColor c(c0, c1, c2);
 
-             float edgecolor[3];
+             vtkFloatingPointType edgecolor[3];
              anActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
              c0 = int (edgecolor[0] * 255);
              c1 = int (edgecolor[1] * 255);
              c2 = int (edgecolor[2] * 255);
              QColor e(c0, c1, c2);
 
-             float backfacecolor[3];
+             vtkFloatingPointType backfacecolor[3];
              anActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
              c0 = int (backfacecolor[0] * 255);
              c1 = int (backfacecolor[1] * 255);
              c2 = int (backfacecolor[2] * 255);
              QColor b(c0, c1, c2);
 
-             float nodecolor[3];
+             vtkFloatingPointType nodecolor[3];
              anActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
              c0 = int (nodecolor[0] * 255);
              c1 = int (nodecolor[1] * 255);
@@ -467,7 +653,7 @@ namespace{
              if(Edgewidth == 0)
                Edgewidth = 1;
              int intValue = int(anActor->GetNodeSize());
-             float Shrink = anActor->GetShrinkFactor();
+             vtkFloatingPointType Shrink = anActor->GetShrinkFactor();
 
              SMESHGUI_Preferences_ColorDlg *aDlg =
                new SMESHGUI_Preferences_ColorDlg( SMESHGUI::GetSMESHGUI(), "" );
@@ -484,28 +670,38 @@ namespace{
                QColor nodecolor = aDlg->GetColor(3);
                QColor backfacecolor = aDlg->GetColor(4);
                /* actor color and backface color */
-               anActor->SetSufaceColor(float (color.red()) / 255.,
-                                        float (color.green()) / 255.,
-                                        float (color.blue()) / 255.);
-               anActor->SetBackSufaceColor(float (backfacecolor.red()) / 255.,
-                                            float (backfacecolor.green()) / 255.,
-                                            float (backfacecolor.blue()) / 255.);
+               anActor->SetSufaceColor(vtkFloatingPointType (color.red()) / 255.,
+                                       vtkFloatingPointType (color.green()) / 255.,
+                                       vtkFloatingPointType (color.blue()) / 255.);
+               anActor->SetBackSufaceColor(vtkFloatingPointType (backfacecolor.red()) / 255.,
+                                           vtkFloatingPointType (backfacecolor.green()) / 255.,
+                                           vtkFloatingPointType (backfacecolor.blue()) / 255.);
 
                /* edge color */
-               anActor->SetEdgeColor(float (edgecolor.red()) / 255.,
-                                      float (edgecolor.green()) / 255.,
-                                      float (edgecolor.blue()) / 255.);
+               anActor->SetEdgeColor(vtkFloatingPointType (edgecolor.red()) / 255.,
+                                     vtkFloatingPointType (edgecolor.green()) / 255.,
+                                     vtkFloatingPointType (edgecolor.blue()) / 255.);
 
                /* Shrink factor and size edges */
                anActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
                anActor->SetLineWidth(aDlg->GetIntValue(1));
 
                /* Nodes color and size */
-               anActor->SetNodeColor(float (nodecolor.red()) / 255.,
-                              float (nodecolor.green()) / 255.,
-                                      float (nodecolor.blue()) / 255.);
+               anActor->SetNodeColor(vtkFloatingPointType (nodecolor.red()) / 255.,
+                                     vtkFloatingPointType (nodecolor.green()) / 255.,
+                                     vtkFloatingPointType (nodecolor.blue()) / 255.);
                anActor->SetNodeSize(aDlg->GetIntValue(2));
 
+               SMESH::SMESH_GroupBase_var aGroupObject = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IObject);
+               if( !aGroupObject->_is_nil() )
+               {
+                 SALOMEDS::Color aColor;
+                 aColor.R = (float)color.red() / 255.0;
+                 aColor.G = (float)color.green() / 255.0;
+                 aColor.B = (float)color.blue() / 255.0;
+                 aGroupObject->SetColor( aColor );
+               }
+
                delete aDlg;
              }
              break;
@@ -707,72 +903,81 @@ namespace{
     SALOME_ListIteratorOfListIO It(selected);
 
     aStudyBuilder->NewCommand();  // There is a transaction
-    for(; It.More(); It.Next()){
+    for(; It.More(); It.Next()){ // loop on selected IO's
       Handle(SALOME_InteractiveObject) IObject = It.Value();
-      if(IObject->hasEntry()){
-       _PTR(SObject) SO = aStudy->FindObjectID(IObject->getEntry());
+      if(IObject->hasEntry()) {
+       _PTR(SObject) aSO = aStudy->FindObjectID(IObject->getEntry());
 
        // disable removal of "SMESH" component object
-       if(SO->FindAttribute(anAttr, "AttributeIOR")){
+       if(aSO->FindAttribute(anAttr, "AttributeIOR")){
          anIOR = anAttr;
          if ( !strcmp( (char*)anIOR->Value().c_str(), engineIOR().latin1() ) )
            continue;
        }
 
-       /* Erase child graphical objects */
-       _PTR(ChildIterator) it = aStudy->NewChildIterator(SO);
-       for(it->InitEx(true); it->More(); it->Next()){
-         _PTR(SObject) CSO = it->Value();
-         if(CSO->FindAttribute(anAttr, "AttributeIOR")){
-           anIOR = anAttr;
+        // put the whole hierarchy of sub-objects of the selected SO into a list and
+        // then treat them all starting from the deepest objects (at list back)
+
+        list< _PTR(SObject) > listSO;
+        listSO.push_back( aSO );
+        list< _PTR(SObject) >::iterator itSO = listSO.begin();
+        for ( ; itSO != listSO.end(); ++itSO ) {
+          _PTR(ChildIterator) it = aStudy->NewChildIterator( *itSO );
+          for (it->InitEx(false); it->More(); it->Next())
+            listSO.push_back( it->Value() );
+        }
+
+        // treat SO's in the list starting from the back
 
+        list< _PTR(SObject) >::reverse_iterator ritSO = listSO.rbegin();
+        for ( ; ritSO != listSO.rend(); ++ritSO ) {
+          _PTR(SObject) SO = *ritSO;
+          if ( !SO ) continue;
+          string anEntry = SO->GetID();
+
+          /** Erase graphical object **/
+         if(SO->FindAttribute(anAttr, "AttributeIOR")){
            QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
            for(int i = 0; i < nbSf; i++){
              SUIT_ViewWindow *sf = aViews[i];
-             CORBA::String_var anEntry = CSO->GetID().c_str();
-             if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.in())){
+             if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,anEntry.c_str())){
                SMESH::RemoveActor(sf,anActor);
              }
            }
          }
-       }
-
-       /* Erase main graphical object */
-       QPtrVector<SUIT_ViewWindow> aViews = vm->getViews();
-       for(int i = 0; i < nbSf; i++){
-         SUIT_ViewWindow *sf = aViews[i];
-         if(SMESH_Actor* anActor = SMESH::FindActorByEntry(sf,IObject->getEntry())){
-           SMESH::RemoveActor(sf,anActor);
-         }
-       }
 
-       // Remove object(s) from data structures
-       _PTR(SObject) obj = aStudy->FindObjectID(IObject->getEntry());
-       if(obj){
-         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( obj ) );
-         SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( obj ) );
-          QString objType = CheckTypeObject(IObject);
-         if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
-           SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
-           aMesh->RemoveGroup( aGroup );
-         }
-         else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
-           SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
-           aMesh->RemoveSubMesh( aSubMesh );
-         }
-         else if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
-            SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
-           aStudyBuilder->RemoveObjectWithChildren( obj );
-         }
-         else {// default action: remove SObject from the study
-           // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
-           //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
-           //op->start();
-           aStudyBuilder->RemoveObjectWithChildren( obj );
-           //op->finish();
-         }
-       }
+          /** Remove an object from data structures **/
+          SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow( SMESH::SObjectToObject( SO ));
+          SMESH::SMESH_subMesh_var   aSubMesh = SMESH::SMESH_subMesh::_narrow( SMESH::SObjectToObject( SO ));
+          if ( !aGroup->_is_nil() ) {                          // DELETE GROUP
+            SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
+            aMesh->RemoveGroup( aGroup );
+          }
+          else if ( !aSubMesh->_is_nil() ) {                   // DELETE SUBMESH
+            SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
+            aMesh->RemoveSubMesh( aSubMesh );
 
+            _PTR(SObject) aMeshSO = SMESH::FindSObject(aMesh);
+            if (aMeshSO)
+              SMESH::ModifiedMesh(aMeshSO, false, aMesh->NbNodes()==0);
+          }
+          else {
+            IObject = new SALOME_InteractiveObject
+              ( anEntry.c_str(), engineIOR().latin1(), SO->GetName().c_str() );
+            QString objType = CheckTypeObject(IObject);
+            if ( objType == "Hypothesis" || objType == "Algorithm" ) {// DELETE HYPOTHESIS
+              SMESH::RemoveHypothesisOrAlgorithmOnMesh(IObject);
+              aStudyBuilder->RemoveObjectWithChildren( SO );
+            }
+            else {// default action: remove SObject from the study
+              // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
+              //SUIT_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
+              //op->start();
+              aStudyBuilder->RemoveObjectWithChildren( SO );
+              //op->finish();
+            }
+          }
+       } /* listSO back loop */
       } /* IObject->hasEntry() */
     } /* more/next */
     aStudyBuilder->CommitCommand();
@@ -783,10 +988,10 @@ namespace{
 
     SMESHGUI::GetSMESHGUI()->updateObjBrowser();
   }
-}
+//}
 
 extern "C" {
-  Standard_EXPORT CAM_Module* createModule()
+  SMESHGUI_EXPORT CAM_Module* createModule()
   {
     return new SMESHGUI();
   }
@@ -804,12 +1009,12 @@ SalomeApp_Module( "SMESH" )
 {
   if ( CORBA::is_nil( myComponentSMESH ) )
   {
-    SALOME_LifeCycleCORBA* ls = new SALOME_LifeCycleCORBA( getApp()->namingService() );
-    Engines::Component_var comp = ls->FindOrLoad_Component( "FactoryServer", "SMESH" );
-    myComponentSMESH = SMESH::SMESH_Gen::_narrow( comp );
+    CORBA::Boolean anIsEmbeddedMode;
+    myComponentSMESH = SMESH_Client::GetSMESHGen(getApp()->orb(),anIsEmbeddedMode);
   }
 
   myActiveDialogBox = 0;
+  myFilterLibraryDlg = 0;
   myState = -1;
   myDisplayer = 0;
 
@@ -1093,6 +1298,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 124:
   case 125:
   case 126:
+  case 140:
+  case 141:
     {
       ::ExportMeshToFile(theCommandID);
       break;
@@ -1121,6 +1328,15 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+    // Auto-color
+  case 1136:
+    ::AutoColor();
+  break;
+
+  case 1137:
+    ::DisableAutoColor();
+  break;
+
   case 1134: // Clipping
   case 1133: // Tranparency
   case 1132: // Colors / Size
@@ -1144,10 +1360,22 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 214:                                    // UPDATE
     {
       if(checkLock(aStudy)) break;
-      SMESH::UpdateView();
+      try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+        OCC_CATCH_SIGNALS;
+#endif
+        SMESH::UpdateView();
+      }
+      catch (std::bad_alloc) { // PAL16774 (Crash after display of many groups)
+        SMESH::OnVisuException();
+      }
+      catch (...) { // PAL16774 (Crash after display of many groups)
+        SMESH::OnVisuException();
+      }
 
       SALOME_ListIO l;
       LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+      aSel->selectedObjects( l );
       aSel->setSelectedObjects( l );
       break;
     }
@@ -1168,50 +1396,35 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if (aSel)
         aSel->selectedObjects( sel_objects );
 
-      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 );
-      }
+      if( theCommandID==302 )
+       startOperation( myEraseAll );
 
-      if (vtkwnd) {
-       SALOME_ListIteratorOfListIO It( to_process );
-       for (; It.More(); It.Next()) {
-         Handle(SALOME_InteractiveObject) IOS = It.Value();
-         if (IOS->hasEntry()) {
-            SMESH::UpdateView(anAction, IOS->getEntry());
-            if (anAction == SMESH::eDisplayOnly)
-              anAction = SMESH::eDisplay;
-         }
-       }
+      extractContainers( sel_objects, to_process );
+
+      try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+        OCC_CATCH_SIGNALS;
+#endif
+        if (vtkwnd) {
+          SALOME_ListIteratorOfListIO It( to_process );
+          for (; It.More(); It.Next()) {
+            Handle(SALOME_InteractiveObject) IOS = It.Value();
+            if (IOS->hasEntry()) {
+              if (!SMESH::UpdateView(anAction, IOS->getEntry()))
+                break; // PAL16774 (Crash after display of many groups)
+              if (anAction == SMESH::eDisplayOnly)
+                anAction = SMESH::eDisplay;
+            }
+          }
+        }
+
+        // PAL13338 + PAL15161 -->
+        if ( ( theCommandID==301 || theCommandID==302 ) && !checkLock(aStudy))
+          SMESH::UpdateView();
+        // PAL13338 + PAL15161 <--
+      }
+      catch (...) { // PAL16774 (Crash after display of many groups)
+        SMESH::OnVisuException();
       }
 
       if (anAction == SMESH::eErase) {
@@ -1220,6 +1433,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       }
       else
        aSel->setSelectedObjects( to_process );
+
       break;
     }
 
@@ -1267,105 +1481,11 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   case 701:                                    // COMPUTE MESH
     {
-      if(checkLock(aStudy)) break;
-      if ( vtkwnd ) {
-       LightApp_SelectionMgr *Sel = selectionMgr();
-       SALOME_ListIO selected; Sel->selectedObjects( selected );
-
-       int nbSel = selected.Extent();
-       if (nbSel != 1){
-         break;
-       }
+      if (checkLock(aStudy)) break;
 
-       SMESH::SMESH_Mesh_var aMesh;
-       SMESH::SMESH_subMesh_var aSubMesh;
-       Handle(SALOME_InteractiveObject) IObject = selected.First();
-       if (IObject->hasEntry()){
-         _PTR(SObject) aMeshSObj = aStudy->FindObjectID(IObject->getEntry());
-         GEOM::GEOM_Object_var aShapeObject = SMESH::GetShapeOnMeshOrSubMesh( aMeshSObj );
-         if ( aShapeObject->_is_nil() ) {
-           // imported mesh
-           break;
-         }
-         if( aMeshSObj ) {
-           SMESH::SMESH_Mesh_var aMesh = SMESH::SObjectToInterface<SMESH::SMESH_Mesh>(aMeshSObj);
-           SMESH::SMESH_subMesh_var aSubMesh = SMESH::SObjectToInterface<SMESH::SMESH_subMesh>(aMeshSObj);
-
-           if (!aMesh->_is_nil()){
-             GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
-             if (!refShapeObject->_is_nil()) {
-               if(!GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject)){
-                 SUIT_MessageBox::warn1(desktop(),
-                                       tr("SMESH_WRN_WARNING"),
-                                       tr("SMESH_WRN_MISSING_PARAMETERS"),
-                                       tr("SMESH_BUT_OK"));
-                 break;
-               }
-               try{
-                 if (GetSMESHGen()->Compute(aMesh,refShapeObject))
-                    SMESH::ModifiedMesh(aMeshSObj,true);
-                 // TO Do : change icon of all submeshes
-                  else
-                    SUIT_MessageBox::warn1(desktop(),
-                                          tr("SMESH_WRN_WARNING"),
-                                          tr("SMESH_WRN_COMPUTE_FAILED"),
-                                          tr("SMESH_BUT_OK"));
-               }
-               catch(const SALOME::SALOME_Exception & S_ex){
-                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
-               }
-             }
-           }else if(!aSubMesh->_is_nil()){
-             aMesh = aSubMesh->GetFather();
-             GEOM::GEOM_Object_var refShapeObject = SMESH::GetShapeOnMeshOrSubMesh(aMeshSObj);
-             if(!refShapeObject->_is_nil()){
-               bool compute = GetSMESHGen()->IsReadyToCompute(aMesh,refShapeObject);
-               if(!compute){
-                 SUIT_MessageBox::warn1(desktop(),
-                                       tr("SMESH_WRN_WARNING"),
-                                       tr("SMESH_WRN_MISSING_PARAMETERS"),
-                                       tr("SMESH_BUT_OK"));
-                 break;
-               }
-               try{
-                 if ( GetSMESHGen()->Compute(aMesh,refShapeObject) )
-                    SMESH::ModifiedMesh(aMeshSObj,true);
-                 // TO Do : change icon of all submeshes
-                  else
-                    SUIT_MessageBox::warn1(desktop(),
-                                          tr("SMESH_WRN_WARNING"),
-                                          tr("SMESH_WRN_COMPUTE_FAILED"),
-                                          tr("SMESH_BUT_OK"));
-               }catch(const SALOME::SALOME_Exception & S_ex){
-                 SalomeApp_Tools::QtCatchCorbaException(S_ex);
-               }
-             }
-           }
-         }
-       }
-       CORBA::Long anId = aStudy->StudyId();
-       TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId,IObject->getEntry());
-       if ( automaticUpdate() && aVisualObj){
-         aVisualObj->Update();
-         SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
-         if(!anActor){
-           anActor = SMESH::CreateActor(aStudy,IObject->getEntry());
-           if(anActor){
-             SMESH::DisplayActor(view,anActor); //apo
-             SMESH::FitAll();
-           }
-         }
-         SMESH::RepaintCurrentView();
-       }
-      }else{
-       SUIT_MessageBox::warn1(desktop(),
-                             tr("SMESH_WRN_WARNING"),
-                             tr("SMESH_WRN_VIEWER_VTK"),
-                             tr("SMESH_BUT_OK"));
-      }
-      updateObjBrowser();
-      break;
+      startOperation( 701 );
     }
+    break;
 
   case 702:  // Create mesh
     startOperation( 702 );
@@ -1376,6 +1496,13 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 704: // Edit mesh/sub-mesh
     startOperation( 704 );
     break;
+  case 710: // Build compound mesh
+    {
+      if (checkLock(aStudy)) break;
+      EmitSignalDeactivateDialog();
+      new SMESHGUI_BuildCompoundDlg( this );
+    }
+    break;
   case 407: // DIAGONAL INVERSION
   case 408: // Delete diagonal
     {
@@ -1428,9 +1555,6 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       else
         aDlg = new SMESHGUI_CuttingOfQuadsDlg(this);
 
-      int x, y ;
-      DefineDlgPosition( aDlg, x, y );
-      aDlg->move( x, y );
       aDlg->show();
       break;
     }
@@ -1504,6 +1628,20 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       }
       break;
     }
+  case 417: // Convert mesh to quadratic
+    {
+    startOperation( 417 );
+      /*      if (checkLock(aStudy)) break;
+      if (vtkwnd) {
+       EmitSignalDeactivateDialog();
+       new SMESHGUI_ConvToQuadDlg();
+      } else {
+       SUIT_MessageBox::warn1(desktop(),
+                               tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
+                               tr("SMESH_BUT_OK"));
+                              }*/
+      break;
+    }
   case 801:                                     // CREATE GROUP
     {
       if ( !vtkwnd )
@@ -1585,13 +1723,20 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
                }
                updateObjBrowser();
 
-             }catch(const SALOME::SALOME_Exception & S_ex){
+             }
+              catch(const SALOME::SALOME_Exception & S_ex){
                SalomeApp_Tools::QtCatchCorbaException(S_ex);
              }
            }
          }
        }
       }
+      else if(nbSel==0) {
+        SUIT_MessageBox::warn1(desktop(),
+                               tr("SMESH_WRN_WARNING"),
+                               tr("SMESH_WRN_NO_AVAILABLE_DATA"),
+                               tr("SMESH_BUT_OK"));
+      }
       break;
     }
 
@@ -1616,8 +1761,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       int nbSelectedGroups = 0;
       for ( ; It.More(); It.Next() )
       {
-        SMESH::SMESH_Group_var aGroup =
-          SMESH::IObjectToInterface<SMESH::SMESH_Group>(It.Value());
+        SMESH::SMESH_GroupBase_var aGroup =
+          SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(It.Value());
         if (!aGroup->_is_nil()) {
          nbSelectedGroups++;
           SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", aGroup);
@@ -1626,7 +1771,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       }
       if (nbSelectedGroups == 0)
        {
-         SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_Group::_nil());
+         SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg( this, "", SMESH::SMESH_GroupBase::_nil());
          aDlg->show();
        }
       break;
@@ -1744,6 +1889,13 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+  case 903:                                    // WHAT IS
+    {
+      EmitSignalDeactivateDialog();
+      new SMESHGUI_WhatIsDlg( this, "", false);
+      break;
+    }
+
   case 1100:                                   // EDIT HYPOTHESIS
     {
       if(checkLock(aStudy)) break;
@@ -1756,19 +1908,18 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       int nbSel = selected.Extent();
 
       if (nbSel == 1) {
-       SMESH::SMESH_Hypothesis_var Hyp = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(selected.First());
+        Handle(SALOME_InteractiveObject) anIObject = selected.First();
+       SMESH::SMESH_Hypothesis_var aHypothesis = SMESH::IObjectToInterface<SMESH::SMESH_Hypothesis>(anIObject);
 
         /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
         /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects                   */
         /* Warning : however by internal mechanism all subMeshes icons are changed !                     */
-        if ( !Hyp->_is_nil() )
+        if ( !aHypothesis->_is_nil() )
         {
-          char* sName = Hyp->GetName();
-          SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(sName);
+          CORBA::String_var aHypType = aHypothesis->GetName();
+          SMESHGUI_GenericHypothesisCreator* aCreator = SMESH::GetHypothesisCreator(aHypType);
           if (aCreator)
-          {
-            aCreator->EditHypothesis(Hyp);
-          }
+            aCreator->edit( aHypothesis.in(), anIObject->getName(), desktop() );
           else
           {
             // report error
@@ -1802,7 +1953,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           {
             aName = anAttr;
             QString newName = QString(aName->Value().c_str());
-            newName = LightApp_NameDlg::getName( desktop(), newName );
+            newName = LightApp_NameDlg::getName(desktop(), newName);
             if ( !newName.isEmpty() )
             {
               //old source: aStudy->renameIObject( IObject, newName );
@@ -1893,6 +2044,46 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       }
       break;
     }
+  case 4034:     // QUADRATIC EDGE
+  case 4035:     // QUADRATIC TRIANGLE
+  case 4036:     // QUADRATIC QUADRANGLE
+  case 4037:     // QUADRATIC TETRAHEDRON
+  case 4038:     // QUADRATIC PYRAMID
+  case 4039:     // QUADRATIC PENTAHEDRON
+  case 4040:     // QUADRATIC HEXAHEDRON
+    {
+      if(checkLock(aStudy)) break;
+      if ( vtkwnd ) {
+       EmitSignalDeactivateDialog();
+       int type;
+
+       switch (theCommandID) {
+       case 4034:
+         type = QUAD_EDGE; break;
+       case 4035:
+         type = QUAD_TRIANGLE; break;
+       case 4036:
+         type = QUAD_QUADRANGLE; break;
+       case 4037:
+         type = QUAD_TETRAHEDRON; break;
+       case 4038:
+         type = QUAD_PYRAMID; break;
+       case 4039:
+         type = QUAD_PENTAHEDRON; break;
+       case 4040:
+         type = QUAD_HEXAHEDRON;
+         break;
+       default:;
+       }
+        new SMESHGUI_AddQuadraticElementDlg( this, type );
+      }
+      else {
+       SUIT_MessageBox::warn1(SMESHGUI::desktop(),
+                              tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
+                              tr("SMESH_BUT_OK"));
+      }
+      break;
+    }
   case 4041:                                   // REMOVES NODES
     {
       if(checkLock(aStudy)) break;
@@ -2013,7 +2204,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if(checkLock(aStudy)) break;
       if(vtkwnd) {
        EmitSignalDeactivateDialog();
-       new SMESHGUI_MergeNodesDlg( this );
+       new SMESHGUI_EditMeshDlg( this, 0 );
       }
       else {
        SUIT_MessageBox::warn1(desktop(),
@@ -2022,15 +2213,12 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       }
       break;
     }
-  case 4066: // MERGE EQUAL ELEMENTS
+  case 4066:                                   // MERGE EQUAL ELEMENTS
     {
       if (checkLock(aStudy)) break;
       if (vtkwnd) {
        EmitSignalDeactivateDialog();
-       new SMESHGUI_EditMeshDlg(this,
-                                 "SMESH_MERGE_ELEMENTS_TITLE",
-                                 "ICON_DLG_MERGE_ELEMENTS",
-                                 1); // MergeEqualElemets
+       new SMESHGUI_EditMeshDlg( this, 1 );
       } else {
        SUIT_MessageBox::warn1(desktop(),
                              tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
@@ -2039,6 +2227,10 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+  case 4067: // MAKE MESH PASS THROUGH POINT
+    startOperation( 4067 );
+    break;
+
   case 5105: // Library of selection filters
   {
     static QValueList<int> aTypes;
@@ -2049,7 +2241,11 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       aTypes.append( SMESH::FACE );
       aTypes.append( SMESH::VOLUME );
     }
-    new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
+    if (!myFilterLibraryDlg)
+      myFilterLibraryDlg = new SMESHGUI_FilterLibraryDlg( this, SMESH::GetDesktop( this ), aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
+    else if (myFilterLibraryDlg->isHidden())
+      myFilterLibraryDlg->Init( aTypes, SMESHGUI_FilterLibraryDlg::EDIT );
+    myFilterLibraryDlg->raise();
   }
   break;
 
@@ -2103,12 +2299,14 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       LightApp_SelectionMgr* mgr = selectionMgr();
       SALOME_ListIO selected; mgr->selectedObjects( selected );
 
-      if (selected.Extent() == 1)      {
-       Handle(SALOME_InteractiveObject) anIObject = selected.First();
-       if(anIObject->hasEntry())
+      SALOME_ListIteratorOfListIO it(selected);
+      for(; it.More(); it.Next()) {
+        Handle(SALOME_InteractiveObject) anIObject = it.Value();
+       if(anIObject->hasEntry()) {
          if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
            anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
          }
+       }
       }
       break;
     }
@@ -2221,7 +2419,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;
 
@@ -2255,15 +2456,18 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  121, "DAT" );
   createSMESHAction(  122, "MED" );
   createSMESHAction(  123, "UNV" );
+  createSMESHAction(  140, "STL" );
   createSMESHAction(  124, "EXPORT_DAT" );
   createSMESHAction(  125, "EXPORT_MED" );
   createSMESHAction(  126, "EXPORT_UNV" );
-  createSMESHAction(   33, "DELETE",          "ICON_DELETE" );
+  createSMESHAction(  141, "EXPORT_STL" );
+  createSMESHAction(   33, "DELETE",          "ICON_DELETE", Key_Delete );
   createSMESHAction( 5105, "SEL_FILTER_LIB" );
   createSMESHAction(  701, "COMPUTE",         "ICON_COMPUTE" );
   createSMESHAction(  702, "CREATE_MESH",     "ICON_DLG_INIT_MESH" );
   createSMESHAction(  703, "CREATE_SUBMESH",  "ICON_DLG_ADD_SUBMESH" );
   createSMESHAction(  704, "EDIT_MESHSUBMESH","ICON_DLG_EDIT_MESH" );
+  createSMESHAction(  710, "BUILD_COMPOUND",  "ICON_BUILD_COMPOUND" );
   createSMESHAction(  801, "CREATE_GROUP",    "ICON_SMESH_TREE_GROUP" );
   createSMESHAction(  802, "CONSTRUCT_GROUP", "ICON_CONSTRUCT_GROUP" );
   createSMESHAction(  803, "EDIT_GROUP",      "ICON_EDIT_GROUP" );
@@ -2275,6 +2479,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  813, "DEL_GROUP",       "ICON_DEL_GROUP" );
   createSMESHAction(  900, "ADV_INFO",        "ICON_ADV_INFO" );
   createSMESHAction(  902, "STD_INFO",        "ICON_STD_INFO" );
+  createSMESHAction(  903, "WHAT_IS",         "ICON_WHAT_IS" );
   createSMESHAction( 6001, "LENGTH",          "ICON_LENGTH" ,       0, true );
   createSMESHAction( 6002, "FREE_EDGE",       "ICON_FREE_EDGE" ,    0, true );
   createSMESHAction( 6003, "FREE_BORDER",     "ICON_FREE_EDGE_2D" , 0, true );
@@ -2301,11 +2506,12 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 4051, "RENUM_NODES",     "ICON_DLG_RENUMBERING_NODES" );
   createSMESHAction( 4052, "RENUM_ELEMENTS",  "ICON_DLG_RENUMBERING_ELEMENTS" );
   createSMESHAction( 4061, "TRANS",           "ICON_SMESH_TRANSLATION_VECTOR" );
-  createSMESHAction( 4062, "ROT",             "ICON_DLG_ROTATION" );
+  createSMESHAction( 4062, "ROT",             "ICON_DLG_MESH_ROTATION" );
   createSMESHAction( 4063, "SYM",             "ICON_SMESH_SYMMETRY_PLANE" );
   createSMESHAction( 4064, "SEW",             "ICON_SMESH_SEWING_FREEBORDERS" );
   createSMESHAction( 4065, "MERGE",           "ICON_SMESH_MERGE_NODES" );
   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
+  createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MESH_THROU_POINT" );
   createSMESHAction(  406, "MOVE",            "ICON_DLG_MOVE_NODE" );
   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
@@ -2317,6 +2523,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  414, "REVOLUTION",      "ICON_REVOLUTION" );
   createSMESHAction(  415, "MAP",             "ICON_MAP" );
   createSMESHAction(  416, "EXTRUSION_ALONG", "ICON_EXTRUSION_ALONG" );
+  createSMESHAction(  417, "CONV_TO_QUAD",    "ICON_CONV_TO_QUAD" );
   createSMESHAction(  200, "RESET" );
   createSMESHAction(  201, "SCALAR_BAR_PROP" );
   createSMESHAction(  211, "WIRE",           "ICON_WIRE", 0, true );
@@ -2329,7 +2536,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction(  219, "VOLUMES",        "ICON_DLG_TETRAS", 0, true );
   createSMESHAction(  220, "ALL" );
   createSMESHAction( 1100, "EDIT_HYPO" );
-  createSMESHAction( 1101, "RENAME" );
+  createSMESHAction( 1101, "RENAME", "", Key_F2 );
   createSMESHAction( 1102, "UNASSIGN" );
   createSMESHAction( 9010, "NUM_NODES", "", 0, true );
   createSMESHAction( 9011, "NUM_ELEMENTS", "", 0, true );
@@ -2338,12 +2545,21 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 1133, "TRANSP" );
   createSMESHAction( 1134, "CLIP" );
   createSMESHAction( 1135, "DISP_ENT" );
+  createSMESHAction( 1136, "AUTO_COLOR" );
+  createSMESHAction( 1137, "DISABLE_AUTO_COLOR" );
   createSMESHAction( 2000, "CTRL" );
 
   createSMESHAction( 300, "ERASE" );
   createSMESHAction( 301, "DISPLAY" );
   createSMESHAction( 302, "DISPLAY_ONLY" );
   createSMESHAction( 4033, "POLYHEDRON", "ICON_DLG_POLYHEDRON" );
+  createSMESHAction( 4034, "QUADRATIC_EDGE", "ICON_DLG_QUADRATIC_EDGE" );
+  createSMESHAction( 4035, "QUADRATIC_TRIANGLE", "ICON_DLG_QUADRATIC_TRIANGLE" );
+  createSMESHAction( 4036, "QUADRATIC_QUADRANGLE", "ICON_DLG_QUADRATIC_QUADRANGLE" );
+  createSMESHAction( 4037, "QUADRATIC_TETRAHEDRON", "ICON_DLG_QUADRATIC_TETRAHEDRON" );
+  createSMESHAction( 4038, "QUADRATIC_PYRAMID", "ICON_DLG_QUADRATIC_PYRAMID" );
+  createSMESHAction( 4039, "QUADRATIC_PENTAHEDRON", "ICON_DLG_QUADRATIC_PENTAHEDRON" );
+  createSMESHAction( 4040, "QUADRATIC_HEXAHEDRON", "ICON_DLG_QUADRATIC_HEXAHEDRON" );
 
   // ----- create menu --------------
   int fileId   = createMenu( tr( "MEN_FILE" ),   -1,  1 ),
@@ -2370,6 +2586,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 121, exportId, -1 );
   createMenu( 122, exportId, -1 );
   createMenu( 123, exportId, -1 );
+  createMenu( 140, exportId, -1 ); // export to stl STL
 
   createMenu( separator(), fileId, 10 );
 
@@ -2380,6 +2597,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 702, meshId, -1 );
   createMenu( 703, meshId, -1 );
   createMenu( 704, meshId, -1 );
+  createMenu( 710, meshId, -1 );
   createMenu( separator(), meshId, -1 );
   createMenu( 701, meshId, -1 );
   createMenu( separator(), meshId, -1 );
@@ -2395,6 +2613,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( separator(), meshId, -1 );
   createMenu( 900, meshId, -1 );
   createMenu( 902, meshId, -1 );
+  createMenu( 903, meshId, -1 );
   createMenu( separator(), meshId, -1 );
 
   createMenu( 6003, ctrlId, -1 );
@@ -2423,6 +2642,14 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 4031, addId, -1 );
   createMenu( 4032, addId, -1 );
   createMenu( 4033, addId, -1 );
+  createMenu( separator(), addId, -1 );
+  createMenu( 4034, addId, -1 );
+  createMenu( 4035, addId, -1 );
+  createMenu( 4036, addId, -1 );
+  createMenu( 4037, addId, -1 );
+  createMenu( 4038, addId, -1 );
+  createMenu( 4039, addId, -1 );
+  createMenu( 4040, addId, -1 );
 
   createMenu( 4041, removeId, -1 );
   createMenu( 4042, removeId, -1 );
@@ -2438,6 +2665,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 4066, transfId, -1 );
 
   createMenu( 406, modifyId, -1 );
+  createMenu( 4067,modifyId, -1 );
   createMenu( 407, modifyId, -1 );
   createMenu( 408, modifyId, -1 );
   createMenu( 409, modifyId, -1 );
@@ -2448,6 +2676,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 416, modifyId, -1 );
   createMenu( 414, modifyId, -1 );
   createMenu( 415, modifyId, -1 );
+  createMenu( 417, modifyId, -1 );
 
   createMenu( 214, viewId, -1 );
 
@@ -2461,6 +2690,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( 702, meshTb );
   createTool( 703, meshTb );
   createTool( 704, meshTb );
+  createTool( 710, meshTb );
   createTool( separator(), meshTb );
   createTool( 701, meshTb );
   createTool( separator(), meshTb );
@@ -2470,6 +2700,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( separator(), meshTb );
   createTool( 900, meshTb );
   createTool( 902, meshTb );
+  createTool( 903, meshTb );
   createTool( separator(), meshTb );
 
   createTool( 6001, ctrlTb );
@@ -2499,6 +2730,14 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( 4032, addRemTb );
   createTool( 4033, addRemTb );
   createTool( separator(), addRemTb );
+  createTool( 4034, addRemTb );
+  createTool( 4035, addRemTb );
+  createTool( 4036, addRemTb );
+  createTool( 4037, addRemTb );
+  createTool( 4038, addRemTb );
+  createTool( 4039, addRemTb );
+  createTool( 4040, addRemTb );
+  createTool( separator(), addRemTb );
   createTool( 4041, addRemTb );
   createTool( 4042, addRemTb );
   createTool( separator(), addRemTb );
@@ -2514,6 +2753,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( separator(), addRemTb );
 
   createTool( 406, modifyTb );
+  createTool( 4067,modifyTb );
   createTool( 407, modifyTb );
   createTool( 408, modifyTb );
   createTool( 409, modifyTb );
@@ -2524,6 +2764,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( 416, modifyTb );
   createTool( 414, modifyTb );
   createTool( 415, modifyTb );
+  createTool( 417, modifyTb );
 
   createTool( 214, dispModeTb );
 
@@ -2536,12 +2777,13 @@ void SMESHGUI::initialize( CAM_Application* app )
          group   = pat.arg( SMESHGUI_Selection::typeName( GROUP ) ),
          hypo    = pat.arg( SMESHGUI_Selection::typeName( HYPOTHESIS ) ),
          algo    = pat.arg( SMESHGUI_Selection::typeName( ALGORITHM ) ),
-         elems   = QString( "'%1' '%2' '%3' '%4' '%5'" ).
+         elems   = QString( "'%1' '%2' '%3' '%4' '%5' '%6'" ).
                        arg( SMESHGUI_Selection::typeName( SUBMESH_VERTEX ) ).
                       arg( SMESHGUI_Selection::typeName( SUBMESH_EDGE ) ).
                       arg( SMESHGUI_Selection::typeName( SUBMESH_FACE ) ).
                       arg( SMESHGUI_Selection::typeName( SUBMESH_SOLID ) ).
-                      arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ),
+                      arg( SMESHGUI_Selection::typeName( SUBMESH_COMPOUND ) ).
+                      arg( SMESHGUI_Selection::typeName( SUBMESH ) ),
           subMesh = elems,
          mesh_group = mesh + " " + subMesh + " " + group,
          hyp_alg = hypo + " " + algo;
@@ -2556,6 +2798,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createPopupItem( 214, OB, mesh_group );                  // UPDATE
   createPopupItem( 900, OB, mesh_group );                  // ADV_INFO
   createPopupItem( 902, OB, mesh );                        // STD_INFO
+  createPopupItem( 903, OB, mesh_group );                  // WHAT_IS
   popupMgr()->insert( separator(), -1, 0 );
   createPopupItem( 801, OB, mesh );                        // CREATE_GROUP
   createPopupItem( 802, OB, subMesh );                     // CONSTRUCT_GROUP
@@ -2566,9 +2809,11 @@ void SMESHGUI::initialize( CAM_Application* app )
   popupMgr()->insert( separator(), -1, 0 );
 
   QString only_one_non_empty = QString( " && %1=1 && numberOfNodes>0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
-  createPopupItem( 125, OB, mesh, only_one_non_empty );    // EXPORT_MED
-  createPopupItem( 126, OB, mesh, only_one_non_empty );    // EXPORT_UNV
-  createPopupItem( 33, OB, subMesh + " " + group );        // DELETE
+  createPopupItem( 125, OB, mesh, only_one_non_empty );   // EXPORT_MED
+  createPopupItem( 126, OB, mesh, only_one_non_empty );   // EXPORT_UNV
+  createPopupItem( 141, OB, mesh, only_one_non_empty );   // EXPORT_STL
+  //createPopupItem( 33, OB, subMesh + " " + group );       // DELETE
+  createPopupItem(  33, OB, mesh_group + " " + hyp_alg ); // DELETE
   popupMgr()->insert( separator(), -1, 0 );
 
   // popup for viewer
@@ -2579,6 +2824,11 @@ void SMESHGUI::initialize( CAM_Application* app )
   createPopupItem( 214, View, mesh_group ); // UPDATE
   createPopupItem( 900, View, mesh_group ); // ADV_INFO
   createPopupItem( 902, View, mesh );       // STD_INFO
+  createPopupItem( 903, View, mesh_group ); // WHAT_IS
+  popupMgr()->insert( separator(), -1, 0 );
+
+  createPopupItem( 1136, OB + " " + View, mesh, "&& (not isAutoColor)" ); // AUTO_COLOR
+  createPopupItem( 1137, OB + " " + View, mesh, "&& isAutoColor" );       // DISABLE_AUTO_COLOR
   popupMgr()->insert( separator(), -1, 0 );
 
   int anId;
@@ -2601,6 +2851,10 @@ void SMESHGUI::initialize( CAM_Application* app )
   aType = aType.arg( mesh_group );
   QString aMeshInVTK = aClient + "&&" + aType;
 
+  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
+  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
+  QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
+
   //-------------------------------------------------
   // Numbering
   //-------------------------------------------------
@@ -2700,7 +2954,7 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   popupMgr()->insert( action( 6003 ), anId, -1 ); // FREE_BORDER
   popupMgr()->setRule( action( 6003 ), aMeshInVtkHasEdges, true );
-  popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeEdges'", false );
+  popupMgr()->setRule( action( 6003 ), "controlMode = 'eFreeBorders'", false );
 
   popupMgr()->insert( action( 6001 ), anId, -1 ); // LENGTH
   popupMgr()->setRule( action( 6001 ), aMeshInVtkHasEdges, true );
@@ -2714,7 +2968,7 @@ void SMESHGUI::initialize( CAM_Application* app )
 
   popupMgr()->insert( action( 6002 ), anId, -1 ); // FREE_EDGE
   popupMgr()->setRule( action( 6002 ), aMeshInVtkHasFaces, true );
-  popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeBorders'", false );
+  popupMgr()->setRule( action( 6002 ), "controlMode = 'eFreeEdges'", false );
 
   popupMgr()->insert( action( 6018 ), anId, -1 ); // LENGTH_2D
   popupMgr()->setRule( action( 6018 ), aMeshInVtkHasFaces, true );
@@ -2768,10 +3022,6 @@ void SMESHGUI::initialize( CAM_Application* app )
   //-------------------------------------------------
   // Display / Erase
   //-------------------------------------------------
-  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
-  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
-  QString aSelCount = QString( "%1 > 0" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
-
   QString aRule = "$component={'SMESH'} and ( type='Component' or (" + aClient + " and " +
     aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";
   popupMgr()->insert( action( 301 ), -1, -1 ); // DISPLAY
@@ -2796,6 +3046,11 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
   setMenuShown( true );
   setToolShown( true );
 
+  // Reset actions accelerator keys
+  action(111)->setAccel(QKeySequence(CTRL + Key_B)); // Import DAT
+  action(112)->setAccel(QKeySequence(CTRL + Key_U)); // Import UNV
+  action(113)->setAccel(QKeySequence(CTRL + Key_M)); // Import MED
+
   return res;
 }
 
@@ -2806,9 +3061,20 @@ bool SMESHGUI::deactivateModule( SUIT_Study* study )
 
   EmitSignalCloseAllDialogs();
 
+  // Unset actions accelerator keys
+  action(111)->setAccel(QKeySequence()); // Import DAT
+  action(112)->setAccel(QKeySequence()); // Import UNV
+  action(113)->setAccel(QKeySequence()); // Import MED
+
   return SalomeApp_Module::deactivateModule( study );
 }
 
+void SMESHGUI::studyClosed( SUIT_Study* s )
+{
+  SMESH::RemoveVisuData( s->id() );
+  SalomeApp_Module::studyClosed( s );
+}
+
 void SMESHGUI::OnGUIEvent()
 {
   const QObject* obj = sender();
@@ -2821,11 +3087,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;
 }
 
@@ -2833,7 +3104,7 @@ QString SMESHGUI::engineIOR() const
 {
   CORBA::ORB_var anORB = getApp()->orb();
   CORBA::String_var anIOR = anORB->object_to_string(GetSMESHGen());
-  return anIOR.in();
+  return QString( anIOR.in() );
 }
 
 void SMESHGUI::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
@@ -2894,6 +3165,10 @@ 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" );
+  addPreference( tr( "PREF_RENUMBER" ), exportgroup, LightApp_Preferences::Bool, "SMESH", "renumbering" );
+
   int meshTab = addPreference( tr( "PREF_TAB_MESH" ) );
   int nodeGroup = addPreference( tr( "PREF_GROUP_NODES" ), meshTab );
 
@@ -2942,14 +3217,15 @@ void SMESHGUI::createPreferences()
 
   addPreference( tr( "PREF_NODES" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_node" );
   addPreference( tr( "PREF_ELEMENTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_element" );
+  addPreference( tr( "PREF_OBJECTS" ), precSelGroup, LightApp_Preferences::Double, "SMESH", "selection_precision_object" );
 
   int sbarTab = addPreference( tr( "SMESH_SCALARBAR" ) );
   int fontGr = addPreference( tr( "SMESH_FONT_SCALARBAR" ), sbarTab );
 
   int tfont = addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_title_font" );
-  addPreference( tr( "SMESH_TITLE" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
+  addPreference( tr( "PREF_TITLE_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_title_color" );
   int lfont = addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Font, "SMESH", "scalar_bar_label_font" );
-  addPreference( tr( "SMESH_LABELS" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
+  addPreference( tr( "PREF_LABELS_COLOR" ), fontGr, LightApp_Preferences::Color, "SMESH", "scalar_bar_label_color" );
 
   QStringList fam;
   fam.append( tr( "SMESH_FONT_ARIAL" ) );
@@ -3025,11 +3301,67 @@ void SMESHGUI::createPreferences()
 
 void SMESHGUI::preferencesChanged( const QString& sect, const QString& name )
 {
-  if( sect=="SMESH" )
-    if( name=="selection_object_color" || name=="selection_element_color" || 
+  if( sect=="SMESH" ){
+    float sbX1,sbY1,sbW,sbH;
+    float aTol = 1.00000009999999;
+    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" )
+        name=="selection_precision_node" || name=="selection_precision_element" ||
+       name=="selection_precision_object")
       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 > aTol){
+       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 > aTol){
+       aWarning = "Origin and Size Vertical: Y+Height > 1\n";
+       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 > aTol){
+       aWarning = "Origin and Size Horizontal: X+Width > 1\n";
+       sbX1=0.01;
+       sbW=0.05;
+       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 > aTol){
+       aWarning = "Origin and Size Horizontal: Y+Height > 1\n";
+       sbY1=0.01;
+       sbH=0.05;
+       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"));
+    }
+  }
 }
 
 //================================================================================
@@ -3095,6 +3427,9 @@ LightApp_Operation* SMESHGUI::createOperation( const int id ) const
   // to do : create operation here
   switch( id )
   {
+    case 701: // Compute mesh
+      op = new SMESHGUI_ComputeOp();
+    break;
     case 702: // Create mesh
       op = new SMESHGUI_MeshOp( true, true );
     break;
@@ -3104,6 +3439,12 @@ LightApp_Operation* SMESHGUI::createOperation( const int id ) const
     case 704: // Edit mesh/sub-mesh
       op = new SMESHGUI_MeshOp( false );
     break;
+    case 417: //convert to quadratic
+      op = new SMESHGUI_ConvToQuadOp();
+    break;
+    case 4067: // make mesh pass through point
+      op = new SMESHGUI_MakeNodeAtPointOp();
+      break;
     default:
     break;
   }
@@ -3113,9 +3454,81 @@ 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 )
-    myDisplayer = new SMESHGUI_Displayer( dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
+    myDisplayer = new SMESHGUI_Displayer( getApp() );
   return myDisplayer;
 }
+
+SALOMEDS::Color SMESHGUI::getUniqueColor( const QValueList<SALOMEDS::Color>& theReservedColors )
+{
+  int aHue = -1;
+  int aTolerance = 64;
+  int anIterations = 0;
+  int aPeriod = 5;
+
+  while( 1 )
+  {
+    anIterations++;
+    if( anIterations % aPeriod == 0 )
+    {
+      aTolerance /= 2;
+      if( aTolerance < 1 )
+       break;
+    }
+    //cout << "Iteration N" << anIterations << " (tolerance=" << aTolerance << ")"<< endl;
+
+    aHue = (int)( 360.0 * rand() / RAND_MAX );
+    //cout << "Hue = " << aHue << endl;
+
+    //cout << "Auto colors : ";
+    bool ok = true;
+    QValueList<SALOMEDS::Color>::const_iterator it = theReservedColors.constBegin();
+    QValueList<SALOMEDS::Color>::const_iterator itEnd = theReservedColors.constEnd();
+    for( ; it != itEnd; ++it )
+    {
+      SALOMEDS::Color anAutoColor = *it;
+      QColor aQColor( (int)( anAutoColor.R * 255.0 ), (int)( anAutoColor.G * 255.0 ), (int)( anAutoColor.B * 255.0 ) );
+
+      int h, s, v;
+      aQColor.getHsv( &h, &s, &v );
+      //cout << h << " ";
+      if( abs( h - aHue ) < aTolerance )
+      {
+       ok = false;
+       //cout << "break (diff = " << abs( h - aHue ) << ")";
+       break;
+      }
+    }
+    //cout << endl;
+
+    if( ok )
+      break;
+  }
+
+  //cout << "Hue of the returned color = " << aHue << endl;
+  QColor aColor;
+  aColor.setHsv( aHue, 255, 255 );
+
+  SALOMEDS::Color aSColor;
+  aSColor.R = (double)aColor.red() / 255.0;
+  aSColor.G = (double)aColor.green() / 255.0;
+  aSColor.B = (double)aColor.blue() / 255.0;
+
+  return aSColor;
+}