Salome HOME
PAL16842 (Genertion of groups when a mesh is transformed)
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
index e6695ed3b06e4b9951d1c5b0ea68ba1c5c219016..c83334fa5aba60b4029f62ab13d397033f86ad2a 100644 (file)
 #include "SMDS_MeshFace.hxx"
 #include "SMDS_MeshVolume.hxx"
 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
-
 #include "SMESH_MeshEditor.hxx"
-
+#include "SMESH_subMeshEventListener.hxx"
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Filter_i.hxx"
 #include "SMESH_PythonDump.hxx"
+#include "CASCatch.hxx"
 
 #include "utilities.h"
 
 
 #include <sstream>
 
+#define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
+
 using namespace std;
 using SMESH::TPythonDump;
 
-//=============================================================================
-/*!
- * \brief Mesh to apply modifications for preview purposes
- */
-//=============================================================================
+namespace {
 
-struct TPreviewMesh: public SMESH_Mesh
-{
-  SMDSAbs_ElementType myPreviewType; // type to show
+  //=============================================================================
+  /*!
+   * \brief Mesh to apply modifications for preview purposes
+   */
+  //=============================================================================
 
-  TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
-    _isShapeToMesh = _id =_studyId =_idDoc = 0;
-    _myMeshDS  = new SMESHDS_Mesh( _id, true );
-    myPreviewType = previewElements;
-  }
-  virtual ~TPreviewMesh() { delete _myMeshDS; }
-  //
-  void Copy( const SMESH::long_array & theIDsOfElements,
-             SMESH_Mesh&               theMesh,
-             TIDSortedElemSet&         theElements,
-             SMDSAbs_ElementType       theSelectType = SMDSAbs_All,
-             SMDSAbs_ElementType       theAvoidType = SMDSAbs_All)
+  struct TPreviewMesh: public SMESH_Mesh
   {
-    SMESHDS_Mesh* aMeshDS = _myMeshDS;
-
-    // loop on theIDsOfElements
-    for ( int i=0; i<theIDsOfElements.length(); ++i )
+    SMDSAbs_ElementType myPreviewType; // type to show
+    //!< Constructor
+    TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
+      _isShapeToMesh = _id =_studyId =_idDoc = 0;
+      _myMeshDS  = new SMESHDS_Mesh( _id, true );
+      myPreviewType = previewElements;
+    }
+    //!< Destructor
+    virtual ~TPreviewMesh() { delete _myMeshDS; }
+    //!< Copy a set of elements
+    void Copy(const TIDSortedElemSet & theElements,
+              TIDSortedElemSet&        theCopyElements,
+              SMDSAbs_ElementType      theSelectType = SMDSAbs_All,
+              SMDSAbs_ElementType      theAvoidType = SMDSAbs_All)
+    {
+      // loop on theIDsOfElements
+      TIDSortedElemSet::const_iterator eIt = theElements.begin();
+      for ( ; eIt != theElements.end(); ++eIt )
+      {
+        const SMDS_MeshElement* anElem = *eIt;
+        if ( !anElem ) continue;
+        SMDSAbs_ElementType type = anElem->GetType();
+        if ( type == theAvoidType ||
+             ( theSelectType != SMDSAbs_All && type != theSelectType ))
+          continue;
+
+        if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
+          theCopyElements.insert( theCopyElements.end(), anElemCopy );
+      }
+    }
+    //!< Copy an element
+    SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
     {
-      const SMDS_MeshElement* anElem =
-        theMesh.GetMeshDS()->FindElement(theIDsOfElements[i]);
-      if ( !anElem ) continue;
-      SMDSAbs_ElementType type = anElem->GetType();
-      if ( type == theAvoidType ||
-           ( theSelectType != SMDSAbs_All && type != theSelectType ))
-        continue;
-
       // copy element nodes
       int anElemNbNodes = anElem->NbNodes();
       vector< int > anElemNodesID( anElemNbNodes ) ;
       SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
       for ( int i = 0; itElemNodes->more(); i++)
       {
-        const SMDS_MeshNode* anElemNode = 
-          static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
-        _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(), 
-                                 anElemNode->GetID());
+        const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
+        Copy( anElemNode );
         anElemNodesID[i] = anElemNode->GetID();
       }
 
       // creates a corresponding element on copied nodes
-      const SMDS_MeshElement* anElemCopy = 0;
-      if ( anElem->IsPoly() && type == SMDSAbs_Volume )
+      SMDS_MeshElement* anElemCopy = 0;
+      if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
       {
         const SMDS_PolyhedralVolumeOfNodes* ph =
           dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
         if ( ph )
-          anElemCopy = aMeshDS->AddPolyhedralVolumeWithID
+          anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
             (anElemNodesID, ph->GetQuanities(),anElem->GetID());
       }
       else {
         anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
-                                                          type,
+                                                          anElem->GetType(),
                                                           anElem->IsPoly() );
       }
-      if ( anElemCopy )
-        theElements.insert( anElemCopy );
-    }// loop on theElems
-  }
+      return anElemCopy;
+    }
+    //!< Copy a node
+    SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
+    {
+      return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(), 
+                                      anElemNode->GetID());
+    }
+  };// struct TPreviewMesh
+
+  static SMESH_NodeSearcher * myNodeSearcher = 0;
+
+  //=============================================================================
+  /*!
+   * \brief Deleter of myNodeSearcher at any compute event occured
+   */
+  //=============================================================================
+
+  struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
+  {
+    SMESH_Mesh* myMesh;
+    //!< Constructor
+    TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
+    myMesh(0) {}
+    //!< Delete myNodeSearcher
+    static void Delete()
+    {
+      if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
+    }
+    typedef map < int, SMESH_subMesh * > TDependsOnMap;
+    //!< The meshod called by submesh: do my main job
+    void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
+                      SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
+    {
+      if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
+        Delete();
+        Unset( sm->GetFather() );
+      }
+    }
+    //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
+    void Set(SMESH_Mesh* mesh)
+    {
+      if ( myMesh && myMesh != mesh ) {
+        Delete();
+        Unset( myMesh );
+      }
+      myMesh = mesh;
+      if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
+        const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
+        TDependsOnMap::const_iterator sm;
+        for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
+          sm->second->SetEventListener( this, 0, sm->second );
+      }
+    }
+    //!<  delete self from all submeshes
+    void Unset(SMESH_Mesh* mesh)
+    {
+      if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
+        const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
+        TDependsOnMap::const_iterator sm;
+        for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
+          sm->second->DeleteEventListener( this );
+      }
+    }
+  };
 
-};// struct TPreviewMesh
+  TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
+  {
+    TCollection_AsciiString typeStr;
+    switch ( theMirrorType ) {
+    case  SMESH::SMESH_MeshEditor::POINT:
+      typeStr = "SMESH.SMESH_MeshEditor.POINT";
+      break;
+    case  SMESH::SMESH_MeshEditor::AXIS:
+      typeStr = "SMESH.SMESH_MeshEditor.AXIS";
+      break;
+    default:
+      typeStr = "SMESH.SMESH_MeshEditor.PLANE";
+    }
+    return typeStr;
+  }
+}
 
 //=============================================================================
 /*!
@@ -139,9 +222,10 @@ struct TPreviewMesh: public SMESH_Mesh
  */
 //=============================================================================
 
-SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh, bool isPreview)
+SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
 {
-  _myMesh = theMesh;
+  myMesh_i = theMesh;
+  myMesh = & theMesh->GetImpl();
   myPreviewMode = isPreview;
 }
 
@@ -169,6 +253,7 @@ void SMESH_MeshEditor_i::initData()
   else {
     myLastCreatedElems = new SMESH::long_array();
     myLastCreatedNodes = new SMESH::long_array();
+    TNodeSearcherDeleter::Delete();
   }
 }
 
