]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/SuperV_Impl.cxx
Salome HOME
NRI : Use component username from Catalog.
[modules/superv.git] / src / Supervision / SuperV_Impl.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SuperV_Impl.cxx
4 // Created   : Nov 2001
5 // Author    : Jean Rahuel
6 // Project   : SALOME
7 // $Header$
8 //=============================================================================
9
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <sys/stat.h>
13
14 #include <fstream>
15 #include <strstream>
16 #include <string>
17
18 #include "Python.h"
19
20 #include "utilities.h"
21
22 #include "SALOME_Container_i.hxx"
23
24 #include "SuperV_Impl.hxx"
25
26 #include "SALOMEDS_Attributes.hh"
27 #include <TCollection_AsciiString.hxx>
28 #include <TColStd_SequenceOfAsciiString.hxx>
29 #include "SALOMEDS_Tool.hxx"
30
31 #include "Utils_CorbaException.hxx"
32
33 #define STUDY_SUPERVISION "SUPERV"
34
35 SuperV_Impl::SuperV_Impl( CORBA::ORB_ptr orb ,
36                           PortableServer::POA_ptr poa ,
37                           PortableServer::ObjectId * contId , 
38                           const char *instanceName ,
39                           const char *interfaceName 
40 //                          , int argc ,
41 //                          char ** argv
42                           ) :
43   Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
44   MESSAGE("SuperV_Impl::SuperV_Impl activate object instanceName("
45           << instanceName << ") interfaceName(" << interfaceName << ") --> "
46           << hex << (void *) this << dec )
47   _thisObj = this ;
48   _id = _poa->activate_object(_thisObj);
49   _Orb = CORBA::ORB::_duplicate(orb);
50   _Poa = poa ;
51   _ContId = contId ;
52 }
53
54 SuperV_Impl::SuperV_Impl() {
55 }
56
57 SuperV_Impl::~SuperV_Impl() {
58   beginService( "SuperV_Impl::~SuperV_Impl" );
59   endService( "SuperV_Impl::~SuperV_Impl" );
60 }
61
62 void SuperV_Impl::Destroy() {
63   beginService( "SuperV_Impl::Destroy" );
64   _poa->deactivate_object(*_id) ;
65   CORBA::release(_poa) ;
66   delete(_id) ;
67   _thisObj->_remove_ref();
68   Py_Finalize();
69   endService( "SuperV_Impl::Destroy" );
70 }
71
72 //  void SuperV_Impl::Save(const char *IORSComponent, const char *aUrlOfFile) {
73 SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
74                                      const char* theURL,
75                                      bool isMultiFile) {
76   SALOMEDS::TMPFile_var aStreamFile;
77   // Get a temporary directory to store a file
78   TCollection_AsciiString aTmpDir("");
79   // Create a list to store names of created files
80   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
81   
82   CORBA::String_var myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()));
83
84   SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
85   TColStd_SequenceOfAsciiString aFileNames;
86   TCollection_AsciiString aName;
87   
88   for(; anIter->More(); anIter->Next()) {
89     SALOMEDS::SObject_var aSO = anIter->Value();
90     SALOMEDS::GenericAttribute_var anAttr;
91     if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
92       aName = TCollection_AsciiString(myStudyName) + 
93         TCollection_AsciiString("_SUPERVISION_") +
94         TCollection_AsciiString(aSO->Tag()) +
95         TCollection_AsciiString(".xml");
96       aFileNames.Append(aName);
97
98       // save to the file
99       CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
100       SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
101       if (aTmpDir.Length() == 0)
102         aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
103       graph->Export((aTmpDir + aName).ToCString());
104     }
105   }
106
107   if (aFileNames.Length() == 0) return new SALOMEDS::TMPFile(0);
108
109   aSeq->length(aFileNames.Length());
110   int aCounter;
111   for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
112     aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
113
114   // Conver a file to the byte stream
115   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
116   // Remove the created file and tmp directory
117   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
118   
119   // Add python files to the temporary files sequence
120   SALOMEDS::ListOfFileNames_var aPySeq = new SALOMEDS::ListOfFileNames;
121   aPySeq->length(aSeq->length());
122   for(aCounter = aSeq->length(); aCounter > 0; aCounter--) {
123     char* aCName = CORBA::string_dup(aSeq[aCounter-1]);
124     int a = strlen(aCName);
125     aCName[a-3] = 'p';aCName[a-2] = 'y';aCName[a-1] = 0;
126     aPySeq[aCounter-1] = aCName;
127   }
128   // Remove the created file and tmp directory
129   SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aPySeq.in(), true);
130   // Return the created byte stream
131   return aStreamFile._retn();
132 }
133
134 //  void SuperV_Impl::Load(const char* IORSComponent, const char* aUrlOfFile) {
135 CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
136                                  const SALOMEDS::TMPFile& theStream,
137                                  const char* theURL,
138                                  bool isMultiFile) {
139   //    MESSAGE("SuperV_Impl::Load : IOR = " << IORSComponent << " , Url = " << aUrlOfFile);
140   // Get a temporary directory for a file
141   if (theStream.length() != 0) {
142     TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):SALOMEDS_Tool::GetTmpDir();
143     myStrURL = strdup(aTmpDir.ToCString());
144     SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile);
145   }
146   return true;
147 }
148
149 void SuperV_Impl::Close(SALOMEDS::SComponent_ptr theComponent) {
150 // mpv 06.03.2003: bug SAL1508 - graphs will be destructed at the GUI-level at the supervision frame closing
151
152 //    SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
153 //    for(; anIter->More(); anIter->Next()) {
154 //      SALOMEDS::SObject_var aSO = anIter->Value();
155 //      SALOMEDS::GenericAttribute_var anAttr;
156 //      if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
157 //        CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
158 //        SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
159 //        graph->destroy();
160 //      }
161 //    } 
162 }
163
164 char* SuperV_Impl::ComponentDataType() {
165     return(strdup("SUPERV"));
166 }
167
168 char* SuperV_Impl::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
169                                           const char* IORString,
170                                           CORBA::Boolean isMultiFile) {
171   MESSAGE("SuperV_Impl::IORToLocalPersistentID: IOR:"<<IORString);
172
173   try {
174     CORBA::Object_var anObj = _orb->string_to_object(IORString) ;
175     if (CORBA::is_nil(anObj)) return CORBA::string_dup(IORString);
176     SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
177     if (aGraph->_is_nil()) return CORBA::string_dup(IORString);
178   } catch (...) {
179     return CORBA::string_dup(IORString);
180   }
181
182 //    sprintf(aName, "%s_SUPERVISION_tmp_%d.xml",myStudyName,myCounter);
183   CORBA::String_var myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
184   TCollection_AsciiString aName = TCollection_AsciiString(myStudyName) + 
185     TCollection_AsciiString("_SUPERVISION_") +
186     TCollection_AsciiString(theSObject->Tag()) +
187     TCollection_AsciiString(".xml");
188   return CORBA::string_dup(aName.ToCString());
189 }
190
191 char* SuperV_Impl::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
192                                           const char* aLocalPersistentID,
193                                           CORBA::Boolean isMultiFile)
194      throw(SALOME::SALOME_Exception)
195 {
196   MESSAGE("SuperV_Impl::LocalPersistentIDToIOR : IOR = " << aLocalPersistentID);
197   CORBA::String_var aFatherID = theSObject->GetFather()->GetID();
198   CORBA::String_var aComponentID = theSObject->GetFatherComponent()->GetID();
199   if (strcmp(aFatherID, aComponentID)) return CORBA::string_dup(aLocalPersistentID);
200
201   string aStr(myStrURL);
202   aStr += string(aLocalPersistentID);
203   SUPERV::Graph_ptr graph = Graph(aStr.c_str());
204
205   if (graph->_is_nil()) 
206     THROW_SALOME_CORBA_EXCEPTION("Unable to find graph in the file",SALOME::BAD_PARAM);
207
208   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
209   aSeq->length(1);
210   aSeq[0]=aLocalPersistentID;
211   if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(myStrURL, aSeq.in(), true);
212   
213   return _Orb->object_to_string(graph);
214 }
215
216 bool SuperV_Impl::CanPublishInStudy(CORBA::Object_ptr theIOR) {
217   SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theIOR);
218   return !(aGraph->_is_nil());
219 }
220
221 SALOMEDS::SObject_ptr SuperV_Impl::PublishInStudy(SALOMEDS::Study_ptr theStudy,
222                                                   SALOMEDS::SObject_ptr theSObject,
223                                                   CORBA::Object_ptr theObject,
224                                                   const char* theName) throw (SALOME::SALOME_Exception) {
225   SALOMEDS::SObject_var aResultSO;
226
227   if(CORBA::is_nil(theObject)) return aResultSO._retn();;
228
229   if(theStudy->_is_nil()) return aResultSO._retn();;
230
231   SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
232   SALOMEDS::GenericAttribute_var anAttr;
233   SALOMEDS::AttributeName_var    aName;
234   SALOMEDS::AttributeIOR_var     anIOR;
235   SALOMEDS::AttributePixMap_var  aPixmap;
236   SALOMEDS::SComponent_var aFather = theStudy->FindComponent(STUDY_SUPERVISION);
237
238   if (aFather->_is_nil()) {
239     aFather = aBuilder->NewComponent(STUDY_SUPERVISION);
240     anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
241     aName = SALOMEDS::AttributeName::_narrow(anAttr);
242     //NRI    aName->SetValue(STUDY_SUPERVISION);
243     
244     SALOME_NamingService *NamingService = new SALOME_NamingService(_Orb);
245     CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
246     SALOME_ModuleCatalog::ModuleCatalog_var Catalogue  = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
247     SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( STUDY_SUPERVISION );
248     if ( !Comp->_is_nil() ) {
249       aName->SetValue( Comp->componentusername() );
250     }
251
252     anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
253     aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
254     aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
255
256     aBuilder->DefineComponentInstance(aFather, SuperG::_this());
257   }
258
259   SALOMEDS::SObject_var       dataflowI;
260   SALOMEDS::ChildIterator_var dataflowS = theStudy->NewChildIterator(aFather);
261
262   SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theObject);
263   
264   const char* name = aGraph->Name();
265
266   if (CORBA::is_nil(theSObject)) { // if SObject is null, then searching for exist graph SObject
267     for (; dataflowS->More(); dataflowS->Next()) {
268       dataflowI = dataflowS->Value();
269       if (dataflowI->FindAttribute(anAttr, "AttributeName")) {
270         aName = SALOMEDS::AttributeName::_narrow(anAttr);
271         if (strcmp(aName->Value(), name) == 0) {
272           aResultSO = dataflowI;
273           break;
274         }
275       }
276     }
277   } else { // else searching for referenced SObject
278     if (!theSObject->ReferencedObject(aResultSO)) 
279       THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
280   }
281
282   if (strlen(theName) != 0) name = theName;
283   if (CORBA::is_nil(aResultSO)) aResultSO = aBuilder->NewObject(aFather);
284
285   aName  = SALOMEDS::AttributeName::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"));
286   aName->SetValue(name);
287   anIOR  = SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
288   anIOR->SetValue(aGraph->getIOR());
289 //    aBuilder->Addreference(theSObject, aResultSO);
290   return aResultSO._retn();
291 }
292
293 CORBA::Boolean SuperV_Impl::CanCopy(SALOMEDS::SObject_ptr theObject) {
294   // Try to retrieve known by SUPERVISION component Graph by given IOR
295   SALOMEDS::GenericAttribute_var anAttr;
296   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
297   try {
298     CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
299     if (CORBA::is_nil(anObj)) return false;
300     else {
301       SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
302       if (aGraph->_is_nil()) return false;
303     }
304   } catch (...) {
305     return false;
306   }
307   return true;
308 }
309
310 SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
311   // Declare a sequence of the byte to store the copied object
312   SALOMEDS::TMPFile_var aStreamFile;
313
314   // Try to get GEOM_Shape object by given SObject
315   SALOMEDS::GenericAttribute_var anAttr;
316   if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
317   CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
318
319   bool isGraph = true;
320   SUPERV::Graph_var aGraph;
321   try {
322     CORBA::Object_var anObj = _orb->string_to_object(anIOR) ;
323     if (CORBA::is_nil(anObj)) isGraph = false;
324     else {
325       aGraph = SUPERV::Graph::_narrow(anObj);
326       if (aGraph->_is_nil()) isGraph = false;
327     }
328   } catch (...) {
329     isGraph = false;
330   }
331
332   if (!isGraph) { // it's just a value, stored in the IOR attribute
333     int aLen = strlen(anIOR);
334     CORBA::Octet* anOctetBuf = (CORBA::Octet*)strdup(anIOR);
335     aStreamFile = SALOMEDS::TMPFile_var(new SALOMEDS::TMPFile(aLen, aLen, anOctetBuf, 1));
336     return aStreamFile._retn();
337   }
338
339   // Get a temporary directory to store a temporary file
340   CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir();
341   // Create a list to store names of created files
342   SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
343   aSeq->length(1);
344   aSeq[0] = strdup("_SUPERVISION_tmp.xml");
345   char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
346   strcpy(aFullName, aTmpDir);
347   strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
348   aGraph->Export(strdup(aFullName));
349   delete(aFullName);
350
351   aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aSeq.in(), false);
352   SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
353
354   // Assign an ID = 1 the the type SUPERV::Graph
355   theObjectID = 1;
356  
357   return aStreamFile._retn();
358 }
359
360 CORBA::Boolean SuperV_Impl::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
361   // The Supervision component can paste only objects copied by Supervision component
362   // and with the object type = 1
363   if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
364   return true;
365 }
366
367 SALOMEDS::SObject_ptr SuperV_Impl::PasteInto(const SALOMEDS::TMPFile& theStream,
368                                              CORBA::Long theObjectID,
369                                              SALOMEDS::SObject_ptr theObject) {
370   SALOMEDS::SObject_var aResultSO;
371
372   SALOMEDS::StudyBuilder_var aBuilder = theObject->GetStudy()->NewBuilder();
373
374   bool isGraph = (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0);
375
376   if (!isGraph) {
377     SALOMEDS::AttributeIOR_var anIOR =
378       SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(theObject, "AttributeIOR"));
379     anIOR->SetValue((char*)theStream.NP_data());
380     return SALOMEDS::SObject_var(theObject)._retn();
381   }
382   if(CORBA::is_nil(theObject)) return aResultSO._retn();
383
384   CORBA::String_var aTmpDir = strdup(SALOMEDS_Tool::GetTmpDir());
385   SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir, false);
386   char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
387   strcpy(aFullName, aTmpDir);
388   strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
389   SUPERV::Graph_ptr aGraph = Graph(strdup(aFullName));
390   delete(aFullName);
391
392   SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
393
394   if (isGraph) {
395     aResultSO = aBuilder->NewObject(theObject);
396   } else {
397     aResultSO = theObject;
398   }
399
400   SALOMEDS::AttributeIOR_var anIOR =
401     SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
402   anIOR->SetValue(aGraph->getIOR());
403
404   return aResultSO._retn();
405 }
406
407 SUPERV::Value_ptr SuperV_Impl::StringValue( const char * aStrIOR ) {
408 //  beginService( "Super_Impl::StringValue" );
409   CORBA::Any * anAny = new CORBA::Any() ;
410
411   try {
412     CORBA::Object_ptr obj = _Orb->string_to_object( aStrIOR ) ;
413     if ( obj ) {
414       *anAny <<= obj ;
415 //      return(anAny);
416     }
417   }
418   catch ( CORBA::BAD_PARAM ) {
419
420     long l;
421     double d;
422     if ( strchr( aStrIOR , '.' ) != NULL &&
423          sscanf( aStrIOR , "%lf%*n", &d)) {
424       *anAny <<= d;
425 //        MESSAGE( "Value( " << aStrIOR << " ) --> double " << d );
426 //    return(anAny);
427     }
428     else if (sscanf( aStrIOR , "%ld%*n", &l)) {
429       *anAny <<= l;
430 //        MESSAGE( "Value( " << aStrIOR << " ) --> long " << l );
431 //    return(anAny);
432     }
433     else {
434       *anAny <<=  aStrIOR ;
435 //        MESSAGE( "Value( " << aStrIOR << " ) --> string " << aStrIOR );
436     }
437   }
438
439 //  endService( "SuperV_Impl::StringValue" );
440   return Value( anAny ) ;
441 }
442
443 SUPERV::Value_ptr SuperV_Impl::AnyValue( const CORBA::Any & anAny ) {
444 //  beginService( "Super_Impl::AnyValue" );
445   CORBA::Any * aAny = new CORBA::Any( anAny ) ;
446 //  endService( "SuperV_Impl::AnyValue" );
447   return Value( aAny ) ;
448 }
449
450 SUPERV::Value_ptr SuperV_Impl::Value( CORBA::Any * anAny ) {
451 //  beginService( "Super_Impl::Value" );
452   Value_Impl * myValue = new Value_Impl( _Orb , _Poa , _ContId ,
453                                          instanceName() , interfaceName() ,
454                                          NULL , NULL , NULL , anAny , true ) ;
455   PortableServer::ObjectId * id = myValue->getId() ;
456   CORBA::Object_var obj = _poa->id_to_reference(*id);
457   SUPERV::Value_var iobject ;
458   iobject = SUPERV::Value::_narrow(obj) ;
459 //  endService( "SuperV_Impl::Value" );
460   return SUPERV::Value::_duplicate( iobject ) ;
461 }
462
463 SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) {
464   beginService( "SuperV_Impl::Graph" );
465   bool created = true ;
466   Graph_Impl * myGraph ;
467   myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
468                             instanceName() , interfaceName() , aGraphName ) ;
469   int lenname = strlen( aGraphName ) ;
470   if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
471     created = myGraph->Import( aGraphName ) ;
472   }
473   else {
474     myGraph->Import( (char * ) NULL ) ;
475   }
476   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
477   if ( created ) {
478     PortableServer::ObjectId * id = myGraph->getId() ;
479     CORBA::Object_var obj = _poa->id_to_reference(*id);
480     iobject = SUPERV::Graph::_narrow(obj) ;
481     myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
482   }
483   endService( "SuperV_Impl::Graph" );
484   return SUPERV::Graph::_duplicate(iobject) ;
485 }
486
487 SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) {
488   beginService( "SuperV_Impl::GraphE" );
489   bool created = true ;
490   Graph_Impl * myGraph ;
491   myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
492                             instanceName() , interfaceName() , aGraphName ) ;
493   int lenname = strlen( aGraphName ) ;
494   if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
495     created = myGraph->Import( aGraphName ) ;
496   }
497   else {
498     myGraph->Import( (char * ) NULL ) ;
499   }
500   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
501   if ( created ) {
502     PortableServer::ObjectId * id = myGraph->getId() ;
503     CORBA::Object_var obj = _poa->id_to_reference(*id);
504     iobject = SUPERV::Graph::_narrow(obj) ;
505     myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
506   }
507   myGraph->ReadOnly() ;
508   endService( "SuperV_Impl::GraphE" );
509   return SUPERV::Graph::_duplicate(iobject) ;
510 }
511
512 SUPERV::Graph_ptr SuperV_Impl::getGraph(const char* ior) {
513     SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
514     try {
515         CORBA::Object_ptr obj = _Orb->string_to_object(ior);
516         iobject = SUPERV::Graph::_narrow(obj);
517     } catch ( ... ) {
518         SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
519     };
520     return(SUPERV::Graph::_duplicate(iobject));
521 }
522
523 PortableServer::ObjectId * SUPERVEngine_factory (
524                                             CORBA::ORB_ptr orb ,
525                                             PortableServer::POA_ptr poa , 
526                                             PortableServer::ObjectId * contId ,
527                                             const char *instanceName ,
528                                             const char *interfaceName
529 //                                            , int argc ,
530 //                                            char ** argv 
531                                             ) {
532     MESSAGE("SuperV_factory SuperV ("
533             << instanceName << "," << interfaceName << ")");
534     SuperV_Impl * mySuperV = new SuperV_Impl( orb , poa , contId ,
535                                               instanceName, interfaceName
536 //                                              , argc , argv
537                                             );
538     return mySuperV->getId() ;
539 }