void UpdateAttachPointOrder() { foreach (var direction in AttachPoints) { List <Tuple <AttachPoint, NodeBaseViewModel> > apByPositionOfConnectedTo = new List <Tuple <AttachPoint, NodeBaseViewModel> >(); foreach (var ap in direction.Value) { ConnectionViewModel cvm = ap.Connection; if (cvm != null) { NodeBaseViewModel connTo = (cvm.AttachPointFrom == ap) ? cvm.To : cvm.From; apByPositionOfConnectedTo.Add(Tuple.Create(ap, connTo)); } } int n = 0; if (direction.Key == AttachDirection.Left || direction.Key == AttachDirection.Right) { foreach (var tuple in apByPositionOfConnectedTo.OrderBy(a => a.Item2.Location.Y)) { tuple.Item1.Order = n++; } } else if (direction.Key == AttachDirection.Top || direction.Key == AttachDirection.Bottom) { foreach (var tuple in apByPositionOfConnectedTo.OrderBy(a => a.Item2.Location.X)) { tuple.Item1.Order = n++; } } } }
void HandleSelectNodeCommand(NodeBaseViewModel node) { if (SelectedCommand != null) { SelectedCommand.HandleNodeClick(node); } }
public void SelectNode(NodeBaseViewModel vm) { HandleSelectNodeCommand(vm); SelectedNode = vm; if (NodeSelected != null) { NodeSelected(this, vm); } }
public AttachDescriptorPlacement(NodeBaseViewModel parentControl) { parent = parentControl; AttachPoints = new Dictionary <AttachDirection, List <AttachPoint> >(); foreach (AttachDirection type in Enum.GetValues(typeof(AttachDirection))) { AttachPoints.Add(type, new List <AttachPoint>()); } }
public ConnectionViewModel(NodeBaseViewModel from, NodeBaseViewModel to) { this.From = from; this.To = to; From.LocationChanged += From_LocationChanged; To.LocationChanged += To_LocationChanged; StrokeThickness = 2; Stroke = Brushes.DarkOliveGreen; Type = EdgeLineType.Bezier; }
public void RemoveNode(NodeBaseViewModel node) { node.ParentDiagram = null; Nodes.Remove(node); node.Dispose(); var edgesToRemove = Edges.Where(edge => edge.From == node || edge.To == node).ToList(); foreach (var edge in edgesToRemove) { RemoveConnection(edge); } }
public void AddNode(NodeBaseViewModel node, Point location) { if (node == null) { return; } if (node.ParentDiagram != null) { throw new InvalidOperationException("Node is already added to diagram"); } node.ParentDiagram = this; node.Location = location; Nodes.Add(node); ForceRedraw(); node.RaiseInitialize(); }
void SendPacketInternal(NodeBaseViewModel from, object message) { // packet view is created in definition FrameworkElement vis = ParentDiagram.Definition.CreateVisualForPacket(message); if (vis == null) { return; } Canvas canvas = ParentDiagram.Canvas; if (canvas != null) { PacketView packet = new PacketView(vis, this, from, canvas); packet.Send(); } }
void SendPacket(NodeBaseViewModel from, object message) { try { if (ParentDiagram.Canvas.Dispatcher.CheckAccess()) { SendPacketInternal(from, message); } else { ParentDiagram.Canvas.Dispatcher.BeginInvoke(new System.Action(() => SendPacketInternal(from, message)), System.Windows.Threading.DispatcherPriority.DataBind); } } catch (Exception ex) { } }
public static Point GetAttachmentLocationOld(NodeBaseViewModel control, Point fromPoint, AttachDirection pos) { switch (pos) { case AttachDirection.Top: return(new Point(fromPoint.X - control.Size.Width / 2, fromPoint.Y - control.Size.Height)); case AttachDirection.Right: return(new Point(fromPoint.X, fromPoint.Y - (control.Size.Height / 2))); case AttachDirection.Bottom: return(new Point(fromPoint.X - control.Size.Width / 2, fromPoint.Y)); case AttachDirection.Left: return(new Point(fromPoint.X - control.Size.Width, fromPoint.Y - control.Size.Height / 2)); default: throw new ArgumentException(); } }
/// <summary> /// Creates connection between from and to according to Definition /// </summary> /// <param name="from"></param> /// <param name="to"></param> /// <returns>Returns null if connection cannot be created</returns> public ConnectionViewModel AddConnection(NodeBaseViewModel from, NodeBaseViewModel to) { var edge = Definition.CreateConnection(from, to); if (edge == null) { return(null); } // prevent showing attach descriptors when their position is not calculated yet // this can be possible not necessary if calculation their location was done before data binding of AttachDescriptors collection // but then we would not have size of attach descriptors and size is necessary for calculating position if (edge.FromDescriptor != null) { edge.FromDescriptor.Location = new Point(-1000, -1000); } if (edge.ToDescriptor != null) { edge.ToDescriptor.Location = new Point(-1000, -1000); } edge.ParentDiagram = this; if (edge.FromDescriptor != null) { AttachDescriptors.Add(edge.FromDescriptor); edge.FromDescriptor.Name = "from"; if (!IsInBatchMode) { ForceRedraw(); edge.FromDescriptor.RaiseInitialize(); } } if (edge.ToDescriptor != null) { AttachDescriptors.Add(edge.ToDescriptor); edge.ToDescriptor.Name = "to"; if (!IsInBatchMode) { ForceRedraw(); edge.ToDescriptor.RaiseInitialize(); } } if (!IsInBatchMode) { ForceRedraw(); } var sides = Definition.ConnectorSideStrategy.GetSidesForConnection(edge); edge.AttachPointFrom = from.Attach(sides.FromSide, edge, edge.FromDescriptor); edge.AttachPointTo = to.Attach(sides.ToSide, edge, edge.ToDescriptor); Edges.Add(edge); if (!IsInBatchMode) { edge.UpdateConnection(); } from.RaiseConnectionAdded(edge); to.RaiseConnectionAdded(edge); return(edge); }
public AttachPoint Attach(AttachDirection direction, ConnectionViewModel connection, NodeBaseViewModel node) { return(AttachPlacement.Attach(direction, connection, node)); }
public AttachPoint Attach(AttachDirection direction, ConnectionViewModel connection, NodeBaseViewModel associatedControl) { AttachPoint attachPoint = new AttachPoint(direction, connection, associatedControl); attachPoint.DirectionChanging += attachPoint_DirectionChanging; AttachPoints[direction].Add(attachPoint); UpdateAttachPoints(); return(attachPoint); }
public AttachPoint(AttachDirection direction, ConnectionViewModel connection, NodeBaseViewModel associatedControl) { Side = direction; this.Connection = connection; this.Control = associatedControl; }
public void StartMessageAnimationFrom(NodeBaseViewModel node, object message) { SendPacket(node, message); }