Salome HOME
PR: tools for crack meshing : detection of elements affected by node duplication...
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
index 0ae64289ecc79bc4a9677a2ad6fe940a4462718a..42d0b3c2fae1d8f2ff8d9c8be9d383be25cdaac0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  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
@@ -296,6 +296,7 @@ namespace {
     else
     {
       arrayToSet( anIDs, theMeshDS, theElemSet, theType);
+      return bool(anIDs->length()) == bool(theElemSet.size());
     }
     return true;
   }
@@ -378,6 +379,24 @@ namespace {
       }
     }
   }
+
+  //================================================================================
+  /*!
+   * \brief Return a string used to detect change of mesh part on which theElementSearcher
+   * is going to be used
+   */
+  //================================================================================
+
+  string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type)
+  {
+    string partIOR = SMESH_Gen_i::GetORB()->object_to_string( theMeshPart );
+    if ( SMESH_Group_i* group_i = SMESH::DownCast<SMESH_Group_i*>( theMeshPart ))
+      // take into account passible group modification
+      partIOR += SMESH_Comment( ((SMESHDS_Group*)group_i->GetGroupDS())->SMDSGroup().Tic() );
+    partIOR += SMESH_Comment( type );
+    return partIOR;
+  }
+
 }
 
 //=============================================================================
@@ -386,11 +405,12 @@ namespace {
  */
 //=============================================================================
 
-SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
+SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview):
+  myMesh_i( theMesh ),
+  myMesh( &theMesh->GetImpl() ),
+  myEditor( myMesh ),
+  myPreviewMode ( isPreview )
 {
-  myMesh_i = theMesh;
-  myMesh = & theMesh->GetImpl();
-  myPreviewMode = isPreview;
 }
 
 //================================================================================
@@ -412,16 +432,139 @@ SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
 {
   if ( myPreviewMode ) {
-    myPreviewData = new SMESH::MeshPreviewStruct();
+    //myPreviewData = new SMESH::MeshPreviewStruct();
   }
   else {
-    myLastCreatedElems = new SMESH::long_array();
-    myLastCreatedNodes = new SMESH::long_array();
     if ( deleteSearchers )
       TSearchersDeleter::Delete();
   }
 }
 
