Salome HOME
Update copyright information
[modules/superv.git] / src / GraphBase / DataFlowBase_EndOfSwitchNode.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
23 //  File   : DataFlowBase_EndOfSwitchNode.cxx
24 //  Author : Jean Rahuel, CEA
25 //  Module : SUPERV
26 //
27 using namespace std;
28 //#include <sstream>
29 //#include <iostream>
30
31 #include "DataFlowBase_EndOfSwitchNode.hxx"
32
33 GraphBase::EndOfSwitchNode::EndOfSwitchNode() :
34   GraphBase::GOTONode::GOTONode() {
35
36   cdebug << "GraphBase::EndOfSwitchNode::EndOfSwitchNode "  << this 
37          << " _Name " << (void *) Name() << " " << Name() << " _Comment "
38          << (void *) Comment() << " "  << Comment() << " "  << endl ;
39
40 }
41
42 GraphBase::EndOfSwitchNode::EndOfSwitchNode( CORBA::ORB_ptr ORB ,
43                                    SALOME_NamingService* ptrNamingService ,
44                                    const char * FuncName ,
45                                    const SUPERV::ListOfStrings & aPythonFunction ,
46                                    const char *NodeName ,
47                                    const SUPERV::KindOfNode akind ,
48                                    const SUPERV::SDate NodeFirstCreation ,
49                                    const SUPERV::SDate NodeLastModification  ,
50                                    const char * NodeEditorRelease ,
51                                    const char * NodeAuthor ,
52                                    const char * NodeComment ,
53                                    const bool   GeneratedName ,
54                                    const long   X ,
55                                    const long   Y ,
56                                    int * Graph_prof_debug ,
57                                    ofstream * Graph_fdebug ) :
58   GraphBase::GOTONode::GOTONode( ORB , ptrNamingService , FuncName ,
59                                  aPythonFunction ,
60                                  NodeName , akind , NodeFirstCreation ,
61                                  NodeLastModification  , NodeEditorRelease ,
62                                  NodeAuthor , NodeComment , GeneratedName ,
63                                  X , Y , Graph_prof_debug , Graph_fdebug ) {
64
65   cdebug_in << "GraphBase::EndOfSwitchNode::EndOfSwitchNode "  << this 
66             << "' _Name " << (void *) Name() << " '" << Name() << " _Comment "
67             << (void *) Comment() << " "  << Comment() << " " 
68             << " KindOfNode " << Kind() << " FuncName " << FuncName
69             << " ServiceName " << ServiceName() << " In("
70             << ServiceInParameter().length()
71             << ") Out(" << ServiceOutParameter().length() << ")" << endl ;
72
73   cdebug_out << "GraphBase::EndOfSwitchNode::EndOfSwitchNode" << endl;
74 }
75
76 GraphBase::EndOfSwitchNode::~EndOfSwitchNode() {
77   cdebug << "GraphBase::EndOfSwitchNode::~EndOfSwitchNode "  << this 
78          << " _Name " << (void *) Name() << " " << Name() << " _Comment "
79          << (void *) Comment() << " "  << Comment() << " "  << endl ;
80 //  if ( _ComponentName != NULLSTRING )
81 //    delete [] _ComponentName ;
82 //  delete [] _Name ;
83 //  delete [] _EditorRelease ;
84 //  if ( _Author != NULLSTRING )
85 //    delete [] _Author ;
86 //  if ( _Computer != FACTORYSERVER )
87 //    delete [] _Computer;
88 //  if ( _Comment != NULLSTRING )
89 //    delete [] _Comment;
90 }
91
92 void GraphBase::EndOfSwitchNode::InitEndSwitchInPortLinked() { // without StreamInPorts
93   cdebug << "Base::EndOfSwitchNode::InitEndSwitchInPortLinked of " << Name() << endl ;
94 //JR 06.07.2005 : the InGatePort(Default) must also be counted (enhancement) ...
95 //           _EndSwitchInPortLinkedNumber = GetNodeInPortsSize() - DataStreamInPortsNumber() - 1 ;
96   _EndSwitchInPortLinkedNumber = GetNodeInPortsSize() - DataStreamInPortsNumber() ;
97   _SwitchWithGOTO = false ;
98   int i ;
99 //JR 06.07.2005 : the InGatePort must also be counted (enhancement) ...
100 //  for ( i = 0 ; i < GetNodeInPortsSize()-1 ; i++ ) {
101   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
102     GetChangeNodeInPort( i )->BranchOfSwitchLinked( false ) ;
103   }
104 }
105
106 bool GraphBase::EndOfSwitchNode::DecrEndSwitchInPortLinked( GraphBase::InPort * anInPort ,
107                                                             string & anErrorMessage ) {
108   bool RetVal = true ;
109 //JR 16.02.2005 : except for DefaultPort
110 //JR 06.07.2005 : the InGatePort must also be counted now (enhancement) ...
111 //  if ( !anInPort->IsGate() ) {
112     if ( !anInPort->BranchOfSwitchLinked( true ) ) {
113       cdebug << Name() << "->DecrEndSwitchInPortLinked ERROR " << anInPort->NodeName() << "( "
114              << anInPort->PortName() << " ) was already linked in that branch." << endl ;
115       anErrorMessage = anErrorMessage + string( Name() ) + string( " The port " ) +
116                        string( anInPort->NodeName() ) + string( "( " ) +
117                        string( anInPort->PortName() ) +
118                        string( " ) was already linked in that branch.\n" ) ;
119       RetVal = false ;
120     }
121     _EndSwitchInPortLinkedNumber -= 1 ;
122 //  }
123   cdebug << Name()
124          << "->EndOfSwitchNode::DecrEndSwitchInPortLinked EndSwitchInPortLinkedNumber "
125          << _EndSwitchInPortLinkedNumber << " InPort '" << anInPort->PortName() << "' of "
126          << anInPort->NodeName() << " RetVal " << RetVal << endl ;
127   return RetVal ;
128 }
129
130 bool GraphBase::EndOfSwitchNode::CheckEndSwitchInPortsLinked( string & anErrorMessage ) {
131   bool RetVal = true ;
132   bool DefaultNotLinked = false ;
133 // Check that all inports of the EndSwitchNode are reachable in that branch(es)
134   int i ;
135 //JR 06.07.2005 : the InGatePort must also be counted now (enhancement) ...
136 //  for ( i = 0 ; i < GetNodeInPortsSize()-1 ; i++ ) {
137   for ( i = 0 ; i < GetNodeInPortsSize() ; i++ ) {
138     GraphBase::InPort * anInPort = GetChangeNodeInPort( i ) ;
139     if ( !anInPort->IsDataStream() && !anInPort->BranchOfSwitchLinked() ) {
140       cdebug << Name() << "->EndOfSwitchNode::CheckEndSwitchInPortsLinked "
141              << anInPort->PortName() << " have no link in that branch"
142              << " SwitchWithGOTO() " << SwitchWithGOTO() << endl ;
143       if ( !SwitchWithGOTO() ) {
144         anErrorMessage = anErrorMessage + string( Name() ) + string( "( " ) +
145                          string( anInPort->PortName() ) +
146                          string( " ) has no link from that branch.\n" ) ;
147         if ( anInPort->IsGate() ) {
148           DefaultNotLinked = true ;
149         }
150         else {
151           RetVal = false ; // that InPort is not linked
152         }
153       }
154     }
155   }
156 // Check that all inports of the EndSwitchNode will have a value only once
157   if ( _EndSwitchInPortLinkedNumber != 0 ) {
158     cdebug << Name()
159            << "->EndOfSwitchNode::CheckEndSwitchInPortsLinked EndSwitchInPortLinkedNumber "
160            << _EndSwitchInPortLinkedNumber << " SwitchWithGOTO() " << SwitchWithGOTO()
161            << " DefaultNotLinked " << DefaultNotLinked << endl ;
162     if ( !SwitchWithGOTO() ) {
163       if ( RetVal && _EndSwitchInPortLinkedNumber == 1 && DefaultNotLinked ) {
164       }
165       else {
166         if ( _EndSwitchInPortLinkedNumber > 0 ) {
167           anErrorMessage = anErrorMessage + string( Name() ) +
168                            string( " has some InPort(s) not linked.\n" ) ;
169         }
170         else {
171           anErrorMessage = anErrorMessage + string( Name() ) +
172                            string( " has some InPort(s) multiply linked.\n" ) ;
173         }
174         RetVal = false ; // Some InPort is not linked or multiply linked
175       }
176     }
177   }
178   return RetVal ;
179 }