/// <summary> /// Normally this just returns the result of <see cref="ComputeMemberBounds"/> expanded by the <see cref="Padding"/>. /// </summary> /// <returns> /// However, if <see cref="SurroundsMembersAfterDrop"/> is true, /// and if the <see cref="Diagram.CurrentTool"/> is the <see cref="Northwoods.GoXam.Tool.DraggingTool"/>, /// and if this <see cref="Group"/> is not being dragged, /// this method returns the last value of <see cref="ComputeBorder"/> before dragging began. /// </returns> protected override Rect ComputeBorder() { if (this.SurroundsMembersAfterDrop && this.SavedBounds != Rect.Empty) { Group sg = Diagram.FindAncestor <Group>(this); if (sg != null) { Diagram diagram = sg.Diagram; if (diagram != null) { Northwoods.GoXam.Tool.DraggingTool tool = diagram.CurrentTool as Northwoods.GoXam.Tool.DraggingTool; if (tool != null && !tool.Dropped && tool.DraggedParts != null && !tool.DraggedParts.ContainsKey(sg)) { return(this.SavedBounds); } } } } Rect r = ComputeMemberBounds(); Thickness pad = this.Padding; return(new Rect(r.X - pad.Left, r.Y - pad.Top, r.Width + pad.Left + pad.Right, r.Height + pad.Top + pad.Bottom)); }
/// <summary> /// Actually perform all of the <see cref="Layouts"/> for the given nodes and links. /// </summary> /// <param name="nodes"></param> /// <param name="links"></param> /// <remarks> /// This iterates over the layouts in <see cref="Layouts"/>. /// If the layout's <see cref="IDiagramLayout.ValidLayout"/> is false, /// it gets the subsets of nodes and links that apply to that particular layout /// and then calls <see cref="IDiagramLayout.DoLayout"/> on it. /// </remarks> public void DoLayout(IEnumerable <Node> nodes, IEnumerable <Link> links) { Diagram diagram = this.Diagram; if (diagram == null) { return; } if (diagram.Panel == null) { return; } LayoutManager mgr = diagram.LayoutManager; Northwoods.GoXam.Tool.DraggingTool tool = diagram.DraggingTool; if (tool == null) { tool = new Northwoods.GoXam.Tool.DraggingTool(); } Point pos = this.ArrangementOrigin; foreach (IDiagramLayout layout in this.Layouts) { bool invalidlayout = !layout.ValidLayout; if (invalidlayout || this.Arrangement != MultiArrangement.None) //??? need to move networks of valid layouts { IEnumerable <Node> subnodes = (mgr != null ? nodes.Where(n => mgr.CanLayoutPart(n, layout)) : nodes); IEnumerable <Link> sublinks = (mgr != null ? links.Where(l => mgr.CanLayoutPart(l, layout)) : links); if (invalidlayout) { //Diagram.Debug("multilayout " + layout.Id + " of " + Diagram.Str(layout.Group) + ": INVALID " + subnodes.Count().ToString() + " nodes " + sublinks.Count().ToString() + " links " + Diagram.Str(subnodes.ToArray()) + " at " + Diagram.Str(pos)); DiagramLayout dlay = layout as DiagramLayout; if (dlay != null) { dlay.ArrangementOrigin = pos; } layout.DoLayout(subnodes, sublinks); } //?? need to make sure all links are routed, so their Bounds aren't bogus Rect b = diagram.Panel.ComputeBounds(subnodes.OfType <Part>() /*.Concat<Part>(sublinks.OfType<Part>())*/); if (!invalidlayout && !b.IsEmpty) { //Diagram.Debug("multilayout " + layout.Id + " of " + Diagram.Str(layout.Group) + ": MOVING " + subnodes.Count().ToString() + " nodes " + sublinks.Count().ToString() + " links " + Diagram.Str(new Point(pos.X-b.X, pos.Y-b.Y)) + " computedBounds: " + Diagram.Str(b)); var dict = tool.ComputeEffectiveCollection(subnodes.OfType <Part>()); tool.MoveParts(dict, new Point(pos.X - b.X, pos.Y - b.Y)); } switch (this.Arrangement) { case MultiArrangement.None: break; case MultiArrangement.Horizontal: if (b.Width > 0) { pos.X += b.Width; pos.X += this.ArrangementSpacing.Width; } break; case MultiArrangement.Vertical: if (b.Height > 0) { pos.Y += b.Height; pos.Y += this.ArrangementSpacing.Height; } break; } } } }
/// <summary> /// Actually perform all of the <see cref="Layouts"/> for the given nodes and links. /// </summary> /// <param name="nodes"></param> /// <param name="links"></param> /// <remarks> /// This iterates over the layouts in <see cref="Layouts"/>. /// If the layout's <see cref="IDiagramLayout.ValidLayout"/> is false, /// it gets the subsets of nodes and links that apply to that particular layout /// and then calls <see cref="IDiagramLayout.DoLayout"/> on it. /// </remarks> public void DoLayout(IEnumerable<Node> nodes, IEnumerable<Link> links) { Diagram diagram = this.Diagram; if (diagram == null) return; if (diagram.Panel == null) return; LayoutManager mgr = diagram.LayoutManager; Northwoods.GoXam.Tool.DraggingTool tool = diagram.DraggingTool; if (tool == null) tool = new Northwoods.GoXam.Tool.DraggingTool(); Point pos = this.ArrangementOrigin; foreach (IDiagramLayout layout in this.Layouts) { bool invalidlayout = !layout.ValidLayout; if (invalidlayout || this.Arrangement != MultiArrangement.None) { //??? need to move networks of valid layouts IEnumerable<Node> subnodes = (mgr != null ? nodes.Where(n => mgr.CanLayoutPart(n, layout)) : nodes); IEnumerable<Link> sublinks = (mgr != null ? links.Where(l => mgr.CanLayoutPart(l, layout)) : links); if (invalidlayout) { //Diagram.Debug("multilayout " + layout.Id + " of " + Diagram.Str(layout.Group) + ": INVALID " + subnodes.Count().ToString() + " nodes " + sublinks.Count().ToString() + " links " + Diagram.Str(subnodes.ToArray()) + " at " + Diagram.Str(pos)); DiagramLayout dlay = layout as DiagramLayout; if (dlay != null) dlay.ArrangementOrigin = pos; layout.DoLayout(subnodes, sublinks); } //?? need to make sure all links are routed, so their Bounds aren't bogus Rect b = diagram.Panel.ComputeBounds(subnodes.OfType<Part>() /*.Concat<Part>(sublinks.OfType<Part>())*/ ); if (!invalidlayout && !b.IsEmpty) { //Diagram.Debug("multilayout " + layout.Id + " of " + Diagram.Str(layout.Group) + ": MOVING " + subnodes.Count().ToString() + " nodes " + sublinks.Count().ToString() + " links " + Diagram.Str(new Point(pos.X-b.X, pos.Y-b.Y)) + " computedBounds: " + Diagram.Str(b)); var dict = tool.ComputeEffectiveCollection(subnodes.OfType<Part>()); tool.MoveParts(dict, new Point(pos.X-b.X, pos.Y-b.Y)); } switch (this.Arrangement) { case MultiArrangement.None: break; case MultiArrangement.Horizontal: if (b.Width > 0) { pos.X += b.Width; pos.X += this.ArrangementSpacing.Width; } break; case MultiArrangement.Vertical: if (b.Height > 0) { pos.Y += b.Height; pos.Y += this.ArrangementSpacing.Height; } break; } } } }