1 // SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : DataFlowBase_Node.cxx
8 // Author : Jean Rahuel, CEA
16 #include "DataFlowBase_InLineNode.hxx"
17 #include "DataFlowBase_LoopNode.hxx"
19 static void InitFields( SUPERV::KindOfNode &_Kind ,
20 SUPERV::SDate &_FirstCreation ,
21 SUPERV::SDate &_LastModification ,
22 char * &_EditorRelease ,
26 bool &_GeneratedName ,
27 int &_DataStreamInPortsNumber ,
28 int &_DataStreamOutPortsNumber ,
29 int &_ConnectedInPortsNumber ,
30 int &_DecrConnectedInPortsNumber,
31 int &_LinkedNodesSize ,
32 int &_SubGraphNumber ) {
33 time_t T = time(NULL);
34 struct tm * Tm = localtime(&T);
36 _Kind = SUPERV::DataFlowNode ;
38 _FirstCreation.Second = _LastModification.Second = Tm->tm_sec;
39 _FirstCreation.Minute = _LastModification.Minute = Tm->tm_min;
40 _FirstCreation.Hour = _LastModification.Hour = Tm->tm_hour;
41 _FirstCreation.Day = _LastModification.Day = Tm->tm_mday;
42 _FirstCreation.Month = _LastModification.Month = Tm->tm_mon + 1;
43 _FirstCreation.Year = _LastModification.Year = Tm->tm_year + 1900;
45 _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
46 strcpy( _EditorRelease , SuperVision_Version ) ;
47 _Author = NULLSTRING ;
48 // _Computer = new char[ strlen( FACTORYSERVER ) + 1 ] ;
49 // strcpy( _Computer , FACTORYSERVER ) ;
50 _Comment = NULLSTRING ;
54 _GeneratedName = false ;
56 _DataStreamInPortsNumber = 0 ;
57 _DataStreamOutPortsNumber = 0 ;
59 _ConnectedInPortsNumber = 0 ;
60 _DecrConnectedInPortsNumber = 0 ;
61 _LinkedNodesSize = 0 ;
65 GraphBase::ComputingNode::ComputingNode() :
66 GraphBase::PortsOfNode::PortsOfNode() {
76 _DataStreamInPortsNumber ,
77 _DataStreamOutPortsNumber ,
78 _ConnectedInPortsNumber ,
79 _DecrConnectedInPortsNumber ,
82 _NamingService = NULL ;
83 _Node = SUPERV::CNode::_nil() ;
85 _ThreadNo = pthread_self() ;
87 cdebug << "GraphBase::Node::Node " << this << " " << endl ;
91 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
92 SALOME_NamingService* ptrNamingService ,
93 const char * aDataFlowName ,
94 int * Graph_prof_debug ,
95 ofstream * Graph_fdebug ) :
96 GraphBase::PortsOfNode::PortsOfNode( aDataFlowName ) {
98 MESSAGE( "GraphBase::ComputingNode::ComputingNode( " << aDataFlowName << " Graph_fdebug " << Graph_fdebug ) ;
107 _DataStreamInPortsNumber ,
108 _DataStreamOutPortsNumber ,
109 _ConnectedInPortsNumber ,
110 _DecrConnectedInPortsNumber ,
114 _ORB = CORBA::ORB::_duplicate( ORB ) ;
115 _NamingService = ptrNamingService ;
116 _Node = SUPERV::CNode::_nil() ;
118 _ThreadNo = pthread_self() ;
120 if ( aDataFlowName != NULLSTRING && strlen( aDataFlowName ) ) {
121 _Name = new char[ strlen( aDataFlowName )+1 ] ;
122 strcpy( _Name , aDataFlowName ) ;
127 if ( Graph_prof_debug ) {
128 // MESSAGE( "GraphBase::ComputingNode::ComputingNode --> SetDebug" ) ;
129 // cout << "GraphBase::ComputingNode::ComputingNode --> SetDebug" << endl ;
130 _Graph_prof_debug = Graph_prof_debug ;
131 _Graph_fdebug = Graph_fdebug ;
132 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
135 // cout << "GraphBase::ComputingNode::ComputingNode NO SetDebug" << endl ;
137 cdebug << "GraphBase::ComputingNode::ComputingNode " << this
139 << (void *) _Name << " '" << _Name << " " << _FirstCreation
140 << " " << _LastModification << endl ;
143 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
144 SALOME_NamingService* ptrNamingService ,
145 const SALOME_ModuleCatalog::Service& aService ,
146 const char *NodeName ,
147 const SUPERV::KindOfNode akind ,
148 const SUPERV::SDate NodeFirstCreation ,
149 const SUPERV::SDate NodeLastModification ,
150 const char * NodeEditorRelease ,
151 const char * NodeAuthor ,
152 const char * NodeComment ,
153 const bool GeneratedName ,
156 int * Graph_prof_debug ,
157 ofstream * Graph_fdebug ) :
158 GraphBase::PortsOfNode::PortsOfNode() {
160 _ORB = CORBA::ORB::_duplicate( ORB ) ;
161 _NamingService = ptrNamingService ;
162 _Node = SUPERV::CNode::_nil() ;
164 _ThreadNo = pthread_self() ;
168 time_t T = time(NULL);
169 struct tm * Tm = localtime(&T);
171 _FirstCreation.Second = _LastModification.Second = Tm->tm_sec;
172 _FirstCreation.Minute = _LastModification.Minute = Tm->tm_min;
173 _FirstCreation.Hour = _LastModification.Hour = Tm->tm_hour;
174 _FirstCreation.Day = _LastModification.Day = Tm->tm_mday;
175 _FirstCreation.Month = _LastModification.Month = Tm->tm_mon + 1;
176 _FirstCreation.Year = _LastModification.Year = Tm->tm_year + 1900;
178 if ( NodeEditorRelease != NULLSTRING ) {
179 _EditorRelease = new char[ strlen( NodeEditorRelease ) + 1 ] ;
180 strcpy( _EditorRelease , NodeEditorRelease ) ;
183 _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
184 strcpy( _EditorRelease , SuperVision_Version ) ;
187 if ( NodeAuthor != NULLSTRING ) {
188 _Author = new char[ strlen( NodeAuthor ) + 1 ] ;
189 strcpy( _Author , NodeAuthor ) ;
192 _Author = NULLSTRING ;
195 if ( NodeComment != NULLSTRING ) {
196 _Comment = new char[ strlen( NodeComment ) + 1 ] ;
197 strcpy( _Comment , NodeComment ) ;
200 _Comment = NULLSTRING ;
203 _SubGraphNumber = 0 ;
205 _GeneratedName = GeneratedName ;
207 const char *aNodeName = NodeName ;
208 _Name = new char[strlen(aNodeName)+1];
209 strcpy(_Name , aNodeName);
211 _DataStreamInPortsNumber = 0 ;
212 _DataStreamOutPortsNumber = 0 ;
214 _ConnectedInPortsNumber = 0 ;
215 _DecrConnectedInPortsNumber = 0 ;
216 _LinkedNodesSize = 0 ;
221 // MESSAGE( "GraphBase::ComputingNode::ComputingNode --> SetDebug " << Graph_prof_debug << " Graph_fdebug "
222 // << Graph_fdebug ) ;
223 // cout << "GraphBase::ComputingNode::ComputingNode --> SetDebug " << Graph_prof_debug << " Graph_fdebug "
224 // << Graph_fdebug << endl ;
225 _Graph_prof_debug = Graph_prof_debug ;
226 _Graph_fdebug = Graph_fdebug ;
227 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
228 // MESSAGE( "GraphBase::ComputingNode::ComputingNode SetDebug Done " << Graph_prof_debug << " Graph_fdebug "
229 // << Graph_fdebug << " aService.ServiceName " << aService.ServiceName ) ;
230 // cout << "GraphBase::ComputingNode::ComputingNode SetDebug Done " << Graph_prof_debug << " Graph_fdebug "
231 // << Graph_fdebug << endl ;
232 // cout << "GraphBase::ComputingNode::ComputingNode(" << aService.ServiceName << "," << aNodeName << ","
233 // << akind << ")" << endl;
234 cdebug_in << "GraphBase::ComputingNode::ComputingNode(" << aService.ServiceName << "," << aNodeName << ","
235 << akind << ")" << endl;
238 DefPortsOfNode( ORB , aService , NamePtr() , Kind() , Graph_prof_debug , Graph_fdebug ) ;
240 cdebug << "GraphBase::ComputingNode::ComputingNode " << this
241 << " _Name " << (void *) _Name << " '" << _Name
242 << " KindOfNode " << _Kind
243 << " ServiceName " << ServiceName() << " In(" << ServiceInParameter().length()
244 << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
246 cdebug_out << "GraphBase::ComputingNode::ComputingNode" << endl;
249 GraphBase::ComputingNode::~ComputingNode() {
250 cdebug << "GraphBase::ComputingNode::~ComputingNode " << this
252 << (void *) _Name << " " << _Name << " _Comment "
253 << (void *) _Comment << " " << _Comment << " " << endl ;
254 // if ( _ComponentName != NULLSTRING )
255 // delete [] _ComponentName ;
257 // delete [] _EditorRelease ;
258 // if ( _Author != NULLSTRING )
259 // delete [] _Author ;
260 // if ( _Computer != FACTORYSERVER )
261 // delete [] _Computer;
262 // if ( _Comment != NULLSTRING )
263 // delete [] _Comment;
266 bool GraphBase::ComputingNode::Name( const char * aName) {
267 cdebug_in << "GraphBase::ComputingNode::Name " << _Name << endl;
269 cdebug << "GraphBase::ComputingNode::ReName " << _Name << " --> " << aName << endl ;
272 _Name = new char[strlen(aName)+1] ;
273 strcpy( _Name , aName ) ;
274 cdebug_out << "GraphBase::ComputingNode::Name " << _Name << endl;
278 SUPERV::SDate GraphBase::ComputingNode::FirstCreation () const {
279 // cdebug << "GraphBase::ComputingNode::FirstCreation "
280 // << "' _Name " << _Name << " " << _FirstCreation << " "
281 // << _LastModification << endl ;
282 return _FirstCreation;
285 SUPERV::SDate GraphBase::ComputingNode::LastModification () const {
286 return _LastModification ;
289 bool GraphBase::ComputingNode::Kind(const SUPERV::KindOfNode aKind) {
294 void GraphBase::ComputingNode::FirstCreation(const SUPERV::SDate aDate ) {
295 _FirstCreation = aDate ;
298 void GraphBase::ComputingNode::LastModification(const SUPERV::SDate aDate ) {
299 _LastModification = aDate ;
302 bool GraphBase::ComputingNode::EditorRelease(const char * c){
303 if ( _EditorRelease && _EditorRelease != NULLSTRING )
304 delete _EditorRelease;
305 _EditorRelease = my_strdup(c);
309 bool GraphBase::ComputingNode::Author(const char * a) {
310 cdebug_in << "GraphBase::ComputingNode::Author " << _Author << endl;
311 if ( _Author && _Author != NULLSTRING )
313 _Author = my_strdup(a);
314 cdebug_out << "GraphBase::ComputingNode::Author " << _Author << endl;
318 bool GraphBase::ComputingNode::Comment(const char *c) {
319 cdebug_in << "GraphBase::ComputingNode::Comment " << _Comment << endl;
320 if ( _Comment != NULLSTRING )
322 _Comment = my_strdup(c);
323 cdebug_out << "GraphBase::ComputingNode::Comment " << _Comment << endl;
327 void GraphBase::ComputingNode::NodePort( const char * NodeName ,
328 const char * ServiceParameterName ,
329 char ** aNode , char ** aPort ) {
330 if ( strcmp( NodeName , Name() ) ) {
331 *aNode = my_strdup( NodeName ) ;
332 *aPort = my_strdup( ServiceParameterName ) ;
335 char * BPort = strchr( ServiceParameterName , '\\' ) ;
337 int len = BPort - ServiceParameterName ;
338 *aNode = new char [ len + 1 ] ;
339 strncpy( *aNode , ServiceParameterName , len ) ;
340 (*aNode)[ len ] = '\0' ;
341 *aPort = my_strdup( &BPort[ 1 ] ) ;
344 *aNode = my_strdup( NULLSTRING ) ;
345 *aPort = my_strdup( NULLSTRING ) ;
350 bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
351 bool RetVal = false ;
352 const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
354 RetVal = thePort->IsConnected() ;
357 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
359 RetVal = thePort->IsConnected() ;
365 bool GraphBase::ComputingNode::HasInput(const char * ToServiceParameterName ) {
366 bool RetVal = false ;
367 const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
368 if ( IsDataFlowNode() && thePort ) {
371 else if ( thePort ) {
372 // cout << "GraphBase::ComputingNode::HasInput theInPort " << thePort << " " << thePort->PortName() << " of "
373 // << thePort->NodeName() << " IsDataConnected " << thePort->IsDataConnected() << " OutPort "
374 // << thePort->GetOutPort() << endl ;
375 RetVal = thePort->IsDataConnected() ;
378 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
380 RetVal = thePort->IsDataConnected() ;
386 GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
387 cdebug_in << "GraphBase::ComputingNode::GetInfo" << endl;
388 GraphBase::SNode * Info = new GraphBase::SNode ;
389 // Info->theComponentName = ComponentName() ;
390 // Info->theInterfaceName = InterfaceName() ;
391 Info->theName = Name() ;
392 Info->theKind = Kind() ;
393 Info->theService = *GetService() ;
394 // Info->theListOfParameters = *GetListOfParameters() ;
395 Info->theFirstCreation = FirstCreation() ;
396 Info->theLastModification = LastModification() ;
397 Info->theEditorRelease = EditorRelease() ;
398 Info->theAuthor = Author() ;
399 // Info->theContainer = Computer() ;
400 Info->theComment = Comment() ;
401 Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
402 Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
403 cdebug_out << "GraphBase::ComputingNode::GetInfo" << endl;
407 void GraphBase::ComputingNode::DelInPort( const char * InputParameterName ) {
408 if ( GetChangeInPort( InputParameterName )->IsDataStream() ) {
409 _DataStreamInPortsNumber-- ;
411 GraphBase::PortsOfNode::DelInPort( InputParameterName ) ;
413 void GraphBase::ComputingNode::DelOutPort( const char * OutputParameterName ) {
414 if ( GetChangeOutPort( OutputParameterName )->IsDataStream() ) {
415 _DataStreamOutPortsNumber-- ;
417 GraphBase::PortsOfNode::DelOutPort( OutputParameterName ) ;
420 GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParameterName ,
421 const char * InputParameterType ) {
422 return GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
426 _Graph_prof_debug , _Graph_fdebug ) ;
428 GraphBase::OutPort * GraphBase::ComputingNode::AddOutPort( const char * OutputParameterName ,
429 const char * OutputParameterType ) {
430 return GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
432 OutputParameterName ,
433 OutputParameterType ,
434 _Graph_prof_debug , _Graph_fdebug ) ;
437 void GraphBase::ComputingNode::AddLink( GraphBase::ComputingNode * ToNode ) {
438 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
440 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
441 << " ) new LinkedNode " << endl ;
442 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
443 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
444 _LinkedNodes[ _LinkedNodesSize ] = ToNode ;
445 _LinkedInPortsNumber[ _LinkedNodesSize ] = 1 ;
446 SetLinkedNodeIndex( ToNode->Name() , _LinkedNodesSize ) ;
447 index = _LinkedNodesSize ;
451 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
452 << " ) old LinkedNode " << _LinkedNodes[index ]->Name() << endl ;
453 _LinkedInPortsNumber[ index ] += 1 ;
455 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
456 << " ) LinkedNodesSize " << _LinkedNodesSize << " [ " << index
457 << " ] _LinkedInPortsNumber " << _LinkedInPortsNumber[ index ]
458 << " ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
459 << " + 1 Service " << ServiceName() << endl ;
460 ToNode->IncrConnectedInPortsNumber() ;
463 void GraphBase::ComputingNode::RemoveLink( GraphBase::ComputingNode * ToNode ) {
464 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
466 cdebug << "GraphBase::ComputingNode::RemoveLink( to " << ToNode->Name() << " from "
467 << Name() << " index : " << index << " ConnectedInPortsNumber "
468 << ToNode->ConnectedInPortsNumber() - 1 << " LinkedInPortsNumber "
469 << _LinkedInPortsNumber[ index ] << " - 1" << endl ;
470 ToNode->DecrConnectedInPortsNumber() ;
471 _LinkedInPortsNumber[ index ] -= 1 ;
472 if ( _LinkedInPortsNumber[ index ] == 0 ) {
474 cdebug << "GraphBase::ComputingNode::RemoveLink new LinkedNodesSize "
475 << _LinkedNodesSize << " " << ToNode->Name() << " removed from "
476 << " linkednodes of " << Name() << endl ;
478 for ( i = index ; i < _LinkedNodesSize ; i++ ) {
479 _LinkedNodes[ i ] = _LinkedNodes[ i+1 ] ;
480 _LinkedInPortsNumber[ i ] = _LinkedInPortsNumber[ i+1 ] ;
481 SetLinkedNodeIndex( _LinkedNodes[ i ]->Name() , i ) ;
483 DelLinkedNodeIndex( ToNode->Name() ) ;
484 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
485 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
489 cdebug << " Error index " << index << endl ;
493 void GraphBase::ComputingNode::ReNameLink( const char* OldNodeName ,
494 const char* NewNodeName ) {
495 cdebug_in << "GraphBase::ComputingNode::ReNameLink (" << OldNodeName << " , "
496 << NewNodeName << ")" << endl;
497 int index = GetLinkedNodeIndex( OldNodeName ) ;
499 _MapOfLinkedNodes.erase( OldNodeName ) ;
500 SetLinkedNodeIndex( NewNodeName , index ) ;
502 cdebug_out << "GraphBase::ComputingNode::ReNameLink" << endl ;
505 #include <sys/time.h>
506 #include <sys/resource.h>
509 const long GraphBase::ComputingNode::CpuUsed() {
510 struct rusage usage ;
511 if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
512 perror("GraphBase::CpuUsed") ;
515 // return usage.ru_utime.__time_t tv_sec ;
516 cdebug << "CpuUsed " << usage.ru_utime.tv_sec << " " << usage.ru_utime.tv_usec << " "
517 << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec << endl ;
518 return usage.ru_utime.tv_sec ;
522 const GraphBase::ListOfParameters * GraphBase::ComputingNode::GetListOfParameters() const {
523 GraphBase::ListOfParameters * aListOfParameters = new GraphBase::ListOfParameters ;
524 if ( IsInLineNode() || IsGOTONode() ) {
526 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
527 const InPort * anInPort = GetNodeInPort( i ) ;
528 if ( anInPort->IsBus() ) {
529 int size = aListOfParameters->size() ;
530 aListOfParameters->resize( size + 1 ) ;
531 (*aListOfParameters)[size].theInParameter.Parametername = anInPort->PortName() ;
532 (*aListOfParameters)[size].theInParameter.Parametertype = anInPort->PortType() ;
533 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
534 (*aListOfParameters)[size].theOutParameter.Parametername = anOutPort->PortName() ;
535 (*aListOfParameters)[size].theOutParameter.Parametertype = anOutPort->PortType() ;
539 return aListOfParameters ;
543 bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & info ,
544 const char * ComponentName ,
545 const char * InterfaceName ,
546 const char * Computer ,
547 const char * CoupledNode ,
548 const ListOfFuncName FuncNames ,
549 const ListOfPythonFunctions PythonFunctions ,
550 int XCoordinate , int YCoordinate ) const {
551 cdebug_in << "SaveXML Node " << Name() << endl ;
552 QDomElement node = Graph.createElement( "node" ) ;
553 info.appendChild( node ) ;
554 QDomElement componentname = Graph.createElement( "component-name" ) ;
556 if ( strlen( ComponentName ) ) {
557 // f << Tabs << "<component-name>" << ComponentName << "</component-name>"
559 // componentname.setNodeValue( ComponentName ) ;
560 aField = Graph.createTextNode( ComponentName ) ;
563 // f << Tabs << "<component-name>?</component-name>" << endl ;
564 // componentname.setNodeValue( "?" ) ;
565 aField = Graph.createTextNode( "?" ) ;
567 node.appendChild( componentname ) ;
568 componentname.appendChild( aField ) ;
570 QDomElement interfacename = Graph.createElement("interface-name") ;
571 if ( strlen( InterfaceName ) ) {
572 // f << Tabs << "<interface-name>" << InterfaceName << "</interface-name>"
574 // interfacename.setAttribute("name" , InterfaceName ) ;
575 aField = Graph.createTextNode( InterfaceName ) ;
578 // f << Tabs << "<interface-name>?</interface-name>" << endl ;
579 // interfacename.setAttribute("name" , "?" ) ;
580 aField = Graph.createTextNode( "?" ) ;
582 node.appendChild(interfacename) ;
583 interfacename.appendChild( aField ) ;
585 // f << Tabs << "<node-name>" << Name() << "</node-name>" << endl ;
586 QDomElement nodename = Graph.createElement("node-name") ;
587 aField = Graph.createTextNode( Name() ) ;
588 node.appendChild( nodename ) ;
589 nodename.appendChild( aField ) ;
591 // f << Tabs << "<kind>" << (int ) Kind() << "</kind>" << endl ;
592 QDomElement kind = Graph.createElement( "kind" ) ;
594 aKind = aKind.setNum( Kind() ) ;
595 aField = Graph.createTextNode( aKind ) ;
596 node.appendChild( kind ) ;
597 kind.appendChild( aField ) ;
599 QDomElement couplednode = Graph.createElement("coupled-node") ;
600 if ( IsGOTONode() || IsLoopNode() || IsEndLoopNode() ||
601 IsSwitchNode() || IsEndSwitchNode() ) {
602 // f << Tabs << "<coupled-node>" << CoupledNode << "</coupled-node>"
604 aField = Graph.createTextNode( CoupledNode ) ;
607 // f << Tabs << "<coupled-node>?</coupled-node>" << endl ;
608 aField = Graph.createTextNode( "?" ) ;
610 node.appendChild(couplednode) ;
611 couplednode.appendChild( aField ) ;
613 // f << Tabs << "<service>" << endl ;
614 QDomElement service = Graph.createElement("service") ;
615 node.appendChild(service) ;
616 QDomElement servicename = Graph.createElement("service-name") ;
617 if ( strlen( ServiceName() ) ) {
618 // f << Tabs << " <service-name>" << ServiceName() << "</service-name>" << endl ;
619 aField = Graph.createTextNode( ServiceName() ) ;
622 // f << Tabs << " <service-name>?</service-name>" << endl ;
623 aField = Graph.createTextNode( "?" ) ;
625 service.appendChild(servicename) ;
626 servicename.appendChild( aField ) ;
628 QDomElement inParameterlist = Graph.createElement("inParameter-list") ;
629 service.appendChild(inParameterlist) ;
631 GraphBase::ComputingNode * aNode = (GraphBase::ComputingNode * ) this ;
632 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
633 const GraphBase::InPort * anInPort ;
634 anInPort = aNode->GetInPort( ServiceInParameter()[i].Parametername ) ;
635 if ( !anInPort->IsDataStream() ) {
636 cdebug << "SaveXML " << i << ". " << ServiceInParameter()[i].Parametername
637 << " InParameterPort " << anInPort->Kind() << endl ;
638 QDomElement inParameter = Graph.createElement("inParameter") ;
639 inParameterlist.appendChild(inParameter) ;
640 QDomElement inParametertype = Graph.createElement("inParameter-type") ;
641 if ( strlen( ServiceInParameter()[i].Parametertype ) ) {
642 aField = Graph.createTextNode( strdup( ServiceInParameter()[i].Parametertype ) ) ;
645 aField = Graph.createTextNode( "?" ) ;
647 inParameter.appendChild(inParametertype) ;
648 inParametertype.appendChild( aField ) ;
649 QDomElement inParametername = Graph.createElement("inParameter-name") ;
650 if ( strlen( ServiceInParameter()[i].Parametername ) ) {
651 aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametername) ) ;
654 aField = Graph.createTextNode( "?" ) ;
656 inParameter.appendChild(inParametername) ;
657 inParametername.appendChild( aField ) ;
660 QDomElement outParameterlist = Graph.createElement("outParameter-list") ;
661 service.appendChild(outParameterlist) ;
662 for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
663 const GraphBase::OutPort * anOutPort ;
664 anOutPort = aNode->GetOutPort( ServiceOutParameter()[i].Parametername ) ;
665 if ( !anOutPort->IsDataStream() ) {
666 cdebug << "SaveXML " << i << ". " << ServiceOutParameter()[i].Parametername
667 << " OutParameterPort " << anOutPort->Kind() << endl ;
668 QDomElement outParameter = Graph.createElement("outParameter") ;
669 outParameterlist.appendChild(outParameter) ;
670 QDomElement outParametertype = Graph.createElement("outParameter-type") ;
671 if ( strlen( ServiceOutParameter()[i].Parametertype ) ) {
672 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametertype) ) ;
675 aField = Graph.createTextNode( "?" ) ;
677 outParameter.appendChild(outParametertype) ;
678 outParametertype.appendChild( aField ) ;
679 QDomElement outParametername = Graph.createElement("outParameter-name") ;
680 if ( strlen( ServiceOutParameter()[i].Parametername ) ) {
681 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametername) ) ;
684 aField = Graph.createTextNode( "?" ) ;
686 outParameter.appendChild(outParametername) ;
687 outParametername.appendChild( aField ) ;
691 QDomElement DataStreamlist = Graph.createElement("DataStream-list") ;
692 node.appendChild( DataStreamlist ) ;
693 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
694 const GraphBase::InPort * anInPort ;
695 anInPort = aNode->GetInPort( ServiceInParameter()[i].Parametername ) ;
696 if ( anInPort->IsDataStream() ) {
697 cdebug << "SaveXML " << ServiceInParameter()[i].Parametername
698 << " InDataStreamPort " << anInPort->Kind() << endl ;
699 QDomElement inParameter = Graph.createElement("inParameter") ;
700 DataStreamlist.appendChild(inParameter) ;
701 QDomElement inParametertype = Graph.createElement("inParameter-type") ;
702 if ( strlen( ServiceInParameter()[i].Parametertype ) ) {
703 aField = Graph.createTextNode( strdup( ServiceInParameter()[i].Parametertype ) ) ;
706 aField = Graph.createTextNode( "?" ) ;
708 inParameter.appendChild(inParametertype) ;
709 inParametertype.appendChild( aField ) ;
710 QDomElement inParametername = Graph.createElement("inParameter-name") ;
711 if ( strlen( ServiceInParameter()[i].Parametername ) ) {
712 aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametername) ) ;
715 aField = Graph.createTextNode( "?" ) ;
717 inParameter.appendChild(inParametername) ;
718 inParametername.appendChild( aField ) ;
721 for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
722 const GraphBase::OutPort * anOutPort ;
723 anOutPort = aNode->GetOutPort( ServiceOutParameter()[i].Parametername ) ;
724 if ( anOutPort->IsDataStream() ) {
725 cdebug << "SaveXML " << ServiceOutParameter()[i].Parametername
726 << " OutDataStreamPort " << anOutPort->Kind() << endl ;
727 QDomElement outParameter = Graph.createElement("outParameter") ;
728 DataStreamlist.appendChild(outParameter) ;
729 QDomElement outParametertype = Graph.createElement("outParameter-type") ;
730 if ( strlen( ServiceOutParameter()[i].Parametertype ) ) {
731 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametertype) ) ;
734 aField = Graph.createTextNode( "?" ) ;
736 outParameter.appendChild(outParametertype) ;
737 outParametertype.appendChild( aField ) ;
738 QDomElement outParametername = Graph.createElement("outParameter-name") ;
739 if ( strlen( ServiceOutParameter()[i].Parametername ) ) {
740 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametername) ) ;
743 aField = Graph.createTextNode( "?" ) ;
745 outParameter.appendChild(outParametername) ;
746 outParametername.appendChild( aField ) ;
749 // f << Tabs << "</Parameter-list>" << endl ;
751 // f << Tabs << "<PyFunction-list>" << endl ;
752 QDomElement PyFunctionlist = Graph.createElement("PyFunction-list") ;
753 node.appendChild( PyFunctionlist ) ;
754 for ( i = 0 ; i < PythonFunctions.size() ; i++ ) {
755 // f << Tabs << " <PyFunction>" << endl ;
756 QDomElement PyFunction = Graph.createElement("PyFunction") ;
757 PyFunctionlist.appendChild( PyFunction ) ;
759 QDomElement FuncName = Graph.createElement("FuncName") ;
760 if ( strlen( FuncNames[i].c_str() ) ) {
761 aField = Graph.createTextNode( FuncNames[i].c_str() ) ;
764 aField = Graph.createTextNode( "?" ) ;
766 PyFunction.appendChild( FuncName ) ;
767 FuncName.appendChild( aField ) ;
768 if ( (*PythonFunctions[i]).length() ) {
769 for ( j = 0 ; j < (int ) (*PythonFunctions[i]).length() ; j++ ) {
770 QDomElement PyFunc = Graph.createElement("PyFunc") ;
771 QDomCDATASection aCDATA ;
772 // mpv: Linux 8.0 compiler compatibility
773 char * aCDATAChar = strdup ((*PythonFunctions[i])[j]) ;
775 for ( i = 0 ; i < (int ) strlen( aCDATAChar ) ; i++ ) {
776 if ( aCDATAChar[ i ] != ' ' ) {
780 if ( i == (int ) strlen( aCDATAChar ) ) {
781 aCDATA = Graph.createCDATASection( "?" ) ;
784 aCDATA = Graph.createCDATASection( aCDATAChar ) ;
786 PyFunction.appendChild( PyFunc ) ;
787 PyFunc.appendChild( aCDATA ) ;
791 QDomElement PyFunc = Graph.createElement("PyFunc") ;
792 QDomCDATASection aCDATA = Graph.createCDATASection( "?" ) ;
793 PyFunction.appendChild( PyFunc ) ;
794 PyFunc.appendChild( aCDATA ) ;
798 // f << Tabs << "<creation-date>" << FirstCreation() << "</creation-date>"
800 QDomElement creationdate = Graph.createElement("creation-date") ;
802 sprintf( fdate , "%d/%d/%d - %d:%d:%d" , FirstCreation().Day , FirstCreation().Month , FirstCreation().Year , FirstCreation().Hour , FirstCreation().Minute , FirstCreation().Second ) ;
803 aField = Graph.createTextNode( fdate ) ;
804 node.appendChild( creationdate ) ;
805 creationdate.appendChild( aField ) ;
806 // f << Tabs << "<lastmodification-date>" << LastModification()
807 // << "</lastmodification-date>" << endl ;
808 QDomElement lastmodificationdate = Graph.createElement("lastmodification-date") ;
810 sprintf( ldate , "%d/%d/%d - %d:%d:%d" , LastModification().Day , LastModification().Month , LastModification().Year , LastModification().Hour , LastModification().Minute , LastModification().Second ) ;
811 aField = Graph.createTextNode( ldate ) ;
812 node.appendChild( lastmodificationdate ) ;
813 lastmodificationdate.appendChild( aField ) ;
814 // f << Tabs << "<editor-release>" << EditorRelease() << "</editor-release>"
816 QDomElement editorrelease = Graph.createElement("editor-release") ;
817 aField = Graph.createTextNode( EditorRelease() ) ;
818 node.appendChild( editorrelease ) ;
819 editorrelease.appendChild( aField ) ;
820 QDomElement author = Graph.createElement("author") ;
821 if ( strlen( Author() ) ) {
822 // f << Tabs << "<author>" << Author() << "</author>" << endl ;
823 aField = Graph.createTextNode( Author() ) ;
826 // f << Tabs << "<author>?</author>" << endl ;
827 aField = Graph.createTextNode( "?" ) ;
829 node.appendChild( author ) ;
830 author.appendChild( aField ) ;
831 QDomElement container = Graph.createElement("container") ;
832 if ( IsFactoryNode() && strlen( Computer) ) {
833 // f << Tabs << "<container>" << Computer << "</container>" << endl ;
834 aField = Graph.createTextNode( Computer ) ;
837 // f << Tabs << "<container>?</container>" << endl ;
838 aField = Graph.createTextNode( "?" ) ;
840 node.appendChild( container ) ;
841 container.appendChild( aField ) ;
842 QDomElement comment = Graph.createElement("comment") ;
843 if ( strlen( Comment() ) ) {
844 // f << Tabs << "<comment>" << Comment() << "</comment>" << endl ;
845 aField = Graph.createTextNode( Comment() ) ;
848 // f << Tabs << "<comment>?</comment>" << endl ;
849 aField = Graph.createTextNode( "?" ) ;
851 node.appendChild( comment ) ;
852 comment.appendChild( aField ) ;
853 // f << Tabs << "<x-position>" << XCoordinate << "</x-position>" << endl ;
854 QDomElement xposition = Graph.createElement("x-position") ;
855 QString aXCoordinate ;
856 aXCoordinate = aKind.setNum( XCoordinate ) ;
857 aField = Graph.createTextNode( aXCoordinate ) ;
858 node.appendChild( xposition ) ;
859 xposition.appendChild( aField ) ;
860 // f << Tabs << "<y-position>" << YCoordinate << "</y-position>" << endl ;
861 QDomElement yposition = Graph.createElement("y-position") ;
862 QString aYCoordinate ;
863 aYCoordinate = aKind.setNum( YCoordinate ) ;
864 aField = Graph.createTextNode( aYCoordinate ) ;
865 node.appendChild( yposition ) ;
866 yposition.appendChild( aField ) ;
867 cdebug_out << "SaveXML Node " << Name() << endl ;
871 bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
872 const char * ComponentName ,
873 const char * InterfaceName ,
874 const char * Computer ,
875 const GraphBase::InLineNode * aCoupledNode ,
876 const ListOfFuncName FuncNames ,
877 const ListOfPythonFunctions PythonFunctions ,
878 int XCoordinate , int YCoordinate ) const {
879 if ( IsDataFlowNode() ) {
880 f << Name() << " = Graph( '" << Name() << "' )" << endl ;
882 else if ( IsComputingNode() ) {
884 f << Name() << "_ServiceinParameter = []" << endl ;
885 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
886 f << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
887 << ServiceInParameter()[i].Parametertype << "' , '"
888 << ServiceInParameter()[i].Parametername << "' ) )" << endl ;
890 f << Name() << "_ServiceoutParameter = []" << endl ;
891 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
892 f << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
893 << ServiceOutParameter()[i].Parametertype << "' , '"
894 << ServiceOutParameter()[i].Parametername << "' ) )" << endl ;
896 f << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
897 << "' , " << Name() << "_ServiceinParameter" << " , "
898 << Name() << "_ServiceoutParameter" << " , 0 )" << endl ;
899 f << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
902 else if ( IsFactoryNode() ) {
903 f << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
904 << "' , '" << InterfaceName << "' , '" << ServiceName() << "' )"
908 f << "Py" << Name() << " = []" << endl ;
910 SUPERV::ListOfStrings aPyFunc ;
911 if ( PythonFunctions.size() ) {
912 aPyFunc = *PythonFunctions[0] ;
913 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
914 f << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
917 if ( IsInLineNode() ) {
918 f << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
919 << Name() << " )" << endl ;
921 else if ( IsGOTONode() ) {
922 if ( aCoupledNode ) {
923 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
924 << Name() << " , '" << aCoupledNode->Name() << "' )" << endl ;
927 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
928 << Name() << " , '' )" << endl ;
932 // char * EndName = NULL ;
933 // EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
934 // strcpy( EndName , "End" ) ;
935 // strcat( EndName , Name() ) ;
936 char * EndName = aCoupledNode->Name() ;
937 if ( IsLoopNode() ) {
938 SUPERV::ListOfStrings aPyMore = *PythonFunctions[1] ;
939 SUPERV::ListOfStrings aPyNext = *PythonFunctions[2] ;
940 f << "PyMore" << Name() << " = []" << endl ;
941 for ( i = 0 ; i < (int ) aPyMore.length() ; i++ ) {
942 f << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
944 f << "PyNext" << Name() << " = []" << endl ;
945 for ( i = 0 ; i < (int ) aPyNext.length() ; i++ ) {
946 f << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
948 f << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
949 << FuncNames[0].c_str() << "' , Py" << Name() << " , '"
950 << FuncNames[1].c_str() << "' , PyMore" << Name()
951 << " , '" << FuncNames[2].c_str() << "' , PyNext"
952 << Name() << " )" << endl ;
953 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
954 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
955 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
956 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
957 << aCoupledNode->YCoordinate() << " )" << endl ;
958 SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
959 f << "Py" << aCoupledNode->Name() << " = []" << endl ;
960 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
961 f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
964 f << EndName << ".SetPyFunction( 'End" << FuncNames[0].c_str() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
966 else if ( IsSwitchNode() ) {
967 f << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
968 << FuncNames[0].c_str() << "' , Py" << Name() << " )" << endl ;
969 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
970 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
971 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
972 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
973 << aCoupledNode->YCoordinate() << " )" << endl ;
974 SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
975 f << "Py" << aCoupledNode->Name() << " = []" << endl ;
976 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
977 f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
980 f << EndName << ".SetPyFunction( 'End" << FuncNames[0].c_str() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
981 for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
982 const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
983 if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
984 f << EndName << ".InPort( '" << anInPort->PortName()
985 << "' , '" << anInPort->PortType() << "' )" << endl ;
988 for ( i = 0 ; i < aCoupledNode->GetNodeOutPortsSize() ; i++ ) {
989 const GraphBase::OutPort * anOutPort = aCoupledNode->GetNodeOutPort(i) ;
990 if ( anOutPort->IsInLine() ) {
991 f << EndName << ".OutPort( '" << anOutPort->PortName()
992 << "' , '" << anOutPort->PortType() << "' )" << endl ;
1000 f << Name() << ".SetName( '" << Name() << "' )" << endl ;
1001 f << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
1002 if ( IsFactoryNode() ) {
1003 f << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
1005 f << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
1006 f << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
1008 if ( IsOneOfInLineNodes() ) {
1010 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1011 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1012 if ( anInPort->IsInLine() ) {
1013 f << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
1014 << anInPort->PortType() << "' )" << endl ;
1017 // for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1018 // const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
1019 // if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
1020 // f << Name() << ".OutPort( '" << anOutPort->PortName()
1021 // << "' , '" << anOutPort->PortType() << "' )" << endl ;
1025 if ( !IsDataFlowNode() ) {
1027 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1028 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
1029 if ( anInPort->IsDataStream() ) {
1030 f << Name() << ".InDataStreamPort( '" << anInPort->PortName() << "' , '"
1031 << anInPort->PortType() << "' )" << endl ;
1034 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1035 const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
1036 if ( anOutPort->IsDataStream() ) {
1037 f << Name() << ".OutDataStreamPort( '" << anOutPort->PortName()
1038 << "' , '" << anOutPort->PortType() << "' )" << endl ;
1044 if ( IsLoopNode() || IsSwitchNode() ) {
1045 f << EndName << ".SetName( '" << CoupledNode
1047 f << EndName << ".SetAuthor( '" << CoupledNode->Author()
1049 f << EndName << ".SetComment( '" << CoupledNode->Comment()
1051 f << EndName << ".Coords( " << CoupledNode->XCoordinate() << " , "
1052 << CoupledNode->YCoordinate() << " )" << endl ;
1054 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1055 const InPort * anInPort = GetNodeInPort( i ) ;
1056 if ( anInPort->IsBus() ) {
1057 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
1058 f << Name() << ".BusPorts( '" << anInPort->PortName() << "' , '"
1059 << anInPort->PortType() << "' , '" << anOutPort->PortName()
1060 << "' , '" << anOutPort->PortType() << "' )" << endl ;
1068 void GraphBase::ComputingNode::NodeInfo(ostream & s) const {
1070 ListPorts( s , true ) ;
1074 ostream & operator<< (ostream & f,const GraphBase::ComputingNode & G) {
1075 // f << "ComponentName " << G.ComponentName() << endl ;
1076 if ( G.IsComputingNode() )
1077 f << "NodeName " << G.Name() << endl ;
1079 f << "DataFlowName " << G.Name() << endl ;
1080 f << "Kind " << G.Kind() << endl ;
1081 f << "Service " << *G.GetService() ;
1082 f << "FirstCreation " << G.FirstCreation () << endl ;
1083 f << "LastModification " << G.LastModification() << endl ;
1084 f << "EditorRelease " << G.EditorRelease() << endl ;
1085 f << "Author " << G.Author() << endl ;
1086 // f << "Computer " << G.Computer() << endl ;
1087 f << "Comment " << G.Comment() << endl ;
1093 void GraphBase::ComputingNode::ListLinks(ostream &f ) const {
1095 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1096 const GraphBase::OutPort* fromPort = GetNodeOutPort( i ) ;
1097 if ( fromPort->IsPortConnected() ) {
1099 for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
1101 f << "FromNode " << Name() << endl ;
1102 f << " FromServiceParameterName "
1103 << fromPort->GetServicesParameter().Parametername ;
1104 const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
1105 f << " ToNode " << toPort->NodeName() ;
1106 f << " ToServiceParameterName "
1107 << toPort->GetServicesParameter().Parametername;
1109 fromPort->StringValue( f ) ;
1116 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D) {
1117 // cdebug_in << "operator<< GraphEditor::Date" << endl;
1119 fOut << D.Day << "/"
1126 // cdebug_out << "operator<< GraphEditor::Date" << endl;