]> SALOME platform Git repositories - modules/superv.git/commitdiff
Salome HOME
New method DumpStudy functionnality
authorrahuel <rahuel@opencascade.com>
Fri, 29 Apr 2005 13:05:48 +0000 (13:05 +0000)
committerrahuel <rahuel@opencascade.com>
Fri, 29 Apr 2005 13:05:48 +0000 (13:05 +0000)
src/Supervision/SuperV_Impl.cxx
src/Supervision/SuperV_Impl.hxx

index ad556e9a9658b67c17ab45939d2a1974877a7d3a..3ab58b563752354c93b873dc991b69e0fd6b44b4 100644 (file)
@@ -89,10 +89,162 @@ void SuperV_Impl::Destroy() {
   endService( "SuperV_Impl::Destroy" );
 }
 
+Engines::TMPFile * SuperV_Impl::DumpPython( CORBA::Object_ptr theStudy ,
+                                           CORBA::Boolean isPublished ,
+                                            CORBA::Boolean & isValidScript ) {
+  beginService( "Super_Impl::DumpPython" );
+  bool success = true ;
+  SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theStudy ) ;
+//  typedef sequence<octet> TMPFile;  
+  Engines::TMPFile_var aStreamPythonvar ;
+  SALOMEDS::SObject_var aStudyObject ;
+  SALOMEDS::SObject_var aStudyObjectValue ;
+  SUPERV::StreamGraph_var aStreamGraph ;
+  char * aGraph ;
+  string aStringGraph ;
+  string aStringRebuildData ;
+  aStringRebuildData = "def RebuildData( theStudy ) :\n" ;
+  if ( CORBA::is_nil( aStudy ) ) {
+    MESSAGE( "aStudy is_nil" ) ;
+    success = false ;
+  }
+  else {
+    SALOMEDS::SObject_var aStudyObject = aStudy->FindComponent( ComponentDataType() ) ;
+    if ( CORBA::is_nil( aStudyObject ) ) {
+      MESSAGE( "aStudyObject is_nil" ) ;
+      success = false ;
+    }
+    else {
+      SALOMEDS::ChildIterator_var aStudyChildIterator = aStudy->NewChildIterator( aStudyObject ) ;
+      bool importSuperV = true ;
+      for ( aStudyChildIterator->InitEx( true ) ;  aStudyChildIterator->More() ;
+            aStudyChildIterator->Next() ) {
+        aStudyObjectValue = aStudyChildIterator->Value() ;
+        int aDepth = aStudyObjectValue->Depth() ;
+        char * aStudyObjectValueIOR = aStudyObjectValue->GetIOR() ;
+        MESSAGE( "Super_Impl::DumpPython aStudyObjectValueIOR " << aStudyObjectValueIOR
+                 << " Depth " << aDepth ) ;
+        if ( strlen( aStudyObjectValueIOR ) ) {
+          CORBA::Object_var obj = CORBA::Object::_nil() ;
+          try {
+            obj = _Orb->string_to_object( aStudyObjectValueIOR ) ;
+            if ( !CORBA::is_nil( obj ) ) {
+              aStreamGraph = SUPERV::StreamGraph::_narrow( obj ) ;
+              if ( !CORBA::is_nil( aStreamGraph ) ) {
+                MESSAGE( "aStreamGraph " << aStreamGraph->Name() ) ;
+                aStreamGraph->IsValid() ;
+                aGraph = aStreamGraph->SavePY( importSuperV ) ;
+                importSuperV = false ;
+                aStringGraph += string( aGraph ) ;
+                aStringRebuildData += "    " ;
+                aStringRebuildData += aStreamGraph->Name() ;
+                aStringRebuildData += " = Def" ;
+                aStringRebuildData += aStreamGraph->Name() ;
+                aStringRebuildData += "()\n" ;
+                aStringRebuildData += "    aBuilder,aStudyObject" ;
+                ostringstream astr ;
+                astr << aDepth ;
+                aStringRebuildData += astr.str() ;
+                aStringRebuildData += " = addDataflowToStudy( theStudy , " ;
+                aStringRebuildData += aStreamGraph->Name() ;
+                aStringRebuildData += " )\n" ;
+                isValidScript = true ;
+             }
+             else {
+                MESSAGE( "Super_Impl::DumpPython aStreamGraph is_nil ERROR" ) ;
+                success = false ;
+                break ;
+             }
+           }
+         }
+          catch ( ... ) {
+            char * aStudyObjectName = aStudyObjectValue->GetName() ;
+            ostringstream newastr ;
+            ostringstream astr ;
+            if ( strlen( aStudyObjectName ) ) {
+              MESSAGE( "Super_Impl::DumpPython aStudyObjectName " << aStudyObjectName ) ;
+              aStringRebuildData += "    aStudyObject" ;
+              astr << aDepth ;
+              aStringRebuildData += astr.str() ;
+              aStringRebuildData += " = aBuilder.NewObject( aStudyObject" ;
+              newastr << (aDepth - 1 ) ;
+              aStringRebuildData += newastr.str() ;
+              aStringRebuildData += " )\n" ;
+              aStringRebuildData += "    anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
+              aStringRebuildData += astr.str() ;
+              aStringRebuildData += " , 'AttributeName' )\n" ;
+              aStringRebuildData += "    aName = anAttr._narrow( SALOMEDS.AttributeName )\n" ;
+              aStringRebuildData += "    aName.SetValue( '" ;
+              aStringRebuildData += aStudyObjectName ;
+              aStringRebuildData += "' )\n" ;
+           }
+           else {
+              MESSAGE( "Super_Impl::DumpPython strlen( aStudyObjectName ) == 0 ERROR" ) ;
+              success = false ;
+              break ;
+           }
+            MESSAGE( "Super_Impl::DumpPython aStudyObjectValueIOR " << aStudyObjectValueIOR ) ;
+//String in fact
+            aStringRebuildData += "    anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
+            aStringRebuildData += astr.str() ;
+            aStringRebuildData += " , 'AttributeIOR')\n";
+            aStringRebuildData += "    anIORAttr = anAttr._narrow( SALOMEDS.AttributeIOR )\n";
+            aStringRebuildData += "    anIORAttr.SetValue( '" ;
+            aStringRebuildData += aStudyObjectValueIOR ;
+            aStringRebuildData += "' )\n" ;
+         }
+       }
+       else {
+          char * aStudyObjectName = aStudyObjectValue->GetName() ;
+          if ( strlen( aStudyObjectName ) ) {
+            MESSAGE( "Super_Impl::DumpPython aStudyObjectName " << aStudyObjectName << " Depth "
+                     << aDepth ) ;
+            aStringRebuildData += "    aStudyObject" ;
+            ostringstream astr ;
+            astr << aDepth ;
+            aStringRebuildData += astr.str() ;
+            aStringRebuildData += " = aBuilder.NewObject( aStudyObject" ;
+            ostringstream newastr ;
+            newastr << (aDepth - 1 ) ;
+            aStringRebuildData += newastr.str() ;
+            aStringRebuildData += " )\n" ;
+            aStringRebuildData += "    anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
+            aStringRebuildData += astr.str() ;
+            aStringRebuildData += " , 'AttributeName' )\n" ;
+            aStringRebuildData += "    aName = anAttr._narrow( SALOMEDS.AttributeName )\n" ;
+            aStringRebuildData += "    aName.SetValue( '" ;
+            aStringRebuildData += aStudyObjectName ;
+            aStringRebuildData += "' )\n" ;
+         }
+         else {
+            MESSAGE( "Super_Impl::DumpPython strlen( aStudyObjectName ) == 0 ERROR" ) ;
+            success = false ;
+            break ;
+         }
+       }
+      }
+    }
+  }
+  if ( !success ) {
+    isValidScript = false ;
+    endService( "Super_Impl::DumpPython ERROR" );
+    return new Engines::TMPFile( 0 ) ;
+  }
+  aStringRebuildData += "    sg.updateObjBrowser( 1 )\n" ;
+  aStringRebuildData += "    return 1\n" ;
+  aStringGraph += aStringRebuildData ;
+  int aLen = strlen( aStringGraph.c_str() ) ;
+  CORBA::Octet * anOctetBuffer = (CORBA::Octet * ) aStringGraph.c_str() ;
+  aStreamPythonvar = new Engines::TMPFile ( aLen+1 , aLen+1 , anOctetBuffer ,1 ) ;
+  endService( "Super_Impl::DumpPython" );
+  return aStreamPythonvar._retn() ;
+}
+
 //  void SuperV_Impl::Save(const char *IORSComponent, const char *aUrlOfFile) {
 SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
                                     const char* theURL,
                                     bool isMultiFile) {
+  beginService( "Super_Impl::Save" );
   SALOMEDS::TMPFile_var aStreamFile;
   // Get a temporary directory to store a file
   TCollection_AsciiString aTmpDir("");
@@ -149,6 +301,7 @@ SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
   // Remove the created file and tmp directory
   SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aPySeq.in(), true);
   // Return the created byte stream
