Salome HOME
Fix to avoid dependence of mesh on itself (it leaded to cycle in 'SetRemovedFromStudy').
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.cxx
index a3041761100ad5f38ffd3c5a961ead1d68dc3d08..20cc26043e36127d0f88380b1313a36392ec0def 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -345,7 +345,7 @@ namespace {
 
 //================================================================================
 /*!
- * \brief Convert a python script using commands of smesh.py
+ * \brief Convert a python script using commands of smeshBuilder.py
  *  \param theScript - Input script
  *  \param theEntry2AccessorMethod - returns method names to access to
  *         objects wrapped with python class
@@ -498,7 +498,7 @@ _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod
 
 //================================================================================
 /*!
- * \brief name of SMESH_Gen in smesh.py
+ * \brief name of SMESH_Gen in smeshBuilder.py
  */
 //================================================================================
 
@@ -916,7 +916,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
 
   // Replace name of SMESH_Gen
 
-  // names of SMESH_Gen methods fully equal to methods defined in smesh.py
+  // names of SMESH_Gen methods fully equal to methods defined in smeshBuilder.py
   static TStringSet smeshpyMethods;
   if ( smeshpyMethods.empty() ) {
     const char * names[] =
@@ -929,7 +929,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
     // smeshgen.Method() --> smesh.Method()
     theCommand->SetObject( SMESH_2smeshpy::SmeshpyName() );
   else
-    // smeshgen.Method() --> smesh.smesh.Method()
+    // smeshgen.Method() --> smesh.Method()
     theCommand->SetObject( SMESH_2smeshpy::GenName() );
 }
 
@@ -982,7 +982,7 @@ void _pyGen::Flush()
   for ( hyp = myHypos.begin(); hyp != myHypos.end(); ++hyp )
     if ( !hyp->IsNull() ) {
       (*hyp)->Flush();
-      // smeshgen.CreateHypothesis() --> smesh.smesh.CreateHypothesis()
+      // smeshgen.CreateHypothesis() --> smesh.CreateHypothesis()
       if ( !(*hyp)->IsWrapped() )
         (*hyp)->GetCreationCmd()->SetObject( SMESH_2smeshpy::GenName() );
     }
@@ -2011,7 +2011,7 @@ void _pyMesh::ClearCommands()
 
 void _pyMesh::addFatherMesh( const _pyID& meshID )
 {
-  if ( !meshID.IsEmpty() )
+  if ( !meshID.IsEmpty() && meshID != GetID() )
     addFatherMesh( Handle(_pyMesh)::DownCast( theGen->FindObject( meshID )));
 }
 
@@ -2023,7 +2023,7 @@ void _pyMesh::addFatherMesh( const _pyID& meshID )
 
 void _pyMesh::addFatherMesh( const Handle(_pyMesh)& mesh )
 {
-  if ( !mesh.IsNull() )
+  if ( !mesh.IsNull() && mesh->GetID() != GetID() )
   {
     //myFatherMeshes.push_back( mesh );
     mesh->myChildMeshes.push_back( this );
@@ -3051,18 +3051,23 @@ void _pyNumberOfSegmentsHyp::Flush()
   list<Handle(_pyCommand)>::reverse_iterator cmd = myUnusedCommands.rbegin();
   int distrTypeNb = 0;
   for ( ; !distrTypeNb && cmd != myUnusedCommands.rend(); ++cmd )
-    if ( (*cmd)->GetMethod() == "SetDistrType" )
-      distrTypeNb = (*cmd)->GetOrderNb();
-    else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" )
+    if ( (*cmd)->GetMethod() == "SetDistrType" ) {
+      if ( cmd != myUnusedCommands.rbegin() )
+        distrTypeNb = (*cmd)->GetOrderNb();
+    }
+    else if (IsWrapped() && (*cmd)->GetMethod() == "SetObjectEntry" ) {
       (*cmd)->Clear();
-
+    }
   // clear commands before the last SetDistrType()
   list<Handle(_pyCommand)> * cmds[2] = { &myArgCommands, &myUnusedCommands };
+  set< int > treatedCmdNbs; // avoid treating same cmd twice
   for ( int i = 0; i < 2; ++i ) {
     set<TCollection_AsciiString> uniqueMethods;
     list<Handle(_pyCommand)> & cmdList = *cmds[i];
     for ( cmd = cmdList.rbegin(); cmd != cmdList.rend(); ++cmd )
     {
+      if ( !treatedCmdNbs.insert( (*cmd)->GetOrderNb() ).second )
+        continue;// avoid treating same cmd twice
       bool clear = ( (*cmd)->GetOrderNb() < distrTypeNb );
       const TCollection_AsciiString& method = (*cmd)->GetMethod();
       if ( !clear || method == "SetNumberOfSegments" ) {
@@ -3311,7 +3316,7 @@ const TCollection_AsciiString & _pyCommand::GetObject()
     }
     myObj = GetWord( myString, begPos, true );
     // check if object is complex,
-    // so far consider case like "smesh.smesh.Method()"
+    // so far consider case like "smesh.Method()"
     if ( int bracketPos = myString.Location( "(", begPos, Length() )) {
       //if ( bracketPos==0 ) bracketPos = Length();
       int dotPos = begPos+myObj.Length();
@@ -3710,9 +3715,9 @@ void _pyCommand::Comment()
     myString.Insert( i, "#" );
     for ( int iPart = 0; iPart < myBegPos.Length(); ++iPart )
     {
-      int begPos = GetBegPos( iPart );
+      int begPos = GetBegPos( iPart + 1 );
       if ( begPos != UNKNOWN )
-        SetBegPos( iPart, begPos + 1 );
+        SetBegPos( iPart + 1, begPos + 1 );
     }
   }
 }