@@ -183,7 +268,7 @@ CORBA::Boolean
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   list< int > IdList;
 
   for (int i = 0; i < IDsOfElements.length(); i++)
@@ -208,7 +293,7 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   list< int > IdList;
   for (int i = 0; i < IDsOfNodes.length(); i++)
     IdList.push_back( IDsOfNodes[i] );
@@ -526,7 +611,7 @@ CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
   TPythonDump() << "isDone = " << this << ".InverseDiag( "
                 << NodeID1 << ", " << NodeID2 << " )";
 
-  ::SMESH_MeshEditor aMeshEditor( _myMesh );
+  ::SMESH_MeshEditor aMeshEditor( myMesh );
   return aMeshEditor.InverseDiag ( n1, n2 );
 }
 
@@ -550,11 +635,11 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
   TPythonDump() << "isDone = " << this << ".DeleteDiag( "
                 << NodeID1 << ", " << NodeID2 <<  " )";
 
-  ::SMESH_MeshEditor aMeshEditor( _myMesh );
+  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
 
-  StoreResult(aMeshEditor);
+  storeResult(aMeshEditor);
 
   return stat;
 }
@@ -569,7 +654,7 @@ CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfEleme
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   for (int i = 0; i < IDsOfElements.length(); i++)
   {
     CORBA::Long index = IDsOfElements[i];
@@ -619,10 +704,10 @@ namespace
    */
   //================================================================================
 
-  void ToMap(const SMESH::long_array & IDs,
-             const SMESHDS_Mesh*       aMesh,
-             TIDSortedElemSet&         aMap,
-             const SMDSAbs_ElementType aType = SMDSAbs_All )
+  void arrayToSet(const SMESH::long_array & IDs,
+                  const SMESHDS_Mesh*       aMesh,
+                  TIDSortedElemSet&         aMap,
+                  const SMDSAbs_ElementType aType = SMDSAbs_All )
   { 
     for (int i=0; i<IDs.length(); i++) {
       CORBA::Long ind = IDs[i];
@@ -646,7 +731,7 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfE
 
   SMESHDS_Mesh* aMesh = GetMeshDS();
   TIDSortedElemSet faces;
-  ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face);
+  arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
 
   SMESH::NumericalFunctor_i* aNumericalFunctor =
     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
@@ -663,11 +748,11 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfE
   TPythonDump() << "print 'TriToQuad: ', isDone";
 #endif
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
 
   bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return stat;
 }
@@ -720,7 +805,7 @@ CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array &   IDsOfE
 
   SMESHDS_Mesh* aMesh = GetMeshDS();
   TIDSortedElemSet faces;
-  ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face);
+  arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
 
   SMESH::NumericalFunctor_i* aNumericalFunctor =
     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
@@ -737,10 +822,10 @@ CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array &   IDsOfE
   TPythonDump() << "print 'QuadToTri: ', isDone";
 #endif
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return stat;
 }
@@ -791,7 +876,7 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfEle
 
   SMESHDS_Mesh* aMesh = GetMeshDS();
   TIDSortedElemSet faces;
-  ToMap(IDsOfElements, aMesh, faces, SMDSAbs_Face);
+  arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
 
   // Update Python script
   TPythonDump() << "isDone = " << this << ".SplitQuad( "
@@ -800,10 +885,10 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfEle
   TPythonDump() << "print 'SplitQuad: ', isDone";
 #endif
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return stat;
 }
@@ -859,7 +944,7 @@ CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long                 IDOfQuad,
     else
       aCrit.reset(new SMESH::Controls::AspectRatio());
 
-    ::SMESH_MeshEditor anEditor (_myMesh);
+    ::SMESH_MeshEditor anEditor (myMesh);
     return anEditor.BestSplit(quad, aCrit);
   }
   return -1;
@@ -953,7 +1038,7 @@ CORBA::Boolean
   SMESHDS_Mesh* aMesh = GetMeshDS();
 
   TIDSortedElemSet elements;
-  ToMap(IDsOfElements, aMesh, elements, SMDSAbs_Face);
+  arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
 
   set<const SMDS_MeshNode*> fixedNodes;
   for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
@@ -966,11 +1051,11 @@ CORBA::Boolean
   if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
     method = ::SMESH_MeshEditor::CENTROIDAL;
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   anEditor.Smooth(elements, fixedNodes, method,
                   MaxNbOfIterations, MaxAspectRatio, IsParametric );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   // Update Python script
   TPythonDump() << "isDone = " << this << "."
@@ -1060,48 +1145,79 @@ void SMESH_MeshEditor_i::RenumberElements()
   GetMeshDS()->Renumber( false );
 }
 
+//=======================================================================
+  /*!
+   * \brief Return groups by their IDs
+   */
+//=======================================================================
+
+SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
+{
+  if ( !groupIDs )
+    return 0;
+  myMesh_i->CreateGroupServants();
+  return myMesh_i->GetGroups( *groupIDs );
+}
 
 //=======================================================================
-//function : RotationSweep
-//purpose  :
+//function : rotationSweep
+//purpose  : 
 //=======================================================================
 
-void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
-                                       const SMESH::AxisStruct & theAxis,
-                                       CORBA::Double             theAngleInRadians,
-                                       CORBA::Long               theNbOfSteps,
-                                       CORBA::Double             theTolerance)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
+                                  const SMESH::AxisStruct & theAxis,
+                                  CORBA::Double             theAngleInRadians,
+                                  CORBA::Long               theNbOfSteps,
+                                  CORBA::Double             theTolerance,
+                                  const bool                theMakeGroups)
 {
   initData();
 
-  TIDSortedElemSet elements;
-  TPreviewMesh     tmpMesh( SMDSAbs_Face );
-  SMESH_Mesh*      mesh = 0;
-  bool             makeWalls=true;
+  TIDSortedElemSet inElements, copyElements;
+  arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
+
+  TIDSortedElemSet* workElements = & inElements;
+  TPreviewMesh      tmpMesh( SMDSAbs_Face );
+  SMESH_Mesh*       mesh = 0;
+  bool              makeWalls=true;
   if ( myPreviewMode )
   {
     SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
-    tmpMesh.Copy( theIDsOfElements, *_myMesh, elements, select, avoid );
+    tmpMesh.Copy( inElements, copyElements, select, avoid );
     mesh = &tmpMesh;
+    workElements = & copyElements;
     //makeWalls = false;
   }
   else
   {
-    ToMap(theIDsOfElements, GetMeshDS(), elements);
-    mesh = _myMesh;
+    mesh = myMesh;
   }
 
   gp_Ax1 Ax1 (gp_Pnt( theAxis.x,  theAxis.y,  theAxis.z ),
               gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
 
   ::SMESH_MeshEditor anEditor( mesh );
-  anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
-                          theNbOfSteps, theTolerance, makeWalls);
+  ::SMESH_MeshEditor::PGroupIDs groupIds =
+    anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
+                            theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
+  storeResult(anEditor);
+
+  return theMakeGroups ? getGroups(groupIds.get()) : 0;
+}
 
-  StoreResult(anEditor);
+//=======================================================================
+//function : RotationSweep
+//purpose  :
+//=======================================================================
 