+  endService( "Super_Impl::Save" );
   return aStreamFile._retn();
 }
 
@@ -164,6 +317,7 @@ CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
                                 const SALOMEDS::TMPFile& theStream,
                                 const char* theURL,
                                 bool isMultiFile) {
+  beginService( "Super_Impl::Load" );
   //    MESSAGE("SuperV_Impl::Load : IOR = " << IORSComponent << " , Url = " << aUrlOfFile);
   // Get a temporary directory for a file
   if (theStream.length() != 0) {
@@ -171,6 +325,7 @@ CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
     myStrURL = strdup(aTmpDir.ToCString());
     SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile);
   }
+  endService( "Super_Impl::Load" );
   return true;
 }
 
@@ -364,6 +519,7 @@ SALOMEDS::SObject_ptr SuperV_Impl::PublishInStudy(SALOMEDS::Study_ptr theStudy,
                                                  SALOMEDS::SObject_ptr theSObject,
                                                  CORBA::Object_ptr theObject,
                                                  const char* theName) throw (SALOME::SALOME_Exception) {
+  beginService( "Super_Impl::PublishInStudy" );
   SALOMEDS::SObject_var aResultSO;
 
   if(CORBA::is_nil(theObject)) return aResultSO._retn();;
@@ -428,6 +584,7 @@ SALOMEDS::SObject_ptr SuperV_Impl::PublishInStudy(SALOMEDS::Study_ptr theStudy,
   anIOR  = SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
   anIOR->SetValue(aGraph->getIOR());
 //    aBuilder->Addreference(theSObject, aResultSO);
+  endService( "Super_Impl::PublishInStudy" );
   return aResultSO._retn();
 }
 
index 6cfb02fa2851917fcda9cf45b3260955f67a5f9a..7be243ce3b8bd544b488f368cbb85ccf4fcca98b 100644 (file)
@@ -65,6 +65,10 @@ class SuperV_Impl : public POA_SUPERV::SuperG ,
     virtual ~SuperV_Impl() ;
     virtual void Destroy() ;
 
+    Engines::TMPFile * DumpPython( CORBA::Object_ptr theStudy ,
+                                  CORBA::Boolean isPublished ,
+                                   CORBA::Boolean & isValidScript ) ;
+
 //      void Save(const char* IORSComponent, const char* aUrlOfFile);
 //      void Load(const char* IORSComponent, const char* aUrlOfFile);
     SALOMEDS::TMPFile* Save(SALOMEDS::SComponent_ptr theComponent,