Salome HOME
PAL10494 (SMESH python dump uses idl interface). Python dump converted to smesh...
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
index 2c444819c7bbabe0ebd1f1af78b0a5bfd020426f..9aa35ea1e2ce8320a14051225d9f6ed4260245a6 100644 (file)
@@ -1,23 +1,23 @@
 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
 //
 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
 //
 //
 //
@@ -36,6 +36,7 @@
 
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Filter_i.hxx"
+#include "SMESH_PythonDump.hxx"
 
 #include "utilities.h"
 
 
 #include <sstream>
 
-using namespace std;
+typedef map<const SMDS_MeshElement*,
+            list<const SMDS_MeshElement*> > TElemOfElemListMap;
 
-//=======================================================================
-//function : addAxis
-//purpose  : 
-//=======================================================================
-
-static TCollection_AsciiString& addAxis(TCollection_AsciiString&  theStr,
-                                        const SMESH::AxisStruct & theAxis)
-{
-  theStr += "SMESH.AxisStruct( ";
-  theStr += TCollection_AsciiString( theAxis.x  ) + ", ";
-  theStr += TCollection_AsciiString( theAxis.y  ) + ", ";
-  theStr += TCollection_AsciiString( theAxis.z  ) + ", ";
-  theStr += TCollection_AsciiString( theAxis.vx ) + ", ";
-  theStr += TCollection_AsciiString( theAxis.vy ) + ", ";
-  theStr += TCollection_AsciiString( theAxis.vz ) + " )";
-  return theStr;
-}
+using namespace std;
+using SMESH::TPythonDump;
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -78,7 +65,7 @@ SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -92,11 +79,9 @@ CORBA::Boolean
     IdList.push_back( IDsOfElements[i] );
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.RemoveElements(");
-  SMESH_Gen_i::AddArray( str, IDsOfElements ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"RemoveElements: \", isDone" );
+  TPythonDump() << "print 'RemoveElements: ', isDone";
 #endif
   // Remove Elements
   return anEditor.Remove( IdList, false );
@@ -104,12 +89,11 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
-CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
-       long_array & IDsOfNodes)
+CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
 {
   ::SMESH_MeshEditor anEditor( _myMesh );
   list< int > IdList;
@@ -117,11 +101,9 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
     IdList.push_back( IDsOfNodes[i] );
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.RemoveNodes(");
-  SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"RemoveNodes: \", isDone" );
+  TPythonDump() << "print 'RemoveNodes: ', isDone";
 #endif
 
   return anEditor.Remove( IdList, true );
@@ -129,7 +111,7 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -143,17 +125,15 @@ CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
     GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
 
     // Update Python script
-    TCollection_AsciiString str ("isDone = mesh_editor.AddEdge([");
-    str += TCollection_AsciiString((int) index1) + ", ";
-    str += TCollection_AsciiString((int) index2) + " ])";
-    SMESH_Gen_i::AddToCurrentPyScript( str );
+    TPythonDump() << "isDone = " << this << ".AddEdge([ "
+                  << index1 << ", " << index2 <<" ])";
   }
   return true;
 }
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -163,11 +143,8 @@ CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
   GetMeshDS()->AddNode(x, y, z);
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.AddNode(");
-  str += TCollection_AsciiString( x ) + ", ";
-  str += TCollection_AsciiString( y ) + ", ";
-  str += TCollection_AsciiString( z ) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".AddNode( "
+                << x << ", " << y << ", " << z << " )";
 
   return true;
 }
@@ -204,11 +181,9 @@ CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
   }
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.AddFace(");
-  SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".AddFace( " << IDsOfNodes << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"AddFace: \", isDone" );
+  TPythonDump() << "print 'AddFace: ', isDone";
 #endif
 
   return true;
@@ -216,12 +191,11 @@ CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
-CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
-                                             long_array & IDsOfNodes)
+CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
 {
   int NbNodes = IDsOfNodes.length();
   vector< const SMDS_MeshNode*> n(NbNodes);
@@ -236,13 +210,11 @@ CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
   case 8:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
   }
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.AddVolume(");
-  SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".AddVolume( " << IDsOfNodes << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"AddVolume: \", isDone" );
+  TPythonDump() << "print 'AddVolume: ', isDone";
 #endif
-  
+
   return true;
 };
 
