]> SALOME platform Git repositories - modules/superv.git/blobdiff - src/Supervision/Port_Impl.cxx
Salome HOME
SMH: 3.0.0 preparation = merged version (POLYWORK + RTVDEBUG01) + adopation for new GUI
[modules/superv.git] / src / Supervision / Port_Impl.cxx
index 3e0ee6792eebd442e80f6d254aa873c989ecef7f..8ca4b76ed6a9bef5e9011b01280eb8f7eb6fba24 100644 (file)
@@ -44,33 +44,26 @@ Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
                       const char *interfaceName ,
                       GraphEditor::DataFlow * DataFlowEditor ,
                       GraphEditor::InNode * DataFlowNode ,
-//                      const char *ParameterName ,
                       GraphBase::Port * DataFlowPort ,
                       bool InputPort ,
                       const CORBA::Any * anAny ) :
-//                      const SUPERV::Value_ptr aValue ) :
   Value_Impl(orb, poa, contId, instanceName, interfaceName,
-//             DataFlowEditor , DataFlowNode , ParameterName, aValue->ToAny() ,
              DataFlowEditor , DataFlowNode , DataFlowPort->PortName(), anAny ,
              false ) {
-//  MESSAGE("Value_Impl::Value_Impl activate object instanceName("
-//          << instanceName << ") interfaceName(" << interfaceName << ") --> "
-//          << hex << (void *) this << dec )
+//  MESSAGE("Port_Impl::Port_Impl activate object instanceName("
+//          << instanceName << ") interfaceName(" << interfaceName
+//          << ") IsDataStream " << DataFlowPort->IsDataStream() )
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
-  _thisObj = this ;
-  _id = _poa->activate_object(_thisObj);
+  if ( !DataFlowPort->IsDataStream() ) {
+    _thisObj = this ;
+    _id = _poa->activate_object(_thisObj) ;
+  }
   _DataFlowEditor = DataFlowEditor ;
   _DataFlowNode = DataFlowNode ;
-//  _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
   _DataFlowPort = DataFlowPort ;
-//  _InputPort = true ;
   _InputPort = InputPort ;
-//  if ( _DataFlowPort == NULL ) {
-//    _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
-//    _InputPort = false ;
-//  }
   InPort( _InputPort ) ;
 }
 
@@ -81,30 +74,29 @@ Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
                       const char *interfaceName ,
                       GraphEditor::DataFlow * DataFlowEditor ,
                       GraphEditor::InNode * DataFlowNode ,
-//                      const char *ParameterName ) :
                       GraphBase::Port * DataFlowPort ,
                       bool InputPort ) :
   Value_Impl(orb, poa, contId, instanceName, interfaceName,
              DataFlowEditor , DataFlowNode , DataFlowPort->PortName() , false ) {
-//             DataFlowEditor , DataFlowNode , ParameterName , false ) {
-//  MESSAGE("Value_Impl::Value_Impl activate object instanceName("
-//          << instanceName << ") interfaceName(" << interfaceName << ") --> "
-//          << hex << (void *) this << dec )
+  char * nodename = DataFlowEditor->Graph()->Name() ;
+  if ( DataFlowNode ) {
+    nodename = DataFlowNode->Name() ;
+  }
+//  MESSAGE("Port_Impl::Port_Impl activate object instanceName("
+//          << instanceName << ") interfaceName(" << interfaceName
+//          << ") " << nodename << "(" << DataFlowPort->PortName()
+//          << ") IsDataStream " << DataFlowPort->IsDataStream() ) ;
   _Orb = CORBA::ORB::_duplicate(orb);
   _Poa = poa ;
   _ContId = contId ;
-  _thisObj = this ;
-  _id = _poa->activate_object(_thisObj);
+  if ( !DataFlowPort->IsDataStream() ) {
+    _thisObj = this ;
+    _id = _poa->activate_object(_thisObj) ;
+  }
   _DataFlowEditor = DataFlowEditor ;
   _DataFlowNode = DataFlowNode ;
-//  _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
   _DataFlowPort = DataFlowPort ;
-//  _InputPort = true ;
   _InputPort = InputPort ;
-//  if ( _DataFlowPort == NULL ) {
-//    _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
-//    _InputPort = false ;
-//  }
   InPort( _InputPort ) ;
 }
 
