public virtual void AddConnection(CNodeConnectionViewModel newConnection, CPinViewModel otherPin) { int prevConnectionCount = Connections.Count; Connections.Add(newConnection); if (prevConnectionCount == 0) { RaisePropertyChanged("PinInnerColor"); RaisePropertyChanged("IsConnected"); } }
public CNodeConnectionViewModel(CPinViewModel sourcePin, CPinViewModel targetPin, CNodeGraphViewModel nodeGraph) { MouseDownCommand = new CRelayCommand(OnMouseDown); m_nodeGraph = nodeGraph; m_sourceNode = sourcePin.NodeViewModel; m_targetNode = targetPin.NodeViewModel; m_sourcePin = sourcePin; m_targetPin = targetPin; m_sourceNode.OnNodeMoved += OnSourceMoved; m_sourcePin.ConnectionPointChanged += OnSourcePinChanged; m_targetNode.OnNodeMoved += OnTargetMoved; m_targetPin.ConnectionPointChanged += OnTargetPinChanged; StrokeColor = m_sourcePin.PinOuterColor; }
private void ConnectPins(CPinViewModel source, CPinViewModel target) { CNodeConnectionViewModel newConnection = new CNodeConnectionViewModel(source, target, this); void Redo() { newConnection.Connect(); } void Undo() { newConnection.Disconnect(); } Redo(); UndoRedoUtility.Record(new CRelayUndoItem(Undo, Redo)); }
public override bool CanConnect(CPinViewModel pinToCheck, out string failReason) { if (pinToCheck == null) { failReason = "Source not existing"; return(false); } if (pinToCheck.NodeViewModel == NodeViewModel) { failReason = "Cannot connect to a pin on the same node"; return(false); } if (pinToCheck is COutputPinViewModel) { failReason = "Output is not compatible with another output"; return(false); } if (pinToCheck is CExecutionPinViewModel) { failReason = "Output is not compatible with execution"; return(false); } if (pinToCheck is CInputPinViewModel inputPin) { if (inputPin.IsLiteralOnly) { failReason = $"Input pin {inputPin.Name} can only be assigned a value by changing its literal value"; return(false); } if (!inputPin.ValueType.IsAssignableFrom(ValueType)) { failReason = "Output of type " + EditorKlaxScriptUtility.GetTypeName(ValueType) + " is not compatible with input of type " + EditorKlaxScriptUtility.GetTypeName(inputPin.ValueType); return(false); } } failReason = ""; return(true); }
private void OnNodeAddNodePopupSelected(CNodeEntryViewModel addNodeEntry) { CNode scriptNode = addNodeEntry.NodeFactory.CreateNode(); scriptNode.NodePosX = m_addNodePoint.X; scriptNode.NodePosY = m_addNodePoint.Y; CScriptNodeViewmodel newNode = AddNode(scriptNode); if (m_addNodeContextPin != null) { CPinViewModel possibleTarget = newNode.GetPossibleTargetPin(m_addNodeContextPin); if (possibleTarget != null) { ConnectPins(m_addNodeContextPin, possibleTarget); } } m_addNodeContextPin = null; AddNodeViewModel.IsOpen = false; }
public override bool CanConnect(CPinViewModel pinToCheck, out string failReason) { if (pinToCheck == null) { failReason = "Source not existing"; return(false); } if (pinToCheck.NodeViewModel == NodeViewModel) { failReason = "Cannot connect to a pin on the same node"; return(false); } if (pinToCheck is COutputPinViewModel) { failReason = "Execution is not compatible with output"; return(false); } if (pinToCheck is CInputPinViewModel) { failReason = "Execution is not compatible with input"; return(false); } if (pinToCheck is CExecutionPinViewModel otherExecution) { if (IsIn == otherExecution.IsIn) { failReason = "Cannot connect to an execution pin with the same direction"; return(false); } } failReason = ""; return(true); }
public override void AddConnection(CNodeConnectionViewModel newConnection, CPinViewModel otherPin) { if (!IsIn) { if (otherPin is CExecutionPinViewModel otherExecution && otherExecution.IsIn) { // Out Execution pins can only be connected to a single node if (Connections.Count > 0) { if (Connections.Count > 1) { List <CNodeConnectionViewModel> oldConnections = new List <CNodeConnectionViewModel>(); foreach (CNodeConnectionViewModel connection in Connections) { oldConnections.Add(connection); } foreach (CNodeConnectionViewModel connection in oldConnections) { connection.Disconnect(); } } Connections[0].Disconnect(); } m_pin.TargetNode = otherPin.NodeViewModel.ScriptNode; m_pin.TargetPin = otherPin.NodeViewModel.ScriptNode.InExecutionPins[otherPin.PinIndex]; m_pin.TargetPinIndex = otherPin.PinIndex; base.AddConnection(newConnection, otherPin); } } else { base.AddConnection(newConnection, otherPin); } }
public override void AddConnection(CNodeConnectionViewModel newConnection, CPinViewModel otherPin) { if (otherPin is COutputPinViewModel outputPin) { // Input pin can only be connected to a single node if (Connections.Count > 0) { if (Connections.Count > 1) { List <CNodeConnectionViewModel> oldConnections = new List <CNodeConnectionViewModel>(); foreach (CNodeConnectionViewModel connection in Connections) { oldConnections.Add(connection); } foreach (CNodeConnectionViewModel connection in oldConnections) { connection.Disconnect(); } } Connections[0].Disconnect(); } m_pin.SourceNode = outputPin.NodeViewModel.ScriptNode; m_pin.SourceParameterIndex = outputPin.PinIndex; CNodeChangeContext context = new CNodeChangeContext(); m_nodeViewmodel.ScriptNode.OnInputConnectionChanged(context, m_pin, outputPin.Pin); foreach (var action in context.Actions) { m_nodeViewmodel.ExecuteNodeAction(action); } base.AddConnection(newConnection, otherPin); } }
public CPinViewModel GetPossibleTargetPin(CPinViewModel source) { foreach (var executionPin in InExecutionPins) { if (executionPin.CanConnect(source, out string failReason)) { return(executionPin); } } foreach (var executionPin in OutExecutionPins) { if (executionPin.CanConnect(source, out string failReason)) { return(executionPin); } } foreach (var inputPin in InputPins) { if (inputPin.CanConnect(source, out string failReason)) { return(inputPin); } } foreach (var outputPin in OutputPins) { if (outputPin.CanConnect(source, out string failReason)) { return(outputPin); } } return(null); }
public virtual void RemoveConnection(CNodeConnectionViewModel removedConnection, CPinViewModel otherPin) { Connections.Remove(removedConnection); if (Connections.Count == 0) { RaisePropertyChanged("PinInnerColor"); RaisePropertyChanged("IsConnected"); } }
public override void RemoveConnection(CNodeConnectionViewModel removedConnection, CPinViewModel otherPin) { m_pin.TargetNode = null; base.RemoveConnection(removedConnection, otherPin); }
public override void RemoveConnection(CNodeConnectionViewModel removedConnection, CPinViewModel otherPin) { m_pin.SourceNode = null; m_pin.SourceParameterIndex = -1; if (otherPin is COutputPinViewModel outputVm) { CNodeChangeContext context = new CNodeChangeContext(); m_nodeViewmodel.ScriptNode.OnInputConnectionChanged(context, m_pin, null); foreach (var action in context.Actions) { m_nodeViewmodel.ExecuteNodeAction(action); } } base.RemoveConnection(removedConnection, otherPin); }
public abstract bool CanConnect(CPinViewModel pinToCheck, out string failReason);