@@ -268,12 +240,10 @@ CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolume
   GetMeshDS()->AddPolyhedralVolume(n, q);
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolume(");
-  SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ", ";
-  SMESH_Gen_i::AddArray( str, Quantities ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".AddPolyhedralVolume( "
+                << IDsOfNodes << ", " << Quantities << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"AddPolyhedralVolume: \", isDone" );
+  TPythonDump() << "print 'AddPolyhedralVolume: ', isDone";
 #endif
 
   return true;
@@ -304,11 +274,10 @@ CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
   GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolumeByFaces(");
-  SMESH_Gen_i::AddArray( str, IdsOfFaces ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".AddPolyhedralVolumeByFaces( "
+                << IdsOfFaces << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"AddPolyhedralVolume: \", isDone" );
+  TPythonDump() << "print 'AddPolyhedralVolume: ', isDone";
 #endif
 
   return true;
@@ -316,7 +285,7 @@ CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -328,23 +297,19 @@ CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long   NodeID,
   const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
   if ( !node )
     return false;
-  
+
   GetMeshDS()->MoveNode(node, x, y, z);
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.MoveNode(");
-  str += TCollection_AsciiString((Standard_Integer) NodeID) + ", ";
-  str += TCollection_AsciiString((Standard_Real) x) + ", ";
-  str += TCollection_AsciiString((Standard_Real) y) + ", ";
-  str += TCollection_AsciiString((Standard_Real) z) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".MoveNode( "
+                << NodeID << ", " << x << ", " << y << ", " << z << " )";
 
   return true;
 }
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -357,10 +322,8 @@ CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
     return false;
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.InverseDiag(");
-  str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
-  str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".InverseDiag( "
+                << NodeID1 << ", " << NodeID2 << " )";
 
   ::SMESH_MeshEditor aMeshEditor( _myMesh );
   return aMeshEditor.InverseDiag ( n1, n2 );
@@ -368,7 +331,7 @@ CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -381,10 +344,8 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
     return false;
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.DeleteDiag(");
-  str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
-  str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".DeleteDiag( "
+                << NodeID1 << ", " << NodeID2 <<  " )";
 
   ::SMESH_MeshEditor aMeshEditor( _myMesh );
   return aMeshEditor.DeleteDiag ( n1, n2 );
@@ -392,7 +353,7 @@ CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -407,9 +368,7 @@ CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfEleme
       anEditor.Reorient( elem );
   }
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.Reorient(");
-  SMESH_Gen_i::AddArray( str, IDsOfElements ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
 
   return true;
 }
@@ -417,7 +376,7 @@ CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfEleme
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -431,23 +390,19 @@ CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theO
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.ReorientObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
 
   return isDone;
 }
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
-
-CORBA::Boolean
-  SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfElements,
-                                 SMESH::NumericalFunctor_ptr Criterion,
-                                 CORBA::Double               MaxAngle)
+CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfElements,
+                                              SMESH::NumericalFunctor_ptr Criterion,
+                                              CORBA::Double               MaxAngle)
 {
   set<const SMDS_MeshElement*> faces;
   for (int i = 0; i < IDsOfElements.length(); i++)
@@ -457,7 +412,7 @@ CORBA::Boolean
     if ( elem && elem->GetType() == SMDSAbs_Face)
       faces.insert( elem );
   }
-  SMESH::NumericalFunctor_i* aNumericalFunctor = 
+  SMESH::NumericalFunctor_i* aNumericalFunctor =
     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
   SMESH::Controls::NumericalFunctorPtr aCrit;
   if ( !aNumericalFunctor )
@@ -466,12 +421,10 @@ CORBA::Boolean
     aCrit = aNumericalFunctor->GetNumericalFunctor();
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.TriToQuad(");
-  SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None, ";
-  str += (Standard_Real) MaxAngle;
-  SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
+  TPythonDump() << "isDone = " << this << ".TriToQuad( "
+                << IDsOfElements << ", None, " << MaxAngle << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuad: \", isDone" );
+  TPythonDump() << "print 'TriToQuad: ', isDone";
 #endif
 
   ::SMESH_MeshEditor anEditor( _myMesh );
@@ -480,14 +433,12 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
-
-CORBA::Boolean
-  SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr   theObject,
-                                      SMESH::NumericalFunctor_ptr Criterion,
-                                      CORBA::Double               MaxAngle)
+CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr   theObject,
+                                                    SMESH::NumericalFunctor_ptr Criterion,
+                                                    CORBA::Double               MaxAngle)
 {
   SMESH::long_array_var anElementsId = theObject->GetIDs();
   CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
@@ -500,12 +451,10 @@ CORBA::Boolean
 #endif
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.TriToQuadObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", None, ";
-  str += (Standard_Real) MaxAngle;
-  SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
+  TPythonDump() << "isDone = " << this << ".TriToQuadObject("
+                << theObject << ", None, " << MaxAngle << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuadObject: \", isDone" );
+  TPythonDump() << "print 'TriToQuadObject: ', isDone";
 #endif
 
   return isDone;
@@ -513,13 +462,11 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
-
-CORBA::Boolean
-  SMESH_MeshEditor_i::QuadToTri(const SMESH::long_array &   IDsOfElements,
-                                SMESH::NumericalFunctor_ptr Criterion)
+CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array &   IDsOfElements,
+                                              SMESH::NumericalFunctor_ptr Criterion)
 {
   set<const SMDS_MeshElement*> faces;
   for (int i = 0; i < IDsOfElements.length(); i++)
@@ -529,7 +476,7 @@ CORBA::Boolean
     if ( elem && elem->GetType() == SMDSAbs_Face)
       faces.insert( elem );
   }
