Salome HOME
Merging with JR_ASV_2_1_0_deb_with_KERNEL_Head branch, which contains many bug fixes...
[modules/superv.git] / src / Supervision / INode_Impl.cxx
index 29689d1c44e26cb469efc23dc6b91617fc4466d0..8797369d8543026f44cedbc2ac2f18e3a38ff4f4 100644 (file)
 using namespace std;
 #include <stdio.h>
 #include <fstream>
-#include <strstream>
+//#include <sstream>
 #include <string>
 
-#include "utilities.h"
+//#include "utilities.h"
 
 #include "LNode_Impl.hxx"
 
@@ -24,20 +24,21 @@ INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
                       PortableServer::ObjectId * contId , 
                       const char *instanceName ,
                        const char *interfaceName ,
-                       const char *aDataFlowName ) :
+                       const char *aDataFlowName ,
+                       const SUPERV::KindOfNode aKindOfNode ) :
 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
-  CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName ) {
+  CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowName , aKindOfNode ) {
 //  MESSAGE("INode_Impl::INode_Impl activate object instanceName("
 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
 //          << hex << (void *) this << dec )
 //  _thisObj = this ;
 //  _id = _poa->activate_object(_thisObj);
-  MESSAGE( "INode_Impl::INode_Impl " << aDataFlowName );
-  beginService( "INode_Impl::INode_Impl" );
+//  MESSAGE( "INode_Impl::INode_Impl " << aDataFlowName );
+//  beginService( "INode_Impl::INode_Impl" );
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
-  endService( "INode_Impl::INode_Impl" );  
+//  endService( "INode_Impl::INode_Impl" );  
 }
 
 INode_Impl::INode_Impl() {
@@ -54,22 +55,22 @@ INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
                         const SUPERV::KindOfNode NodeKindOfNode ) :
 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName , NodeKindOfNode , FuncName , aPythonFunction ) {
-  beginService( "INode_Impl::INode_Impl" );
+//  beginService( "INode_Impl::INode_Impl" );
   if ( FuncName ) {
-    cout << "INode_Impl::CNode_Impl " << (void *) FuncName << " " << FuncName
-         << " " << strlen( FuncName ) << endl ;
+//    cout << "INode_Impl::CNode_Impl " << (void *) FuncName << " " << FuncName
+//         << " " << strlen( FuncName ) << endl ;
   }
   if ( NodeKindOfNode == SUPERV::InLineNode ) {
-    MESSAGE( "INode_Impl::INode_Impl " << FuncName << " _poa->activate_object" );
+//    MESSAGE( "INode_Impl::INode_Impl " << FuncName << " _poa->activate_object" );
     _thisObj = this ;
     _id = _poa->activate_object(_thisObj);
   }
-  MESSAGE("INode_Impl::INode_Impl " << FuncName << " " << strlen( FuncName ) ) ;
+//  MESSAGE("INode_Impl::INode_Impl " << FuncName << " " << strlen( FuncName ) ) ;
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
 //  DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
-  endService( "INode_Impl::INode_Impl" );  
+//  endService( "INode_Impl::INode_Impl" );  
 }
 
 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
@@ -83,18 +84,18 @@ INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
                         const SUPERV::KindOfNode NodeKindOfNode ) :
 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , SALOME_ModuleCatalog::Service() , FuncName[0].c_str() , NodeKindOfNode , FuncName , aPythonFunction ) {
-  beginService( "INode_Impl::INode_Impl" );
+//  beginService( "INode_Impl::INode_Impl" );
   if ( NodeKindOfNode == SUPERV::InLineNode ) {
-    MESSAGE( "INode_Impl::INode_Impl " << FuncName[0] << " _poa->activate_object" );
+//    MESSAGE( "INode_Impl::INode_Impl " << FuncName[0] << " _poa->activate_object" );
     _thisObj = this ;
     _id = _poa->activate_object(_thisObj);
   }
-  MESSAGE("INode_Impl::INode_Impl " << FuncName[0].c_str() << " " << strlen( FuncName[0].c_str() ) ) ;
+//  MESSAGE("INode_Impl::INode_Impl " << FuncName[0].c_str() << " " << strlen( FuncName[0].c_str() ) ) ;
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
 //  DataFlowNode()->SetPythonFunction( FuncName , aPythonFunction ) ;
-  endService( "INode_Impl::INode_Impl" );  
+//  endService( "INode_Impl::INode_Impl" );  
 }
 
 INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
