From acdaecf8defc93bd78778a2343e526e8db7753d9 Mon Sep 17 00:00:00 2001 From: Ankitkumar Satapara Date: Mon, 20 Apr 2026 20:31:35 +0530 Subject: [PATCH] Added knot nodes to for channing the lines to the proper format --- .../Nodify.Calculator/CalculatorViewModel.cs | 52 +++++++++++++------ .../Nodify.Calculator/ConnectorViewModel.cs | 2 + push command.txt | 1 + 3 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 push command.txt diff --git a/Examples/Nodify.Calculator/CalculatorViewModel.cs b/Examples/Nodify.Calculator/CalculatorViewModel.cs index eec8739..7bb917e 100644 --- a/Examples/Nodify.Calculator/CalculatorViewModel.cs +++ b/Examples/Nodify.Calculator/CalculatorViewModel.cs @@ -155,6 +155,25 @@ namespace Nodify.Calculator public INodifyCommand DeleteSelectionCommand { get; } public INodifyCommand GroupSelectionCommand { get; } + /// + /// A knot connector allows any shape only when its knot node has no existing connections (unadapted). + /// Once adapted (input connected), shape must match. + /// + private bool IsKnotConnectorAllowed(ConnectorViewModel source, ConnectorViewModel target) + { + ConnectorViewModel knotConn = source.IsKnotConnector ? source : target.IsKnotConnector ? target : null; + if (knotConn == null) return false; + + var knotOp = knotConn.Operation as KnotOperationViewModel; + if (knotOp == null) return false; + + // If knot has no connections yet, allow any shape + bool hasAnyConnection = Connections.Any(con => + con.Input.Operation == knotOp || con.Output.Operation == knotOp); + + return !hasAnyConnection; + } + private void DisconnectConnector(ConnectorViewModel connector) { var connections = Connections.Where(c => c.Input == connector || c.Output == connector).ToList(); @@ -164,7 +183,7 @@ namespace Nodify.Calculator internal bool CanCreateConnection(ConnectorViewModel source, ConnectorViewModel? target) => target == null || (source != target && (source.Shape == target.Shape || - source.IsKnotConnector || target.IsKnotConnector || + IsKnotConnectorAllowed(source, target) || ((source.IsCopyConnector || target.IsCopyConnector) && source.Shape != ConnectorShape.Triangle && target.Shape != ConnectorShape.Triangle)) && !source.IsConnected && !target.IsConnected && @@ -729,34 +748,33 @@ namespace Nodify.Calculator private void HandleKnotNodeConnected(ConnectionViewModel c) { - ConnectorViewModel knotConn = null; + // Determine if a knot node's INPUT connector is being connected + // c.Input is the receiving connector, c.Output is the source connector + KnotOperationViewModel knotOp = null; ConnectorViewModel sourceConn = null; - if (c.Input.IsKnotConnector) + // Connection into the knot's input: c.Input belongs to knot, c.Output is the source + if (c.Input.IsKnotConnector && c.Input.IsInput && c.Input.Operation is KnotOperationViewModel k1) { - knotConn = c.Input; + knotOp = k1; sourceConn = c.Output; } - else if (c.Output.IsKnotConnector) + // Connection from knot's output into something: c.Output belongs to knot, c.Input is the target + // If knot is unadapted and output connects first, adapt from the target + else if (c.Output.IsKnotConnector && !c.Output.IsInput && c.Output.Operation is KnotOperationViewModel k2) { - knotConn = c.Output; + knotOp = k2; sourceConn = c.Input; } - if (knotConn == null) return; + if (knotOp == null || sourceConn == null) return; - var knotOp = knotConn.Operation as KnotOperationViewModel; - if (knotOp == null) return; - - // Adapt both input and output connectors to match the connected wire's shape/color/type + // Adapt ALL connectors (both input and output) to match the connected wire's shape/color/type foreach (var conn in knotOp.Input.Concat(knotOp.Output)) { - if (conn.Shape != ConnectorShape.Triangle) - { - conn.Shape = sourceConn.Shape; - conn.ConnectorColor = sourceConn.RawColor; - conn.DataType = sourceConn.DataType; - } + conn.Shape = sourceConn.Shape; + conn.ConnectorColor = sourceConn.RawColor; + conn.DataType = sourceConn.DataType; } } diff --git a/Examples/Nodify.Calculator/ConnectorViewModel.cs b/Examples/Nodify.Calculator/ConnectorViewModel.cs index a56173f..61c3234 100644 --- a/Examples/Nodify.Calculator/ConnectorViewModel.cs +++ b/Examples/Nodify.Calculator/ConnectorViewModel.cs @@ -65,6 +65,8 @@ namespace Nodify.Calculator set { _color = value; + OnPropertyChanged(nameof(Color)); + OnPropertyChanged(nameof(RawColor)); } } diff --git a/push command.txt b/push command.txt new file mode 100644 index 0000000..f09fafb --- /dev/null +++ b/push command.txt @@ -0,0 +1 @@ +git push -u origin master \ No newline at end of file