Salome HOME
Debug (problem with SALOME_Notebook::Substitute method)
authorouv <ouv@opencascade.com>
Thu, 3 Dec 2009 11:20:36 +0000 (11:20 +0000)
committerouv <ouv@opencascade.com>
Thu, 3 Dec 2009 11:20:36 +0000 (11:20 +0000)
src/Notebook/SALOME_EvalParser.cxx
src/Notebook/SALOME_EvalParser.hxx
src/Notebook/SALOME_Notebook.cxx

index d022a1ca101ac7627e0e273303a601e78493ed44..72fa687d1f916e891b631447b0b3e4a71f89b55e 100755 (executable)
@@ -945,6 +945,19 @@ bool SALOME_EvalParser::isMonoParam() const
   return myError==EvalExpr_OK && myPostfix.size()==1 && myPostfix.begin()->myType==Param;
 }
 
+//=======================================================================
+//function : isMonoParam
+//purpose  :
+//=======================================================================
+bool SALOME_EvalParser::hasPostfix( const SALOME_String& theName ) const
+{
+  Postfix::const_iterator it = myPostfix.begin(), last = myPostfix.end();
+  for( ; it!=last; it++ )
+    if( it->myValue.toString() == theName )
+      return true;
+  return false;
+}
+
 //=======================================================================
 //function : substitute
 //purpose  :
index 673c1d195c8969227987ec61f46bee33684e6ff3..bc9480b155fbaef768d0448c92f4a4b52f2d6163 100755 (executable)
@@ -68,6 +68,8 @@ public:
   SALOME_StringList          parameters     () const;
   bool                       isMonoParam    () const;
 
+  virtual bool               hasPostfix( const SALOME_String& theName ) const;
+
   static SALOME_String       toString( const SALOME_ListOfEvalVariant& theList );
 
 protected:
index e01da251201f70583f00a79507da2b5de48ded16..fbc02177680f5e56943110527a635ac65e86425a 100644 (file)
@@ -309,12 +309,26 @@ bool SALOME_Notebook::Substitute( SubstitutionInfo& theSubstitution )
       for( int i=0; i<n; i++ )
       {
         //printf( "\t%s\n", aParams[i].in() );
+        // the code below has been improved to take into account cases when
+        // a parameter is not just a variable name, but an expression
+        // (to discuss with ASL)
+        /*
         if( anOldName == aParams[i].in() )
         {
           if( !isRename )
             AddExpression( aNewName.c_str() );
           aParams[i] = CORBA::string_dup( aNewName.c_str() );
         }
+        */
+        SALOME_EvalExpr aTmpExpr1( aParams[i].in() );
+        if( aTmpExpr1.parser()->hasPostfix( anOldName ) )
+        {
+          if( !isRename && anOldName == aParams[i].in() )
+            AddExpression( aNewName.c_str() );
+          SALOME_EvalExpr aTmpExpr2( aNewName );
+          aTmpExpr1.substitute( anOldName, aTmpExpr2 );
+          aParams[i] = CORBA::string_dup( aTmpExpr1.expression().c_str() );
+        }
       }
       anObj->SetParameters( _this(), aParams );
     }