-  SMESH::NumericalFunctor_i* aNumericalFunctor = 
+  SMESH::NumericalFunctor_i* aNumericalFunctor =
     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
   SMESH::Controls::NumericalFunctorPtr aCrit;
   if ( !aNumericalFunctor )
@@ -539,11 +486,9 @@ CORBA::Boolean
 
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.QuadToTri(");
-  SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None ), ";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", None )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"QuadToTri: \", isDone" );
+  TPythonDump() << "print 'QuadToTri: ', isDone";
 #endif
 
   ::SMESH_MeshEditor anEditor( _myMesh );
@@ -552,13 +497,38 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
+CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr   theObject,
+                                                    SMESH::NumericalFunctor_ptr Criterion)
+{
+  SMESH::long_array_var anElementsId = theObject->GetIDs();
+  CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
 
-CORBA::Boolean
-  SMESH_MeshEditor_i::SplitQuad(const SMESH::long_array & IDsOfElements,
-                                CORBA::Boolean            Diag13)
+  // Clear python line(s), created by QuadToTri()
+  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
+  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
+#ifdef _DEBUG_
+  aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
+#endif
+
+  // Update Python script
+  TPythonDump() << "isDone = " << this << ".QuadToTriObject(" << theObject << ", None )";
+#ifdef _DEBUG_
+  TPythonDump() << "print 'QuadToTriObject: ', isDone";
+#endif
+
+  return isDone;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
+                                              CORBA::Boolean            Diag13)
 {
   set<const SMDS_MeshElement*> faces;
   for (int i = 0; i < IDsOfElements.length(); i++)
@@ -570,12 +540,10 @@ CORBA::Boolean
   }
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.SplitQuad(");
-  SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
-  str += TCollection_AsciiString( Diag13 );
-  SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
+  TPythonDump() << "isDone = " << this << ".SplitQuad( "
+                << IDsOfElements << ", " << Diag13 << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuad: \", isDone" );
+  TPythonDump() << "print 'SplitQuad: ', isDone";
 #endif
 
   ::SMESH_MeshEditor anEditor( _myMesh );
@@ -584,13 +552,11 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
-
-CORBA::Boolean
-  SMESH_MeshEditor_i::SplitQuadObject(SMESH::SMESH_IDSource_ptr theObject,
-                                     CORBA::Boolean            Diag13)
+CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
+                                                    CORBA::Boolean            Diag13)
 {
   SMESH::long_array_var anElementsId = theObject->GetIDs();
   CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
@@ -603,20 +569,43 @@ CORBA::Boolean
 #endif
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.SplitQuadObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", ";
-  str += TCollection_AsciiString( Diag13 ) + ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
+                << theObject << ", " << Diag13 << " )";
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuadObject: \", isDone" );
+  TPythonDump() << "print 'SplitQuadObject: ', isDone";
 #endif
 
   return isDone;
 }
 
+//=============================================================================
+/*!
+ *  BestSplit
+ */
+//=============================================================================
+CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long                 IDOfQuad,
+                                           SMESH::NumericalFunctor_ptr Criterion)
+{
+  const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
+  if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
+  {
+    SMESH::NumericalFunctor_i* aNumericalFunctor =
+      dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
+    SMESH::Controls::NumericalFunctorPtr aCrit;
+    if (aNumericalFunctor)
+      aCrit = aNumericalFunctor->GetNumericalFunctor();
+    else
+      aCrit.reset(new SMESH::Controls::AspectRatio());
+
+    ::SMESH_MeshEditor anEditor (_myMesh);
+    return anEditor.BestSplit(quad, aCrit);
+  }
+  return -1;
+}
+
 //=======================================================================
 //function : Smooth
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Boolean
@@ -632,7 +621,7 @@ CORBA::Boolean
 
 //=======================================================================
 //function : SmoothParametric
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Boolean
@@ -648,7 +637,7 @@ CORBA::Boolean
 
 //=======================================================================
 //function : SmoothObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Boolean
@@ -664,7 +653,7 @@ CORBA::Boolean
 
 //=======================================================================
 //function : SmoothParametricObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Boolean
@@ -680,7 +669,7 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
@@ -720,22 +709,15 @@ CORBA::Boolean
                   MaxNbOfIterations, MaxAspectRatio, IsParametric );
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.");
-  str += (char*) (IsParametric ? "SmoothParametric( " : "Smooth( ");
-  SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
-  SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
-  str += (Standard_Integer) MaxNbOfIterations;
-  str += ", ";
-  str += (Standard_Real) MaxAspectRatio;
-  if ( method == ::SMESH_MeshEditor::CENTROIDAL )
-    str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
-  else
-    str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
-  str += IsParametric;
-  str += " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << "."
+                << (IsParametric ? "SmoothParametric( " : "Smooth( ")
+                << IDsOfElements << ", "     << IDsOfFixedNodes << ", "
+                << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
+                << "SMESH.SMESH_MeshEditor."
+                << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
+                     "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"Smooth: \", isDone" );
+  TPythonDump() << "print 'Smooth: ', isDone";
 #endif
 
   return true;
