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