+//================================================================================
+/*!
+ * \brief Now does nothing
+ */
+//================================================================================
+
+void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& )
+{
+}
+
+//================================================================================
+/*!
+ * Return data of mesh edition preview
+ */
+//================================================================================
+
+SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
+{
+  if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
+
+    list<int> aNodesConnectivity;
+    typedef map<int, int> TNodesMap;
+    TNodesMap nodesMap;
+
+    SMESHDS_Mesh* aMeshDS = myEditor.GetMeshDS();
+    int nbEdges = aMeshDS->NbEdges();
+    int nbFaces = aMeshDS->NbFaces();
+    int nbVolum = aMeshDS->NbVolumes();
+    myPreviewData = new SMESH::MeshPreviewStruct();
+    myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
+
+    TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( myEditor.GetMesh() );
+    SMDSAbs_ElementType previewType = SMDSAbs_All;
+    if (aPreviewMesh) {
+      previewType = aPreviewMesh->myPreviewType;
+      switch ( previewType ) {
+      case SMDSAbs_Edge  : nbFaces = nbVolum = 0; break;
+      case SMDSAbs_Face  : nbEdges = nbVolum = 0; break;
+      case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
+      default:;
+      }
+    }
+
+    myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
+    int i = 0, j = 0;
+    SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
+
+    while ( itMeshElems->more() ) {
+      const SMDS_MeshElement* aMeshElem = itMeshElems->next();
+      if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
+        continue;
+
+      SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
+      while ( itElemNodes->more() ) {
+        const SMDS_MeshNode* aMeshNode =
+          static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
+        int aNodeID = aMeshNode->GetID();
+        TNodesMap::iterator anIter = nodesMap.find(aNodeID);
+        if ( anIter == nodesMap.end() ) {
+          // filling the nodes coordinates
+          myPreviewData->nodesXYZ[j].x = aMeshNode->X();
+          myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
+          myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
+          anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
+          j++;
+        }
+        aNodesConnectivity.push_back(anIter->second);
+      }
+
+      // filling the elements types
+      SMDSAbs_ElementType aType = aMeshElem->GetType();
+      bool               isPoly = aMeshElem->IsPoly();
+
+      myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
+      myPreviewData->elementTypes[i].isPoly = isPoly;
+      myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
+      i++;
+
+    }
+    myPreviewData->nodesXYZ.length( j );
+
+    // filling the elements connectivities
+    list<int>::iterator aConnIter = aNodesConnectivity.begin();
+    myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
+    for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
+      myPreviewData->elementConnectivities[i] = *aConnIter;
+  }
+
+  return myPreviewData._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Returns list of it's IDs of created nodes
+ * \retval SMESH::long_array* - list of node ID
+ */
+//================================================================================
+
+SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
+{
+  SMESH::long_array_var myLastCreatedNodes = new SMESH::long_array();
+  const SMESH_SequenceOfElemPtr& aSeq = myEditor.GetLastCreatedNodes();
+  myLastCreatedNodes->length( aSeq.Length() );
+  for (int i = 1; i <= aSeq.Length(); i++)
+    myLastCreatedNodes[i-1] = aSeq.Value(i)->GetID();
+  return myLastCreatedNodes._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Returns list of it's IDs of created elements
+ * \retval SMESH::long_array* - list of elements' ID
+ */
+//================================================================================
+
+SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
+{
+  SMESH::long_array_var myLastCreatedElems = new SMESH::long_array();
+  const SMESH_SequenceOfElemPtr& aSeq = myEditor.GetLastCreatedElems();
+  myLastCreatedElems->length( aSeq.Length() );
+  for ( int i = 1; i <= aSeq.Length(); i++ )
+    myLastCreatedElems[i-1] = aSeq.Value(i)->GetID();
+  return myLastCreatedElems._retn();
+}
+
 //=======================================================================
 //function : MakeIDSource
 //purpose  : Wrap a sequence of ids in a SMESH_IDSource
@@ -470,7 +613,6 @@ SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   list< int > IdList;
 
   for (int i = 0; i < IDsOfElements.length(); i++)
@@ -480,7 +622,7 @@ SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
   TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
 
   // Remove Elements
-  bool ret = anEditor.Remove( IdList, false );
+  bool ret = myEditor.Remove( IdList, false );
   myMesh->GetMeshDS()->Modified();
   if ( IDsOfElements.length() )
     myMesh->SetIsModified( true ); // issue 0020693
@@ -497,7 +639,6 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   list< int > IdList;
   for (int i = 0; i < IDsOfNodes.length(); i++)
     IdList.push_back( IDsOfNodes[i] );
@@ -505,7 +646,7 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo
   // Update Python script
   TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
 
-  bool ret = anEditor.Remove( IdList, true );
+  bool ret = myEditor.Remove( IdList, true );
   myMesh->GetMeshDS()->Modified();
   if ( IDsOfNodes.length() )
     myMesh->SetIsModified( true ); // issue 0020693
@@ -522,7 +663,6 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( myMesh );
 
   // Update Python script
   TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
@@ -538,7 +678,7 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
     IdList.push_back( seq[i] );
 
   int nbNodesBefore = myMesh->NbNodes();
-  anEditor.Remove( IdList, true );
+  myEditor.Remove( IdList, true );
   myMesh->GetMeshDS()->Modified();
   if ( IdList.size() )
     myMesh->SetIsModified( true );
@@ -549,7 +689,7 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
 
 //=============================================================================
 /*!
- *
+ * Add a new node.
  */
 //=============================================================================
 
@@ -571,9 +711,10 @@ CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
 
 //=============================================================================
 /*!
- *
+ * Create 0D element on the given node.
  */
 //=============================================================================
+
 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
 {
   initData();
@@ -595,7 +736,38 @@ CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
 
 //=============================================================================
 /*!
- *
+ * Create a ball element on the given node.
+ */
+//=============================================================================
+
+CORBA::Long SMESH_MeshEditor_i::AddBall(CORBA::Long IDOfNode, CORBA::Double diameter)
+  throw (SALOME::SALOME_Exception)
+{
+  initData();
+
+  if ( diameter < std::numeric_limits<double>::min() )
+    THROW_SALOME_CORBA_EXCEPTION("Invalid diameter", SALOME::BAD_PARAM);
+
+  const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
+  SMDS_MeshElement* elem = GetMeshDS()->AddBall(aNode, diameter);
+
+  // Update Python script
+  TPythonDump() << "ballElem = "
+                << this << ".AddBall( " << IDOfNode << ", " << diameter <<" )";
+
+  myMesh->GetMeshDS()->Modified();
+  myMesh->SetIsModified( true ); // issue 0020693
+
+  if (elem)
+    return elem->GetID();
+
+  return 0;
+}
+
+//=============================================================================
+/*!
+ * Create an edge, either linear and quadratic (this is determed
+ *  by number of given nodes, two or three)
  */
 //=============================================================================
 
@@ -712,7 +884,8 @@ CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsO
 
 //=============================================================================
 /*!
- *
+ * Create volume, either linear and quadratic (this is determed
+ *  by number of given nodes)
  */
 //=============================================================================
 
@@ -1039,8 +1212,7 @@ CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
                 << NodeID1 << ", " << NodeID2 << " )";
 
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
-  int ret =  aMeshEditor.InverseDiag ( n1, n2 );
+  int ret =  myEditor.InverseDiag ( n1, n2 );
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
   return ret;
@@ -1066,15 +1238,14 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
   TPythonDump() << "isDone = " << this << ".DeleteDiag( "
                 << NodeID1 << ", " << NodeID2 <<  " )";
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
-  bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
+  bool stat = myEditor.DeleteDiag ( n1, n2 );
 
   myMesh->GetMeshDS()->Modified();
   if ( stat )
     myMesh->SetIsModified( true ); // issue 0020693
 
-  storeResult(aMeshEditor);
+  storeResult(myEditor);
 
   return stat;
 }
@@ -1089,13 +1260,12 @@ CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfEleme
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   for (int i = 0; i < IDsOfElements.length(); i++)
   {
     CORBA::Long index = IDsOfElements[i];
     const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
     if ( elem )
-      anEditor.Reorient( elem );
+      myEditor.Reorient( elem );
   }
   // Update Python script
   TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
@@ -1129,6 +1299,93 @@ CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theO
   return isDone;
 }
 