@@ -743,17 +725,17 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
 CORBA::Boolean
-  SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr              theObject,
-                                  const SMESH::long_array &              IDsOfFixedNodes,
-                                  CORBA::Long                            MaxNbOfIterations,
-                                  CORBA::Double                          MaxAspectRatio,
-                                  SMESH::SMESH_MeshEditor::Smooth_Method Method,
-                                   bool                                   IsParametric)
+SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr              theObject,
+                                 const SMESH::long_array &              IDsOfFixedNodes,
+                                 CORBA::Long                            MaxNbOfIterations,
+                                 CORBA::Double                          MaxAspectRatio,
+                                 SMESH::SMESH_MeshEditor::Smooth_Method Method,
+                                 bool                                   IsParametric)
 {
   SMESH::long_array_var anElementsId = theObject->GetIDs();
   CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
@@ -767,22 +749,15 @@ CORBA::Boolean
 #endif
 
   // Update Python script
-  TCollection_AsciiString str ("isDone = mesh_editor.");
-  str += (char*) (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", ";
-  SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
-  str += (Standard_Integer) MaxNbOfIterations;
-  str += ", ";
-  str += (Standard_Real) MaxAspectRatio;
-  if ( Method == ::SMESH_MeshEditor::CENTROIDAL )
-    str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
-  else
-    str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
-  str += IsParametric;
-  str += " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "isDone = " << this << "."
+                << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
+                << theObject << ", " << IDsOfFixedNodes << ", "
+                << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
+                << "SMESH.SMESH_MeshEditor."
+                << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
+                     "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
 #ifdef _DEBUG_
-  SMESH_Gen_i::AddToCurrentPyScript( "print \"SmoothObject: \", isDone" );
+  TPythonDump() << "print 'SmoothObject: ', isDone";
 #endif
 
   return isDone;
@@ -790,35 +765,35 @@ CORBA::Boolean
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
 void SMESH_MeshEditor_i::RenumberNodes()
 {
   // Update Python script
-  SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberNodes()" );
+  TPythonDump() << this << ".RenumberNodes()";
 
   GetMeshDS()->Renumber( true );
 }
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 
 void SMESH_MeshEditor_i::RenumberElements()
 {
   // Update Python script
-  SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberElements()" );
+  TPythonDump() << this << ".RenumberElements()";
 
   GetMeshDS()->Renumber( false );
 }
 
 //=======================================================================
 //function : RotationSweep
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
@@ -845,20 +820,18 @@ void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElement
                           theNbOfSteps, theTolerance);
 
   // Update Python script
-  TCollection_AsciiString str = "axis = ";
-  addAxis( str, theAxis );
-  SMESH_Gen_i::AddToCurrentPyScript( str );
-  str = "mesh_editor.RotationSweep(";
-  SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
-  str += TCollection_AsciiString( theAngleInRadians ) + ", ";
-  str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
-  str += TCollection_AsciiString( theTolerance      ) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "axis = " << theAxis;
+  TPythonDump() << this << ".RotationSweep( "
+                << theIDsOfElements
+                << ", axis, "
+                << theAngleInRadians << ", "
+                << theNbOfSteps << ", "
+                << theTolerance << " )";
 }
 
 //=======================================================================
 //function : RotationSweepObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
@@ -875,17 +848,17 @@ void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString str ("mesh_editor.RotationSweepObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
-  str += TCollection_AsciiString( theAngleInRadians ) + ", ";
-  str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
-  str += TCollection_AsciiString( theTolerance      ) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << this << ".RotationSweepObject( "
+                << theObject
+                << ", axis, "
+                << theAngleInRadians << ", "
+                << theNbOfSteps << ", "
+                << theTolerance << " )";
 }
 
 //=======================================================================
 //function : ExtrusionSweep
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
@@ -906,24 +879,20 @@ void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElemen
   gp_Vec stepVec( P->x, P->y, P->z );
 
   ::SMESH_MeshEditor anEditor( _myMesh );
-  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  TElemOfElemListMap aHystory;
+  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
 
   // Update Python script
-  TCollection_AsciiString str = "stepVector = SMESH.DirStruct( SMESH.PointStruct ( ";
-  str += (TCollection_AsciiString) stepVec.X() + ", ";
-  str += (TCollection_AsciiString) stepVec.Y() + ", ";
-  str += (TCollection_AsciiString) stepVec.Z() + " ))";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
-  str = ("mesh_editor.ExtrusionSweep(");
-  SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", stepVector, ";
-  str += TCollection_AsciiString((int)theNbOfSteps) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "stepVector = " << theStepVector;
+  TPythonDump() << this << ".ExtrusionSweep( "
+                << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
 }
 
 
 //=======================================================================
 //function : ExtrusionSweepObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
