public NodeViewModel(Node model, PipelineViewModel parent) { fake = new InOutputViewModel(model: null, parent: this); Model = model; NodeType = new NodeType { Type = model.GetType() }; Parent = parent; ZIndex = 0; inputs = Model.Inputs.Select(i => new InOutputViewModel(i, this)).ToList(); Outputs = Model.Outputs.Select(i => new InOutputViewModel(i, this)).ToList(); if (Model.Outputs is INotifyCollectionChanged) { ((INotifyCollectionChanged)Model.Outputs).CollectionChanged += delegate { Outputs = Model.Outputs.Select(i => new InOutputViewModel(i, this)).ToList(); NotifyOfPropertyChange(() => Outputs); NotifyOfPropertyChange(() => HasOutputs); Parent.NotifyOfPropertyChange(() => Parent.Edges); } } ; }
/// <summary> /// Connects the dragged edge to the in-/output, if valid. /// </summary> public void InOutputMouseUp(InOutputViewModel inOut) { if (DraggedEdge == null) { return; } DraggedEdge.EndViewModel = inOut; InOutputViewModel inputVM, outputVM; if (DraggedEdge.GetInOut(out inputVM, out outputVM)) { var output = (Node.Output)outputVM.Model; if (Parent.Model.Graph.CanAddEdge(output.Node, inputVM.Parent.Model)) { if (inputVM.IsFake) { inputVM.Parent.AddInput(output); } else { ((Node.Input)inputVM.Model).Source = output; } CullInputs(); NotifyOfPropertyChange(() => Edges); Parent.SaveSnapshot(); } } DraggedEdge = null; }
/// <summary> /// Lets the dragged edge snap to the in-/output hovered over. /// </summary> public void InOutputMouseMove(InOutputViewModel inOut, RoutedEventArgs e) { if (DraggedEdge == null) { return; } InOutputViewModel inputVM, outputVM; DraggedEdge.EndViewModel = inOut; DraggedEdge.Status = DraggedEdge.GetInOut(out inputVM, out outputVM) && Parent.Model.Graph.CanAddEdge(outputVM.Parent.Model, inputVM.Parent.Model) ? EdgeStatus.Valid : EdgeStatus.Invalid; e.Handled = true; // don't bubble up into MouseMove }
/// <summary> /// Try and sort two InOutputViewModels into input and output. /// Returns false if there are two inputs or outputs. /// </summary> public bool GetInOut(out InOutputViewModel inputVM, out InOutputViewModel outputVM) { if ((StartViewModel.IsFake || StartViewModel.Model is Node.Input) && EndViewModel.Model is Node.Output) { inputVM = StartViewModel; outputVM = EndViewModel; return(true); } if (StartViewModel.Model is Node.Output && (EndViewModel.IsFake || EndViewModel.Model is Node.Input)) { inputVM = EndViewModel; outputVM = StartViewModel; return(true); } inputVM = outputVM = null; return(false); }
public NodeViewModel(Node model, PipelineViewModel parent) { fake = new InOutputViewModel(model: null, parent: this); Model = model; NodeType = new NodeType { Type = model.GetType() }; Parent = parent; ZIndex = 0; inputs = Model.Inputs.Select(i => new InOutputViewModel(i, this)).ToList(); Outputs = Model.Outputs.Select(i => new InOutputViewModel(i, this)).ToList(); if (Model.Outputs is INotifyCollectionChanged) ((INotifyCollectionChanged)Model.Outputs).CollectionChanged += delegate { Outputs = Model.Outputs.Select(i => new InOutputViewModel(i, this)).ToList(); NotifyOfPropertyChange(() => Outputs); NotifyOfPropertyChange(() => HasOutputs); Parent.NotifyOfPropertyChange(() => Parent.Edges); }; }
/// <summary> /// Starts dragging the connected edge, if any, or a new one. /// </summary> public void InOutputMouseDown(InOutputViewModel inOut) { /* Only allow this if pipeline is not rendering */ if (!Parent.Model.IsPlaying) { InOutputViewModel start = inOut; // If the input is already connected, drag the existing edge if (inOut.Model is Node.Input) { start = GetOutputViewModel(((Node.Input)inOut.Model).Source) ?? start; ((Node.Input)inOut.Model).Source = null; NotifyOfPropertyChange(() => Edges); // remember the end of the grabbed edge draggedEdgeEndNodeVM = inOut.Parent; } DraggedEdge = new EdgeViewModel { StartViewModel = start, EndViewModel = inOut }; } }
/// <summary> /// Try and sort two InOutputViewModels into input and output. /// Returns false if there are two inputs or outputs. /// </summary> public bool GetInOut(out InOutputViewModel inputVM, out InOutputViewModel outputVM) { if ((StartViewModel.IsFake || StartViewModel.Model is Node.Input) && EndViewModel.Model is Node.Output) { inputVM = StartViewModel; outputVM = EndViewModel; return true; } if (StartViewModel.Model is Node.Output && (EndViewModel.IsFake || EndViewModel.Model is Node.Input)) { inputVM = EndViewModel; outputVM = StartViewModel; return true; } inputVM = outputVM = null; return false; }