1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SuperV_Impl.cxx
25 // Author : Jean Rahuel
40 //#include "utilities.h"
42 #include "SALOME_Container_i.hxx"
44 #include "SuperV_Impl.hxx"
46 #include "SALOMEDS_Attributes.hh"
47 #include <TCollection_AsciiString.hxx>
48 #include <TColStd_SequenceOfAsciiString.hxx>
49 #include "SALOMEDS_Tool.hxx"
51 #include "Utils_CorbaException.hxx"
53 #define STUDY_SUPERVISION "SUPERV"
55 SuperV_Impl::SuperV_Impl( CORBA::ORB_ptr orb ,
56 PortableServer::POA_ptr poa ,
57 PortableServer::ObjectId * contId ,
58 const char *instanceName ,
59 const char *interfaceName
63 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
64 MESSAGE("SuperV_Impl::SuperV_Impl activate object instanceName("
65 << instanceName << ") interfaceName(" << interfaceName << ") --> "
66 << hex << (void *) this << dec )
68 _id = _poa->activate_object(_thisObj);
69 _Orb = CORBA::ORB::_duplicate(orb);
74 SuperV_Impl::SuperV_Impl() {
77 SuperV_Impl::~SuperV_Impl() {
78 beginService( "SuperV_Impl::~SuperV_Impl" );
79 endService( "SuperV_Impl::~SuperV_Impl" );
82 void SuperV_Impl::Destroy() {
83 beginService( "SuperV_Impl::Destroy" );
84 _poa->deactivate_object(*_id) ;
85 // CORBA::release(_poa) ;
87 // _thisObj->_remove_ref();
89 endService( "SuperV_Impl::Destroy" );
92 Engines::TMPFile * SuperV_Impl::DumpPython( CORBA::Object_ptr theStudy ,
93 CORBA::Boolean isPublished ,
94 CORBA::Boolean & isValidScript ) {
95 beginService( "Super_Impl::DumpPython" );
97 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theStudy ) ;
98 // typedef sequence<octet> TMPFile;
99 SALOMEDS::SObject_var aStudyObject ;
100 SALOMEDS::SObject_var aStudyObjectValue ;
101 SUPERV::StreamGraph_var aStreamGraph ;
103 string aStringGraph ;
104 string aStringRebuildData ;
106 "### This file is generated by SALOME automatically by dump python functionality\n"
107 "### of Supervisor component\n\n";
108 aStringRebuildData = "def RebuildData( theStudy ) :\n" ;
109 if ( CORBA::is_nil( aStudy ) ) {
110 MESSAGE( "aStudy is_nil" ) ;
114 SALOMEDS::SObject_var aStudyObject = aStudy->FindComponent( ComponentDataType() ) ;
115 if ( CORBA::is_nil( aStudyObject ) ) {
116 MESSAGE( "aStudyObject is_nil" ) ;
120 SALOMEDS::ChildIterator_var aStudyChildIterator = aStudy->NewChildIterator( aStudyObject ) ;
121 bool importSuperV = true ;
122 for ( aStudyChildIterator->InitEx( true ) ; aStudyChildIterator->More() ;
123 aStudyChildIterator->Next() ) {
124 aStudyObjectValue = aStudyChildIterator->Value() ;
125 int aDepth = aStudyObjectValue->Depth() ;
126 char * aStudyObjectValueIOR = aStudyObjectValue->GetIOR() ;
127 MESSAGE( "Super_Impl::DumpPython aStudyObjectValueIOR " << aStudyObjectValueIOR
128 << " Depth " << aDepth ) ;
129 if ( strlen( aStudyObjectValueIOR ) ) {
130 CORBA::Object_var obj = CORBA::Object::_nil() ;
132 obj = _Orb->string_to_object( aStudyObjectValueIOR ) ;
133 if ( !CORBA::is_nil( obj ) ) {
134 aStreamGraph = SUPERV::StreamGraph::_narrow( obj ) ;
135 if ( !CORBA::is_nil( aStreamGraph ) ) {
136 MESSAGE( "aStreamGraph " << aStreamGraph->Name() ) ;
137 aStreamGraph->IsValid() ;
138 aGraph = aStreamGraph->SavePY( importSuperV ) ;
139 importSuperV = false ;
140 aStringGraph += string( aGraph ) ;
141 aStringRebuildData += " " ;
142 aStringRebuildData += aStreamGraph->Name() ;
143 aStringRebuildData += " = Def" ;
144 aStringRebuildData += aStreamGraph->Name() ;
145 aStringRebuildData += "()\n" ;
146 aStringRebuildData += " aBuilder,aStudyObject" ;
149 aStringRebuildData += astr.str() ;
150 aStringRebuildData += " = addDataflowToStudy( theStudy , " ;
151 aStringRebuildData += aStreamGraph->Name() ;
152 aStringRebuildData += " )\n" ;
153 isValidScript = true ;
156 MESSAGE( "Super_Impl::DumpPython aStreamGraph is_nil ERROR" ) ;
163 char * aStudyObjectName = aStudyObjectValue->GetName() ;
164 ostringstream newastr ;
166 if ( strlen( aStudyObjectName ) ) {
167 MESSAGE( "Super_Impl::DumpPython aStudyObjectName " << aStudyObjectName ) ;
168 aStringRebuildData += " aStudyObject" ;
170 aStringRebuildData += astr.str() ;
171 aStringRebuildData += " = aBuilder.NewObject( aStudyObject" ;
172 newastr << (aDepth - 1 ) ;
173 aStringRebuildData += newastr.str() ;
174 aStringRebuildData += " )\n" ;
175 aStringRebuildData += " anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
176 aStringRebuildData += astr.str() ;
177 aStringRebuildData += " , 'AttributeName' )\n" ;
178 aStringRebuildData += " aName = anAttr._narrow( SALOMEDS.AttributeName )\n" ;
179 aStringRebuildData += " aName.SetValue( '" ;
180 aStringRebuildData += aStudyObjectName ;
181 aStringRebuildData += "' )\n" ;
184 MESSAGE( "Super_Impl::DumpPython strlen( aStudyObjectName ) == 0 ERROR" ) ;
188 MESSAGE( "Super_Impl::DumpPython aStudyObjectValueIOR " << aStudyObjectValueIOR ) ;
190 aStringRebuildData += " anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
191 aStringRebuildData += astr.str() ;
192 aStringRebuildData += " , 'AttributeIOR')\n";
193 aStringRebuildData += " anIORAttr = anAttr._narrow( SALOMEDS.AttributeIOR )\n";
194 aStringRebuildData += " anIORAttr.SetValue( '" ;
195 aStringRebuildData += aStudyObjectValueIOR ;
196 aStringRebuildData += "' )\n" ;
200 char * aStudyObjectName = aStudyObjectValue->GetName() ;
201 if ( strlen( aStudyObjectName ) ) {
202 MESSAGE( "Super_Impl::DumpPython aStudyObjectName " << aStudyObjectName << " Depth "
204 aStringRebuildData += " aStudyObject" ;
207 aStringRebuildData += astr.str() ;
208 aStringRebuildData += " = aBuilder.NewObject( aStudyObject" ;
209 ostringstream newastr ;
210 newastr << (aDepth - 1 ) ;
211 aStringRebuildData += newastr.str() ;
212 aStringRebuildData += " )\n" ;
213 aStringRebuildData += " anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
214 aStringRebuildData += astr.str() ;
215 aStringRebuildData += " , 'AttributeName' )\n" ;
216 aStringRebuildData += " aName = anAttr._narrow( SALOMEDS.AttributeName )\n" ;
217 aStringRebuildData += " aName.SetValue( '" ;
218 aStringRebuildData += aStudyObjectName ;
219 aStringRebuildData += "' )\n" ;
222 MESSAGE( "Super_Impl::DumpPython strlen( aStudyObjectName ) == 0 ERROR" ) ;
231 isValidScript = false ;
232 endService( "Super_Impl::DumpPython ERROR" );
233 return new Engines::TMPFile( 0 ) ;
235 aStringRebuildData += " sg.updateObjBrowser( 1 )\n" ;
236 aStringRebuildData += " return 1\n" ;
237 aStringGraph += aStringRebuildData ;
239 int aLen = strlen( aStringGraph.c_str() ) ;
240 unsigned char* aBuffer = new unsigned char[aLen+1];
241 strcpy((char*)aBuffer, aStringGraph.c_str());
243 CORBA::Octet* anOctetBuffer = (CORBA::Octet*)aBuffer;
244 Engines::TMPFile_var aStreamPythonvar = new Engines::TMPFile ( aLen+1 , aLen+1 , anOctetBuffer ,1 ) ;
246 endService( "Super_Impl::DumpPython" );
247 return aStreamPythonvar._retn() ;
250 // void SuperV_Impl::Save(const char *IORSComponent, const char *aUrlOfFile) {
251 SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
254 SALOMEDS::TMPFile_var aStreamFile;
255 // Get a temporary directory to store a file
256 TCollection_AsciiString aTmpDir("");
257 // Create a list to store names of created files
258 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
260 TCollection_AsciiString myStudyName("");
261 if (isMultiFile) myStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str();
263 SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
264 TColStd_SequenceOfAsciiString aFileNames;
265 TCollection_AsciiString aName;
267 for(; anIter->More(); anIter->Next()) {
268 SALOMEDS::SObject_var aSO = anIter->Value();
269 SALOMEDS::GenericAttribute_var anAttr;
270 if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
271 aName = myStudyName +
272 TCollection_AsciiString("_SUPERVISION_") +
273 TCollection_AsciiString(aSO->Tag()) +
274 TCollection_AsciiString(".xml");
275 aFileNames.Append(aName);
278 CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
279 SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
280 if (aTmpDir.Length() == 0)
281 aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
282 graph->Export((aTmpDir + aName).ToCString());
286 if (aFileNames.Length() == 0) return new SALOMEDS::TMPFile(0);
288 aSeq->length(aFileNames.Length());
290 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
291 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
293 // Conver a file to the byte stream
294 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
295 // Remove the created file and tmp directory
296 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
298 // Add python files to the temporary files sequence
299 SALOMEDS::ListOfFileNames_var aPySeq = new SALOMEDS::ListOfFileNames;
300 aPySeq->length(aSeq->length());
301 for(aCounter = aSeq->length(); aCounter > 0; aCounter--) {
302 char* aCName = CORBA::string_dup(aSeq[aCounter-1]);
303 int a = strlen(aCName);
304 aCName[a-3] = 'p';aCName[a-2] = 'y';aCName[a-1] = 0;
305 aPySeq[aCounter-1] = aCName;
307 // Remove the created file and tmp directory
308 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aPySeq.in(), true);
309 // Return the created byte stream
310 return aStreamFile._retn();
313 SALOMEDS::TMPFile* SuperV_Impl::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
316 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
317 return aStreamFile._retn();
320 // void SuperV_Impl::Load(const char* IORSComponent, const char* aUrlOfFile) {
321 CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
322 const SALOMEDS::TMPFile& theStream,
325 // MESSAGE("SuperV_Impl::Load : IOR = " << IORSComponent << " , Url = " << aUrlOfFile);
326 // Get a temporary directory for a file
327 if (theStream.length() != 0) {
328 TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
329 myStrURL = strdup(aTmpDir.ToCString());
330 SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile);
335 CORBA::Boolean SuperV_Impl::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
336 const SALOMEDS::TMPFile& theStream,
339 return Load(theComponent, theStream, theURL, isMultiFile);
342 void SuperV_Impl::Close(SALOMEDS::SComponent_ptr theComponent) {
343 // mpv 06.03.2003: bug SAL1508 - graphs will be destructed at the GUI-level at the supervision frame closing
345 // SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
346 // for(; anIter->More(); anIter->Next()) {
347 // SALOMEDS::SObject_var aSO = anIter->Value();
348 // SALOMEDS::GenericAttribute_var anAttr;
349 // if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
350 // CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
351 // SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
357 char* SuperV_Impl::ComponentDataType() {
358 return(strdup("SUPERV"));
361 char* SuperV_Impl::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
362 const char* IORString,
363 CORBA::Boolean isMultiFile,
364 CORBA::Boolean isASCII) {
365 MESSAGE("SuperV_Impl::IORToLocalPersistentID: IOR:"<<IORString);
368 CORBA::Object_var anObj = _orb->string_to_object(IORString) ;
369 if (CORBA::is_nil(anObj)) return CORBA::string_dup(IORString);
370 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
371 if (aGraph->_is_nil()) return CORBA::string_dup(IORString);
373 return CORBA::string_dup(IORString);
376 // sprintf(aName, "%s_SUPERVISION_tmp_%d.xml",myStudyName,myCounter);
377 // CORBA::String_var myStudyName("");
378 // if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
379 TCollection_AsciiString aName = //TCollection_AsciiString(myStudyName) +
380 TCollection_AsciiString("_SUPERVISION_") +
381 TCollection_AsciiString(theSObject->Tag()) +
382 TCollection_AsciiString(".xml");
383 return CORBA::string_dup(aName.ToCString());
386 char* SuperV_Impl::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
387 const char* aLocalPersistentID,
388 CORBA::Boolean isMultiFile,
389 CORBA::Boolean isASCII)
390 throw(SALOME::SALOME_Exception)
392 MESSAGE("SuperV_Impl::LocalPersistentIDToIOR : IOR = " << aLocalPersistentID);
393 CORBA::String_var aFatherID = theSObject->GetFather()->GetID();
394 CORBA::String_var aComponentID = theSObject->GetFatherComponent()->GetID();
395 if (strcmp(aFatherID, aComponentID)) return CORBA::string_dup(aLocalPersistentID);
397 string myStudyName("");
398 if (isMultiFile) myStudyName = SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL());
400 string aStr(myStrURL);
401 aStr += myStudyName + string(aLocalPersistentID);
402 SUPERV::StreamGraph_ptr graph = StreamGraph(aStr.c_str());
404 if (graph->_is_nil())
405 THROW_SALOME_CORBA_EXCEPTION("Unable to find graph in the file",SALOME::BAD_PARAM);
407 // mpv: remove IORs input ports on loading
408 MESSAGE("Remove IORs input ports on loading");
409 SUPERV::ListOfNodes_var aNodes = graph->Nodes();
410 SUPERV::CNode_var aNode;
411 const char* aStrIOR = "";
412 CORBA::Any * anAny = new CORBA::Any();
415 for(i = aNodes->CNodes.length() - 1; i >= 0; i--) {
416 aNode = aNodes->CNodes[i];
417 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
418 for(j = aPorts->length() - 1; j >= 0; j--) {
419 SUPERV::Port_var aPort = aPorts[j];
420 if (aPort->IsIOR()) {
421 aPort->Input(AnyValue(*anAny));
425 for(i = aNodes->FNodes.length() - 1; i >= 0; i--) {
426 aNode = aNodes->FNodes[i];
427 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
428 for(j = aPorts->length() - 1; j >= 0; j--) {
429 SUPERV::Port_var aPort = aPorts[j];
430 if (aPort->IsIOR()) {
431 //CORBA::Any * anAny = new CORBA::Any(CORBA::TypeCode::PR_null_tc(), (void*)NULL, 0) ;
432 aPort->Input(AnyValue(*anAny));
436 for(i = aNodes->INodes.length() - 1; i >= 0; i--) {
437 aNode = aNodes->INodes[i];
438 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
439 for(j = aPorts->length() - 1; j >= 0; j--) {
440 SUPERV::Port_var aPort = aPorts[j];
441 if (aPort->IsIOR()) {
442 aPort->Input(AnyValue(*anAny));
446 for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
447 aNode = aNodes->GNodes[i];
448 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
449 for(j = aPorts->length() - 1; j >= 0; j--) {
450 SUPERV::Port_var aPort = aPorts[j];
451 if (aPort->IsIOR()) {
452 aPort->Input(AnyValue(*anAny));
456 for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
457 aNode = aNodes->GNodes[i];
458 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
459 for(j = aPorts->length() - 1; j >= 0; j--) {
460 SUPERV::Port_var aPort = aPorts[j];
461 if (aPort->IsIOR()) {
462 aPort->Input(AnyValue(*anAny));
466 for(i = aNodes->LNodes.length() - 1; i >= 0; i--) {
467 aNode = aNodes->LNodes[i];
468 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
469 for(j = aPorts->length() - 1; j >= 0; j--) {
470 SUPERV::Port_var aPort = aPorts[j];
471 if (aPort->IsIOR()) {
472 aPort->Input(AnyValue(*anAny));
476 for(i = aNodes->ELNodes.length() - 1; i >= 0; i--) {
477 aNode = aNodes->ELNodes[i];
478 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
479 for(j = aPorts->length() - 1; j >= 0; j--) {
480 SUPERV::Port_var aPort = aPorts[j];
481 if (aPort->IsIOR()) {
482 aPort->Input(AnyValue(*anAny));
486 for(i = aNodes->SNodes.length() - 1; i >= 0; i--) {
487 aNode = aNodes->SNodes[i];
488 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
489 for(j = aPorts->length() - 1; j >= 0; j--) {
490 SUPERV::Port_var aPort = aPorts[j];
491 if (aPort->IsIOR()) {
492 aPort->Input(AnyValue(*anAny));
496 for(i = aNodes->ESNodes.length() - 1; i >= 0; i--) {
497 aNode = aNodes->ESNodes[i];
498 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
499 for(j = aPorts->length() - 1; j >= 0; j--) {
500 SUPERV::Port_var aPort = aPorts[j];
501 if (aPort->IsIOR()) {
502 aPort->Input(AnyValue(*anAny));
508 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
510 aSeq[0]=aLocalPersistentID;
511 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(myStrURL, aSeq.in(), true);
513 return _Orb->object_to_string(graph);
516 bool SuperV_Impl::CanPublishInStudy(CORBA::Object_ptr theIOR) {
517 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theIOR);
518 return !(aGraph->_is_nil());
521 SALOMEDS::SObject_ptr SuperV_Impl::PublishInStudy(SALOMEDS::Study_ptr theStudy,
522 SALOMEDS::SObject_ptr theSObject,
523 CORBA::Object_ptr theObject,
524 const char* theName) throw (SALOME::SALOME_Exception) {
525 SALOMEDS::SObject_var aResultSO;
527 if(CORBA::is_nil(theObject)) return aResultSO._retn();;
529 if(theStudy->_is_nil()) return aResultSO._retn();;
531 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
532 SALOMEDS::GenericAttribute_var anAttr;
533 SALOMEDS::AttributeName_var aName;
534 SALOMEDS::AttributeIOR_var anIOR;
535 SALOMEDS::AttributePixMap_var aPixmap;
536 SALOMEDS::SComponent_var aFather = theStudy->FindComponent(STUDY_SUPERVISION);
538 if (aFather->_is_nil()) {
539 aFather = aBuilder->NewComponent(STUDY_SUPERVISION);
540 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
541 aName = SALOMEDS::AttributeName::_narrow(anAttr);
542 //NRI aName->SetValue(STUDY_SUPERVISION);
544 SALOME_NamingService *NamingService = new SALOME_NamingService(_Orb);
545 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
546 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
547 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( STUDY_SUPERVISION );
548 if ( !Comp->_is_nil() ) {
549 aName->SetValue( Comp->componentusername() );
551 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
552 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
553 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
555 aBuilder->DefineComponentInstance(aFather, SuperG::_this());
558 SALOMEDS::SObject_var dataflowI;
559 SALOMEDS::ChildIterator_var dataflowS = theStudy->NewChildIterator(aFather);
561 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theObject);
563 const char* name = aGraph->Name();
565 if (CORBA::is_nil(theSObject)) { // if SObject is null, then searching for exist graph SObject
566 for (; dataflowS->More(); dataflowS->Next()) {
567 dataflowI = dataflowS->Value();
568 if (dataflowI->FindAttribute(anAttr, "AttributeName")) {
569 aName = SALOMEDS::AttributeName::_narrow(anAttr);
570 if (strcmp(aName->Value(), name) == 0) {
571 aResultSO = dataflowI;
576 } else { // else searching for referenced SObject
577 if (!theSObject->ReferencedObject(aResultSO))
578 THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
581 if (strlen(theName) != 0) name = theName;
582 if (CORBA::is_nil(aResultSO)) aResultSO = aBuilder->NewObject(aFather);
584 aName = SALOMEDS::AttributeName::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"));
585 aName->SetValue(name);
586 anIOR = SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
587 anIOR->SetValue(aGraph->getIOR());
588 // aBuilder->Addreference(theSObject, aResultSO);
589 return aResultSO._retn();
592 CORBA::Boolean SuperV_Impl::CanCopy(SALOMEDS::SObject_ptr theObject) {
593 // Try to retrieve known by SUPERVISION component Graph by given IOR
594 SALOMEDS::GenericAttribute_var anAttr;
595 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
597 CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
598 if (CORBA::is_nil(anObj)) return false;
600 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
601 if (aGraph->_is_nil()) return false;
609 SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
610 // Declare a sequence of the byte to store the copied object
611 SALOMEDS::TMPFile_var aStreamFile;
613 // Try to get GEOM_Shape object by given SObject
614 SALOMEDS::GenericAttribute_var anAttr;
615 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
616 CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
619 SUPERV::Graph_var aGraph;
621 CORBA::Object_var anObj = _orb->string_to_object(anIOR) ;
622 if (CORBA::is_nil(anObj)) isGraph = false;
624 aGraph = SUPERV::Graph::_narrow(anObj);
625 if (aGraph->_is_nil()) isGraph = false;
631 if (!isGraph) { // it's just a value, stored in the IOR attribute
632 int aLen = strlen(anIOR);
633 CORBA::Octet* anOctetBuf = (CORBA::Octet*)strdup(anIOR);
634 aStreamFile = SALOMEDS::TMPFile_var(new SALOMEDS::TMPFile(aLen, aLen, anOctetBuf, 1));
635 return aStreamFile._retn();
638 // Get a temporary directory to store a temporary file
639 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str();
640 // Create a list to store names of created files
641 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
643 aSeq[0] = strdup("_SUPERVISION_tmp.xml");
644 char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
645 strcpy(aFullName, aTmpDir);
646 strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
647 aGraph->Export(strdup(aFullName));
650 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.in(), aSeq.in(), false);
651 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.in(), aSeq.in(), true);
653 // Assign an ID = 1 the the type SUPERV::Graph
656 return aStreamFile._retn();
659 CORBA::Boolean SuperV_Impl::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
660 // The Supervision component can paste only objects copied by Supervision component
661 // and with the object type = 1
662 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
666 SALOMEDS::SObject_ptr SuperV_Impl::PasteInto(const SALOMEDS::TMPFile& theStream,
667 CORBA::Long theObjectID,
668 SALOMEDS::SObject_ptr theObject) {
669 SALOMEDS::SObject_var aResultSO;
670 if(CORBA::is_nil(theObject)) return aResultSO._retn();
671 SALOMEDS::StudyBuilder_var aBuilder = theObject->GetStudy()->NewBuilder();
673 aResultSO = SALOMEDS::SObject::_narrow(CORBA::Object::_duplicate(theObject));
675 bool isGraph = (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0);
679 SALOMEDS::AttributeIOR_var anIOR =
680 SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(theObject, "AttributeIOR"));
681 int aLen = theStream.length();
682 char* aVal = new char[aLen+1];
683 aVal[aLen] = (char)0;
684 memcpy((void*)aVal, (void*)theStream.NP_data(), aLen);
685 anIOR->SetValue(aVal);
686 return aResultSO._retn();
689 TCollection_AsciiString aTmpDir = (char*)SALOMEDS_Tool::GetTmpDir().c_str();
690 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), false);
691 TCollection_AsciiString aFullName;
692 aFullName = aTmpDir+aSeq[0];
693 SUPERV::Graph_var aGraph = Graph(aFullName.ToCString());
695 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
698 aResultSO = aBuilder->NewObject(theObject);
701 SALOMEDS::AttributeIOR_var anIOR =
702 SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
703 anIOR->SetValue(CORBA::string_dup(aGraph->getIOR()));
705 return aResultSO._retn();
708 SUPERV::Value_ptr SuperV_Impl::StringValue( const char * aStrIOR ) {
709 // beginService( "Super_Impl::StringValue" );
710 CORBA::Any * anAny = new CORBA::Any() ;
713 CORBA::Object_ptr obj = _Orb->string_to_object( aStrIOR ) ;
719 catch ( ... ) { // mkr : catch any exception to avoid crash after set incorrect
720 // value of 'objref' type for input port
721 //catch ( CORBA::BAD_PARAM ) {
723 // JR : objref or string only ==> the eventual convertion to long or double is done in
724 // the SuperVisionEngine with the real type of the argument
728 if ( strchr( aStrIOR , '.' ) != NULL &&
729 sscanf( aStrIOR , "%lf%*n", &d)) {
731 // MESSAGE( "Value( " << aStrIOR << " ) --> double " << d );
734 else if (sscanf( aStrIOR , "%ld%*n", &l)) {
736 // MESSAGE( "Value( " << aStrIOR << " ) --> long " << l );
742 // MESSAGE( "Value( " << aStrIOR << " ) --> string " << aStrIOR );
748 // endService( "SuperV_Impl::StringValue" );
749 return Value( anAny ) ;
752 SUPERV::Value_ptr SuperV_Impl::AnyValue( const CORBA::Any & anAny ) {
753 // beginService( "Super_Impl::AnyValue" );
754 CORBA::Any * aAny = new CORBA::Any( anAny ) ;
755 // endService( "SuperV_Impl::AnyValue" );
756 return Value( aAny ) ;
759 SUPERV::Value_ptr SuperV_Impl::Value( CORBA::Any * anAny ) {
760 // beginService( "Super_Impl::Value" );
761 Value_Impl * myValue = new Value_Impl( _Orb , _Poa , _ContId ,
762 instanceName() , interfaceName() ,
763 NULL , NULL , NULL , anAny , true ) ;
764 PortableServer::ObjectId * id = myValue->getId() ;
765 CORBA::Object_var obj = _poa->id_to_reference(*id);
766 SUPERV::Value_var iobject ;
767 iobject = SUPERV::Value::_narrow(obj) ;
768 // endService( "SuperV_Impl::Value" );
769 return SUPERV::Value::_duplicate( iobject ) ;
772 CORBA::Object_ptr SuperV_Impl::ToObject( CORBA::Object_ptr anObjectRef ) {
773 beginService( "SuperV_Impl::ToObject" );
774 CORBA::Object_ptr anObject ;
775 anObject = CORBA::Object::_duplicate( anObjectRef ) ;
776 endService( "SuperV_Impl::ToObject" );
780 SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) {
781 beginService( "SuperV_Impl::Graph" );
782 bool created = true ;
783 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
784 Graph_Impl * myGraph ;
785 myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() ,
786 aGraphName , SUPERV::DataFlowGraph ) ;
787 int lenname = strlen( aGraphName ) ;
788 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
789 created = myGraph->Import( aGraphName ) ;
792 myGraph->Import( (char * ) NULL ) ;
794 if ( !created && myGraph->IsStreamGraph() ) {
795 MESSAGE( "SuperV_Impl::Graph " << aGraphName << " IsStreamGraph !" ) ;
797 SUPERV::StreamGraph_var streamiobject = StreamGraph( aGraphName ) ;
798 iobject = SUPERV::Graph::_narrow( streamiobject ) ;
799 if ( CORBA::is_nil( iobject ) ) {
803 else if ( created ) {
804 PortableServer::ObjectId * id = myGraph->getId() ;
805 CORBA::Object_var obj = _poa->id_to_reference(*id);
806 iobject = SUPERV::Graph::_narrow(obj) ;
807 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
809 endService( "SuperV_Impl::Graph" );
810 return SUPERV::Graph::_duplicate(iobject) ;
813 SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) {
814 beginService( "SuperV_Impl::GraphE" );
815 bool created = true ;
816 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
817 Graph_Impl * myGraph ;
818 myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() ,
819 aGraphName , SUPERV::DataFlowGraph ) ;
820 int lenname = strlen( aGraphName ) ;
821 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
822 created = myGraph->Import( aGraphName ) ;
825 myGraph->Import( (char * ) NULL ) ;
827 if ( !created && myGraph->IsStreamGraph() ) {
829 SUPERV::StreamGraph_var streamiobject = StreamGraphE( aGraphName ) ;
830 iobject = SUPERV::Graph::_narrow( streamiobject ) ;
831 if ( CORBA::is_nil( iobject ) ) {
835 else if ( created ) {
836 PortableServer::ObjectId * id = myGraph->getId() ;
837 CORBA::Object_var obj = _poa->id_to_reference(*id);
838 iobject = SUPERV::Graph::_narrow(obj) ;
839 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
841 myGraph->ReadOnly() ;
842 myGraph->DataFlowEditor()->Graph()->ClearMapOfComponentNameContainer() ; // mkr : PAL13947
843 endService( "SuperV_Impl::GraphE" );
844 return SUPERV::Graph::_duplicate(iobject) ;
847 SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraph(const char * aGraphName ) {
848 beginService( "SuperV_Impl::StreamGraph" );
849 bool created = true ;
850 StreamGraph_Impl * myStreamGraph ;
851 myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() ,
852 interfaceName() , aGraphName ) ;
853 int lenname = strlen( aGraphName ) ;
854 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
855 created = myStreamGraph->Import( aGraphName ) ;
858 myStreamGraph->Import( (char * ) NULL ) ;
860 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
862 PortableServer::ObjectId * id = myStreamGraph->getId() ;
863 CORBA::Object_var obj = _poa->id_to_reference(*id);
864 iobject = SUPERV::StreamGraph::_narrow(obj) ;
865 myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ;
867 endService( "SuperV_Impl::StreamGraph" );
868 return SUPERV::StreamGraph::_duplicate(iobject) ;
871 SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraphE(const char * aGraphName ) {
872 beginService( "SuperV_Impl::StreamGraphE" );
873 bool created = true ;
874 StreamGraph_Impl * myStreamGraph ;
875 myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() ,
876 interfaceName() , aGraphName ) ;
877 int lenname = strlen( aGraphName ) ;
878 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
879 created = myStreamGraph->Import( aGraphName ) ;
882 myStreamGraph->Import( (char * ) NULL ) ;
884 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
886 PortableServer::ObjectId * id = myStreamGraph->getId() ;
887 CORBA::Object_var obj = _poa->id_to_reference(*id);
888 iobject = SUPERV::StreamGraph::_narrow(obj) ;
889 myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ;
891 myStreamGraph->ReadOnly() ;
892 myStreamGraph->DataFlowEditor()->Graph()->ClearMapOfComponentNameContainer() ; // mkr : PAL13947
893 endService( "SuperV_Impl::StreamGraphE" );
894 return SUPERV::StreamGraph::_duplicate(iobject) ;
897 SUPERV::Graph_ptr SuperV_Impl::getGraph(const char* ior) {
898 SUPERV::Graph_var iobject = SUPERV::Graph::_nil();
900 CORBA::Object_ptr obj = _Orb->string_to_object(ior);
901 iobject = SUPERV::Graph::_narrow(obj);
903 return SUPERV::Graph::_nil();
904 // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
906 return(SUPERV::Graph::_duplicate(iobject));
909 SUPERV::StreamGraph_ptr SuperV_Impl::getStreamGraph(const char* ior) {
910 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil();
912 CORBA::Object_ptr obj = _Orb->string_to_object(ior);
913 iobject = SUPERV::StreamGraph::_narrow(obj);
915 return SUPERV::StreamGraph::_nil();
916 // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
918 return(SUPERV::StreamGraph::_duplicate(iobject));
921 PortableServer::ObjectId * SUPERVEngine_factory (
923 PortableServer::POA_ptr poa ,
924 PortableServer::ObjectId * contId ,
925 const char *instanceName ,
926 const char *interfaceName
930 MESSAGE("SuperV_factory SuperV ("
931 << instanceName << "," << interfaceName << ")");
932 SuperV_Impl * mySuperV = new SuperV_Impl( orb , poa , contId ,
933 instanceName, interfaceName
936 return mySuperV->getId() ;