+//=======================================================================
+//function : Reorient2D
+//purpose  : Reorient faces contained in \a the2Dgroup.
+//           the2Dgroup   - the mesh or its part to reorient
+//           theDirection - desired direction of normal of \a theFace
+//           theFace      - ID of face whose orientation is checked.
+//           It can be < 1 then \a thePoint is used to find a face.
+//           thePoint     - is used to find a face if \a theFace < 1.
+//           return number of reoriented elements.
+//=======================================================================
+
+CORBA::Long SMESH_MeshEditor_i::Reorient2D(SMESH::SMESH_IDSource_ptr the2Dgroup,
+                                           const SMESH::DirStruct&   theDirection,
+                                           CORBA::Long               theFace,
+                                           const SMESH::PointStruct& thePoint)
+  throw (SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+
+  initData(/*deleteSearchers=*/false);
+
+  TIDSortedElemSet elements;
+  if ( !idSourceToSet( the2Dgroup, GetMeshDS(), elements, SMDSAbs_Face, /*emptyIfIsMesh=*/1))
+    THROW_SALOME_CORBA_EXCEPTION("No faces in given group", SALOME::BAD_PARAM);
+
+
+  const SMDS_MeshElement* face = 0;
+  if ( theFace > 0 )
+  {
+    face = GetMeshDS()->FindElement( theFace );
+    if ( !face )
+      THROW_SALOME_CORBA_EXCEPTION("Inexistent face given", SALOME::BAD_PARAM);
+    if ( face->GetType() != SMDSAbs_Face )
+      THROW_SALOME_CORBA_EXCEPTION("Wrong element type", SALOME::BAD_PARAM);
+  }
+  else
+  {
+    // create theElementSearcher if needed
+    theSearchersDeleter.Set( myMesh, getPartIOR( the2Dgroup, SMESH::FACE ));
+    if ( !theElementSearcher )
+    {
+      if ( elements.empty() ) // search in the whole mesh
+      {
+        if ( myMesh->NbFaces() == 0 )
+          THROW_SALOME_CORBA_EXCEPTION("No faces in the mesh", SALOME::BAD_PARAM);
+
+        theElementSearcher = myEditor.GetElementSearcher();
+      }
+      else
+      {
+        typedef SMDS_SetIterator<const SMDS_MeshElement*, TIDSortedElemSet::const_iterator > TIter;
+        SMDS_ElemIteratorPtr elemsIt( new TIter( elements.begin(), elements.end() ));
+
+        theElementSearcher = myEditor.GetElementSearcher(elemsIt);
+      }
+    }
+    // find a face
+    gp_Pnt p( thePoint.x, thePoint.y, thePoint.z );
+    face = theElementSearcher->FindClosestTo( p, SMDSAbs_Face );
+
+    if ( !face )
+      THROW_SALOME_CORBA_EXCEPTION("No face found by point", SALOME::INTERNAL_ERROR );
+    if ( !elements.empty() && !elements.count( face ))
+      THROW_SALOME_CORBA_EXCEPTION("Found face is not in the group", SALOME::BAD_PARAM );
+  }
+
+  const SMESH::PointStruct * P = &theDirection.PS;
+  gp_Vec dirVec( P->x, P->y, P->z );
+  if ( dirVec.Magnitude() < std::numeric_limits< double >::min() )
+    THROW_SALOME_CORBA_EXCEPTION("Zero size vector", SALOME::BAD_PARAM);
+
+  int nbReori = myEditor.Reorient2D( elements, dirVec, face );
+  storeResult(myEditor);
+
+  if ( nbReori ) {
+    myMesh->SetIsModified( true );
+    myMesh->GetMeshDS()->Modified();
+  }
+  TPythonDump() << this << ".Reorient2D( "
+                << the2Dgroup << ", "
+                << theDirection << ", "
+                << theFace << ", "
+                << thePoint << " )";
+
+  return nbReori;
+}
+
 //=============================================================================
 /*!
  *
@@ -1156,14 +1413,13 @@ CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfE
   TPythonDump() << "isDone = " << this << ".TriToQuad( "
                 << IDsOfElements << ", " << aNumericalFunctor << ", " << TVar( MaxAngle ) << " )";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
 
-  bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
+  bool stat = myEditor.TriToQuad( faces, aCrit, MaxAngle );
   myMesh->GetMeshDS()->Modified();
   if ( stat )
     myMesh->SetIsModified( true ); // issue 0020693
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   return stat;
 }
@@ -1221,13 +1477,12 @@ CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array &   IDsOfE
   // Update Python script
   TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
-  CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
+  CORBA::Boolean stat = myEditor.QuadToTri( faces, aCrit );
   myMesh->GetMeshDS()->Modified();
   if ( stat )
     myMesh->SetIsModified( true ); // issue 0020693
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   return stat;
 }
@@ -1276,14 +1531,13 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfEle
   TPythonDump() << "isDone = " << this << ".SplitQuad( "
                 << IDsOfElements << ", " << Diag13 << " )";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
-  CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
+  CORBA::Boolean stat = myEditor.QuadToTri( faces, Diag13 );
   myMesh->GetMeshDS()->Modified();
   if ( stat )
     myMesh->SetIsModified( true ); // issue 0020693
 
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   return stat;
 }
@@ -1333,8 +1587,7 @@ CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long                 IDOfQuad,
     else
       aCrit.reset(new SMESH::Controls::AspectRatio());
 
-    ::SMESH_MeshEditor anEditor (myMesh);
-    return anEditor.BestSplit(quad, aCrit);
+    return myEditor.BestSplit(quad, aCrit);
   }
   return -1;
 }
@@ -1357,11 +1610,10 @@ void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
   TIDSortedElemSet elemSet;
   arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
 
-  ::SMESH_MeshEditor anEditor (myMesh);
-  anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
+  myEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
   myMesh->GetMeshDS()->Modified();
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
 //   if ( myLastCreatedElems.length() ) - it does not influence Compute()
 //     myMesh->SetIsModified( true ); // issue 0020693
@@ -1470,14 +1722,13 @@ SMESH_MeshEditor_i::smooth(const SMESH::long_array &              IDsOfElements,
   if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
     method = ::SMESH_MeshEditor::CENTROIDAL;
 
-  ::SMESH_MeshEditor anEditor( myMesh );
-  anEditor.Smooth(elements, fixedNodes, method,
+  myEditor.Smooth(elements, fixedNodes, method,
                   MaxNbOfIterations, MaxAspectRatio, IsParametric );
 
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true ); // issue 0020693
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   // Update Python script
   TPythonDump() << "isDone = " << this << "."
@@ -1609,11 +1860,10 @@ SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
   gp_Ax1 Ax1 (gp_Pnt( theAxis.x,  theAxis.y,  theAxis.z ),
               gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
 
-  ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::PGroupIDs groupIds =
-      anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
+      myEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
                               theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
-  storeResult(anEditor);
+  storeResult(myEditor);
   myMesh->GetMeshDS()->Modified();
 
   //  myMesh->SetIsModified( true ); -- it does not influence Compute()
@@ -1913,12 +2163,11 @@ SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
     }
 
     TElemOfElemListMap aHystory;
-    ::SMESH_MeshEditor anEditor( mesh );
     ::SMESH_MeshEditor::PGroupIDs groupIds = 
-        anEditor.ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
+        myEditor.ExtrusionSweep (*workElements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
 
     myMesh->GetMeshDS()->Modified();
-    storeResult(anEditor);
+    storeResult(myEditor);
 
     return theMakeGroups ? getGroups(groupIds.get()) : 0;
 
@@ -2187,12 +2436,11 @@ SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements
   const SMESH::PointStruct * P = &theStepVector.PS;
   gp_Vec stepVec( P->x, P->y, P->z );
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   TElemOfElemListMap aHystory;
   ::SMESH_MeshEditor::PGroupIDs groupIds =
-      anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
+      myEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
                                theMakeGroups, theExtrFlags, theSewTolerance);
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   return theMakeGroups ? getGroups(groupIds.get()) : 0;
 }
@@ -2336,13 +2584,12 @@ SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array &   theIDsOfEleme
 
   int nbOldGroups = myMesh->NbGroup();
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   ::SMESH_MeshEditor::Extrusion_Error error =
-      anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
+      myEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
                                     theHasAngles, angles, false,
                                     theHasRefPoint, refPnt, theMakeGroups );
   myMesh->GetMeshDS()->Modified();
-  storeResult(anEditor);
+  storeResult(myEditor);
   theError = convExtrError( error );
 
   if ( theMakeGroups ) {
@@ -2405,7 +2652,6 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
     MakeGroups = false;
   }
 
-  ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::Extrusion_Error error;
 
   if ( SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path ))
@@ -2417,7 +2663,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
       Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
       return EmptyGr;
     }
-    error = anEditor.ExtrusionAlongTrack( *workElements, &(aMeshImp->GetImpl()), aNodeStart,
+    error = myEditor.ExtrusionAlongTrack( *workElements, &(aMeshImp->GetImpl()), aNodeStart,
                                           HasAngles, angles, LinearVariation,
                                           HasRefPoint, refPnt, MakeGroups );
     myMesh->GetMeshDS()->Modified();
@@ -2435,7 +2681,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
     }
     SMESH_subMesh* aSubMesh =
       aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
-    error = anEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart,
+    error = myEditor.ExtrusionAlongTrack( *workElements, aSubMesh, aNodeStart,
                                           HasAngles, angles, LinearVariation,
                                           HasRefPoint, refPnt, MakeGroups );
     myMesh->GetMeshDS()->Modified();
@@ -2452,7 +2698,7 @@ SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array &  IDsOfElements
     return EmptyGr;
   }
 
-  storeResult(anEditor);
+  storeResult(myEditor);
   Error = convExtrError( error );
 
   if ( MakeGroups ) {
@@ -3089,12 +3335,11 @@ SMESH_MeshEditor_i::mirror(TIDSortedElemSet &                  theElements,
     theMakeGroups = false;
   }
 
-  ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::PGroupIDs groupIds =
-      anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+      myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
 
   if(theCopy || myPreviewMode)
-    storeResult(anEditor); // store preview data or new elements
+    storeResult(myEditor); // store preview data or new elements
 
   if ( !myPreviewMode )
   {
@@ -3352,12 +3597,11 @@ SMESH_MeshEditor_i::translate(TIDSortedElemSet        & theElements,
     theMakeGroups = false;
   }
 
-  ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::PGroupIDs groupIds =
-      anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+      myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
 
   if(theCopy || myPreviewMode)
-    storeResult(anEditor);
+    storeResult(myEditor);
 
   if ( !myPreviewMode )
   {
@@ -3602,12 +3846,11 @@ SMESH_MeshEditor_i::rotate(TIDSortedElemSet &        theElements,
     theMakeGroups = false;
   }
 
-  ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::PGroupIDs groupIds =
-      anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+      myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
 
   if(theCopy || myPreviewMode)
-    storeResult(anEditor);
+    storeResult(myEditor);
 
   if ( !myPreviewMode )
   {
@@ -3881,12 +4124,11 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr  theObject,
     theMakeGroups = false;
   }
 
-  ::SMESH_MeshEditor anEditor( mesh );
   ::SMESH_MeshEditor::PGroupIDs groupIds =
-      anEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
+      myEditor.Transform (*workElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
 
   if(theCopy || myPreviewMode )
-    storeResult(anEditor);
+    storeResult(myEditor);
 
   if ( !myPreviewMode )
   {
@@ -4003,9 +4245,8 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tol
   initData();
 
   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
-  ::SMESH_MeshEditor anEditor( myMesh );
   TIDSortedNodeSet nodes; // no input nodes
-  anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
+  myEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
 
   GroupsOfNodes = new SMESH::array_of_long_array;
   GroupsOfNodes->length( aListOfListOfNodes.size() );
@@ -4036,9 +4277,8 @@ void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr
   idSourceToNodeSet( theObject, GetMeshDS(), nodes );
 
   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
-  ::SMESH_MeshEditor anEditor( myMesh );
   if(!nodes.empty())
-    anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
+    myEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
 
   GroupsOfNodes = new SMESH::array_of_long_array;
   GroupsOfNodes->length( aListOfListOfNodes.size() );
@@ -4084,9 +4324,8 @@ FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr      theObject,
       nodes.erase( *avoidNode );
   }
   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
-  ::SMESH_MeshEditor anEditor( myMesh );
   if(!nodes.empty())
-    anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
+    myEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
 
   theGroupsOfNodes = new SMESH::array_of_long_array;
   theGroupsOfNodes->length( aListOfListOfNodes.size() );
@@ -4138,8 +4377,7 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN
     if ( i > 0 ) aTPythonDump << ", ";
     aTPythonDump << aNodeGroup;
   }
-  ::SMESH_MeshEditor anEditor( myMesh );
-  anEditor.MergeNodes( aListOfListOfNodes );
+  myEditor.MergeNodes( aListOfListOfNodes );
 
   aTPythonDump <<  "])";
   myMesh->GetMeshDS()->Modified();
@@ -4172,8 +4410,7 @@ void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr      theObj
     }
 
     ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
-    ::SMESH_MeshEditor anEditor( myMesh );
-    anEditor.FindEqualElements( elems, aListOfListOfElementsID );
+    myEditor.FindEqualElements( elems, aListOfListOfElementsID );
 
     GroupsOfElementsID = new SMESH::array_of_long_array;
     GroupsOfElementsID->length( aListOfListOfElementsID.size() );
@@ -4222,8 +4459,7 @@ void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsO
     aTPythonDump << anElemsIDGroup;
   }
 
-  ::SMESH_MeshEditor anEditor( myMesh );
-  anEditor.MergeElements(aListOfListOfElementsID);
+  myEditor.MergeElements(aListOfListOfElementsID);
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
 
@@ -4239,8 +4475,7 @@ void SMESH_MeshEditor_i::MergeEqualElements()
 {
   initData();
 
-  ::SMESH_MeshEditor anEditor( myMesh );
-  anEditor.MergeEqualElements();
+  myEditor.MergeEqualElements();
 
   myMesh->GetMeshDS()->Modified();
 
@@ -4284,8 +4519,7 @@ CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long   NodeID,
     if ( nodeCpy1 )
       tmpMesh.GetMeshDS()->MoveNode(nodeCpy1, x, y, z);
     // fill preview data
-    ::SMESH_MeshEditor anEditor( & tmpMesh );
-    storeResult( anEditor );
+    storeResult( myEditor );
   }
   else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
     theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
@@ -4317,8 +4551,7 @@ CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
   theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
 
   if ( !theNodeSearcher ) {
-    ::SMESH_MeshEditor anEditor( myMesh );
-    theNodeSearcher = anEditor.GetNodeSearcher();
+    theNodeSearcher = myEditor.GetNodeSearcher();
   }
   gp_Pnt p( x,y,z );
   if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
@@ -4352,8 +4585,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
   if ( !node ) // preview moving node
   {
     if ( !theNodeSearcher ) {
-      ::SMESH_MeshEditor anEditor( myMesh );
-      theNodeSearcher = anEditor.GetNodeSearcher();
+      theNodeSearcher = myEditor.GetNodeSearcher();
     }
     gp_Pnt p( x,y,z );
     node = theNodeSearcher->FindClosestTo( p );
@@ -4377,8 +4609,7 @@ CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
       if ( node )
         tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
       // fill preview data
-      ::SMESH_MeshEditor anEditor( & tmpMesh );
-      storeResult( anEditor );
+      storeResult( myEditor );
     }
     else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
     {
@@ -4421,8 +4652,7 @@ SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double      x,
 
   theSearchersDeleter.Set( myMesh );
   if ( !theElementSearcher ) {
-    ::SMESH_MeshEditor anEditor( myMesh );
-    theElementSearcher = anEditor.GetElementSearcher();
+    theElementSearcher = myEditor.GetElementSearcher();
   }
   theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
                                            SMDSAbs_ElementType( type ),
@@ -4459,22 +4689,16 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID
   
   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 ) &&
+       ( types[0] == SMESH::NODE || types[0] == SMESH::ELEM0D || types[0] == SMESH::BALL) &&
        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 );
+  theSearchersDeleter.Set( myMesh, getPartIOR( elementIDs, type ));
   if ( !theElementSearcher )
   {
     // create a searcher from elementIDs
@@ -4488,8 +4712,7 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID
     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);
+    theElementSearcher = myEditor.GetElementSearcher(elemsIt);
   }
 
   vector< const SMDS_MeshElement* > foundElems;
@@ -4524,8 +4747,7 @@ CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
 {
   theSearchersDeleter.Set( myMesh );
   if ( !theElementSearcher ) {
-    ::SMESH_MeshEditor anEditor( myMesh );
-    theElementSearcher = anEditor.GetElementSearcher();
+    theElementSearcher = myEditor.GetElementSearcher();
   }
   return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
 }
@@ -4599,9 +4821,8 @@ SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
                 << CreatePolygons<< ", "
                 << CreatePolyedrs<< " )";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
-    convError( anEditor.SewFreeBorder (aBorderFirstNode,
+    convError( myEditor.SewFreeBorder (aBorderFirstNode,
                                        aBorderSecondNode,
                                        aBorderLastNode,
                                        aSide2FirstNode,
@@ -4611,7 +4832,7 @@ SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
                                        CreatePolygons,
                                        CreatePolyedrs) );
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
@@ -4658,9 +4879,8 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
                 << FirstNodeID2  << ", "
                 << SecondNodeID2 << " )";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
-    convError( anEditor.SewFreeBorder (aBorderFirstNode,
+    convError( myEditor.SewFreeBorder (aBorderFirstNode,
                                        aBorderSecondNode,
                                        aBorderLastNode,
                                        aSide2FirstNode,
@@ -4669,7 +4889,7 @@ SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
                                        true,
                                        false, false) );
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
@@ -4720,9 +4940,8 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
                 << CreatePolygons           << ", "
                 << CreatePolyedrs           << ") ";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
-    convError( anEditor.SewFreeBorder (aBorderFirstNode,
+    convError( myEditor.SewFreeBorder (aBorderFirstNode,
                                        aBorderSecondNode,
                                        aBorderLastNode,
                                        aSide2FirstNode,
@@ -4732,7 +4951,7 @@ SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
                                        CreatePolygons,
                                        CreatePolyedrs) );
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
@@ -4782,15 +5001,14 @@ SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
                 << NodeID2OfSide1ToMerge << ", "
                 << NodeID2OfSide2ToMerge << ")";
 
-  ::SMESH_MeshEditor anEditor( myMesh );
   SMESH::SMESH_MeshEditor::Sew_Error error =
-    convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
+    convError( myEditor.SewSideElements (aSide1Elems, aSide2Elems,
                                          aFirstNode1ToMerge,
                                          aFirstNode2ToMerge,
                                          aSecondNode1ToMerge,
                                          aSecondNode2ToMerge));
 
-  storeResult(anEditor);
+  storeResult(myEditor);
 
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
@@ -4839,145 +5057,6 @@ CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
   return res;
 }
 
-//================================================================================
-/*!
- * \brief Update myLastCreated* or myPreviewData
- * \param anEditor - it contains last modification results
- */
-//================================================================================
-
-void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
-{
-  if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
-
-    list<int> aNodesConnectivity;
-    typedef map<int, int> TNodesMap;
-    TNodesMap nodesMap;
-
-    TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
-    SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
-
-    SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
-    int nbEdges = aMeshDS->NbEdges();
-    int nbFaces = aMeshDS->NbFaces();
-    int nbVolum = aMeshDS->NbVolumes();
-    switch ( previewType ) {
-    case SMDSAbs_Edge  : nbFaces = nbVolum = 0; break;
-    case SMDSAbs_Face  : nbEdges = nbVolum = 0; break;
-    case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
-    default:;
-    }
-    myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
-    myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
-    int i = 0, j = 0;
-    SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
-
-    while ( itMeshElems->more() ) {
-      const SMDS_MeshElement* aMeshElem = itMeshElems->next();
-      if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
-        continue;
-
-      SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
-      while ( itElemNodes->more() ) {
-        const SMDS_MeshNode* aMeshNode =
-          static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
-        int aNodeID = aMeshNode->GetID();
-        TNodesMap::iterator anIter = nodesMap.find(aNodeID);
-        if ( anIter == nodesMap.end() ) {
-          // filling the nodes coordinates
-          myPreviewData->nodesXYZ[j].x = aMeshNode->X();
-          myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
-          myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
-          anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
-          j++;
-        }
-        aNodesConnectivity.push_back(anIter->second);
-      }
-
-      // filling the elements types
-      SMDSAbs_ElementType aType;
-      bool isPoly;
-      /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
-        aType = SMDSAbs_Node;
-        isPoly = false;
-        }
-        else*/ {
-        aType = aMeshElem->GetType();
-        isPoly = aMeshElem->IsPoly();
-      }
-
-      myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
-      myPreviewData->elementTypes[i].isPoly = isPoly;
-      myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
-      i++;
-
-    }
-    myPreviewData->nodesXYZ.length( j );
-
-    // filling the elements connectivities
-    list<int>::iterator aConnIter = aNodesConnectivity.begin();
-    myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
-    for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
-      myPreviewData->elementConnectivities[i] = *aConnIter;
-
-    return;
-  }
-
-  {
-    // append new nodes into myLastCreatedNodes
-    const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
-    int j = myLastCreatedNodes->length();
-    int newLen = j + aSeq.Length();
-    myLastCreatedNodes->length( newLen );
-    for(int i=0; j<newLen; i++,j++)
-      myLastCreatedNodes[j] = aSeq.Value(i+1)->GetID();
-  }
-  {
-    // append new elements into myLastCreatedElems
-    const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
-    int j = myLastCreatedElems->length();
-    int newLen = j + aSeq.Length();
-    myLastCreatedElems->length( newLen );
-    for(int i=0; j<newLen; i++,j++)
-      myLastCreatedElems[j] = aSeq.Value(i+1)->GetID();
-  }
-}
-
-//================================================================================
-/*!
- * Return data of mesh edition preview
- */
-//================================================================================
-
-SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
-{
-  return myPreviewData._retn();
-}
-
-//================================================================================
-/*!
- * \brief Returns list of it's IDs of created nodes
- * \retval SMESH::long_array* - list of node ID
- */
-//================================================================================
-
-SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
-{
-  return myLastCreatedNodes._retn();
-}
-
-//================================================================================
-/*!
- * \brief Returns list of it's IDs of created elements
- * \retval SMESH::long_array* - list of elements' ID
- */
-//================================================================================
-
-SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
-{
-  return myLastCreatedElems._retn();
-}
-
 //=======================================================================
 //function : ConvertToQuadratic
 //purpose  :
