Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.hxx
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_ComputingNode.hxx
8 //  Author : Jean Rahuel, CEA
9 //  Module : SUPERV
10 //  $Header:
11
12 #ifndef _DATAFLOWBASE_COMPUTINGNODE_HXX
13 #define _DATAFLOWBASE_COMPUTINGNODE_HXX
14
15 #include "SALOME_NamingService.hxx"
16
17 #include "DataFlowBase_StreamNode.hxx"
18
19 class CNode_Impl ;
20
21 namespace GraphBase {
22
23   class Graph ;
24
25   class InLineNode ;
26
27   class ComputingNode : public StreamNode {
28
29     private:
30     
31       CORBA::ORB_ptr         _ORB ;
32       SALOME_NamingService * _NamingService ;
33 //->StreamNode      int                  * _Graph_prof_debug ;
34 //->StreamNode      ofstream             * _Graph_fdebug ;
35       SUPERV::CNode_var      _Node_var ;
36       CNode_Impl           * _Node_Impl ;
37       void                 * _InNode ; // From GraphExecutor:: or GraphEditor::
38       bool                   _ObjInterface ;
39
40       pthread_t              _ThreadNo ;
41
42 //->StreamNode      char                 * _Name ;
43 //->StreamNode      SUPERV::KindOfNode     _Kind ;
44       SUPERV::SDate          _FirstCreation ;
45       SUPERV::SDate          _LastModification ;
46       char                 * _EditorRelease ;
47       char                 * _Author ;
48       char                 * _Comment ;
49
50 //->StreamNode      bool                   _HeadNode ;
51 //->StreamNode      int                    _LevelNumber ;
52 //->StreamNode      int                    _SubGraphNumber ;
53       bool                   _GeneratedName ;
54
55 //->StreamNode      int                    _DataStreamInPortsNumber ;
56 //->StreamNode      int                    _DataStreamOutPortsNumber ;
57
58       int                    _ConnectedInPortsNumber ;
59       int                    _DecrConnectedInPortsNumber ;
60
61 // For generated NodeNames with ServiceName : number of Nodes using
62 // the same ServiceName. It is not the same Service if it belongs to
63 // a different Interface and/or a different Component ...
64 //->StreamNode      map< string , int > _MapOfServiceNames ;
65
66 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
67 //->StreamNode      map< string , int >      _MapOfLinkedNodes ;
68 //->StreamNode      int                      _LinkedNodesSize ;
69 //->StreamNode      vector<ComputingNode * > _LinkedNodes ;
70 //->StreamNode      vector<int >             _LinkedInPortsNumber ;
71
72     protected:
73
74       long _X ;
75       long _Y ;
76
77     public:
78
79       ComputingNode() ;
80       ComputingNode( CORBA::ORB_ptr ORB ,
81                      SALOME_NamingService* ptrNamingService ,
82                      const char * DataFlowName ,
83                      const SUPERV::KindOfNode DataFlowkind ,
84                      int * Graph_prof_debug ,
85                      ofstream * Graph_fdebug ) ;
86       ComputingNode( CORBA::ORB_ptr ORB ,
87                      SALOME_NamingService* ptrNamingService ,
88                      const SALOME_ModuleCatalog::Service& NodeService ,
89                      const char *NodeName ,
90                      const SUPERV::KindOfNode akind ,
91                      const SUPERV::SDate NodeFirstCreation ,
92                      const SUPERV::SDate NodeLastModification ,
93                      const char * NodeEditorRelease ,
94                      const char * NodeAuthor ,
95                      const char * NodeComment ,
96                      const bool   GeneratedName ,
97                      const long   X ,
98                      const long   Y ,
99                      int * Graph_prof_debug = NULL ,
100                      ofstream * Graph_fdebug = NULL ) ;
101       virtual ~ComputingNode() ;
102
103       SALOME_NamingService * NamingService() const {
104              return _NamingService ; } ;
105
106       SUPERV::CNode_var ObjRef() const {
107 //                        char * _NodeName ;
108 //                        cdebug << "ComputingNode::ObjRef() " << _Node << " " << Name()
109 //                               << " " << endl ;
110 //                        SUPERV::CNode_var _NodeObjRef = SUPERV::CNode::_narrow( _Node ) ;
111 //                        if ( CORBA::is_nil( _NodeObjRef ) ) {
112 //                          _NodeName = "NilRef" ;
113 //                      }
114 //                      else {
115 //                          try {
116 //                            _NodeName = _NodeObjRef->Name() ;
117 //                        }
118 //                          catch ( ... ) {
119 //                            _NodeName = "Catch Error" ;
120 //                        }
121 //                      }
122 //                        cdebug << _NodeName << " " << Name() << endl ;
123                          return _Node_var ; } ;
124       void SetObjRef( SUPERV::CNode_var aNode_var ) {
125 //                        char * _NodeName ;
126 //                        if ( CORBA::is_nil( _Node ) ) {
127 //                          _NodeName = "NilRef" ;
128 //                      }
129 //                      else {
130 //                          _NodeName = _Node->Name() ;
131 //                      }
132 //                        cdebug << "ComputingNode::SetObjRef( " << _Node << " "
133 //                               << _NodeName << " ) " << Name() << " --> " ;
134                         _Node_var = aNode_var ;
135 //                        cdebug << _Node << " " << _Node->Name() << " ) " << Name() << endl ;
136                         } ;
137
138       CNode_Impl * ObjImpl() const { return _Node_Impl ; } ;
139       void SetObjImpl( CNode_Impl * aNode_Impl ) {
140                        _Node_Impl = aNode_Impl ; } ;
141
142       void InNode( void * anInNode ) {
143 //           cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
144            _InNode = anInNode ; } ;
145       void * GetInNode() const {
146              return _InNode ; } ;
147
148       void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
149       bool ObjInterface() { return _ObjInterface ; } ;
150
151       pthread_t ThreadNo() { return _ThreadNo ; } ;
152       void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
153
154 //->StreamNode      char * Name() const { return my_strdup( _Name ) ; } ;
155 //->StreamNode      const char *const * NamePtr() const { return &_Name ; } ;
156 //      const SALOME_ModuleCatalog::Service * Service() const ;
157       SUPERV::SDate FirstCreation() const ;
158       SUPERV::SDate LastModification() const ;
159       char* Author() const { return my_strdup( _Author ) ; } ;
160       char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
161       char * Comment() const { return my_strdup( _Comment ) ; } ;
162       int XCoordinate() const { return _X ; } ;
163       int YCoordinate() const { return _Y ; } ;
164
165 //->StreamNode      bool Name( const char * aName ) ;
166 //      void Service( const SALOME_ModuleCatalog::Service aService ) ;
167       void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
168       void LastModification( const SUPERV::SDate aLastModification ) ;
169       bool Author( const char * anAuthor ) ;
170       bool EditorRelease( const char* anEditorRelease ) ;
171       bool Comment( const char *c ) ;
172       void Coordinates( const int X , const int Y ) {
173            _X = X ; _Y = Y ; } ;
174
175       void NodePort( const char * NodeName ,
176                      const char * ServiceParameterName ,
177                      char ** aNode , char ** aPort ) ;
178
179       bool IsLinked(const char * ToServiceParameterName ) ;
180       bool HasInput(const char * ToServiceParameterName ) ;
181
182       GraphBase::SNode * GetInfo() ;
183
184 //      void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
185 //      const bool IsHeadNode() const { return _HeadNode ; } ;
186
187       bool RemovePorts( const char* aNodeName ) ;
188
189       void SetMacroPorts( GraphBase::Graph * aGraph ) ;
190       void UpdateMacroPorts( GraphBase::Graph * aGraph ) ;
191       void SetMacroDatas( GraphBase::Graph * aGraph , GraphBase::Graph * aGraphOfMacroGraph ) ;
192
193       void DelInPort( const char * InputParameterName ) ;
194       void DelOutPort( const char * OutputParameterName ) ;
195
196       InPort * AddInPort( const char * InputParameterName ,
197                           const char * InputParameterType ,
198                           const SUPERV::KindOfPort aKindOfPort ,
199                           int index = -1 ) ;
200       OutPort * AddOutPort( const char * OutputParameterName ,
201                             const char * OutputParameterType ,
202                             const SUPERV::KindOfPort aKindOfPort ,
203                             int index = -1 ) ;
204
205       void DelInDataStreamPort( const char * InputParameterName ) ;
206       void DelOutDataStreamPort( const char * OutputParameterName ) ;
207
208       InDataStreamPort * AddInDataStreamPort( const char * InputParameterName ,
209                                               const SALOME_ModuleCatalog::DataStreamType InputParameterType ,
210                                               const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
211                                               const SUPERV::KindOfPort aKindOfPort ,
212                                               int index = -1 ) ;
213       OutDataStreamPort * AddOutDataStreamPort( const char * OutputParameterName ,
214                                                 const SALOME_ModuleCatalog::DataStreamType OutputParameterType ,
215                                                 const SALOME_ModuleCatalog::DataStreamDependency aDependency ,
216                                                 const SUPERV::KindOfPort aKindOfPort ,
217                                                 int index = -1 ) ;
218
219 //      ComputingNode * LinkedNodes( int i ) const { return (GraphBase::ComputingNode *) GraphBase::StreamNode::LinkedNodes( i ) ; } ;
220
221       void AddLinkedNode( GraphBase::ComputingNode * ToNode ) {
222            GraphBase::StreamNode::AddLinkedNode( ToNode ) ;
223            cdebug << Name() << "->GraphBase::ComputingNode::AddLinkedNode( " << ToNode->Name()
224                   << ") ConnectedInPortsNumber " << ToNode->ConnectedInPortsNumber()
225                   << " + 1 Service " << ServiceName() << endl ;
226            ToNode->IncrConnectedInPortsNumber() ; } ;
227
228       bool RemoveLinkedNode( GraphBase::ComputingNode * ToNode ) {
229            bool RetVal = GraphBase::StreamNode::RemoveLinkedNode( ToNode ) ;
230            if ( RetVal ) {
231              cdebug << "GraphBase::StreamNode::RemoveLinkedNode to " << ToNode->Name() << " from "
232                     << Name() << " ConnectedInPortsNumber "
233                     << ToNode->ConnectedInPortsNumber() - 1 << endl ;
234              ToNode->DecrConnectedInPortsNumber() ;
235            }
236            return RetVal ; } ;
237
238       void ReNameLinkedNode( const char* OldNodeName ,
239                              const char* NewNodeName ) {
240            GraphBase::StreamNode::ReNameLinkedNode( OldNodeName , NewNodeName ) ; } ;
241
242       void IncrConnectedInPortsNumber() {
243            cdebug << "IncrConnectedInPortsNumber " << Name() << " -> "
244                   << _ConnectedInPortsNumber+1 << endl ;
245            _ConnectedInPortsNumber++ ; } ;
246       void DecrConnectedInPortsNumber() {
247            _ConnectedInPortsNumber-- ; } ;
248       int ConnectedInPortsNumber() const {
249           return _ConnectedInPortsNumber ; } ;
250       void ConnectedInPortsNumber( int c ) {
251            cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
252            _ConnectedInPortsNumber = c ; } ;
253
254       void IncrDecrConnectedInPortsNumber(const int cnt ) {
255            _DecrConnectedInPortsNumber += cnt ; } ;
256       bool DecrIncrDecrConnectedInPortsNumber() {
257            if ( _DecrConnectedInPortsNumber ) {
258              _ConnectedInPortsNumber = _ConnectedInPortsNumber -
259                                        _DecrConnectedInPortsNumber ;
260              _DecrConnectedInPortsNumber = 0 ;
261              return true ;
262            }
263            return false ; } ;
264
265 //      const GraphBase::ListOfParameters * GetListOfParameters() const ;
266
267       const long CpuUsed() ;
268
269       bool SaveXML( QDomDocument & Graph , QDomElement & info , 
270                     int X , int Y ) const {
271                     ListOfFuncName aFuncNames ; 
272                     GraphBase::ListOfPythonFunctions aVoidList ;
273            return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
274                            X , Y ) ; } ;
275
276       bool SavePY( ostream &f , const char * aGraphName ,
277                    int X , int Y ) const {
278            ListOfFuncName aFuncNames ; 
279            GraphBase::ListOfPythonFunctions aVoidList ;
280            return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames  , aVoidList ,
281                           X , Y ) ; } ;
282 //      bool SaveXML(ostream &f , char *Tabs , 
283       bool SaveXML(QDomDocument & Graph , QDomElement & info , 
284                    const char * ComponentName ,
285                    const char * InterfaceName ,
286                    const char * Computer ,
287                    const char * CoupledNode ,
288                    const ListOfFuncName FuncNames ,
289                    const GraphBase::ListOfPythonFunctions PythonFunctions ,
290                    int X , int Y ) const ;
291
292       bool SavePY(ostream &f , const char * aGraphName ,
293                                const char * ComponentName ,
294                                const char * InterfaceName ,
295                                const char * Computer ,
296                                const GraphBase::InLineNode * aCoupledNode ,
297                                const ListOfFuncName FuncNames ,
298                                const GraphBase::ListOfPythonFunctions PythonFunctions ,
299                                int X , int Y ) const ;
300
301       void NodeInfo(ostream & s) const ;
302
303       void ListLinks(ostream &f ) const ;
304
305   };
306   
307 };
308
309 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
310
311 ostream & operator<< (ostream &,const SUPERV::SDate & D );
312
313 #endif