+++ /dev/null
-// SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
-//
-// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-//
-//
-//
-// File : SuperV_Impl.cxx
-// Author : Jean Rahuel
-// Module : SUPERV
-// $Header$
-
-using namespace std;
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-
-#include <fstream>
-//#include <sstream>
-#include <string>
-
-#include "Python.h"
-
-//#include "utilities.h"
-
-#include "SALOME_Container_i.hxx"
-
-#include "SuperV_Impl.hxx"
-
-#include "SALOMEDS_Attributes.hh"
-#include <TCollection_AsciiString.hxx>
-#include <TColStd_SequenceOfAsciiString.hxx>
-#include "SALOMEDS_Tool.hxx"
-
-#include "Utils_CorbaException.hxx"
-
-#define STUDY_SUPERVISION "SUPERV"
-
-SuperV_Impl::SuperV_Impl( CORBA::ORB_ptr orb ,
- PortableServer::POA_ptr poa ,
- PortableServer::ObjectId * contId ,
- const char *instanceName ,
- const char *interfaceName
-// , int argc ,
-// char ** argv
- ) :
- Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
- MESSAGE("SuperV_Impl::SuperV_Impl activate object instanceName("
- << instanceName << ") interfaceName(" << interfaceName << ") --> "
- << hex << (void *) this << dec )
- _thisObj = this ;
- _id = _poa->activate_object(_thisObj);
- _Orb = CORBA::ORB::_duplicate(orb);
- _Poa = poa ;
- _ContId = contId ;
-}
-
-SuperV_Impl::SuperV_Impl() {
-}
-
-SuperV_Impl::~SuperV_Impl() {
- beginService( "SuperV_Impl::~SuperV_Impl" );
- endService( "SuperV_Impl::~SuperV_Impl" );
-}
-
-void SuperV_Impl::Destroy() {
- beginService( "SuperV_Impl::Destroy" );
- _poa->deactivate_object(*_id) ;
- CORBA::release(_poa) ;
- delete(_id) ;
- _thisObj->_remove_ref();
- Py_Finalize();
- endService( "SuperV_Impl::Destroy" );
-}
-
-// void SuperV_Impl::Save(const char *IORSComponent, const char *aUrlOfFile) {
-SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
- const char* theURL,
- bool isMultiFile) {
- SALOMEDS::TMPFile_var aStreamFile;
- // Get a temporary directory to store a file
- TCollection_AsciiString aTmpDir("");
- // Create a list to store names of created files
- SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
-
- TCollection_AsciiString myStudyName("");
- if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
-
- SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
- TColStd_SequenceOfAsciiString aFileNames;
- TCollection_AsciiString aName;
-
- for(; anIter->More(); anIter->Next()) {
- SALOMEDS::SObject_var aSO = anIter->Value();
- SALOMEDS::GenericAttribute_var anAttr;
- if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
- aName = myStudyName +
- TCollection_AsciiString("_SUPERVISION_") +
- TCollection_AsciiString(aSO->Tag()) +
- TCollection_AsciiString(".xml");
- aFileNames.Append(aName);
-
- // save to the file
- 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();
- graph->Export((aTmpDir + aName).ToCString());
- }
- }
-
- if (aFileNames.Length() == 0) return new SALOMEDS::TMPFile(0);
-
- aSeq->length(aFileNames.Length());
- int aCounter;
- for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
- aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
-
- // Conver a file to the byte stream
- aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
- // Remove the created file and tmp directory
- if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
-
- // Add python files to the temporary files sequence
- SALOMEDS::ListOfFileNames_var aPySeq = new SALOMEDS::ListOfFileNames;
- aPySeq->length(aSeq->length());
- for(aCounter = aSeq->length(); aCounter > 0; aCounter--) {
- char* aCName = CORBA::string_dup(aSeq[aCounter-1]);
- int a = strlen(aCName);
- aCName[a-3] = 'p';aCName[a-2] = 'y';aCName[a-1] = 0;
- aPySeq[aCounter-1] = aCName;
- }
- // Remove the created file and tmp directory
- SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aPySeq.in(), true);
- // Return the created byte stream
- return aStreamFile._retn();
-}
-
-SALOMEDS::TMPFile* SuperV_Impl::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
- const char* theURL,
- bool isMultiFile) {
- SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
- return aStreamFile._retn();
-}
-
-// void SuperV_Impl::Load(const char* IORSComponent, const char* aUrlOfFile) {
-CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
- const SALOMEDS::TMPFile& theStream,
- const char* theURL,
- bool isMultiFile) {
- // 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();
- myStrURL = strdup(aTmpDir.ToCString());
- SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile);
- }
- return true;
-}
-
-CORBA::Boolean SuperV_Impl::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
- const SALOMEDS::TMPFile& theStream,
- const char* theURL,
- bool isMultiFile) {
- return Load(theComponent, theStream, theURL, isMultiFile);
-}
-
-void SuperV_Impl::Close(SALOMEDS::SComponent_ptr theComponent) {
-// mpv 06.03.2003: bug SAL1508 - graphs will be destructed at the GUI-level at the supervision frame closing
-
-// SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
-// for(; anIter->More(); anIter->Next()) {
-// SALOMEDS::SObject_var aSO = anIter->Value();
-// SALOMEDS::GenericAttribute_var anAttr;
-// if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
-// CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
-// SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
-// graph->destroy();
-// }
-// }
-}
-
-char* SuperV_Impl::ComponentDataType() {
- return(strdup("SUPERV"));
-}
-
-char* SuperV_Impl::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
- const char* IORString,
- CORBA::Boolean isMultiFile,
- CORBA::Boolean isASCII) {
- MESSAGE("SuperV_Impl::IORToLocalPersistentID: IOR:"<<IORString);
-
- try {
- CORBA::Object_var anObj = _orb->string_to_object(IORString) ;
- if (CORBA::is_nil(anObj)) return CORBA::string_dup(IORString);
- SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
- if (aGraph->_is_nil()) return CORBA::string_dup(IORString);
- } catch (...) {
- return CORBA::string_dup(IORString);
- }
-
-// sprintf(aName, "%s_SUPERVISION_tmp_%d.xml",myStudyName,myCounter);
-// CORBA::String_var myStudyName("");
-// if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
- TCollection_AsciiString aName = //TCollection_AsciiString(myStudyName) +
- TCollection_AsciiString("_SUPERVISION_") +
- TCollection_AsciiString(theSObject->Tag()) +
- TCollection_AsciiString(".xml");
- return CORBA::string_dup(aName.ToCString());
-}
-
-char* SuperV_Impl::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
- const char* aLocalPersistentID,
- CORBA::Boolean isMultiFile,
- CORBA::Boolean isASCII)
- throw(SALOME::SALOME_Exception)
-{
- MESSAGE("SuperV_Impl::LocalPersistentIDToIOR : IOR = " << aLocalPersistentID);
- CORBA::String_var aFatherID = theSObject->GetFather()->GetID();
- CORBA::String_var aComponentID = theSObject->GetFatherComponent()->GetID();
- if (strcmp(aFatherID, aComponentID)) return CORBA::string_dup(aLocalPersistentID);
-
- string myStudyName("");
- if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
-
- string aStr(myStrURL);
- aStr += myStudyName + string(aLocalPersistentID);
- 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);
-
- // mpv: remove IORs input ports on loading
- MESSAGE("Remove IORs input ports on loading");
- SUPERV::ListOfNodes_var aNodes = graph->Nodes();
- SUPERV::CNode_var aNode;
- const char* aStrIOR = "";
- CORBA::Any * anAny = new CORBA::Any();
- *anAny <<= aStrIOR ;
- int i, j;
- for(i = aNodes->CNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->CNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->FNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->FNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- //CORBA::Any * anAny = new CORBA::Any(CORBA::TypeCode::PR_null_tc(), (void*)NULL, 0) ;
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->INodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->INodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->GNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->GNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->LNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->LNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->ELNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->ELNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->SNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->SNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
- for(i = aNodes->ESNodes.length() - 1; i >= 0; i--) {
- aNode = aNodes->ESNodes[i];
- SUPERV::ListOfPorts_var aPorts = aNode->Ports();
- for(j = aPorts->length() - 1; j >= 0; j--) {
- SUPERV::Port_var aPort = aPorts[j];
- if (aPort->IsIOR()) {
- aPort->Input(AnyValue(*anAny));
- }
- }
- }
-
-
- SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
- aSeq->length(1);
- aSeq[0]=aLocalPersistentID;
- if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(myStrURL, aSeq.in(), true);
-
- return _Orb->object_to_string(graph);
-}
-
-bool SuperV_Impl::CanPublishInStudy(CORBA::Object_ptr theIOR) {
- SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theIOR);
- return !(aGraph->_is_nil());
-}
-
-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) {
- SALOMEDS::SObject_var aResultSO;
-
- if(CORBA::is_nil(theObject)) return aResultSO._retn();;
-
- if(theStudy->_is_nil()) return aResultSO._retn();;
-
- SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
- SALOMEDS::GenericAttribute_var anAttr;
- SALOMEDS::AttributeName_var aName;
- SALOMEDS::AttributeIOR_var anIOR;
- SALOMEDS::AttributePixMap_var aPixmap;
- SALOMEDS::SComponent_var aFather = theStudy->FindComponent(STUDY_SUPERVISION);
-
- if (aFather->_is_nil()) {
- aFather = aBuilder->NewComponent(STUDY_SUPERVISION);
- anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
- aName = SALOMEDS::AttributeName::_narrow(anAttr);
- //NRI aName->SetValue(STUDY_SUPERVISION);
-
- SALOME_NamingService *NamingService = new SALOME_NamingService(_Orb);
- CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
- SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
- SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( STUDY_SUPERVISION );
- if ( !Comp->_is_nil() ) {
- aName->SetValue( Comp->componentusername() );
- }
- anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
- aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
- aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
-
- aBuilder->DefineComponentInstance(aFather, SuperG::_this());
- }
-
- SALOMEDS::SObject_var dataflowI;
- SALOMEDS::ChildIterator_var dataflowS = theStudy->NewChildIterator(aFather);
-
- SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theObject);
-
- const char* name = aGraph->Name();
-
- if (CORBA::is_nil(theSObject)) { // if SObject is null, then searching for exist graph SObject
- for (; dataflowS->More(); dataflowS->Next()) {
- dataflowI = dataflowS->Value();
- if (dataflowI->FindAttribute(anAttr, "AttributeName")) {
- aName = SALOMEDS::AttributeName::_narrow(anAttr);
- if (strcmp(aName->Value(), name) == 0) {
- aResultSO = dataflowI;
- break;
- }
- }
- }
- } else { // else searching for referenced SObject
- if (!theSObject->ReferencedObject(aResultSO))
- THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
- }
-
- if (strlen(theName) != 0) name = theName;
- if (CORBA::is_nil(aResultSO)) aResultSO = aBuilder->NewObject(aFather);
-
- aName = SALOMEDS::AttributeName::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"));
- aName->SetValue(name);
- anIOR = SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
- anIOR->SetValue(aGraph->getIOR());
-// aBuilder->Addreference(theSObject, aResultSO);
- return aResultSO._retn();
-}
-
-CORBA::Boolean SuperV_Impl::CanCopy(SALOMEDS::SObject_ptr theObject) {
- // Try to retrieve known by SUPERVISION component Graph by given IOR
- SALOMEDS::GenericAttribute_var anAttr;
- if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
- try {
- CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
- if (CORBA::is_nil(anObj)) return false;
- else {
- SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
- if (aGraph->_is_nil()) return false;
- }
- } catch (...) {
- return false;
- }
- return true;
-}
-
-SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
- // Declare a sequence of the byte to store the copied object
- SALOMEDS::TMPFile_var aStreamFile;
-
- // Try to get GEOM_Shape object by given SObject
- SALOMEDS::GenericAttribute_var anAttr;
- if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
- CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
-
- bool isGraph = true;
- SUPERV::Graph_var aGraph;
- try {
- CORBA::Object_var anObj = _orb->string_to_object(anIOR) ;
- if (CORBA::is_nil(anObj)) isGraph = false;
- else {
- aGraph = SUPERV::Graph::_narrow(anObj);
- if (aGraph->_is_nil()) isGraph = false;
- }
- } catch (...) {
- isGraph = false;
- }
-
- if (!isGraph) { // it's just a value, stored in the IOR attribute
- int aLen = strlen(anIOR);
- CORBA::Octet* anOctetBuf = (CORBA::Octet*)strdup(anIOR);
- aStreamFile = SALOMEDS::TMPFile_var(new SALOMEDS::TMPFile(aLen, aLen, anOctetBuf, 1));
- return aStreamFile._retn();
- }
-
- // Get a temporary directory to store a temporary file
- CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
- // Create a list to store names of created files
- SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
- aSeq->length(1);
- aSeq[0] = strdup("_SUPERVISION_tmp.xml");
- char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
- strcpy(aFullName, aTmpDir);
- strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
- aGraph->Export(strdup(aFullName));
- delete(aFullName);
-
- aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
- SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
-
- // Assign an ID = 1 the the type SUPERV::Graph
- theObjectID = 1;
-
- return aStreamFile._retn();
-}
-
-CORBA::Boolean SuperV_Impl::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
- // The Supervision component can paste only objects copied by Supervision component
- // and with the object type = 1
- if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
- return true;
-}
-
-SALOMEDS::SObject_ptr SuperV_Impl::PasteInto(const SALOMEDS::TMPFile& theStream,
- CORBA::Long theObjectID,
- SALOMEDS::SObject_ptr theObject) {
- SALOMEDS::SObject_var aResultSO;
- if(CORBA::is_nil(theObject)) return aResultSO._retn();
- SALOMEDS::StudyBuilder_var aBuilder = theObject->GetStudy()->NewBuilder();
-
- aResultSO = SALOMEDS::SObject::_narrow(CORBA::Object::_duplicate(theObject));
-
- bool isGraph = (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0);
-
-
- if (!isGraph) {
- SALOMEDS::AttributeIOR_var anIOR =
- SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(theObject, "AttributeIOR"));
- int aLen = theStream.length();
- char* aVal = new char[aLen+1];
- aVal[aLen] = (char)0;
- memcpy((void*)aVal, (void*)theStream.NP_data(), aLen);
- anIOR->SetValue(aVal);
- return aResultSO._retn();
- }
-
- TCollection_AsciiString aTmpDir = SALOMEDS_Tool::GetTmpDir();
- SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), false);
- TCollection_AsciiString aFullName;
- aFullName = aTmpDir+aSeq[0];
- SUPERV::Graph_var aGraph = Graph(aFullName.ToCString());
-
- SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
-
- if (isGraph) {
- aResultSO = aBuilder->NewObject(theObject);
- }
-
- SALOMEDS::AttributeIOR_var anIOR =
- SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
- anIOR->SetValue(CORBA::string_dup(aGraph->getIOR()));
-
- return aResultSO._retn();
-}
-
-SUPERV::Value_ptr SuperV_Impl::StringValue( const char * aStrIOR ) {
-// beginService( "Super_Impl::StringValue" );
- CORBA::Any * anAny = new CORBA::Any() ;
-
- try {
- CORBA::Object_ptr obj = _Orb->string_to_object( aStrIOR ) ;
- if ( obj ) {
- *anAny <<= obj ;
-// return(anAny);
- }
- }
- catch ( CORBA::BAD_PARAM ) {
-
-// JR : objref or string only ==> the eventual convertion to long or double is done in
-// the SuperVisionEngine with the real type of the argument
-#if 0
- long l;
- double d;
- if ( strchr( aStrIOR , '.' ) != NULL &&
- sscanf( aStrIOR , "%lf%*n", &d)) {
- *anAny <<= d;
-// MESSAGE( "Value( " << aStrIOR << " ) --> double " << d );
-// return(anAny);
- }
- else if (sscanf( aStrIOR , "%ld%*n", &l)) {
- *anAny <<= l;
-// MESSAGE( "Value( " << aStrIOR << " ) --> long " << l );
-// return(anAny);
- }
- else {
-#endif
- *anAny <<= aStrIOR ;
-// MESSAGE( "Value( " << aStrIOR << " ) --> string " << aStrIOR );
-#if 0
- }
-#endif
- }
-
-// endService( "SuperV_Impl::StringValue" );
- return Value( anAny ) ;
-}
-
-SUPERV::Value_ptr SuperV_Impl::AnyValue( const CORBA::Any & anAny ) {
-// beginService( "Super_Impl::AnyValue" );
- CORBA::Any * aAny = new CORBA::Any( anAny ) ;
-// endService( "SuperV_Impl::AnyValue" );
- return Value( aAny ) ;
-}
-
-SUPERV::Value_ptr SuperV_Impl::Value( CORBA::Any * anAny ) {
-// beginService( "Super_Impl::Value" );
- Value_Impl * myValue = new Value_Impl( _Orb , _Poa , _ContId ,
- instanceName() , interfaceName() ,
- NULL , NULL , NULL , anAny , true ) ;
- PortableServer::ObjectId * id = myValue->getId() ;
- CORBA::Object_var obj = _poa->id_to_reference(*id);
- SUPERV::Value_var iobject ;
- iobject = SUPERV::Value::_narrow(obj) ;
-// endService( "SuperV_Impl::Value" );
- return SUPERV::Value::_duplicate( iobject ) ;
-}
-
-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 , SUPERV::DataFlowGraph ) ;
- int lenname = strlen( aGraphName ) ;
- if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
- created = myGraph->Import( aGraphName ) ;
- }
- else {
- myGraph->Import( (char * ) NULL ) ;
- }
- 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) ;
- myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
- }
- endService( "SuperV_Impl::Graph" );
- return SUPERV::Graph::_duplicate(iobject) ;
-}
-
-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 , SUPERV::DataFlowGraph ) ;
- int lenname = strlen( aGraphName ) ;
- if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
- created = myGraph->Import( aGraphName ) ;
- }
- else {
- myGraph->Import( (char * ) NULL ) ;
- }
- 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) ;
- myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
- }
- myGraph->ReadOnly() ;
- endService( "SuperV_Impl::GraphE" );
- 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 {
- CORBA::Object_ptr obj = _Orb->string_to_object(ior);
- iobject = SUPERV::Graph::_narrow(obj);
- } catch ( ... ) {
- return SUPERV::Graph::_nil();
- // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
- };
- 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 ,
- PortableServer::ObjectId * contId ,
- const char *instanceName ,
- const char *interfaceName
-// , int argc ,
-// char ** argv
- ) {
- MESSAGE("SuperV_factory SuperV ("
- << instanceName << "," << interfaceName << ")");
- SuperV_Impl * mySuperV = new SuperV_Impl( orb , poa , contId ,
- instanceName, interfaceName
-// , argc , argv
- );
- return mySuperV->getId() ;
-}