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
82 << (void *) _Name << " " << _Name << " _Comment "
83 << (void *) _Comment << " " << _Comment << " " << endl ;
87 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
88 SALOME_NamingService* ptrNamingService ,
89 const char * aDataFlowName ,
90 int * Graph_prof_debug ,
91 ostream * Graph_fdebug ) :
92 GraphBase::PortsOfNode::PortsOfNode( aDataFlowName ) {
102 _ConnectedInPortsNumber ,
103 _DecrConnectedInPortsNumber ,
107 _ORB = CORBA::ORB::_duplicate( ORB ) ;
108 _NamingService = ptrNamingService ;
109 _Graph_prof_debug = Graph_prof_debug ;
110 _Graph_fdebug = Graph_fdebug ;
111 _Node = SUPERV::CNode::_nil() ;
113 _ThreadNo = pthread_self() ;
115 if ( aDataFlowName && strlen( aDataFlowName ) ) {
116 _Name = new char[ strlen( aDataFlowName )+1 ] ;
117 strcpy( _Name , aDataFlowName ) ;
121 if ( Graph_prof_debug ) {
122 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
123 // MESSAGE( "Invalid DataFlow Name." );
125 cdebug << "GraphBase::ComputingNode::ComputingNode " << this
127 << (void *) _Name << " '" << _Name << " _Comment "
128 << (void *) _Comment << " " << _Comment << " " << _FirstCreation
129 << " " << _LastModification << endl ;
132 GraphBase::ComputingNode::ComputingNode( CORBA::ORB_ptr ORB ,
133 SALOME_NamingService* ptrNamingService ,
134 const SALOME_ModuleCatalog::Service& aService ,
135 const char *NodeName ,
136 const SUPERV::KindOfNode akind ,
137 const SUPERV::SDate NodeFirstCreation ,
138 const SUPERV::SDate NodeLastModification ,
139 const char * NodeEditorRelease ,
140 const char * NodeAuthor ,
141 const char * NodeComment ,
142 const bool GeneratedName ,
145 int * Graph_prof_debug ,
146 ostream * Graph_fdebug ) :
147 GraphBase::PortsOfNode::PortsOfNode() {
149 _ORB = CORBA::ORB::_duplicate( ORB ) ;
150 _NamingService = ptrNamingService ;
151 _Graph_prof_debug = Graph_prof_debug ;
152 _Graph_fdebug = Graph_fdebug ;
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 ) {
170 _EditorRelease = new char[ strlen( NodeEditorRelease ) + 1 ] ;
171 strcpy( _EditorRelease , NodeEditorRelease ) ;
174 _EditorRelease = new char[ strlen( SuperVision_Version ) + 1 ] ;
175 strcpy( _EditorRelease , SuperVision_Version ) ;
179 _Author = new char[ strlen( NodeAuthor ) + 1 ] ;
180 strcpy( _Author , NodeAuthor ) ;
183 _Author = NULLSTRING ;
186 _Comment = new char[ strlen( NodeComment ) + 1 ] ;
187 strcpy( _Comment , NodeComment ) ;
190 _Comment = NULLSTRING ;
192 _SubGraphNumber = 0 ;
194 _GeneratedName = GeneratedName ;
196 const char *aNodeName = NodeName ;
197 _Name = new char[strlen(aNodeName)+1];
198 strcpy(_Name , aNodeName);
200 _ConnectedInPortsNumber = 0 ;
201 _DecrConnectedInPortsNumber = 0 ;
202 _LinkedNodesSize = 0 ;
207 if ( Graph_prof_debug )
208 SetDebug( ORB , Graph_prof_debug , Graph_fdebug ) ;
210 DefPortsOfNode( ORB , aService , NamePtr() , Kind() ,
211 Graph_prof_debug , Graph_fdebug ) ;
213 cdebug_in << "GraphBase::ComputingNode::ComputingNode(" << aService.ServiceName << ","
214 << aNodeName << "," << akind
215 << "," << NodeComment << ")" << endl;
217 cdebug << "GraphBase::ComputingNode::ComputingNode " << this
219 << (void *) _Name << " '" << _Name << "' _Comment "
220 << (void *) _Comment << " " << _Comment << " "
221 << " KindOfNode " << _Kind
222 << " ServiceName " << ServiceName() << " In(" << ServiceInParameter().length()
223 << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
225 cdebug_out << "GraphBase::ComputingNode::ComputingNode" << endl;
228 GraphBase::ComputingNode::~ComputingNode() {
229 cdebug << "GraphBase::ComputingNode::~ComputingNode " << this
231 << (void *) _Name << " " << _Name << " _Comment "
232 << (void *) _Comment << " " << _Comment << " " << endl ;
233 // if ( _ComponentName != NULLSTRING )
234 // delete [] _ComponentName ;
236 // delete [] _EditorRelease ;
237 // if ( _Author != NULLSTRING )
238 // delete [] _Author ;
239 // if ( _Computer != FACTORYSERVER )
240 // delete [] _Computer;
241 // if ( _Comment != NULLSTRING )
242 // delete [] _Comment;
245 bool GraphBase::ComputingNode::Name( const char * aName) {
247 cdebug << "GraphBase::ComputingNode::ReName " << _Name << " --> " << aName << endl ;
250 _Name = new char[strlen(aName)+1] ;
251 strcpy( _Name , aName ) ;
255 SUPERV::SDate GraphBase::ComputingNode::FirstCreation () const {
256 cdebug << "GraphBase::ComputingNode::FirstCreation "
257 << "' _Name " << _Name << " " << _FirstCreation << " "
258 << _LastModification << endl ;
259 return _FirstCreation;
262 SUPERV::SDate GraphBase::ComputingNode::LastModification () const {
263 return _LastModification ;
266 bool GraphBase::ComputingNode::Kind(const SUPERV::KindOfNode aKind) {
271 void GraphBase::ComputingNode::FirstCreation(const SUPERV::SDate aDate ) {
272 _FirstCreation = aDate ;
275 void GraphBase::ComputingNode::LastModification(const SUPERV::SDate aDate ) {
276 _LastModification = aDate ;
279 bool GraphBase::ComputingNode::EditorRelease(const char * c){
280 if ( _EditorRelease && _EditorRelease != NULLSTRING )
281 delete _EditorRelease;
282 _EditorRelease = my_strdup(c);
286 bool GraphBase::ComputingNode::Author(const char * a) {
287 if ( _Author && _Author != NULLSTRING )
289 _Author = my_strdup(a);
293 bool GraphBase::ComputingNode::Comment(const char *c) {
294 cdebug_in << "GraphBase::ComputingNode::Comment" << endl;
295 if ( _Comment != NULLSTRING )
297 _Comment = my_strdup(c);
298 cdebug_out << "GraphBase::ComputingNode::Comment" << endl;
302 void GraphBase::ComputingNode::NodePort( const char * NodeName ,
303 const char * ServiceParameterName ,
304 char ** aNode , char ** aPort ) {
305 if ( strcmp( NodeName , Name() ) ) {
306 *aNode = my_strdup( NodeName ) ;
307 *aPort = my_strdup( ServiceParameterName ) ;
310 char * BPort = strchr( ServiceParameterName , '\\' ) ;
312 int len = BPort - ServiceParameterName ;
313 *aNode = new char [ len + 1 ] ;
314 strncpy( *aNode , ServiceParameterName , len ) ;
315 (*aNode)[ len ] = '\0' ;
316 *aPort = my_strdup( &BPort[ 1 ] ) ;
319 *aNode = my_strdup( NULLSTRING ) ;
320 *aPort = my_strdup( NULLSTRING ) ;
325 bool GraphBase::ComputingNode::IsLinked(const char * ToServiceParameterName ) {
326 bool RetVal = false ;
327 const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
329 RetVal = thePort->IsConnected() ;
332 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
334 RetVal = thePort->IsConnected() ;
340 bool GraphBase::ComputingNode::HasInput(const char * ToServiceParameterName ) {
341 bool RetVal = false ;
342 const GraphBase::InPort * thePort = GetInPort( ToServiceParameterName ) ;
343 if ( IsDataFlowNode() && thePort ) {
346 else if ( thePort ) {
347 RetVal = thePort->IsDataConnected() ;
350 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
352 RetVal = thePort->IsDataConnected() ;
358 GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
359 cdebug_in << "GraphBase::ComputingNode::GetInfo" << endl;
360 GraphBase::SNode * Info = new GraphBase::SNode ;
361 // Info->theComponentName = ComponentName() ;
362 // Info->theInterfaceName = InterfaceName() ;
363 Info->theName = Name() ;
364 Info->theKind = Kind() ;
365 Info->theService = *GetService() ;
366 // Info->theListOfParameters = *GetListOfParameters() ;
367 Info->theFirstCreation = FirstCreation() ;
368 Info->theLastModification = LastModification() ;
369 Info->theEditorRelease = EditorRelease() ;
370 Info->theAuthor = Author() ;
371 // Info->theContainer = Computer() ;
372 Info->theComment = Comment() ;
373 Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
374 Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
375 cdebug_out << "GraphBase::ComputingNode::GetInfo" << endl;
379 GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParameterName ,
380 const char * InputParameterType ) {
381 return GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
385 _Graph_prof_debug , _Graph_fdebug ) ;
387 GraphBase::OutPort * GraphBase::ComputingNode::AddOutPort( const char * OutputParameterName ,
388 const char * OutputParameterType ) {
389 return GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
391 OutputParameterName ,
392 OutputParameterType ,
393 _Graph_prof_debug , _Graph_fdebug ) ;
396 void GraphBase::ComputingNode::AddLink( GraphBase::ComputingNode * ToNode ) {
397 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
399 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
400 << " ) new LinkedNode " << endl ;
401 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
402 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
403 _LinkedNodes[ _LinkedNodesSize ] = ToNode ;
404 _LinkedInPortsNumber[ _LinkedNodesSize ] = 1 ;
405 SetLinkedNodeIndex( ToNode->Name() , _LinkedNodesSize ) ;
406 index = _LinkedNodesSize ;
410 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
411 << " ) old LinkedNode " << _LinkedNodes[index ]->Name() << endl ;
412 _LinkedInPortsNumber[ index ] += 1 ;
414 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
415 << " ) LinkedNodesSize " << _LinkedNodesSize << " [ " << index
416 << " ] _LinkedInPortsNumber " << _LinkedInPortsNumber[ index ]
417 << " ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
418 << " + 1 Service " << ServiceName() << endl ;
419 ToNode->IncrConnectedInPortsNumber() ;
422 void GraphBase::ComputingNode::RemoveLink( GraphBase::ComputingNode * ToNode ) {
423 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
425 cdebug << "GraphBase::ComputingNode::RemoveLink( to " << ToNode->Name() << " from "
426 << Name() << " index : " << index << " ConnectedInPortsNumber "
427 << ToNode->ConnectedInPortsNumber() - 1 << " LinkedInPortsNumber "
428 << _LinkedInPortsNumber[ index ] << " - 1" << endl ;
429 ToNode->DecrConnectedInPortsNumber() ;
430 _LinkedInPortsNumber[ index ] -= 1 ;
431 if ( _LinkedInPortsNumber[ index ] == 0 ) {
433 cdebug << "GraphBase::ComputingNode::RemoveLink new LinkedNodesSize "
434 << _LinkedNodesSize << " " << ToNode->Name() << " removed from "
435 << " linkednodes of " << Name() << endl ;
437 for ( i = index ; i < _LinkedNodesSize ; i++ ) {
438 _LinkedNodes[ i ] = _LinkedNodes[ i+1 ] ;
439 _LinkedInPortsNumber[ i ] = _LinkedInPortsNumber[ i+1 ] ;
440 SetLinkedNodeIndex( _LinkedNodes[ i ]->Name() , i ) ;
442 DelLinkedNodeIndex( ToNode->Name() ) ;
443 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
444 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
448 cdebug << " Error index " << index << endl ;
452 void GraphBase::ComputingNode::ReNameLink( const char* OldNodeName ,
453 const char* NewNodeName ) {
454 cdebug_in << "GraphBase::ComputingNode::ReNameLink (" << OldNodeName << " , "
455 << NewNodeName << ")" << endl;
456 int index = GetLinkedNodeIndex( OldNodeName ) ;
458 _MapOfLinkedNodes.erase( OldNodeName ) ;
459 SetLinkedNodeIndex( NewNodeName , index ) ;
461 cdebug_out << "GraphBase::ComputingNode::ReNameLink" << endl ;
464 #include <sys/time.h>
465 #include <sys/resource.h>
468 const long GraphBase::ComputingNode::CpuUsed() {
469 struct rusage usage ;
470 if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
471 perror("GraphBase::CpuUsed") ;
474 // return usage.ru_utime.__time_t tv_sec ;
475 cdebug << "CpuUsed " << usage.ru_utime.tv_sec << " " << usage.ru_utime.tv_usec << " "
476 << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec << endl ;
477 return usage.ru_utime.tv_sec ;
481 const GraphBase::ListOfParameters * GraphBase::ComputingNode::GetListOfParameters() const {
482 GraphBase::ListOfParameters * aListOfParameters = new GraphBase::ListOfParameters ;
483 if ( IsInLineNode() || IsGOTONode() ) {
485 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
486 const InPort * anInPort = GetNodeInPort( i ) ;
487 if ( anInPort->IsBus() ) {
488 int size = aListOfParameters->size() ;
489 aListOfParameters->resize( size + 1 ) ;
490 (*aListOfParameters)[size].theInParameter.Parametername = anInPort->PortName() ;
491 (*aListOfParameters)[size].theInParameter.Parametertype = anInPort->PortType() ;
492 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
493 (*aListOfParameters)[size].theOutParameter.Parametername = anOutPort->PortName() ;
494 (*aListOfParameters)[size].theOutParameter.Parametertype = anOutPort->PortType() ;
498 return aListOfParameters ;
502 bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & info ,
503 const char * ComponentName ,
504 const char * InterfaceName ,
505 const char * Computer ,
506 const char * CoupledNode ,
507 const ListOfFuncName FuncNames ,
508 const ListOfPythonFunctions PythonFunctions ,
509 int XCoordinate , int YCoordinate ) const {
510 QDomElement node = Graph.createElement( "node" ) ;
511 info.appendChild( node ) ;
512 QDomElement componentname = Graph.createElement( "component-name" ) ;
514 if ( strlen( ComponentName ) ) {
515 // f << Tabs << "<component-name>" << ComponentName << "</component-name>"
517 // componentname.setNodeValue( ComponentName ) ;
518 aField = Graph.createTextNode( ComponentName ) ;
521 // f << Tabs << "<component-name>?</component-name>" << endl ;
522 // componentname.setNodeValue( "?" ) ;
523 aField = Graph.createTextNode( "?" ) ;
525 node.appendChild( componentname ) ;
526 componentname.appendChild( aField ) ;
528 QDomElement interfacename = Graph.createElement("interface-name") ;
529 if ( strlen( InterfaceName ) ) {
530 // f << Tabs << "<interface-name>" << InterfaceName << "</interface-name>"
532 // interfacename.setAttribute("name" , InterfaceName ) ;
533 aField = Graph.createTextNode( InterfaceName ) ;
536 // f << Tabs << "<interface-name>?</interface-name>" << endl ;
537 // interfacename.setAttribute("name" , "?" ) ;
538 aField = Graph.createTextNode( "?" ) ;
540 node.appendChild(interfacename) ;
541 interfacename.appendChild( aField ) ;
543 // f << Tabs << "<node-name>" << Name() << "</node-name>" << endl ;
544 QDomElement nodename = Graph.createElement("node-name") ;
545 aField = Graph.createTextNode( Name() ) ;
546 node.appendChild( nodename ) ;
547 nodename.appendChild( aField ) ;
549 // f << Tabs << "<kind>" << (int ) Kind() << "</kind>" << endl ;
550 QDomElement kind = Graph.createElement( "kind" ) ;
552 aKind = aKind.setNum( Kind() ) ;
553 aField = Graph.createTextNode( aKind ) ;
554 node.appendChild( kind ) ;
555 kind.appendChild( aField ) ;
557 QDomElement couplednode = Graph.createElement("coupled-node") ;
558 if ( IsGOTONode() || IsLoopNode() || IsEndLoopNode() ||
559 IsSwitchNode() || IsEndSwitchNode() ) {
560 // f << Tabs << "<coupled-node>" << CoupledNode << "</coupled-node>"
562 aField = Graph.createTextNode( CoupledNode ) ;
565 // f << Tabs << "<coupled-node>?</coupled-node>" << endl ;
566 aField = Graph.createTextNode( "?" ) ;
568 node.appendChild(couplednode) ;
569 couplednode.appendChild( aField ) ;
571 // f << Tabs << "<service>" << endl ;
572 QDomElement service = Graph.createElement("service") ;
573 node.appendChild(service) ;
574 QDomElement servicename = Graph.createElement("service-name") ;
575 if ( strlen( ServiceName() ) ) {
576 // f << Tabs << " <service-name>" << ServiceName() << "</service-name>" << endl ;
577 aField = Graph.createTextNode( ServiceName() ) ;
580 // f << Tabs << " <service-name>?</service-name>" << endl ;
581 aField = Graph.createTextNode( "?" ) ;
583 service.appendChild(servicename) ;
584 servicename.appendChild( aField ) ;
586 // f << Tabs << " <inParameter-list>" << endl ;
587 QDomElement inParameterlist = Graph.createElement("inParameter-list") ;
588 service.appendChild(inParameterlist) ;
590 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
591 // f << Tabs << " <inParameter>" << endl ;
592 QDomElement inParameter = Graph.createElement("inParameter") ;
593 inParameterlist.appendChild(inParameter) ;
594 // f << Tabs << " <inParameter-type>"
595 // << ServiceInParameter()[i].Parametertype << "</inParameter-type>"
597 QDomElement inParametertype = Graph.createElement("inParameter-type") ;
598 // mpv: Linux 8.0 compiler compatibility
599 // aField = Graph.createTextNode( (char *)ServiceInParameter()[i].Parametertype ) ;
600 aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametertype) ) ;
601 inParameter.appendChild(inParametertype) ;
602 inParametertype.appendChild( aField ) ;
603 // f << Tabs << " <inParameter-name>"
604 // << ServiceInParameter()[i].Parametername << "</inParameter-name>"
606 QDomElement inParametername = Graph.createElement("inParameter-name") ;
607 // mpv: Linux 8.0 compiler compatibility
608 // aField = Graph.createTextNode( (char *) ServiceInParameter()[i].Parametername ) ;
609 aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametername) ) ;
610 inParameter.appendChild(inParametername) ;
611 inParametername.appendChild( aField ) ;
612 // f << Tabs << " </inParameter>" << endl ;
614 // f << Tabs << " </inParameter-list>" << endl ;
615 // f << Tabs << " <outParameter-list>" << endl ;
616 QDomElement outParameterlist = Graph.createElement("outParameter-list") ;
617 service.appendChild(outParameterlist) ;
618 for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
619 // f << Tabs << " <outParameter>" << endl ;
620 QDomElement outParameter = Graph.createElement("outParameter") ;
621 outParameterlist.appendChild(outParameter) ;
622 // f << Tabs << " <outParameter-type>"
623 // << ServiceOutParameter()[i].Parametertype << "</outParameter-type>"
625 QDomElement outParametertype = Graph.createElement("outParameter-type") ;
626 // mpv: Linux 8.0 compiler compatibility
627 // aField = Graph.createTextNode( (char *) ServiceOutParameter()[i].Parametertype ) ;
628 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametertype) ) ;
629 outParameter.appendChild(outParametertype) ;
630 outParametertype.appendChild( aField ) ;
631 // f << Tabs << " <outParameter-name>"
632 // << ServiceOutParameter()[i].Parametername << "</outParameter-name>"
634 QDomElement outParametername = Graph.createElement("outParameter-name") ;
635 // mpv: Linux 8.0 compiler compatibility
636 // aField = Graph.createTextNode( (char *) ServiceOutParameter()[i].Parametername ) ;
637 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametername) ) ;
638 outParameter.appendChild(outParametername) ;
639 outParametername.appendChild( aField ) ;
640 // f << Tabs << " </outParameter>" << endl ;
642 // f << Tabs << " </outParameter-list>" << endl ;
643 // f << Tabs << "</service>" << endl ;
645 // f << Tabs << "<Parameter-list>" << endl ;
646 QDomElement Parameterlist = Graph.createElement("Parameter-list") ;
647 node.appendChild( Parameterlist ) ;
649 if ( IsInLineNode() || IsGOTONode() ||
650 IsLoopNode() || IsEndLoopNode() ||
651 IsSwitchNode() || IsEndSwitchNode() ) {
653 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
654 const InPort * anInPort = GetNodeInPort( i ) ;
655 if ( anInPort->IsBus() ) {
656 f << Tabs << " <inParameter>" << endl ;
657 f << Tabs << " <inParameter-type>"
658 << anInPort->PortType() << "</inParameter-type>"
660 f << Tabs << " <inParameter-name>"
661 << anInPort->PortName() << "</inParameter-name>"
663 f << Tabs << " </inParameter>" << endl ;
664 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
665 f << Tabs << " <outParameter>" << endl ;
666 f << Tabs << " <outParameter-type>"
667 << anOutPort->PortType() << "</outParameter-type>"
669 f << Tabs << " <outParameter-name>"
670 << anOutPort->PortName() << "</outParameter-name>"
672 f << Tabs << " </outParameter>" << endl ;
677 // f << Tabs << "</Parameter-list>" << endl ;
679 // f << Tabs << "<PyFunction-list>" << endl ;
680 QDomElement PyFunctionlist = Graph.createElement("PyFunction-list") ;
681 node.appendChild( PyFunctionlist ) ;
682 for ( i = 0 ; i < PythonFunctions.size() ; i++ ) {
683 // f << Tabs << " <PyFunction>" << endl ;
684 QDomElement PyFunction = Graph.createElement("PyFunction") ;
685 PyFunctionlist.appendChild( PyFunction ) ;
687 for ( j = 0 ; j < (*PythonFunctions[i]).length() ; j++ ) {
690 // f << Tabs << " <FuncName>" << FuncNames[i].c_str()
691 // << "</FuncName>" << endl ;
692 QDomElement FuncName = Graph.createElement("FuncName") ;
693 if ( strlen( FuncNames[i].c_str() ) ) {
694 aField = Graph.createTextNode( FuncNames[i].c_str() ) ;
697 aField = Graph.createTextNode( "?" ) ;
699 PyFunction.appendChild( FuncName ) ;
700 FuncName.appendChild( aField ) ;
702 // else if ( i == 1 ) {
703 // f << Tabs << " <FuncName>" << FuncNames[i].c_str()
704 // << "</FuncName>" << endl ;
706 // else if ( i == 2 ) {
707 // f << Tabs << " <FuncName>" << FuncNames[i].c_str()
708 // << "</FuncName>" << endl ;
711 // f << Tabs << " <PyFunc>" << (*PythonFunctions[i])[j]
712 // << "</PyFunc>" << endl ;
713 QDomElement PyFunc = Graph.createElement("PyFunc") ;
714 QDomCDATASection aCDATA ;
715 // mpv: Linux 8.0 compiler compatibility
716 // char * aCDATAChar = (char *) (*PythonFunctions[i])[j] ;
717 char * aCDATAChar = strdup ((*PythonFunctions[i])[j]) ;
719 for ( i = 0 ; i < strlen( aCDATAChar ) ; i++ ) {
720 if ( aCDATAChar[ i ] != ' ' ) {
724 if ( i == strlen( aCDATAChar ) ) {
725 aCDATA = Graph.createCDATASection( "?" ) ;
728 aCDATA = Graph.createCDATASection( aCDATAChar ) ;
730 PyFunction.appendChild( PyFunc ) ;
731 PyFunc.appendChild( aCDATA ) ;
733 // f << Tabs << " </PyFunction>" << endl ;
735 // f << Tabs << "</PyFunction-list>" << endl ;
737 // f << Tabs << "<creation-date>" << FirstCreation() << "</creation-date>"
739 QDomElement creationdate = Graph.createElement("creation-date") ;
741 sprintf( fdate , "%d/%d/%d - %d:%d:%d" , FirstCreation().Day , FirstCreation().Month , FirstCreation().Year , FirstCreation().Hour , FirstCreation().Minute , FirstCreation().Second ) ;
742 aField = Graph.createTextNode( fdate ) ;
743 node.appendChild( creationdate ) ;
744 creationdate.appendChild( aField ) ;
745 // f << Tabs << "<lastmodification-date>" << LastModification()
746 // << "</lastmodification-date>" << endl ;
747 QDomElement lastmodificationdate = Graph.createElement("lastmodification-date") ;
749 sprintf( ldate , "%d/%d/%d - %d:%d:%d" , LastModification().Day , LastModification().Month , LastModification().Year , LastModification().Hour , LastModification().Minute , LastModification().Second ) ;
750 aField = Graph.createTextNode( ldate ) ;
751 node.appendChild( lastmodificationdate ) ;
752 lastmodificationdate.appendChild( aField ) ;
753 // f << Tabs << "<editor-release>" << EditorRelease() << "</editor-release>"
755 QDomElement editorrelease = Graph.createElement("editor-release") ;
756 aField = Graph.createTextNode( EditorRelease() ) ;
757 node.appendChild( editorrelease ) ;
758 editorrelease.appendChild( aField ) ;
759 QDomElement author = Graph.createElement("author") ;
760 if ( strlen( Author() ) ) {
761 // f << Tabs << "<author>" << Author() << "</author>" << endl ;
762 aField = Graph.createTextNode( Author() ) ;
765 // f << Tabs << "<author>?</author>" << endl ;
766 aField = Graph.createTextNode( "?" ) ;
768 node.appendChild( author ) ;
769 author.appendChild( aField ) ;
770 QDomElement container = Graph.createElement("container") ;
771 if ( IsFactoryNode() && strlen( Computer) ) {
772 // f << Tabs << "<container>" << Computer << "</container>" << endl ;
773 aField = Graph.createTextNode( Computer ) ;
776 // f << Tabs << "<container>?</container>" << endl ;
777 aField = Graph.createTextNode( "?" ) ;
779 node.appendChild( container ) ;
780 container.appendChild( aField ) ;
781 QDomElement comment = Graph.createElement("comment") ;
782 if ( strlen( Comment() ) ) {
783 // f << Tabs << "<comment>" << Comment() << "</comment>" << endl ;
784 aField = Graph.createTextNode( Comment() ) ;
787 // f << Tabs << "<comment>?</comment>" << endl ;
788 aField = Graph.createTextNode( "?" ) ;
790 node.appendChild( comment ) ;
791 comment.appendChild( aField ) ;
792 // f << Tabs << "<x-position>" << XCoordinate << "</x-position>" << endl ;
793 QDomElement xposition = Graph.createElement("x-position") ;
794 QString aXCoordinate ;
795 aXCoordinate = aKind.setNum( XCoordinate ) ;
796 aField = Graph.createTextNode( aXCoordinate ) ;
797 node.appendChild( xposition ) ;
798 xposition.appendChild( aField ) ;
799 // f << Tabs << "<y-position>" << YCoordinate << "</y-position>" << endl ;
800 QDomElement yposition = Graph.createElement("y-position") ;
801 QString aYCoordinate ;
802 aYCoordinate = aKind.setNum( YCoordinate ) ;
803 aField = Graph.createTextNode( aYCoordinate ) ;
804 node.appendChild( yposition ) ;
805 yposition.appendChild( aField ) ;
809 bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
810 const char * ComponentName ,
811 const char * InterfaceName ,
812 const char * Computer ,
813 const GraphBase::InLineNode * aCoupledNode ,
814 const ListOfFuncName FuncNames ,
815 const ListOfPythonFunctions PythonFunctions ,
816 int XCoordinate , int YCoordinate ) const {
817 if ( IsDataFlowNode() ) {
818 f << Name() << " = Graph( '" << Name() << "' )" << endl ;
820 else if ( IsComputingNode() ) {
822 f << Name() << "_ServiceinParameter = []" << endl ;
823 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
824 f << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
825 << ServiceInParameter()[i].Parametertype << "' , '"
826 << ServiceInParameter()[i].Parametername << "' ) )" << endl ;
828 f << Name() << "_ServiceoutParameter = []" << endl ;
829 for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
830 f << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
831 << ServiceOutParameter()[i].Parametertype << "' , '"
832 << ServiceOutParameter()[i].Parametername << "' ) )" << endl ;
834 f << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
835 << "' , " << Name() << "_ServiceinParameter" << " , "
836 << Name() << "_ServiceoutParameter" << " , 0 )" << endl ;
837 f << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
840 else if ( IsFactoryNode() ) {
841 f << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
842 << "' , '" << InterfaceName << "' , '" << ServiceName() << "' )"
846 f << "Py" << Name() << " = []" << endl ;
848 SUPERV::ListOfStrings aPyFunc ;
849 if ( PythonFunctions.size() ) {
850 aPyFunc = *PythonFunctions[0] ;
851 for ( i = 0 ; i < aPyFunc.length() ; i++ ) {
852 f << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
855 if ( IsInLineNode() ) {
856 f << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
857 << Name() << " )" << endl ;
859 else if ( IsGOTONode() ) {
860 if ( aCoupledNode ) {
861 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
862 << Name() << " , '" << aCoupledNode->Name() << "' )" << endl ;
865 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
866 << Name() << " , '' )" << endl ;
870 // char * EndName = NULL ;
871 // EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
872 // strcpy( EndName , "End" ) ;
873 // strcat( EndName , Name() ) ;
874 char * EndName = aCoupledNode->Name() ;
875 if ( IsLoopNode() ) {
876 SUPERV::ListOfStrings aPyMore = *PythonFunctions[1] ;
877 SUPERV::ListOfStrings aPyNext = *PythonFunctions[2] ;
878 f << "PyMore" << Name() << " = []" << endl ;
879 for ( i = 0 ; i < aPyMore.length() ; i++ ) {
880 f << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
882 f << "PyNext" << Name() << " = []" << endl ;
883 for ( i = 0 ; i < aPyNext.length() ; i++ ) {
884 f << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
886 f << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
887 << FuncNames[0].c_str() << "' , Py" << Name() << " , '"
888 << FuncNames[1].c_str() << "' , PyMore" << Name()
889 << " , '" << FuncNames[2].c_str() << "' , PyNext"
890 << Name() << " )" << endl ;
891 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
892 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
893 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
894 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
895 << aCoupledNode->YCoordinate() << " )" << endl ;
897 else if ( IsSwitchNode() ) {
898 f << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
899 << FuncNames[0].c_str() << "' , Py" << Name() << " )" << endl ;
900 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
901 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
902 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
903 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
904 << aCoupledNode->YCoordinate() << " )" << endl ;
905 SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
906 f << "Py" << aCoupledNode->Name() << " = []" << endl ;
907 for ( i = 0 ; i < aPyFunc.length() ; i++ ) {
908 f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
911 f << EndName << ".SetPyFunction( 'End" << FuncNames[0].c_str() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
912 for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
913 const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
914 if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
915 f << EndName << ".InPort( '" << anInPort->PortName()
916 << "' , '" << anInPort->PortType() << "' )" << endl ;
919 for ( i = 0 ; i < aCoupledNode->GetNodeOutPortsSize() ; i++ ) {
920 const GraphBase::OutPort * anOutPort = aCoupledNode->GetNodeOutPort(i) ;
921 if ( anOutPort->IsInLine() ) {
922 f << EndName << ".OutPort( '" << anOutPort->PortName()
923 << "' , '" << anOutPort->PortType() << "' )" << endl ;
929 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
930 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
931 if ( anInPort->IsInLine() ) {
932 f << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
933 << anInPort->PortType() << "' )" << endl ;
936 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
937 const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
938 if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
939 f << Name() << ".OutPort( '" << anOutPort->PortName()
940 << "' , '" << anOutPort->PortType() << "' )" << endl ;
945 f << Name() << ".SetName( '" << Name() << "' )" << endl ;
946 f << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
947 if ( IsFactoryNode() ) {
948 f << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
950 f << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
951 f << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
954 if ( IsLoopNode() || IsSwitchNode() ) {
955 f << EndName << ".SetName( '" << CoupledNode
957 f << EndName << ".SetAuthor( '" << CoupledNode->Author()
959 f << EndName << ".SetComment( '" << CoupledNode->Comment()
961 f << EndName << ".Coords( " << CoupledNode->XCoordinate() << " , "
962 << CoupledNode->YCoordinate() << " )" << endl ;
964 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
965 const InPort * anInPort = GetNodeInPort( i ) ;
966 if ( anInPort->IsBus() ) {
967 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
968 f << Name() << ".BusPorts( '" << anInPort->PortName() << "' , '"
969 << anInPort->PortType() << "' , '" << anOutPort->PortName()
970 << "' , '" << anOutPort->PortType() << "' )" << endl ;
978 void GraphBase::ComputingNode::NodeInfo(ostrstream & s) const {
981 ListPorts( s , true ) ;
985 ostream & operator<< (ostream & f,const GraphBase::ComputingNode & G) {
986 // f << "ComponentName " << G.ComponentName() << endl ;
987 if ( G.IsComputingNode() )
988 f << "NodeName " << G.Name() << endl ;
990 f << "DataFlowName " << G.Name() << endl ;
991 f << "Kind " << G.Kind() << endl ;
992 f << "Service " << *G.GetService() ;
993 f << "FirstCreation " << G.FirstCreation () << endl ;
994 f << "LastModification " << G.LastModification() << endl ;
995 f << "EditorRelease " << G.EditorRelease() << endl ;
996 f << "Author " << G.Author() << endl ;
997 // f << "Computer " << G.Computer() << endl ;
998 f << "Comment " << G.Comment() << endl ;
1004 void GraphBase::ComputingNode::ListLinks(ostream &f ) const {
1006 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1007 const GraphBase::OutPort* fromPort = GetNodeOutPort( i ) ;
1008 if ( fromPort->IsPortConnected() ) {
1010 for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
1012 f << "FromNode " << Name() << endl ;
1013 f << " FromServiceParameterName "
1014 << fromPort->GetServicesParameter().Parametername ;
1015 const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
1016 f << " ToNode " << toPort->NodeName() ;
1017 f << " ToServiceParameterName "
1018 << toPort->GetServicesParameter().Parametername;
1020 fromPort->StringValue( f ) ;
1027 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D) {
1028 // cdebug_in << "operator<< GraphEditor::Date" << endl;
1030 fOut << D.Day << "/"
1037 // cdebug_out << "operator<< GraphEditor::Date" << endl;