@@ -938,14 +907,13 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObjec
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString str ("mesh_editor.ExtrusionSweepObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", stepVector, ";
-  str += TCollection_AsciiString((int)theNbOfSteps) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << this << ".ExtrusionSweepObject( "
+                << theObject << ", stepVector, " << theNbOfSteps << " )";
 }
+
 //=======================================================================
 //function : ExtrusionSweepObject1D
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
@@ -968,12 +936,19 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObj
   gp_Vec stepVec( P->x, P->y, P->z );
 
   ::SMESH_MeshEditor anEditor( _myMesh );
-  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  TElemOfElemListMap aHystory;
+  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
+
+  // Update Python script
+  TPythonDump() << "stepVector = " << theStepVector;
+  TPythonDump() << this << ".ExtrusionSweepObject1D( "
+                << theObject << ", stepVector, " << theNbOfSteps << " )";
 }
 
 //=======================================================================
 //function : ExtrusionSweepObject2D
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
@@ -996,9 +971,57 @@ void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObj
   gp_Vec stepVec( P->x, P->y, P->z );
 
   ::SMESH_MeshEditor anEditor( _myMesh );
-  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  //anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
+  TElemOfElemListMap aHystory;
+  anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory);
+
+  // Update Python script
+  TPythonDump() << "stepVector = " << theStepVector;
+  TPythonDump() << this << ".ExtrusionSweepObject2D( "
+                << theObject << ", stepVector, " << theNbOfSteps << " )";
 }
 
+
+//=======================================================================
+//function : AdvancedExtrusion
+//purpose  :
+//=======================================================================
+
+void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
+                                          const SMESH::DirStruct &  theStepVector,
+                                          CORBA::Long               theNbOfSteps,
+                                          CORBA::Long               theExtrFlags,
+                                          CORBA::Double             theSewTolerance)
+{
+  SMESHDS_Mesh* aMesh = GetMeshDS();
+
+  set<const SMDS_MeshElement*> elements;
+  for (int i = 0; i < theIDsOfElements.length(); i++)
+  {
+    CORBA::Long index = theIDsOfElements[i];
+    const SMDS_MeshElement * elem = aMesh->FindElement(index);
+    if ( elem )
+      elements.insert( elem );
+  }
+  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);
+
+  // Update Python script
+  TPythonDump() << "stepVector = " << theStepVector;
+  TPythonDump() << this << ".AdvancedExtrusion("
+                << theIDsOfElements
+                << ", stepVector, "
+                << theNbOfSteps << ","
+                << theExtrFlags << ", "
+                << theSewTolerance <<  " )";
+}
+
+
 #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 )
@@ -1017,7 +1040,7 @@ static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_Mesh
 
 //=======================================================================
 //function : ExtrusionAlongPath
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH::SMESH_MeshEditor::Extrusion_Error
@@ -1064,39 +1087,39 @@ SMESH::SMESH_MeshEditor::Extrusion_Error
   gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
 
   // Update Python script
-  TCollection_AsciiString str = "refPoint = SMESH.PointStruct( ";
-  str += (TCollection_AsciiString) refPnt.X() + ", ";
-  str += (TCollection_AsciiString) refPnt.Y() + ", ";
-  str += (TCollection_AsciiString) refPnt.Z() + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
-  str = ("error = mesh_editor.ExtrusionAlongPath(");
-  SMESH_Gen_i::AddArray ( str, theIDsOfElements ) += ", ";
-  SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
-  SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
-  str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
-  str += TCollection_AsciiString( (int)theHasAngles ) + ", ";
-  SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
-  str += (TCollection_AsciiString) theHasRefPoint + ", refPoint )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "refPoint = SMESH.PointStruct( "
+                << refPnt.X() << ", "
+                << refPnt.Y() << ", "
+                << refPnt.Z() << " )";
+  TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
+                << theIDsOfElements << ", "
+                << thePathMesh  <<  ", "
+                << thePathShape <<  ", "
+                << theNodeStart << ", "
+                << theHasAngles << ", "
+                << theAngles << ", "
+                << theHasRefPoint << ", refPoint )";
 
   ::SMESH_MeshEditor anEditor( _myMesh );
-  return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
+  return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
+                                                      theHasAngles, angles,
+                                                      theHasRefPoint, refPnt ) );
 }
 
 //=======================================================================
 //function : ExtrusionAlongPathObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH::SMESH_MeshEditor::Extrusion_Error