@@ -125,21 +117,27 @@ void Port_Impl::destroy() {
       if ( anInPort->GetOutPort() ) {
         anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
       }
-      _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
-      if ( _DataFlowNode->IsLoopNode() ) {
-        _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
-        _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
-        _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
+      if ( _DataFlowNode->IsOneOfInLineNodes() ) {
+        _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
+        if ( _DataFlowNode->IsLoopNode() ) {
+          _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
+          _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
+          _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
+        }
+      }
+      else {
       }
       destroyed = true ;
     }
-    else if ( !_DataFlowNode->IsLoopNode() ) {
+    else if ( _DataFlowNode->IsOneOfInLineNodes() && !_DataFlowNode->IsLoopNode() ) {
       _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
       destroyed = true ;
     }
+    else {
+      destroyed = true ;
+    }
     if ( destroyed ) {
       _DataFlowEditor->UnValid() ;
-//      _DataFlowEditor->IsValid() ;
     }
   }
   if ( destroyed ) {
@@ -151,6 +149,15 @@ void Port_Impl::destroy() {
   endService( "Port_Impl::destroy" );
 }
 
+void Port_Impl::Remove() {
+  beginService( "Port_Impl::Remove" );
+  _poa->deactivate_object(*_id) ;
+  CORBA::release(_poa) ;
+  delete(_id) ;
+  _thisObj->_remove_ref();
+  endService( "Port_Impl::Remove" );
+}
+
 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
   return Input( aValue->ToAny() ) ;
 }
@@ -158,21 +165,31 @@ bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
 bool Port_Impl::Input( const CORBA::Any * anAny ) {
   beginService( "Port_Impl::Input" );
   bool RetVal = false ;
-  if ( _InputPort && _DataFlowEditor->IsEditing() ) {
-    RetVal = true ;
-    Value_Impl::Input( anAny ) ;
-    RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
-                                            _DataFlowPort->PortName() ,
-                                            *anAny ) ;
-  }
-  else if ( _DataFlowEditor->IsExecuting() ) {
-    GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
-//    if ( _DataFlowExecutor && ( _DataFlowExecutor->IsSuspended() ||
-//         _DataFlowExecutor->IsSuspended( _DataFlowNode->Name() ) ) ) {
-    if ( _DataFlowExecutor ) {
-      RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
-                                                   _DataFlowPort->PortName() ,
-                                                   *anAny ) ;
+  if ( _DataFlowEditor->Graph()->GraphMacroLevel() == 0 ) {
+    if ( _InputPort && _DataFlowEditor->IsEditing() ) {
+      RetVal = true ;
+      Value_Impl::Input( anAny ) ;
+      RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
+                                              _DataFlowPort->PortName() ,
+                                              *anAny ) ;
+    }
+    else if ( _DataFlowEditor->IsExecuting() ) {
+      GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
+      
+      /* commenting out the lines below because it seems to be never executed
+         Editor::_Executing flag is set OFF in Executor::OutNode on execution finished
+         and in CNode_Impl class (also not called probably)
+      // asv: turn off Editor::_Executing flag
+      if ( _DataFlowExecutor->IsDone() ) {
+        _DataFlowEditor->Executing( false );
+      }
+      else 
+      */ 
+      if ( !_DataFlowExecutor->IsDone() ) {
+        RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
+                                                     _DataFlowPort->PortName() ,
+                                                     *anAny ) ;
+      }
     }
   }
   if ( !RetVal ) {
@@ -199,24 +216,123 @@ char * Port_Impl::Type() {
 
 SUPERV::CNode_ptr Port_Impl::Node() {
   bool begin = true ;
-  SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
-  if ( CORBA::is_nil( _DataFlowNode->ObjRef() ) ) {
-    if ( begin ) {
-      beginService( "Port_Impl::Node" ) ;
-      begin = false ;
+  SUPERV::CNode_var iobject ;
+  if ( _DataFlowNode ) {
+//    MESSAGE( "Port_Impl::Node " << _DataFlowNode->Name() ) ;
+    iobject = SUPERV::CNode::_narrow( _DataFlowNode->ObjRef() ) ;
+    if ( CORBA::is_nil( iobject ) ) {
+      if ( begin ) {
+        beginService( "Port_Impl::Node" ) ;
+        begin = false ;
+      }
+      PortableServer::ObjectId * id ;
+      CORBA::Object_var obj ;
+      if ( _DataFlowNode->IsComputingNode() ) {
+        CNode_Impl * myNode = NULL ;
+        myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 _DataFlowEditor ,
+                                 _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        iobject = SUPERV::CNode::_narrow( obj ) ;
+        myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsFactoryNode() ) {
+        FNode_Impl * myNode = NULL ;
+        myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 _DataFlowEditor ,
+                                 _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::FNode_var Fiobject = SUPERV::FNode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( Fiobject ) ;
+        myNode->SetObjRef( SUPERV::FNode::_duplicate( Fiobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsInLineNode() ) {
+        INode_Impl * myNode = NULL ;
+        myNode = new INode_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 _DataFlowEditor ,
+                                 _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::INode_var Iiobject = SUPERV::INode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( Iiobject ) ;
+        myNode->SetObjRef( SUPERV::INode::_duplicate( Iiobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsGOTONode() ) {
+        GNode_Impl * myNode = NULL ;
+        myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 _DataFlowEditor ,
+                                 _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::GNode_var Giobject = SUPERV::GNode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( Giobject ) ;
+        myNode->SetObjRef( SUPERV::GNode::_duplicate( Giobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsLoopNode() ) {
+        LNode_Impl * myNode = NULL ;
+        myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 _DataFlowEditor ,
+                                 _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::LNode_var Liobject = SUPERV::LNode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( Liobject ) ;
+        myNode->SetObjRef( SUPERV::LNode::_duplicate( Liobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsEndLoopNode() ) {
+        ELNode_Impl * myNode = NULL ;
+        myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
+                                  instanceName() , interfaceName() ,
+                                  _DataFlowEditor ,
+                                  _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::ELNode_var ELiobject = SUPERV::ELNode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( ELiobject ) ;
+        myNode->SetObjRef( SUPERV::ELNode::_duplicate( ELiobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsSwitchNode() ) {
+        SNode_Impl * myNode = NULL ;
+        myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
+                                 instanceName() , interfaceName() ,
+                                 _DataFlowEditor ,
+                                 _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::SNode_var Siobject = SUPERV::SNode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( Siobject ) ;
+        myNode->SetObjRef( SUPERV::SNode::_duplicate( Siobject ) ) ;
+      }
+      else if ( _DataFlowNode->IsEndSwitchNode() ) {
+        ESNode_Impl * myNode = NULL ;
+        myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
+                                  instanceName() , interfaceName() ,
+                                  _DataFlowEditor ,
+                                  _DataFlowNode ) ;
+        id = myNode->getId() ;
+        obj = _poa->id_to_reference(*id);
+        SUPERV::ESNode_var ESiobject = SUPERV::ESNode::_narrow( obj ) ;
+        iobject = SUPERV::CNode::_narrow( ESiobject ) ;
+        myNode->SetObjRef( SUPERV::ESNode::_duplicate( ESiobject ) ) ;
+      }
+    }
+    else {
+//      MESSAGE( "Port_Impl::Node known objref " << iobject->Name() ) ;
     }
-    CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
-                                          instanceName() , interfaceName() ,
-                                          _DataFlowEditor ,
-                                          _DataFlowNode ) ;
-    PortableServer::ObjectId * id = myNode->getId() ;
-    CORBA::Object_var obj = _poa->id_to_reference(*id);
-    SUPERV::CNode_var iobject ;
-    iobject = SUPERV::CNode::_narrow(obj) ;
-    myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
   }
   else {
-    iobject = _DataFlowNode->ObjRef() ;
+    MESSAGE( "Port_Impl::GraphNode " << _DataFlowEditor->Graph()->Name() ) ;
+    iobject = SUPERV::CNode::_narrow( _DataFlowEditor->Graph()->ObjRef() ) ;
+    if ( CORBA::is_nil( iobject ) ) {
+      MESSAGE( "Port_Impl::GraphNode NilRef" ) ;
+    }
   }
   if ( !begin ) {
     endService( "Port_Impl::Node" ) ;
@@ -227,8 +343,18 @@ SUPERV::CNode_ptr Port_Impl::Node() {
 SUPERV::ListOfLinks * Port_Impl::Links() {
   beginService( "Port_Impl::Links" ) ;
   SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
-  RetVal = _DataFlowEditor->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
-                                              _DataFlowPort->PortName() ) ;
+  RetVal = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
+                                                        _DataFlowPort->PortName()*/ ) ;
+  MESSAGE( "Links of Node " << _DataFlowNode->ComputingNode()->Name()
+           << " and of Port " << _DataFlowPort->PortName()
+           << " _InputPort " << _InputPort ) ;
+  int i ;
+  for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
+    MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
+             << RetVal[i]->OutPort()->Name() << ") --> "
+             << RetVal[i]->InPort()->Node()->Name() << "("
+             << RetVal[i]->InPort()->Name() << ")" ) ;
+  }
   endService( "Port_Impl::Links" ) ;
   return ( RetVal._retn() ) ;
 }
@@ -242,8 +368,8 @@ SUPERV::Link_ptr Port_Impl::Link() {
     SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
 //    cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
 //         << _DataFlowPort->PortName() << endl ;
-    Links = _DataFlowEditor->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
-                                               _DataFlowPort->PortName() ) ;
+    Links = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
+                                                         _DataFlowPort->PortName()*/ ) ;
     if ( Links->length() ) {
       iobject = Links[ 0 ] ;
     }
@@ -275,18 +401,21 @@ SUPERV::Link_ptr Port_Impl::Link() {
             beginService( "Port_Impl::Link" ) ;
             begin = false ;
          }
+          bool Success ;
           Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
                                     instanceName() , interfaceName() ,
                                     _DataFlowEditor ,
                                     _DataFlowNode ,
                                     _DataFlowPort->PortName() ,
-                                    (GraphEditor::InNode * ) _DataFlowEditor->GetChangeGraphNode( FromNodeName )->GetInNode() ,
+                                    (GraphEditor::InNode * ) _DataFlowEditor->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
                                     FromServiceParameterName ,
-                                    false ) ;
-          PortableServer::ObjectId * id = myLink->getId() ;
-          CORBA::Object_var obj = _poa->id_to_reference(*id);
-          iobject = SUPERV::Link::_narrow(obj) ;
-          anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
+                                    false , true , Success ) ;
+          if ( Success ) {
+            PortableServer::ObjectId * id = myLink->getId() ;
+            CORBA::Object_var obj = _poa->id_to_reference(*id);
+            iobject = SUPERV::Link::_narrow(obj) ;
+            anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
+         }
         }
         else {
           iobject = anOutPort->InPortObjRef( anInPort ) ;
@@ -313,19 +442,21 @@ bool Port_Impl::IsInput() {
 bool Port_Impl::IsLinked() {
 //  beginService( "Port_Impl::IsLinked" ) ;
   bool RetVal = false ;
-  GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
-  GraphBase::OutPort * anOutPort = NULL ;
-  if ( anInPort) {
-    anOutPort = anInPort->GetOutPort() ;
-  }
-  if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
-       !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
-//    MESSAGE( "Link " << anOutPort->NodeName() << "("
-//            << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
-//            << anInPort->PortName() << ")" << " ignored" ) ;
-  }
-  else {
-    RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
+  if ( _DataFlowNode ) {
+    GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
+    GraphBase::OutPort * anOutPort = NULL ;
+    if ( anInPort) {
+      anOutPort = anInPort->GetOutPort() ;
+    }
+    if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
+         !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
+//      MESSAGE( "Link " << anOutPort->NodeName() << "("
+//              << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
+//              << anInPort->PortName() << ")" << " ignored" ) ;
+    }
+    else {
+      RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
+    }
   }
 //  endService( "Port_Impl::IsLinked" ) ;
   return RetVal ;
@@ -338,6 +469,12 @@ SUPERV::KindOfPort Port_Impl::Kind() {
   return RetVal ;
 }
 
+void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
+//  beginService( "Port_Impl::SetKind" ) ;
+  _DataFlowPort->Kind( aKindOfPort ) ;
+//  endService( "Port_Impl::SetKind" ) ;
+}
+
 bool Port_Impl::IsParam() {
 //  beginService( "Port_Impl::IsParam" ) ;
   bool RetVal = _DataFlowPort->IsParam() ;
@@ -381,6 +518,13 @@ bool Port_Impl::IsEndSwitch() {
   return RetVal ;
 }
 
+bool Port_Impl::IsDataStream() {
+//  beginService( "Port_Impl::IsDataStream" ) ;
+  bool RetVal = _DataFlowPort->IsDataStream() ;
+//  endService( "Port_Impl::IsDataStream" ) ;
+  return RetVal ;
+}
+
 bool Port_Impl::HasInput() {
 //  beginService( "Port_Impl::" ) ;
   bool RetVal = false ;
@@ -413,10 +557,11 @@ bool Port_Impl::IsDone() {
   if ( _DataFlowEditor ) {
     GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
     if ( _DataFlowExecutor ) {
-      RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
-                                          _DataFlowPort->PortName() ) ;
+      RetVal = _DataFlowExecutor->PortDone( _DataFlowPort->NodeName() ,
+                                            _DataFlowPort->PortName() ) ;
     }
   }
 //  endService( "Port_Impl::IsDone" );
   return RetVal ;
 }
+