X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSupervision%2FSuperV_Impl.cxx;h=6806ada002e139db22e2a2b8399f7391a24b1060;hb=b27a45845d224c2c005c02bcccb780df2cb7ea0f;hp=2c42ac0b19bea6fffbe89cc3ac1b94c4b7a233f2;hpb=1cbaac50370d660382c7c00c94a1ec13741a4e3a;p=modules%2Fsuperv.git diff --git a/src/Supervision/SuperV_Impl.cxx b/src/Supervision/SuperV_Impl.cxx index 2c42ac0..6806ada 100644 --- a/src/Supervision/SuperV_Impl.cxx +++ b/src/Supervision/SuperV_Impl.cxx @@ -82,13 +82,167 @@ SuperV_Impl::~SuperV_Impl() { void SuperV_Impl::Destroy() { beginService( "SuperV_Impl::Destroy" ); _poa->deactivate_object(*_id) ; - CORBA::release(_poa) ; +// CORBA::release(_poa) ; delete(_id) ; - _thisObj->_remove_ref(); +// _thisObj->_remove_ref(); Py_Finalize(); 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 TMPFile; + Engines::TMPFile_var aStreamPythonvar ; + SALOMEDS::SObject_var aStudyObject ; + SALOMEDS::SObject_var aStudyObjectValue ; + SUPERV::StreamGraph_var aStreamGraph ; + char * aGraph ; + string aStringGraph ; + string aStringRebuildData ; + aStringGraph = + "### This file is generated by SALOME automatically by dump python funcitonality\n" + "### of Supervisor component\n\n"; + 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, @@ -100,7 +254,7 @@ SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent, SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; TCollection_AsciiString myStudyName(""); - if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL())); + if (isMultiFile) myStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str(); SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent); TColStd_SequenceOfAsciiString aFileNames; @@ -120,7 +274,7 @@ SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent, CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ; SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj); if (aTmpDir.Length() == 0) - aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir(); + aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); graph->Export((aTmpDir + aName).ToCString()); } } @@ -167,7 +321,7 @@ CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent, // MESSAGE("SuperV_Impl::Load : IOR = " << IORSComponent << " , Url = " << aUrlOfFile); // Get a temporary directory for a file if (theStream.length() != 0) { - TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir(); + TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str(); myStrURL = strdup(aTmpDir.ToCString()); SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile); } @@ -237,11 +391,11 @@ char* SuperV_Impl::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject, if (strcmp(aFatherID, aComponentID)) return CORBA::string_dup(aLocalPersistentID); string myStudyName(""); - if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL())); + if (isMultiFile) myStudyName = SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()); string aStr(myStrURL); aStr += myStudyName + string(aLocalPersistentID); - SUPERV::Graph_ptr graph = Graph(aStr.c_str()); + SUPERV::StreamGraph_ptr graph = StreamGraph(aStr.c_str()); if (graph->_is_nil()) THROW_SALOME_CORBA_EXCEPTION("Unable to find graph in the file",SALOME::BAD_PARAM); @@ -478,7 +632,7 @@ SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA: } // Get a temporary directory to store a temporary file - CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir(); + CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str(); // Create a list to store names of created files SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames; aSeq->length(1); @@ -489,8 +643,8 @@ SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA: aGraph->Export(strdup(aFullName)); delete(aFullName); - aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false); - SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true); + aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.in(), aSeq.in(), false); + SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.in(), aSeq.in(), true); // Assign an ID = 1 the the type SUPERV::Graph theObjectID = 1; @@ -528,7 +682,7 @@ SALOMEDS::SObject_ptr SuperV_Impl::PasteInto(const SALOMEDS::TMPFile& theStream, return aResultSO._retn(); } - TCollection_AsciiString aTmpDir = SALOMEDS_Tool::GetTmpDir(); + TCollection_AsciiString aTmpDir = (char*)SALOMEDS_Tool::GetTmpDir().c_str(); SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), false); TCollection_AsciiString aFullName; aFullName = aTmpDir+aSeq[0]; @@ -609,12 +763,21 @@ SUPERV::Value_ptr SuperV_Impl::Value( CORBA::Any * anAny ) { return SUPERV::Value::_duplicate( iobject ) ; } +CORBA::Object_ptr SuperV_Impl::ToObject( CORBA::Object_ptr anObjectRef ) { + beginService( "SuperV_Impl::ToObject" ); + CORBA::Object_ptr anObject ; + anObject = CORBA::Object::_duplicate( anObjectRef ) ; + endService( "SuperV_Impl::ToObject" ); + return anObject ; +} + SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) { beginService( "SuperV_Impl::Graph" ); bool created = true ; + SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ; Graph_Impl * myGraph ; - myGraph = new Graph_Impl( _Orb , _Poa, _ContId, - instanceName() , interfaceName() , aGraphName ) ; + myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() , + aGraphName , SUPERV::DataFlowGraph ) ; int lenname = strlen( aGraphName ) ; if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) { created = myGraph->Import( aGraphName ) ; @@ -622,8 +785,16 @@ SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) { else { myGraph->Import( (char * ) NULL ) ; } - SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ; - if ( created ) { + if ( !created && myGraph->IsStreamGraph() ) { + MESSAGE( "SuperV_Impl::Graph " << aGraphName << " IsStreamGraph !" ) ; + myGraph->destroy() ; + SUPERV::StreamGraph_var streamiobject = StreamGraph( aGraphName ) ; + iobject = SUPERV::Graph::_narrow( streamiobject ) ; + if ( CORBA::is_nil( iobject ) ) { + created = false ; + } + } + else if ( created ) { PortableServer::ObjectId * id = myGraph->getId() ; CORBA::Object_var obj = _poa->id_to_reference(*id); iobject = SUPERV::Graph::_narrow(obj) ; @@ -636,9 +807,10 @@ SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) { SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) { beginService( "SuperV_Impl::GraphE" ); bool created = true ; + SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ; Graph_Impl * myGraph ; - myGraph = new Graph_Impl( _Orb , _Poa, _ContId, - instanceName() , interfaceName() , aGraphName ) ; + myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() , + aGraphName , SUPERV::DataFlowGraph ) ; int lenname = strlen( aGraphName ) ; if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) { created = myGraph->Import( aGraphName ) ; @@ -646,8 +818,15 @@ SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) { else { myGraph->Import( (char * ) NULL ) ; } - SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ; - if ( created ) { + if ( !created && myGraph->IsStreamGraph() ) { + myGraph->destroy() ; + SUPERV::StreamGraph_var streamiobject = StreamGraphE( aGraphName ) ; + iobject = SUPERV::Graph::_narrow( streamiobject ) ; + if ( CORBA::is_nil( iobject ) ) { + created = false ; + } + } + else if ( created ) { PortableServer::ObjectId * id = myGraph->getId() ; CORBA::Object_var obj = _poa->id_to_reference(*id); iobject = SUPERV::Graph::_narrow(obj) ; @@ -658,6 +837,55 @@ SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) { return SUPERV::Graph::_duplicate(iobject) ; } +SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraph(const char * aGraphName ) { + beginService( "SuperV_Impl::StreamGraph" ); + bool created = true ; + StreamGraph_Impl * myStreamGraph ; + myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() , + interfaceName() , aGraphName ) ; + int lenname = strlen( aGraphName ) ; + if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) { + created = myStreamGraph->Import( aGraphName ) ; + } + else { + myStreamGraph->Import( (char * ) NULL ) ; + } + SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ; + if ( created ) { + PortableServer::ObjectId * id = myStreamGraph->getId() ; + CORBA::Object_var obj = _poa->id_to_reference(*id); + iobject = SUPERV::StreamGraph::_narrow(obj) ; + myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ; + } + endService( "SuperV_Impl::StreamGraph" ); + return SUPERV::StreamGraph::_duplicate(iobject) ; +} + +SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraphE(const char * aGraphName ) { + beginService( "SuperV_Impl::StreamGraphE" ); + bool created = true ; + StreamGraph_Impl * myStreamGraph ; + myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() , + interfaceName() , aGraphName ) ; + int lenname = strlen( aGraphName ) ; + if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) { + created = myStreamGraph->Import( aGraphName ) ; + } + else { + myStreamGraph->Import( (char * ) NULL ) ; + } + SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ; + if ( created ) { + PortableServer::ObjectId * id = myStreamGraph->getId() ; + CORBA::Object_var obj = _poa->id_to_reference(*id); + iobject = SUPERV::StreamGraph::_narrow(obj) ; + myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ; + } + myStreamGraph->ReadOnly() ; + endService( "SuperV_Impl::StreamGraphE" ); + return SUPERV::StreamGraph::_duplicate(iobject) ; +} + SUPERV::Graph_ptr SuperV_Impl::getGraph(const char* ior) { SUPERV::Graph_var iobject = SUPERV::Graph::_nil(); try { @@ -670,6 +898,18 @@ SUPERV::Graph_ptr SuperV_Impl::getGraph(const char* ior) { return(SUPERV::Graph::_duplicate(iobject)); } +SUPERV::StreamGraph_ptr SuperV_Impl::getStreamGraph(const char* ior) { + SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil(); + try { + CORBA::Object_ptr obj = _Orb->string_to_object(ior); + iobject = SUPERV::StreamGraph::_narrow(obj); + } catch ( ... ) { + return SUPERV::StreamGraph::_nil(); + // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL; + }; + return(SUPERV::StreamGraph::_duplicate(iobject)); +} + PortableServer::ObjectId * SUPERVEngine_factory ( CORBA::ORB_ptr orb , PortableServer::POA_ptr poa ,