@@ -612,12 +612,13 @@ private void ConnectNode(RGLNodeHandle nodeToConnect)
612
612
throw new RGLException ( $ "Attempted to connect node '{ nodeToConnect . Identifier } ' twice!") ;
613
613
}
614
614
615
- // Collect previous and next nodes that are connected
615
+ // Collect previous and next nodes to the nodeToConnect that are connected
616
616
RGLNodeHandle [ ] prevNodes = GetPreviousNodes ( nodeToConnect , true ) ;
617
617
RGLNodeHandle [ ] nextNodes = GetNextNodes ( nodeToConnect , true ) ;
618
618
619
- // Nodes are connected with each other. Need to disconnect them.
620
- if ( prevNodes . Length != 0 && nextNodes . Length != 0 )
619
+ // If there are any other connected (active) nodes in this sequence, prevNodes and nextNodes are connected
620
+ // Before connecting a new node between them, we have to disconnect them first
621
+ if ( GetConnectedNodesCount ( ) > 0 )
621
622
{
622
623
foreach ( RGLNodeHandle prevNode in prevNodes )
623
624
{
@@ -648,7 +649,7 @@ private void DisconnectNode(RGLNodeHandle nodeToDisconnect)
648
649
throw new RGLException ( $ "Attempted to disconnect node '{ nodeToDisconnect . Identifier } ' that is not connected!") ;
649
650
}
650
651
651
- // Collect previous and next nodes that are connected
652
+ // Collect previous and next nodes to the nodeToDisconnect that are connected
652
653
RGLNodeHandle [ ] prevNodes = GetPreviousNodes ( nodeToDisconnect , true ) ;
653
654
RGLNodeHandle [ ] nextNodes = GetNextNodes ( nodeToDisconnect , true ) ;
654
655
@@ -662,19 +663,11 @@ private void DisconnectNode(RGLNodeHandle nodeToDisconnect)
662
663
RGLNativeAPI . GraphNodeRemoveChild ( nodeToDisconnect . Node , nextNode . Node ) ;
663
664
}
664
665
665
- bool anyNodeRemained = false ;
666
- foreach ( RGLNodeHandle node in prevNodes . ToList ( ) . Concat ( nextNodes . ToList ( ) ) )
667
- {
668
- if ( nodes . Contains ( node ) )
669
- {
670
- anyNodeRemained = true ;
671
- break ;
672
- }
673
- }
666
+ nodeToDisconnect . Connected = false ;
674
667
675
- // Connect nodes that have become adjacent
676
- // If there is no remaining nodes in this sequence - skip connecting
677
- if ( prevNodes . Length != 0 && nextNodes . Length != 0 && anyNodeRemained )
668
+ // If there are any other connected (active) nodes in this sequence, connect nodes that have become adjacent to each other
669
+ // Otherwise, we don't want to connect parent and child NodeSequences by omitting the current NodeSequence
670
+ if ( GetConnectedNodesCount ( ) > 0 )
678
671
{
679
672
foreach ( RGLNodeHandle prevNode in prevNodes )
680
673
{
@@ -684,8 +677,6 @@ private void DisconnectNode(RGLNodeHandle nodeToDisconnect)
684
677
}
685
678
}
686
679
}
687
-
688
- nodeToDisconnect . Connected = false ;
689
680
}
690
681
691
682
//// NODE GETTERS ////
@@ -755,6 +746,11 @@ private RGLNodeHandle[] GetNextNodes(RGLNodeHandle referenceNode, bool mustBeCon
755
746
return outNodes . ToArray ( ) ;
756
747
}
757
748
749
+ private int GetConnectedNodesCount ( )
750
+ {
751
+ return nodes . Count ( n => n . Connected ) ;
752
+ }
753
+
758
754
private void DisconnectAllChilds ( )
759
755
{
760
756
foreach ( RGLNodeSequence nodeSequence in childs . ToList ( ) )
0 commit comments