Salome HOME
1. New method GetParametersDependingOn()
authorasl <asl@opencascade.com>
Tue, 8 Dec 2009 11:10:44 +0000 (11:10 +0000)
committerasl <asl@opencascade.com>
Tue, 8 Dec 2009 11:10:44 +0000 (11:10 +0000)
2. Loading of old studies containing notebook data

src/Notebook/SALOME_Notebook.cxx
src/Notebook/SALOME_Notebook.hxx

index dccd3e9aa73653e0dfcaa5bd9142ed72940a7992..fb4e59aae6f81a43fd5ef1d85cc8237f5f1eec4e 100644 (file)
@@ -66,11 +66,11 @@ std::vector<std::string> split( const std::string& theData, const std::string& t
 {
   std::vector<std::string> aParts;
   int aPrev = 0, anInd = 0;
-  while( true )
+  while( anInd<theData.length() )
   {
     anInd = theData.find( theSeparator, aPrev );
     if( anInd < 0 )
-      break;
+      anInd = theData.length();
 
     std::string aPart = theData.substr( aPrev, anInd - aPrev );
     if( aPart.length() > 0 || theIsKeepEmpty )
@@ -1117,3 +1117,90 @@ SALOME::Parameter_ptr SALOME_Notebook::Calculate( const char* theExpr )
   myTmpParam->Update( _this() );
   return myTmpParam.in();
 }
+
+void SALOME_Notebook::ParseOldStyleParam( const std::string& theName, const std::string& theType, const std::string& theValue )
+{
+  int aType;
+  if( sscanf( theType.c_str(), "%i", &aType ) != 1 )
+    return;
+
+  switch( aType )
+  {
+  case 0:
+    {
+      double aValue;
+      if( sscanf( theValue.c_str(), "%lf", &aValue ) != 1 )
+        return;
+
+      AddReal( theName.c_str(), aValue );
+      break;
+    }
+  case 1:
+    {
+      int aValue;
+      if( sscanf( theValue.c_str(), "%i", &aValue ) != 1 )
+        return;
+
+      AddInteger( theName.c_str(), aValue );
+      break;
+    }
+  case 2:
+    {
+      int aValue;
+      if( sscanf( theValue.c_str(), "%i", &aValue ) != 1 )
+        return;
+
+      AddBoolean( theName.c_str(), aValue );
+      break;
+    }
+  case 3:
+    {
+      std::string aValue = theValue;
+      for( int i = 0, n = aValue.length(); i < n; i++ )
+        if( aValue[i]=='"' )
+          aValue[i] = ' ';
+
+      AddNamedExpression( theName.c_str(), aValue.c_str() );
+      break;
+    }
+  }
+}
+
+void SALOME_Notebook::ParseOldStyleObject( const std::string& theComponent, const std::string& theEntry, const std::string& theData )
+{
+  //printf( "ParseOldStyleObject: %s\n", theData.c_str() );
+  std::string anObjKey = GetKey( theComponent, theEntry );
+  std::vector<std::string> aParts = split( theData, "|", false ), anItems;
+  for( int i=0, n=aParts.size(); i<n; i++ )
+  {
+    //printf( "part: %s\n", aParts[i].c_str() );
+    anItems = split( aParts[i], ":", false );
+    //printf( "size = %i\n", anItems.size() );
+    for( int j=0, m=anItems.size(); j<m; j++ )
+    {
+      std::string aRefKey = GetKey( anItems[j] );
+      //printf( "key = %s\n", aRefKey.c_str() );
+      if( !HasDependency( anObjKey, aRefKey ) )
+        AddDependency( anObjKey, aRefKey );
+    }
+  }
+  myEntriesToRebuild.push_back( theEntry );
+}
+
+void SALOME_Notebook::RebuildLinks()
+{
+  printf( "Rebuild links\n" );
+}
+
+SALOME::StringArray* SALOME_Notebook::GetParametersDependingOn( const char* theParamName )
+{
+  std::list<std::string> aParamsDeps;
+  std::list<std::string> aDeps = GetAllDependingOn( GetKey( theParamName ) );
+  std::list<std::string>::const_iterator it = aDeps.begin(), last = aDeps.end();
+  std::string aName;
+  for( ; it!=last; it++ )
+    if( GetComponent( *it, aName ) == PARAM_COMPONENT )
+      aParamsDeps.push_back( aName );
+
+  return GenerateList( aParamsDeps );
+}
index b26df17508cccc2c0d4f0aa4d1238cf35a361019..203117b62f5ec66250e0e2107c9510bb2c56c23e 100644 (file)
@@ -72,16 +72,20 @@ public:
 
   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();
-  virtual char*          Dump();
-  virtual char*          GetParameters( const char* theComponent, const char* theEntry );
+  virtual CORBA::Boolean       Save( const char* theFileName );
+  virtual CORBA::Boolean       Load( const char* theFileName );
+  virtual char*                DumpPython();
+  virtual char*                Dump();
+  virtual char*                GetParameters( const char* theComponent, const char* theEntry );
+  virtual SALOME::StringArray* GetParametersDependingOn( const char* theParamName );
 
   SALOME_Parameter* GetParameterPtr( const char* theParamName ) const;
   void              UpdateAnonymous( const std::string& theOldName, const std::string& theNewName );
   int               GetNewId();
   bool              HasDependency( const std::string& theObjKey, const std::string& theRefKey ) const;
+  void              ParseOldStyleParam( const std::string& theName, const std::string& theType, const std::string& theValue );
+  void              ParseOldStyleObject( const std::string& theComponent, const std::string& theEntry, const std::string& theData );
+  void              RebuildLinks();
 
 private:
   void Update( bool theOnlyParameters );
@@ -94,7 +98,7 @@ private:
   std::string GetComponent( const std::string& theKey, std::string& theEntry ) const;
   void ParseDependencies( FILE* theFile, const std::string& theFirstLine );
   std::string GetKey( SALOME::ParameterizedObject_ptr theObj ) const;
-  std::string GetKey( const std::string& theComponent, const std::string& theParamName ) const;
+  std::string GetKey( const std::string& theComponent, const std::string& theEntry ) const;
   std::string GetKey( const std::string& theParamName ) const;
   std::list<std::string> GetAllDependingOn( const std::string& theKey ) const;
   SALOME::ParameterizedObject_ptr FindObject( const std::string& theKey ) const;
@@ -136,6 +140,7 @@ private:
   std::map< std::string, SALOME_Parameter* > myParameters;
   std::list< KeyHelper > myToUpdate;
   std::list<SubstitutionInfo> mySubstitutions;
+  std::list< std::string > myEntriesToRebuild;
   SALOMEDS::Study_var myStudy;
   SALOME::Parameter_var myTmpParam;
   Utils_Mutex myMutex;