@@ -4985,8 +5064,7 @@ SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
 
 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
 {
-  ::SMESH_MeshEditor anEditor( myMesh );
-  anEditor.ConvertToQuadratic(theForce3d);
+  myEditor.ConvertToQuadratic(theForce3d);
   TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
   myMesh->GetMeshDS()->Modified();
   myMesh->SetIsModified( true );
@@ -4999,8 +5077,7 @@ void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
 
 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
 {
-  ::SMESH_MeshEditor anEditor( myMesh );
-  CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
+  CORBA::Boolean isDone = myEditor.ConvertFromQuadratic();
   TPythonDump() << this << ".ConvertFromQuadratic()";
   myMesh->GetMeshDS()->Modified();
   if ( isDone )
@@ -5032,8 +5109,7 @@ void SMESH_MeshEditor_i::ConvertToQuadraticObject(CORBA::Boolean            theF
     }
     else
     {
-      ::SMESH_MeshEditor anEditor( myMesh );
-      anEditor.ConvertToQuadratic(theForce3d, elems);
+      myEditor.ConvertToQuadratic(theForce3d, elems);
     }
   }
   myMesh->GetMeshDS()->Modified();
@@ -5066,8 +5142,7 @@ void SMESH_MeshEditor_i::ConvertFromQuadraticObject(SMESH::SMESH_IDSource_ptr th
     }
     else
     {
-      ::SMESH_MeshEditor anEditor( myMesh );
-      anEditor.ConvertFromQuadratic(elems);
+      myEditor.ConvertFromQuadratic(elems);
     }
   }
   myMesh->GetMeshDS()->Modified();