-  SMESH_MeshEditor_i::ExtrusionAlongPathObject(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_MeshEditor_i::ExtrusionAlongPathObject(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::long_array_var anElementsId = theObject->GetIDs();
   SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
@@ -1108,22 +1131,21 @@ SMESH::SMESH_MeshEditor::Extrusion_Error
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString str ("error = mesh_editor.ExtrusionAlongPathObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", ";
-  SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
-  SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
-  str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
-  str += TCollection_AsciiString( theHasAngles ) + ", ";
-  SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
-  str += TCollection_AsciiString( theHasRefPoint ) + ", refPoint )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
+                << theObject    << ", "
+                << thePathMesh  << ", "
+                << thePathShape << ", "
+                << theNodeStart << ", "
+                << theHasAngles << ", "
+                << theAngles << ", "
+                << theHasRefPoint << ", refPoint )";
 
   return error;
 }
 
 //=======================================================================
 //function : Mirror
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElements,
@@ -1145,7 +1167,7 @@ void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElem
   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
 
   gp_Trsf aTrsf;
-  TCollection_AsciiString typeStr, copyStr( theCopy );
+  TCollection_AsciiString typeStr;
   switch ( theMirrorType ) {
   case  SMESH::SMESH_MeshEditor::POINT:
     aTrsf.SetMirror( P );
@@ -1161,12 +1183,11 @@ void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElem
   }
 
   // Update Python script
-  TCollection_AsciiString str ("mesh_editor.Mirror(");
-  SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", ";
-  addAxis( str, theAxis )           += ", ";
-  str += typeStr                     + ", ";
-  str += copyStr                     + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << this << ".Mirror( "
+                << theIDsOfElements << ", "
+                << theAxis           << ", "
+                << typeStr           << ", "
+                << theCopy           << " )";
 
   ::SMESH_MeshEditor anEditor( _myMesh );
   anEditor.Transform (elements, aTrsf, theCopy);
@@ -1174,7 +1195,7 @@ void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElem
 
 //=======================================================================
 //function : MirrorObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObject,
@@ -1190,7 +1211,7 @@ void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObj
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString typeStr, copyStr( theCopy );
+  TCollection_AsciiString typeStr;
   switch ( theMirrorType ) {
   case  SMESH::SMESH_MeshEditor::POINT:
     typeStr = "SMESH.SMESH_MeshEditor.POINT";
@@ -1201,17 +1222,17 @@ void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObj
   default:
     typeStr = "SMESH.SMESH_MeshEditor.PLANE";
   }
-
-  TCollection_AsciiString str ("mesh_editor.MirrorObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", ";
-  addAxis( str, theAxis ) += ", ";
-  str += typeStr + ", " + copyStr + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "axis = " << theAxis;
+  TPythonDump() << this << ".MirrorObject( "
+                << theObject << ", "
+                << "axis, "
+                << typeStr << ", "
+                << theCopy << " )";
 }
 
 //=======================================================================
 //function : Translate
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
@@ -1236,20 +1257,16 @@ void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
   anEditor.Transform (elements, aTrsf, theCopy);
 
   // Update Python script
-  TCollection_AsciiString str = "vector = SMESH.DirStruct( SMESH.PointStruct ( ";
-  str += (TCollection_AsciiString) P->x + ", ";
-  str += (TCollection_AsciiString) P->y + ", ";
-  str += (TCollection_AsciiString) P->z + " ))";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
-  str = ("mesh_editor.Translate(");
-  SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", vector, ";
-  str += (TCollection_AsciiString) theCopy + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "vector = " << theVector;
+  TPythonDump() << this << ".Translate( "
+                << theIDsOfElements
+                << ", vector, "
+                << theCopy << " )";
 }
 
 //=======================================================================
 //function : TranslateObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
@@ -1264,15 +1281,15 @@ void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString str ("mesh_editor.TranslateObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", vector, ";
-  str += TCollection_AsciiString( theCopy ) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << this << ".TranslateObject( "
+                << theObject
+                << ", vector, "
+                << theCopy << " )";
 }
 
 //=======================================================================
 //function : Rotate
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
@@ -1295,24 +1312,22 @@ 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);
 
   // Update Python script
-  TCollection_AsciiString str ("axis = ");
-  addAxis( str, theAxis );
-  SMESH_Gen_i::AddToCurrentPyScript( str );
-  str = ("mesh_editor.Rotate(");
-  SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
-  str += (TCollection_AsciiString) theAngle + ", ";
-  str += (TCollection_AsciiString) theCopy + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "axis = " << theAxis;
+  TPythonDump() << this << ".Rotate( "
+                << theIDsOfElements
+                << ", axis, "
+                << theAngle << ", "
+                << theCopy << " )";
 }
 
 //=======================================================================
 //function : RotateObject
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
@@ -1328,16 +1343,16 @@ void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
 
   // Update Python script
-  TCollection_AsciiString str ("mesh_editor.RotateObject(");
-  SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
-  str += TCollection_AsciiString( theAngle ) + ", ";
-  str += TCollection_AsciiString( theCopy ) + " )";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << this << ".RotateObject( "
+                << theObject
+                << ", axis, "
+                << theAngle << ", "
+                << theCopy << " )";
 }
 
 //=======================================================================
 //function : FindCoincidentNodes
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tolerance,
@@ -1360,18 +1375,22 @@ void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tol
     for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
       aGroup[ j ] = (*lIt)->GetID();
   }