+void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
+                                       const SMESH::AxisStruct & theAxis,
+                                       CORBA::Double             theAngleInRadians,
+                                       CORBA::Long               theNbOfSteps,
+                                       CORBA::Double             theTolerance)
+{
   if ( !myPreviewMode ) {
-    // Update Python script
     TPythonDump() << "axis = " << theAxis;
     TPythonDump() << this << ".RotationSweep( "
                   << theIDsOfElements
@@ -1110,6 +1226,41 @@ void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElement
                   << theNbOfSteps << ", "
                   << theTolerance << " )";
   }
+  rotationSweep(theIDsOfElements,
+                theAxis,
+                theAngleInRadians,
+                theNbOfSteps,
+                theTolerance,
+                false);
+}
+
+//=======================================================================
+//function : RotationSweepMakeGroups
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
+                                            const SMESH::AxisStruct& theAxis,
+                                            CORBA::Double            theAngleInRadians,
+                                            CORBA::Long              theNbOfSteps,
+                                            CORBA::Double            theTolerance)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".RotationSweepMakeGroups( "
+                  << theIDsOfElements
+                  << ", axis, "
+                  << theAngleInRadians << ", "
+                  << theNbOfSteps << ", "
+                  << theTolerance << " )";
+  }
+  return rotationSweep(theIDsOfElements,
+                       theAxis,
+                       theAngleInRadians,
+                       theNbOfSteps,
+                       theTolerance,
+                       true);
 }
 
 //=======================================================================
@@ -1123,32 +1274,66 @@ void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject
                                             CORBA::Long               theNbOfSteps,
                                             CORBA::Double             theTolerance)
 {
-  initData();
-
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".RotationSweepObject( "
+                  << theObject
+                  << ", axis, "
+                  << theAngleInRadians << ", "
+                  << theNbOfSteps << ", "
+                  << theTolerance << " )";
+  }
   SMESH::long_array_var anElementsId = theObject->GetIDs();
-  RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
+  rotationSweep(anElementsId,
+                theAxis,
+                theAngleInRadians,
+                theNbOfSteps,
+                theTolerance,
+                false);
+}
 
-  // Clear python line, created by RotationSweep()
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
+//=======================================================================
+//function : RotationSweepObjectMakeGroups
+//purpose  : 
+//=======================================================================
 
-  // Update Python script
-  TPythonDump() << this << ".RotationSweepObject( "
-                << theObject
-                << ", axis, "
-                << theAngleInRadians << ", "
-                << theNbOfSteps << ", "
-                << theTolerance << " )";
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                                  const SMESH::AxisStruct&  theAxis,
+                                                  CORBA::Double             theAngleInRadians,
+                                                  CORBA::Long               theNbOfSteps,
+                                                  CORBA::Double             theTolerance)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".RotationSweepObjectMakeGroups( "
+                  << theObject
+                  << ", axis, "
+                  << theAngleInRadians << ", "
+                  << theNbOfSteps << ", "
+                  << theTolerance << " )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return rotationSweep(anElementsId,
+                       theAxis,
+                       theAngleInRadians,
+                       theNbOfSteps,
+                       theTolerance,
+                       true);
 }
 
+
 //=======================================================================
-//function : ExtrusionSweep
-//purpose  :
+//function : extrusionSweep
+//purpose  : 
 //=======================================================================
 
-void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
-                                        const SMESH::DirStruct &  theStepVector,
-                                        CORBA::Long               theNbOfSteps)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
+                                   const SMESH::DirStruct &  theStepVector,
+                                   CORBA::Long               theNbOfSteps,
+                                   const bool                theMakeGroups,
+                                   const SMDSAbs_ElementType theElementType)
 {
   initData();
 
@@ -1158,24 +1343,20 @@ void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElemen
 #else
   CASCatch_TRY {
 #endif
-    SMESHDS_Mesh* aMesh = GetMeshDS();
-
     TIDSortedElemSet elements;
-    ToMap(theIDsOfElements, aMesh, elements);
+    arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
 
     const SMESH::PointStruct * P = &theStepVector.PS;
     gp_Vec stepVec( P->x, P->y, P->z );
 
     TElemOfElemListMap aHystory;
-    ::SMESH_MeshEditor anEditor( _myMesh );
-    anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
+    ::SMESH_MeshEditor anEditor( myMesh );
+    ::SMESH_MeshEditor::PGroupIDs groupIds =
+        anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
 
-    StoreResult(anEditor);
+    storeResult(anEditor);
 
-    // Update Python script
-    TPythonDump() << "stepVector = " << theStepVector;
-    TPythonDump() << this << ".ExtrusionSweep( "
-                  << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
+    return theMakeGroups ? getGroups(groupIds.get()) : 0;
 
 #ifdef NO_CAS_CATCH
   } catch(Standard_Failure) {
@@ -1185,6 +1366,24 @@ void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElemen
     Handle(Standard_Failure) aFail = Standard_Failure::Caught();          
     INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
   }
+  return 0;
+}
+
+//=======================================================================
+//function : ExtrusionSweep
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
+                                        const SMESH::DirStruct &  theStepVector,
+                                        CORBA::Long               theNbOfSteps)
+{
+  extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweep( "
+                  << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
+  }
 }
 
 
@@ -1197,18 +1396,13 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObjec
                                              const SMESH::DirStruct &  theStepVector,
                                              CORBA::Long               theNbOfSteps)
 {
-  initData();
-
   SMESH::long_array_var anElementsId = theObject->GetIDs();
-  ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
-
-  // Clear python line, created by ExtrusionSweep()
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
-
-  // Update Python script
-  TPythonDump() << this << ".ExtrusionSweepObject( "
-                << theObject << ", stepVector, " << theNbOfSteps << " )";
+  extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepObject( "
+                  << theObject << ", stepVector, " << theNbOfSteps << " )";
+  }
 }
 
 //=======================================================================
@@ -1220,66 +1414,139 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObj
                                                 const SMESH::DirStruct &  theStepVector,
                                                 CORBA::Long               theNbOfSteps)
 {
-  initData();
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepObject1D( "
+                  << theObject << ", stepVector, " << theNbOfSteps << " )";
+  }
+}
 
-  SMESHDS_Mesh* aMesh = GetMeshDS();
+//=======================================================================
+//function : ExtrusionSweepObject2D
+//purpose  :
+//=======================================================================
 
-  SMESH::long_array_var allElementsId = theObject->GetIDs();
+void SMESH_MeshEditor_i::ExtrusionSweepObject2D(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_Face );
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepObject2D( "
+                  << theObject << ", stepVector, " << theNbOfSteps << " )";
+  }
+}
 
-  TIDSortedElemSet elements;
-  ToMap(allElementsId, aMesh, elements);
+//=======================================================================
+//function : ExtrusionSweepMakeGroups
+//purpose  : 
+//=======================================================================
 
-  const SMESH::PointStruct * P = &theStepVector.PS;
-  gp_Vec stepVec( P->x, P->y, P->z );
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
+                                             const SMESH::DirStruct&  theStepVector,
+                                             CORBA::Long              theNbOfSteps)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepMakeGroups( "
+                  << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
+  }
+  return extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
+}
+//=======================================================================
+//function : ExtrusionSweepObjectMakeGroups
+//purpose  : 
+//=======================================================================
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
-  TElemOfElemListMap aHystory;
-  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                                   const SMESH::DirStruct&   theStepVector,
+                                                   CORBA::Long               theNbOfSteps)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepObjectMakeGroups( "
+                  << theObject << ", stepVector, " << theNbOfSteps << " )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
+}
 
-  StoreResult(anEditor);
+//=======================================================================
+//function : ExtrusionSweepObject1DMakeGroups
+//purpose  : 
+//=======================================================================
 
-  // Update Python script
-  TPythonDump() << "stepVector = " << theStepVector;
-  TPythonDump() << this << ".ExtrusionSweepObject1D( "
-                << theObject << ", stepVector, " << theNbOfSteps << " )";
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                                     const SMESH::DirStruct&   theStepVector,
+                                                     CORBA::Long               theNbOfSteps)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepObject1DMakeGroups( "
+                  << theObject << ", stepVector, " << theNbOfSteps << " )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
 }
 
 //=======================================================================
-//function : ExtrusionSweepObject2D
-//purpose  :
+//function : ExtrusionSweepObject2DMakeGroups
+//purpose  : 
 //=======================================================================
 
