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 &_ConnectedInPortsNumber ,
28 int &_DecrConnectedInPortsNumber,
29 int &_LinkedNodesSize ,
30 int &_SubGraphNumber ) {
31 time_t T = time(NULL);
32 struct tm * Tm = localtime(&T);
34 _Kind = SUPERV::DataFlowNode ;
36 _FirstCreation.Second = _LastModification.Second = Tm->tm_sec;
37 _FirstCreation.Minute = _LastModification.Minute = Tm->tm_min;
38 _FirstCreation.Hour = _LastModification.Hour = Tm->tm_hour;
39 _FirstCreation.Day = _LastModification.Day = Tm->tm_mday;
40 _FirstCreation.Month = _LastModification.Month = Tm->tm_mon + 1;
41 _FirstCreation.Year = _LastModification.Year = Tm->tm_year + 1900;
43 _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
44 strcpy( _EditorRelease , SuperVision_Version ) ;
45 _Author = NULLSTRING ;
46 // _Computer = new char[ strlen( FACTORYSERVER ) + 1 ] ;
47 // strcpy( _Computer , FACTORYSERVER ) ;
48 _Comment = NULLSTRING ;
52 _GeneratedName = false ;
54 _ConnectedInPortsNumber = 0 ;
55 _DecrConnectedInPortsNumber = 0 ;
56 _LinkedNodesSize = 0 ;
60 GraphBase::ComputingNode::ComputingNode() :
61 GraphBase::PortsOfNode::PortsOfNode() {
71 _ConnectedInPortsNumber ,
72 _DecrConnectedInPortsNumber ,
75 _NamingService = NULL ;
76 _Node = SUPERV::CNode::_nil() ;
78 _ThreadNo = pthread_self() ;
80 cdebug << "GraphBase::Node::Node " << this << " " << endl ;
84 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
85 SALOME_NamingService* ptrNamingService ,
86 const char * aDataFlowName ,
87 int * Graph_prof_debug ,
88 ofstream * Graph_fdebug ) :
89 GraphBase::PortsOfNode::PortsOfNode( aDataFlowName ) {
91 MESSAGE( "GraphBase::ComputingNode::ComputingNode( " << aDataFlowName << " Graph_fdebug " << Graph_fdebug ) ;
100 _ConnectedInPortsNumber ,
101 _DecrConnectedInPortsNumber ,
105 _ORB = CORBA::ORB::_duplicate( ORB ) ;
106 _NamingService = ptrNamingService ;
107 _Node = SUPERV::CNode::_nil() ;
109 _ThreadNo = pthread_self() ;
111 if ( aDataFlowName != NULLSTRING && strlen( aDataFlowName ) ) {
112 _Name = new char[ strlen( aDataFlowName )+1 ] ;
113 strcpy( _Name , aDataFlowName ) ;
118 if ( Graph_prof_debug ) {
119 // MESSAGE( "GraphBase::ComputingNode::ComputingNode --> SetDebug" ) ;
120 // cout << "GraphBase::ComputingNode::ComputingNode --> SetDebug" << endl ;
121 _Graph_prof_debug = Graph_prof_debug ;
122 _Graph_fdebug = Graph_fdebug ;
123 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
126 // cout << "GraphBase::ComputingNode::ComputingNode NO SetDebug" << endl ;
128 cdebug << "GraphBase::ComputingNode::ComputingNode " << this
130 << (void *) _Name << " '" << _Name << " " << _FirstCreation
131 << " " << _LastModification << endl ;
134 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
135 SALOME_NamingService* ptrNamingService ,
136 const SALOME_ModuleCatalog::Service& aService ,
137 const char *NodeName ,
138 const SUPERV::KindOfNode akind ,
139 const SUPERV::SDate NodeFirstCreation ,
140 const SUPERV::SDate NodeLastModification ,
141 const char * NodeEditorRelease ,
142 const char * NodeAuthor ,
143 const char * NodeComment ,
144 const bool GeneratedName ,
147 int * Graph_prof_debug ,
148 ofstream * Graph_fdebug ) :
149 GraphBase::PortsOfNode::PortsOfNode() {
151 _ORB = CORBA::ORB::_duplicate( ORB ) ;
152 _NamingService = ptrNamingService ;
153 _Node = SUPERV::CNode::_nil() ;
155 _ThreadNo = pthread_self() ;
159 time_t T = time(NULL);
160 struct tm * Tm = localtime(&T);
162 _FirstCreation.Second = _LastModification.Second = Tm->tm_sec;
163 _FirstCreation.Minute = _LastModification.Minute = Tm->tm_min;
164 _FirstCreation.Hour = _LastModification.Hour = Tm->tm_hour;
165 _FirstCreation.Day = _LastModification.Day = Tm->tm_mday;
166 _FirstCreation.Month = _LastModification.Month = Tm->tm_mon + 1;
167 _FirstCreation.Year = _LastModification.Year = Tm->tm_year + 1900;
169 if ( NodeEditorRelease != NULLSTRING ) {
170 _EditorRelease = new char[ strlen( NodeEditorRelease ) + 1 ] ;
171 strcpy( _EditorRelease , NodeEditorRelease ) ;
174 _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
175 strcpy( _EditorRelease , SuperVision_Version ) ;
178 if ( NodeAuthor != NULLSTRING ) {
179 _Author = new char[ strlen( NodeAuthor ) + 1 ] ;
180 strcpy( _Author , NodeAuthor ) ;
183 _Author = NULLSTRING ;
186 if ( NodeComment != NULLSTRING ) {
187 _Comment = new char[ strlen( NodeComment ) + 1 ] ;
188 strcpy( _Comment , NodeComment ) ;
191 _Comment = NULLSTRING ;
194 _SubGraphNumber = 0 ;
196 _GeneratedName = GeneratedName ;
198 const char *aNodeName = NodeName ;
199 _Name = new char[strlen(aNodeName)+1];
200 strcpy(_Name , aNodeName);
202 _ConnectedInPortsNumber = 0 ;
203 _DecrConnectedInPortsNumber = 0 ;
204 _LinkedNodesSize = 0 ;
209 // MESSAGE( "GraphBase::ComputingNode::ComputingNode --> SetDebug " << Graph_prof_debug << " Graph_fdebug "
210 // << Graph_fdebug ) ;
211 // cout << "GraphBase::ComputingNode::ComputingNode --> SetDebug " << Graph_prof_debug << " Graph_fdebug "
212 // << Graph_fdebug << endl ;
213 _Graph_prof_debug = Graph_prof_debug ;
214 _Graph_fdebug = Graph_fdebug ;
215 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
216 // MESSAGE( "GraphBase::ComputingNode::ComputingNode SetDebug Done " << Graph_prof_debug << " Graph_fdebug "
217 // << Graph_fdebug << " aService.ServiceName " << aService.ServiceName ) ;
218 // cout << "GraphBase::ComputingNode::ComputingNode SetDebug Done " << Graph_prof_debug << " Graph_fdebug "
219 // << Graph_fdebug << endl ;
220 // cout << "GraphBase::ComputingNode::ComputingNode(" << aService.ServiceName << "," << aNodeName << ","
221 // << akind << ")" << endl;
222 cdebug_in << "GraphBase::ComputingNode::ComputingNode(" << aService.ServiceName << "," << aNodeName << ","
223 << akind << ")" << endl;
226 DefPortsOfNode( ORB , aService , NamePtr() , Kind() , Graph_prof_debug , Graph_fdebug ) ;
228 cdebug << "GraphBase::ComputingNode::ComputingNode " << this
229 << " _Name " << (void *) _Name << " '" << _Name
230 << " KindOfNode " << _Kind
231 << " ServiceName " << ServiceName() << " In(" << ServiceInParameter().length()
232 << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
234 cdebug_out << "GraphBase::ComputingNode::ComputingNode" << endl;
237 GraphBase::ComputingNode::~ComputingNode() {
238 cdebug << "GraphBase::ComputingNode::~ComputingNode " << this
240 << (void *) _Name << " " << _Name << " _Comment "
241 << (void *) _Comment << " " << _Comment << " " << endl ;
242 // if ( _ComponentName != NULLSTRING )
243 // delete [] _ComponentName ;
245 // delete [] _EditorRelease ;
246 // if ( _Author != NULLSTRING )
247 // delete [] _Author ;
248 // if ( _Computer != FACTORYSERVER )
249 // delete [] _Computer;
250 // if ( _Comment != NULLSTRING )
251 // delete [] _Comment;
254 bool GraphBase::ComputingNode::Name( const char * aName) {
255 cdebug_in << "GraphBase::ComputingNode::Name " << _Name << endl;
257 cdebug << "GraphBase::ComputingNode::ReName " << _Name << " --> " << aName << endl ;
260 _Name = new char[strlen(aName)+1] ;
261 strcpy( _Name , aName ) ;
262 cdebug_out << "GraphBase::ComputingNode::Name " << _Name << endl;
266 SUPERV::SDate GraphBase::ComputingNode::FirstCreation () const {
267 // cdebug << "GraphBase::ComputingNode::FirstCreation "
268 // << "' _Name " << _Name << " " << _FirstCreation << " "
269 // << _LastModification << endl ;
270 return _FirstCreation;
273 SUPERV::SDate GraphBase::ComputingNode::LastModification () const {
274 return _LastModification ;
277 bool GraphBase::ComputingNode::Kind(const SUPERV::KindOfNode aKind) {
282 void GraphBase::ComputingNode::FirstCreation(const SUPERV::SDate aDate ) {
283 _FirstCreation = aDate ;
286 void GraphBase::ComputingNode::LastModification(const SUPERV::SDate aDate ) {
287 _LastModification = aDate ;
290 bool GraphBase::ComputingNode::EditorRelease(const char * c){
291 if ( _EditorRelease && _EditorRelease != NULLSTRING )
292 delete _EditorRelease;
293 _EditorRelease = my_strdup(c);
297 bool GraphBase::ComputingNode::Author(const char * a) {
298 cdebug_in << "GraphBase::ComputingNode::Author " << _Author << endl;
299 if ( _Author && _Author != NULLSTRING )
301 _Author = my_strdup(a);
302 cdebug_out << "GraphBase::ComputingNode::Author " << _Author << endl;
306 bool GraphBase::ComputingNode::Comment(const char *c) {
307 cdebug_in << "GraphBase::ComputingNode::Comment " << _Comment << endl;
308 if ( _Comment != NULLSTRING )
310 _Comment = my_strdup(c);
311 cdebug_out << "GraphBase::ComputingNode::Comment " << _Comment << endl;
315 void GraphBase::ComputingNode::NodePort( const char * NodeName ,
316 const char * ServiceParameterName ,
317 char ** aNode , char ** aPort ) {
318 if ( strcmp( NodeName , Name() ) ) {
319 *aNode = my_strdup( NodeName ) ;
320 *aPort = my_strdup( ServiceParameterName ) ;
323 char * BPort = strchr( ServiceParameterName , '\\' ) ;
325 int len = BPort - ServiceParameterName ;
326 *aNode = new char [ len + 1 ] ;
327 strncpy( *aNode , ServiceParameterName , len ) ;
328 (*aNode)[ len ] = '\0' ;
329 *aPort = my_strdup( &BPort[ 1 ] ) ;
332 *aNode = my_strdup( NULLSTRING ) ;
333 *aPort = my_strdup( NULLSTRING ) ;
338 bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
339 bool RetVal = false ;
340 const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
342 RetVal = thePort->IsConnected() ;
345 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
347 RetVal = thePort->IsConnected() ;
353 bool GraphBase::ComputingNode::HasInput(const char * ToServiceParameterName ) {
354 bool RetVal = false ;
355 const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
356 if ( IsDataFlowNode() && thePort ) {
359 else if ( thePort ) {
360 RetVal = thePort->IsDataConnected() ;
363 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
365 RetVal = thePort->IsDataConnected() ;
371 GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
372 cdebug_in << "GraphBase::ComputingNode::GetInfo" << endl;
373 GraphBase::SNode * Info = new GraphBase::SNode ;
374 // Info->theComponentName = ComponentName() ;
375 // Info->theInterfaceName = InterfaceName() ;
376 Info->theName = Name() ;
377 Info->theKind = Kind() ;
378 Info->theService = *GetService() ;
379 // Info->theListOfParameters = *GetListOfParameters() ;
380 Info->theFirstCreation = FirstCreation() ;
381 Info->theLastModification = LastModification() ;
382 Info->theEditorRelease = EditorRelease() ;
383 Info->theAuthor = Author() ;
384 // Info->theContainer = Computer() ;
385 Info->theComment = Comment() ;
386 Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
387 Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
388 cdebug_out << "GraphBase::ComputingNode::GetInfo" << endl;
392 GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParameterName ,
393 const char * InputParameterType ) {
394 return GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
398 _Graph_prof_debug , _Graph_fdebug ) ;
400 GraphBase::OutPort * GraphBase::ComputingNode::AddOutPort( const char * OutputParameterName ,
401 const char * OutputParameterType ) {
402 return GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
404 OutputParameterName ,
405 OutputParameterType ,
406 _Graph_prof_debug , _Graph_fdebug ) ;
409 void GraphBase::ComputingNode::AddLink( GraphBase::ComputingNode * ToNode ) {
410 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
412 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
413 << " ) new LinkedNode " << endl ;
414 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
415 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
416 _LinkedNodes[ _LinkedNodesSize ] = ToNode ;
417 _LinkedInPortsNumber[ _LinkedNodesSize ] = 1 ;
418 SetLinkedNodeIndex( ToNode->Name() , _LinkedNodesSize ) ;
419 index = _LinkedNodesSize ;
423 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
424 << " ) old LinkedNode " << _LinkedNodes[index ]->Name() << endl ;
425 _LinkedInPortsNumber[ index ] += 1 ;
427 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
428 << " ) LinkedNodesSize " << _LinkedNodesSize << " [ " << index
429 << " ] _LinkedInPortsNumber " << _LinkedInPortsNumber[ index ]
430 << " ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
431 << " + 1 Service " << ServiceName() << endl ;
432 ToNode->IncrConnectedInPortsNumber() ;
435 void GraphBase::ComputingNode::RemoveLink( GraphBase::ComputingNode * ToNode ) {
436 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
438 cdebug << "GraphBase::ComputingNode::RemoveLink( to " << ToNode->Name() << " from "
439 << Name() << " index : " << index << " ConnectedInPortsNumber "
440 << ToNode->ConnectedInPortsNumber() - 1 << " LinkedInPortsNumber "
441 << _LinkedInPortsNumber[ index ] << " - 1" << endl ;
442 ToNode->DecrConnectedInPortsNumber() ;
443 _LinkedInPortsNumber[ index ] -= 1 ;
444 if ( _LinkedInPortsNumber[ index ] == 0 ) {
446 cdebug << "GraphBase::ComputingNode::RemoveLink new LinkedNodesSize "
447 << _LinkedNodesSize << " " << ToNode->Name() << " removed from "
448 << " linkednodes of " << Name() << endl ;
450 for ( i = index ; i < _LinkedNodesSize ; i++ ) {
451 _LinkedNodes[ i ] = _LinkedNodes[ i+1 ] ;
452 _LinkedInPortsNumber[ i ] = _LinkedInPortsNumber[ i+1 ] ;
453 SetLinkedNodeIndex( _LinkedNodes[ i ]->Name() , i ) ;
455 DelLinkedNodeIndex( ToNode->Name() ) ;
456 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
457 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
461 cdebug << " Error index " << index << endl ;
465 void GraphBase::ComputingNode::ReNameLink( const char* OldNodeName ,
466 const char* NewNodeName ) {
467 cdebug_in << "GraphBase::ComputingNode::ReNameLink (" << OldNodeName << " , "
468 << NewNodeName << ")" << endl;
469 int index = GetLinkedNodeIndex( OldNodeName ) ;
471 _MapOfLinkedNodes.erase( OldNodeName ) ;
472 SetLinkedNodeIndex( NewNodeName , index ) ;
474 cdebug_out << "GraphBase::ComputingNode::ReNameLink" << endl ;
477 #include <sys/time.h>
478 #include <sys/resource.h>
481 const long GraphBase::ComputingNode::CpuUsed() {
482 struct rusage usage ;
483 if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
484 perror("GraphBase::CpuUsed") ;
487 // return usage.ru_utime.__time_t tv_sec ;
488 cdebug << "CpuUsed " << usage.ru_utime.tv_sec << " " << usage.ru_utime.tv_usec << " "
489 << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec << endl ;
490 return usage.ru_utime.tv_sec ;
494 const GraphBase::ListOfParameters * GraphBase::ComputingNode::GetListOfParameters() const {
495 GraphBase::ListOfParameters * aListOfParameters = new GraphBase::ListOfParameters ;
496 if ( IsInLineNode() || IsGOTONode() ) {
498 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
499 const InPort * anInPort = GetNodeInPort( i ) ;
500 if ( anInPort->IsBus() ) {
501 int size = aListOfParameters->size() ;
502 aListOfParameters->resize( size + 1 ) ;
503 (*aListOfParameters)[size].theInParameter.Parametername = anInPort->PortName() ;
504 (*aListOfParameters)[size].theInParameter.Parametertype = anInPort->PortType() ;
505 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
506 (*aListOfParameters)[size].theOutParameter.Parametername = anOutPort->PortName() ;
507 (*aListOfParameters)[size].theOutParameter.Parametertype = anOutPort->PortType() ;
511 return aListOfParameters ;
515 bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & info ,
516 const char * ComponentName ,
517 const char * InterfaceName ,
518 const char * Computer ,
519 const char * CoupledNode ,
520 const ListOfFuncName FuncNames ,
521 const ListOfPythonFunctions PythonFunctions ,
522 int XCoordinate , int YCoordinate ) const {
523 QDomElement node = Graph.createElement( "node" ) ;
524 info.appendChild( node ) ;
525 QDomElement componentname = Graph.createElement( "component-name" ) ;
527 if ( strlen( ComponentName ) ) {
528 // f << Tabs << "<component-name>" << ComponentName << "</component-name>"
530 // componentname.setNodeValue( ComponentName ) ;
531 aField = Graph.createTextNode( ComponentName ) ;
534 // f << Tabs << "<component-name>?</component-name>" << endl ;
535 // componentname.setNodeValue( "?" ) ;
536 aField = Graph.createTextNode( "?" ) ;
538 node.appendChild( componentname ) ;
539 componentname.appendChild( aField ) ;
541 QDomElement interfacename = Graph.createElement("interface-name") ;
542 if ( strlen( InterfaceName ) ) {
543 // f << Tabs << "<interface-name>" << InterfaceName << "</interface-name>"
545 // interfacename.setAttribute("name" , InterfaceName ) ;
546 aField = Graph.createTextNode( InterfaceName ) ;
549 // f << Tabs << "<interface-name>?</interface-name>" << endl ;
550 // interfacename.setAttribute("name" , "?" ) ;
551 aField = Graph.createTextNode( "?" ) ;
553 node.appendChild(interfacename) ;
554 interfacename.appendChild( aField ) ;
556 // f << Tabs << "<node-name>" << Name() << "</node-name>" << endl ;
557 QDomElement nodename = Graph.createElement("node-name") ;
558 aField = Graph.createTextNode( Name() ) ;
559 node.appendChild( nodename ) ;
560 nodename.appendChild( aField ) ;
562 // f << Tabs << "<kind>" << (int ) Kind() << "</kind>" << endl ;
563 QDomElement kind = Graph.createElement( "kind" ) ;
565 aKind = aKind.setNum( Kind() ) ;
566 aField = Graph.createTextNode( aKind ) ;
567 node.appendChild( kind ) ;
568 kind.appendChild( aField ) ;
570 QDomElement couplednode = Graph.createElement("coupled-node") ;
571 if ( IsGOTONode() || IsLoopNode() || IsEndLoopNode() ||
572 IsSwitchNode() || IsEndSwitchNode() ) {
573 // f << Tabs << "<coupled-node>" << CoupledNode << "</coupled-node>"
575 aField = Graph.createTextNode( CoupledNode ) ;
578 // f << Tabs << "<coupled-node>?</coupled-node>" << endl ;
579 aField = Graph.createTextNode( "?" ) ;
581 node.appendChild(couplednode) ;
582 couplednode.appendChild( aField ) ;
584 // f << Tabs << "<service>" << endl ;
585 QDomElement service = Graph.createElement("service") ;
586 node.appendChild(service) ;
587 QDomElement servicename = Graph.createElement("service-name") ;
588 if ( strlen( ServiceName() ) ) {
589 // f << Tabs << " <service-name>" << ServiceName() << "</service-name>" << endl ;
590 aField = Graph.createTextNode( ServiceName() ) ;
593 // f << Tabs << " <service-name>?</service-name>" << endl ;
594 aField = Graph.createTextNode( "?" ) ;
596 service.appendChild(servicename) ;
597 servicename.appendChild( aField ) ;
599 // f << Tabs << " <inParameter-list>" << endl ;
600 QDomElement inParameterlist = Graph.createElement("inParameter-list") ;
601 service.appendChild(inParameterlist) ;
603 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
604 // f << Tabs << " <inParameter>" << endl ;
605 QDomElement inParameter = Graph.createElement("inParameter") ;
606 inParameterlist.appendChild(inParameter) ;
607 // f << Tabs << " <inParameter-type>"
608 // << ServiceInParameter()[i].Parametertype << "</inParameter-type>"
610 QDomElement inParametertype = Graph.createElement("inParameter-type") ;
611 // mpv: Linux 8.0 compiler compatibility
612 // aField = Graph.createTextNode( (char *)ServiceInParameter()[i].Parametertype ) ;
613 if ( strlen( ServiceInParameter()[i].Parametertype ) ) {
614 aField = Graph.createTextNode( strdup( ServiceInParameter()[i].Parametertype ) ) ;
617 aField = Graph.createTextNode( "?" ) ;
619 inParameter.appendChild(inParametertype) ;
620 inParametertype.appendChild( aField ) ;
621 // f << Tabs << " <inParameter-name>"
622 // << ServiceInParameter()[i].Parametername << "</inParameter-name>"
624 QDomElement inParametername = Graph.createElement("inParameter-name") ;
625 // mpv: Linux 8.0 compiler compatibility
626 // aField = Graph.createTextNode( (char *) ServiceInParameter()[i].Parametername ) ;
627 if ( strlen( ServiceInParameter()[i].Parametername ) ) {
628 aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametername) ) ;
631 aField = Graph.createTextNode( "?" ) ;
633 inParameter.appendChild(inParametername) ;
634 inParametername.appendChild( aField ) ;
635 // f << Tabs << " </inParameter>" << endl ;
637 // f << Tabs << " </inParameter-list>" << endl ;
638 // f << Tabs << " <outParameter-list>" << endl ;
639 QDomElement outParameterlist = Graph.createElement("outParameter-list") ;
640 service.appendChild(outParameterlist) ;
641 for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
642 // f << Tabs << " <outParameter>" << endl ;
643 QDomElement outParameter = Graph.createElement("outParameter") ;
644 outParameterlist.appendChild(outParameter) ;
645 // f << Tabs << " <outParameter-type>"
646 // << ServiceOutParameter()[i].Parametertype << "</outParameter-type>"
648 QDomElement outParametertype = Graph.createElement("outParameter-type") ;
649 // mpv: Linux 8.0 compiler compatibility
650 // aField = Graph.createTextNode( (char *) ServiceOutParameter()[i].Parametertype ) ;
651 if ( strlen( ServiceOutParameter()[i].Parametertype ) ) {
652 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametertype) ) ;
655 aField = Graph.createTextNode( "?" ) ;
657 outParameter.appendChild(outParametertype) ;
658 outParametertype.appendChild( aField ) ;
659 // f << Tabs << " <outParameter-name>"
660 // << ServiceOutParameter()[i].Parametername << "</outParameter-name>"
662 QDomElement outParametername = Graph.createElement("outParameter-name") ;
663 // mpv: Linux 8.0 compiler compatibility
664 // aField = Graph.createTextNode( (char *) ServiceOutParameter()[i].Parametername ) ;
665 if ( strlen( ServiceOutParameter()[i].Parametername ) ) {
666 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametername) ) ;
669 aField = Graph.createTextNode( "?" ) ;
671 outParameter.appendChild(outParametername) ;
672 outParametername.appendChild( aField ) ;
673 // f << Tabs << " </outParameter>" << endl ;
675 // f << Tabs << " </outParameter-list>" << endl ;
676 // f << Tabs << "</service>" << endl ;
678 // f << Tabs << "<Parameter-list>" << endl ;
679 QDomElement Parameterlist = Graph.createElement("Parameter-list") ;
680 node.appendChild( Parameterlist ) ;
682 if ( IsInLineNode() || IsGOTONode() ||
683 IsLoopNode() || IsEndLoopNode() ||
684 IsSwitchNode() || IsEndSwitchNode() ) {
686 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
687 const InPort * anInPort = GetNodeInPort( i ) ;
688 if ( anInPort->IsBus() ) {
689 f << Tabs << " <inParameter>" << endl ;
690 f << Tabs << " <inParameter-type>"
691 << anInPort->PortType() << "</inParameter-type>"
693 f << Tabs << " <inParameter-name>"
694 << anInPort->PortName() << "</inParameter-name>"
696 f << Tabs << " </inParameter>" << endl ;
697 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
698 f << Tabs << " <outParameter>" << endl ;
699 f << Tabs << " <outParameter-type>"
700 << anOutPort->PortType() << "</outParameter-type>"
702 f << Tabs << " <outParameter-name>"
703 << anOutPort->PortName() << "</outParameter-name>"
705 f << Tabs << " </outParameter>" << endl ;
710 // f << Tabs << "</Parameter-list>" << endl ;
712 // f << Tabs << "<PyFunction-list>" << endl ;
713 QDomElement PyFunctionlist = Graph.createElement("PyFunction-list") ;
714 node.appendChild( PyFunctionlist ) ;
715 for ( i = 0 ; i < PythonFunctions.size() ; i++ ) {
716 // f << Tabs << " <PyFunction>" << endl ;
717 QDomElement PyFunction = Graph.createElement("PyFunction") ;
718 PyFunctionlist.appendChild( PyFunction ) ;
720 for ( j = 0 ; j < (int ) (*PythonFunctions[i]).length() ; j++ ) {
723 // f << Tabs << " <FuncName>" << FuncNames[i].c_str()
724 // << "</FuncName>" << endl ;
725 QDomElement FuncName = Graph.createElement("FuncName") ;
726 if ( strlen( FuncNames[i].c_str() ) ) {
727 aField = Graph.createTextNode( FuncNames[i].c_str() ) ;
730 aField = Graph.createTextNode( "?" ) ;
732 PyFunction.appendChild( FuncName ) ;
733 FuncName.appendChild( aField ) ;
735 // else if ( i == 1 ) {
736 // f << Tabs << " <FuncName>" << FuncNames[i].c_str()
737 // << "</FuncName>" << endl ;
739 // else if ( i == 2 ) {
740 // f << Tabs << " <FuncName>" << FuncNames[i].c_str()
741 // << "</FuncName>" << endl ;
744 // f << Tabs << " <PyFunc>" << (*PythonFunctions[i])[j]
745 // << "</PyFunc>" << endl ;
746 QDomElement PyFunc = Graph.createElement("PyFunc") ;
747 QDomCDATASection aCDATA ;
748 // mpv: Linux 8.0 compiler compatibility
749 // char * aCDATAChar = (char *) (*PythonFunctions[i])[j] ;
750 char * aCDATAChar = strdup ((*PythonFunctions[i])[j]) ;
752 for ( i = 0 ; i < (int ) strlen( aCDATAChar ) ; i++ ) {
753 if ( aCDATAChar[ i ] != ' ' ) {
757 if ( i == (int ) strlen( aCDATAChar ) ) {
758 aCDATA = Graph.createCDATASection( "?" ) ;
761 aCDATA = Graph.createCDATASection( aCDATAChar ) ;
763 PyFunction.appendChild( PyFunc ) ;
764 PyFunc.appendChild( aCDATA ) ;
766 // f << Tabs << " </PyFunction>" << endl ;
768 // f << Tabs << "</PyFunction-list>" << endl ;
770 // f << Tabs << "<creation-date>" << FirstCreation() << "</creation-date>"
772 QDomElement creationdate = Graph.createElement("creation-date") ;
774 sprintf( fdate , "%d/%d/%d - %d:%d:%d" , FirstCreation().Day , FirstCreation().Month , FirstCreation().Year , FirstCreation().Hour , FirstCreation().Minute , FirstCreation().Second ) ;
775 aField = Graph.createTextNode( fdate ) ;
776 node.appendChild( creationdate ) ;
777 creationdate.appendChild( aField ) ;
778 // f << Tabs << "<lastmodification-date>" << LastModification()
779 // << "</lastmodification-date>" << endl ;
780 QDomElement lastmodificationdate = Graph.createElement("lastmodification-date") ;
782 sprintf( ldate , "%d/%d/%d - %d:%d:%d" , LastModification().Day , LastModification().Month , LastModification().Year , LastModification().Hour , LastModification().Minute , LastModification().Second ) ;
783 aField = Graph.createTextNode( ldate ) ;
784 node.appendChild( lastmodificationdate ) ;
785 lastmodificationdate.appendChild( aField ) ;
786 // f << Tabs << "<editor-release>" << EditorRelease() << "</editor-release>"
788 QDomElement editorrelease = Graph.createElement("editor-release") ;
789 aField = Graph.createTextNode( EditorRelease() ) ;
790 node.appendChild( editorrelease ) ;
791 editorrelease.appendChild( aField ) ;
792 QDomElement author = Graph.createElement("author") ;
793 if ( strlen( Author() ) ) {
794 // f << Tabs << "<author>" << Author() << "</author>" << endl ;
795 aField = Graph.createTextNode( Author() ) ;
798 // f << Tabs << "<author>?</author>" << endl ;
799 aField = Graph.createTextNode( "?" ) ;
801 node.appendChild( author ) ;
802 author.appendChild( aField ) ;
803 QDomElement container = Graph.createElement("container") ;
804 if ( IsFactoryNode() && strlen( Computer) ) {
805 // f << Tabs << "<container>" << Computer << "</container>" << endl ;
806 aField = Graph.createTextNode( Computer ) ;
809 // f << Tabs << "<container>?</container>" << endl ;
810 aField = Graph.createTextNode( "?" ) ;
812 node.appendChild( container ) ;
813 container.appendChild( aField ) ;
814 QDomElement comment = Graph.createElement("comment") ;
815 if ( strlen( Comment() ) ) {
816 // f << Tabs << "<comment>" << Comment() << "</comment>" << endl ;
817 aField = Graph.createTextNode( Comment() ) ;
820 // f << Tabs << "<comment>?</comment>" << endl ;
821 aField = Graph.createTextNode( "?" ) ;
823 node.appendChild( comment ) ;
824 comment.appendChild( aField ) ;
825 // f << Tabs << "<x-position>" << XCoordinate << "</x-position>" << endl ;
826 QDomElement xposition = Graph.createElement("x-position") ;
827 QString aXCoordinate ;
828 aXCoordinate = aKind.setNum( XCoordinate ) ;
829 aField = Graph.createTextNode( aXCoordinate ) ;
830 node.appendChild( xposition ) ;
831 xposition.appendChild( aField ) ;
832 // f << Tabs << "<y-position>" << YCoordinate << "</y-position>" << endl ;
833 QDomElement yposition = Graph.createElement("y-position") ;
834 QString aYCoordinate ;
835 aYCoordinate = aKind.setNum( YCoordinate ) ;
836 aField = Graph.createTextNode( aYCoordinate ) ;
837 node.appendChild( yposition ) ;
838 yposition.appendChild( aField ) ;
842 bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
843 const char * ComponentName ,
844 const char * InterfaceName ,
845 const char * Computer ,
846 const GraphBase::InLineNode * aCoupledNode ,
847 const ListOfFuncName FuncNames ,
848 const ListOfPythonFunctions PythonFunctions ,
849 int XCoordinate , int YCoordinate ) const {
850 if ( IsDataFlowNode() ) {
851 f << Name() << " = Graph( '" << Name() << "' )" << endl ;
853 else if ( IsComputingNode() ) {
855 f << Name() << "_ServiceinParameter = []" << endl ;
856 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
857 f << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
858 << ServiceInParameter()[i].Parametertype << "' , '"
859 << ServiceInParameter()[i].Parametername << "' ) )" << endl ;
861 f << Name() << "_ServiceoutParameter = []" << endl ;
862 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
863 f << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
864 << ServiceOutParameter()[i].Parametertype << "' , '"
865 << ServiceOutParameter()[i].Parametername << "' ) )" << endl ;
867 f << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
868 << "' , " << Name() << "_ServiceinParameter" << " , "
869 << Name() << "_ServiceoutParameter" << " , 0 )" << endl ;
870 f << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
873 else if ( IsFactoryNode() ) {
874 f << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
875 << "' , '" << InterfaceName << "' , '" << ServiceName() << "' )"
879 f << "Py" << Name() << " = []" << endl ;
881 SUPERV::ListOfStrings aPyFunc ;
882 if ( PythonFunctions.size() ) {
883 aPyFunc = *PythonFunctions[0] ;
884 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
885 f << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
888 if ( IsInLineNode() ) {
889 f << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
890 << Name() << " )" << endl ;
892 else if ( IsGOTONode() ) {
893 if ( aCoupledNode ) {
894 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
895 << Name() << " , '" << aCoupledNode->Name() << "' )" << endl ;
898 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
899 << Name() << " , '' )" << endl ;
903 // char * EndName = NULL ;
904 // EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
905 // strcpy( EndName , "End" ) ;
906 // strcat( EndName , Name() ) ;
907 char * EndName = aCoupledNode->Name() ;
908 if ( IsLoopNode() ) {
909 SUPERV::ListOfStrings aPyMore = *PythonFunctions[1] ;
910 SUPERV::ListOfStrings aPyNext = *PythonFunctions[2] ;
911 f << "PyMore" << Name() << " = []" << endl ;
912 for ( i = 0 ; i < (int ) aPyMore.length() ; i++ ) {
913 f << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
915 f << "PyNext" << Name() << " = []" << endl ;
916 for ( i = 0 ; i < (int ) aPyNext.length() ; i++ ) {
917 f << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
919 f << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
920 << FuncNames[0].c_str() << "' , Py" << Name() << " , '"
921 << FuncNames[1].c_str() << "' , PyMore" << Name()
922 << " , '" << FuncNames[2].c_str() << "' , PyNext"
923 << Name() << " )" << endl ;
924 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
925 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
926 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
927 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
928 << aCoupledNode->YCoordinate() << " )" << endl ;
930 else if ( IsSwitchNode() ) {
931 f << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
932 << FuncNames[0].c_str() << "' , Py" << Name() << " )" << endl ;
933 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
934 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
935 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
936 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
937 << aCoupledNode->YCoordinate() << " )" << endl ;
938 SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
939 f << "Py" << aCoupledNode->Name() << " = []" << endl ;
940 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
941 f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
944 f << EndName << ".SetPyFunction( 'End" << FuncNames[0].c_str() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
945 for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
946 const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
947 if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
948 f << EndName << ".InPort( '" << anInPort->PortName()
949 << "' , '" << anInPort->PortType() << "' )" << endl ;
952 for ( i = 0 ; i < aCoupledNode->GetNodeOutPortsSize() ; i++ ) {
953 const GraphBase::OutPort * anOutPort = aCoupledNode->GetNodeOutPort(i) ;
954 if ( anOutPort->IsInLine() ) {
955 f << EndName << ".OutPort( '" << anOutPort->PortName()
956 << "' , '" << anOutPort->PortType() << "' )" << endl ;
964 f << Name() << ".SetName( '" << Name() << "' )" << endl ;
965 f << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
966 if ( IsFactoryNode() ) {
967 f << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
969 f << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
970 f << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
972 if ( IsOneOfInLineNodes() ) {
974 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
975 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
976 if ( anInPort->IsInLine() ) {
977 f << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
978 << anInPort->PortType() << "' )" << endl ;
981 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
982 const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
983 if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
984 f << Name() << ".OutPort( '" << anOutPort->PortName()
985 << "' , '" << anOutPort->PortType() << "' )" << endl ;
991 if ( IsLoopNode() || IsSwitchNode() ) {
992 f << EndName << ".SetName( '" << CoupledNode
994 f << EndName << ".SetAuthor( '" << CoupledNode->Author()
996 f << EndName << ".SetComment( '" << CoupledNode->Comment()
998 f << EndName << ".Coords( " << CoupledNode->XCoordinate() << " , "
999 << CoupledNode->YCoordinate() << " )" << endl ;
1001 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1002 const InPort * anInPort = GetNodeInPort( i ) ;
1003 if ( anInPort->IsBus() ) {
1004 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
1005 f << Name() << ".BusPorts( '" << anInPort->PortName() << "' , '"
1006 << anInPort->PortType() << "' , '" << anOutPort->PortName()
1007 << "' , '" << anOutPort->PortType() << "' )" << endl ;
1015 void GraphBase::ComputingNode::NodeInfo(ostream & s) const {
1017 ListPorts( s , true ) ;
1021 ostream & operator<< (ostream & f,const GraphBase::ComputingNode & G) {
1022 // f << "ComponentName " << G.ComponentName() << endl ;
1023 if ( G.IsComputingNode() )
1024 f << "NodeName " << G.Name() << endl ;
1026 f << "DataFlowName " << G.Name() << endl ;
1027 f << "Kind " << G.Kind() << endl ;
1028 f << "Service " << *G.GetService() ;
1029 f << "FirstCreation " << G.FirstCreation () << endl ;
1030 f << "LastModification " << G.LastModification() << endl ;
1031 f << "EditorRelease " << G.EditorRelease() << endl ;
1032 f << "Author " << G.Author() << endl ;
1033 // f << "Computer " << G.Computer() << endl ;
1034 f << "Comment " << G.Comment() << endl ;
1040 void GraphBase::ComputingNode::ListLinks(ostream &f ) const {
1042 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1043 const GraphBase::OutPort* fromPort = GetNodeOutPort( i ) ;
1044 if ( fromPort->IsPortConnected() ) {
1046 for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
1048 f << "FromNode " << Name() << endl ;
1049 f << " FromServiceParameterName "
1050 << fromPort->GetServicesParameter().Parametername ;
1051 const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
1052 f << " ToNode " << toPort->NodeName() ;
1053 f << " ToServiceParameterName "
1054 << toPort->GetServicesParameter().Parametername;
1056 fromPort->StringValue( f ) ;
1063 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D) {
1064 // cdebug_in << "operator<< GraphEditor::Date" << endl;
1066 fOut << D.Day << "/"
1073 // cdebug_out << "operator<< GraphEditor::Date" << endl;