Salome HOME
Implementations of Update(), Calculate()
authorasl <asl@opencascade.com>
Mon, 7 Dec 2009 11:19:46 +0000 (11:19 +0000)
committerasl <asl@opencascade.com>
Mon, 7 Dec 2009 11:19:46 +0000 (11:19 +0000)
src/Notebook/SALOME_Notebook.cxx
src/Notebook/SALOME_Notebook.hxx

index fbc02177680f5e56943110527a635ac65e86425a..75863cad0d735eb4d7d188c6d3a3e9f084589a6e 100644 (file)
@@ -244,7 +244,12 @@ bool SALOME_Notebook::CanUpdate( SALOME::ParameterizedObject_ptr theObj ) const
   return !myUpdateOnlyParameters || !CORBA::is_nil( aParam );
 }
 
-void SALOME_Notebook::Update( CORBA::Boolean theOnlyParameters )
+void SALOME_Notebook::Update()
+{
+  Update( false );
+}
+
+void SALOME_Notebook::Update( bool theOnlyParameters )
 {
   myUpdateOnlyParameters = theOnlyParameters;
   //Utils_Locker lock( &myMutex );
@@ -309,26 +314,12 @@ 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 );
     }
@@ -1109,3 +1100,16 @@ bool SALOME_Notebook::HasDependency( const std::string& theObjKey, const std::st
   std::map< std::string, std::list<std::string> >::const_iterator it = myDependencies.find( theObjKey );
   return it==myDependencies.end() ? false : find( it->second.begin(), it->second.end(), theRefKey ) != it->second.end();
 }
+
+SALOME::Parameter_ptr SALOME_Notebook::Calculate( const char* theExpr )
+{
+  if( CORBA::is_nil( myTmpParam ) )
+  {
+    SALOME_Parameter* aParam = new SALOME_Parameter( this, "__tmp__", 0.0 );
+    myTmpParam = aParam->_this();
+  }
+
+  myTmpParam->SetExpression( theExpr );
+  myTmpParam->Update( _this() );
+  return myTmpParam.in();
+}
index 2fe29235049148d00032c60dd4fd6681f9a64497..b26df17508cccc2c0d4f0aa4d1238cf35a361019 100644 (file)
@@ -56,7 +56,7 @@ public:
   virtual void RemoveDependency( SALOME::ParameterizedObject_ptr theObj, SALOME::ParameterizedObject_ptr theRef );
   virtual void ClearDependencies( SALOME::ParameterizedObject_ptr theObj, SALOME::DependenciesType theType );
   virtual void SetToUpdate( SALOME::ParameterizedObject_ptr theObj );
-  virtual void Update( CORBA::Boolean theOnlyParameters );
+  virtual void Update();
 
   virtual void AddExpression( const char* theExpr );
   virtual void AddNamedExpression( const char* theName, const char* theExpr );
@@ -70,6 +70,8 @@ public:
   virtual SALOME::StringArray* Parameters();
   virtual SALOME::StringArray* AbsentParameters( const char* theExpr );
 
+  virtual SALOME::Parameter_ptr Calculate( const char* theExpr );
+
   virtual CORBA::Boolean Save( const char* theFileName );
   virtual CORBA::Boolean Load( const char* theFileName );
   virtual char*          DumpPython();
@@ -82,6 +84,7 @@ public:
   bool              HasDependency( const std::string& theObjKey, const std::string& theRefKey ) const;
 
 private:
+  void Update( bool theOnlyParameters );
   void AddParameter( SALOME_Parameter* theParam, bool theAddDependencies = true );
   void AddDependencies( SALOME_Parameter* theParam );
   void AddDependency( const std::string& theObjKey, const std::string& theRefKey );
@@ -134,6 +137,7 @@ private:
   std::list< KeyHelper > myToUpdate;
   std::list<SubstitutionInfo> mySubstitutions;
   SALOMEDS::Study_var myStudy;
+  SALOME::Parameter_var myTmpParam;
   Utils_Mutex myMutex;
   bool myUpdateOnlyParameters;
   int myMaxId;