Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
index 690f46831b057a3d0622ede0d768ca41f973a2da..821a8a0a1e925dd789128b215ae1c99d8821e639 100644 (file)
@@ -1,25 +1,24 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
 //  File   : SMESH_MeshEditor_i.cxx
 //  Author : Nicolas REJNERI
 //  Module : SMESH
 
 #include "SMESH_MeshEditor_i.hxx"
 
-#include "SMDS_Mesh0DElement.hxx"
 #include "SMDS_LinearEdge.hxx"
+#include "SMDS_Mesh0DElement.hxx"
 #include "SMDS_MeshFace.hxx"
 #include "SMDS_MeshVolume.hxx"
 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
-#include "SMESH_subMeshEventListener.hxx"
-#include "SMESH_Gen_i.hxx"
+#include "SMDS_SetIterator.hxx"
+#include "SMESHDS_Group.hxx"
+#include "SMESH_ControlsDef.hxx"
 #include "SMESH_Filter_i.hxx"
-#include "SMESH_subMesh_i.hxx"
+#include "SMESH_Gen_i.hxx"
 #include "SMESH_Group_i.hxx"
 #include "SMESH_PythonDump.hxx"
-#include "SMESH_ControlsDef.hxx"
+#include "SMESH_subMeshEventListener.hxx"
+#include "SMESH_subMesh_i.hxx"
 
 #include "utilities.h"
 #include "Utils_ExceptHandlers.hxx"
@@ -74,6 +75,7 @@
 
 using namespace std;
 using SMESH::TPythonDump;
+using SMESH::TVar;
 
 namespace {
 
@@ -93,7 +95,7 @@ namespace {
       myPreviewType = previewElements;
     }
     //!< Destructor
-    virtual ~TPreviewMesh() { delete _myMeshDS; }
+    virtual ~TPreviewMesh() { delete _myMeshDS; _myMeshDS = 0; }
     //!< Copy a set of elements
     void Copy(const TIDSortedElemSet & theElements,
               TIDSortedElemSet&        theCopyElements,
@@ -110,8 +112,12 @@ namespace {
         if ( type == theAvoidType ||
              ( theSelectType != SMDSAbs_All && type != theSelectType ))
           continue;
-
-        if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
+        const SMDS_MeshElement* anElemCopy;
+        if ( type == SMDSAbs_Node)
+          anElemCopy = Copy( cast2Node(anElem) );
+        else
+          anElemCopy = Copy( anElem );
+        if ( anElemCopy )
           theCopyElements.insert( theCopyElements.end(), anElemCopy );
       }
     }
@@ -166,8 +172,10 @@ namespace {
   struct TSearchersDeleter : public SMESH_subMeshEventListener
   {
     SMESH_Mesh* myMesh;
+    string      myMeshPartIOR;
     //!< Constructor
-    TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
+    TSearchersDeleter(): SMESH_subMeshEventListener( false, // won't be deleted by submesh
+                                                     "SMESH_MeshEditor_i::TSearchersDeleter"),
                          myMesh(0) {}
     //!< Delete theNodeSearcher
     static void Delete()
@@ -186,15 +194,16 @@ namespace {
       }
     }
     //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
-    void Set(SMESH_Mesh* mesh)
+    void Set(SMESH_Mesh* mesh, const string& meshPartIOR = string())
     {
-      if ( myMesh != mesh )
+      if ( myMesh != mesh || myMeshPartIOR != meshPartIOR)
       {
         if ( myMesh ) {
           Delete();
           Unset( myMesh );
         }
         myMesh = mesh;
+        myMeshPartIOR = meshPartIOR;
         if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
           const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
           TDependsOnMap::const_iterator sm;
@@ -234,7 +243,7 @@ namespace {
   }
   //================================================================================
   /*!
-   * \brief function for conversion long_array to TIDSortedElemSet
+   * \brief function for conversion of long_array to TIDSortedElemSet
    * \param IDs - array of IDs
    * \param aMesh - mesh
    * \param aMap - collection to fill
@@ -311,12 +320,64 @@ namespace {
         if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
           theNodeSet.insert( theNodeSet.end(), n);
     }
-    else {
+    else if ( SMESH::DownCast<SMESH_Mesh_i*>( theObject ))
+    {
+      SMDS_NodeIteratorPtr nIt = theMeshDS->nodesIterator();
+      while ( nIt->more( ))
+        if( const SMDS_MeshElement * elem = nIt->next() )
+          theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
+    }
+    else
+    {
       for(int i = 0; i < aElementsId->length(); i++)
         if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
           theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
     }
   }
+
+  //================================================================================
+  /*!
+   * \brief Returns elements connected to the given elements
+   */
+  //================================================================================
+
+  void getElementsAround(const TIDSortedElemSet& theElements,
+                         const SMESHDS_Mesh*     theMeshDS,
+                         TIDSortedElemSet&       theElementsAround)
+  {
+    if ( theElements.empty() ) return;
+
+    SMDSAbs_ElementType elemType    = (*theElements.begin())->GetType();
+    bool sameElemType = ( elemType == (*theElements.rbegin())->GetType() );
+    if ( sameElemType &&
+         theMeshDS->GetMeshInfo().NbElements( elemType ) == theElements.size() )
+      return; // all the elements are in theElements
+
+    if ( !sameElemType )
+      elemType = SMDSAbs_All;
+
+    TIDSortedElemSet visitedNodes;
+    TIDSortedElemSet::const_iterator elemIt = theElements.begin();
+    for ( ; elemIt != theElements.end(); ++elemIt )
+    {
+      const SMDS_MeshElement* e = *elemIt;
+      int i = e->NbCornerNodes();
+      while ( --i != -1 )
+      {
+        const SMDS_MeshNode* n = e->GetNode( i );
+        if ( visitedNodes.insert( n ).second )
+        {
+          SMDS_ElemIteratorPtr invIt = n->GetInverseElementIterator(elemType);
+          while ( invIt->more() )
+          {
+            const SMDS_MeshElement* elemAround = invIt->next();
+            if ( !theElements.count( elemAround ))
+              theElementsAround.insert( elemAround );
+          }
+        }
+      }
+    }
+  }
 }
 
 //=============================================================================
@@ -374,11 +435,14 @@ struct _IDSource : public POA_SMESH::SMESH_IDSource
   SMESH::long_array* GetIDs()      { return new SMESH::long_array( _ids ); }
   SMESH::long_array* GetMeshInfo() { return 0; }
   SMESH::SMESH_Mesh_ptr GetMesh()  { return SMESH::SMESH_Mesh::_duplicate( _mesh ); }
+  bool IsMeshInfoCorrect()         { return true; }
   SMESH::array_of_ElementType* GetTypes()
   {
     SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
-    types->length( 1 );
-    types[0] = _type;
+    if ( _ids.length() > 0 ) {
+      types->length( 1 );
+      types[0] = _type;
+    }
     return types._retn();
   }
 };
@@ -473,12 +537,14 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
   for ( int i = 0; i < seq.size(); i++ )
     IdList.push_back( seq[i] );
 
-  bool ret = anEditor.Remove( IdList, true );
+  int nbNodesBefore = myMesh->NbNodes();
+  anEditor.Remove( IdList, true );
   myMesh->GetMeshDS()->Modified();
   if ( IdList.size() )
     myMesh->SetIsModified( true );
+  int nbNodesAfter = myMesh->NbNodes();
 
-  return ret;
+  return nbNodesBefore - nbNodesAfter;
 }
 
 //=============================================================================
@@ -496,7 +562,7 @@ CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
 
   // Update Python script
   TPythonDump() << "nodeID = " << this << ".AddNode( "
-                << x << ", " << y << ", " << z << " )";
+                << TVar( x ) << ", " << TVar( y ) << ", " << TVar( z )<< " )";
 
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true ); // issue 0020693
@@ -603,6 +669,10 @@ CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
     elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
                                 nodes[4], nodes[5], nodes[6], nodes[7]);
   }
+  else if (NbNodes == 9) {
+    elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
+                                nodes[4], nodes[5], nodes[6], nodes[7], nodes[8] );
+  }
   else if (NbNodes > 2) {
     elem = GetMeshDS()->AddPolygonalFace(nodes);
   }
@@ -665,6 +735,9 @@ CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
   case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
                                         n[6],n[7],n[8],n[9]);
     break;
+  case 12:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
+                                        n[6],n[7],n[8],n[9],n[10],n[11]);
+    break;
   case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
                                         n[7],n[8],n[9],n[10],n[11],n[12]);
     break;
