1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : StreamGraph_Impl.cxx
25 // Author : Jean Rahuel
31 #include "StreamGraph_Impl.hxx"
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" );
45 _id = _poa->activate_object(_thisObj);
46 _Orb = CORBA::ORB::_duplicate(orb);
50 endService( "StreamGraph_Impl::StreamGraph_Impl" );
53 StreamGraph_Impl::StreamGraph_Impl() {
56 StreamGraph_Impl::~StreamGraph_Impl() {
57 beginService( "StreamGraph_Impl::~StreamGraph_Impl" );
58 endService( "StreamGraph_Impl::~StreamGraph_Impl" );
61 void StreamGraph_Impl::destroy() {
62 beginService( "StreamGraph_Impl::destroy" );
63 _poa->deactivate_object(*_id) ;
64 CORBA::release(_poa) ;
66 _thisObj->_remove_ref();
67 endService( "StreamGraph_Impl::destroy" );
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) ;
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() ,
101 InStreamPort->Name() ,
103 OutStreamPort->Name() ,
105 PortableServer::ObjectId * id = myStreamLink->getId() ;
106 CORBA::Object_var obj = _poa->id_to_reference(*id);
107 iobject = SUPERV::StreamLink::_narrow(obj) ;
110 endService( "StreamGraph_Impl::StreamLink" );
111 return SUPERV::StreamLink::_duplicate(iobject) ;
114 SUPERV::ListOfStreamLinks * StreamGraph_Impl::GStreamLinks() {
115 return StreamLinks( NULL , NULL ) ;
118 SUPERV::ListOfStreamLinks * StreamGraph_Impl::StreamLinks( GraphBase::ComputingNode * theNode ,
119 const char * anInputParam ) {
121 SUPERV::ListOfStreamLinks_var RetVal = new SUPERV::ListOfStreamLinks ;
122 int i , j , countlink ;
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 ) {
132 if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
133 if ( !theNode->IsEndSwitchNode() ) {
137 else if ( theNode->IsEndSwitchNode() ) {
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" ) ;
164 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
166 beginService( "StreamGraph_Impl::StreamLinks" );
169 GraphEditor::InNode * anOutNode = NULL ;
170 anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
172 StreamLink_Impl * myStreamLink = new StreamLink_Impl(
173 _Orb , _Poa , _ContId ,
174 instanceName() , interfaceName() ,
177 anInPort->PortName() ,
179 anOutPort->PortName() ,
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() << ")" ) ;
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() << ")" ) ;
210 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
211 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
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" ) ;
229 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
231 beginService( "Graph_Impl::StreamLinks" );
234 StreamLink_Impl * myStreamLink = new StreamLink_Impl(
235 _Orb , _Poa , _ContId ,
236 instanceName() , interfaceName() ,
239 anInPort->PortName() ,
241 anOutPort->PortName() ,
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 ) ) ;
252 RetVal->length( countlink + 1 ) ;
253 RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
255 MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
256 << anOutPort->PortName() << ") --> " << toNode->Name() << "("
257 << anInPort->PortName() << ")" << " selected" ) ;
260 MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
261 << anOutPort->PortName() << ") --> " << toNode->Name() << "("
262 << anInPort->PortName() << ")" << " skipped" ) ;
271 const char * NodeName = "" ;
272 const char * InputParamName = "" ;
274 NodeName = theNode->Name() ;
276 if ( anInputParam ) {
277 InputParamName = anInputParam ;
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() << ")" ) ;
288 endService( "StreamGraph_Impl::StreamLinks" );
290 return ( RetVal._retn() ) ;
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 ) ;
299 void StreamGraph_Impl::StreamParams( long & Timeout ,
300 SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
301 double & DeltaTime ) {
302 DataFlowEditor()->StreamGraph()->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
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 ) ;
317 bool StreamGraph_Impl::StreamMerge(const SUPERV::StreamGraph_ptr aGraph ) {
318 beginService( "StreamGraph_Impl::StreamMerge" );
320 endService( "StreamGraph_Impl::StreamMerge" );