56 lines
2.6 KiB
C#
56 lines
2.6 KiB
C#
using System;
|
|
using DynamicData;
|
|
using Intromat.ViewModels.Nodes;
|
|
using NodeNetwork.Toolkit.Group;
|
|
using NodeNetwork.Toolkit.ValueNode;
|
|
using NodeNetwork.ViewModels;
|
|
|
|
namespace Intromat.ViewModels
|
|
{
|
|
public class CodeNodeGroupIOBinding : ValueNodeGroupIOBinding
|
|
{
|
|
public CodeNodeGroupIOBinding(NodeViewModel groupNode, NodeViewModel entranceNode, NodeViewModel exitNode)
|
|
: base(groupNode, entranceNode, exitNode)
|
|
{
|
|
}
|
|
|
|
public override ValueNodeOutputViewModel<T> CreateCompatibleOutput<T>(ValueNodeInputViewModel<T> input)
|
|
{
|
|
return (ValueNodeOutputViewModel<T>)CreateOutput(((CodeGenPortViewModel)input.Port).PortType, input.Name, typeof(T), false);
|
|
}
|
|
|
|
public override ValueNodeOutputViewModel<IObservableList<T>> CreateCompatibleOutput<T>(ValueListNodeInputViewModel<T> input)
|
|
{
|
|
return (ValueNodeOutputViewModel<IObservableList<T>>)CreateOutput(((CodeGenPortViewModel)input.Port).PortType, input.Name, typeof(T), true);
|
|
}
|
|
|
|
public NodeOutputViewModel CreateOutput(EPortType portType, string name, Type valueType, bool list)
|
|
{
|
|
var genericType = list ? typeof(IObservableList<>).MakeGenericType(valueType) : valueType;
|
|
var outputType = typeof(CodeGenOutputViewModel<>).MakeGenericType(genericType);
|
|
var editorType = typeof(GroupEndpointEditorViewModel<>).MakeGenericType(genericType);
|
|
var output = (NodeOutputViewModel)Activator.CreateInstance(outputType, portType)!;
|
|
var editor = (NodeEndpointEditorViewModel)Activator.CreateInstance(editorType, this)!;
|
|
output.Name = name;
|
|
output.Editor = editor;
|
|
return output;
|
|
}
|
|
|
|
public override ValueNodeInputViewModel<T> CreateCompatibleInput<T>(ValueNodeOutputViewModel<T> output)
|
|
{
|
|
return (ValueNodeInputViewModel<T>)CreateInput(((CodeGenPortViewModel)output.Port).PortType, output.Name, typeof(T));
|
|
}
|
|
|
|
public NodeInputViewModel CreateInput(EPortType portType, string name, Type valueType)
|
|
{
|
|
var inputType = typeof(CodeGenInputViewModel<>).MakeGenericType(valueType);
|
|
var editorType = typeof(GroupEndpointEditorViewModel<>).MakeGenericType(valueType);
|
|
var input = (NodeInputViewModel)Activator.CreateInstance(inputType, portType)!;
|
|
var editor = (NodeEndpointEditorViewModel)Activator.CreateInstance(editorType, this)!;
|
|
input.Name = name;
|
|
input.Editor = editor;
|
|
input.HideEditorIfConnected = false;
|
|
return input;
|
|
}
|
|
}
|
|
} |