@@ -5163,7 +5238,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNode
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
   list< int > aListOfNodes;
   int i, n;
   for ( i = 0, n = theNodes.length(); i < n; i++ )
@@ -5173,10 +5247,10 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNode
   for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
     aListOfElems.push_back( theModifiedElems[ i ] );
 
-  bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
+  bool aResult = myEditor.DoubleNodes( aListOfNodes, aListOfElems );
 
   myMesh->GetMeshDS()->Modified();
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
   if ( aResult )
     myMesh->SetIsModified( true );
 
@@ -5257,14 +5331,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;
@@ -5278,7 +5353,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
@@ -5288,11 +5362,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();
 }
@@ -5313,7 +5388,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& t
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   std::list< int > aNodes;
   int i, n, j, m;
@@ -5340,9 +5414,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& t
     }
   }
 
-  bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
+  bool aResult = myEditor.DoubleNodes( aNodes, anElems );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5365,8 +5439,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;
 
@@ -5383,11 +5458,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();
 }
@@ -5413,7 +5489,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theE
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes, anAffected;
@@ -5421,9 +5496,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theE
   arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
   arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
 
-  bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
+  bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5456,7 +5531,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_ar
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes;
@@ -5464,9 +5538,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_ar
   arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
 
   TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
-  bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
+  bool aResult = myEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5499,7 +5573,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_pt
 
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes, anAffected;
@@ -5507,9 +5580,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_pt
   idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
   idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
 
