]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/StreamGraph_Impl.cxx
Salome HOME
*** empty log message ***
[modules/superv.git] / src / Supervision / StreamGraph_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
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   : StreamGraph_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30
31 #include "StreamGraph_Impl.hxx"
32
33 StreamGraph_Impl::StreamGraph_Impl( CORBA::ORB_ptr orb ,
34                                     PortableServer::POA_ptr poa ,
35                                     PortableServer::ObjectId * contId , 
36                                     const char *instanceName ,
37                                     const char *interfaceName ,
38                                     const char *aDataFlowName ) :
39   Graph_Impl(orb, poa, contId, instanceName, interfaceName, aDataFlowName , SUPERV::DataStreamGraph ) {
40 //  MESSAGE("StreamGraph_Impl::StreamGraph_Impl activate object instanceName("
41 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
42 //          << hex << (void *) this << dec )
43   beginService( "StreamGraph_Impl::StreamGraph_Impl" );
44   _thisObj = this ;
45   _id = _poa->activate_object(_thisObj);
46   _Orb = CORBA::ORB::_duplicate(orb);
47   _Poa = poa ;
48   _ContId = contId ;
49
50   endService( "StreamGraph_Impl::StreamGraph_Impl" );
51 }
52
53 StreamGraph_Impl::StreamGraph_Impl() {
54 }
55
56 StreamGraph_Impl::~StreamGraph_Impl() {
57   beginService( "StreamGraph_Impl::~StreamGraph_Impl" );
58   endService( "StreamGraph_Impl::~StreamGraph_Impl" );
59 }
60
61 void StreamGraph_Impl::destroy() {
62   beginService( "StreamGraph_Impl::destroy" );
63   _poa->deactivate_object(*_id) ;
64   CORBA::release(_poa) ;
65   delete(_id) ;
66   _thisObj->_remove_ref();
67   endService( "StreamGraph_Impl::destroy" );
68 }
69
70 SUPERV::StreamGraph_ptr StreamGraph_Impl::StreamCopy() {
71   beginService( "StreamGraph_Impl::StreamCopy" );
72   StreamGraph_Impl * myStreamGraph ;
73   myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
74                                         instanceName() , interfaceName() ,
75                                         DataFlowEditor()->Graph()->Name() ) ;
76   PortableServer::ObjectId * id = myStreamGraph->getId() ;
77   CORBA::Object_var obj = _poa->id_to_reference(*id);
78   SUPERV::StreamGraph_var iobject ;
79   iobject = SUPERV::StreamGraph::_narrow(obj) ;
80   GraphBase::SGraph * aSGraph = GetGraph() ;
81   myStreamGraph->LoadGraph( aSGraph ) ;
82   endService( "StreamGraph_Impl::StreamCopy" );
83   return SUPERV::StreamGraph::_duplicate(iobject) ;
84 }
85
86 SUPERV::StreamLink_ptr StreamGraph_Impl::StreamLink(  SUPERV::StreamPort_ptr OutStreamPort ,
87                                                       SUPERV::StreamPort_ptr InStreamPort ) {
88   beginService( "StreamGraph_Impl::StreamLink" );
89   SUPERV::StreamLink_var iobject = SUPERV::StreamLink::_nil() ;
90   if ( DataFlowEditor()->IsEditing() &&
91        !DataFlowEditor()->IsReadOnly() ) {
92     const char * DataFlowOutNodeName = OutStreamPort->Node()->Name() ;
93     GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
94     const char * DataFlowInNodeName = InStreamPort->Node()->Name() ;
95     GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
96     if ( DataFlowOutNode && DataFlowInNode ) {
97       StreamLink_Impl * myStreamLink = new StreamLink_Impl( _Orb , _Poa , _ContId ,
98                                           instanceName() , interfaceName() ,
99                                           DataFlowEditor() ,
100                                           DataFlowInNode ,
101                                           InStreamPort->Name() ,
102                                           DataFlowOutNode ,
103                                           OutStreamPort->Name() ,
104                                           true ) ;
105       PortableServer::ObjectId * id = myStreamLink->getId() ;
106       CORBA::Object_var obj = _poa->id_to_reference(*id);
107       iobject = SUPERV::StreamLink::_narrow(obj) ;
108     }
109   }
110   endService( "StreamGraph_Impl::StreamLink" );
111   return SUPERV::StreamLink::_duplicate(iobject) ;
112 }
113
114 SUPERV::ListOfStreamLinks * StreamGraph_Impl::GStreamLinks() {
115   return StreamLinks( NULL , NULL ) ;
116 }
117
118 SUPERV::ListOfStreamLinks * StreamGraph_Impl::StreamLinks( GraphBase::ComputingNode * theNode ,
119                                                            const char * anInputParam ) {
120   bool begin = true ;
121   SUPERV::ListOfStreamLinks_var RetVal = new SUPERV::ListOfStreamLinks ;
122   int i , j , countlink ;
123   countlink = 0 ;
124   for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
125     GraphEditor::InNode * aNode = NULL ;
126     aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
127     bool ToProcess = false ;
128     if ( theNode == NULL ) {
129       ToProcess = true ;
130     }
131     else {
132       if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
133         if ( !theNode->IsEndSwitchNode() ) {
134           ToProcess = true ;
135         }
136       }
137       else if ( theNode->IsEndSwitchNode() ) {
138         ToProcess = true ;
139       }
140     }
141     if ( ToProcess ) {
142       for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
143         GraphBase::InPort * anInPort = NULL ;
144         anInPort = aNode->GetChangeNodeInPort( j ) ;
145         if ( anInputParam == NULL ||
146              !strcmp( anInPort->PortName() , anInputParam ) ) {
147           GraphBase::OutPort * anOutPort = NULL ;
148           anOutPort = anInPort->GetOutPort() ;
149           if ( anOutPort && anOutPort->IsDataStream() ) {
150             if ( strcmp( anOutPort->NodeName() , Name() ) ) {
151               MESSAGE("StreamGraph_Impl::StreamLinks " << anOutPort->NodeName() << "("
152                       << anOutPort->PortName() << ") --> " << aNode->Name() << "("
153                       << anInPort->PortName() << ")" ) ;
154               if ( theNode == NULL ||
155                    ( theNode != NULL && !theNode->IsEndSwitchNode() &&
156                      !strcmp( theNode->Name() , aNode->Name() ) ) ) {
157                 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
158                      ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
159                                                           anOutPort->NodeName() ) ) ) {
160                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
161                           << anOutPort->PortName() << ") --> " << aNode->Name() << "("
162                           << anInPort->PortName() << ")" << " ignored" ) ;
163                 }
164                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
165                   if ( begin ) {
166                     beginService( "StreamGraph_Impl::StreamLinks" );
167                     begin = false ;
168                   }
169                   GraphEditor::InNode * anOutNode = NULL ;
170                   anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
171                   if ( anOutNode ) {
172                     StreamLink_Impl * myStreamLink = new StreamLink_Impl(
173                                           _Orb , _Poa , _ContId ,
174                                           instanceName() , interfaceName() ,
175                                           DataFlowEditor() ,
176                                           aNode ,
177                                           anInPort->PortName() ,
178                                           anOutNode ,
179                                           anOutPort->PortName() ,
180                                           false ) ;
181                     PortableServer::ObjectId * id = myStreamLink->getId() ;
182                     CORBA::Object_var obj = _poa->id_to_reference(*id);
183                     SUPERV::StreamLink_var iobject ;
184                     iobject = SUPERV::StreamLink::_narrow(obj) ;
185                     RetVal->length( countlink + 1 ) ;
186                     RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
187                     anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
188                     MESSAGE( "Link" << countlink-1 << " "
189                              << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
190                              << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
191                              << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
192                              << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
193                   }
194                 }
195                 else {
196                   RetVal->length( countlink + 1 ) ;
197                   RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
198                   MESSAGE( "Link" << countlink-1 << " "
199                            << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
200                            << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
201                            << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
202                            << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
203                 }
204               }
205             }
206           }
207         }
208       }
209     }
210     for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
211       GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
212       int k ;
213       for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
214         GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
215         GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
216         if ( theNode == NULL ||
217              !strcmp( theNode->Name() , aNode->Name() ) ) {
218           if ( anInPort->IsDataStream() ) {
219             if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
220               if ( anInputParam == NULL ||
221                    !strcmp( anInPort->PortName() , anInputParam ) ) {
222                 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
223                      ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
224                                                            anOutPort->NodeName() ) ) ) {
225                   MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
226                           << anOutPort->PortName() << ") --> " << toNode->Name() << "("
227                           << anInPort->PortName() << ")" << " ignored" ) ;
228                 }
229                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
230                   if ( begin ) {
231                     beginService( "Graph_Impl::StreamLinks" );
232                     begin = false ;
233                   }
234                   StreamLink_Impl * myStreamLink = new StreamLink_Impl(
235                                         _Orb , _Poa , _ContId ,
236                                         instanceName() , interfaceName() ,
237                                         DataFlowEditor() ,
238                                         toNode ,
239                                         anInPort->PortName() ,
240                                         aNode ,
241                                         anOutPort->PortName() ,
242                                         false ) ;
243                   PortableServer::ObjectId * id = myStreamLink->getId() ;
244                   CORBA::Object_var obj = _poa->id_to_reference(*id);
245                   SUPERV::StreamLink_var iobject ;
246                   iobject = SUPERV::StreamLink::_narrow(obj) ;
247                   RetVal->length( countlink + 1 ) ;
248                   RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
249                   anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
250                 }
251                 else {
252                   RetVal->length( countlink + 1 ) ;
253                   RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
254                 }
255                 MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
256                          << anOutPort->PortName() << ") --> " << toNode->Name() << "("
257                          << anInPort->PortName() << ")" << " selected" ) ;
258               }
259               else {
260                 MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
261                          << anOutPort->PortName() << ") --> " << toNode->Name() << "("
262                          << anInPort->PortName() << ")" << " skipped" ) ;
263               }
264             }
265           }
266         }
267       }
268     }
269   }
270 //#if 0
271   const char * NodeName = "" ;
272   const char * InputParamName = "" ;
273   if ( theNode ) {
274     NodeName = theNode->Name() ;
275   }
276   if ( anInputParam ) {
277     InputParamName = anInputParam ;
278   }
279   MESSAGE( RetVal->length() << " StreamLinks of Node " << NodeName << " and of InPort " << InputParamName ) ;
280   for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
281     MESSAGE( "Link" << i << " " << RetVal[i]->OutStreamPort()->Node()->Name() << "("
282              << RetVal[i]->OutStreamPort()->Name() << ") --> "
283              << RetVal[i]->InStreamPort()->Node()->Name() << "("
284              << RetVal[i]->InStreamPort()->Name() << ")" ) ;
285   }
286 //#endif
287   if ( !begin ) {
288     endService( "StreamGraph_Impl::StreamLinks" );
289   }
290   return ( RetVal._retn() ) ;
291 }
292
293 bool StreamGraph_Impl::SetStreamParams( const long Timeout ,
294                                         const SUPERV::KindOfDataStreamTrace DataStreamTrace ,
295                                         const double  DeltaTime ) {
296   return DataFlowEditor()->StreamGraph()->SetStreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
297 }
298
299 void StreamGraph_Impl::StreamParams( long & Timeout ,
300                                      SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
301                                      double & DeltaTime ) {
302   DataFlowEditor()->StreamGraph()->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
303 }
304
305 SUPERV::Graph_ptr StreamGraph_Impl::ToFlowGraph() {
306   SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
307   beginService( "StreamGraph_Impl::ToFlowGraph" );
308 //  Graph_Impl * myFlowGraph = new Graph_Impl( _Orb , _Poa , _ContId ,
309 //                                             instanceName() , interfaceName() ) ;
310 //  PortableServer::ObjectId * id = myFlowGraph->getId() ;
311 //  CORBA::Object_var obj = _poa->id_to_reference(*id);
312 //  iobject = SUPERV::Graph::_narrow(obj) ;
313   endService( "StreamGraph_Impl::ToFlowGraph" );
314   return SUPERV::Graph::_duplicate( iobject ) ;
315 }
316
317 bool StreamGraph_Impl::StreamMerge(const SUPERV::StreamGraph_ptr aGraph ) {
318   beginService( "StreamGraph_Impl::StreamMerge" );
319   bool RetVal = true ;
320   endService( "StreamGraph_Impl::StreamMerge" );
321   return RetVal ;
322 }
323