@@ -675,6 +748,11 @@ CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
                                         n[8],n[9],n[10],n[11],n[12],n[13],n[14],
                                         n[15],n[16],n[17],n[18],n[19]);
     break;
+  case 27:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
+                                        n[8],n[9],n[10],n[11],n[12],n[13],n[14],
+                                        n[15],n[16],n[17],n[18],n[19],
+                                        n[20],n[21],n[22],n[23],n[24],n[25],n[26]);
+    break;
   }
 
   // Update Python script
@@ -1076,7 +1154,7 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfE
 
   // Update Python script
   TPythonDump() << "isDone = " << this << ".TriToQuad( "
-                << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
+                << IDsOfElements << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )";
 
   ::SMESH_MeshEditor anEditor( myMesh );
 
@@ -1111,7 +1189,7 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr
 
   // Update Python script
   aTPythonDump << "isDone = " << this << ".TriToQuadObject("
-               << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
+               << theObject << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )";
 
   return isDone;
 }
@@ -1405,7 +1483,7 @@ SMESH_MeshEditor_i::smooth(const SMESH::long_array &              IDsOfElements,
   TPythonDump() << "isDone = " << this << "."
                 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
                 << IDsOfElements << ", "     << IDsOfFixedNodes << ", "
-                << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
+                << TVar( MaxNbOfIterations ) << ", " << TVar( MaxAspectRatio ) << ", "
                 << "SMESH.SMESH_MeshEditor."
                 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
                      "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
@@ -1440,7 +1518,7 @@ SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr              theObjec
   aTPythonDump << "isDone = " << this << "."
                << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
                << theObject << ", " << IDsOfFixedNodes << ", "
-               << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
+               << TVar( MaxNbOfIterations ) << ", " << TVar( MaxAspectRatio ) << ", "
                << "SMESH.SMESH_MeshEditor."
                << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
                     "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
@@ -1556,11 +1634,11 @@ void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElement
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".RotationSweep( "
-                  << theIDsOfElements << ", "
-                  << theAxis << ", "
-                  << theAngleInRadians << ", "
-                  << theNbOfSteps << ", "
-                  << theTolerance << " )";
+                  << theIDsOfElements          << ", "
+                  << theAxis                   << ", "
+                  << TVar( theAngleInRadians ) << ", "
+                  << TVar( theNbOfSteps      ) << ", "
+                  << TVar( theTolerance      ) << " )";
   }
   rotationSweep(theIDsOfElements,
                 theAxis,
@@ -1593,11 +1671,11 @@ SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfEle
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".RotationSweepMakeGroups( "
-                << theIDsOfElements << ", "
-                << theAxis << ", "
-                << theAngleInRadians << ", "
-                << theNbOfSteps << ", "
-                << theTolerance << " )";
+                << theIDsOfElements        << ", "
+                << theAxis                   << ", "
+                << TVar( theAngleInRadians ) << ", "
+                << TVar( theNbOfSteps      ) << ", "
+                << TVar( theTolerance      ) << " )";
   }
   return aGroups;
 }
@@ -1643,11 +1721,11 @@ void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObje
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".RotationSweepObject1D( "
-                  << theObject << ", "
-                  << theAxis << ", "
-                  << theAngleInRadians << ", "
-                  << theNbOfSteps << ", "
-                  << theTolerance << " )";
+                  << theObject                 << ", "
+                  << theAxis                   << ", "
+                  << TVar( theAngleInRadians ) << ", "
+                  << TVar( theNbOfSteps      ) << ", "
+                  << TVar( theTolerance      ) << " )";
   }
   SMESH::long_array_var anElementsId = theObject->GetIDs();
   rotationSweep(anElementsId,
@@ -1672,11 +1750,11 @@ void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObje
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".RotationSweepObject2D( "
-                  << theObject << ", "
-                  << theAxis << ", "
-                  << theAngleInRadians << ", "
-                  << theNbOfSteps << ", "
-                  << theTolerance << " )";
+                  << theObject                 << ", "
+                  << theAxis                   << ", "
+                  << TVar( theAngleInRadians ) << ", "
+                  << TVar( theNbOfSteps      ) << ", "
+                  << TVar( theTolerance      ) << " )";
   }
   SMESH::long_array_var anElementsId = theObject->GetIDs();
   rotationSweep(anElementsId,
@@ -1746,11 +1824,11 @@ SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr th
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".RotationSweepObject1DMakeGroups( "
-                << theObject << ", "
-                << theAxis << ", "
-                << theAngleInRadians << ", "
-                << theNbOfSteps << ", "
-                << theTolerance << " )";
+                << theObject                 << ", "
+                << theAxis                   << ", "
+                << TVar( theAngleInRadians ) << ", "
+                << TVar( theNbOfSteps )      << ", "
+                << TVar( theTolerance )      << " )";
   }
   return aGroups;
 }
@@ -1780,11 +1858,11 @@ SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr th
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".RotationSweepObject2DMakeGroups( "
-                << theObject << ", "
-                << theAxis << ", "
-                << theAngleInRadians << ", "
-                << theNbOfSteps << ", "
-                << theTolerance << " )";
+                << theObject                 << ", "
+                << theAxis                   << ", "
+                << TVar( theAngleInRadians ) << ", "
+                << TVar( theNbOfSteps      ) << ", "
+                << TVar( theTolerance      ) << " )";
   }
   return aGroups;
 }
@@ -1799,7 +1877,7 @@ SMESH::ListOfGroups*
 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
                                    const SMESH::DirStruct &  theStepVector,
                                    CORBA::Long               theNbOfSteps,
-                                   const bool                theMakeGroups,
+                                   bool                      theMakeGroups,
                                    const SMDSAbs_ElementType theElementType)
 {
   initData();
@@ -1815,22 +1893,28 @@ SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
     gp_Vec stepVec( P->x, P->y, P->z );
 
     TIDSortedElemSet* workElements = & elements;
-    TPreviewMesh      tmpMesh( SMDSAbs_Face );
-    SMESH_Mesh*       mesh = 0;
-    
+
+    SMDSAbs_ElementType aType = SMDSAbs_Face;
+    //::SMESH_MeshEditor::ExtrusionFlags aFlag = ::SMESH_MeshEditor::ExtrusionFlags::EXTRUSION_FLAG_BOUNDARY;
+    if (theElementType == SMDSAbs_Node)
+    {
+      aType = SMDSAbs_Edge;
+      //aFlag = ::SMESH_MeshEditor::ExtrusionFlags::EXTRUSION_FLAG_SEW;
+    }
+    TPreviewMesh      tmpMesh( aType );
+    SMESH_Mesh* mesh = myMesh;
+
     if ( myPreviewMode ) {
       SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
       tmpMesh.Copy( elements, copyElements, select, avoid );
       mesh = &tmpMesh;
       workElements = & copyElements;
-    }
-    else {
-       mesh = myMesh;
+      theMakeGroups = false;
     }
 
     TElemOfElemListMap aHystory;
     ::SMESH_MeshEditor anEditor( mesh );
-    ::SMESH_MeshEditor::PGroupIDs groupIds =
+    ::SMESH_MeshEditor::PGroupIDs groupIds = 
         anEditor.ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
 
     myMesh->GetMeshDS()->Modified();
@@ -1857,10 +1941,25 @@ void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElemen
   extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
   if (!myPreviewMode) {
     TPythonDump() << this << ".ExtrusionSweep( "
-                  << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
+                  << theIDsOfElements << ", " << theStepVector <<", " << TVar(theNbOfSteps) << " )";
   }
 }
 
+//=======================================================================
+//function : ExtrusionSweep0D
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::ExtrusionSweep0D(const SMESH::long_array & theIDsOfElements,
+                                          const SMESH::DirStruct &  theStepVector,
+                                          CORBA::Long               theNbOfSteps)
+{
+  extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false, SMDSAbs_Node );
+  if (!myPreviewMode) {
+    TPythonDump() << this << ".ExtrusionSweep0D( "
+                  << theIDsOfElements << ", " << theStepVector <<", " << TVar(theNbOfSteps)<< " )";
+  }
+}
 
 //=======================================================================
 //function : ExtrusionSweepObject
@@ -1879,6 +1978,23 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObjec
   }
 }
 
