Salome HOME
b1e8324d55301f8ddbc9b7ad9c3e928a341f0388
[modules/superv.git] / src / GraphBase / DataFlowBase_DataNode.cxx
1 //  SUPERV GraphBase : contains fondamental classes for Services, Input Ports, Output Ports Links and Nodes.
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 //  File   : DataFlowBase_DataNode.cxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include "DataFlowBase_DataNode.hxx"
31 #include "DataFlowBase_Graph.hxx"
32
33 GraphBase::DataNode::DataNode() :
34            GOTONode() {
35   MESSAGE( "GraphBase::DataNode::DataNode" );
36   _Created = false ;
37 }
38
39 GraphBase::DataNode::DataNode( CORBA::ORB_ptr ORB ,
40                                SALOME_NamingService* ptrNamingService ,
41                                const char *DataFlowName ,
42                                const SUPERV::KindOfNode DataFlowkind ,
43                                int * Graph_prof_debug ,
44                                ofstream * Graph_fdebug ) :
45            GOTONode( ORB , ptrNamingService , DataFlowName , DataFlowkind , Graph_prof_debug , Graph_fdebug ) {
46 //  MESSAGE( "GraphBase::DataNode::DataNode" );
47   cdebug << "GraphBase::DataNode::DataNode" << endl ;
48   _Created = false ;
49 }
50
51 GraphBase::DataNode::DataNode( CORBA::ORB_ptr ORB ,
52                                SALOME_NamingService* ptrNamingService ,
53                                const SALOME_ModuleCatalog::Service& DataFlowService ,
54                                const char *DataFlowName ,
55                                const SUPERV::KindOfNode DataFlowkind ,
56                                const SUPERV::SDate DataFlowFirstCreation ,
57                                const SUPERV::SDate DataFlowLastModification ,
58                                const char * DataFlowEditorRelease ,
59                                const char * DataFlowAuthor ,
60                                const char * DataFlowComment ) :
61            GOTONode( ORB , ptrNamingService ,
62                      DataFlowName , SUPERV::ListOfStrings() , DataFlowName , DataFlowkind ,
63                      DataFlowFirstCreation , DataFlowLastModification  ,
64                      DataFlowEditorRelease , DataFlowAuthor ,
65                      DataFlowComment , false , 0 , 0) {
66 //  MESSAGE( "GraphBase::DataNode::DataNode" );
67 }
68
69 GraphBase::DataNode::~DataNode() {
70 //  MESSAGE( "GraphBase::DataNode::~DataNode" );
71   cdebug << "GraphBase::DataNode::~DataNode" << endl ;
72 }
73
74 void GraphBase::DataNode::DataService( CORBA::ORB_ptr ORB ,
75                                        SALOME_ModuleCatalog::Service aService ,
76                                        int * Graph_prof_debug ,
77                                        ofstream * Graph_fdebug ) {
78   cdebug << "GraphBase::DataNode::DataService : DataFlowPortsOfNode of "
79          << aService << endl ;
80   DefPortsOfNode( ORB , aService , NamePtr() , Kind() ,
81                   Graph_prof_debug , Graph_fdebug ) ;
82
83   if ( _Created ) {
84     delete _DataFlowDataPorts ;
85   }
86   SALOME_ModuleCatalog::Service aReversedService ;
87   aReversedService.ServiceName = aService.ServiceName ;
88   aReversedService.ServiceinParameter = aService.ServiceoutParameter ;
89   aReversedService.ServiceoutParameter = aService.ServiceinParameter ;
90   _DataFlowDataPorts = new PortsOfNode() ;
91   cdebug << "GraphBase::DataNode::DataService : Mirrored DataFlowPortsOfNode of "
92          << aReversedService << endl ;
93   _DataFlowDataPorts->DefPortsOfNode( ORB , aReversedService , NamePtr() , Kind() ,
94                                       Graph_prof_debug , Graph_fdebug ) ;
95   _Created = true ;
96 }
97
98 int GraphBase::DataNode::CheckDataServerNodes() const {
99
100   cdebug_in << "GraphBase::DataNode::CheckDataServerNodes :" << endl;
101
102   int i , ierr = 0 ;
103
104   for ( i = 0 ; i < _DataFlowDataPorts->GetNodeOutPortsSize() ; i++ ) {
105 // Not a BUG : Reversed Service of the graph : OutPort of the Graph give input values to nodes
106     const GraphBase::OutPort * anOutPort = _DataFlowDataPorts->GetNodeOutPort(i) ;
107 //    if ( !anOutPort->IsGate() && !anOutPort->IsDataStream() && !anOutPort->IsDataConnected() ) {
108     if ( !anOutPort->IsGate() && !anOutPort->IsDataConnected() ) {
109       if ( anOutPort->IsExternConnected() && GraphMacroLevel() != 0 ) {
110         cdebug << "Base::DataNode::CheckDataServerNodes InPort " << anOutPort->PortName() << " "
111                << anOutPort->PortType() << " "
112                << anOutPort->PortStatus() << " of DataFlow " << Name()
113                << " is ExternConnected. GraphMacroLevel " << GraphMacroLevel() << endl ;
114       }
115       else {
116         cdebug << "Base::DataNode::CheckDataServerNodes InPort " << anOutPort->PortName() << " "
117                << anOutPort->PortType() << " " << anOutPort->PortStatus() << " of DataFlow " << Name()
118                << " has NO Data. GraphMacroLevel " << GraphMacroLevel() << " InPortsSize "
119                << anOutPort->InPortsSize() << " corresponding to :"
120                << endl ;
121         int i ;
122         for ( i = 0 ; i < anOutPort->InPortsSize() ; i++ ) {
123           cdebug << "           " << anOutPort->InPorts( i )->NodeName() << "( "
124                  << anOutPort->InPorts( i )->PortName() << " ) " << endl ;
125         }
126         if ( anOutPort->InPortsSize() == 1 &&
127              GraphOfNode()->GetGraphNode( anOutPort->InPorts( 0 )->NodeName() )->IsEndSwitchNode() ) {
128           cdebug << "Base::DataNode::CheckDataServerNodes InPort " << anOutPort->PortName()
129                  << " is connected to an EndSwitchNode. Input Data is controlled by ValidSwitchs."
130                  << endl ;
131         }
132         else {
133           ostringstream astr ;
134           astr << anOutPort->PortStatus() ;
135           string anErrorMessage = string( "InPort " ) + string( anOutPort->NodeName() ) +
136                                   string( "( " ) + string( anOutPort->PortName() ) + string( " ) " ) +
137                                   astr.str() + string( " has NO Input Data.\n" ) ;
138           GraphOfNode()->SetMessages( anErrorMessage ) ;
139           ierr++ ;
140         }
141       }
142     }
143     else {
144       cdebug << "Base::DataNode::CheckDataServerNodes InPort " << anOutPort->PortName() << " "
145              << anOutPort->PortType() << " "
146              << anOutPort->PortStatus() << " of DataFlow " << Name()  << " has Data or IsGate"
147              << endl ;
148     }
149   }
150
151   for ( i = 0 ; i < _DataFlowDataPorts->GetNodeInPortsSize() ; i++ ) {
152     if ( _DataFlowDataPorts->GetNodeInPort(i)->IsPortConnected() ) {
153       cdebug << "Base::DataNode::CheckDataServerNodes OutPort "
154              << _DataFlowDataPorts->GetNodeInPort(i)->PortName()
155              << " of DataFlow " << Name()  << " is Connected" << endl ;
156     }
157     else {
158       cdebug << "Base::DataNode::CheckDataServerNodes OutPort "
159              << _DataFlowDataPorts->GetNodeInPort(i)->PortName()
160              << " of DataFlow " << Name()  << " is NOT Connected" << endl ;
161     }
162   }
163
164   if ( ierr ) {
165     GraphOfNode()->SetMessages( "Some Input Data are missing.\n" ) ;
166     cdebug << "Base::DataNode::CheckDataServerNodes In the DataFlow " << Name() << " " << ierr
167            << " Some Input Data are missing" << endl ;
168   }
169
170   cdebug_out << "GraphBase::DataNode::CheckDataServerNodes ierr " << ierr << endl;
171   return ierr ;
172 }
173
174 void GraphBase::DataNode::ListDatas(ostream & f ) const {
175   _DataFlowDataPorts->ListPorts( f , false ) ;
176 }
177
178 void GraphBase::DataNode::DataNodeInfo(ostream & s ) const {
179   s << *this ;
180   s << "Ports :" << endl ;
181   ListPorts( s , true ) ;
182   s << "Datas :" << endl ;
183   _DataFlowDataPorts->ListPorts( s , false ) ;
184   s << ends ;
185 }
186
187 // inlined :
188 //GraphBase::OutPort * GraphBase::DataNode::GetChangeInDataNodePort( const char * DataFlowInPortName ) {
189 //  return _DataFlowDataPorts->GetChangeOutPort( DataFlowInPortName ) ;
190 //}
191
192 //GraphBase::InPort * GraphBase::DataNode::GetChangeOutDataNodePort( const char * DataFlowOutPortName ) {
193 //  return _DataFlowDataPorts->GetChangeInPort( DataFlowOutPortName ) ;
194 //}
195