@@ -106,18 +107,20 @@ INode_Impl::INode_Impl( CORBA::ORB_ptr orb ,
                         GraphEditor::InNode * aDataFlowNode ) :
 //  Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
   CNode_Impl( orb , poa , contId , instanceName , interfaceName , aDataFlowEditor , aDataFlowNode ) {
-  MESSAGE( DataFlowNode()->Name() << " " );
-  beginService( "INode_Impl::INode_Impl" );
-  if ( DataFlowNode()->IsInLineNode() ) {
-    MESSAGE( "INode_Impl::INode_Impl " << DataFlowNode()->PyFuncName()
-             << " _poa->activate_object" );
+//  beginService( "INode_Impl::INode_Impl" );
+  if ( DataFlowNode() && DataFlowNode()->IsInLineNode() ) {
+//    MESSAGE( "INode_Impl::INode_Impl " << DataFlowNode()->PyFuncName()
+//             << " _poa->activate_object" );
     _thisObj = this ;
     _id = _poa->activate_object(_thisObj);
   }
+  else {
+//    MESSAGE( "INode_Impl::INode_Impl NO _poa->activate_object" );
+  }
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
-  endService( "INode_Impl::INode_Impl" );  
+//  endService( "INode_Impl::INode_Impl" );  
 }
 
 INode_Impl::~INode_Impl() {
@@ -134,6 +137,9 @@ void INode_Impl::destroy() {
       delete(_id) ;
       _thisObj->_remove_ref();
     }
+    else {
+      MESSAGE("INode_Impl::destroy ERROR ") ;
+    }
   }
   endService( "INode_Impl::Destroy" );
 }