+//=======================================================================
+//function : ExtrusionSweepObject0D
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::ExtrusionSweepObject0D(SMESH::SMESH_IDSource_ptr theObject,
+                                                const SMESH::DirStruct &  theStepVector,
+                                                CORBA::Long               theNbOfSteps)
+{
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Node );
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".ExtrusionSweepObject0D( "
+                  << theObject << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
+  }
+}
+
 //=======================================================================
 //function : ExtrusionSweepObject1D
 //purpose  :
@@ -1892,7 +2008,7 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObj
   extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".ExtrusionSweepObject1D( "
-                  << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
+                  << theObject << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
   }
 }
 
@@ -1909,7 +2025,7 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObj
   extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".ExtrusionSweepObject2D( "
-                  << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
+                  << theObject << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
   }
 }
 
@@ -1930,7 +2046,29 @@ SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfEl
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".ExtrusionSweepMakeGroups( " << theIDsOfElements
-                << ", " << theStepVector <<", " << theNbOfSteps << " )";
+                << ", " << theStepVector <<", " << TVar( theNbOfSteps ) << " )";
+  }
+  return aGroups;
+}
+
+//=======================================================================
+//function : ExtrusionSweepMakeGroups0D
+//purpose  :
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionSweepMakeGroups0D(const SMESH::long_array& theIDsOfElements,
+                                               const SMESH::DirStruct&  theStepVector,
+                                               CORBA::Long              theNbOfSteps)
+{
+  TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
+
+  SMESH::ListOfGroups* aGroups = extrusionSweep(theIDsOfElements, theStepVector, theNbOfSteps, true,SMDSAbs_Node);
+
+  if (!myPreviewMode) {
+    DumpGroupsList(aPythonDump, aGroups);
+    aPythonDump << this << ".ExtrusionSweepMakeGroups0D( " << theIDsOfElements
+                << ", " << theStepVector <<", " << TVar( theNbOfSteps ) << " )";
   }
   return aGroups;
 }
@@ -1958,6 +2096,29 @@ SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr the
   return aGroups;
 }
 
+//=======================================================================
+//function : ExtrusionSweepObject0DMakeGroups
+//purpose  :
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionSweepObject0DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                                     const SMESH::DirStruct&   theStepVector,
+                                                     CORBA::Long               theNbOfSteps)
+{
+  TPythonDump aPythonDump; // it is here to prevent dump of GetGroups()
+
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  SMESH::ListOfGroups * aGroups = extrusionSweep(anElementsId, theStepVector,
+                                                 theNbOfSteps, true, SMDSAbs_Node);
+  if (!myPreviewMode) {
+    DumpGroupsList(aPythonDump, aGroups);
+    aPythonDump << this << ".ExtrusionSweepObject0DMakeGroups( " << theObject
+                << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
+  }
+  return aGroups;
+}
+
 //=======================================================================
 //function : ExtrusionSweepObject1DMakeGroups
 //purpose  :
@@ -1976,7 +2137,7 @@ SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr t
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( " << theObject
-                << ", " << theStepVector << ", " << theNbOfSteps << " )";
+                << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
   }
   return aGroups;
 }
@@ -1999,7 +2160,7 @@ SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr t
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( " << theObject
-                << ", " << theStepVector << ", " << theNbOfSteps << " )";
+                << ", " << theStepVector << ", " << TVar( theNbOfSteps ) << " )";
   }
   return aGroups;
 }
@@ -2208,7 +2369,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
                                         CORBA::Boolean             LinearVariation,
                                         CORBA::Boolean             HasRefPoint,
                                         const SMESH::PointStruct&  RefPoint,
-                                        const bool                 MakeGroups,
+                                        bool                       MakeGroups,
                                         const SMDSAbs_ElementType  ElementType,
                                         SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
 {
@@ -2233,7 +2394,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
 
   TIDSortedElemSet* workElements = &elements;
   TPreviewMesh      tmpMesh( SMDSAbs_Face );
-  SMESH_Mesh*       mesh = 0;
+  SMESH_Mesh*       mesh = myMesh;
 
   if ( myPreviewMode )
   {
@@ -2241,17 +2402,14 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
     tmpMesh.Copy( elements, copyElements, select, avoid );
     mesh = &tmpMesh;
     workElements = & copyElements;
-  }
-  else
-  {
-    mesh = myMesh;
+    MakeGroups = false;
   }
 
   ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::Extrusion_Error error;
 
-  SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
-  if(aMeshImp) {
+  if ( SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path ))
+  {
     // path as mesh
     SMDS_MeshNode* aNodeStart =
       (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
@@ -2264,36 +2422,34 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
                                           HasRefPoint, refPnt, MakeGroups );
     myMesh->GetMeshDS()->Modified();
   }
-  else {
-    SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
-    if(aSubMeshImp) {
-      // path as submesh
-      SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
-      aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
-      SMDS_MeshNode* aNodeStart =
-        (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
-      if ( !aNodeStart ) {
-        Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
-        return EmptyGr;
-      }
-      SMESH_subMesh* aSubMesh =
-        aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
-      error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart,
-                                            HasAngles, angles, LinearVariation,
-                                            HasRefPoint, refPnt, MakeGroups );
-      myMesh->GetMeshDS()->Modified();
-    }
-    else {
-      SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
-      if(aGroupImp) {
-        // path as group of 1D elements
-      }
-      else {
-        // invalid path
-        Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
-        return EmptyGr;
-      }
+  else if ( SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path ))
+  {
+    // path as submesh
+    SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
+    aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
+    SMDS_MeshNode* aNodeStart =
+      (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
+    if ( !aNodeStart ) {
+      Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
+      return EmptyGr;
     }
+    SMESH_subMesh* aSubMesh =
+      aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
+    error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart,
+                                          HasAngles, angles, LinearVariation,
+                                          HasRefPoint, refPnt, MakeGroups );
+    myMesh->GetMeshDS()->Modified();
+  }
+  else if ( SMESH::DownCast<SMESH_Group_i*>( Path ))
+  {
+    // path as group of 1D elements
+    // ????????
+  }
+  else
+  {
+    // invalid path
+    Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+    return EmptyGr;
   }
 
   storeResult(anEditor);
@@ -2734,17 +2890,17 @@ ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr  Object,
       aPythonDump << "error";
 
     aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
-                << Object      << ", "
-                << Path        << ", "
-                << NodeStart   << ", "
-                << HasAngles   << ", "
-                << Angles      << ", "
+                << Object          << ", "
+                << Path            << ", "
+                << NodeStart       << ", "
+                << HasAngles       << ", "
+                << TVar( Angles )  << ", "
                 << LinearVariation << ", "
-                << HasRefPoint << ", "
+                << HasRefPoint     << ", "
                 << "SMESH.PointStruct( "
-                << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
-                << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
-                << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
+                << TVar( HasRefPoint ? RefPoint.x : 0 ) << ", "
+                << TVar( HasRefPoint ? RefPoint.y : 0 ) << ", "
+                << TVar( HasRefPoint ? RefPoint.z : 0 ) << " ), "
                 << MakeGroups << ", "
                 << ElemType << " )";
   }
@@ -2791,17 +2947,17 @@ ExtrusionAlongPathX(const SMESH::long_array&   IDsOfElements,
       aPythonDump <<"error";
 
     aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
-                << IDsOfElements << ", "
-                << Path        << ", "
-                << NodeStart   << ", "
-                << HasAngles   << ", "
-                << Angles      << ", "
+                << IDsOfElements   << ", "
+                << Path            << ", "
+                << NodeStart       << ", "
+                << HasAngles       << ", "
+                << TVar( Angles )  << ", "
                 << LinearVariation << ", "
-                << HasRefPoint << ", "
+                << HasRefPoint     << ", "
                 << "SMESH.PointStruct( "
-                << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
-                << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
-                << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
+                << TVar( HasRefPoint ? RefPoint.x : 0 ) << ", "
+                << TVar( HasRefPoint ? RefPoint.y : 0 ) << ", "
+                << TVar( HasRefPoint ? RefPoint.z : 0 ) << " ), "
                 << MakeGroups << ", "
                 << ElemType << " )";
   }
@@ -2891,7 +3047,7 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet &                  theElements,
                            const SMESH::AxisStruct &           theAxis,
                            SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
                            CORBA::Boolean                      theCopy,
-                           const bool                          theMakeGroups,
+                           bool                                theMakeGroups,
                            ::SMESH_Mesh*                       theTargetMesh)
 {
   initData();
@@ -2899,6 +3055,9 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet &                  theElements,
   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
 
+  if ( theTargetMesh )
+    theCopy = false;
+
   gp_Trsf aTrsf;
   switch ( theMirrorType ) {
   case  SMESH::SMESH_MeshEditor::POINT:
@@ -2911,21 +3070,23 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet &                  theElements,
     aTrsf.SetMirror( gp_Ax2( P, V ));
   }
 
-  TIDSortedElemSet copyElements;
+  TIDSortedElemSet  copyElements;
   TPreviewMesh      tmpMesh;
-  TIDSortedElemSet* workElements = 0;
-  SMESH_Mesh*       mesh = 0;
+  TIDSortedElemSet* workElements = & theElements;
+  SMESH_Mesh*       mesh = myMesh;
 
   if ( myPreviewMode )
   {
     tmpMesh.Copy( theElements, copyElements);
+    if ( !theCopy && !theTargetMesh )
+    {
+      TIDSortedElemSet elemsAround, elemsAroundCopy;
+      getElementsAround( theElements, GetMeshDS(), elemsAround );
+      tmpMesh.Copy( elemsAround, elemsAroundCopy);
+    }
     mesh = &tmpMesh;
     workElements = & copyElements;
-  }
-  else
-  {
-    mesh = myMesh;
-    workElements = & theElements;
+    theMakeGroups = false;
   }
 
   ::SMESH_MeshEditor anEditor( mesh );
@@ -2933,13 +3094,20 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet &                  theElements,
       anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
 
   if(theCopy || myPreviewMode)
-    storeResult(anEditor);
-  else
+    storeResult(anEditor); // store preview data or new elements
+
+  if ( !myPreviewMode )
+  {
+    if ( theTargetMesh )
+    {
+      theTargetMesh->GetMeshDS()->Modified();
+    }
+    else
     {
       myMesh->GetMeshDS()->Modified();
       myMesh->SetIsModified( true );
     }
-
+  }
   return theMakeGroups ? getGroups(groupIds.get()) : 0;
 }
 