-  bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
+  bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5531,18 +5604,43 @@ 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();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes, anAffected;
@@ -5551,28 +5649,52 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_G
   idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
 
 
-  bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
+  bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
+  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->GetName();
+    string aNewName = generateGroupName( string(elemGroupName.in()) + "_double");
+    if ( !myEditor.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 ( !myEditor.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();
 }
 
 //================================================================================
@@ -5598,7 +5720,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_Grou
 
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes, anAffected;
@@ -5606,9 +5727,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_Grou
   idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
 
   TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
-  bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
+  bool aResult = myEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5656,7 +5777,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes, anAffected;
@@ -5664,9 +5784,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroup
   listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
   listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
 
-  bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
+  bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5691,15 +5811,40 @@ 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();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes, anAffected;
@@ -5707,29 +5852,51 @@ SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupsNew(const SMESH::
   listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
   listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
 
-  bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
+  bool aResult = myEditor.DoubleNodes( anElems, aNodes, anAffected );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   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 ( !myEditor.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 ( !myEditor.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();
 }
 
 //================================================================================
@@ -5753,7 +5920,6 @@ SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theE
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
   TIDSortedElemSet anElems, aNodes;
@@ -5761,9 +5927,9 @@ SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theE
   listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
 
   TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
-  bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
+  bool aResult = myEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
 
   myMesh->GetMeshDS()->Modified();
   if ( aResult )
@@ -5775,6 +5941,124 @@ SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theE
   return aResult;
 }
 
+//================================================================================
+/*!
+  \brief Identify the elements that will be affected by node duplication (actual duplication is not performed.
+  This method is the first step of DoubleNodeElemGroupsInRegion.
+  \param theElems - list of groups of elements (edges or faces) to be replicated
+  \param theNodesNot - list of groups of nodes not to replicated
+  \param theShape - shape to detect affected elements (element which geometric center
+         located on or inside shape).
+         The replicated nodes should be associated to affected elements.
+  \return groups of affected elements
+  \sa DoubleNodeElemGroupsInRegion()
+ */
+//================================================================================
+SMESH::ListOfGroups*
+SMESH_MeshEditor_i::AffectedElemGroupsInRegion( const SMESH::ListOfGroups& theElems,
+                                                const SMESH::ListOfGroups& theNodesNot,
+                                                GEOM::GEOM_Object_ptr      theShape )
+{
+  MESSAGE("AffectedElemGroupsInRegion");
+  SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
+  bool isEdgeGroup = false;
+  bool isFaceGroup = false;
+  bool isVolumeGroup = false;
+  SMESH::SMESH_Group_var aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE, "affectedEdges");
+  SMESH::SMESH_Group_var aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE, "affectedFaces");
+  SMESH::SMESH_Group_var aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME, "affectedVolumes");
+
+  initData();
+
+  ::SMESH_MeshEditor aMeshEditor(myMesh);
+
+  SMESHDS_Mesh* aMeshDS = GetMeshDS();
+  TIDSortedElemSet anElems, aNodes;
+  listOfGroupToSet(theElems, aMeshDS, anElems, false);
+  listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true);
+
+  TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape(theShape);
+  TIDSortedElemSet anAffected;
+  bool aResult = aMeshEditor.AffectedElemGroupsInRegion(anElems, aNodes, aShape, anAffected);
+
+  storeResult(aMeshEditor);
+
+  myMesh->GetMeshDS()->Modified();
+  TPythonDump pyDump;
+  if (aResult)
+    {
+      myMesh->SetIsModified(true);
+
+      int lg = anAffected.size();
+      MESSAGE("lg="<< lg);
+      SMESH::long_array_var volumeIds = new SMESH::long_array;
+      volumeIds->length(lg);
+      SMESH::long_array_var faceIds = new SMESH::long_array;
+      faceIds->length(lg);
+      SMESH::long_array_var edgeIds = new SMESH::long_array;
+      edgeIds->length(lg);
+      int ivol = 0;
+      int iface = 0;
+      int iedge = 0;
+
+      TIDSortedElemSet::const_iterator eIt = anAffected.begin();
+      for (; eIt != anAffected.end(); ++eIt)
+        {
+          const SMDS_MeshElement* anElem = *eIt;
+          if (!anElem)
+            continue;
+          int elemId = anElem->GetID();
+          if (myMesh->GetElementType(elemId, true) == SMDSAbs_Volume)
+            volumeIds[ivol++] = elemId;
+          else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Face)
+            faceIds[iface++] = elemId;
+          else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Edge)
+            edgeIds[iedge++] = elemId;
+        }
+      volumeIds->length(ivol);
+      faceIds->length(iface);
+      edgeIds->length(iedge);
+
+      aNewVolumeGroup->Add(volumeIds);
+      aNewFaceGroup->Add(faceIds);
+      aNewEdgeGroup->Add(edgeIds);
+      isVolumeGroup = (aNewVolumeGroup->Size() > 0);
+      isFaceGroup = (aNewFaceGroup->Size() > 0);
+      isEdgeGroup = (aNewEdgeGroup->Size() > 0);
+    }
+
+  int nbGroups = 0;
+  if (isEdgeGroup)
+    nbGroups++;
+  if (isFaceGroup)
+    nbGroups++;
+  if (isVolumeGroup)
+    nbGroups++;
+  aListOfGroups->length(nbGroups);
+
+  int i = 0;
+  if (isEdgeGroup)
+    aListOfGroups[i++] = aNewEdgeGroup._retn();
+  if (isFaceGroup)
+    aListOfGroups[i++] = aNewFaceGroup._retn();
+  if (isVolumeGroup)
+    aListOfGroups[i++] = aNewVolumeGroup._retn();
+
+  // Update Python script
+
+  pyDump << "[ ";
+  if (isEdgeGroup)
+    pyDump << aNewEdgeGroup << ", ";
+  if (isFaceGroup)
+    pyDump << aNewFaceGroup << ", ";
+  if (isVolumeGroup)
+    pyDump << aNewVolumeGroup << ", ";
+  pyDump << "] = ";
+  pyDump << this << ".AffectedElemGroupsInRegion( " << &theElems << ", " << &theNodesNot << ", " << theShape << " )";
+
+  return aListOfGroups._retn();
+}
+
 //================================================================================
 /*!
   \brief Generated skin mesh (containing 2D cells) from 3D mesh
@@ -5787,9 +6071,8 @@ CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
-  bool aResult = aMeshEditor.Make2DMeshFrom3D();
-  storeResult( aMeshEditor) ;
+  bool aResult = myEditor.Make2DMeshFrom3D();
+  storeResult( myEditor) ;
   myMesh->GetMeshDS()->Modified();
   TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
   return aResult;
@@ -5815,7 +6098,6 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
 
@@ -5837,10 +6119,10 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li
     }
   }
 
-  bool aResult = aMeshEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
+  bool aResult = myEditor.DoubleNodesOnGroupBoundaries( domains, createJointElems );
   // TODO publish the groups of flat elements in study
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
   myMesh->GetMeshDS()->Modified();
 
   // Update Python script
@@ -5865,7 +6147,6 @@ CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH:
 {
   initData();
 
-  ::SMESH_MeshEditor aMeshEditor( myMesh );
 
   SMESHDS_Mesh* aMeshDS = GetMeshDS();
 
@@ -5885,10 +6166,10 @@ CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH:
     }
   }
 
-  bool aResult = aMeshEditor.CreateFlatElementsOnFacesGroups( faceGroups );
+  bool aResult = myEditor.CreateFlatElementsOnFacesGroups( faceGroups );
   // TODO publish the groups of flat elements in study
 
-  storeResult( aMeshEditor) ;
+  storeResult( myEditor) ;
   myMesh->GetMeshDS()->Modified();
 
   // Update Python script
@@ -5896,6 +6177,53 @@ CORBA::Boolean SMESH_MeshEditor_i::CreateFlatElementsOnFacesGroups( const SMESH:
   return aResult;
 }
 
+/*!
+ *  \brief identify all the elements around a geom shape, get the faces delimiting the hole
+ *  Build groups of volume to remove, groups of faces to replace on the skin of the object,
+ *  groups of faces to remove inside the object, (idem edges).
+ *  Build ordered list of nodes at the border of each group of faces to replace (to be used to build a geom subshape)
+ */
+void SMESH_MeshEditor_i::CreateHoleSkin(CORBA::Double radius,
+                                        GEOM::GEOM_Object_ptr theShape,
+                                        const char* groupName,
+                                        const SMESH::double_array& theNodesCoords,
+                                        SMESH::array_of_long_array_out GroupsOfNodes)
+throw (SALOME::SALOME_Exception)
+{
+  initData();
+  std::vector<std::vector<int> > aListOfListOfNodes;
+  ::SMESH_MeshEditor aMeshEditor( myMesh );
+
+  theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
+  if ( !theNodeSearcher )
+    theNodeSearcher = aMeshEditor.GetNodeSearcher();
+
+  vector<double> nodesCoords;
+  for (int i = 0; i < theNodesCoords.length(); i++)
+    {
+      nodesCoords.push_back( theNodesCoords[i] );
+  }
+
+  TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
+  aMeshEditor.CreateHoleSkin(radius, aShape, theNodeSearcher, groupName, nodesCoords, aListOfListOfNodes);
+
+  GroupsOfNodes = new SMESH::array_of_long_array;
+  GroupsOfNodes->length( aListOfListOfNodes.size() );
+  std::vector<std::vector<int> >::iterator llIt = aListOfListOfNodes.begin();
+  for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
+    {
+      vector<int>& aListOfNodes = *llIt;
+      vector<int>::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);
+    }
+  TPythonDump() << "lists_nodes = " << this << ".CreateHoleSkin( "
+      << radius << ", " << theShape << ", " << ", " << groupName << ", " << theNodesCoords << " )";
+}
+
+
 // issue 20749 ===================================================================
 /*!
  * \brief Creates missing boundary elements
@@ -5955,14 +6283,13 @@ SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr idSource,
     }
 
     // do it
-    ::SMESH_MeshEditor aMeshEditor( myMesh );
-    aMeshEditor.MakeBoundaryMesh( elements,
+    myEditor.MakeBoundaryMesh( elements,
                                   ::SMESH_MeshEditor::Bnd_Dimension(dim),
                                   smesh_group,
                                   smesh_mesh,
                                   toCopyElements,
                                   toCopyExistingBondary);
-    storeResult( aMeshEditor );
+    storeResult( myEditor );
 
     if ( smesh_mesh )
       smesh_mesh->GetMeshDS()->Modified();
@@ -6100,8 +6427,7 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
       {
         SMESH::Bnd_Dimension bdim = 
           ( elemType == SMDSAbs_Volume ) ? SMESH::BND_2DFROM3D : SMESH::BND_1DFROM2D;
-        ::SMESH_MeshEditor aMeshEditor( srcMesh );
-        nbAdded += aMeshEditor.MakeBoundaryMesh( elements,
+        nbAdded += myEditor.MakeBoundaryMesh( elements,
                                                  ::SMESH_MeshEditor::Bnd_Dimension(bdim),
                                                  smesh_group,
                                                  tgtMesh,
@@ -6109,21 +6435,20 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim,
                                                  /*toCopyExistingBondary=*/srcMesh != tgtMesh,
                                                  /*toAddExistingBondary=*/true,
                                                  /*aroundElements=*/true);
-        storeResult( aMeshEditor );
+        storeResult( myEditor );
       }
     }
   }
   else
   {
-    ::SMESH_MeshEditor aMeshEditor( srcMesh );
-    nbAdded += aMeshEditor.MakeBoundaryMesh( elements,
+    nbAdded += myEditor.MakeBoundaryMesh( elements,
                                              ::SMESH_MeshEditor::Bnd_Dimension(dim),
                                              smesh_group,
                                              tgtMesh,
                                              /*toCopyElements=*/false,
                                              /*toCopyExistingBondary=*/srcMesh != tgtMesh,
                                              /*toAddExistingBondary=*/true);
-    storeResult( aMeshEditor );
+    storeResult( myEditor );
   }
   tgtMesh->GetMeshDS()->Modified();