Salome HOME
End of developpement/test of Switch Python Nodes
[modules/superv.git] / src / GraphBase / DataFlowBase_EndOfSwitchNode.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : DataFlowBase_EndOfSwitchNode.cxx
8 //  Author : Jean Rahuel, CEA
9 //  Module : SUPERV
10 //  $Header:
11
12 using namespace std;
13 //#include <sstream>
14 //#include <iostream>
15
16 #include "DataFlowBase_EndOfSwitchNode.hxx"
17
18 GraphBase::EndOfSwitchNode::EndOfSwitchNode() :
19   GraphBase::GOTONode::GOTONode() {
20
21   cdebug << "GraphBase::EndOfSwitchNode::EndOfSwitchNode "  << this 
22          << " _Name " << (void *) Name() << " " << Name() << " _Comment "
23          << (void *) Comment() << " "  << Comment() << " "  << endl ;
24
25 }
26
27 GraphBase::EndOfSwitchNode::EndOfSwitchNode( CORBA::ORB_ptr ORB ,
28                                    SALOME_NamingService* ptrNamingService ,
29                                    const char * FuncName ,
30                                    const SUPERV::ListOfStrings & aPythonFunction ,
31                                    const char *NodeName ,
32                                    const SUPERV::KindOfNode akind ,
33                                    const SUPERV::SDate NodeFirstCreation ,
34                                    const SUPERV::SDate NodeLastModification  ,
35                                    const char * NodeEditorRelease ,
36                                    const char * NodeAuthor ,
37                                    const char * NodeComment ,
38                                    const bool   GeneratedName ,
39                                    const long   X ,
40                                    const long   Y ,
41                                    int * Graph_prof_debug ,
42                                    ofstream * Graph_fdebug ) :
43   GraphBase::GOTONode::GOTONode( ORB , ptrNamingService , FuncName ,
44                                  aPythonFunction ,
45                                  NodeName , akind , NodeFirstCreation ,
46                                  NodeLastModification  , NodeEditorRelease ,
47                                  NodeAuthor , NodeComment , GeneratedName ,
48                                  X , Y , Graph_prof_debug , Graph_fdebug ) {
49
50   cdebug_in << "GraphBase::EndOfSwitchNode::EndOfSwitchNode "  << this 
51             << "' _Name " << (void *) Name() << " '" << Name() << " _Comment "
52             << (void *) Comment() << " "  << Comment() << " " 
53             << " KindOfNode " << Kind() << " FuncName " << FuncName
54             << " ServiceName " << ServiceName() << " In("
55             << ServiceInParameter().length()
56             << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
57
58   cdebug_out << "GraphBase::EndOfSwitchNode::EndOfSwitchNode" << endl;
59 }
60
61 GraphBase::EndOfSwitchNode::~EndOfSwitchNode() {
62   cdebug << "GraphBase::EndOfSwitchNode::~EndOfSwitchNode "  << this 
63          << " _Name " << (void *) Name() << " " << Name() << " _Comment "
64          << (void *) Comment() << " "  << Comment() << " "  << endl ;
65 //  if ( _ComponentName != NULLSTRING )
66 //    delete [] _ComponentName ;
67 //  delete [] _Name ;
68 //  delete [] _EditorRelease ;
69 //  if ( _Author != NULLSTRING )
70 //    delete [] _Author ;
71 //  if ( _Computer != FACTORYSERVER )
72 //    delete [] _Computer;
73 //  if ( _Comment != NULLSTRING )
74 //    delete [] _Comment;
75 }
76
77 void GraphBase::EndOfSwitchNode::InitEndSwitchInPortLinked() { // without StreamInPorts
78   cdebug << "Base::EndOfSwitchNode::InitEndSwitchInPortLinked of " << Name() << endl ;
79 //JR 06.07.2005 : the InGatePort(Default) must also be counted (enhancement) ...
80 //           _EndSwitchInPortLinkedNumber = GetNodeInPortsSize() - DataStreamInPortsNumber() - 1 ;
81   _EndSwitchInPortLinkedNumber = GetNodeInPortsSize() - DataStreamInPortsNumber() ;
82   _SwitchWithGOTO = false ;
83   int i ;
84 //JR 06.07.2005 : the InGatePort must also be counted (enhancement) ...
85 //  for ( i = 0 ; i < GetNodeInPortsSize()-1 ; i++ ) {
86   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
87     GetChangeNodeInPort( i )->BranchOfSwitchLinked( false ) ;
88   }
89 }
90
91 bool GraphBase::EndOfSwitchNode::DecrEndSwitchInPortLinked( GraphBase::InPort * anInPort ,
92                                                             string & anErrorMessage ) {
93   bool RetVal = true ;
94 //JR 16.02.2005 : except for DefaultPort
95 //JR 06.07.2005 : the InGatePort must also be counted now (enhancement) ...
96 //  if ( !anInPort->IsGate() ) {
97     if ( !anInPort->BranchOfSwitchLinked( true ) ) {
98       cdebug << Name() << "->DecrEndSwitchInPortLinked ERROR " << anInPort->NodeName() << "( "
99              << anInPort->PortName() << " ) was already linked in that branch." << endl ;
100       anErrorMessage = anErrorMessage + string( Name() ) + string( " The port " ) +
101                        string( anInPort->NodeName() ) + string( "( " ) +
102                        string( anInPort->PortName() ) +
103                        string( " ) was already linked in that branch.\n" ) ;
104       RetVal = false ;
105     }
106     _EndSwitchInPortLinkedNumber -= 1 ;
107 //  }
108   cdebug << Name()
109          << "->EndOfSwitchNode::DecrEndSwitchInPortLinked EndSwitchInPortLinkedNumber "
110          << _EndSwitchInPortLinkedNumber << " InPort '" << anInPort->PortName() << "' of "
111          << anInPort->NodeName() << " RetVal " << RetVal << endl ;
112   return RetVal ;
113 }
114
115 bool GraphBase::EndOfSwitchNode::CheckEndSwitchInPortsLinked( string & anErrorMessage ) {
116   bool RetVal = true ;
117   bool DefaultNotLinked = false ;
118 // Check that all inports of the EndSwitchNode are reachable in that branch(es)
119   int i ;
120 //JR 06.07.2005 : the InGatePort must also be counted now (enhancement) ...
121 //  for ( i = 0 ; i < GetNodeInPortsSize()-1 ; i++ ) {
122   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
123     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
124     if ( !anInPort->IsDataStream() && !anInPort->BranchOfSwitchLinked() ) {
125       cdebug << Name() << "->EndOfSwitchNode::CheckEndSwitchInPortsLinked "
126              << anInPort->PortName() << " have no link in that branch"
127              << " SwitchWithGOTO() " << SwitchWithGOTO() << endl ;
128       if ( !SwitchWithGOTO() ) {
129         anErrorMessage = anErrorMessage + string( Name() ) + string( "( " ) +
130                          string( anInPort->PortName() ) +
131                          string( " ) has no link from that branch.\n" ) ;
132         if ( anInPort->IsGate() ) {
133           DefaultNotLinked = true ;
134         }
135         else {
136           RetVal = false ; // that InPort is not linked
137         }
138       }
139     }
140   }
141 // Check that all inports of the EndSwitchNode will have a value only once
142   if ( _EndSwitchInPortLinkedNumber != 0 ) {
143     cdebug << Name()
144            << "->EndOfSwitchNode::CheckEndSwitchInPortsLinked EndSwitchInPortLinkedNumber "
145            << _EndSwitchInPortLinkedNumber << " SwitchWithGOTO() " << SwitchWithGOTO()
146            << " DefaultNotLinked " << DefaultNotLinked << endl ;
147     if ( !SwitchWithGOTO() ) {
148       if ( RetVal && _EndSwitchInPortLinkedNumber == 1 && DefaultNotLinked ) {
149       }
150       else {
151         if ( _EndSwitchInPortLinkedNumber > 0 ) {
152           anErrorMessage = anErrorMessage + string( Name() ) +
153                            string( " has some InPort(s) not linked.\n" ) ;
154         }
155         else {
156           anErrorMessage = anErrorMessage + string( Name() ) +
157                            string( " has some InPort(s) multiply linked.\n" ) ;
158         }
159         RetVal = false ; // Some InPort is not linked or multiply linked
160       }
161     }
162   }
163   return RetVal ;
164 }