@@ -2955,10 +3123,10 @@ void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElem
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".Mirror( "
-                  << theIDsOfElements << ", "
-                  << theAxis          << ", "
+                  << theIDsOfElements              << ", "
+                  << theAxis                       << ", "
                   << mirrorTypeName(theMirrorType) << ", "
-                  << theCopy          << " )";
+                  << theCopy                       << " )";
   }
   if ( theIDsOfElements.length() > 0 )
   {
@@ -2981,10 +3149,10 @@ void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObj
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".MirrorObject( "
-                  << theObject << ", "
-                  << theAxis   << ", "
+                  << theObject                     << ", "
+                  << theAxis                       << ", "
                   << mirrorTypeName(theMirrorType) << ", "
-                  << theCopy   << " )";
+                  << theCopy                       << " )";
   }
   TIDSortedElemSet elements;
 
@@ -3016,8 +3184,8 @@ SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array&            theIDsO
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".MirrorMakeGroups( "
-                << theIDsOfElements << ", "
-                << theMirror << ", "
+                << theIDsOfElements              << ", "
+                << theMirror                     << ", "
                 << mirrorTypeName(theMirrorType) << " )";
   }
   return aGroups;
@@ -3044,8 +3212,8 @@ SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr           t
   {
     DumpGroupsList(aPythonDump,aGroups);
     aPythonDump << this << ".MirrorObjectMakeGroups( "
-                << theObject << ", "
-                << theMirror << ", "
+                << theObject                     << ", "
+                << theMirror                     << ", "
                 << mirrorTypeName(theMirrorType) << " )";
   }
   return aGroups;
@@ -3083,11 +3251,11 @@ SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array&            theIDsOfE
 
     if (!myPreviewMode) {
       pydump << mesh << " = " << this << ".MirrorMakeMesh( "
-             << theIDsOfElements << ", "
-             << theMirror   << ", "
+             << theIDsOfElements              << ", "
+             << theMirror                     << ", "
              << mirrorTypeName(theMirrorType) << ", "
-             << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theCopyGroups                 << ", '"
+             << theMeshName                   << "' )";
     }
   }
 
@@ -3129,11 +3297,11 @@ SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr           the
     }
     if (!myPreviewMode) {
       pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
-             << theObject << ", "
-             << theMirror   << ", "
+             << theObject                     << ", "
+             << theMirror                     << ", "
              << mirrorTypeName(theMirrorType) << ", "
-             << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theCopyGroups                 << ", '"
+             << theMeshName                   << "' )";
     }
   }
 
@@ -3153,30 +3321,35 @@ SMESH::ListOfGroups*
 SMESH_MeshEditor_i::translate(TIDSortedElemSet        & theElements,
                               const SMESH::DirStruct &  theVector,
                               CORBA::Boolean            theCopy,
-                              const bool                theMakeGroups,
+                              bool                      theMakeGroups,
                               ::SMESH_Mesh*             theTargetMesh)
 {
   initData();
 
+  if ( theTargetMesh )
+    theCopy = false;
+
   gp_Trsf aTrsf;
   const SMESH::PointStruct * P = &theVector.PS;
   aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
 
-  TIDSortedElemSet copyElements;
+  TIDSortedElemSet  copyElements;
+  TIDSortedElemSet* workElements = &theElements;
   TPreviewMesh      tmpMesh;
-  TIDSortedElemSet* workElements = 0;
-  SMESH_Mesh*       mesh = 0;
+  SMESH_Mesh*       mesh = myMesh;
 
   if ( myPreviewMode )
   {
     tmpMesh.Copy( theElements, copyElements);
+    if ( !theCopy && !theTargetMesh )
+    {
+      TIDSortedElemSet elemsAround, elemsAroundCopy;
+      getElementsAround( theElements, GetMeshDS(), elemsAround );
+      tmpMesh.Copy( elemsAround, elemsAroundCopy);
+    }
     mesh = &tmpMesh;
     workElements = & copyElements;
-  }
-  else
-  {
-    mesh = myMesh;
-    workElements = & theElements;
+    theMakeGroups = false;
   }
 
   ::SMESH_MeshEditor anEditor( mesh );
@@ -3185,11 +3358,19 @@ SMESH_MeshEditor_i::translate(TIDSortedElemSet        & theElements,
 
   if(theCopy || myPreviewMode)
     storeResult(anEditor);
-  else
+
+  if ( !myPreviewMode )
+  {
+    if ( theTargetMesh )
+    {
+      theTargetMesh->GetMeshDS()->Modified();
+    }
+    else
     {
       myMesh->GetMeshDS()->Modified();
       myMesh->SetIsModified( true );
     }
+  }
 
   return theMakeGroups ? getGroups(groupIds.get()) : 0;
 }
@@ -3206,8 +3387,8 @@ void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
   if (!myPreviewMode) {
     TPythonDump() << this << ".Translate( "
                   << theIDsOfElements << ", "
-                  << theVector << ", "
-                  << theCopy << " )";
+                  << theVector        << ", "
+                  << theCopy          << " )";
   }
   if (theIDsOfElements.length()) {
     TIDSortedElemSet elements;
@@ -3229,7 +3410,7 @@ void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
     TPythonDump() << this << ".TranslateObject( "
                   << theObject << ", "
                   << theVector << ", "
-                  << theCopy << " )";
+                  << theCopy   << " )";
   }
   TIDSortedElemSet elements;
 
@@ -3260,7 +3441,7 @@ SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElement
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".TranslateMakeGroups( "
                 << theIDsOfElements << ", "
-                << theVector << " )";
+                << theVector        << " )";
   }
   return aGroups;
 }
@@ -3323,9 +3504,9 @@ SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
     if ( !myPreviewMode ) {
       pydump << mesh << " = " << this << ".TranslateMakeMesh( "
              << theIDsOfElements << ", "
-             << theVector   << ", "
-             << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theVector        << ", "
+             << theCopyGroups    << ", '"
+             << theMeshName      << "' )";
     }
   }
 
@@ -3365,10 +3546,10 @@ SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
     }
     if ( !myPreviewMode ) {
       pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
-             << theObject << ", "
-             << theVector   << ", "
+             << theObject     << ", "
+             << theVector     << ", "
              << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theMeshName   << "' )";
     }
   }
 
