/// <summary> /// Removes a connection from the view model. /// </summary> /// <param name="pConnection">The connection to remove.</param> public void RemoveConnection(ConnectionViewModel pConnection) { this.mConnections.Remove(pConnection); this.mGraphItems.Remove(pConnection); if (this.ConnectionRemoved != null) { this.ConnectionRemoved(this, pConnection); } }
/// <summary> /// Adds a node to the view model. /// </summary> /// <param name="pConnection">The connection to add.</param> public void AddConnection(ConnectionViewModel pConnection) { this.mConnections.Add(pConnection); this.mGraphItems.Add(pConnection); if (this.ConnectionAdded != null) { this.ConnectionAdded(this, pConnection); } }
/// <summary> /// Delegate called when the mouse isup on the working canvas. /// </summary> /// <param name="pSender">The event sender.</param> /// <param name="pEventArgs">The event arguments.</param> private void OnWorkingCanvasMouseUp(object pSender, MouseButtonEventArgs pEventArgs) { // Release the mouse capture. this.WorkingCanvas.ReleaseMouseCapture(); this.WorkingCanvas.MouseMove -= this.OnWorkingCanvasMouseMove; this.WorkingCanvas.MouseUp -= this.OnWorkingCanvasMouseUp; this.WorkingCanvas.Visibility = Visibility.Collapsed; this.ConnectingLine.Visibility = Visibility.Collapsed; // Trying to create the final connection. if (this.mSourceConnector != null && this.mTargetConnector != null) { // Both defined means the connection can be created. Test have been made in the mouse move event handler. GraphViewModel lGraphViewModel = this.ParentView.DataContext as GraphViewModel; if (lGraphViewModel == null) { return; } PortViewModel lSourceViewModel = this.mSourceConnector.ParentPort.Content as PortViewModel; PortViewModel lTargetViewModel = this.mTargetConnector.ParentPort.Content as PortViewModel; ConnectionViewModel lConnectionViewModel = new ConnectionViewModel(); lConnectionViewModel.Output = lSourceViewModel; lConnectionViewModel.Input = lTargetViewModel; lGraphViewModel.AddConnection(lConnectionViewModel); } // Forget the reference on connectors. this.mSourceConnector = null; this.mTargetConnector = null; }
/// <summary> /// Fires the request connection creation. /// </summary> /// <param name="pConnectionToRemove">The connection to remove.</param> protected abstract void RequestConnectionRemoval(ConnectionViewModel pConnectionToRemove);
/// <summary> /// Removes a connection from the view model. /// </summary> /// <param name="pConnection">The connection to remove.</param> /// <!-- WARNING From outside, this method must be called only for test purpose --> protected void RemoveConnection(ConnectionViewModel pConnection) { this.mConnections.Remove(pConnection); this.mGraphItems.Remove(pConnection); }
/// <summary> /// Adds a node to the view model. /// </summary> /// <param name="pConnection">The connection to add.</param> /// <!-- WARNING From outside, this method must be called only for test purpose --> protected void AddConnection(ConnectionViewModel pConnection) { this.mConnections.Add(pConnection); this.mGraphItems.Add(pConnection); }
/// <summary> /// This method is called when a mouse button up occured on the adorner. /// </summary> /// <param name="pEventArgs">The event arguments</param> protected override void OnMouseUp(MouseButtonEventArgs pEventArgs) { // Release the mouse capture. if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); } // Getting the position. Point lHitPoint = pEventArgs.GetPosition(this); AdornerLayeredCanvas lParentCanvas = this.AdornedElement as AdornerLayeredCanvas; if (lParentCanvas != null) { // Remove the adorner. AdornerLayer lLayer = lParentCanvas.AdornerLayer; if (lLayer != null) { lLayer.Remove(this); } // Hitting the target connector. InputConnector lTargetConnector = lParentCanvas.HitControl<InputConnector>(lHitPoint); if (lTargetConnector != null) { GraphViewModel lGraphViewModel = lParentCanvas.DataContext as GraphViewModel; if (lGraphViewModel != null) { PortViewModel lTargetViewModel = lTargetConnector.ParentPort.Content as PortViewModel; PortViewModel lSourceViewModel = this.mSourceConnector.ParentPort.Content as PortViewModel; if (lTargetViewModel != null && lSourceViewModel.CanBeConnectedTo(lTargetViewModel)) { ConnectionViewModel lConnectionViewModel = new ConnectionViewModel(); lConnectionViewModel.Output= lSourceViewModel; lConnectionViewModel.Input = lTargetViewModel; lGraphViewModel.AddConnection(lConnectionViewModel); } } } } }
/// <summary> /// Creates the type graph. /// </summary> /// <returns>The graph view model.</returns> public GraphViewModel CreateTypeGraph() { GraphViewModel lGraph = new GraphViewModel(); NodeViewModel lNode0 = new TypeNodeViewModel(typeof(SampleClass)); lGraph.AddNode(lNode0); NodeViewModel lNode1 = new TypeNodeViewModel(typeof(SampleClass1VeryTooMuchLong)); lGraph.AddNode(lNode1); NodeViewModel lNode2 = new NodeViewModel(); lNode2.DisplayString = "Empty node"; lGraph.AddNode(lNode2); int i = 0; foreach (NodeViewModel lNode in lGraph.Nodes) { lNode.X = 300 * i; lNode.Y = 100 * i; i++; } ConnectionViewModel lConnectionViewModel = new ConnectionViewModel(); lConnectionViewModel.Output = lGraph.Nodes.ElementAt(0).Ports.FirstOrDefault(pPort => pPort.Direction == PortDirection.Output); lConnectionViewModel.Input = lGraph.Nodes.ElementAt(1).Ports.FirstOrDefault(pPort => pPort.Direction == PortDirection.Input); lGraph.AddConnection(lConnectionViewModel); return lGraph; }