-void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
-                                                const SMESH::DirStruct &  theStepVector,
-                                                CORBA::Long               theNbOfSteps)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                                     const SMESH::DirStruct&   theStepVector,
+                                                     CORBA::Long               theNbOfSteps)
 {
-  initData();
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".ExtrusionSweepObject2DMakeGroups( "
+                  << theObject << ", stepVector, " << theNbOfSteps << " )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
+}
 
-  SMESHDS_Mesh* aMesh = GetMeshDS();
 
-  SMESH::long_array_var allElementsId = theObject->GetIDs();
+//=======================================================================
+//function : advancedExtrusion
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
+                                      const SMESH::DirStruct &  theStepVector,
+                                      CORBA::Long               theNbOfSteps,
+                                      CORBA::Long               theExtrFlags,
+                                      CORBA::Double             theSewTolerance,
+                                      const bool                theMakeGroups)
+{
+  initData();
 
   TIDSortedElemSet elements;
-  ToMap(allElementsId, aMesh, elements);
+  arrayToSet(theIDsOfElements, GetMeshDS(), elements);
 
   const SMESH::PointStruct * P = &theStepVector.PS;
   gp_Vec stepVec( P->x, P->y, P->z );
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  ::SMESH_MeshEditor anEditor( myMesh );
   TElemOfElemListMap aHystory;
-  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
+  ::SMESH_MeshEditor::PGroupIDs groupIds =
+      anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
+                               theMakeGroups, theExtrFlags, theSewTolerance);
+  storeResult(anEditor);
 
-  StoreResult(anEditor);
-
-  // Update Python script
-  TPythonDump() << "stepVector = " << theStepVector;
-  TPythonDump() << this << ".ExtrusionSweepObject2D( "
-                << theObject << ", stepVector, " << theNbOfSteps << " )";
+  return theMakeGroups ? getGroups(groupIds.get()) : 0;
 }
 
-
 //=======================================================================
 //function : AdvancedExtrusion
 //purpose  :
@@ -1291,34 +1558,59 @@ void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfEle
                                           CORBA::Long               theExtrFlags,
                                           CORBA::Double             theSewTolerance)
 {
-  initData();
-
-  SMESHDS_Mesh* aMesh = GetMeshDS();
-
-  TIDSortedElemSet elements;
-  ToMap(theIDsOfElements, aMesh, elements);
-
-  const SMESH::PointStruct * P = &theStepVector.PS;
-  gp_Vec stepVec( P->x, P->y, P->z );
-
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  TElemOfElemListMap aHystory;
-  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
-                          theExtrFlags, theSewTolerance);
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".AdvancedExtrusion("
+                  << theIDsOfElements
+                  << ", stepVector, "
+                  << theNbOfSteps << ","
+                  << theExtrFlags << ", "
+                  << theSewTolerance <<  " )";
+  }
+  advancedExtrusion( theIDsOfElements,
+                     theStepVector,
+                     theNbOfSteps,
+                     theExtrFlags,
+                     theSewTolerance,
+                     false);
+}
 
-  StoreResult(anEditor);
+//=======================================================================
+//function : AdvancedExtrusionMakeGroups
+//purpose  : 
+//=======================================================================
 
-  // Update Python script
-  TPythonDump() << "stepVector = " << theStepVector;
-  TPythonDump() << this << ".AdvancedExtrusion("
-                << theIDsOfElements
-                << ", stepVector, "
-                << theNbOfSteps << ","
-                << theExtrFlags << ", "
-                << theSewTolerance <<  " )";
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
+                                                const SMESH::DirStruct&  theStepVector,
+                                                CORBA::Long              theNbOfSteps,
+                                                CORBA::Long              theExtrFlags,
+                                                CORBA::Double            theSewTolerance)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "stepVector = " << theStepVector;
+    TPythonDump() << this << ".AdvancedExtrusionMakeGroups("
+                  << theIDsOfElements
+                  << ", stepVector, "
+                  << theNbOfSteps << ","
+                  << theExtrFlags << ", "
+                  << theSewTolerance <<  " )";
+  }
+  return advancedExtrusion( theIDsOfElements,
+                            theStepVector,
+                            theNbOfSteps,
+                            theExtrFlags,
+                            theSewTolerance,
+                            true);
 }
 
 
+//================================================================================
+/*!
+ * \brief Convert extrusion error to IDL enum
+ */
+//================================================================================
+
 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
 
 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
@@ -1335,41 +1627,48 @@ static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_Mesh
   return SMESH::SMESH_MeshEditor::EXTR_OK;
 }
 
+
 //=======================================================================
-//function : ExtrusionAlongPath
-//purpose  :
+//function : extrusionAlongPath
+//purpose  : 
 //=======================================================================
 
-SMESH::SMESH_MeshEditor::Extrusion_Error
-  SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array &   theIDsOfElements,
-                                        SMESH::SMESH_Mesh_ptr       thePathMesh,
-                                        GEOM::GEOM_Object_ptr       thePathShape,
-                                        CORBA::Long                 theNodeStart,
-                                        CORBA::Boolean              theHasAngles,
-                                        const SMESH::double_array & theAngles,
-                                        CORBA::Boolean              theHasRefPoint,
-                                        const SMESH::PointStruct &  theRefPoint)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array &   theIDsOfElements,
+                                       SMESH::SMESH_Mesh_ptr       thePathMesh,
+                                       GEOM::GEOM_Object_ptr       thePathShape,
+                                       CORBA::Long                 theNodeStart,
+                                       CORBA::Boolean              theHasAngles,
+                                       const SMESH::double_array & theAngles,
+                                       CORBA::Boolean              theHasRefPoint,
+                                       const SMESH::PointStruct &  theRefPoint,
+                                       const bool                  theMakeGroups,
+                                       SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
 {
   initData();
 
-  SMESHDS_Mesh*  aMesh = GetMeshDS();
-
-  if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
-    return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+  if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
+    theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+    return 0;
+  }
+  SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
 
-  SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
   TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
   SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
 
-  if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
-    return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+  if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
+    theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
+    return 0;
+  }
 
   SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
-  if ( !nodeStart )
-    return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
+  if ( !nodeStart ) {
+    theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
+    return 0;
+  }
 
   TIDSortedElemSet elements;
-  ToMap(theIDsOfElements, aMesh, elements);
+  arrayToSet(theIDsOfElements, GetMeshDS(), elements);
 
   list<double> angles;
   for (int i = 0; i < theAngles.length(); i++) {
@@ -1378,35 +1677,73 @@ SMESH::SMESH_MeshEditor::Extrusion_Error
 
   gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
 
-  // Update Python script
-  TPythonDump() << "rotAngles = " << theAngles;
-
-  if ( theHasRefPoint )
-    TPythonDump() << "refPoint = SMESH.PointStruct( "
-                  << refPnt.X() << ", "
-                  << refPnt.Y() << ", "
-                  << refPnt.Z() << " )";
-  else
-    TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
-
-  TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
-                << theIDsOfElements << ", "
-                << thePathMesh      << ", "
-                << thePathShape     << ", "
-                << theNodeStart     << ", "
-                << theHasAngles     << ", "
-                << "rotAngles"      << ", "
-                << theHasRefPoint   << ", refPoint )";
+  int nbOldGroups = myMesh->NbGroup();
+
+  ::SMESH_MeshEditor anEditor( myMesh );
+  ::SMESH_MeshEditor::Extrusion_Error error =
+      anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
+                                    theHasAngles, angles,
+                                    theHasRefPoint, refPnt, theMakeGroups );
+  storeResult(anEditor);
+  theError = convExtrError( error );
+
+  if ( theMakeGroups ) {
+    list<int> groupIDs = myMesh->GetGroupIds();
+    list<int>::iterator newBegin = groupIDs.begin();
+    std::advance( newBegin, nbOldGroups ); // skip old groups
+    groupIDs.erase( groupIDs.begin(), newBegin );
+    return getGroups( & groupIDs );
+  }
+  return 0;
+}
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  SMESH::SMESH_MeshEditor::Extrusion_Error error = 
-    convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
-                                                theHasAngles, angles,
-                                                theHasRefPoint, refPnt ) );
+//=======================================================================
+//function : ExtrusionAlongPath
+//purpose  :
+//=======================================================================
 