@@ -3389,31 +3570,36 @@ SMESH_MeshEditor_i::rotate(TIDSortedElemSet &        theElements,
                            const SMESH::AxisStruct & theAxis,
                            CORBA::Double             theAngle,
                            CORBA::Boolean            theCopy,
-                           const bool                theMakeGroups,
+                           bool                      theMakeGroups,
                            ::SMESH_Mesh*             theTargetMesh)
 {
   initData();
 
+  if ( theTargetMesh )
+    theCopy = false;
+
   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
 
   gp_Trsf aTrsf;
   aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
 
-  TIDSortedElemSet copyElements;
+  TIDSortedElemSet  copyElements;
+  TIDSortedElemSet* workElements = &theElements;
   TPreviewMesh      tmpMesh;
-  TIDSortedElemSet* workElements = 0;
-  SMESH_Mesh*       mesh = 0;
+  SMESH_Mesh*       mesh = myMesh;
 
   if ( myPreviewMode ) {
     tmpMesh.Copy( theElements, copyElements );
+    if ( !theCopy && !theTargetMesh )
+    {
+      TIDSortedElemSet elemsAround, elemsAroundCopy;
+      getElementsAround( theElements, GetMeshDS(), elemsAround );
+      tmpMesh.Copy( elemsAround, elemsAroundCopy);
+    }
     mesh = &tmpMesh;
     workElements = &copyElements;
-  }
-  else
-  {
-    mesh = myMesh;
-    workElements=&theElements;
+    theMakeGroups = false;
   }
 
   ::SMESH_MeshEditor anEditor( mesh );
@@ -3422,11 +3608,19 @@ SMESH_MeshEditor_i::rotate(TIDSortedElemSet &        theElements,
 
   if(theCopy || myPreviewMode)
     storeResult(anEditor);
-  else
+
+  if ( !myPreviewMode )
+  {
+    if ( theTargetMesh )
+    {
+      theTargetMesh->GetMeshDS()->Modified();
+    }
+    else
     {
       myMesh->GetMeshDS()->Modified();
       myMesh->SetIsModified( true );
     }
+  }
 
   return theMakeGroups ? getGroups(groupIds.get()) : 0;
 }
@@ -3444,9 +3638,9 @@ void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
   if (!myPreviewMode) {
     TPythonDump() << this << ".Rotate( "
                   << theIDsOfElements << ", "
-                  << theAxis << ", "
-                  << theAngle << ", "
-                  << theCopy << " )";
+                  << theAxis          << ", "
+                  << TVar( theAngle ) << ", "
+                  << theCopy          << " )";
   }
   if (theIDsOfElements.length() > 0)
   {
@@ -3468,10 +3662,10 @@ void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".RotateObject( "
-                  << theObject << ", "
-                  << theAxis << ", "
-                  << theAngle << ", "
-                  << theCopy << " )";
+                  << theObject        << ", "
+                  << theAxis          << ", "
+                  << TVar( theAngle ) << ", "
+                  << theCopy          << " )";
   }
   TIDSortedElemSet elements;
   bool emptyIfIsMesh = myPreviewMode ? false : true;
@@ -3502,8 +3696,8 @@ SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".RotateMakeGroups( "
                 << theIDsOfElements << ", "
-                << theAxis << ", "
-                << theAngle << " )";
+                << theAxis          << ", "
+                << TVar( theAngle ) << " )";
   }
   return aGroups;
 }
@@ -3528,9 +3722,9 @@ SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".RotateObjectMakeGroups( "
-                << theObject << ", "
-                << theAxis << ", "
-                << theAngle << " )";
+                << theObject        << ", "
+                << theAxis          << ", "
+                << TVar( theAngle ) << " )";
   }
   return aGroups;
 }
@@ -3568,11 +3762,11 @@ SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
     }
     if ( !myPreviewMode ) {
       pydump << mesh << " = " << this << ".RotateMakeMesh( "
-             << theIDsOfElements << ", "
-             << theAxis << ", "
-             << theAngleInRadians   << ", "
-             << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theIDsOfElements          << ", "
+             << theAxis                   << ", "
+             << TVar( theAngleInRadians ) << ", "
+             << theCopyGroups             << ", '"
+             << theMeshName               << "' )";
     }
   }
 
@@ -3615,11 +3809,11 @@ SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
     }
     if ( !myPreviewMode ) {
       pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
-             << theObject << ", "
-             << theAxis << ", "
-             << theAngleInRadians   << ", "
-             << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theObject                 << ", "
+             << theAxis                   << ", "
+             << TVar( theAngleInRadians ) << ", "
+             << theCopyGroups             << ", '"
+             << theMeshName               << "' )";
     }
   }
 
@@ -3640,7 +3834,7 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr  theObject,
                           const SMESH::PointStruct&  thePoint,
                           const SMESH::double_array& theScaleFact,
                           CORBA::Boolean             theCopy,
-                          const bool                 theMakeGroups,
+                          bool                       theMakeGroups,
                           ::SMESH_Mesh*              theTargetMesh)
 {
   initData();
@@ -3649,36 +3843,42 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr  theObject,
   if ( theScaleFact.length() == 2 )
     THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
 
+  if ( theTargetMesh )
+    theCopy = false;
+
   TIDSortedElemSet elements;
   bool emptyIfIsMesh = myPreviewMode ? false : true;
   if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, emptyIfIsMesh))
     return 0;
 
-  vector<double> S(3);
-  S[0] = theScaleFact[0];
-  S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
-  S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
+  double S[3] = {
+    theScaleFact[0],
+    (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1],
+    (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2],
+  };
   double tol = std::numeric_limits<double>::max();
   gp_Trsf aTrsf;
   aTrsf.SetValues( S[0], 0,    0,    thePoint.x * (1-S[0]),
                    0,    S[1], 0,    thePoint.y * (1-S[1]),
                    0,    0,    S[2], thePoint.z * (1-S[2]),   tol, tol);
 
-  TIDSortedElemSet copyElements;
+  TIDSortedElemSet  copyElements;
   TPreviewMesh      tmpMesh;
-  TIDSortedElemSet* workElements = 0;
-  SMESH_Mesh*       mesh = 0;
+  TIDSortedElemSet* workElements = &elements;
+  SMESH_Mesh*       mesh = myMesh;
   
   if ( myPreviewMode )
   {
     tmpMesh.Copy( elements, copyElements);
+    if ( !theCopy && !theTargetMesh )
+    {
+      TIDSortedElemSet elemsAround, elemsAroundCopy;
+      getElementsAround( elements, GetMeshDS(), elemsAround );
+      tmpMesh.Copy( elemsAround, elemsAroundCopy);
+    }
     mesh = &tmpMesh;
     workElements = & copyElements;
-  }
-  else
-  {
-    mesh = myMesh;
-    workElements = & elements;
+    theMakeGroups = false;
   }
 
   ::SMESH_MeshEditor anEditor( mesh );
@@ -3687,11 +3887,20 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr  theObject,
 
   if(theCopy || myPreviewMode )
     storeResult(anEditor);
-  else
+
+  if ( !myPreviewMode )
+  {
+    if ( theTargetMesh )
+    {
+      theTargetMesh->GetMeshDS()->Modified();
+    }
+    else
     {
       myMesh->GetMeshDS()->Modified();
       myMesh->SetIsModified( true );
     }
+  }
+
   return theMakeGroups ? getGroups(groupIds.get()) : 0;
 }
 
@@ -3707,11 +3916,10 @@ void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr  theObject,
 {
   if ( !myPreviewMode ) {
     TPythonDump() << this << ".Scale( "
-                  << theObject << ", "
-                  << "SMESH.PointStruct( "  << thePoint.x << ", "
-                  << thePoint.y << ", " << thePoint.z << " ) ,"
-                  << theScaleFact << ", "
-                  << theCopy << " )";
+                  << theObject            << ", "
+                  << thePoint             << ", "
+                  << TVar( theScaleFact ) << ", "
+                  << theCopy              << " )";
   }
   scale(theObject, thePoint, theScaleFact, theCopy, false);
 }
@@ -3733,10 +3941,9 @@ SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr  theObject,
   if (!myPreviewMode) {
     DumpGroupsList(aPythonDump, aGroups);
     aPythonDump << this << ".Scale("
-                << theObject << ","
-                << "SMESH.PointStruct(" <<thePoint.x << ","
-                << thePoint.y << "," << thePoint.z << "),"
-                << theScaleFact << ",True,True)";
+                << theObject            << ","
+                << thePoint             << ","
+                << TVar( theScaleFact ) << ",True,True)";
   }
   return aGroups;
 }
