Salome HOME
NRI : First integration.
[modules/superv.git] / src / GraphBase / DataFlowBase_ComputingNode.hxx
1 //=============================================================================
2 // File      : DataFlowBase_ComputingNode.hxx
3 // Created   : 2002
4 // Author    : Jean Rahuel, CEA
5 // Project   : SALOME
6 // $Header:
7 //=============================================================================
8
9 #ifndef _DATAFLOWBASE_NODE_HXX
10 #define _DATAFLOWBASE_NODE_HXX
11
12 #include "DataFlowBase_PortsOfNode.hxx"
13
14 namespace GraphBase {
15
16   class InLineNode ;
17
18   class ComputingNode : public PortsOfNode {
19
20     private:
21     
22       CORBA::ORB_ptr         _ORB ;
23       SALOME_NamingService * _NamingService ;
24       int                  * _Graph_prof_debug ;
25       ostream              * _Graph_fdebug ;
26       SUPERV::CNode_var      _Node ;
27       void                 * _InNode ; // From GraphExecutor:: or GraphEditor::
28       bool                   _ObjInterface ;
29
30       pthread_t              _ThreadNo ;
31
32       char                 * _Name ;
33       SUPERV::KindOfNode     _Kind ;
34       SUPERV::SDate          _FirstCreation ;
35       SUPERV::SDate          _LastModification ;
36       char                 * _EditorRelease ;
37       char                 * _Author ;
38       char                 * _Comment ;
39
40       bool                   _HeadNode ;
41       int                    _LevelNumber ;
42       int                    _SubGraphNumber ;
43       bool                   _GeneratedName ;
44
45       int                    _ConnectedInPortsNumber ;
46       int                    _DecrConnectedInPortsNumber ;
47
48 // For generated NodeNames with ServiceName : number of Nodes using
49 // the same ServiceName. It is not the same Service if it belongs to
50 // a different Interface and/or a different Component ...
51       map< string , int > _MapOfServiceNames ;
52
53 // Nodes with LinkedInPortsNumber InPort(s) linked to Outport(s) of this node :
54       map< string , int >      _MapOfLinkedNodes ;
55       int                      _LinkedNodesSize ;
56       vector<ComputingNode * > _LinkedNodes ;
57       vector<int >             _LinkedInPortsNumber ;
58
59     protected:
60
61       long _X ;
62       long _Y ;
63
64     public:
65
66       ComputingNode() ;
67       ComputingNode( CORBA::ORB_ptr ORB ,
68                      SALOME_NamingService* ptrNamingService ,
69                      const char * DataFlowName ,
70                      int * Graph_prof_debug = NULL ,
71                      ostream * Graph_fdebug = NULL ) ;
72       ComputingNode( CORBA::ORB_ptr ORB ,
73                      SALOME_NamingService* ptrNamingService ,
74                      const SALOME_ModuleCatalog::Service& NodeService ,
75                      const char *NodeName ,
76                      const SUPERV::KindOfNode akind ,
77                      const SUPERV::SDate NodeFirstCreation ,
78                      const SUPERV::SDate NodeLastModification ,
79                      const char * NodeEditorRelease ,
80                      const char * NodeAuthor ,
81                      const char * NodeComment ,
82                      const bool   GeneratedName ,
83                      const long   X ,
84                      const long   Y ,
85                      int * Graph_prof_debug = NULL ,
86                      ostream * Graph_fdebug = NULL ) ;
87       virtual ~ComputingNode() ;
88
89       SALOME_NamingService * NamingService() const {
90              return _NamingService ; } ;
91
92       SUPERV::CNode_var ObjRef() const { return _Node ; } ;
93       void SetObjRef(SUPERV::CNode_var aNode) {
94                      _Node = aNode ; } ;
95       void InNode( void * anInNode ) {
96 //           cdebug << "GraphBase::ComputingNode::InNode " << Name() << endl ;
97            _InNode = anInNode ; } ;
98       void * GetInNode() const {
99              return _InNode ; } ;
100
101       void ObjInterface( bool k_interface ) { _ObjInterface = k_interface ; } ;
102       bool ObjInterface() { return _ObjInterface ; } ;
103
104       pthread_t ThreadNo() { return _ThreadNo ; } ;
105       void ThreadNo( pthread_t aThread ) { _ThreadNo = aThread ; } ;
106
107       char * Name() const { return my_strdup( _Name ) ; } ;
108       const char *const * NamePtr() const { return &_Name ; } ;
109       SUPERV::KindOfNode Kind() const {
110             return _Kind; } ;
111 //      const SALOME_ModuleCatalog::Service * Service() const ;
112       SUPERV::SDate FirstCreation() const ;
113       SUPERV::SDate LastModification() const ;
114       char* Author() const { return my_strdup( _Author ) ; } ;
115       char* EditorRelease() const { return my_strdup( _EditorRelease ) ; } ;
116       char * Comment() const { return my_strdup( _Comment ) ; } ;
117       int XCoordinate() const { return _X ; } ;
118       int YCoordinate() const { return _Y ; } ;
119
120       bool Name( const char * aName ) ;
121       bool Kind( SUPERV::KindOfNode aKind) ;
122 //      void Service( const SALOME_ModuleCatalog::Service aService ) ;
123       void FirstCreation( const SUPERV::SDate aFirstCreation ) ;
124       void LastModification( const SUPERV::SDate aLastModification ) ;
125       bool Author( const char * anAuthor ) ;
126       bool EditorRelease( const char* anEditorRelease ) ;
127       bool Comment( const char *c ) ;
128       void Coordinates( const int X , const int Y ) {
129            _X = X ; _Y = Y ; } ;
130
131       void NodePort( const char * NodeName ,
132                      const char * ServiceParameterName ,
133                      char ** aNode , char ** aPort ) ;
134
135       bool IsLinked(const char * ToServiceParameterName ) ;
136       bool HasInput(const char * ToServiceParameterName ) ;
137
138       GraphBase::SNode * GetInfo() ;
139
140       const bool IsComputingNode() const {
141             return (_Kind == SUPERV::ComputingNode ) ; } ;
142       const bool IsFactoryNode() const {
143             return (_Kind == SUPERV::FactoryNode ) ; } ;
144       const bool IsOneOfGOTONodes() const {
145             return (_Kind == SUPERV::LoopNode ||
146                     _Kind == SUPERV::EndLoopNode ||
147                     _Kind == SUPERV::SwitchNode ||
148                     _Kind == SUPERV::EndSwitchNode ||
149                     _Kind == SUPERV::GOTONode ) ; } ;
150       const bool IsOneOfInLineNodes() const {
151             return (_Kind == SUPERV::InLineNode || IsOneOfGOTONodes() ) ; } ;
152       const bool IsInLineNode() const {
153             return (_Kind == SUPERV::InLineNode ) ; } ;
154       const bool IsDataFlowNode() const {
155             return (_Kind == SUPERV::DataFlowNode ) ; } ;
156       const bool IsLoopNode() const {
157             return (_Kind == SUPERV::LoopNode ) ; } ;
158       const bool IsEndLoopNode() const {
159             return (_Kind == SUPERV::EndLoopNode ) ; } ;
160       const bool IsSwitchNode() const {
161             return (_Kind == SUPERV::SwitchNode ) ; } ;
162       const bool IsEndSwitchNode() const {
163             return (_Kind == SUPERV::EndSwitchNode ) ; } ;
164       const bool IsGOTONode() const {
165             return (_Kind == SUPERV::GOTONode ) ; } ;
166       void HeadNode( bool aHeadNode ) { _HeadNode = aHeadNode ; } ;
167       const bool IsHeadNode() const { return _HeadNode ; } ;
168
169       bool RemovePorts( const char* aNodeName ) ;
170
171       InPort * AddInPort( const char * InputParameterName ,
172                           const char * InputParameterType ) ;
173       OutPort * AddOutPort( const char * OutputParameterName ,
174                             const char * OutputParameterType ) ;
175
176       void AddLink( ComputingNode * aNode ) ;
177       void RemoveLink( ComputingNode * aNode ) ;
178       void ReNameLink( const char* OldNodeName ,
179                        const char* NewNodeName ) ;
180
181       int GetServiceNameNumber( const char * name ) {
182           int num = _MapOfServiceNames[ name ] ;
183           if ( num == 0 ) {
184             _MapOfServiceNames[ name ] = 1 ;
185           }
186           else {
187             _MapOfServiceNames[ name ] = num + 1 ;
188           }
189           return _MapOfServiceNames[ name ] ; } ;
190
191       void IncrConnectedInPortsNumber() {
192            cdebug << "IncrConnectedInPortsNumber " << Name() << " -> "
193                   << _ConnectedInPortsNumber+1 << endl ;
194            _ConnectedInPortsNumber++ ; } ;
195       void DecrConnectedInPortsNumber() {
196            _ConnectedInPortsNumber-- ; } ;
197       int ConnectedInPortsNumber() const {
198           return _ConnectedInPortsNumber ; } ;
199       void ConnectedInPortsNumber( int c ) {
200            cdebug << "ConnectedInPortsNumber " << Name() << " -> " << c << endl ;
201            _ConnectedInPortsNumber = c ; } ;
202
203       void IncrDecrConnectedInPortsNumber(const int cnt ) {
204            _DecrConnectedInPortsNumber += cnt ; } ;
205       bool DecrIncrDecrConnectedInPortsNumber() {
206            if ( _DecrConnectedInPortsNumber ) {
207              _ConnectedInPortsNumber = _ConnectedInPortsNumber -
208                                        _DecrConnectedInPortsNumber ;
209              _DecrConnectedInPortsNumber = 0 ;
210              return true ;
211            }
212            return false ; } ;
213
214       int GetLinkedNodeIndex( const char * name ) {
215           int index = _MapOfLinkedNodes[ name ] -1 ;
216           if ( index >= 0 ) {
217             cdebug << "GetLinkedNodeIndex of " << name
218                    << " in _MapOfLinkedNodes : "
219                    << index << " Node " << hex << (void *) _LinkedNodes[ index ]
220                    << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
221                    << endl ;
222           }
223           return index ; } ;
224       void SetLinkedNodeIndex( const char * name , const int index ) {
225           _MapOfLinkedNodes[ name ] = index +1 ;
226           cdebug << "SetLinkedNodeIndex of " << name << " in _MapOfLinkedNodes : "
227                  << index << " Node " << hex << (void *) _LinkedNodes[ index ]
228                  << dec << " '" << _LinkedNodes[ index ]->Name() << "'"
229                  << " _MapOfLinkedNodes " << _MapOfLinkedNodes[ name ] - 1
230                  << endl ;
231           } ;
232       void DelLinkedNodeIndex( const char * name ) {
233            _MapOfLinkedNodes.erase( name ) ; } ;
234       int LinkedNodesSize() const { return _LinkedNodesSize ; } ;
235       ComputingNode * LinkedNodes( int i ) const { return _LinkedNodes[ i ] ; } ;
236       const int LinkedInPortsNumber( int i ) const { return _LinkedInPortsNumber[ i ] ; } ;
237
238       int Level() { return _LevelNumber ; } ;
239       void Level( int LevelNumber ) {
240            _LevelNumber = LevelNumber ; } ;
241       int SubGraph() { return _SubGraphNumber ; } ;
242       void SubGraph( int SubGraphNumber ) {
243            _SubGraphNumber = SubGraphNumber ; } ;
244
245 //      const GraphBase::ListOfParameters * GetListOfParameters() const ;
246
247       bool SaveXML( QDomDocument & Graph , QDomElement & info , 
248                     int X , int Y ) const {
249                     ListOfFuncName aFuncNames ; 
250                     GraphBase::ListOfPythonFunctions aVoidList ;
251            return SaveXML( Graph , info , "" , "" , "" , "" , aFuncNames , aVoidList ,
252                            X , Y ) ; } ;
253
254       bool SavePY( ostream &f , const char * aGraphName ,
255                    int X , int Y ) const {
256            ListOfFuncName aFuncNames ; 
257            GraphBase::ListOfPythonFunctions aVoidList ;
258            return SavePY( f , aGraphName , "" , "" , "" , NULL , aFuncNames  , aVoidList ,
259                           X , Y ) ; } ;
260 //      bool SaveXML(ostream &f , char *Tabs , 
261       bool SaveXML(QDomDocument & Graph , QDomElement & info , 
262                    const char * ComponentName ,
263                    const char * InterfaceName ,
264                    const char * Computer ,
265                    const char * CoupledNode ,
266                    const ListOfFuncName FuncNames ,
267                    const GraphBase::ListOfPythonFunctions PythonFunctions ,
268                    int X , int Y ) const ;
269
270       bool SavePY(ostream &f , const char * aGraphName ,
271                                const char * ComponentName ,
272                                const char * InterfaceName ,
273                                const char * Computer ,
274                                const GraphBase::InLineNode * aCoupledNode ,
275                                const ListOfFuncName FuncNames ,
276                                const GraphBase::ListOfPythonFunctions PythonFunctions ,
277                                int X , int Y ) const ;
278
279       void NodeInfo(ostrstream & s) const ;
280
281       void ListLinks(ostream &f ) const ;
282
283   };
284   
285 };
286
287 ostream & operator<< (ostream &,const GraphBase::ComputingNode & N );
288
289 ostream & operator<< (ostream &,const SUPERV::SDate & D );
290
291 #endif