+  // Update Python script
+  TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
+                << Tolerance << " )";
 }
 
 //=======================================================================
 //function : MergeNodes
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
 {
   SMESHDS_Mesh* aMesh = GetMeshDS();
 
-  TCollection_AsciiString str( "mesh_editor.MergeNodes([" );
+  TPythonDump aTPythonDump;
+  aTPythonDump << this << ".MergeNodes([";
   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
   for (int i = 0; i < GroupsOfNodes.length(); i++)
   {
@@ -1388,20 +1407,19 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN
     if ( aListOfNodes.size() < 2 )
       aListOfListOfNodes.pop_back();
 
-    if ( i > 0 )
-      str += ",";
-    SMESH_Gen_i::AddArray( str, aNodeGroup );
+    if ( i > 0 ) aTPythonDump << ", ";
+    aTPythonDump << aNodeGroup;
   }
   ::SMESH_MeshEditor anEditor( _myMesh );
   anEditor.MergeNodes( aListOfListOfNodes );
 
   // Update Python script
-  SMESH_Gen_i::AddToCurrentPyScript( str + "])" );
+  aTPythonDump <<  "])";
 }
 
 //=======================================================================
 //function : MergeEqualElements
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void SMESH_MeshEditor_i::MergeEqualElements()
@@ -1410,12 +1428,12 @@ void SMESH_MeshEditor_i::MergeEqualElements()
   anEditor.MergeEqualElements();
 
   // Update Python script
-  SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.MergeEqualElements()" );
+  TPythonDump() << this << ".MergeEqualElements()";
 }
 
 //=======================================================================
 //function : operator
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
@@ -1439,7 +1457,7 @@ static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Se
 
 //=======================================================================
 //function : SewFreeBorders
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH::SMESH_MeshEditor::Sew_Error
@@ -1471,16 +1489,15 @@ SMESH::SMESH_MeshEditor::Sew_Error
     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
 
   // Update Python script