@@ -3770,12 +3977,11 @@ SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr  theObject,
     }
     if ( !myPreviewMode )
       pydump << mesh << " = " << this << ".ScaleMakeMesh( "
-             << theObject << ", "
-             << "SMESH.PointStruct( "  << thePoint.x << ", "
-             << thePoint.y << ", " << thePoint.z << " ) ,"
-             << theScaleFact << ", "
-             << theCopyGroups << ", '"
-             << theMeshName << "' )";
+             << theObject            << ", "
+             << thePoint             << ", "
+             << TVar( theScaleFact ) << ", "
+             << theCopyGroups        << ", '"
+             << theMeshName          << "' )";
   }
 
   // dump "GetGroups"
@@ -4036,6 +4242,8 @@ void SMESH_MeshEditor_i::MergeEqualElements()
   ::SMESH_MeshEditor anEditor( myMesh );
   anEditor.MergeEqualElements();
 
+  myMesh->GetMeshDS()->Modified();
+
   TPythonDump() << this << ".MergeEqualElements()";
 }
 
@@ -4088,7 +4296,7 @@ CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long   NodeID,
   {
     // Update Python script
     TPythonDump() << "isDone = " << this << ".MoveNode( "
-                  << NodeID << ", " << x << ", " << y << ", " << z << " )";
+                  << NodeID << ", " << TVar(x) << ", " << TVar(y) << ", " << TVar(z) << " )";
     myMesh->GetMeshDS()->Modified();
     myMesh->SetIsModified( true );
   }
@@ -4224,7 +4432,7 @@ SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double      x,
     res[i] = foundElems[i]->GetID();
 
   if ( !myPreviewMode ) // call from tui
-    TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
+    TPythonDump() << "res = " << this << ".FindElementsByPoint( "
                   << x << ", "
                   << y << ", "
                   << z << ", "
@@ -4233,6 +4441,77 @@ SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double      x,
   return res._retn();
 }
 
+//=======================================================================
+//function : FindAmongElementsByPoint
+//purpose  : Searching among the given elements, return elements of given type 
+//           where the given point is IN or ON.
+//           'ALL' type means elements of any type excluding nodes
+//=======================================================================
+
+SMESH::long_array*
+SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementIDs,
+                                             CORBA::Double             x,
+                                             CORBA::Double             y,
+                                             CORBA::Double             z,
+                                             SMESH::ElementType        type)
+{
+  SMESH::long_array_var res = new SMESH::long_array;
+  
+  SMESH::array_of_ElementType_var types = elementIDs->GetTypes();
+  if ( types->length() == 1 && // a part contains only nodes or 0D elements
+       ( types[0] == SMESH::NODE || types[0] == SMESH::ELEM0D ) &&
+       type != types[0] ) // but search of elements of dim > 0
+    return res._retn();
+
+  if ( SMESH::DownCast<SMESH_Mesh_i*>( elementIDs )) // elementIDs is the whole mesh 
+    return FindElementsByPoint( x,y,z, type );
+
+  string partIOR = SMESH_Gen_i::GetORB()->object_to_string( elementIDs );
+  if ( SMESH_Group_i* group_i = SMESH::DownCast<SMESH_Group_i*>( elementIDs ))
+    // take into account passible group modification
+    partIOR += SMESH_Comment( ((SMESHDS_Group*)group_i->GetGroupDS())->SMDSGroup().Tic() );
+  partIOR += SMESH_Comment( type );
+
+  TIDSortedElemSet elements; // elems should live until FindElementsByPoint() finishes
+
+  theSearchersDeleter.Set( myMesh, partIOR );
+  if ( !theElementSearcher )
+  {
+    // create a searcher from elementIDs
+    SMESH::SMESH_Mesh_var mesh = elementIDs->GetMesh();
+    SMESHDS_Mesh* meshDS = SMESH::DownCast<SMESH_Mesh_i*>( mesh )->GetImpl().GetMeshDS();
+
+    if ( !idSourceToSet( elementIDs, meshDS, elements,
+                         SMDSAbs_ElementType(type), /*emptyIfIsMesh=*/true))
+      return res._retn();
+
+    typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
+    SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() ));
+
+    ::SMESH_MeshEditor anEditor( myMesh );
+    theElementSearcher = anEditor.GetElementSearcher(elemsIt);
+  }
+
+  vector< const SMDS_MeshElement* > foundElems;
+
+  theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
+                                           SMDSAbs_ElementType( type ),
+                                           foundElems);
+  res->length( foundElems.size() );
+  for ( int i = 0; i < foundElems.size(); ++i )
+    res[i] = foundElems[i]->GetID();
+
+  if ( !myPreviewMode ) // call from tui
+    TPythonDump() << "res = " << this << ".FindAmongElementsByPoint( "
+                  << elementIDs << ", "
+                  << x << ", "
+                  << y << ", "
+                  << z << ", "
+                  << type << " )";
+
+  return res._retn();
+  
+}
 //=======================================================================
 //function : GetPointState
 //purpose  : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
@@ -4728,6 +5007,74 @@ CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
     myMesh->SetIsModified( true );
   return isDone;
 }
+//================================================================================
+/*!
+ * \brief Makes a part of the mesh quadratic
+ */
+//================================================================================
+
+void SMESH_MeshEditor_i::ConvertToQuadraticObject(CORBA::Boolean            theForce3d,
+                                                  SMESH::SMESH_IDSource_ptr theObject)
+  throw (SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  TPythonDump pyDump;
+  TIDSortedElemSet elems;
+  if ( idSourceToSet( theObject, GetMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true ))
+  {
+    if ( elems.empty() )
+    {
+      ConvertToQuadratic( theForce3d );
+    }
+    else if ( (*elems.begin())->GetType() == SMDSAbs_Node )
+    {
+      THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM);
+    }
+    else
+    {
+      ::SMESH_MeshEditor anEditor( myMesh );
+      anEditor.ConvertToQuadratic(theForce3d, elems);
+    }
+  }
+  myMesh->GetMeshDS()->Modified();
+  myMesh->SetIsModified( true );
+
+  pyDump << this << ".ConvertToQuadraticObject( "<<theForce3d<<", "<<theObject<<" )";
+}
+
+//================================================================================
+/*!
+ * \brief Makes a part of the mesh linear
+ */
+//================================================================================
+
+void SMESH_MeshEditor_i::ConvertFromQuadraticObject(SMESH::SMESH_IDSource_ptr theObject)
+  throw (SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  TPythonDump pyDump;
+  TIDSortedElemSet elems;
+  if ( idSourceToSet( theObject, GetMeshDS(), elems, SMDSAbs_All, /*emptyIfIsMesh=*/true ))
+  {
+    if ( elems.empty() )
+    {
+      ConvertFromQuadratic();
+    }
+    else if ( (*elems.begin())->GetType() == SMDSAbs_Node )
+    {
+      THROW_SALOME_CORBA_EXCEPTION("Group of nodes is not allowed", SALOME::BAD_PARAM);
+    }
+    else
+    {
+      ::SMESH_MeshEditor anEditor( myMesh );
+      anEditor.ConvertFromQuadratic(elems);
+    }
+  }
+  myMesh->GetMeshDS()->Modified();
+  myMesh->SetIsModified( true );
+
+  pyDump << this << ".ConvertFromQuadraticObject( "<<theObject<<" )";
+}
 
 //=======================================================================
 //function : makeMesh
@@ -4910,14 +5257,15 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr th
  * \return a new group with newly created nodes
  * \sa DoubleNodeGroup()
  */
-SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
-                                                               SMESH::SMESH_GroupBase_ptr theModifiedElems )
+SMESH::SMESH_Group_ptr
+SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
+                                        SMESH::SMESH_GroupBase_ptr theModifiedElems )
 {
-  if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
-    return false;
-
   SMESH::SMESH_Group_var aNewGroup;
 
+  if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
+    return aNewGroup._retn();
+
   // Duplicate nodes
   SMESH::long_array_var aNodes = theNodes->GetListOfID();
   SMESH::long_array_var aModifiedElems;
@@ -4931,7 +5279,6 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_Grou
   TPythonDump pyDump; // suppress dump by the next line
 
   bool aResult = DoubleNodes( aNodes, aModifiedElems );
-
   if ( aResult )
   {
     // Create group with newly created nodes
@@ -4941,11 +5288,12 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_Grou
       string aNewName = generateGroupName(anUnindexedName + "_double");
       aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
       aNewGroup->Add(anIds);
+      pyDump << aNewGroup << " = ";
     }
   }
 
