Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[modules/superv.git] / src / GraphBase / DataFlowBase_Graph.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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_Graph.hxx
25 //  Author : Jean Rahuel, CEA
26 //  Module : SUPERV
27 //  $Header:
28
29 #ifndef _DATAFLOWBASE_GRAPH_HXX
30 #define _DATAFLOWBASE_GRAPH_HXX
31
32 #include "DataFlowBase_FactoryNode.hxx"
33 #include "DataFlowBase_LoopNode.hxx"
34 #include "DataFlowBase_EndOfLoopNode.hxx"
35 #include "DataFlowBase_SwitchNode.hxx"
36 #include "DataFlowBase_EndOfSwitchNode.hxx"
37 #include "DataFlowBase_DataNode.hxx"
38
39 namespace GraphBase {
40
41   class Graph : public DataNode {
42
43     private:
44
45 //      int                 _Graph_prof_debug;
46 //      ofstream          * _Graph_fdebug;
47       CORBA::ORB_ptr      _Orb ;
48 //      SUPERV::Graph_var   _Graph ;
49 //      Graph_Impl        * _GraphImpl ;
50
51 // Map of Nodes of the Graph
52       map< string , int >      _MapOfGraphNodes ;
53       long                     _GraphNodesSize ;
54       vector<bool >            _Sorted ;
55       vector<ComputingNode *>  _GraphNodes ;
56
57 // _SortedNodes[ _LevelsNumber ] : topological sort from 0 to _LevelsNumber
58 // _SortedNodes[ _level ][ _NodesNumber[ _level ] ] : _NodesNumber[ _level ] Nodes in the level
59       int                              _LevelsNumber ;
60       int                              _ThreadsMax ;
61       vector<int >                     _NodesNumber ;
62       vector<vector<ComputingNode *> > _SortedNodes ;
63
64       vector<int >             _CnxInPortsNumber ;
65       vector<int >             _DecrInPortsNumber ;
66
67       long                     _HeadNodesSize ; 
68       vector<ComputingNode *>  _HeadNodes ;
69       long                     _QueueNodesSize ; 
70       vector<ComputingNode *>  _QueueNodes ;
71       bool                     _ParallelExecutionNodes ;
72
73 // For StreamGraphs. It is not the same Service if it belongs to
74 // a different Interface and/or a different Component ...
75       map< string , GraphBase::Service * > _MapOfServiceNames ;
76
77 // For automactic rename of nodes if unique names in graphs
78       map< string , int >      _MapOfServiceInstanceNumber ;
79
80 // Total number of SubGraphs
81       int                              _SubGraphsNumber ;
82 // _SubGraphs[ SubGraphNumero ] [ NodeNumero ]
83 // SubGraphNumero : [ 0 , _SubGraphsSize [ ; NodeNumero : [ 0 , _SubGraphs[ SubGraphNumero ].size() [
84       int                              _SubGraphsSize ;
85       vector<vector<ComputingNode *> > _SubGraphs ;
86
87 // _SubStreamGraphs[ SubStreamGraphNumero ] [ NodeNumero ]
88 // SubStreamGraphNumero : [ 0 , _SubStreamGraphsSize [
89 // NodeNumero : [ 0 , _SubStreamGraphs[ SubStreamGraphNumero ].size() [
90 //      int                              _SubStreamGraphsSize ;
91 //      vector<vector<ComputingNode *> > _SubStreamGraphs ;
92
93       bool AddLink( GraphBase::ComputingNode *fromNode ,
94                     GraphBase::OutPort *fromPort ,
95                     GraphBase::ComputingNode *toNode ,
96                     GraphBase::InPort *toPort ) ;
97
98     public:
99
100       Graph() ;
101       Graph( CORBA::ORB_ptr ORB ,
102              SALOME_NamingService* ptrNamingService ,
103              const char *DataFlowName ,
104              const SUPERV::KindOfNode DataFlowkind ,
105              int * Graph_prof_debug ,
106              ofstream * Graph_fdebug ) ;
107 //             const char * DebugFileName ) ;
108       Graph( CORBA::ORB_ptr ORB ,
109              SALOME_NamingService* ptrNamingService ,
110              const SALOME_ModuleCatalog::Service& DataFlowService ,
111              const char *DataFlowComponentName ,
112              const char *DataFlowInterfaceName ,
113              const char *DataFlowName ,
114              const SUPERV::KindOfNode DataFlowkind ,
115              const SUPERV::SDate DataFlowFirstCreation ,
116              const SUPERV::SDate DataFlowLastModification ,
117              const char * DataFlowEditorRelease ,
118              const char * DataFlowAuthor ,
119              const char * DataFlowComputer ,
120              const char * DataFlowComment ,
121              int * Graph_prof_debug ,
122              ofstream * Graph_fdebug ) ;
123 //             const char * DebugFileName ) ;
124       virtual ~Graph() ;
125
126 //      void Set_prof_debug( CORBA::ORB_ptr ORB ,
127 //                           const char * DebugFileName ) ;
128       void Set_prof_debug( int * Graph_prof_debug ,
129                            ofstream * Graph_fdebug ) ;
130       int * Graph_prof_debug() {
131             return _prof_debug ; } ;
132       ofstream * Graph_fdebug() { return _fdebug ; } ;
133
134 //      SUPERV::Graph_var ObjRef() const { return _Graph ; } ;
135 //      void SetObjRef( SUPERV::Graph_var aGraph ) {
136 //                      _Graph = aGraph ; } ;
137 //      Graph_Impl * ObjImpl() const { return _GraphImpl ; } ;
138 //      void SetObjImpl( Graph_Impl * aGraphImpl ) {
139 //                       _GraphImpl = aGraphImpl ; } ;
140
141       void AddLinkedNode( const char* FromNodeName , GraphBase::ComputingNode * anOutNode ) {
142            GetChangeGraphNode( FromNodeName )->AddLinkedNode( anOutNode ) ; } ;
143
144       const int GetGraphNodeIndex( const char *name ) {
145             const int index = _MapOfGraphNodes[ name ] - 1 ;
146 //            if ( index >= 0 )
147 //              cdebug << "GetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
148 //                     << index << " Node " << hex << (void *) _GraphNodes[ index ]
149 //                     << dec << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
150             return index ; } ;
151       void SetGraphNodeIndex( const char *name , const int index ) {
152            _MapOfGraphNodes[ name ] = index + 1 ;
153            cdebug << "SetGraphNodeIndex of " << name << " in _MapOfGraphNodes : "
154                   << index << " Node " << (void *) _GraphNodes[ index ]
155                   << " '" << _GraphNodes[ index ]->Name() << "'" << endl ;
156            } ;
157       void DelGraphNodeIndex( const char *name ) {
158            _MapOfGraphNodes.erase( name ) ; } ;
159
160       int GetGraphNodeSize() const {
161           return _MapOfGraphNodes.size() ; }
162       const GraphBase::ComputingNode * GetGraphNode( const int index ) const {
163             const ComputingNode * aNode = GetChangeGraphNode( index ) ;
164             return aNode ; } ;
165       ComputingNode * GetChangeGraphNode( const int index ) const {
166             if ( index >= 0 && index < _GraphNodesSize ) {
167               ComputingNode * aNode = _GraphNodes[ index ] ;
168               return aNode ;
169             }
170             else
171               return NULL ; } ;
172       const ComputingNode * GetGraphNode( const char *name ) {
173             const ComputingNode * aNode = GetChangeGraphNode( name ) ;
174             return aNode ; } ;
175       ComputingNode * GetChangeGraphNode( const char *name ) {
176             int index = GetGraphNodeIndex( name ) ;
177             if ( index >= 0 && index < _GraphNodesSize ) {
178               ComputingNode * aNode = GetChangeGraphNode( index ) ;
179               return aNode ;
180             }
181             else
182               return NULL ; } ;
183
184       const int GraphNodesSize() const {
185             return _GraphNodesSize ; } ;
186       ComputingNode * GraphNodes( int i ) const {
187             return _GraphNodes[ i ] ; } ;
188
189       const int HeadNodesSize() const {
190             return _HeadNodesSize ; } ;
191       ComputingNode * HeadNodes( int i ) const {
192             return _HeadNodes[ i ] ; } ;
193
194       const int QueueNodesSize() const {
195             return _QueueNodesSize ; } ;
196       ComputingNode * QueueNodes( int i ) const {
197             return _QueueNodes[ i ] ; } ;
198
199       const GraphBase::InPort * GetInPort( const char * ToServiceParameterName ) {
200                                 return GraphBase::PortsOfNode::GetInPort( ToServiceParameterName ) ; } ;
201       GraphBase::InPort * GetChangeInPort( const char * ToServiceParameterName ) {
202                           return GraphBase::PortsOfNode::GetChangeInPort( ToServiceParameterName ) ; } ;
203       const GraphBase::OutPort * GetOutPort( const char * FromServiceParameterName ) {
204                                  return GraphBase::PortsOfNode::GetOutPort( FromServiceParameterName ) ; } ;
205       GraphBase::OutPort * GetChangeOutPort( const char * FromServiceParameterName ) {
206                            return GraphBase::PortsOfNode::GetChangeOutPort( FromServiceParameterName ); } ;
207
208       const GraphBase::InPort * GetInPort( const char * ToNodeName ,
209                                           const char * ToServiceParameterName ) {
210             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
211             if ( aNode ) {
212               return aNode->GetInPort(ToServiceParameterName);
213             }
214             else
215               return NULL ; } ;
216       GraphBase::InPort * GetChangeInPort( const char * ToNodeName ,
217                                           const char * ToServiceParameterName ) {
218             ComputingNode * aNode = GetChangeGraphNode( ToNodeName ) ;
219             if ( aNode ) {
220               return aNode->GetChangeInPort( ToServiceParameterName ) ;
221             }
222             else
223               return NULL ; } ;
224       const GraphBase::OutPort * GetOutPort( const char * FromNodeName ,
225                                     const char * FromServiceParameterName ) {
226             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
227             if ( aNode ) {
228               return aNode->GetOutPort( FromServiceParameterName ) ;
229             }
230             else
231               return NULL ; } ;
232       GraphBase::OutPort * GetChangeOutPort( const char * FromNodeName ,
233                                             const char * FromServiceParameterName ) {
234             ComputingNode * aNode = GetChangeGraphNode( FromNodeName ) ;
235             if ( aNode ) {
236               return aNode->GetChangeOutPort( FromServiceParameterName );
237             }
238             else
239               return NULL ; } ;
240
241       SUPERV::GraphState PortState( const char* NodeName ,
242                                     const char* ServiceParameterName ) ;
243       bool PortDone( const char* NodeName ,
244                      const char* ServiceParameterName ) {
245         bool aRet = false ;
246         SUPERV::GraphState aState = PortState( NodeName ,
247                                                 ServiceParameterName ) ;
248         if ( aState == SUPERV::DoneState )
249           aRet = true ;
250         return aRet ; } ;
251 //JR 30.03.2005      const CORBA::Any * PortInData( const char* ToNodeName ,
252       const CORBA::Any PortInData( const char* ToNodeName ,
253                                    const char* ToServiceParameterName ) ;
254 //JR 30.03.2005      const CORBA::Any * PortOutData( const char* FromNodeName ,
255       const CORBA::Any PortOutData( const char* FromNodeName ,
256                                     const char* FromServiceParameterName ) ;
257
258       bool LoadXml( CORBA::ORB_ptr Orb , const char* anXmlFile ,
259                     GraphBase::ListOfSGraphs & aListOfDataFlows ) ;
260
261       GraphBase::SNode * GetInfo() const ;
262       GraphBase::ListOfSNodes * GetNodes() const ;
263       GraphBase::ListOfSLinks * GetLinks(bool AllLinks = false ) const ;
264       GraphBase::ListOfSGraphs * GetGraphs() const ;
265       GraphBase::ListOfSLinks * GetDatas() const ;
266
267       bool AddNode( ComputingNode * aNode ) ;
268       bool RemoveNode( const char* NodeName ) ;
269       bool ReNameNode( const char* OldNodeName ,
270                        const char* NewNodeName ) ;
271
272       bool AddLink( const char* FromNodeName ,
273                     const char* FromServiceParameterName ,
274                     const char* ToNodeName ,
275                     const char* ToServiceParameterName ) ;
276 //                    , const CORBA::Any aValue ) ;
277       bool RemoveLink( const char* FromNodeName ,
278                        const char* FromServiceParameterName ,
279                        const char* ToNodeName ,
280                        const char* ToServiceParameterName ) ;
281       bool GetLink( const char* ToNodeName ,
282                     const char* ToServiceParameterName ,
283                     char** FromNodeName ,
284                     char** FromServiceParameterName ) ;
285       GraphBase::SLink * GetLink( GraphBase::ComputingNode * aNode ,
286                                   GraphBase::InPort* toPort ) ;
287
288       bool AddInputData( const char* ToNodeName ,
289                          const char* ToParameterName ,
290                          const CORBA::Any aValue ) ;
291       bool ChangeInputData( const char* ToNodeName ,
292                             const char* ToParameterName ,
293                             const CORBA::Any aValue ) ;
294 //      bool AddInputData( const char* ToNodeName ,
295 //                         const char* ToParameterName ,
296 //                         const CORBA::Any ** aValue ) ;
297
298       bool AddOutputData( const char* FromNodeName ,
299                           const char* FromParameterName ,
300                           const CORBA::Any aValue ) ;
301
302       void SetGraphPorts() ;
303
304       bool CreateService() ;
305       bool InLineServices() ;
306
307       bool Sort( int & SubStreamGraphsNumber ) ;
308       bool ValidLoops() const ;
309       bool ValidSwitchs() const ;
310       bool ComputingNodes() const ;
311       bool LinkLoopNodes(bool & NewLink ) ;
312       bool DataServerNodes() const ;
313   
314       long LevelMax() {
315            return _LevelsNumber + 1 ; } ;
316
317       map< string , GraphBase::Service * > MapOfServiceNames() ;
318       GraphBase::Service * GetServiceOfMap( char * name ) ;
319       bool SetServiceOfMap( GraphBase::Service * aService ) ;
320       int GetNewServiceInstanceNumber( char * aServiceName ) ;
321
322       SUPERV::ListOfStrings * LevelNodes(long aLevel ) ;
323       long ThreadsMax() {
324            return _ThreadsMax ; } ;
325
326       long SubGraphsNumber() {
327            return _SubGraphsNumber ; } ;
328
329       int NodesNumber(const int aLevel ) {
330           return _NodesNumber[ aLevel ] ; } ;
331       GraphBase::ComputingNode * SortedNodes( const int aLevel , const int index ) {
332              return (_SortedNodes[ aLevel ])[ index ] ; } ;
333
334       bool StartComponent( const int aThread ,
335                            const char * ComputerContainer ,
336                            const char * ComponentName ,
337                            Engines::Container_var & myContainer ,
338                            Engines::Component_var & objComponent ) ;
339
340   };
341   
342 };
343
344 #endif