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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 Engines::TMPFile_var aStreamPythonvar ;
100 SALOMEDS::SObject_var aStudyObject ;
101 SALOMEDS::SObject_var aStudyObjectValue ;
102 SUPERV::StreamGraph_var aStreamGraph ;
104 string aStringGraph ;
105 string aStringRebuildData ;
107 "### This file is generated by SALOME automatically by dump python funcitonality\n"
108 "### of Supervisor component\n\n";
109 aStringRebuildData = "def RebuildData( theStudy ) :\n" ;
110 if ( CORBA::is_nil( aStudy ) ) {
111 MESSAGE( "aStudy is_nil" ) ;
115 SALOMEDS::SObject_var aStudyObject = aStudy->FindComponent( ComponentDataType() ) ;
116 if ( CORBA::is_nil( aStudyObject ) ) {
117 MESSAGE( "aStudyObject is_nil" ) ;
121 SALOMEDS::ChildIterator_var aStudyChildIterator = aStudy->NewChildIterator( aStudyObject ) ;
122 bool importSuperV = true ;
123 for ( aStudyChildIterator->InitEx( true ) ; aStudyChildIterator->More() ;
124 aStudyChildIterator->Next() ) {
125 aStudyObjectValue = aStudyChildIterator->Value() ;
126 int aDepth = aStudyObjectValue->Depth() ;
127 char * aStudyObjectValueIOR = aStudyObjectValue->GetIOR() ;
128 MESSAGE( "Super_Impl::DumpPython aStudyObjectValueIOR " << aStudyObjectValueIOR
129 << " Depth " << aDepth ) ;
130 if ( strlen( aStudyObjectValueIOR ) ) {
131 CORBA::Object_var obj = CORBA::Object::_nil() ;
133 obj = _Orb->string_to_object( aStudyObjectValueIOR ) ;
134 if ( !CORBA::is_nil( obj ) ) {
135 aStreamGraph = SUPERV::StreamGraph::_narrow( obj ) ;
136 if ( !CORBA::is_nil( aStreamGraph ) ) {
137 MESSAGE( "aStreamGraph " << aStreamGraph->Name() ) ;
138 aStreamGraph->IsValid() ;
139 aGraph = aStreamGraph->SavePY( importSuperV ) ;
140 importSuperV = false ;
141 aStringGraph += string( aGraph ) ;
142 aStringRebuildData += " " ;
143 aStringRebuildData += aStreamGraph->Name() ;
144 aStringRebuildData += " = Def" ;
145 aStringRebuildData += aStreamGraph->Name() ;
146 aStringRebuildData += "()\n" ;
147 aStringRebuildData += " aBuilder,aStudyObject" ;
150 aStringRebuildData += astr.str() ;
151 aStringRebuildData += " = addDataflowToStudy( theStudy , " ;
152 aStringRebuildData += aStreamGraph->Name() ;
153 aStringRebuildData += " )\n" ;
154 isValidScript = true ;
157 MESSAGE( "Super_Impl::DumpPython aStreamGraph is_nil ERROR" ) ;
164 char * aStudyObjectName = aStudyObjectValue->GetName() ;
165 ostringstream newastr ;
167 if ( strlen( aStudyObjectName ) ) {
168 MESSAGE( "Super_Impl::DumpPython aStudyObjectName " << aStudyObjectName ) ;
169 aStringRebuildData += " aStudyObject" ;
171 aStringRebuildData += astr.str() ;
172 aStringRebuildData += " = aBuilder.NewObject( aStudyObject" ;
173 newastr << (aDepth - 1 ) ;
174 aStringRebuildData += newastr.str() ;
175 aStringRebuildData += " )\n" ;
176 aStringRebuildData += " anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
177 aStringRebuildData += astr.str() ;
178 aStringRebuildData += " , 'AttributeName' )\n" ;
179 aStringRebuildData += " aName = anAttr._narrow( SALOMEDS.AttributeName )\n" ;
180 aStringRebuildData += " aName.SetValue( '" ;
181 aStringRebuildData += aStudyObjectName ;
182 aStringRebuildData += "' )\n" ;
185 MESSAGE( "Super_Impl::DumpPython strlen( aStudyObjectName ) == 0 ERROR" ) ;
189 MESSAGE( "Super_Impl::DumpPython aStudyObjectValueIOR " << aStudyObjectValueIOR ) ;
191 aStringRebuildData += " anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
192 aStringRebuildData += astr.str() ;
193 aStringRebuildData += " , 'AttributeIOR')\n";
194 aStringRebuildData += " anIORAttr = anAttr._narrow( SALOMEDS.AttributeIOR )\n";
195 aStringRebuildData += " anIORAttr.SetValue( '" ;
196 aStringRebuildData += aStudyObjectValueIOR ;
197 aStringRebuildData += "' )\n" ;
201 char * aStudyObjectName = aStudyObjectValue->GetName() ;
202 if ( strlen( aStudyObjectName ) ) {
203 MESSAGE( "Super_Impl::DumpPython aStudyObjectName " << aStudyObjectName << " Depth "
205 aStringRebuildData += " aStudyObject" ;
208 aStringRebuildData += astr.str() ;
209 aStringRebuildData += " = aBuilder.NewObject( aStudyObject" ;
210 ostringstream newastr ;
211 newastr << (aDepth - 1 ) ;
212 aStringRebuildData += newastr.str() ;
213 aStringRebuildData += " )\n" ;
214 aStringRebuildData += " anAttr = aBuilder.FindOrCreateAttribute( aStudyObject" ;
215 aStringRebuildData += astr.str() ;
216 aStringRebuildData += " , 'AttributeName' )\n" ;
217 aStringRebuildData += " aName = anAttr._narrow( SALOMEDS.AttributeName )\n" ;
218 aStringRebuildData += " aName.SetValue( '" ;
219 aStringRebuildData += aStudyObjectName ;
220 aStringRebuildData += "' )\n" ;
223 MESSAGE( "Super_Impl::DumpPython strlen( aStudyObjectName ) == 0 ERROR" ) ;
232 isValidScript = false ;
233 endService( "Super_Impl::DumpPython ERROR" );
234 return new Engines::TMPFile( 0 ) ;
236 aStringRebuildData += " sg.updateObjBrowser( 1 )\n" ;
237 aStringRebuildData += " return 1\n" ;
238 aStringGraph += aStringRebuildData ;
239 int aLen = strlen( aStringGraph.c_str() ) ;
240 CORBA::Octet * anOctetBuffer = (CORBA::Octet * ) aStringGraph.c_str() ;
241 aStreamPythonvar = new Engines::TMPFile ( aLen+1 , aLen+1 , anOctetBuffer ,1 ) ;
242 endService( "Super_Impl::DumpPython" );
243 return aStreamPythonvar._retn() ;
246 // void SuperV_Impl::Save(const char *IORSComponent, const char *aUrlOfFile) {
247 SALOMEDS::TMPFile* SuperV_Impl::Save(SALOMEDS::SComponent_ptr theComponent,
250 SALOMEDS::TMPFile_var aStreamFile;
251 // Get a temporary directory to store a file
252 TCollection_AsciiString aTmpDir("");
253 // Create a list to store names of created files
254 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
256 TCollection_AsciiString myStudyName("");
257 if (isMultiFile) myStudyName = (char*)SALOMEDS_Tool::GetNameFromPath(theComponent->GetStudy()->URL()).c_str();
259 SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
260 TColStd_SequenceOfAsciiString aFileNames;
261 TCollection_AsciiString aName;
263 for(; anIter->More(); anIter->Next()) {
264 SALOMEDS::SObject_var aSO = anIter->Value();
265 SALOMEDS::GenericAttribute_var anAttr;
266 if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
267 aName = myStudyName +
268 TCollection_AsciiString("_SUPERVISION_") +
269 TCollection_AsciiString(aSO->Tag()) +
270 TCollection_AsciiString(".xml");
271 aFileNames.Append(aName);
274 CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
275 SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
276 if (aTmpDir.Length() == 0)
277 aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
278 graph->Export((aTmpDir + aName).ToCString());
282 if (aFileNames.Length() == 0) return new SALOMEDS::TMPFile(0);
284 aSeq->length(aFileNames.Length());
286 for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
287 aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
289 // Conver a file to the byte stream
290 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
291 // Remove the created file and tmp directory
292 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
294 // Add python files to the temporary files sequence
295 SALOMEDS::ListOfFileNames_var aPySeq = new SALOMEDS::ListOfFileNames;
296 aPySeq->length(aSeq->length());
297 for(aCounter = aSeq->length(); aCounter > 0; aCounter--) {
298 char* aCName = CORBA::string_dup(aSeq[aCounter-1]);
299 int a = strlen(aCName);
300 aCName[a-3] = 'p';aCName[a-2] = 'y';aCName[a-1] = 0;
301 aPySeq[aCounter-1] = aCName;
303 // Remove the created file and tmp directory
304 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aPySeq.in(), true);
305 // Return the created byte stream
306 return aStreamFile._retn();
309 SALOMEDS::TMPFile* SuperV_Impl::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
312 SALOMEDS::TMPFile_var aStreamFile = Save(theComponent, theURL, isMultiFile);
313 return aStreamFile._retn();
316 // void SuperV_Impl::Load(const char* IORSComponent, const char* aUrlOfFile) {
317 CORBA::Boolean SuperV_Impl::Load(SALOMEDS::SComponent_ptr theComponent,
318 const SALOMEDS::TMPFile& theStream,
321 // MESSAGE("SuperV_Impl::Load : IOR = " << IORSComponent << " , Url = " << aUrlOfFile);
322 // Get a temporary directory for a file
323 if (theStream.length() != 0) {
324 TCollection_AsciiString aTmpDir = (isMultiFile)?TCollection_AsciiString((char*)theURL):(char*)SALOMEDS_Tool::GetTmpDir().c_str();
325 myStrURL = strdup(aTmpDir.ToCString());
326 SALOMEDS_Tool::PutStreamToFiles(theStream, myStrURL, isMultiFile);
331 CORBA::Boolean SuperV_Impl::LoadASCII(SALOMEDS::SComponent_ptr theComponent,
332 const SALOMEDS::TMPFile& theStream,
335 return Load(theComponent, theStream, theURL, isMultiFile);
338 void SuperV_Impl::Close(SALOMEDS::SComponent_ptr theComponent) {
339 // mpv 06.03.2003: bug SAL1508 - graphs will be destructed at the GUI-level at the supervision frame closing
341 // SALOMEDS::ChildIterator_var anIter = theComponent->GetStudy()->NewChildIterator(theComponent);
342 // for(; anIter->More(); anIter->Next()) {
343 // SALOMEDS::SObject_var aSO = anIter->Value();
344 // SALOMEDS::GenericAttribute_var anAttr;
345 // if (aSO->FindAttribute(anAttr,"AttributeIOR")) {
346 // CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value()) ;
347 // SUPERV::Graph_var graph = SUPERV::Graph::_narrow(anObj);
353 char* SuperV_Impl::ComponentDataType() {
354 return(strdup("SUPERV"));
357 char* SuperV_Impl::IORToLocalPersistentID(SALOMEDS::SObject_ptr theSObject,
358 const char* IORString,
359 CORBA::Boolean isMultiFile,
360 CORBA::Boolean isASCII) {
361 MESSAGE("SuperV_Impl::IORToLocalPersistentID: IOR:"<<IORString);
364 CORBA::Object_var anObj = _orb->string_to_object(IORString) ;
365 if (CORBA::is_nil(anObj)) return CORBA::string_dup(IORString);
366 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
367 if (aGraph->_is_nil()) return CORBA::string_dup(IORString);
369 return CORBA::string_dup(IORString);
372 // sprintf(aName, "%s_SUPERVISION_tmp_%d.xml",myStudyName,myCounter);
373 // CORBA::String_var myStudyName("");
374 // if (isMultiFile) myStudyName = strdup(SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL()));
375 TCollection_AsciiString aName = //TCollection_AsciiString(myStudyName) +
376 TCollection_AsciiString("_SUPERVISION_") +
377 TCollection_AsciiString(theSObject->Tag()) +
378 TCollection_AsciiString(".xml");
379 return CORBA::string_dup(aName.ToCString());
382 char* SuperV_Impl::LocalPersistentIDToIOR(SALOMEDS::SObject_ptr theSObject,
383 const char* aLocalPersistentID,
384 CORBA::Boolean isMultiFile,
385 CORBA::Boolean isASCII)
386 throw(SALOME::SALOME_Exception)
388 MESSAGE("SuperV_Impl::LocalPersistentIDToIOR : IOR = " << aLocalPersistentID);
389 CORBA::String_var aFatherID = theSObject->GetFather()->GetID();
390 CORBA::String_var aComponentID = theSObject->GetFatherComponent()->GetID();
391 if (strcmp(aFatherID, aComponentID)) return CORBA::string_dup(aLocalPersistentID);
393 string myStudyName("");
394 if (isMultiFile) myStudyName = SALOMEDS_Tool::GetNameFromPath(theSObject->GetStudy()->URL());
396 string aStr(myStrURL);
397 aStr += myStudyName + string(aLocalPersistentID);
398 SUPERV::StreamGraph_ptr graph = StreamGraph(aStr.c_str());
400 if (graph->_is_nil())
401 THROW_SALOME_CORBA_EXCEPTION("Unable to find graph in the file",SALOME::BAD_PARAM);
403 // mpv: remove IORs input ports on loading
404 MESSAGE("Remove IORs input ports on loading");
405 SUPERV::ListOfNodes_var aNodes = graph->Nodes();
406 SUPERV::CNode_var aNode;
407 const char* aStrIOR = "";
408 CORBA::Any * anAny = new CORBA::Any();
411 for(i = aNodes->CNodes.length() - 1; i >= 0; i--) {
412 aNode = aNodes->CNodes[i];
413 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
414 for(j = aPorts->length() - 1; j >= 0; j--) {
415 SUPERV::Port_var aPort = aPorts[j];
416 if (aPort->IsIOR()) {
417 aPort->Input(AnyValue(*anAny));
421 for(i = aNodes->FNodes.length() - 1; i >= 0; i--) {
422 aNode = aNodes->FNodes[i];
423 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
424 for(j = aPorts->length() - 1; j >= 0; j--) {
425 SUPERV::Port_var aPort = aPorts[j];
426 if (aPort->IsIOR()) {
427 //CORBA::Any * anAny = new CORBA::Any(CORBA::TypeCode::PR_null_tc(), (void*)NULL, 0) ;
428 aPort->Input(AnyValue(*anAny));
432 for(i = aNodes->INodes.length() - 1; i >= 0; i--) {
433 aNode = aNodes->INodes[i];
434 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
435 for(j = aPorts->length() - 1; j >= 0; j--) {
436 SUPERV::Port_var aPort = aPorts[j];
437 if (aPort->IsIOR()) {
438 aPort->Input(AnyValue(*anAny));
442 for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
443 aNode = aNodes->GNodes[i];
444 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
445 for(j = aPorts->length() - 1; j >= 0; j--) {
446 SUPERV::Port_var aPort = aPorts[j];
447 if (aPort->IsIOR()) {
448 aPort->Input(AnyValue(*anAny));
452 for(i = aNodes->GNodes.length() - 1; i >= 0; i--) {
453 aNode = aNodes->GNodes[i];
454 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
455 for(j = aPorts->length() - 1; j >= 0; j--) {
456 SUPERV::Port_var aPort = aPorts[j];
457 if (aPort->IsIOR()) {
458 aPort->Input(AnyValue(*anAny));
462 for(i = aNodes->LNodes.length() - 1; i >= 0; i--) {
463 aNode = aNodes->LNodes[i];
464 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
465 for(j = aPorts->length() - 1; j >= 0; j--) {
466 SUPERV::Port_var aPort = aPorts[j];
467 if (aPort->IsIOR()) {
468 aPort->Input(AnyValue(*anAny));
472 for(i = aNodes->ELNodes.length() - 1; i >= 0; i--) {
473 aNode = aNodes->ELNodes[i];
474 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
475 for(j = aPorts->length() - 1; j >= 0; j--) {
476 SUPERV::Port_var aPort = aPorts[j];
477 if (aPort->IsIOR()) {
478 aPort->Input(AnyValue(*anAny));
482 for(i = aNodes->SNodes.length() - 1; i >= 0; i--) {
483 aNode = aNodes->SNodes[i];
484 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
485 for(j = aPorts->length() - 1; j >= 0; j--) {
486 SUPERV::Port_var aPort = aPorts[j];
487 if (aPort->IsIOR()) {
488 aPort->Input(AnyValue(*anAny));
492 for(i = aNodes->ESNodes.length() - 1; i >= 0; i--) {
493 aNode = aNodes->ESNodes[i];
494 SUPERV::ListOfPorts_var aPorts = aNode->Ports();
495 for(j = aPorts->length() - 1; j >= 0; j--) {
496 SUPERV::Port_var aPort = aPorts[j];
497 if (aPort->IsIOR()) {
498 aPort->Input(AnyValue(*anAny));
504 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
506 aSeq[0]=aLocalPersistentID;
507 if (!isMultiFile) SALOMEDS_Tool::RemoveTemporaryFiles(myStrURL, aSeq.in(), true);
509 return _Orb->object_to_string(graph);
512 bool SuperV_Impl::CanPublishInStudy(CORBA::Object_ptr theIOR) {
513 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theIOR);
514 return !(aGraph->_is_nil());
517 SALOMEDS::SObject_ptr SuperV_Impl::PublishInStudy(SALOMEDS::Study_ptr theStudy,
518 SALOMEDS::SObject_ptr theSObject,
519 CORBA::Object_ptr theObject,
520 const char* theName) throw (SALOME::SALOME_Exception) {
521 SALOMEDS::SObject_var aResultSO;
523 if(CORBA::is_nil(theObject)) return aResultSO._retn();;
525 if(theStudy->_is_nil()) return aResultSO._retn();;
527 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
528 SALOMEDS::GenericAttribute_var anAttr;
529 SALOMEDS::AttributeName_var aName;
530 SALOMEDS::AttributeIOR_var anIOR;
531 SALOMEDS::AttributePixMap_var aPixmap;
532 SALOMEDS::SComponent_var aFather = theStudy->FindComponent(STUDY_SUPERVISION);
534 if (aFather->_is_nil()) {
535 aFather = aBuilder->NewComponent(STUDY_SUPERVISION);
536 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributeName");
537 aName = SALOMEDS::AttributeName::_narrow(anAttr);
538 //NRI aName->SetValue(STUDY_SUPERVISION);
540 SALOME_NamingService *NamingService = new SALOME_NamingService(_Orb);
541 CORBA::Object_var objVarN = NamingService->Resolve("/Kernel/ModulCatalog");
542 SALOME_ModuleCatalog::ModuleCatalog_var Catalogue = SALOME_ModuleCatalog::ModuleCatalog::_narrow(objVarN);
543 SALOME_ModuleCatalog::Acomponent_var Comp = Catalogue->GetComponent( STUDY_SUPERVISION );
544 if ( !Comp->_is_nil() ) {
545 aName->SetValue( Comp->componentusername() );
547 anAttr = aBuilder->FindOrCreateAttribute(aFather, "AttributePixMap");
548 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
549 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
551 aBuilder->DefineComponentInstance(aFather, SuperG::_this());
554 SALOMEDS::SObject_var dataflowI;
555 SALOMEDS::ChildIterator_var dataflowS = theStudy->NewChildIterator(aFather);
557 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(theObject);
559 const char* name = aGraph->Name();
561 if (CORBA::is_nil(theSObject)) { // if SObject is null, then searching for exist graph SObject
562 for (; dataflowS->More(); dataflowS->Next()) {
563 dataflowI = dataflowS->Value();
564 if (dataflowI->FindAttribute(anAttr, "AttributeName")) {
565 aName = SALOMEDS::AttributeName::_narrow(anAttr);
566 if (strcmp(aName->Value(), name) == 0) {
567 aResultSO = dataflowI;
572 } else { // else searching for referenced SObject
573 if (!theSObject->ReferencedObject(aResultSO))
574 THROW_SALOME_CORBA_EXCEPTION("Publish in study supervision graph error",SALOME::BAD_PARAM);
577 if (strlen(theName) != 0) name = theName;
578 if (CORBA::is_nil(aResultSO)) aResultSO = aBuilder->NewObject(aFather);
580 aName = SALOMEDS::AttributeName::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeName"));
581 aName->SetValue(name);
582 anIOR = SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
583 anIOR->SetValue(aGraph->getIOR());
584 // aBuilder->Addreference(theSObject, aResultSO);
585 return aResultSO._retn();
588 CORBA::Boolean SuperV_Impl::CanCopy(SALOMEDS::SObject_ptr theObject) {
589 // Try to retrieve known by SUPERVISION component Graph by given IOR
590 SALOMEDS::GenericAttribute_var anAttr;
591 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return false;
593 CORBA::Object_var anObj = _orb->string_to_object(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
594 if (CORBA::is_nil(anObj)) return false;
596 SUPERV::Graph_var aGraph = SUPERV::Graph::_narrow(anObj);
597 if (aGraph->_is_nil()) return false;
605 SALOMEDS::TMPFile* SuperV_Impl::CopyFrom(SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) {
606 // Declare a sequence of the byte to store the copied object
607 SALOMEDS::TMPFile_var aStreamFile;
609 // Try to get GEOM_Shape object by given SObject
610 SALOMEDS::GenericAttribute_var anAttr;
611 if (!theObject->FindAttribute(anAttr, "AttributeIOR")) return aStreamFile._retn();
612 CORBA::String_var anIOR = strdup(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value());
615 SUPERV::Graph_var aGraph;
617 CORBA::Object_var anObj = _orb->string_to_object(anIOR) ;
618 if (CORBA::is_nil(anObj)) isGraph = false;
620 aGraph = SUPERV::Graph::_narrow(anObj);
621 if (aGraph->_is_nil()) isGraph = false;
627 if (!isGraph) { // it's just a value, stored in the IOR attribute
628 int aLen = strlen(anIOR);
629 CORBA::Octet* anOctetBuf = (CORBA::Octet*)strdup(anIOR);
630 aStreamFile = SALOMEDS::TMPFile_var(new SALOMEDS::TMPFile(aLen, aLen, anOctetBuf, 1));
631 return aStreamFile._retn();
634 // Get a temporary directory to store a temporary file
635 CORBA::String_var aTmpDir = SALOMEDS_Tool::GetTmpDir().c_str();
636 // Create a list to store names of created files
637 SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
639 aSeq[0] = strdup("_SUPERVISION_tmp.xml");
640 char* aFullName = new char[strlen(aTmpDir)+strlen(aSeq[0])+1];
641 strcpy(aFullName, aTmpDir);
642 strcpy(aFullName+strlen(aTmpDir), aSeq[0]);
643 aGraph->Export(strdup(aFullName));
646 aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.in(), aSeq.in(), false);
647 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.in(), aSeq.in(), true);
649 // Assign an ID = 1 the the type SUPERV::Graph
652 return aStreamFile._retn();
655 CORBA::Boolean SuperV_Impl::CanPaste(const char* theComponentName, CORBA::Long theObjectID) {
656 // The Supervision component can paste only objects copied by Supervision component
657 // and with the object type = 1
658 if (strcmp(theComponentName, ComponentDataType()) != 0 || theObjectID != 1) return false;
662 SALOMEDS::SObject_ptr SuperV_Impl::PasteInto(const SALOMEDS::TMPFile& theStream,
663 CORBA::Long theObjectID,
664 SALOMEDS::SObject_ptr theObject) {
665 SALOMEDS::SObject_var aResultSO;
666 if(CORBA::is_nil(theObject)) return aResultSO._retn();
667 SALOMEDS::StudyBuilder_var aBuilder = theObject->GetStudy()->NewBuilder();
669 aResultSO = SALOMEDS::SObject::_narrow(CORBA::Object::_duplicate(theObject));
671 bool isGraph = (strcmp(theObject->GetFatherComponent()->GetID(),theObject->GetID()) == 0);
675 SALOMEDS::AttributeIOR_var anIOR =
676 SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(theObject, "AttributeIOR"));
677 int aLen = theStream.length();
678 char* aVal = new char[aLen+1];
679 aVal[aLen] = (char)0;
680 memcpy((void*)aVal, (void*)theStream.NP_data(), aLen);
681 anIOR->SetValue(aVal);
682 return aResultSO._retn();
685 TCollection_AsciiString aTmpDir = (char*)SALOMEDS_Tool::GetTmpDir().c_str();
686 SALOMEDS::ListOfFileNames_var aSeq = SALOMEDS_Tool::PutStreamToFiles(theStream, aTmpDir.ToCString(), false);
687 TCollection_AsciiString aFullName;
688 aFullName = aTmpDir+aSeq[0];
689 SUPERV::Graph_var aGraph = Graph(aFullName.ToCString());
691 SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
694 aResultSO = aBuilder->NewObject(theObject);
697 SALOMEDS::AttributeIOR_var anIOR =
698 SALOMEDS::AttributeIOR::_narrow(aBuilder->FindOrCreateAttribute(aResultSO, "AttributeIOR"));
699 anIOR->SetValue(CORBA::string_dup(aGraph->getIOR()));
701 return aResultSO._retn();
704 SUPERV::Value_ptr SuperV_Impl::StringValue( const char * aStrIOR ) {
705 // beginService( "Super_Impl::StringValue" );
706 CORBA::Any * anAny = new CORBA::Any() ;
709 CORBA::Object_ptr obj = _Orb->string_to_object( aStrIOR ) ;
715 catch ( CORBA::BAD_PARAM ) {
717 // JR : objref or string only ==> the eventual convertion to long or double is done in
718 // the SuperVisionEngine with the real type of the argument
722 if ( strchr( aStrIOR , '.' ) != NULL &&
723 sscanf( aStrIOR , "%lf%*n", &d)) {
725 // MESSAGE( "Value( " << aStrIOR << " ) --> double " << d );
728 else if (sscanf( aStrIOR , "%ld%*n", &l)) {
730 // MESSAGE( "Value( " << aStrIOR << " ) --> long " << l );
736 // MESSAGE( "Value( " << aStrIOR << " ) --> string " << aStrIOR );
742 // endService( "SuperV_Impl::StringValue" );
743 return Value( anAny ) ;
746 SUPERV::Value_ptr SuperV_Impl::AnyValue( const CORBA::Any & anAny ) {
747 // beginService( "Super_Impl::AnyValue" );
748 CORBA::Any * aAny = new CORBA::Any( anAny ) ;
749 // endService( "SuperV_Impl::AnyValue" );
750 return Value( aAny ) ;
753 SUPERV::Value_ptr SuperV_Impl::Value( CORBA::Any * anAny ) {
754 // beginService( "Super_Impl::Value" );
755 Value_Impl * myValue = new Value_Impl( _Orb , _Poa , _ContId ,
756 instanceName() , interfaceName() ,
757 NULL , NULL , NULL , anAny , true ) ;
758 PortableServer::ObjectId * id = myValue->getId() ;
759 CORBA::Object_var obj = _poa->id_to_reference(*id);
760 SUPERV::Value_var iobject ;
761 iobject = SUPERV::Value::_narrow(obj) ;
762 // endService( "SuperV_Impl::Value" );
763 return SUPERV::Value::_duplicate( iobject ) ;
766 CORBA::Object_ptr SuperV_Impl::ToObject( CORBA::Object_ptr anObjectRef ) {
767 beginService( "SuperV_Impl::ToObject" );
768 CORBA::Object_ptr anObject ;
769 anObject = CORBA::Object::_duplicate( anObjectRef ) ;
770 endService( "SuperV_Impl::ToObject" );
774 SUPERV::Graph_ptr SuperV_Impl::Graph(const char * aGraphName ) {
775 beginService( "SuperV_Impl::Graph" );
776 bool created = true ;
777 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
778 Graph_Impl * myGraph ;
779 myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() ,
780 aGraphName , SUPERV::DataFlowGraph ) ;
781 int lenname = strlen( aGraphName ) ;
782 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
783 created = myGraph->Import( aGraphName ) ;
786 myGraph->Import( (char * ) NULL ) ;
788 if ( !created && myGraph->IsStreamGraph() ) {
789 MESSAGE( "SuperV_Impl::Graph " << aGraphName << " IsStreamGraph !" ) ;
791 SUPERV::StreamGraph_var streamiobject = StreamGraph( aGraphName ) ;
792 iobject = SUPERV::Graph::_narrow( streamiobject ) ;
793 if ( CORBA::is_nil( iobject ) ) {
797 else if ( created ) {
798 PortableServer::ObjectId * id = myGraph->getId() ;
799 CORBA::Object_var obj = _poa->id_to_reference(*id);
800 iobject = SUPERV::Graph::_narrow(obj) ;
801 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
803 endService( "SuperV_Impl::Graph" );
804 return SUPERV::Graph::_duplicate(iobject) ;
807 SUPERV::Graph_ptr SuperV_Impl::GraphE(const char * aGraphName ) {
808 beginService( "SuperV_Impl::GraphE" );
809 bool created = true ;
810 SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
811 Graph_Impl * myGraph ;
812 myGraph = new Graph_Impl( _Orb , _Poa, _ContId, instanceName() , interfaceName() ,
813 aGraphName , SUPERV::DataFlowGraph ) ;
814 int lenname = strlen( aGraphName ) ;
815 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
816 created = myGraph->Import( aGraphName ) ;
819 myGraph->Import( (char * ) NULL ) ;
821 if ( !created && myGraph->IsStreamGraph() ) {
823 SUPERV::StreamGraph_var streamiobject = StreamGraphE( aGraphName ) ;
824 iobject = SUPERV::Graph::_narrow( streamiobject ) ;
825 if ( CORBA::is_nil( iobject ) ) {
829 else if ( created ) {
830 PortableServer::ObjectId * id = myGraph->getId() ;
831 CORBA::Object_var obj = _poa->id_to_reference(*id);
832 iobject = SUPERV::Graph::_narrow(obj) ;
833 myGraph->SetObjRef( SUPERV::Graph::_duplicate( iobject ) ) ;
835 myGraph->ReadOnly() ;
836 endService( "SuperV_Impl::GraphE" );
837 return SUPERV::Graph::_duplicate(iobject) ;
840 SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraph(const char * aGraphName ) {
841 beginService( "SuperV_Impl::StreamGraph" );
842 bool created = true ;
843 StreamGraph_Impl * myStreamGraph ;
844 myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() ,
845 interfaceName() , aGraphName ) ;
846 int lenname = strlen( aGraphName ) ;
847 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
848 created = myStreamGraph->Import( aGraphName ) ;
851 myStreamGraph->Import( (char * ) NULL ) ;
853 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
855 PortableServer::ObjectId * id = myStreamGraph->getId() ;
856 CORBA::Object_var obj = _poa->id_to_reference(*id);
857 iobject = SUPERV::StreamGraph::_narrow(obj) ;
858 myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ;
860 endService( "SuperV_Impl::StreamGraph" );
861 return SUPERV::StreamGraph::_duplicate(iobject) ;
864 SUPERV::StreamGraph_ptr SuperV_Impl::StreamGraphE(const char * aGraphName ) {
865 beginService( "SuperV_Impl::StreamGraphE" );
866 bool created = true ;
867 StreamGraph_Impl * myStreamGraph ;
868 myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId, instanceName() ,
869 interfaceName() , aGraphName ) ;
870 int lenname = strlen( aGraphName ) ;
871 if ( lenname > 4 && !strcmp( &aGraphName[ lenname - 4 ] , ".xml" ) ) {
872 created = myStreamGraph->Import( aGraphName ) ;
875 myStreamGraph->Import( (char * ) NULL ) ;
877 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil() ;
879 PortableServer::ObjectId * id = myStreamGraph->getId() ;
880 CORBA::Object_var obj = _poa->id_to_reference(*id);
881 iobject = SUPERV::StreamGraph::_narrow(obj) ;
882 myStreamGraph->SetObjRef( SUPERV::StreamGraph::_duplicate( iobject ) ) ;
884 myStreamGraph->ReadOnly() ;
885 endService( "SuperV_Impl::StreamGraphE" );
886 return SUPERV::StreamGraph::_duplicate(iobject) ;
889 SUPERV::Graph_ptr SuperV_Impl::getGraph(const char* ior) {
890 SUPERV::Graph_var iobject = SUPERV::Graph::_nil();
892 CORBA::Object_ptr obj = _Orb->string_to_object(ior);
893 iobject = SUPERV::Graph::_narrow(obj);
895 return SUPERV::Graph::_nil();
896 // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
898 return(SUPERV::Graph::_duplicate(iobject));
901 SUPERV::StreamGraph_ptr SuperV_Impl::getStreamGraph(const char* ior) {
902 SUPERV::StreamGraph_var iobject = SUPERV::StreamGraph::_nil();
904 CORBA::Object_ptr obj = _Orb->string_to_object(ior);
905 iobject = SUPERV::StreamGraph::_narrow(obj);
907 return SUPERV::StreamGraph::_nil();
908 // SUPERV::Graph_var iobject = (SUPERV::Graph_var)NULL;
910 return(SUPERV::StreamGraph::_duplicate(iobject));
913 PortableServer::ObjectId * SUPERVEngine_factory (
915 PortableServer::POA_ptr poa ,
916 PortableServer::ObjectId * contId ,
917 const char *instanceName ,
918 const char *interfaceName
922 MESSAGE("SuperV_factory SuperV ("
923 << instanceName << "," << interfaceName << ")");
924 SuperV_Impl * mySuperV = new SuperV_Impl( orb , poa , contId ,
925 instanceName, interfaceName
928 return mySuperV->getId() ;