Salome HOME
This commit was generated by cvs2git to create branch
[modules/superv.git] / src / Supervision / StreamGraph_Impl.cxx
diff --git a/src/Supervision/StreamGraph_Impl.cxx b/src/Supervision/StreamGraph_Impl.cxx
new file mode 100644 (file)
index 0000000..4d6fb18
--- /dev/null
@@ -0,0 +1,323 @@
+//  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : StreamGraph_Impl.cxx
+//  Author : Jean Rahuel
+//  Module : SUPERV
+//  $Header: 
+
+using namespace std;
+
+#include "StreamGraph_Impl.hxx"
+
+StreamGraph_Impl::StreamGraph_Impl( CORBA::ORB_ptr orb ,
+                                   PortableServer::POA_ptr poa ,
+                                   PortableServer::ObjectId * contId , 
+                                   const char *instanceName ,
+                                    const char *interfaceName ,
+                                    const char *aDataFlowName ) :
+  Graph_Impl(orb, poa, contId, instanceName, interfaceName, aDataFlowName , SUPERV::DataStreamGraph ) {
+//  MESSAGE("StreamGraph_Impl::StreamGraph_Impl activate object instanceName("
+//          << instanceName << ") interfaceName(" << interfaceName << ") --> "
+//          << hex << (void *) this << dec )
+  beginService( "StreamGraph_Impl::StreamGraph_Impl" );
+  _thisObj = this ;
+  _id = _poa->activate_object(_thisObj);
+  _Orb = CORBA::ORB::_duplicate(orb);
+  _Poa = poa ;
+  _ContId = contId ;
+
+  endService( "StreamGraph_Impl::StreamGraph_Impl" );
+}
+
+StreamGraph_Impl::StreamGraph_Impl() {
+}
+
+StreamGraph_Impl::~StreamGraph_Impl() {
+  beginService( "StreamGraph_Impl::~StreamGraph_Impl" );
+  endService( "StreamGraph_Impl::~StreamGraph_Impl" );
+}
+
+void StreamGraph_Impl::destroy() {
+  beginService( "StreamGraph_Impl::destroy" );
+  _poa->deactivate_object(*_id) ;
+  CORBA::release(_poa) ;
+  delete(_id) ;
+  _thisObj->_remove_ref();
+  endService( "StreamGraph_Impl::destroy" );
+}
+
+SUPERV::StreamGraph_ptr StreamGraph_Impl::StreamCopy() {
+  beginService( "StreamGraph_Impl::StreamCopy" );
+  StreamGraph_Impl * myStreamGraph ;
+  myStreamGraph = new StreamGraph_Impl( _Orb , _Poa, _ContId,
+                                        instanceName() , interfaceName() ,
+                                        DataFlowEditor()->Graph()->Name() ) ;
+  PortableServer::ObjectId * id = myStreamGraph->getId() ;
+  CORBA::Object_var obj = _poa->id_to_reference(*id);
+  SUPERV::StreamGraph_var iobject ;
+  iobject = SUPERV::StreamGraph::_narrow(obj) ;
+  GraphBase::SGraph * aSGraph = GetGraph() ;
+  myStreamGraph->LoadGraph( aSGraph ) ;
+  endService( "StreamGraph_Impl::StreamCopy" );
+  return SUPERV::StreamGraph::_duplicate(iobject) ;
+}
+
+SUPERV::StreamLink_ptr StreamGraph_Impl::StreamLink(  SUPERV::StreamPort_ptr OutStreamPort ,
+                                                      SUPERV::StreamPort_ptr InStreamPort ) {
+  beginService( "StreamGraph_Impl::StreamLink" );
+  SUPERV::StreamLink_var iobject = SUPERV::StreamLink::_nil() ;
+  if ( DataFlowEditor()->IsEditing() &&
+       !DataFlowEditor()->IsReadOnly() ) {
+    const char * DataFlowOutNodeName = OutStreamPort->Node()->Name() ;
+    GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
+    const char * DataFlowInNodeName = InStreamPort->Node()->Name() ;
+    GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
+    if ( DataFlowOutNode && DataFlowInNode ) {
+      StreamLink_Impl * myStreamLink = new StreamLink_Impl( _Orb , _Poa , _ContId ,
+                                          instanceName() , interfaceName() ,
+                                          DataFlowEditor() ,
+                                          DataFlowInNode ,
+                                          InStreamPort->Name() ,
+                                          DataFlowOutNode ,
+                                          OutStreamPort->Name() ,
+                                          true ) ;
+      PortableServer::ObjectId * id = myStreamLink->getId() ;
+      CORBA::Object_var obj = _poa->id_to_reference(*id);
+      iobject = SUPERV::StreamLink::_narrow(obj) ;
+    }
+  }
+  endService( "StreamGraph_Impl::StreamLink" );
+  return SUPERV::StreamLink::_duplicate(iobject) ;
+}
+
+SUPERV::ListOfStreamLinks * StreamGraph_Impl::GStreamLinks() {
+  return StreamLinks( NULL , NULL ) ;
+}
+
+SUPERV::ListOfStreamLinks * StreamGraph_Impl::StreamLinks( GraphBase::ComputingNode * theNode ,
+                                                           const char * anInputParam ) {
+  bool begin = true ;
+  SUPERV::ListOfStreamLinks_var RetVal = new SUPERV::ListOfStreamLinks ;
+  int i , j , countlink ;
+  countlink = 0 ;
+  for ( i = 0 ; i < DataFlowEditor()->Graph()->GraphNodesSize() ; i++ ) {
+    GraphEditor::InNode * aNode = NULL ;
+    aNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GraphNodes( i )->GetInNode() ;
+    bool ToProcess = false ;
+    if ( theNode == NULL ) {
+      ToProcess = true ;
+    }
+    else {
+      if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
+        if ( !theNode->IsEndSwitchNode() ) {
+          ToProcess = true ;
+       }
+      }
+      else if ( theNode->IsEndSwitchNode() ) {
+        ToProcess = true ;
+      }
+    }
+    if ( ToProcess ) {
+      for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
+        GraphBase::InPort * anInPort = NULL ;
+        anInPort = aNode->GetChangeNodeInPort( j ) ;
+        if ( anInputParam == NULL ||
+             !strcmp( anInPort->PortName() , anInputParam ) ) {
+          GraphBase::OutPort * anOutPort = NULL ;
+          anOutPort = anInPort->GetOutPort() ;
+          if ( anOutPort && anOutPort->IsDataStream() ) {
+            if ( strcmp( anOutPort->NodeName() , Name() ) ) {
+              MESSAGE("StreamGraph_Impl::StreamLinks " << anOutPort->NodeName() << "("
+                      << anOutPort->PortName() << ") --> " << aNode->Name() << "("
+                      << anInPort->PortName() << ")" ) ;
+              if ( theNode == NULL ||
+                   ( theNode != NULL && !theNode->IsEndSwitchNode() &&
+                     !strcmp( theNode->Name() , aNode->Name() ) ) ) {
+                if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
+                     ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
+                                                          anOutPort->NodeName() ) ) ) {
+                  MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
+                          << anOutPort->PortName() << ") --> " << aNode->Name() << "("
+                          << anInPort->PortName() << ")" << " ignored" ) ;
+               }
+                else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
+                  if ( begin ) {
+                    beginService( "StreamGraph_Impl::StreamLinks" );
+                    begin = false ;
+                  }
+                  GraphEditor::InNode * anOutNode = NULL ;
+                  anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
+                  if ( anOutNode ) {
+                    StreamLink_Impl * myStreamLink = new StreamLink_Impl(
+                                          _Orb , _Poa , _ContId ,
+                                          instanceName() , interfaceName() ,
+                                          DataFlowEditor() ,
+                                          aNode ,
+                                          anInPort->PortName() ,
+                                          anOutNode ,
+                                          anOutPort->PortName() ,
+                                          false ) ;
+                    PortableServer::ObjectId * id = myStreamLink->getId() ;
+                    CORBA::Object_var obj = _poa->id_to_reference(*id);
+                    SUPERV::StreamLink_var iobject ;
+                    iobject = SUPERV::StreamLink::_narrow(obj) ;
+                    RetVal->length( countlink + 1 ) ;
+                    RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
+                    anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
+                    MESSAGE( "Link" << countlink-1 << " "
+                             << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
+                             << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
+                             << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
+                             << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
+                 }
+               }
+                else {
+                  RetVal->length( countlink + 1 ) ;
+                  RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
+                  MESSAGE( "Link" << countlink-1 << " "
+                           << RetVal[countlink-1]->OutStreamPort()->Node()->Name() << "("
+                           << RetVal[countlink-1]->OutStreamPort()->Name() << ") --> "
+                           << RetVal[countlink-1]->InStreamPort()->Node()->Name() << "("
+                           << RetVal[countlink-1]->InStreamPort()->Name() << ")" ) ;
+               }
+             }
+           }
+          }
+       }
+      }
+    }
+    for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
+      GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
+      int k ;
+      for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
+        GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
+        GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
+        if ( theNode == NULL ||
+             !strcmp( theNode->Name() , aNode->Name() ) ) {
+          if ( anInPort->IsDataStream() ) {
+            if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
+              if ( anInputParam == NULL ||
+                   !strcmp( anInPort->PortName() , anInputParam ) ) {
+                if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
+                     ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
+                                                           anOutPort->NodeName() ) ) ) {
+                  MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
+                          << anOutPort->PortName() << ") --> " << toNode->Name() << "("
+                          << anInPort->PortName() << ")" << " ignored" ) ;
+               }
+                else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
+                  if ( begin ) {
+                    beginService( "Graph_Impl::StreamLinks" );
+                    begin = false ;
+                  }
+                  StreamLink_Impl * myStreamLink = new StreamLink_Impl(
+                                        _Orb , _Poa , _ContId ,
+                                        instanceName() , interfaceName() ,
+                                        DataFlowEditor() ,
+                                        toNode ,
+                                        anInPort->PortName() ,
+                                        aNode ,
+                                        anOutPort->PortName() ,
+                                        false ) ;
+                  PortableServer::ObjectId * id = myStreamLink->getId() ;
+                  CORBA::Object_var obj = _poa->id_to_reference(*id);
+                  SUPERV::StreamLink_var iobject ;
+                  iobject = SUPERV::StreamLink::_narrow(obj) ;
+                  RetVal->length( countlink + 1 ) ;
+                  RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( iobject ) ;
+                  anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
+               }
+                else {
+                  RetVal->length( countlink + 1 ) ;
+                  RetVal[ countlink++ ] = SUPERV::StreamLink::_duplicate( SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ) ;
+               }
+                MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
+                         << anOutPort->PortName() << ") --> " << toNode->Name() << "("
+                         << anInPort->PortName() << ")" << " selected" ) ;
+             }
+              else {
+                MESSAGE( "StreamLink " << anOutPort->NodeName() << "("
+                         << anOutPort->PortName() << ") --> " << toNode->Name() << "("
+                         << anInPort->PortName() << ")" << " skipped" ) ;
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+//#if 0
+  const char * NodeName = "" ;
+  const char * InputParamName = "" ;
+  if ( theNode ) {
+    NodeName = theNode->Name() ;
+  }
+  if ( anInputParam ) {
+    InputParamName = anInputParam ;
+  }
+  MESSAGE( RetVal->length() << " StreamLinks of Node " << NodeName << " and of InPort " << InputParamName ) ;
+  for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
+    MESSAGE( "Link" << i << " " << RetVal[i]->OutStreamPort()->Node()->Name() << "("
+             << RetVal[i]->OutStreamPort()->Name() << ") --> "
+             << RetVal[i]->InStreamPort()->Node()->Name() << "("
+             << RetVal[i]->InStreamPort()->Name() << ")" ) ;
+  }
+//#endif
+  if ( !begin ) {
+    endService( "StreamGraph_Impl::StreamLinks" );
+  }
+  return ( RetVal._retn() ) ;
+}
+
+bool StreamGraph_Impl::SetStreamParams( const long Timeout ,
+                                        const SUPERV::KindOfDataStreamTrace DataStreamTrace ,
+                                        const double  DeltaTime ) {
+  return DataFlowEditor()->StreamGraph()->SetStreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
+}
+
+void StreamGraph_Impl::StreamParams( long & Timeout ,
+                                     SUPERV::KindOfDataStreamTrace & DataStreamTrace ,
+                                     double & DeltaTime ) {
+  DataFlowEditor()->StreamGraph()->StreamParams( Timeout , DataStreamTrace , DeltaTime ) ;
+}
+
+SUPERV::Graph_ptr StreamGraph_Impl::ToFlowGraph() {
+  SUPERV::Graph_var iobject = SUPERV::Graph::_nil() ;
+  beginService( "StreamGraph_Impl::ToFlowGraph" );
+//  Graph_Impl * myFlowGraph = new Graph_Impl( _Orb , _Poa , _ContId ,
+//                                             instanceName() , interfaceName() ) ;
+//  PortableServer::ObjectId * id = myFlowGraph->getId() ;
+//  CORBA::Object_var obj = _poa->id_to_reference(*id);
+//  iobject = SUPERV::Graph::_narrow(obj) ;
+  endService( "StreamGraph_Impl::ToFlowGraph" );
+  return SUPERV::Graph::_duplicate( iobject ) ;
+}
+
+bool StreamGraph_Impl::StreamMerge(const SUPERV::StreamGraph_ptr aGraph ) {
+  beginService( "StreamGraph_Impl::StreamMerge" );
+  bool RetVal = true ;
+  endService( "StreamGraph_Impl::StreamMerge" );
+  return RetVal ;
+}
+