-  TCollection_AsciiString str ("error = mesh_editor.SewFreeBorders( ");
-  str += TCollection_AsciiString( (int) FirstNodeID1  )  + ", ";
-  str += TCollection_AsciiString( (int) SecondNodeID1 )  + ", ";
-  str += TCollection_AsciiString( (int) LastNodeID1   )  + ", ";
-  str += TCollection_AsciiString( (int) FirstNodeID2  )  + ", ";
-  str += TCollection_AsciiString( (int) SecondNodeID2 )  + ", ";
-  str += TCollection_AsciiString( (int) LastNodeID2   )  + ", ";
-  str += TCollection_AsciiString( CreatePolygons      )  + ", ";
-  str += TCollection_AsciiString( CreatePolyedrs      )  + ") ";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "error = " << this << ".SewFreeBorders( "
+                << FirstNodeID1  << ", "
+                << SecondNodeID1 << ", "
+                << LastNodeID1   << ", "
+                << FirstNodeID2  << ", "
+                << SecondNodeID2 << ", "
+                << LastNodeID2   << ", "
+                << CreatePolygons<< ", "
+                << CreatePolyedrs<< " )";
 
   ::SMESH_MeshEditor anEditor( _myMesh );
   return convError( anEditor.SewFreeBorder (aBorderFirstNode,
@@ -1496,15 +1513,15 @@ SMESH::SMESH_MeshEditor::Sew_Error
 
 //=======================================================================
 //function : SewConformFreeBorders
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH::SMESH_MeshEditor::Sew_Error
-  SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
-                                            CORBA::Long SecondNodeID1,
-                                            CORBA::Long LastNodeID1,
-                                            CORBA::Long FirstNodeID2,
-                                            CORBA::Long SecondNodeID2)
+SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
+                                          CORBA::Long SecondNodeID1,
+                                          CORBA::Long LastNodeID1,
+                                          CORBA::Long FirstNodeID2,
+                                          CORBA::Long SecondNodeID2)
 {
   SMESHDS_Mesh* aMesh = GetMeshDS();
 
@@ -1524,13 +1541,12 @@ SMESH::SMESH_MeshEditor::Sew_Error
     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
 
   // Update Python script
-  TCollection_AsciiString str ("error = mesh_editor.SewConformFreeBorders( ");
-  str += TCollection_AsciiString( (int) FirstNodeID1  )  + ", ";
-  str += TCollection_AsciiString( (int) SecondNodeID1 )  + ", ";
-  str += TCollection_AsciiString( (int) LastNodeID1   )  + ", ";
-  str += TCollection_AsciiString( (int) FirstNodeID2  )  + ", ";
-  str += TCollection_AsciiString( (int) SecondNodeID2 )  + ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
+                << FirstNodeID1  << ", "
+                << SecondNodeID1 << ", "
+                << LastNodeID1   << ", "
+                << FirstNodeID2  << ", "
+                << SecondNodeID2 << " )";
 
   ::SMESH_MeshEditor anEditor( _myMesh );
   return convError( anEditor.SewFreeBorder (aBorderFirstNode,
@@ -1545,17 +1561,17 @@ SMESH::SMESH_MeshEditor::Sew_Error
 
 //=======================================================================
 //function : SewBorderToSide
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH::SMESH_MeshEditor::Sew_Error
-  SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
-                                      CORBA::Long SecondNodeIDOnFreeBorder,
-                                      CORBA::Long LastNodeIDOnFreeBorder,
-                                      CORBA::Long FirstNodeIDOnSide,
-                                      CORBA::Long LastNodeIDOnSide,
-                                      CORBA::Boolean CreatePolygons,
-                                      CORBA::Boolean CreatePolyedrs)
+SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
+                                    CORBA::Long SecondNodeIDOnFreeBorder,
+                                    CORBA::Long LastNodeIDOnFreeBorder,
+                                    CORBA::Long FirstNodeIDOnSide,
+                                    CORBA::Long LastNodeIDOnSide,
+                                    CORBA::Boolean CreatePolygons,
+                                    CORBA::Boolean CreatePolyedrs)
 {
   SMESHDS_Mesh* aMesh = GetMeshDS();
 
@@ -1575,15 +1591,14 @@ SMESH::SMESH_MeshEditor::Sew_Error
     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
 
   // Update Python script
-  TCollection_AsciiString str ("error = mesh_editor.SewBorderToSide( ");
-  str += TCollection_AsciiString( (int) FirstNodeIDOnFreeBorder  ) + ", ";
-  str += TCollection_AsciiString( (int) SecondNodeIDOnFreeBorder ) + ", ";
-  str += TCollection_AsciiString( (int) LastNodeIDOnFreeBorder   ) + ", ";
-  str += TCollection_AsciiString( (int) FirstNodeIDOnSide        ) + ", ";
-  str += TCollection_AsciiString( (int) LastNodeIDOnSide         ) + ", ";
-  str += TCollection_AsciiString( CreatePolygons                 ) + ", ";
-  str += TCollection_AsciiString( CreatePolyedrs                 ) + ") ";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "error = " << this << ".SewBorderToSide( "
+                << FirstNodeIDOnFreeBorder  << ", "
+                << SecondNodeIDOnFreeBorder << ", "
+                << LastNodeIDOnFreeBorder   << ", "
+                << FirstNodeIDOnSide        << ", "
+                << LastNodeIDOnSide         << ", "
+                << CreatePolygons           << ", "
+                << CreatePolyedrs           << ") ";
 
   ::SMESH_MeshEditor anEditor( _myMesh );
   return convError( anEditor.SewFreeBorder (aBorderFirstNode,
@@ -1599,16 +1614,16 @@ SMESH::SMESH_MeshEditor::Sew_Error
 
 //=======================================================================
 //function : SewSideElements
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH::SMESH_MeshEditor::Sew_Error
-  SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
-                                      const SMESH::long_array& IDsOfSide2Elements,
-                                      CORBA::Long NodeID1OfSide1ToMerge,
-                                      CORBA::Long NodeID1OfSide2ToMerge,
-                                      CORBA::Long NodeID2OfSide1ToMerge,
-                                      CORBA::Long NodeID2OfSide2ToMerge)
+SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
+                                    const SMESH::long_array& IDsOfSide2Elements,
+                                    CORBA::Long NodeID1OfSide1ToMerge,
+                                    CORBA::Long NodeID1OfSide2ToMerge,
+                                    CORBA::Long NodeID2OfSide1ToMerge,
+                                    CORBA::Long NodeID2OfSide2ToMerge)
 {
   SMESHDS_Mesh* aMesh = GetMeshDS();
 
@@ -1640,14 +1655,13 @@ SMESH::SMESH_MeshEditor::Sew_Error
       aSide2Elems.insert( elem );
   }
   // Update Python script
-  TCollection_AsciiString str ("error = mesh_editor.SewSideElements( ");
-  SMESH_Gen_i::AddArray( str, IDsOfSide1Elements ) += ", ";
-  SMESH_Gen_i::AddArray( str, IDsOfSide2Elements ) += ", ";
-  str += TCollection_AsciiString( (int) NodeID1OfSide1ToMerge ) + ", ";
-  str += TCollection_AsciiString( (int) NodeID1OfSide2ToMerge ) + ", ";
-  str += TCollection_AsciiString( (int) NodeID2OfSide1ToMerge ) + ", ";
-  str += TCollection_AsciiString( (int) NodeID2OfSide2ToMerge ) + ")";
-  SMESH_Gen_i::AddToCurrentPyScript( str );
+  TPythonDump() << "error = " << this << ".SewSideElements( "
+                << IDsOfSide1Elements << ", "
+                << IDsOfSide2Elements << ", "
+                << NodeID1OfSide1ToMerge << ", "
+                << NodeID1OfSide2ToMerge << ", "
+                << NodeID2OfSide1ToMerge << ", "
+                << NodeID2OfSide2ToMerge << ")";
 
   ::SMESH_MeshEditor anEditor( _myMesh );
   return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,