-  StoreResult(anEditor);
+SMESH::SMESH_MeshEditor::Extrusion_Error
+  SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array &   theIDsOfElements,
+                                        SMESH::SMESH_Mesh_ptr       thePathMesh,
+                                        GEOM::GEOM_Object_ptr       thePathShape,
+                                        CORBA::Long                 theNodeStart,
+                                        CORBA::Boolean              theHasAngles,
+                                        const SMESH::double_array & theAngles,
+                                        CORBA::Boolean              theHasRefPoint,
+                                        const SMESH::PointStruct &  theRefPoint)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "rotAngles = " << theAngles;
 
-  return error;
+    if ( theHasRefPoint )
+      TPythonDump() << "refPoint = SMESH.PointStruct( "
+                    << theRefPoint.x << ", "
+                    << theRefPoint.y << ", "
+                    << theRefPoint.z << " )";
+    else
+      TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
+
+    TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
+                  << theIDsOfElements << ", "
+                  << thePathMesh      << ", "
+                  << thePathShape     << ", "
+                  << theNodeStart     << ", "
+                  << theHasAngles     << ", "
+                  << "rotAngles"      << ", "
+                  << theHasRefPoint   << ", refPoint )";
+  }
+  SMESH::SMESH_MeshEditor::Extrusion_Error anError;
+  extrusionAlongPath( theIDsOfElements,
+                      thePathMesh,
+                      thePathShape,
+                      theNodeStart,
+                      theHasAngles,
+                      theAngles,
+                      theHasRefPoint,
+                      theRefPoint,
+                      false,
+                      anError);
+  return anError;
 }
 
 //=======================================================================
@@ -1424,29 +1761,137 @@ SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr   theObje
                                              CORBA::Boolean              theHasRefPoint,
                                              const SMESH::PointStruct &  theRefPoint)
 {
-  initData();
+  if ( !myPreviewMode ) {
+    TPythonDump() << "rotAngles = " << theAngles;
 
+    if ( theHasRefPoint )
+      TPythonDump() << "refPoint = SMESH.PointStruct( "
+                    << theRefPoint.x << ", "
+                    << theRefPoint.y << ", "
+                    << theRefPoint.z << " )";
+    else
+      TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
+
+    TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
+                  << theObject        << ", "
+                  << thePathMesh      << ", "
+                  << thePathShape     << ", "
+                  << theNodeStart     << ", "
+                  << theHasAngles     << ", "
+                  << "rotAngles"      << ", "
+                  << theHasRefPoint   << ", refPoint )";
+  }
+  SMESH::SMESH_MeshEditor::Extrusion_Error anError;
   SMESH::long_array_var anElementsId = theObject->GetIDs();
-  SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
-    (anElementsId, thePathMesh, thePathShape, theNodeStart,
-     theHasAngles, theAngles, theHasRefPoint, theRefPoint);
+  extrusionAlongPath( anElementsId,
+                      thePathMesh,
+                      thePathShape,
+                      theNodeStart,
+                      theHasAngles,
+                      theAngles,
+                      theHasRefPoint,
+                      theRefPoint,
+                      false,
+                      anError);
+  return anError;
+}
 
-  // Clear python line, created by ExtrusionAlongPath()
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
-  // Update Python script
-  TPythonDump() << "rotAngles = " << theAngles;
-  TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
-                << theObject    << ", "
-                << thePathMesh  << ", "
-                << thePathShape << ", "
-                << theNodeStart << ", "
-                << theHasAngles << ", "
-                << "rotAngles"     << ", "
-                << theHasRefPoint<<", refPoint )";
+//=======================================================================
+//function : ExtrusionAlongPathMakeGroups
+//purpose  : 
+//=======================================================================
 
-  return error;
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array&   theIDsOfElements,
+                                                 SMESH::SMESH_Mesh_ptr      thePathMesh,
+                                                 GEOM::GEOM_Object_ptr      thePathShape,
+                                                 CORBA::Long                theNodeStart,
+                                                 CORBA::Boolean             theHasAngles,
+                                                 const SMESH::double_array& theAngles,
+                                                 CORBA::Boolean             theHasRefPoint,
+                                                 const SMESH::PointStruct&  theRefPoint,
+                                                 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "rotAngles = " << theAngles;
+
+    if ( theHasRefPoint )
+      TPythonDump() << "refPoint = SMESH.PointStruct( "
+                    << theRefPoint.x << ", "
+                    << theRefPoint.y << ", "
+                    << theRefPoint.z << " )";
+    else
+      TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
+
+    TPythonDump() << "groups = " << this << ".ExtrusionAlongPathMakeGroups( "
+                  << theIDsOfElements << ", "
+                  << thePathMesh      << ", "
+                  << thePathShape     << ", "
+                  << theNodeStart     << ", "
+                  << theHasAngles     << ", "
+                  << "rotAngles"      << ", "
+                  << theHasRefPoint   << ", refPoint )";
+  }
+  return extrusionAlongPath( theIDsOfElements,
+                             thePathMesh,
+                             thePathShape,
+                             theNodeStart,
+                             theHasAngles,
+                             theAngles,
+                             theHasRefPoint,
+                             theRefPoint,
+                             true,
+                             Error);
+}
+
+//=======================================================================
+//function : ExtrusionAlongPathObjectMakeGroups
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups* SMESH_MeshEditor_i::
+ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr  theObject,
+                                   SMESH::SMESH_Mesh_ptr      thePathMesh,
+                                   GEOM::GEOM_Object_ptr      thePathShape,
+                                   CORBA::Long                theNodeStart,
+                                   CORBA::Boolean             theHasAngles,
+                                   const SMESH::double_array& theAngles,
+                                   CORBA::Boolean             theHasRefPoint,
+                                   const SMESH::PointStruct&  theRefPoint,
+                                   SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "rotAngles = " << theAngles;
+
+    if ( theHasRefPoint )
+      TPythonDump() << "refPoint = SMESH.PointStruct( "
+                    << theRefPoint.x << ", "
+                    << theRefPoint.y << ", "
+                    << theRefPoint.z << " )";
+    else
+      TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
+
+    TPythonDump() << "groups = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
+                  << theObject << ", "
+                  << thePathMesh      << ", "
+                  << thePathShape     << ", "
+                  << theNodeStart     << ", "
+                  << theHasAngles     << ", "
+                  << "rotAngles"      << ", "
+                  << theHasRefPoint   << ", refPoint )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return extrusionAlongPath( anElementsId,
+                             thePathMesh,
+                             thePathShape,
+                             theNodeStart,
+                             theHasAngles,
+                             theAngles,
+                             theHasRefPoint,
+                             theRefPoint,
+                             true,
+                             Error);
 }
 
 //================================================================================
@@ -1469,55 +1914,67 @@ SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr       thePathMes
   return aResult._retn();
 }
 
+
 //=======================================================================
-//function : Mirror
-//purpose  :
+//function : mirror
+//purpose  : 
 //=======================================================================
 
