Salome HOME
Fix for bug IPAL9558 : Maintainance Mandrake porting: black rectangle in table view.
[modules/superv.git] / src / GraphBase / DataFlowBase_StreamGraph.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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : DataFlowBase_StreamGraph.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header:
28
29 using namespace std;
30 #include "DataFlowBase_StreamGraph.hxx"
31
32 #include "SALOME_LifeCycleCORBA.hxx"
33
34 GraphBase::StreamGraph::StreamGraph() :
35            Graph() {
36   cdebug << "GraphBase::StreamGraph::StreamGraph" << endl ;
37 }
38
39 GraphBase::StreamGraph::StreamGraph( 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 //                                             const char * DebugFileName ) :
46 //           Graph( ORB ,ptrNamingService , DataFlowName , DebugFileName ) {
47            Graph( ORB ,ptrNamingService , DataFlowName , DataFlowkind , Graph_prof_debug , Graph_fdebug ) {
48   _Timeout = 300 ;
49   _DataStreamTrace = SUPERV::WithoutTrace ;
50   _DeltaTime = 0 ;
51   Kind( SUPERV::DataStreamGraph ) ;
52   cdebug << "GraphBase::StreamGraph::StreamGraph" << endl ;
53 }
54
55 GraphBase::StreamGraph::StreamGraph( CORBA::ORB_ptr ORB ,
56                        SALOME_NamingService* ptrNamingService ,
57                        const SALOME_ModuleCatalog::Service& DataFlowService ,
58                        const char *DataFlowComponentName ,
59                        const char *DataFlowInterfaceName ,
60                        const char *DataFlowName ,
61                        const SUPERV::KindOfNode DataFlowkind ,
62                        const SUPERV::SDate DataFlowFirstCreation ,
63                        const SUPERV::SDate DataFlowLastModification ,
64                        const char * DataFlowEditorRelease ,
65                        const char * DataFlowAuthor ,
66                        const char * DataFlowComputer ,
67                        const char * DataFlowComment ,
68                        int * Graph_prof_debug ,
69                        ofstream * Graph_fdebug ) :
70 //                       const char * DebugFileName ) :
71            Graph( ORB ,ptrNamingService , DataFlowService , DataFlowComponentName ,
72                   DataFlowInterfaceName , DataFlowName , DataFlowkind ,
73                   DataFlowFirstCreation , DataFlowLastModification  ,
74                   DataFlowEditorRelease , DataFlowAuthor , DataFlowComputer ,
75                   DataFlowComment , Graph_prof_debug , Graph_fdebug ) {
76 //                  DataFlowComment , DebugFileName ) {
77   _Timeout = 300 ;
78   _DataStreamTrace = SUPERV::WithoutTrace ;
79   _DeltaTime = 0 ;
80   cdebug << "GraphBase::StreamGraph::StreamGraph" << endl ;
81 }
82
83 GraphBase::StreamGraph::~StreamGraph() {
84   cdebug << "GraphBase::StreamGraph::~StreamGraph" << endl ;
85 }
86
87 bool GraphBase::StreamGraph::SetStreamParams( const long Timeout ,
88                                               const SUPERV::KindOfDataStreamTrace DataStreamTrace ,
89                                               const double  DeltaTime ) {
90   _Timeout = Timeout ;
91   _DataStreamTrace = DataStreamTrace ;
92   _DeltaTime = DeltaTime ;
93   cdebug << "GraphBase::StreamGraph:::SetStreamGraph _Timeout " << _Timeout << " _DataStreamTrace " << _DataStreamTrace << " _DeltaTime " << _DeltaTime
94          << endl ;
95   return true ;
96 }
97
98 void GraphBase::StreamGraph::StreamParams( long & Timeout ,
99                                            SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
100                                            double & DeltaTime ) const {
101   Timeout = _Timeout ;
102   DataStreamTrace = _DataStreamTrace ;
103   DeltaTime = _DeltaTime ;
104   cdebug << "GraphBase::StreamGraph:::StreamGraph _Timeout " << _Timeout << " _DataStreamTrace " << _DataStreamTrace << " _DeltaTime " << _DeltaTime
105          << endl ;
106 }
107
108 bool GraphBase::StreamGraph::CreateStreamTopology( const char * aDirectory ) {
109   cdebug_in << "GraphBase::StreamGraph::CreateStreamTopology()" << endl;
110   int istream ;
111   for ( istream = 1 ; istream <= SubStreamGraphsNumber() ; istream++ ) {
112     ostringstream astr ;
113     astr << istream << ends ;
114     string filename = string( Name() ) + string( "_" ) + astr.str().c_str() ;
115     string fullfilename = aDirectory + filename + ".cpl" ;
116     ofstream f( fullfilename.c_str() ) ;
117     f << "DEBUT " << filename << endl ;
118     f << "      TIMEOUT " << _Timeout << endl ;
119     f << "      TRACE   " << KindOfDataStreamTraceToString( _DataStreamTrace ) << endl ;
120     f << "      DELTAT  " << _DeltaTime << endl ;
121     f << endl ;
122     f << endl ;
123     f << "# Liste des codes" << endl ;
124     f << endl ;
125     map< string , GraphBase::Service * > aMapOfServiceNames = MapOfServiceNames() ;
126     map< string , GraphBase::Service * >::iterator aMapOfServiceNamesIterator ;
127     for ( aMapOfServiceNamesIterator = aMapOfServiceNames.begin() ;
128           aMapOfServiceNamesIterator != aMapOfServiceNames.end() ; aMapOfServiceNamesIterator++ ) {
129       GraphBase::Service * aService = aMapOfServiceNamesIterator->second ;
130       int n ;
131       for ( n = 0 ; n < GraphNodesSize() ; n++ ) {
132         if ( GetGraphNode( n )->HasDataStream() && GetChangeGraphNode( n )->SubStreamGraph() == istream ) {
133           if ( !strcmp( aService->ServiceName() , GetGraphNode( n )->ServiceName() ) ) {
134             f << "      CODE    " << aService->ServiceName() << endl ;
135             unsigned int j ;
136             cdebug << "CreateStreamTopology " << aService->ServiceName() << " InStreamParameter("
137                    << aService->ServiceInStreamParameter().length() << ") OutStreamParameter("
138                    << aService->ServiceOutStreamParameter().length() << ")" << endl ;
139             cdebug << aService->GetService() << endl ;
140             for ( j = 0 ; j < aService->ServiceInStreamParameter().length() ; j++ ) {
141               f << "            " << aService->ServiceInStreamParameter()[ j ].Parametername << "       "
142                 << DataStreamDependencyToString( aService->ServiceInStreamParameter()[ j ].Parameterdependency ) << "   IN      "
143                 << DataStreamToString( aService->ServiceInStreamParameter()[ j ].Parametertype ) << endl ;
144             }
145             for ( j = 0 ; j < aService->ServiceOutStreamParameter().length() ; j++ ) {
146               f << "            " << aService->ServiceOutStreamParameter()[ j ].Parametername << "      "
147                 << DataStreamDependencyToString( aService->ServiceOutStreamParameter()[ j ].Parameterdependency ) << "  OUT     "
148                 << DataStreamToString( aService->ServiceOutStreamParameter()[ j ].Parametertype ) << endl ;
149             }
150             f << "      FIN     #" << aService->ServiceName() << endl ;
151             f << endl ;
152             f << endl ;
153             break ;
154           }
155         }
156       }
157     }
158     f << endl ;
159     f << endl ;
160     f << "# Liste des instances" << endl ;
161     int j ;
162     for ( j = 0 ; j < GraphNodesSize() ; j++ ) {
163       if ( GetGraphNode( j )->HasDataStream() && GetChangeGraphNode( j )->SubStreamGraph() == istream ) {
164         f << endl ;
165         f << "  INSTANCE        " << GetGraphNode( j )->Name() << endl ;
166         f << "          CODE    " << GetGraphNode( j )->ServiceName() << endl ;
167         f << "          EXEC    \"" << GetGraphNode( j )->ServiceName() << "\"" << endl ;
168         f << "  FIN" << endl ;
169       }
170     }
171     f << endl ;
172     f << endl ;
173     f << endl ;
174     f << endl ;
175     f << endl ;
176     f << "# Liste des liens" << endl ;
177     f << endl ;
178     f << "      LIEN" << endl ;
179     for ( j = 0 ; j < GraphNodesSize() ; j++ ) {
180       if ( GetGraphNode( j )->HasDataStream() && GetChangeGraphNode( j )->SubStreamGraph() == istream ) {
181         int k ;
182         for ( k = 0 ; k < GetGraphNode( j )->GetNodeOutPortsSize() ; k++ ) {
183           if ( GetGraphNode( j )->GetNodeOutPort( k )->IsDataStream() ) {
184             long aNumberOfValues = ((GraphBase::OutDataStreamPort *) GetGraphNode( j )->GetNodeOutPort( k ))->NumberOfValues() ;
185             int n ;
186             for ( n = 0 ; n < GetGraphNode( j )->GetNodeOutPort( k )->InPortsSize() ; n++ ) {
187               SUPERV::KindOfSchema aKindOfSchema ;
188               SUPERV::KindOfInterpolation aKindOfInterpolation ;
189               SUPERV::KindOfExtrapolation aKindOfExtrapolation ;
190               ((GraphBase::InDataStreamPort *) GetGraphNode( j )->GetNodeOutPort( k )->InPorts( n ))->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
191               f << "            " << GetGraphNode( j )->Name() << "."
192                 << GetGraphNode( j )->GetNodeOutPort( k )->PortName() ;
193               if ( aNumberOfValues != 0 ) {
194                 f << "  NIVEAU " << aNumberOfValues ;
195               }
196               f << "            =>      "
197                 << GetGraphNode( j )->GetNodeOutPort( k )->InPorts( n )->NodeName() << "."
198                 << GetGraphNode( j )->GetNodeOutPort( k )->InPorts( n )->PortName()
199                 << "    " << aKindOfSchema << " " << aKindOfInterpolation ;
200               if ( aKindOfExtrapolation != SUPERV::EXTRANULL ) {
201                 f << "  " << aKindOfExtrapolation ;
202               }
203               f << " ;" << endl ;
204             }
205           }
206         }
207       }
208     }
209     f << "      FIN" << endl ;
210     f << endl ;
211     f << "FIN" << endl ;
212   }
213   cdebug_out << "GraphBase::StreamGraph::CreateStreamTopology()" << endl;
214   return true ;
215 }
216
217 ostream & operator<< (ostream & f ,const SUPERV::KindOfDataStreamTrace & s ) {
218   switch (s) {
219   case SUPERV::WithoutTrace :
220     f << "WithoutTrace";
221     break;
222   case SUPERV::SummaryTrace :
223     f << "SummaryTrace";
224     break;
225   case SUPERV::DetailedTrace :
226     f << "DetailedTrace";
227     break;
228   default :
229     f << "UndefinedKindOfDataStreamTrace";
230     break;
231   }
232
233   return f;
234 }
235
236