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 // cout << "GraphBase::ComputingNode::HasInput theInPort " << thePort << " " << thePort->PortName() << " of "
361 // << thePort->NodeName() << " IsDataConnected " << thePort->IsDataConnected() << " OutPort "
362 // << thePort->GetOutPort() << endl ;
363 RetVal = thePort->IsDataConnected() ;
366 const GraphBase::OutPort * thePort = GetOutPort( ToServiceParameterName ) ;
368 RetVal = thePort->IsDataConnected() ;
374 GraphBase::SNode * GraphBase::ComputingNode::GetInfo() {
375 cdebug_in << "GraphBase::ComputingNode::GetInfo" << endl;
376 GraphBase::SNode * Info = new GraphBase::SNode ;
377 // Info->theComponentName = ComponentName() ;
378 // Info->theInterfaceName = InterfaceName() ;
379 Info->theName = Name() ;
380 Info->theKind = Kind() ;
381 Info->theService = *GetService() ;
382 // Info->theListOfParameters = *GetListOfParameters() ;
383 Info->theFirstCreation = FirstCreation() ;
384 Info->theLastModification = LastModification() ;
385 Info->theEditorRelease = EditorRelease() ;
386 Info->theAuthor = Author() ;
387 // Info->theContainer = Computer() ;
388 Info->theComment = Comment() ;
389 Info->theCoords.theX = GraphBase::ComputingNode::XCoordinate() ;
390 Info->theCoords.theY = GraphBase::ComputingNode::YCoordinate() ;
391 cdebug_out << "GraphBase::ComputingNode::GetInfo" << endl;
395 GraphBase::InPort * GraphBase::ComputingNode::AddInPort( const char * InputParameterName ,
396 const char * InputParameterType ) {
397 return GraphBase::PortsOfNode::AddInPort( _ORB , NamePtr() ,
401 _Graph_prof_debug , _Graph_fdebug ) ;
403 GraphBase::OutPort * GraphBase::ComputingNode::AddOutPort( const char * OutputParameterName ,
404 const char * OutputParameterType ) {
405 return GraphBase::PortsOfNode::AddOutPort( _ORB , NamePtr() ,
407 OutputParameterName ,
408 OutputParameterType ,
409 _Graph_prof_debug , _Graph_fdebug ) ;
412 void GraphBase::ComputingNode::AddLink( GraphBase::ComputingNode * ToNode ) {
413 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
415 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
416 << " ) new LinkedNode " << endl ;
417 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
418 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
419 _LinkedNodes[ _LinkedNodesSize ] = ToNode ;
420 _LinkedInPortsNumber[ _LinkedNodesSize ] = 1 ;
421 SetLinkedNodeIndex( ToNode->Name() , _LinkedNodesSize ) ;
422 index = _LinkedNodesSize ;
426 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
427 << " ) old LinkedNode " << _LinkedNodes[index ]->Name() << endl ;
428 _LinkedInPortsNumber[ index ] += 1 ;
430 cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
431 << " ) LinkedNodesSize " << _LinkedNodesSize << " [ " << index
432 << " ] _LinkedInPortsNumber " << _LinkedInPortsNumber[ index ]
433 << " ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
434 << " + 1 Service " << ServiceName() << endl ;
435 ToNode->IncrConnectedInPortsNumber() ;
438 void GraphBase::ComputingNode::RemoveLink( GraphBase::ComputingNode * ToNode ) {
439 int index = GetLinkedNodeIndex( ToNode->Name() ) ;
441 cdebug << "GraphBase::ComputingNode::RemoveLink( to " << ToNode->Name() << " from "
442 << Name() << " index : " << index << " ConnectedInPortsNumber "
443 << ToNode->ConnectedInPortsNumber() - 1 << " LinkedInPortsNumber "
444 << _LinkedInPortsNumber[ index ] << " - 1" << endl ;
445 ToNode->DecrConnectedInPortsNumber() ;
446 _LinkedInPortsNumber[ index ] -= 1 ;
447 if ( _LinkedInPortsNumber[ index ] == 0 ) {
449 cdebug << "GraphBase::ComputingNode::RemoveLink new LinkedNodesSize "
450 << _LinkedNodesSize << " " << ToNode->Name() << " removed from "
451 << " linkednodes of " << Name() << endl ;
453 for ( i = index ; i < _LinkedNodesSize ; i++ ) {
454 _LinkedNodes[ i ] = _LinkedNodes[ i+1 ] ;
455 _LinkedInPortsNumber[ i ] = _LinkedInPortsNumber[ i+1 ] ;
456 SetLinkedNodeIndex( _LinkedNodes[ i ]->Name() , i ) ;
458 DelLinkedNodeIndex( ToNode->Name() ) ;
459 _LinkedNodes.resize( _LinkedNodesSize+1 ) ;
460 _LinkedInPortsNumber.resize( _LinkedNodesSize+1 ) ;
464 cdebug << " Error index " << index << endl ;
468 void GraphBase::ComputingNode::ReNameLink( const char* OldNodeName ,
469 const char* NewNodeName ) {
470 cdebug_in << "GraphBase::ComputingNode::ReNameLink (" << OldNodeName << " , "
471 << NewNodeName << ")" << endl;
472 int index = GetLinkedNodeIndex( OldNodeName ) ;
474 _MapOfLinkedNodes.erase( OldNodeName ) ;
475 SetLinkedNodeIndex( NewNodeName , index ) ;
477 cdebug_out << "GraphBase::ComputingNode::ReNameLink" << endl ;
480 #include <sys/time.h>
481 #include <sys/resource.h>
484 const long GraphBase::ComputingNode::CpuUsed() {
485 struct rusage usage ;
486 if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) {
487 perror("GraphBase::CpuUsed") ;
490 // return usage.ru_utime.__time_t tv_sec ;
491 cdebug << "CpuUsed " << usage.ru_utime.tv_sec << " " << usage.ru_utime.tv_usec << " "
492 << usage.ru_stime.tv_sec << " " << usage.ru_stime.tv_usec << endl ;
493 return usage.ru_utime.tv_sec ;
497 const GraphBase::ListOfParameters * GraphBase::ComputingNode::GetListOfParameters() const {
498 GraphBase::ListOfParameters * aListOfParameters = new GraphBase::ListOfParameters ;
499 if ( IsInLineNode() || IsGOTONode() ) {
501 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
502 const InPort * anInPort = GetNodeInPort( i ) ;
503 if ( anInPort->IsBus() ) {
504 int size = aListOfParameters->size() ;
505 aListOfParameters->resize( size + 1 ) ;
506 (*aListOfParameters)[size].theInParameter.Parametername = anInPort->PortName() ;
507 (*aListOfParameters)[size].theInParameter.Parametertype = anInPort->PortType() ;
508 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
509 (*aListOfParameters)[size].theOutParameter.Parametername = anOutPort->PortName() ;
510 (*aListOfParameters)[size].theOutParameter.Parametertype = anOutPort->PortType() ;
514 return aListOfParameters ;
518 bool GraphBase::ComputingNode::SaveXML( QDomDocument & Graph , QDomElement & info ,
519 const char * ComponentName ,
520 const char * InterfaceName ,
521 const char * Computer ,
522 const char * CoupledNode ,
523 const ListOfFuncName FuncNames ,
524 const ListOfPythonFunctions PythonFunctions ,
525 int XCoordinate , int YCoordinate ) const {
526 QDomElement node = Graph.createElement( "node" ) ;
527 info.appendChild( node ) ;
528 QDomElement componentname = Graph.createElement( "component-name" ) ;
530 if ( strlen( ComponentName ) ) {
531 // f << Tabs << "<component-name>" << ComponentName << "</component-name>"
533 // componentname.setNodeValue( ComponentName ) ;
534 aField = Graph.createTextNode( ComponentName ) ;
537 // f << Tabs << "<component-name>?</component-name>" << endl ;
538 // componentname.setNodeValue( "?" ) ;
539 aField = Graph.createTextNode( "?" ) ;
541 node.appendChild( componentname ) ;
542 componentname.appendChild( aField ) ;
544 QDomElement interfacename = Graph.createElement("interface-name") ;
545 if ( strlen( InterfaceName ) ) {
546 // f << Tabs << "<interface-name>" << InterfaceName << "</interface-name>"
548 // interfacename.setAttribute("name" , InterfaceName ) ;
549 aField = Graph.createTextNode( InterfaceName ) ;
552 // f << Tabs << "<interface-name>?</interface-name>" << endl ;
553 // interfacename.setAttribute("name" , "?" ) ;
554 aField = Graph.createTextNode( "?" ) ;
556 node.appendChild(interfacename) ;
557 interfacename.appendChild( aField ) ;
559 // f << Tabs << "<node-name>" << Name() << "</node-name>" << endl ;
560 QDomElement nodename = Graph.createElement("node-name") ;
561 aField = Graph.createTextNode( Name() ) ;
562 node.appendChild( nodename ) ;
563 nodename.appendChild( aField ) ;
565 // f << Tabs << "<kind>" << (int ) Kind() << "</kind>" << endl ;
566 QDomElement kind = Graph.createElement( "kind" ) ;
568 aKind = aKind.setNum( Kind() ) ;
569 aField = Graph.createTextNode( aKind ) ;
570 node.appendChild( kind ) ;
571 kind.appendChild( aField ) ;
573 QDomElement couplednode = Graph.createElement("coupled-node") ;
574 if ( IsGOTONode() || IsLoopNode() || IsEndLoopNode() ||
575 IsSwitchNode() || IsEndSwitchNode() ) {
576 // f << Tabs << "<coupled-node>" << CoupledNode << "</coupled-node>"
578 aField = Graph.createTextNode( CoupledNode ) ;
581 // f << Tabs << "<coupled-node>?</coupled-node>" << endl ;
582 aField = Graph.createTextNode( "?" ) ;
584 node.appendChild(couplednode) ;
585 couplednode.appendChild( aField ) ;
587 // f << Tabs << "<service>" << endl ;
588 QDomElement service = Graph.createElement("service") ;
589 node.appendChild(service) ;
590 QDomElement servicename = Graph.createElement("service-name") ;
591 if ( strlen( ServiceName() ) ) {
592 // f << Tabs << " <service-name>" << ServiceName() << "</service-name>" << endl ;
593 aField = Graph.createTextNode( ServiceName() ) ;
596 // f << Tabs << " <service-name>?</service-name>" << endl ;
597 aField = Graph.createTextNode( "?" ) ;
599 service.appendChild(servicename) ;
600 servicename.appendChild( aField ) ;
602 // f << Tabs << " <inParameter-list>" << endl ;
603 QDomElement inParameterlist = Graph.createElement("inParameter-list") ;
604 service.appendChild(inParameterlist) ;
606 for ( i = 0 ; i < ServiceInParameter().length() ; i++ ) {
607 // f << Tabs << " <inParameter>" << endl ;
608 QDomElement inParameter = Graph.createElement("inParameter") ;
609 inParameterlist.appendChild(inParameter) ;
610 // f << Tabs << " <inParameter-type>"
611 // << ServiceInParameter()[i].Parametertype << "</inParameter-type>"
613 QDomElement inParametertype = Graph.createElement("inParameter-type") ;
614 // mpv: Linux 8.0 compiler compatibility
615 // aField = Graph.createTextNode( (char *)ServiceInParameter()[i].Parametertype ) ;
616 if ( strlen( ServiceInParameter()[i].Parametertype ) ) {
617 aField = Graph.createTextNode( strdup( ServiceInParameter()[i].Parametertype ) ) ;
620 aField = Graph.createTextNode( "?" ) ;
622 inParameter.appendChild(inParametertype) ;
623 inParametertype.appendChild( aField ) ;
624 // f << Tabs << " <inParameter-name>"
625 // << ServiceInParameter()[i].Parametername << "</inParameter-name>"
627 QDomElement inParametername = Graph.createElement("inParameter-name") ;
628 // mpv: Linux 8.0 compiler compatibility
629 // aField = Graph.createTextNode( (char *) ServiceInParameter()[i].Parametername ) ;
630 if ( strlen( ServiceInParameter()[i].Parametername ) ) {
631 aField = Graph.createTextNode( strdup(ServiceInParameter()[i].Parametername) ) ;
634 aField = Graph.createTextNode( "?" ) ;
636 inParameter.appendChild(inParametername) ;
637 inParametername.appendChild( aField ) ;
638 // f << Tabs << " </inParameter>" << endl ;
640 // f << Tabs << " </inParameter-list>" << endl ;
641 // f << Tabs << " <outParameter-list>" << endl ;
642 QDomElement outParameterlist = Graph.createElement("outParameter-list") ;
643 service.appendChild(outParameterlist) ;
644 for ( i = 0 ; i < ServiceOutParameter().length() ; i++ ) {
645 // f << Tabs << " <outParameter>" << endl ;
646 QDomElement outParameter = Graph.createElement("outParameter") ;
647 outParameterlist.appendChild(outParameter) ;
648 // f << Tabs << " <outParameter-type>"
649 // << ServiceOutParameter()[i].Parametertype << "</outParameter-type>"
651 QDomElement outParametertype = Graph.createElement("outParameter-type") ;
652 // mpv: Linux 8.0 compiler compatibility
653 // aField = Graph.createTextNode( (char *) ServiceOutParameter()[i].Parametertype ) ;
654 if ( strlen( ServiceOutParameter()[i].Parametertype ) ) {
655 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametertype) ) ;
658 aField = Graph.createTextNode( "?" ) ;
660 outParameter.appendChild(outParametertype) ;
661 outParametertype.appendChild( aField ) ;
662 // f << Tabs << " <outParameter-name>"
663 // << ServiceOutParameter()[i].Parametername << "</outParameter-name>"
665 QDomElement outParametername = Graph.createElement("outParameter-name") ;
666 // mpv: Linux 8.0 compiler compatibility
667 // aField = Graph.createTextNode( (char *) ServiceOutParameter()[i].Parametername ) ;
668 if ( strlen( ServiceOutParameter()[i].Parametername ) ) {
669 aField = Graph.createTextNode( strdup(ServiceOutParameter()[i].Parametername) ) ;
672 aField = Graph.createTextNode( "?" ) ;
674 outParameter.appendChild(outParametername) ;
675 outParametername.appendChild( aField ) ;
676 // f << Tabs << " </outParameter>" << endl ;
678 // f << Tabs << " </outParameter-list>" << endl ;
679 // f << Tabs << "</service>" << endl ;
681 // f << Tabs << "<Parameter-list>" << endl ;
682 QDomElement Parameterlist = Graph.createElement("Parameter-list") ;
683 node.appendChild( Parameterlist ) ;
685 if ( IsInLineNode() || IsGOTONode() ||
686 IsLoopNode() || IsEndLoopNode() ||
687 IsSwitchNode() || IsEndSwitchNode() ) {
689 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
690 const InPort * anInPort = GetNodeInPort( i ) ;
691 if ( anInPort->IsBus() ) {
692 f << Tabs << " <inParameter>" << endl ;
693 f << Tabs << " <inParameter-type>"
694 << anInPort->PortType() << "</inParameter-type>"
696 f << Tabs << " <inParameter-name>"
697 << anInPort->PortName() << "</inParameter-name>"
699 f << Tabs << " </inParameter>" << endl ;
700 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
701 f << Tabs << " <outParameter>" << endl ;
702 f << Tabs << " <outParameter-type>"
703 << anOutPort->PortType() << "</outParameter-type>"
705 f << Tabs << " <outParameter-name>"
706 << anOutPort->PortName() << "</outParameter-name>"
708 f << Tabs << " </outParameter>" << endl ;
713 // f << Tabs << "</Parameter-list>" << endl ;
715 // f << Tabs << "<PyFunction-list>" << endl ;
716 QDomElement PyFunctionlist = Graph.createElement("PyFunction-list") ;
717 node.appendChild( PyFunctionlist ) ;
718 for ( i = 0 ; i < PythonFunctions.size() ; i++ ) {
719 // f << Tabs << " <PyFunction>" << endl ;
720 QDomElement PyFunction = Graph.createElement("PyFunction") ;
721 PyFunctionlist.appendChild( PyFunction ) ;
723 QDomElement FuncName = Graph.createElement("FuncName") ;
724 if ( strlen( FuncNames[i].c_str() ) ) {
725 aField = Graph.createTextNode( FuncNames[i].c_str() ) ;
728 aField = Graph.createTextNode( "?" ) ;
730 PyFunction.appendChild( FuncName ) ;
731 FuncName.appendChild( aField ) ;
732 if ( (*PythonFunctions[i]).length() ) {
733 for ( j = 0 ; j < (int ) (*PythonFunctions[i]).length() ; j++ ) {
734 QDomElement PyFunc = Graph.createElement("PyFunc") ;
735 QDomCDATASection aCDATA ;
736 // mpv: Linux 8.0 compiler compatibility
737 char * aCDATAChar = strdup ((*PythonFunctions[i])[j]) ;
739 for ( i = 0 ; i < (int ) strlen( aCDATAChar ) ; i++ ) {
740 if ( aCDATAChar[ i ] != ' ' ) {
744 if ( i == (int ) strlen( aCDATAChar ) ) {
745 aCDATA = Graph.createCDATASection( "?" ) ;
748 aCDATA = Graph.createCDATASection( aCDATAChar ) ;
750 PyFunction.appendChild( PyFunc ) ;
751 PyFunc.appendChild( aCDATA ) ;
755 QDomElement PyFunc = Graph.createElement("PyFunc") ;
756 QDomCDATASection aCDATA = Graph.createCDATASection( "?" ) ;
757 PyFunction.appendChild( PyFunc ) ;
758 PyFunc.appendChild( aCDATA ) ;
762 // f << Tabs << "<creation-date>" << FirstCreation() << "</creation-date>"
764 QDomElement creationdate = Graph.createElement("creation-date") ;
766 sprintf( fdate , "%d/%d/%d - %d:%d:%d" , FirstCreation().Day , FirstCreation().Month , FirstCreation().Year , FirstCreation().Hour , FirstCreation().Minute , FirstCreation().Second ) ;
767 aField = Graph.createTextNode( fdate ) ;
768 node.appendChild( creationdate ) ;
769 creationdate.appendChild( aField ) ;
770 // f << Tabs << "<lastmodification-date>" << LastModification()
771 // << "</lastmodification-date>" << endl ;
772 QDomElement lastmodificationdate = Graph.createElement("lastmodification-date") ;
774 sprintf( ldate , "%d/%d/%d - %d:%d:%d" , LastModification().Day , LastModification().Month , LastModification().Year , LastModification().Hour , LastModification().Minute , LastModification().Second ) ;
775 aField = Graph.createTextNode( ldate ) ;
776 node.appendChild( lastmodificationdate ) ;
777 lastmodificationdate.appendChild( aField ) ;
778 // f << Tabs << "<editor-release>" << EditorRelease() << "</editor-release>"
780 QDomElement editorrelease = Graph.createElement("editor-release") ;
781 aField = Graph.createTextNode( EditorRelease() ) ;
782 node.appendChild( editorrelease ) ;
783 editorrelease.appendChild( aField ) ;
784 QDomElement author = Graph.createElement("author") ;
785 if ( strlen( Author() ) ) {
786 // f << Tabs << "<author>" << Author() << "</author>" << endl ;
787 aField = Graph.createTextNode( Author() ) ;
790 // f << Tabs << "<author>?</author>" << endl ;
791 aField = Graph.createTextNode( "?" ) ;
793 node.appendChild( author ) ;
794 author.appendChild( aField ) ;
795 QDomElement container = Graph.createElement("container") ;
796 if ( IsFactoryNode() && strlen( Computer) ) {
797 // f << Tabs << "<container>" << Computer << "</container>" << endl ;
798 aField = Graph.createTextNode( Computer ) ;
801 // f << Tabs << "<container>?</container>" << endl ;
802 aField = Graph.createTextNode( "?" ) ;
804 node.appendChild( container ) ;
805 container.appendChild( aField ) ;
806 QDomElement comment = Graph.createElement("comment") ;
807 if ( strlen( Comment() ) ) {
808 // f << Tabs << "<comment>" << Comment() << "</comment>" << endl ;
809 aField = Graph.createTextNode( Comment() ) ;
812 // f << Tabs << "<comment>?</comment>" << endl ;
813 aField = Graph.createTextNode( "?" ) ;
815 node.appendChild( comment ) ;
816 comment.appendChild( aField ) ;
817 // f << Tabs << "<x-position>" << XCoordinate << "</x-position>" << endl ;
818 QDomElement xposition = Graph.createElement("x-position") ;
819 QString aXCoordinate ;
820 aXCoordinate = aKind.setNum( XCoordinate ) ;
821 aField = Graph.createTextNode( aXCoordinate ) ;
822 node.appendChild( xposition ) ;
823 xposition.appendChild( aField ) ;
824 // f << Tabs << "<y-position>" << YCoordinate << "</y-position>" << endl ;
825 QDomElement yposition = Graph.createElement("y-position") ;
826 QString aYCoordinate ;
827 aYCoordinate = aKind.setNum( YCoordinate ) ;
828 aField = Graph.createTextNode( aYCoordinate ) ;
829 node.appendChild( yposition ) ;
830 yposition.appendChild( aField ) ;
834 bool GraphBase::ComputingNode::SavePY( ostream &f , const char * aGraphName ,
835 const char * ComponentName ,
836 const char * InterfaceName ,
837 const char * Computer ,
838 const GraphBase::InLineNode * aCoupledNode ,
839 const ListOfFuncName FuncNames ,
840 const ListOfPythonFunctions PythonFunctions ,
841 int XCoordinate , int YCoordinate ) const {
842 if ( IsDataFlowNode() ) {
843 f << Name() << " = Graph( '" << Name() << "' )" << endl ;
845 else if ( IsComputingNode() ) {
847 f << Name() << "_ServiceinParameter = []" << endl ;
848 for ( i = 0 ; i < (int ) ServiceInParameter().length() ; i++ ) {
849 f << Name() << "_ServiceinParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
850 << ServiceInParameter()[i].Parametertype << "' , '"
851 << ServiceInParameter()[i].Parametername << "' ) )" << endl ;
853 f << Name() << "_ServiceoutParameter = []" << endl ;
854 for ( i = 0 ; i < (int ) ServiceOutParameter().length() ; i++ ) {
855 f << Name() << "_ServiceoutParameter.append( SALOME_ModuleCatalog.ServicesParameter( '"
856 << ServiceOutParameter()[i].Parametertype << "' , '"
857 << ServiceOutParameter()[i].Parametername << "' ) )" << endl ;
859 f << Name() << "_Service = SALOME_ModuleCatalog.Service( '" << ServiceName()
860 << "' , " << Name() << "_ServiceinParameter" << " , "
861 << Name() << "_ServiceoutParameter" << " , 0 )" << endl ;
862 f << Name() << " = " << aGraphName << ".CNode( " << Name() << "_Service" << " )"
865 else if ( IsFactoryNode() ) {
866 f << Name() << " = " << aGraphName << ".FNode( '" << ComponentName
867 << "' , '" << InterfaceName << "' , '" << ServiceName() << "' )"
871 f << "Py" << Name() << " = []" << endl ;
873 SUPERV::ListOfStrings aPyFunc ;
874 if ( PythonFunctions.size() ) {
875 aPyFunc = *PythonFunctions[0] ;
876 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
877 f << "Py" << Name() << ".append( '" << aPyFunc[i] << "' )" << endl ;
880 if ( IsInLineNode() ) {
881 f << Name() << " = " << aGraphName << ".INode( '" << FuncNames[0].c_str() << "' , Py"
882 << Name() << " )" << endl ;
884 else if ( IsGOTONode() ) {
885 if ( aCoupledNode ) {
886 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
887 << Name() << " , '" << aCoupledNode->Name() << "' )" << endl ;
890 f << Name() << " = " << aGraphName << ".GNode( '" << FuncNames[0].c_str() << "' , Py"
891 << Name() << " , '' )" << endl ;
895 // char * EndName = NULL ;
896 // EndName = new char[ 3 + strlen( Name() ) + 1 ] ;
897 // strcpy( EndName , "End" ) ;
898 // strcat( EndName , Name() ) ;
899 char * EndName = aCoupledNode->Name() ;
900 if ( IsLoopNode() ) {
901 SUPERV::ListOfStrings aPyMore = *PythonFunctions[1] ;
902 SUPERV::ListOfStrings aPyNext = *PythonFunctions[2] ;
903 f << "PyMore" << Name() << " = []" << endl ;
904 for ( i = 0 ; i < (int ) aPyMore.length() ; i++ ) {
905 f << "PyMore" << Name() << ".append( '" << aPyMore[i] << "' )" << endl ;
907 f << "PyNext" << Name() << " = []" << endl ;
908 for ( i = 0 ; i < (int ) aPyNext.length() ; i++ ) {
909 f << "PyNext" << Name() << ".append( '" << aPyNext[i] << "' )" << endl ;
911 f << Name() << "," << EndName << " = " << aGraphName << ".LNode( '"
912 << FuncNames[0].c_str() << "' , Py" << Name() << " , '"
913 << FuncNames[1].c_str() << "' , PyMore" << Name()
914 << " , '" << FuncNames[2].c_str() << "' , PyNext"
915 << Name() << " )" << endl ;
916 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
917 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
918 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
919 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
920 << aCoupledNode->YCoordinate() << " )" << endl ;
921 SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
922 f << "Py" << aCoupledNode->Name() << " = []" << endl ;
923 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
924 f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
927 f << EndName << ".SetPyFunction( 'End" << FuncNames[0].c_str() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
929 else if ( IsSwitchNode() ) {
930 f << Name() << "," << EndName << " = " << aGraphName << ".SNode( '"
931 << FuncNames[0].c_str() << "' , Py" << Name() << " )" << endl ;
932 f << EndName << ".SetName( '" << aCoupledNode->Name() << "' )" << endl ;
933 f << EndName << ".SetAuthor( '" << aCoupledNode->Author() << "' )" << endl ;
934 f << EndName << ".SetComment( '" << aCoupledNode->Comment() << "' )" << endl ;
935 f << EndName << ".Coords( " << aCoupledNode->XCoordinate() << " , "
936 << aCoupledNode->YCoordinate() << " )" << endl ;
937 SUPERV::ListOfStrings aPyFunc = *aCoupledNode->PythonFunction() ;
938 f << "Py" << aCoupledNode->Name() << " = []" << endl ;
939 for ( i = 0 ; i < (int ) aPyFunc.length() ; i++ ) {
940 f << "Py" << aCoupledNode->Name() << ".append( '" << aPyFunc[i] << "' )"
943 f << EndName << ".SetPyFunction( 'End" << FuncNames[0].c_str() << "' , Py" << aCoupledNode->Name() << " )" << endl ;
944 for ( i = 0 ; i < aCoupledNode->GetNodeInPortsSize() ; i++ ) {
945 const GraphBase::InPort * anInPort = aCoupledNode->GetNodeInPort(i) ;
946 if ( anInPort->IsInLine() || anInPort->IsEndSwitch() ) {
947 f << EndName << ".InPort( '" << anInPort->PortName()
948 << "' , '" << anInPort->PortType() << "' )" << endl ;
951 for ( i = 0 ; i < aCoupledNode->GetNodeOutPortsSize() ; i++ ) {
952 const GraphBase::OutPort * anOutPort = aCoupledNode->GetNodeOutPort(i) ;
953 if ( anOutPort->IsInLine() ) {
954 f << EndName << ".OutPort( '" << anOutPort->PortName()
955 << "' , '" << anOutPort->PortType() << "' )" << endl ;
963 f << Name() << ".SetName( '" << Name() << "' )" << endl ;
964 f << Name() << ".SetAuthor( '" << Author() << "' )" << endl ;
965 if ( IsFactoryNode() ) {
966 f << Name() << ".SetContainer( '" << Computer << "' )" << endl ;
968 f << Name() << ".SetComment( '" << Comment() << "' )" << endl ;
969 f << Name() << ".Coords( " << XCoordinate << " , " << YCoordinate << " )" << endl ;
971 if ( IsOneOfInLineNodes() ) {
973 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
974 const GraphBase::InPort * anInPort = GetNodeInPort(i) ;
975 if ( anInPort->IsInLine() ) {
976 f << Name() << ".InPort( '" << anInPort->PortName() << "' , '"
977 << anInPort->PortType() << "' )" << endl ;
980 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
981 const GraphBase::OutPort * anOutPort = GetNodeOutPort(i) ;
982 if ( anOutPort->IsInLine() || anOutPort->IsSwitch() ) {
983 f << Name() << ".OutPort( '" << anOutPort->PortName()
984 << "' , '" << anOutPort->PortType() << "' )" << endl ;
990 if ( IsLoopNode() || IsSwitchNode() ) {
991 f << EndName << ".SetName( '" << CoupledNode
993 f << EndName << ".SetAuthor( '" << CoupledNode->Author()
995 f << EndName << ".SetComment( '" << CoupledNode->Comment()
997 f << EndName << ".Coords( " << CoupledNode->XCoordinate() << " , "
998 << CoupledNode->YCoordinate() << " )" << endl ;
1000 for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
1001 const InPort * anInPort = GetNodeInPort( i ) ;
1002 if ( anInPort->IsBus() ) {
1003 const OutPort * anOutPort = GetNodeOutPort( anInPort->PortIndex() ) ;
1004 f << Name() << ".BusPorts( '" << anInPort->PortName() << "' , '"
1005 << anInPort->PortType() << "' , '" << anOutPort->PortName()
1006 << "' , '" << anOutPort->PortType() << "' )" << endl ;
1014 void GraphBase::ComputingNode::NodeInfo(ostream & s) const {
1016 ListPorts( s , true ) ;
1020 ostream & operator<< (ostream & f,const GraphBase::ComputingNode & G) {
1021 // f << "ComponentName " << G.ComponentName() << endl ;
1022 if ( G.IsComputingNode() )
1023 f << "NodeName " << G.Name() << endl ;
1025 f << "DataFlowName " << G.Name() << endl ;
1026 f << "Kind " << G.Kind() << endl ;
1027 f << "Service " << *G.GetService() ;
1028 f << "FirstCreation " << G.FirstCreation () << endl ;
1029 f << "LastModification " << G.LastModification() << endl ;
1030 f << "EditorRelease " << G.EditorRelease() << endl ;
1031 f << "Author " << G.Author() << endl ;
1032 // f << "Computer " << G.Computer() << endl ;
1033 f << "Comment " << G.Comment() << endl ;
1039 void GraphBase::ComputingNode::ListLinks(ostream &f ) const {
1041 for ( i = 0 ; i < GetNodeOutPortsSize() ; i++ ) {
1042 const GraphBase::OutPort* fromPort = GetNodeOutPort( i ) ;
1043 if ( fromPort->IsPortConnected() ) {
1045 for ( j = 0 ; j < fromPort->InPortsSize() ; j++ ) {
1047 f << "FromNode " << Name() << endl ;
1048 f << " FromServiceParameterName "
1049 << fromPort->GetServicesParameter().Parametername ;
1050 const GraphBase::InPort* toPort = fromPort->InPorts( j ) ;
1051 f << " ToNode " << toPort->NodeName() ;
1052 f << " ToServiceParameterName "
1053 << toPort->GetServicesParameter().Parametername;
1055 fromPort->StringValue( f ) ;
1062 ostream & operator<< (ostream &fOut,const SUPERV::SDate &D) {
1063 // cdebug_in << "operator<< GraphEditor::Date" << endl;
1065 fOut << D.Day << "/"
1072 // cdebug_out << "operator<< GraphEditor::Date" << endl;