-void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElements,
-                                const SMESH::AxisStruct &           theAxis,
-                                SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
-                                CORBA::Boolean                      theCopy)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::mirror(const SMESH::long_array &           theIDsOfElements,
+                           const SMESH::AxisStruct &           theAxis,
+                           SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
+                           CORBA::Boolean                      theCopy,
+                           const bool                          theMakeGroups)
 {
   initData();
 
-  SMESHDS_Mesh* aMesh = GetMeshDS();
-
   TIDSortedElemSet elements;
-  ToMap(theIDsOfElements, aMesh, elements);
+  arrayToSet(theIDsOfElements, GetMeshDS(), elements);
 
   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
 
   gp_Trsf aTrsf;
-  TCollection_AsciiString typeStr;
   switch ( theMirrorType ) {
   case  SMESH::SMESH_MeshEditor::POINT:
     aTrsf.SetMirror( P );
-    typeStr = "SMESH.SMESH_MeshEditor.POINT";
     break;
   case  SMESH::SMESH_MeshEditor::AXIS:
     aTrsf.SetMirror( gp_Ax1( P, V ));
-    typeStr = "SMESH.SMESH_MeshEditor.AXIS";
     break;
   default:
     aTrsf.SetMirror( gp_Ax2( P, V ));
-    typeStr = "SMESH.SMESH_MeshEditor.PLANE";
   }
 
-  // Update Python script
-  TPythonDump() << this << ".Mirror( "
-                << theIDsOfElements << ", "
-                << theAxis           << ", "
-                << typeStr           << ", "
-                << theCopy           << " )";
-
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  anEditor.Transform (elements, aTrsf, theCopy);
+  ::SMESH_MeshEditor anEditor( myMesh );
+  ::SMESH_MeshEditor::PGroupIDs groupIds =
+      anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
 
   if(theCopy) {
-    StoreResult(anEditor);
+    storeResult(anEditor);
   }
+  return theMakeGroups ? getGroups(groupIds.get()) : 0;
+}
+
+//=======================================================================
+//function : Mirror
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElements,
+                                const SMESH::AxisStruct &           theAxis,
+                                SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
+                                CORBA::Boolean                      theCopy)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".Mirror( "
+                  << theIDsOfElements << ", "
+                  << theAxis          << ", "
+                  << mirrorTypeName(theMirrorType) << ", "
+                  << theCopy          << " )";
+  }
+  mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
 }
 
 
@@ -1531,68 +1988,107 @@ void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObj
                                      SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
                                      CORBA::Boolean                      theCopy)
 {
-  initData();
-
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".MirrorObject( "
+                  << theObject << ", "
+                  << theAxis   << ", "
+                  << mirrorTypeName(theMirrorType) << ", "
+                  << theCopy   << " )";
+  }
   SMESH::long_array_var anElementsId = theObject->GetIDs();
-  Mirror(anElementsId, theAxis, theMirrorType, theCopy);
+  mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
+}
 
-  // Clear python line, created by Mirror()
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
+//=======================================================================
+//function : MirrorMakeGroups
+//purpose  : 
+//=======================================================================
 
-  // Update Python script
-  TCollection_AsciiString typeStr;
-  switch ( theMirrorType ) {
-  case  SMESH::SMESH_MeshEditor::POINT:
-    typeStr = "SMESH.SMESH_MeshEditor.POINT";
-    break;
-  case  SMESH::SMESH_MeshEditor::AXIS:
-    typeStr = "SMESH.SMESH_MeshEditor.AXIS";
-    break;
-  default:
-    typeStr = "SMESH.SMESH_MeshEditor.PLANE";
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array&            theIDsOfElements,
+                                     const SMESH::AxisStruct&            theMirror,
+                                     SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".MirrorMakeGroups( "
+                  << theIDsOfElements << ", "
+                  << theMirror          << ", "
+                  << mirrorTypeName(theMirrorType) << " )";
   }
-  TPythonDump() << "axis = " << theAxis;
-  TPythonDump() << this << ".MirrorObject( "
-                << theObject << ", "
-                << "axis, "
-                << typeStr << ", "
-                << theCopy << " )";
+  return mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
 }
 
 //=======================================================================
-//function : Translate
-//purpose  :
+//function : MirrorObjectMakeGroups
+//purpose  : 
 //=======================================================================
 
-void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
-                                   const SMESH::DirStruct &  theVector,
-                                   CORBA::Boolean            theCopy)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr           theObject,
+                                           const SMESH::AxisStruct&            theMirror,
+                                           SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
 {
-  initData();
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".MirrorObjectMakeGroups( "
+                  << theObject << ", "
+                  << theMirror   << ", "
+                  << mirrorTypeName(theMirrorType) << " )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return mirror(anElementsId, theMirror, theMirrorType, true, true);
+}
 
-  SMESHDS_Mesh* aMesh = GetMeshDS();
+
+//=======================================================================
+//function : translate
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
+                              const SMESH::DirStruct &  theVector,
+                              CORBA::Boolean            theCopy,
+                              const bool                theMakeGroups)
+{
+  initData();
 
   TIDSortedElemSet elements;
-  ToMap(theIDsOfElements, aMesh, elements);
+  arrayToSet(theIDsOfElements, GetMeshDS(), elements);
 
   gp_Trsf aTrsf;
   const SMESH::PointStruct * P = &theVector.PS;
   aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  anEditor.Transform (elements, aTrsf, theCopy);
+  ::SMESH_MeshEditor anEditor( myMesh );
+  ::SMESH_MeshEditor::PGroupIDs groupIds =
+      anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
 
-  if(theCopy) {
-    StoreResult(anEditor);
-  }
+  if(theCopy)
+    storeResult(anEditor);
 
-  // Update Python script
-  TPythonDump() << "vector = " << theVector;
-  TPythonDump() << this << ".Translate( "
-                << theIDsOfElements
-                << ", vector, "
-                << theCopy << " )";
+  return theMakeGroups ? getGroups(groupIds.get()) : 0;
+}
+
+//=======================================================================
+//function : Translate
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
+                                   const SMESH::DirStruct &  theVector,
+                                   CORBA::Boolean            theCopy)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "vector = " << theVector;
+    TPythonDump() << this << ".Translate( "
+                  << theIDsOfElements
+                  << ", vector, "
+                  << theCopy << " )";
+  }
+  translate(theIDsOfElements,
+            theVector,
+            theCopy,
+            false);
 }
 
 //=======================================================================
@@ -1604,38 +2100,71 @@ void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
                                         const SMESH::DirStruct &  theVector,
                                         CORBA::Boolean            theCopy)
 {
-  initData();
-
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".TranslateObject( "
+                  << theObject
+                  << ", vector, "
+                  << theCopy << " )";
+  }
   SMESH::long_array_var anElementsId = theObject->GetIDs();
-  Translate(anElementsId, theVector, theCopy);
+  translate(anElementsId,
+            theVector,
+            theCopy,
+            false);
+}
 
-  // Clear python line, created by Translate()
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
+//=======================================================================
+//function : TranslateMakeGroups
+//purpose  : 
+//=======================================================================
 
-  // Update Python script
-  TPythonDump() << this << ".TranslateObject( "
-                << theObject
-                << ", vector, "
-                << theCopy << " )";
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
+                                        const SMESH::DirStruct&  theVector)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "vector = " << theVector;
+    TPythonDump() << this << ".TranslateMakeGroups( "
+                  << theIDsOfElements
+                  << ", vector )";
+  }
+  return translate(theIDsOfElements,theVector,true,true);
 }
 
 //=======================================================================
-//function : Rotate
-//purpose  :
+//function : TranslateObjectMakeGroups
+//purpose  : 
 //=======================================================================
 
