Salome HOME
Debug : an OutPort connected to a Gate may only be connected again to a Gate of an...
authorrahuel <rahuel@opencascade.com>
Thu, 13 Jan 2005 15:23:17 +0000 (15:23 +0000)
committerrahuel <rahuel@opencascade.com>
Thu, 13 Jan 2005 15:23:17 +0000 (15:23 +0000)
Debug : RemoveLink of a link to an EndSwitchNode was wrong

src/GraphBase/DataFlowBase_Graph.cxx

index 1df1159b5c8c446336fab7e66851be3c1f915773..d72d31dcac7f196c6ba93afa57b78b051e13fe7d 100644 (file)
@@ -1069,6 +1069,12 @@ bool GraphBase::Graph::AddLink( GraphBase::ComputingNode *fromNode ,
       toPort->Kind( SUPERV::EndSwitchParameter ) ;
     }
   }
+// JR 12.01.2005 : an OutPort of a SwitchNode connected to a Gate can be connected only to Gate
+  else if ( fromNode->IsSwitchNode() && fromPort->IsSwitch() && !toPort->IsGate() ) {
+    cdebug << "toPort->AddLink Error( fromPort->IsSwitch() && !toPort->IsGate())." << endl ;
+    cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
+    return false ;
+  }
   else if ( !fromPort->AddInPort( toPort ) ) { // --> MapOfInports in the OutPort
     cdebug << "!fromPort->AddLink Error." << endl ;
     cdebug_out << "GraphBase::Graph::AddLink 0" << endl;
@@ -1178,11 +1184,19 @@ bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
     if ( anInPort && ( anInPort->IsPortConnected() ||
                        anInPort->IsDataConnected() ||
                        anInPort->IsExternConnected() ) ) {
-      GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
-      RetVal = anOutPort->RemoveInPort( anInPort ) ; // ==> :
-//      anInPort->RemoveOutPort() ;
-      const char * FromNodeName = anOutPort->NodeName() ;
+// JR 13.01.2005 : Bug if it is a link to an EndSwitchNode. The OutPort may be an other one !!!
       GraphBase::ComputingNode * fromNode = GetChangeGraphNode( FromNodeName ) ;
+      GraphBase::OutPort * anOutPort = NULL ;
+      if ( toNode->IsEndSwitchNode() ) {
+        anOutPort = fromNode->GetChangeOutPort( FromServiceParameterName ) ;
+        RetVal = anOutPort->RemoveInPort( anInPort ) ;
+      }
+      else {
+        anOutPort = anInPort->GetOutPort() ;
+        RetVal = anOutPort->RemoveInPort( anInPort ) ;
+      }
+//      anInPort->RemoveOutPort() ; // Already done in RemoveInPort
+//      const char * FromNodeName = anOutPort->NodeName() ;
       if ( RetVal ) {
         if ( fromNode ) {
           if ( anInPort->IsDataStream() ) {
@@ -1195,6 +1209,36 @@ bool GraphBase::Graph::RemoveLink( const char* FromNodeName ,
         if ( fromNode->IsSwitchNode() && !anOutPort->IsGate() && !toNode->IsEndSwitchNode() ) {
           anOutPort->Kind( SUPERV::InLineParameter ) ;
         }
+// JR 13.01.2005 : Bug if it is a link to an EndSwitchNode. The InPort may be linked !!!
+        if ( toNode->IsEndSwitchNode() ) {
+          int i ;
+          int done = false ;
+          for ( i = 0 ; i < toNode->LinkedFromNodesSize() ; i++ ) {
+            GraphBase::StreamNode * fromNode = toNode->LinkedFromNodes( i ) ;
+            int j ;
+            for ( j = 0 ; j < fromNode->GetNodeOutPortsSize() ; j++ ) {
+              GraphBase::OutPort * fromOutPort = fromNode->GetChangeNodeOutPort( j ) ;
+              int k ;
+              for ( k = 0 ; k < fromOutPort->InPortsSize() ; k++ ) {
+                if ( strcmp( toNode->Name() , fromOutPort->InPorts( k )->NodeName() ) == 0 ) {
+// Restore an OutPort in the InPort
+                  anInPort->ChangeOutPort( fromOutPort ) ;
+                  cdebug << "Graph::RemoveLink reestablish " << fromOutPort->NodeName() << "( "
+                         << fromOutPort->PortName() << " ) in the InPort of EndSwitch : "
+                         << toNode->Name() << "( " << anInPort->PortName() << " )" << endl;
+                  done = true ;
+                  break ;
+               }
+             }
+              if ( done ) {
+                break ;
+             }
+           }
+            if ( done ) {
+              break ;
+           }
+         }
+       }
       }
     }
   }