Added knot nodes to for channing the lines to the proper format
Some checks failed
Build / build (push) Has been cancelled

This commit is contained in:
Ankitkumar Satapara
2026-04-20 20:31:35 +05:30
parent f604f58068
commit acdaecf8de
3 changed files with 38 additions and 17 deletions

View File

@@ -155,6 +155,25 @@ namespace Nodify.Calculator
public INodifyCommand DeleteSelectionCommand { get; } public INodifyCommand DeleteSelectionCommand { get; }
public INodifyCommand GroupSelectionCommand { get; } public INodifyCommand GroupSelectionCommand { get; }
/// <summary>
/// A knot connector allows any shape only when its knot node has no existing connections (unadapted).
/// Once adapted (input connected), shape must match.
/// </summary>
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) private void DisconnectConnector(ConnectorViewModel connector)
{ {
var connections = Connections.Where(c => c.Input == connector || c.Output == connector).ToList(); 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) internal bool CanCreateConnection(ConnectorViewModel source, ConnectorViewModel? target)
=> target == null || (source != target && => target == null || (source != target &&
(source.Shape == target.Shape || (source.Shape == target.Shape ||
source.IsKnotConnector || target.IsKnotConnector || IsKnotConnectorAllowed(source, target) ||
((source.IsCopyConnector || target.IsCopyConnector) && source.Shape != ConnectorShape.Triangle && target.Shape != ConnectorShape.Triangle)) && ((source.IsCopyConnector || target.IsCopyConnector) && source.Shape != ConnectorShape.Triangle && target.Shape != ConnectorShape.Triangle)) &&
!source.IsConnected && !source.IsConnected &&
!target.IsConnected && !target.IsConnected &&
@@ -729,36 +748,35 @@ namespace Nodify.Calculator
private void HandleKnotNodeConnected(ConnectionViewModel c) 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; 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; 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; sourceConn = c.Input;
} }
if (knotConn == null) return; if (knotOp == null || sourceConn == null) return;
var knotOp = knotConn.Operation as KnotOperationViewModel; // Adapt ALL connectors (both input and output) to match the connected wire's shape/color/type
if (knotOp == null) return;
// Adapt both input and output connectors to match the connected wire's shape/color/type
foreach (var conn in knotOp.Input.Concat(knotOp.Output)) foreach (var conn in knotOp.Input.Concat(knotOp.Output))
{
if (conn.Shape != ConnectorShape.Triangle)
{ {
conn.Shape = sourceConn.Shape; conn.Shape = sourceConn.Shape;
conn.ConnectorColor = sourceConn.RawColor; conn.ConnectorColor = sourceConn.RawColor;
conn.DataType = sourceConn.DataType; conn.DataType = sourceConn.DataType;
} }
} }
}
private void HandleKnotNodeDisconnected(ConnectionViewModel c) private void HandleKnotNodeDisconnected(ConnectionViewModel c)
{ {

View File

@@ -65,6 +65,8 @@ namespace Nodify.Calculator
set set
{ {
_color = value; _color = value;
OnPropertyChanged(nameof(Color));
OnPropertyChanged(nameof(RawColor));
} }
} }

1
push command.txt Normal file
View File

@@ -0,0 +1 @@
git push -u origin master