-void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
-                                const SMESH::AxisStruct & theAxis,
-                                CORBA::Double             theAngle,
-                                CORBA::Boolean            theCopy)
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                              const SMESH::DirStruct&   theVector)
 {
-  initData();
+  if ( !myPreviewMode ) {
+    TPythonDump() << this << ".TranslateObjectMakeGroups( "
+                  << theObject
+                  << ", vector )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return translate(anElementsId, theVector, true, true);
+}
 
-  SMESHDS_Mesh* aMesh = GetMeshDS();
+//=======================================================================
+//function : rotate
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
+                           const SMESH::AxisStruct & theAxis,
+                           CORBA::Double             theAngle,
+                           CORBA::Boolean            theCopy,
+                           const bool                theMakeGroups)
+{
+  initData();
 
   TIDSortedElemSet elements;
-  ToMap(theIDsOfElements, aMesh, elements);
+  arrayToSet(theIDsOfElements, GetMeshDS(), elements);
 
   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
@@ -1643,20 +2172,39 @@ void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
   gp_Trsf aTrsf;
   aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
-  anEditor.Transform (elements, aTrsf, theCopy);
+  ::SMESH_MeshEditor anEditor( myMesh );
+  ::SMESH_MeshEditor::PGroupIDs groupIds =
+      anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups);
 
   if(theCopy) {
-    StoreResult(anEditor);
+    storeResult(anEditor);
   }
+  return theMakeGroups ? getGroups(groupIds.get()) : 0;
+}
 
-  // Update Python script
-  TPythonDump() << "axis = " << theAxis;
-  TPythonDump() << this << ".Rotate( "
-                << theIDsOfElements
-                << ", axis, "
-                << theAngle << ", "
-                << theCopy << " )";
+//=======================================================================
+//function : Rotate
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
+                                const SMESH::AxisStruct & theAxis,
+                                CORBA::Double             theAngle,
+                                CORBA::Boolean            theCopy)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".Rotate( "
+                  << theIDsOfElements
+                  << ", axis, "
+                  << theAngle << ", "
+                  << theCopy << " )";
+  }
+  rotate(theIDsOfElements,
+         theAxis,
+         theAngle,
+         theCopy,
+         false);
 }
 
 //=======================================================================
@@ -1669,21 +2217,61 @@ void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
                                      CORBA::Double             theAngle,
                                      CORBA::Boolean            theCopy)
 {
-  initData();
-
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".RotateObject( "
+                  << theObject
+                  << ", axis, "
+                  << theAngle << ", "
+                  << theCopy << " )";
+  }
   SMESH::long_array_var anElementsId = theObject->GetIDs();
-  Rotate(anElementsId, theAxis, theAngle, theCopy);
+  rotate(anElementsId,
+         theAxis,
+         theAngle,
+         theCopy,
+         false);
+}
 
-  // Clear python line, created by Rotate()
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
+//=======================================================================
+//function : RotateMakeGroups
+//purpose  : 
+//=======================================================================
 
-  // Update Python script
-  TPythonDump() << this << ".RotateObject( "
-                << theObject
-                << ", axis, "
-                << theAngle << ", "
-                << theCopy << " )";
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
+                                     const SMESH::AxisStruct& theAxis,
+                                     CORBA::Double            theAngle)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".RotateMakeGroups( "
+                  << theIDsOfElements
+                  << ", axis, "
+                  << theAngle << " )";
+  }
+  return rotate(theIDsOfElements,theAxis,theAngle,true,true);
+}
+
+//=======================================================================
+//function : RotateObjectMakeGroups
+//purpose  : 
+//=======================================================================
+
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
+                                           const SMESH::AxisStruct&  theAxis,
+                                           CORBA::Double             theAngle)
+{
+  if ( !myPreviewMode ) {
+    TPythonDump() << "axis = " << theAxis;
+    TPythonDump() << this << ".RotateObjectMakeGroups( "
+                  << theObject
+                  << ", axis, "
+                  << theAngle << " )";
+  }
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  return rotate(anElementsId,theAxis,theAngle,true,true);
 }
 
 //=======================================================================
@@ -1697,7 +2285,7 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tol
   initData();
 
   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   set<const SMDS_MeshNode*> nodes; // no input nodes
   anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
 
@@ -1707,16 +2295,72 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tol
   for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
     list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
     list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
-    SMESH::long_array& aGroup = GroupsOfNodes[ i ];
+    SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
     aGroup.length( aListOfNodes.size() );
     for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
       aGroup[ j ] = (*lIt)->GetID();
   }
-  // Update Python script
   TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
                 << Tolerance << " )";
 }
 
+//=======================================================================
+//function : FindCoincidentNodesOnPart
+//purpose  :
+//=======================================================================
+void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr      theObject,
+                                                   CORBA::Double                  Tolerance,
+                                                   SMESH::array_of_long_array_out GroupsOfNodes)
+{
+  initData();
+  SMESH::long_array_var aElementsId = theObject->GetIDs();
+
+  SMESHDS_Mesh* aMesh = GetMeshDS();
+  set<const SMDS_MeshNode*> nodes;
+
+  if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
+      SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
+    for(int i = 0; i < aElementsId->length(); i++) {
+      CORBA::Long ind = aElementsId[i];
+      const SMDS_MeshNode * elem = aMesh->FindNode(ind);
+      if(elem)
+        nodes.insert(elem);
+    }
+  }
+  else {
+    for(int i = 0; i < aElementsId->length(); i++) {
+      CORBA::Long ind = aElementsId[i];
+      const SMDS_MeshElement * elem = aMesh->FindElement(ind);
+      if(elem) {
+        SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
+        while ( nIt->more() )
+          nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
+      }
+    }
+  }
+    
+  
+  ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
+  ::SMESH_MeshEditor anEditor( myMesh );
+  if(!nodes.empty())
+    anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
+  
+  GroupsOfNodes = new SMESH::array_of_long_array;
+  GroupsOfNodes->length( aListOfListOfNodes.size() );
+  ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
+  for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
+    list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
+    list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
+    SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
+    aGroup.length( aListOfNodes.size() );
+    for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
+      aGroup[ j ] = (*lIt)->GetID();
+  }
+  TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
+                <<theObject<<", "
+                << Tolerance << " )";
+}
+
 //=======================================================================
 //function : MergeNodes
 //purpose  :
@@ -1749,13 +2393,92 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN
     if ( i > 0 ) aTPythonDump << ", ";
     aTPythonDump << aNodeGroup;
   }
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   anEditor.MergeNodes( aListOfListOfNodes );
 
-  // Update Python script
   aTPythonDump <<  "])";
 }
 
+//=======================================================================
+//function : FindEqualElements
+//purpose  :
+//=======================================================================
+void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr      theObject,
+                                          SMESH::array_of_long_array_out GroupsOfElementsID)
+{
+  initData();
+  if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
+        SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
+    typedef list<int> TListOfIDs;
+    set<const SMDS_MeshElement*> elems;
+    SMESH::long_array_var aElementsId = theObject->GetIDs();
+    SMESHDS_Mesh* aMesh = GetMeshDS();
+
+    for(int i = 0; i < aElementsId->length(); i++) {
+      CORBA::Long anID = aElementsId[i];
+      const SMDS_MeshElement * elem = aMesh->FindElement(anID);
+      if (elem) {
+       elems.insert(elem);
+      }
+    }
+
+    ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
+    ::SMESH_MeshEditor anEditor( myMesh );
+    anEditor.FindEqualElements( elems, aListOfListOfElementsID );
+
+    GroupsOfElementsID = new SMESH::array_of_long_array;
+    GroupsOfElementsID->length( aListOfListOfElementsID.size() );
+
+    ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
+    for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
+      SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
+      TListOfIDs& listOfIDs = *arraysIt;
+      aGroup.length( listOfIDs.size() );
+      TListOfIDs::iterator idIt = listOfIDs.begin();
+      for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
+       aGroup[ k ] = *idIt;
+      }
+    }
+
+  TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
+                <<theObject<<" )";
+  }
+}
+
+//=======================================================================
+//function : MergeElements
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
+{
+  initData();
+
+  TPythonDump aTPythonDump;
+  aTPythonDump << this << ".MergeElements( [";
+
+  ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
+
+  for (int i = 0; i < GroupsOfElementsID.length(); i++) {
+    const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
+    aListOfListOfElementsID.push_back( list< int >() );
+    list< int >& aListOfElemsID = aListOfListOfElementsID.back();
+    for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
+      CORBA::Long id = anElemsIDGroup[ j ];
+      aListOfElemsID.push_back( id );
+    }
+    if ( aListOfElemsID.size() < 2 )
+      aListOfListOfElementsID.pop_back();
+    if ( i > 0 ) aTPythonDump << ", ";
+    aTPythonDump << anElemsIDGroup;
+  }
+
+  ::SMESH_MeshEditor anEditor( myMesh );
+  anEditor.MergeElements(aListOfListOfElementsID);
+
+  aTPythonDump << "] )";
+}
+
 //=======================================================================
 //function : MergeEqualElements
 //purpose  :
