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