@@ -142,9 +148,10 @@ bool INode_Impl::Delete() {
 //  beginService( "INode_Impl::Delete" );
   bool RetVal = false ;
   if ( DataFlowEditor()->IsEditing() ) {
+    DeletePorts() ;
     RetVal = DataFlowEditor()->RemoveNode( Name() ) ;
     if ( RetVal )
-      RetVal = DataFlowEditor()->IsValid() ;
+      RetVal = DataFlowEditor()->UnValid() ;
   }
 //  endService( "INode_Impl::Delete" );
   return RetVal ;
@@ -184,9 +191,11 @@ SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
   SUPERV::Port_ptr InEndobject = SUPERV::Port::_nil() ;
   Port_Impl * myInPort = NULL ;
   bool InPortCreated = false ;
+//  MESSAGE( "CNode_Impl::InPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
+//           << aParameterType << " )" ) ;
   GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
-  if ( anInPort == NULL && DataFlowNode()->IsOneOfInLineNodes() ) {
-    anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType ) ;
+  if ( anInPort == NULL ) {
+    anInPort = DataFlowNode()->AddInPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
     InPortCreated = true ;
   }
   if ( anInPort ) {
@@ -207,8 +216,8 @@ SUPERV::Port_ptr INode_Impl::InPort( const char *aParameterName ,
   }
 
   if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
-       ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
-         DataFlowNode()->IsEndSwitchNode() ) ) {
+       ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ) ) {
+//         || DataFlowNode()->IsEndSwitchNode() ) ) {
     Outobject = OutPort( aParameterName , aParameterType ) ;
     if ( DataFlowNode()->IsLoopNode() ) {
       LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
@@ -225,9 +234,11 @@ SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
                                       const char *aParameterType ) {
   Port_Impl * myOutPort = NULL ;
   SUPERV::Port_ptr Outobject = SUPERV::Port::_nil() ;
+//  MESSAGE( "CNode_Impl::OutPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
+//           << aParameterType << " )" ) ;
   GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
-  if ( anOutPort == NULL && DataFlowNode()->IsOneOfInLineNodes() ) {
-    anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType ) ;
+  if ( anOutPort == NULL ) {
+    anOutPort = DataFlowNode()->AddOutPort( aParameterName , aParameterType , SUPERV::InLineParameter ) ;
   }
   if ( anOutPort ) {
     Outobject = anOutPort->ObjRef() ;
@@ -251,80 +262,100 @@ SUPERV::Port_ptr INode_Impl::OutPort( const char *aParameterName ,
   return SUPERV::Port::_duplicate( Outobject );
 }
 
-#if 0
-bool INode_Impl::BusPort( const char * InOutParameterName ,
-                         const char * InOutParameterType ,
-                        SUPERV::Port_out InputPort ,
-                        SUPERV::Port_out OutputPort ) {
-  return BusPorts( InOutParameterName , InOutParameterType ,
-                   InOutParameterName , InOutParameterType ,
-                   InputPort , OutputPort ) ;
-}
+SUPERV::StreamPort_ptr INode_Impl::InStreamPort( const char *aParameterName ,
+                                                 const SALOME_ModuleCatalog::DataStreamType aParameterType ,
+                                                 const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
+  SUPERV::StreamPort_ptr Inobject = SUPERV::StreamPort::_nil() ;
+  if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
+    StreamPort_Impl * myInStreamPort = NULL ;
+    bool InPortCreated = false ;
+    MESSAGE( "INode_Impl::InStreamPort " << DataFlowNode()->Name() << "->AddInPort( " << aParameterName << " , "
+             << aParameterType << " )" ) ;
+    GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( aParameterName ) ;
+    if ( anInPort && !anInPort->IsDataStream() ) {
+      MESSAGE( "INode_Impl::InStreamPort ERROR !IsDataStream " ) ;
+    }
+    else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
+      if ( anInPort == NULL ) {
+        anInPort = DataFlowNode()->ComputingNode()->AddInDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
+        InPortCreated = true ;
+      }
 
-bool INode_Impl::BusPorts( const char * InputParameterName ,
-                          const char * InputParameterType ,
-                          const char * OutputParameterName ,
-                          const char * OutputParameterType ,
-                         SUPERV::Port_out InputPort ,
-                         SUPERV::Port_out OutputPort ) {
-  beginService( "INode_Impl::BusPorts" );
-  bool RetVal = false ;
-  Port_Impl * myInPort = NULL ;
-  Port_Impl * myOutPort = NULL ;
-  SUPERV::Port_var Inobject = SUPERV::Port::_nil() ;
-  SUPERV::Port_var Outobject = SUPERV::Port::_nil() ;
-//  if ( DataFlowNode()->GetInPort( InputParameterName ) ||
-//       DataFlowNode()->GetOutPort( OutputParameterName ) ) {
-//  }
-//  else {
-    GraphBase::InPort * anInPort = DataFlowNode()->AddInPort( InputParameterName ,
-                                                             InputParameterType ) ;
-    if ( anInPort ) {
-      myInPort = new Port_Impl( _Orb , _Poa , _ContId ,
+      if ( anInPort ) {
+        Inobject = SUPERV::StreamPort::_narrow( anInPort->ObjRef() ) ;
+        if ( CORBA::is_nil( Inobject ) ) {
+          myInStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
                                 instanceName() , interfaceName() ,
                                 DataFlowEditor() ,
                                 DataFlowNode() ,
-//                                InputParameterName ) ;
                                 (GraphBase::Port * ) anInPort ,
                                 true ) ;
-      GraphBase::OutPort * anOutPort = DataFlowNode()->AddOutPort( OutputParameterName ,
-                                                                  OutputParameterType ) ;
-      if ( anOutPort ) {
-        const CORBA::Any * anAny = anOutPort->Value() ;
-        myOutPort = new Port_Impl( _Orb , _Poa , _ContId ,
-                                  instanceName() , interfaceName() ,
-                                  DataFlowEditor() ,
-                                  DataFlowNode() ,
-//                                  OutputParameterName ,
-                                  (GraphBase::Port * ) anOutPort ,
-                                  false ,
-                                  anAny ) ;
-        DataFlowNode()->InOutPort( anInPort , anOutPort ) ;
-        RetVal = true ;
+          if ( myInStreamPort ) {
+            PortableServer::ObjectId * id = myInStreamPort->getId() ;
+            CORBA::Object_var obj = _poa->id_to_reference(*id) ;
+            Inobject = SUPERV::StreamPort::_narrow(obj) ;
+            anInPort->ObjRef( SUPERV::StreamPort::_duplicate( Inobject ) ) ;
+         }
+       }
       }
     }
-//  }
-  if ( RetVal && myInPort && myOutPort ) {
-    if ( DataFlowNode()->CoupledNode() ) {
-      GraphBase::InPort * anInPort ;
-      anInPort = DataFlowNode()->CoupledNode()->AddInPort( OutputParameterName ,
-                                                          OutputParameterType ) ;
-      GraphBase::OutPort * anOutPort ;
-      anOutPort = DataFlowNode()->CoupledNode()->AddOutPort( InputParameterName ,
-                                                            InputParameterType ) ;
-      DataFlowNode()->CoupledNode()->InOutPort( anInPort , anOutPort ) ;
+
+//    if ( !CORBA::is_nil( Inobject ) && InPortCreated &&
+//         ( DataFlowNode()->IsLoopNode() || DataFlowNode()->IsEndLoopNode() ||
+//           DataFlowNode()->IsEndSwitchNode() ) ) {
+//      Outobject = OutPort( aParameterName , aParameterType ) ;
+//      if ( DataFlowNode()->IsLoopNode() ) {
+//        LNode_Impl * myLoopNode = (LNode_Impl * ) this ;
+//        InEndobject = myLoopNode->Coupled()->InPort( aParameterName , aParameterType ) ;
+//        DataFlowEditor()->AddLink( Outobject->Node()->Name() , Outobject->Name() ,
+//                                   InEndobject->Node()->Name() , InEndobject->Name() ) ;
+//      }
+//    }
+    DataFlowEditor()->UnValid() ;
+  }
+  return SUPERV::StreamPort::_duplicate( Inobject ) ;
+}
+
+SUPERV::StreamPort_ptr INode_Impl::OutStreamPort( const char * aParameterName ,
+                                                  const SALOME_ModuleCatalog::DataStreamType aParameterType ,
+                                                  const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
+  StreamPort_Impl * myOutStreamPort = NULL ;
+  SUPERV::StreamPort_ptr Outobject = SUPERV::StreamPort::_nil() ;
+  if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
+    MESSAGE( "INode_Impl::OutStreamPort " << DataFlowNode()->Name() << "->AddOutPort( " << aParameterName << " , "
+             << aParameterType << " )" ) ;
+    GraphBase::OutPort * anOutPort = DataFlowNode()->GetChangeOutPort( aParameterName ) ;
+    if ( anOutPort && !anOutPort->IsDataStream() ) {
+      MESSAGE( "INode_Impl::OutStreamPort ERROR !IsDataStream " ) ;
+    }
+    else if ( DataFlowEditor()->Graph()->IsDataStreamNode() ) {
+      if ( anOutPort == NULL ) {
+        anOutPort = DataFlowNode()->ComputingNode()->AddOutDataStreamPort( aParameterName , aParameterType , aDependency , SUPERV::DataStreamParameter ) ;
+      }
+
+      if ( anOutPort ) {
+        Outobject = SUPERV::StreamPort::_narrow( anOutPort->ObjRef() ) ;
+        if ( CORBA::is_nil( Outobject ) ) {
+          const CORBA::Any * anAny = anOutPort->Value() ;
+          myOutStreamPort = new StreamPort_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 DataFlowEditor() ,
+                                 DataFlowNode() ,
+                                 (GraphBase::Port * ) anOutPort ,
+                                 false ,
+                                 anAny ) ;
+          if ( myOutStreamPort ) {
+            PortableServer::ObjectId * id = myOutStreamPort->getId() ;
+            CORBA::Object_var obj = _poa->id_to_reference(*id) ;
+            Outobject = SUPERV::StreamPort::_narrow(obj) ;
+            anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( Outobject ) ) ;
+         }
+       }
+      }
     }
-    PortableServer::ObjectId * id = myInPort->getId() ;
-    CORBA::Object_var obj = _poa->id_to_reference(*id) ;
-    Inobject = SUPERV::Port::_narrow(obj) ;
-    InputPort = SUPERV::Port::_duplicate( Inobject ) ;
-    id = myOutPort->getId() ;
-    obj = _poa->id_to_reference(*id);
-    Outobject = SUPERV::Port::_narrow(obj) ;
-    OutputPort = SUPERV::Port::_duplicate( Outobject ) ;
+    DataFlowEditor()->UnValid() ;
   }
-  endService( "INode_Impl::BusPorts" );
-  return RetVal ;
+  return SUPERV::StreamPort::_duplicate( Outobject );
 }
-#endif
+