// Override DragOver to implement highlighting of links and nodes when dragged over protected override void DragOver(Point pt, bool moving, bool copying) { // Make the dragged node less opaque ClearOpacities(); this.CurrentPart = FindPartAt(this.Diagram.LastMousePointInModel, false); Node node = this.CurrentPart as Node; if (node != null) { MyNodeData mnd = node.Data as MyNodeData; if (mnd != null) { mnd.Opacity = .5; } } this.DropOntoEnabled = true; if (this.DropOntoEnabled && this.Diagram.Model.Modifiable) { Part overpart = this.Diagram.Panel.FindElementsAt <Part>(pt, Part.FindAncestor <Part>, p => !this.Diagram.SelectedParts.Contains(p), SearchLayers.Parts).FirstOrDefault(); this.DragOverPart = overpart; // When overpart changes, clear any previous highlights ClearHighlights(); // Highlights the part being dragged over if it is a link or a node Link l = overpart as Link; if (l != null) { MyLinkData mld = l.Data as MyLinkData; if (mld != null) { mld.Highlight = true; } } else { Node n = overpart as Node; if (n != null) { MyNodeData mnd = n.Data as MyNodeData; // Don't highlight "Start" node if (mnd != null && mnd.Category != "Start") { mnd.Highlight = true; } } } } if (this.Diagram.AllowScroll && (moving || copying)) { this.Diagram.Panel.DoAutoScroll(pt); } }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Link link = value as Link; if (link != null && link.FromNode != null && link.FromPortId == "LeftPort") { MyNodeData d = link.FromNode.Data as MyNodeData; if (d != null && d.Key.StartsWith("If")) { return(Visibility.Visible); } } return(Visibility.Collapsed); }
// Mark a node as being part of the subgraph private void Mark(Node n, int i) { if (n == null) { return; } MyNodeData mnd = n.Data as MyNodeData; mnd.UserFlags |= i; foreach (Node x in n.NodesOutOf) { Mark(x, i); } }
// Clear the UserFlags on a given node and all nodes out of it private void Clear(Node n) { if (n == null) { return; } MyNodeData mnd = n.Data as MyNodeData; mnd.UserFlags = 0; foreach (Node x in n.NodesOutOf) { Clear(x); } }
// Now add marked nodes to the collection private void SelectMarked(Node n, int i, HashSet <Part> coll) { if (n == null) { return; } MyNodeData mnd = n.Data as MyNodeData; if (mnd.UserFlags != i) { coll.Add(n); foreach (Node x in n.NodesOutOf) { SelectMarked(x, i, coll); } } }
// Find the node where the two sides of the subgraph meet back up private Node FindJoin(Node n, int i) { if (n == null) { return(null); } MyNodeData mnd = n.Data as MyNodeData; if (mnd.UserFlags == i) { return(n); } foreach (Node x in n.NodesOutOf) { Node r = FindJoin(x, i); if (r != null) { return(r); } } return(null); }