@@ -1765,15 +2488,81 @@ void SMESH_MeshEditor_i::MergeEqualElements()
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   anEditor.MergeEqualElements();
 
-  // Update Python script
   TPythonDump() << this << ".MergeEqualElements()";
 }
 
+//================================================================================
+/*!
+ * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
+ * move the node closest to the point to point's location and return ID of the node
+ */
+//================================================================================
+
+CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
+                                                       CORBA::Double y,
+                                                       CORBA::Double z,
+                                                       CORBA::Long   theNodeID)
+{
+  // We keep myNodeSearcher until any mesh modification:
+  // 1) initData() deletes myNodeSearcher at any edition,
+  // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
+
+  initData();
+
+  int nodeID = theNodeID;
+  const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
+  if ( !node )
+  {
+    static TNodeSearcherDeleter deleter;
+    deleter.Set( myMesh );
+    if ( !myNodeSearcher ) {
+      ::SMESH_MeshEditor anEditor( myMesh );
+      myNodeSearcher = anEditor.GetNodeSearcher();
+    }
+    gp_Pnt p( x,y,z );
+    node = myNodeSearcher->FindClosestTo( p );
+  }
+  if ( node ) {
+    nodeID = node->GetID();
+    if ( myPreviewMode ) // make preview data
+    {
+      // in a preview mesh, make edges linked to a node
+      TPreviewMesh tmpMesh;
+      TIDSortedElemSet linkedNodes;
+      ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
+      TIDSortedElemSet::iterator nIt = linkedNodes.begin();
+      for ( ; nIt != linkedNodes.end(); ++nIt )
+      {
+        SMDS_MeshEdge edge( node, cast2Node( *nIt ));
+        tmpMesh.Copy( &edge );
+      }
+      // move copied node
+      node = tmpMesh.GetMeshDS()->FindNode( nodeID );
+      if ( node )
+        tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
+      // fill preview data
+      ::SMESH_MeshEditor anEditor( & tmpMesh );
+      storeResult( anEditor );
+    }
+    else
+    {
+      GetMeshDS()->MoveNode(node, x, y, z);
+    }
+  }
+
+  if ( !myPreviewMode ) {
+    TPythonDump() << "nodeID = " << this
+                  << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z << " )";
+  }
+
+  return nodeID;
+}
+
 //=======================================================================
-//function : operator
+//function : convError
 //purpose  :
 //=======================================================================
 
@@ -1831,7 +2620,6 @@ SMESH::SMESH_MeshEditor::Sew_Error
       !aSide2ThirdNode)
     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
 
-  // Update Python script
   TPythonDump() << "error = " << this << ".SewFreeBorders( "
                 << FirstNodeID1  << ", "
                 << SecondNodeID1 << ", "
@@ -1842,7 +2630,7 @@ SMESH::SMESH_MeshEditor::Sew_Error
                 << CreatePolygons<< ", "
                 << CreatePolyedrs<< " )";
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
     convError( anEditor.SewFreeBorder (aBorderFirstNode,
                                        aBorderSecondNode,
@@ -1854,7 +2642,7 @@ SMESH::SMESH_MeshEditor::Sew_Error
                                        CreatePolygons,
                                        CreatePolyedrs) );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return error;
 }
@@ -1891,7 +2679,6 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
       !aSide2SecondNode)
     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
 
-  // Update Python script
   TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
                 << FirstNodeID1  << ", "
                 << SecondNodeID1 << ", "
@@ -1899,7 +2686,7 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
                 << FirstNodeID2  << ", "
                 << SecondNodeID2 << " )";
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
     convError( anEditor.SewFreeBorder (aBorderFirstNode,
                                        aBorderSecondNode,
@@ -1910,7 +2697,7 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
                                        true,
                                        false, false) );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return error;
 }
@@ -1949,7 +2736,6 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
       !aSide2SecondNode)
     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
 
-  // Update Python script
   TPythonDump() << "error = " << this << ".SewBorderToSide( "
                 << FirstNodeIDOnFreeBorder  << ", "
                 << SecondNodeIDOnFreeBorder << ", "
@@ -1959,7 +2745,7 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
                 << CreatePolygons           << ", "
                 << CreatePolyedrs           << ") ";
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
     convError( anEditor.SewFreeBorder (aBorderFirstNode,
                                        aBorderSecondNode,
@@ -1971,7 +2757,7 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
                                        CreatePolygons,
                                        CreatePolyedrs) );
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return error;
 }
@@ -2007,10 +2793,9 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
 
   TIDSortedElemSet aSide1Elems, aSide2Elems;
-  ToMap(IDsOfSide1Elements, aMesh, aSide1Elems);
-  ToMap(IDsOfSide2Elements, aMesh, aSide2Elems);
+  arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
+  arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
 
-  // Update Python script
   TPythonDump() << "error = " << this << ".SewSideElements( "
                 << IDsOfSide1Elements << ", "
                 << IDsOfSide2Elements << ", "
@@ -2019,7 +2804,7 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
                 << NodeID2OfSide1ToMerge << ", "
                 << NodeID2OfSide2ToMerge << ")";
 
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
     convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
                                          aFirstNode1ToMerge,
@@ -2027,7 +2812,7 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
                                          aSecondNode1ToMerge,
                                          aSecondNode2ToMerge));
 
-  StoreResult(anEditor);
+  storeResult(anEditor);
 
   return error;
 }
@@ -2051,7 +2836,7 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
 
   int nbn = newIDs.length();
   int i=0;
-  const SMDS_MeshNode* aNodes [nbn];
+  vector<const SMDS_MeshNode*> aNodes(nbn);
   int nbn1=-1;
   for(; i<nbn; i++) {
     const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
@@ -2060,14 +2845,13 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
       aNodes[nbn1] = aNode;
     }
   }
-  // Update Python script
   TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
                 << ide << ", " << newIDs << " )";
 #ifdef _DEBUG_
   TPythonDump() << "print 'ChangeElemNodes: ', isDone";
 #endif
 
-  return GetMeshDS()->ChangeElementNodes( elem, aNodes, nbn1+1 );
+  return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
 }
   
 //================================================================================
@@ -2077,7 +2861,7 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
  */
 //================================================================================
 
-void SMESH_MeshEditor_i::StoreResult(::SMESH_MeshEditor& anEditor)
+void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
 {
   if ( myPreviewMode ) { // --- MeshPreviewStruct filling --- 
 
@@ -2212,22 +2996,20 @@ SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
 
 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
 {
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   anEditor.ConvertToQuadratic(theForce3d);
- // Update Python script
   TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
 }
 
 //=======================================================================
 //function : ConvertFromQuadratic
-//purpose  :
+//purpose  : 
 //=======================================================================
 
 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
 {
-  ::SMESH_MeshEditor anEditor( _myMesh );
+  ::SMESH_MeshEditor anEditor( myMesh );
   CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
-  // Update Python script
   TPythonDump() << this << ".ConvertFromQuadratic()";
   return isDone;
 }