Added knot nodes to for channing the lines to the proper format
Some checks failed
Build / build (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
This commit is contained in:
@@ -155,6 +155,25 @@ namespace Nodify.Calculator
|
||||
public INodifyCommand DeleteSelectionCommand { 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,8 @@ namespace Nodify.Calculator
|
||||
set
|
||||
{
|
||||
_color = value;
|
||||
OnPropertyChanged(nameof(Color));
|
||||
OnPropertyChanged(nameof(RawColor));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user