1- using NodeDev . Blazor . DiagramsModels ;
2- using NodeDev . Core ;
1+ using NodeDev . Core ;
32using NodeDev . Core . Connections ;
43using NodeDev . Core . Nodes ;
54using NodeDev . Core . Types ;
@@ -25,14 +24,14 @@ public void AddNewConnectionBetween(Connection source, Connection destination)
2524 Graph . Connect ( source , destination , false ) ;
2625
2726 // we're plugging something something with a generic into something without a generic
28- if ( source . Type . IsAssignableTo ( destination . Type , out var newTypes ) && newTypes . Count != 0 )
27+ if ( source . IsAssignableTo ( destination , true , true , out var newTypes , out var usedInitialTypes ) && newTypes . Count != 0 )
2928 {
30- PropagateNewGeneric ( source . Parent , newTypes , false ) ;
31- PropagateNewGeneric ( destination . Parent , newTypes , false ) ;
29+ PropagateNewGeneric ( source . Parent , newTypes , usedInitialTypes , destination , false ) ;
30+ PropagateNewGeneric ( destination . Parent , newTypes , usedInitialTypes , source , false ) ;
3231 }
3332
34- GraphCanvas . UpdatePortTypeAndColor ( source ) ;
35- GraphCanvas . UpdatePortTypeAndColor ( destination ) ;
33+ GraphCanvas . UpdatePortColor ( source ) ;
34+ GraphCanvas . UpdatePortColor ( destination ) ;
3635
3736 // we have to disconnect the previously connected exec, since exec outputs can only have one connection
3837 if ( source . Type . IsExec && source . Connections . Count > 1 )
@@ -48,38 +47,47 @@ public void DisconnectConnectionBetween(Connection source, Connection destinatio
4847 Graph . Disconnect ( source , destination , false ) ;
4948 GraphCanvas . RemoveLinkFromGraphCanvas ( source , destination ) ;
5049
51- GraphCanvas . UpdatePortTypeAndColor ( source ) ;
52- GraphCanvas . UpdatePortTypeAndColor ( destination ) ;
50+ GraphCanvas . UpdatePortColor ( source ) ;
51+ GraphCanvas . UpdatePortColor ( destination ) ;
5352 }
5453
55- public void PropagateNewGeneric ( Node node , IReadOnlyDictionary < UndefinedGenericType , TypeBase > changedGenerics , bool requireUIRefresh )
54+ /// <summary>
55+ /// Propagate the new generic type to all the connections of the node and recursively to the connected nodes.
56+ /// </summary>
57+ /// <param name="initiatingConnection">The connection that initiated the propagation. This is used to avoid reupdating back and forth, sometimes erasing information in the process.</param>
58+ public void PropagateNewGeneric ( Node node , IReadOnlyDictionary < UndefinedGenericType , TypeBase > changedGenerics , bool useInitialTypes , Connection ? initiatingConnection , bool overrideInitialTypes )
5659 {
60+ bool hadAnyChanges = false ;
5761 foreach ( var port in node . InputsAndOutputs ) // check if any of the ports have the generic we just solved
5862 {
59- var previousType = port . Type ;
63+ var previousType = useInitialTypes ? port . InitialType : port . Type ;
6064
6165 if ( ! previousType . GetUndefinedGenericTypes ( ) . Any ( changedGenerics . ContainsKey ) )
6266 continue ;
6367
6468 // update port.Type property as well as the textbox visibility if necessary
65- port . UpdateTypeAndTextboxVisibility ( previousType . ReplaceUndefinedGeneric ( changedGenerics ) ) ;
66- node . GenericConnectionTypeDefined ( port ) ;
67- GraphCanvas . UpdatePortTypeAndColor ( port ) ;
69+ port . UpdateTypeAndTextboxVisibility ( previousType . ReplaceUndefinedGeneric ( changedGenerics ) , overrideInitialType : overrideInitialTypes ) ;
70+ hadAnyChanges |= node . GenericConnectionTypeDefined ( port ) . Count != 0 ;
71+ GraphCanvas . UpdatePortColor ( port ) ;
6872
6973 var isPortInput = port . IsInput ; // cache for performance, IsInput is slow
7074 // check if other connections had their own generics and if we just solved them
7175 foreach ( var other in port . Connections . ToList ( ) )
7276 {
77+ if ( other == initiatingConnection )
78+ continue ;
79+
7380 var source = isPortInput ? other : port ;
7481 var target = isPortInput ? port : other ;
75- if ( source . Type . IsAssignableTo ( target . Type , out var changedGenerics2 ) && changedGenerics2 . Count != 0 )
76- PropagateNewGeneric ( other . Parent , changedGenerics2 , false ) ; // no need to refresh UI since we'll do it ourselves anyway at the end of this call
82+ if ( source . IsAssignableTo ( target , isPortInput , ! isPortInput , out var changedGenerics2 , out var usedInitialTypes ) && changedGenerics2 . Count != 0 )
83+ PropagateNewGeneric ( other . Parent , changedGenerics2 , usedInitialTypes , port , false ) ;
7784 else if ( ( changedGenerics2 ? . Count ?? 0 ) != 0 ) // looks like changing the generic made it so we can't link to this connection anymore
7885 DisconnectConnectionBetween ( port , other ) ;
7986 }
8087 }
8188
82- Graph . RaiseGraphChanged ( requireUIRefresh ) ;
89+ if ( hadAnyChanges )
90+ Graph . RaiseGraphChanged ( false ) ;
8391 }
8492
8593 public void SelectNodeOverload ( Node popupNode , Node . AlternateOverload overload )
0 commit comments