-  pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
-    << theModifiedElems << " )";
+  pyDump << this << ".DoubleNodeGroupNew( " << theNodes << ", "
+         << theModifiedElems << " )";
 
   return aNewGroup._retn();
 }
@@ -5018,8 +5366,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& t
  */
 //================================================================================
 
-SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::ListOfGroups& theNodes,
-                                                                const SMESH::ListOfGroups& theModifiedElems )
+SMESH::SMESH_Group_ptr
+SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::ListOfGroups& theNodes,
+                                         const SMESH::ListOfGroups& theModifiedElems )
 {
   SMESH::SMESH_Group_var aNewGroup;
 
@@ -5036,11 +5385,12 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupsNew( const SMESH::Lis
       string aNewName = generateGroupName(anUnindexedName + "_double");
       aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
       aNewGroup->Add(anIds);
+      pyDump << aNewGroup << " = ";
     }
   }
 
-  pyDump << "createdNodes = " << this << ".DoubleNodeGroupsNew( " << theNodes << ", "
-    << theModifiedElems << " )";
+  pyDump << this << ".DoubleNodeGroupsNew( " << theNodes << ", "
+         << theModifiedElems << " )";
 
   return aNewGroup._retn();
 }
@@ -5184,14 +5534,40 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_pt
  * \return a new group with newly created elements
  * \sa DoubleNodeElemGroup()
  */
-SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
-                                                                  SMESH::SMESH_GroupBase_ptr theNodesNot,
-                                                                  SMESH::SMESH_GroupBase_ptr theAffectedElems)
+SMESH::SMESH_Group_ptr
+SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
+                                           SMESH::SMESH_GroupBase_ptr theNodesNot,
+                                           SMESH::SMESH_GroupBase_ptr theAffectedElems)
 {
-  if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
-    return false;
+  TPythonDump pyDump;
+  SMESH::ListOfGroups_var twoGroups = DoubleNodeElemGroup2New( theElems,
+                                                               theNodesNot,
+                                                               theAffectedElems,
+                                                               true, false );
+  SMESH::SMESH_GroupBase_var baseGroup = twoGroups[0].in();
+  SMESH::SMESH_Group_var     elemGroup = SMESH::SMESH_Group::_narrow( baseGroup );
 
-  SMESH::SMESH_Group_var aNewGroup;
+  pyDump << elemGroup << " = " << this << ".DoubleNodeElemGroupNew( "
+         << theElems         << ", "
+         << theNodesNot      << ", "
+         << theAffectedElems << " )";
+
+  return elemGroup._retn();
+}
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::DoubleNodeElemGroup2New(SMESH::SMESH_GroupBase_ptr theElems,
+                                            SMESH::SMESH_GroupBase_ptr theNodesNot,
+                                            SMESH::SMESH_GroupBase_ptr theAffectedElems,
+                                            CORBA::Boolean             theElemGroupNeeded,
+                                            CORBA::Boolean             theNodeGroupNeeded)
+{
+  SMESH::SMESH_Group_var aNewElemGroup, aNewNodeGroup;
+  SMESH::ListOfGroups_var aTwoGroups = new SMESH::ListOfGroups();
+  aTwoGroups->length( 2 );
+
+  if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
+    return aTwoGroups._retn();
 
   initData();
 
@@ -5207,25 +5583,49 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_G
   bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
 
   storeResult( aMeshEditor) ;
+  myMesh->GetMeshDS()->Modified();
+
+  TPythonDump pyDump;
 
-  if ( aResult ) {
+  if ( aResult )
+  {
     myMesh->SetIsModified( true );
 
     // Create group with newly created elements
-    SMESH::long_array_var anIds = GetLastCreatedElems();
-    if (anIds->length() > 0) {
+    CORBA::String_var elemGroupName = theElems->GetName();
+    string aNewName = generateGroupName( string(elemGroupName.in()) + "_double");
+    if ( !aMeshEditor.GetLastCreatedElems().IsEmpty() && theElemGroupNeeded )
+    {
+      SMESH::long_array_var anIds = GetLastCreatedElems();
       SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
-      string anUnindexedName (theElems->GetName());
-      string aNewName = generateGroupName(anUnindexedName + "_double");
-      aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
-      aNewGroup->Add(anIds);
+      aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
+      aNewElemGroup->Add(anIds);
+    }
+    if ( !aMeshEditor.GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded )
+    {
+      SMESH::long_array_var anIds = GetLastCreatedNodes();
+      aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
+      aNewNodeGroup->Add(anIds);
     }
   }
 
   // Update Python script
-  TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
-    << theNodesNot << ", " << theAffectedElems << " )";
-  return aNewGroup._retn();
+
+  pyDump << "[ ";
+  if ( aNewElemGroup->_is_nil() ) pyDump << "nothing, ";
+  else                            pyDump << aNewElemGroup << ", ";
+  if ( aNewNodeGroup->_is_nil() ) pyDump << "nothing ] = ";
+  else                            pyDump << aNewNodeGroup << " ] = ";
+
+  pyDump << this << ".DoubleNodeElemGroup2New( " << theElems << ", "
+         << theNodesNot        << ", "
+         << theAffectedElems   << ", "
+         << theElemGroupNeeded << ", "
+         << theNodeGroupNeeded <<" )";
+
+  aTwoGroups[0] = aNewElemGroup._retn();
+  aTwoGroups[1] = aNewNodeGroup._retn();
+  return aTwoGroups._retn();
 }
 
 //================================================================================
@@ -5344,11 +5744,37 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup
  */
 //================================================================================
 
-SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems,
-                                                                   const SMESH::ListOfGroups& theNodesNot,
-                                                                   const SMESH::ListOfGroups& theAffectedElems)
+SMESH::SMESH_Group_ptr
+SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::ListOfGroups& theElems,
+                                            const SMESH::ListOfGroups& theNodesNot,
+                                            const SMESH::ListOfGroups& theAffectedElems)
 {
-  SMESH::SMESH_Group_var aNewGroup;
+  TPythonDump pyDump;
+  SMESH::ListOfGroups_var twoGroups = DoubleNodeElemGroups2New( theElems,
+                                                                theNodesNot,
+                                                                theAffectedElems,
+                                                                true, false );
+  SMESH::SMESH_GroupBase_var baseGroup = twoGroups[0].in();
+  SMESH::SMESH_Group_var     elemGroup = SMESH::SMESH_Group::_narrow( baseGroup );
+
+  pyDump << elemGroup << " = " << this << ".DoubleNodeElemGroupsNew( "
+         << theElems         << ", "
+         << theNodesNot      << ", "
+         << theAffectedElems << " )";
+
+  return elemGroup._retn();
+}
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::DoubleNodeElemGroups2New(const SMESH::ListOfGroups& theElems,
+                                             const SMESH::ListOfGroups& theNodesNot,
+                                             const SMESH::ListOfGroups& theAffectedElems,
+                                             CORBA::Boolean             theElemGroupNeeded,
+                                             CORBA::Boolean             theNodeGroupNeeded)
+{
+  SMESH::SMESH_Group_var aNewElemGroup, aNewNodeGroup;
+  SMESH::ListOfGroups_var aTwoGroups = new SMESH::ListOfGroups();
+  aTwoGroups->length( 2 );
   
   initData();
 
@@ -5365,24 +5791,46 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::
   storeResult( aMeshEditor) ;
 
   myMesh->GetMeshDS()->Modified();
-  if ( aResult ) {
+  TPythonDump pyDump;
+  if ( aResult )
+  {
     myMesh->SetIsModified( true );
 
     // Create group with newly created elements
-    SMESH::long_array_var anIds = GetLastCreatedElems();
-    if (anIds->length() > 0) {
+    CORBA::String_var elemGroupName = theElems[0]->GetName();
+    string aNewName = generateGroupName( string(elemGroupName.in()) + "_double");
+    if ( !aMeshEditor.GetLastCreatedElems().IsEmpty() && theElemGroupNeeded )
+    {
+      SMESH::long_array_var anIds = GetLastCreatedElems();
       SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
-      string anUnindexedName (theElems[0]->GetName());
-      string aNewName = generateGroupName(anUnindexedName + "_double");
-      aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
-      aNewGroup->Add(anIds);
+      aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
+      aNewElemGroup->Add(anIds);
+    }
+    if ( !aMeshEditor.GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded )
+    {
+      SMESH::long_array_var anIds = GetLastCreatedNodes();
+      aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
+      aNewNodeGroup->Add(anIds);
     }
   }
 
   // Update Python script
-  TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupsNew( " << &theElems << ", "
-                << &theNodesNot << ", " << &theAffectedElems << " )";
-  return aNewGroup._retn();
+
+  pyDump << "[ ";
+  if ( aNewElemGroup->_is_nil() ) pyDump << "nothing, ";
+  else                            pyDump << aNewElemGroup << ", ";
+  if ( aNewNodeGroup->_is_nil() ) pyDump << "nothing ] = ";
+  else                            pyDump << aNewNodeGroup << " ] = ";
+
+  pyDump << this << ".DoubleNodeElemGroups2New( " << &theElems << ", "
+         << &theNodesNot       << ", "
+         << &theAffectedElems  << ", "
+         << theElemGroupNeeded << ", "
+         << theNodeGroupNeeded << " )";
+
+  aTwoGroups[0] = aNewElemGroup._retn();
+  aTwoGroups[1] = aNewNodeGroup._retn();
+  return aTwoGroups._retn();
 }
 
 //================================================================================
@@ -5455,6 +5903,7 @@ CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
  * The nodes of the internal faces at the boundaries of the groups are doubled.
  * In option, the internal faces are replaced by flat elements.
  * Triangles are transformed in prisms, and quadrangles in hexahedrons.
+ * The flat elements are stored in groups of volumes.
  * @param theDomains - list of groups of volumes
  * @param createJointElems - if TRUE, create the elements
  * @return TRUE if operation has been completed successfully, FALSE otherwise
@@ -5463,6 +5912,7 @@ CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
 
 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::ListOfGroups& theDomains,
                                                                  CORBA::Boolean createJointElems )
+  throw (SALOME::SALOME_Exception)
 {
   initData();
 
@@ -5476,8 +5926,10 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li
   for ( int i = 0, n = theDomains.length(); i < n; i++ )
   {
     SMESH::SMESH_GroupBase_var aGrp = theDomains[ i ];
-    if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
+    if ( !CORBA::is_nil( aGrp ) /*&& ( aGrp->GetType() != SMESH::NODE )*/ )
     {
+//      if ( aGrp->GetType() != SMESH::VOLUME )
+//        THROW_SALOME_CORBA_EXCEPTION("Not a volume group", SALOME::BAD_PARAM);
       TIDSortedElemSet domain;
       domain.clear();
       domains.push_back(domain);
@@ -5487,6 +5939,7 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li
   }
 
   bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
+  // TODO publish the groups of flat elements in study
 
   storeResult( aMeshEditor) ;
   myMesh->GetMeshDS()->Modified();
@@ -5497,6 +5950,53 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li
   return aResult;
 }
 
+//================================================================================
+/*!
+ * \brief Double nodes on some external faces and create flat elements.
+ * Flat elements are mainly used by some types of mechanic calculations.
+ *
+ * Each group of the list must be constituted of faces.
+ * Triangles are transformed in prisms, and quadrangles in hexahedrons.
+ * @param theGroupsOfFaces - list of groups of faces
+ * @return TRUE if operation has been completed successfully, FALSE otherwise
+ */
+//================================================================================
+
+CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH::ListOfGroups& theGroupsOfFaces )
+{
+  initData();
+
+  ::SMESH_MeshEditor aMeshEditor( myMesh );
+
+  SMESHDS_Mesh* aMeshDS = GetMeshDS();
+
+  vector<TIDSortedElemSet> faceGroups;
+  faceGroups.clear();
+
+  for ( int i = 0, n = theGroupsOfFaces.length(); i < n; i++ )
+  {
+    SMESH::SMESH_GroupBase_var aGrp = theGroupsOfFaces[ i ];
+    if ( !CORBA::is_nil( aGrp ) && ( aGrp->GetType() != SMESH::NODE ) )
+    {
+      TIDSortedElemSet faceGroup;
+      faceGroup.clear();
+      faceGroups.push_back(faceGroup);
+      SMESH::long_array_var anIDs = aGrp->GetIDs();
+      arrayToSet( anIDs, aMeshDS, faceGroups[ i ], SMDSAbs_All );
+    }
+  }
+
+  bool aResult = aMeshEditor.CreateFlatElementsOnFacesGroups( faceGroups );
+  // TODO publish the groups of flat elements in study
+
+  storeResult( aMeshEditor) ;
+  myMesh->GetMeshDS()->Modified();
+
+  // Update Python script
+  TPythonDump() << "isDone = " << this << ".CreateFlatElementsOnFacesGroups( " << &theGroupsOfFaces << " )";
+  return aResult;
+}
+
 // issue 20749 ===================================================================
 /*!
  * \brief Creates missing boundary elements
@@ -5625,20 +6125,37 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
   if ( dim > SMESH::BND_1DFROM2D )
     THROW_SALOME_CORBA_EXCEPTION("Invalid boundary dimension", SALOME::BAD_PARAM);
 
-  // check that groups belongs to to this mesh and is not this mesh
-  const int nbGroups = groups.length();
-  for ( int i = 0; i < nbGroups; ++i )
+  // separate groups belonging to this and other mesh
+  SMESH::ListOfIDSources_var groupsOfThisMesh = new SMESH::ListOfIDSources;
+  SMESH::ListOfIDSources_var groupsOfOtherMesh = new SMESH::ListOfIDSources;
+  groupsOfThisMesh->length( groups.length() );
+  groupsOfOtherMesh->length( groups.length() );
+  int nbGroups = 0, nbGroupsOfOtherMesh = 0;
+  for ( int i = 0; i < groups.length(); ++i )
   {
     SMESH::SMESH_Mesh_var m = groups[i]->GetMesh();
     if ( myMesh_i != SMESH::DownCast<SMESH_Mesh_i*>( m ))
-      THROW_SALOME_CORBA_EXCEPTION("group does not belong to this mesh", SALOME::BAD_PARAM);
+      groupsOfOtherMesh[ nbGroupsOfOtherMesh++ ] = groups[i];
+    else
+      groupsOfThisMesh[ nbGroups++ ] = groups[i];
     if ( SMESH::DownCast<SMESH_Mesh_i*>( groups[i] ))
       THROW_SALOME_CORBA_EXCEPTION("expect a group but recieve a mesh", SALOME::BAD_PARAM);
   }
+  groupsOfThisMesh->length( nbGroups );
+  groupsOfOtherMesh->length( nbGroupsOfOtherMesh );
 
+  int nbAdded = 0;
   TPythonDump pyDump;
 
-  int nbAdded = 0;
+  if ( nbGroupsOfOtherMesh > 0 )
+  {
+    // process groups belonging to another mesh
+    SMESH::SMESH_Mesh_var    otherMesh = groupsOfOtherMesh[0]->GetMesh();
+    SMESH::SMESH_MeshEditor_var editor = otherMesh->GetMeshEditor();
+    nbAdded += editor->MakeBoundaryElements( dim, groupName, meshName, toCopyAll,
+                                             groupsOfOtherMesh, mesh, group );
+  }
+
   SMESH::SMESH_Mesh_var mesh_var;
   SMESH::SMESH_Group_var group_var;
 
@@ -5662,7 +6179,7 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
   SMESH_Mesh*     srcMesh = ( toCopyMesh && !toCopyAll ) ? myMesh : tgtMesh;
   SMESHDS_Mesh* srcMeshDS = srcMesh->GetMeshDS();
 
-  // group of new boundary elements
+  // group of boundary elements
   SMESH_Group* smesh_group = 0;
   SMDSAbs_ElementType elemType = (dim == SMESH::BND_2DFROM3D) ? SMDSAbs_Volume : SMDSAbs_Face;
   if ( strlen(groupName) )
@@ -5675,12 +6192,12 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
 
   TIDSortedElemSet elements;
 
-  if ( nbGroups > 0 )
+  if ( groups.length() > 0 )
   {
     for ( int i = 0; i < nbGroups; ++i )
     {
       elements.clear();
-      if ( idSourceToSet( groups[i], srcMeshDS, elements, elemType,/*emptyIfIsMesh=*/false ))
+      if ( idSourceToSet( groupsOfThisMesh[i], srcMeshDS, elements, elemType,/*emptyIfIsMesh=*/0 ))
       {
         SMESH::Bnd_Dimension bdim = 
           ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D;