public void ExpandingSearchTest_LessThanMiddle() { var expected = new int[] { 3, 4, 2, 5, 1, 6, 0, 7, 8, 9 }; var r = EdgeLabelPlacement.ExpandingSearch(3, 0, 10).ToList(); CollectionAssert.AreEqual(expected, r); }
public void ExpandingSearchTest_BiggerThanMiddle() { var expected = new int[] { 7, 8, 6, 9, 5, 4, 3, 2, 1, 0 }; var r = EdgeLabelPlacement.ExpandingSearch(7, 0, 10).ToList(); CollectionAssert.AreEqual(expected, r); }
public void ExpandingSearchTest_MiddleOut() { int[] expected = new int[] { 5, 6, 4, 7, 3, 8, 2, 9, 1, 0 }; var r = EdgeLabelPlacement.ExpandingSearch(5, 0, 10).ToList(); CollectionAssert.AreEqual(expected, r); }
public void ExpandingSearchTest_DecreasingOnly() { int[] expected = new int[] { 4, 3, 2, 1, 0 }; var r = EdgeLabelPlacement.ExpandingSearch(4, 0, 5).ToList(); CollectionAssert.AreEqual(expected, r); }
void DragObjectsForRectilinearCase(Point delta) { foreach (GeomNode node in objectsToDrag.Where(n => n is GeomNode)) { node.Center += delta; } RectilinearInteractiveEditor.CreatePortsAndRouteEdges(LayoutSettings.NodeSeparation / 3, 1, graph.Nodes, graph.Edges, LayoutSettings.EdgeRoutingSettings.EdgeRoutingMode, true, LayoutSettings.EdgeRoutingSettings .UseObstacleRectangles, LayoutSettings.EdgeRoutingSettings.BendPenalty); var labelPlacer = new EdgeLabelPlacement(graph); labelPlacer.Run(); foreach (GeomEdge e in Graph.Edges) { UpdateGraphBoundingBoxWithCheck(e); } foreach (GeomNode n in Graph.Nodes) { UpdateGraphBoundingBoxWithCheck(n); } }
internal static void PlaceLabels(GeometryGraph component, CancelToken cancelToken) { List <Label> labelList = component.Edges.SelectMany(e => e.Labels).ToList(); var labelPlacer = new EdgeLabelPlacement(component, labelList); labelPlacer.Run(cancelToken); }
/// <summary> /// </summary> /// <param name="geometryGraph"></param> /// <param name="layoutSettings"></param> /// <param name="edgesToRoute"></param> public static void RouteAndLabelEdges(GeometryGraph geometryGraph, LayoutAlgorithmSettings layoutSettings, IEnumerable <Edge> edgesToRoute, int straighLineRoutingThreshold, CancelToken cancelToken) { //todo: what about parent edges!!!! var filteredEdgesToRoute = edgesToRoute.Where(e => !e.UnderCollapsedCluster()).ToArray(); var ers = layoutSettings.EdgeRoutingSettings; var mode = (straighLineRoutingThreshold == 0 || geometryGraph.Nodes.Count < straighLineRoutingThreshold) ? ers.EdgeRoutingMode : EdgeRoutingMode.StraightLine; if (mode == EdgeRoutingMode.Rectilinear || mode == EdgeRoutingMode.RectilinearToCenter) { RectilinearInteractiveEditor.CreatePortsAndRouteEdges( layoutSettings.NodeSeparation / 3, layoutSettings.NodeSeparation / 3, geometryGraph.Nodes, edgesToRoute, mode, true, ers.UseObstacleRectangles, ers.BendPenalty, cancelToken); } else if (mode == EdgeRoutingMode.Spline || mode == EdgeRoutingMode.SugiyamaSplines) { new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, null) { ContinueOnOverlaps = true, KeepOriginalSpline = ers.KeepOriginalSpline }.Run(cancelToken); } else if (mode == EdgeRoutingMode.SplineBundling) { var edgeBundlingSettings = ers.BundlingSettings ?? new BundlingSettings(); var bundleRouter = new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, edgeBundlingSettings) { KeepOriginalSpline = ers.KeepOriginalSpline }; bundleRouter.Run(cancelToken); if (bundleRouter.OverlapsDetected) { new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, null) { ContinueOnOverlaps = true, KeepOriginalSpline = ers.KeepOriginalSpline }.Run(cancelToken); } } else if (mode == EdgeRoutingMode.StraightLine) { var router = new StraightLineEdges(filteredEdgesToRoute, ers.Padding); router.Run(); } var elb = new EdgeLabelPlacement(geometryGraph.Nodes, filteredEdgesToRoute); elb.Run(); geometryGraph.UpdateBoundingBox(); }
void RunSplineRouterAndPutLabels() { var router = new SplineRouter(graph, LayoutSettings.EdgeRoutingSettings.Padding, LayoutSettings.EdgeRoutingSettings.PolylinePadding, LayoutSettings.EdgeRoutingSettings.ConeAngle, LayoutSettings.EdgeRoutingSettings.BundlingSettings); router.Run(); var elp = new EdgeLabelPlacement(graph); elp.Run(); UpdateGraphBoundingBoxWithCheck(); }
internal void UpdateEdgesPlacement() { if (DisplayedSubmodel.Node.Count <= 0) { return; } GeometryGraph geomGraph = GeometryGraph ?? GraphEditor.Viewer.Graph.GeometryGraph; geomGraph.BoundingBox = geomGraph.PumpTheBoxToTheGraphWithMargins(); EdgeLabelPlacement placement = new EdgeLabelPlacement(geomGraph); placement.Run(); }
private void DragEdgesAsRatio(Point delta) { foreach (GeomEdge edge in edgesDraggedWithSource) { ModifyEdgeByScale(delta, edge); } foreach (GeomEdge edge in edgesDraggedWithTarget) { ModifyEdgeByScale(delta, edge); } var ep = new EdgeLabelPlacement(graph.Nodes, edgesDraggedWithSource.Union(edgesDraggedWithTarget)); ep.Run(); }
void DragEdgesAsStraighLines(Point delta) { foreach (GeomEdge edge in edgesDraggedWithSource) { DragEdgeAsStraightLine(delta, edge); } foreach (GeomEdge edge in edgesDraggedWithTarget) { DragEdgeAsStraightLine(delta, edge); } var ep = new EdgeLabelPlacement(graph.Nodes, edgesDraggedWithSource.Union(edgesDraggedWithTarget)); ep.Run(); }
static void LabelParentEdgesAndMaybeRerouteThemNicely(GeometryGraph graph, List<Edge> inParentEdges, List<Edge> outParentEdges, EdgeRoutingSettings edgeRoutingSettings) { if (AllowedToRoute(inParentEdges, outParentEdges, edgeRoutingSettings)) { var shapeGroupRouter = new SplineRouter(graph, edgeRoutingSettings.Padding, edgeRoutingSettings.PolylinePadding, edgeRoutingSettings.RoutingToParentConeAngle, inParentEdges, outParentEdges); shapeGroupRouter.Run(); } var labeledEdges = outParentEdges.Concat(inParentEdges).Where(e => e.Labels.Any()); if (labeledEdges.Any()) { var elb = new EdgeLabelPlacement(graph.Nodes, labeledEdges); //consider adding more nodes here: some sibling clusters maybe elb.Run(); } }
private void ViewerOnEdgeAdded(object sender, EventArgs eventArgs) { var edge = (Edge)sender; var form = new Form(); var tableLayout = new TableLayoutPanel { Dock = DockStyle.Fill }; form.Controls.Add(tableLayout); // TODO: GetEdgeTypes or something foreach (var type in this.graph.GetNodeTypes()) { if (type.InstanceMetatype != Repo.Metatype.Edge || type.IsAbstract) { continue; } var edgeType = type as Repo.IEdge; tableLayout.RowStyles.Add(new RowStyle(SizeType.Percent, 25)); // TODO: We definitely need names for non-abstract edges. Maybe as attribute? var associationButton = new Button { Text = "Link", Dock = DockStyle.Fill }; associationButton.Click += (o, args) => { this.graph.CreateNewEdge(edgeType, edge); this.viewer.Graph.AddPrecalculatedEdge(edge); this.viewer.SetEdgeLabel(edge, edge.Label); var ep = new EdgeLabelPlacement(this.viewer.Graph.GeometryGraph); ep.Run(); this.viewer.Invalidate(); form.DialogResult = DialogResult.OK; }; associationButton.Font = new Font(associationButton.Font.FontFamily, fontSize); tableLayout.Controls.Add(associationButton, 0, tableLayout.RowCount - 1); ++tableLayout.RowCount; } var result = form.ShowDialog(); if (result == DialogResult.Cancel) { this.viewer.Undo(); this.viewer.Invalidate(); } }
static void LabelParentEdgesAndMaybeRerouteThemNicely(GeometryGraph graph, List <Edge> inParentEdges, List <Edge> outParentEdges, EdgeRoutingSettings edgeRoutingSettings) { if (AllowedToRoute(inParentEdges, outParentEdges, edgeRoutingSettings)) { var shapeGroupRouter = new SplineRouter(graph, edgeRoutingSettings.Padding, edgeRoutingSettings.PolylinePadding, edgeRoutingSettings.RoutingToParentConeAngle, inParentEdges, outParentEdges); shapeGroupRouter.Run(); } var labeledEdges = outParentEdges.Concat(inParentEdges).Where(e => e.Labels.Any()); if (labeledEdges.Any()) { var elb = new EdgeLabelPlacement(graph.Nodes, labeledEdges); //consider adding more nodes here: some sibling clusters maybe elb.Run(); } /*//*************debug code start * var parentEdges = inParentEdges.Concat(outParentEdges); * var ll = new List<DebugCurve>(); * var marked = new Microsoft.Msagl.Core.DataStructures.Set<Node>(); * foreach (var e in parentEdges) { * marked.Insert(e.Source); * marked.Insert(e.Target); * ll.Add(new DebugCurve(100, 1, "blue", e.Curve)); * } * foreach (var c in graph.RootCluster.AllClustersDepthFirst()) { * var color = marked.Contains(c) ? "red" : "green"; * ll.Add(new DebugCurve(100, 1, color, c.BoundaryCurve)); * } * foreach (var c in graph.Nodes) { * var color = marked.Contains(c) ? "red" : "green"; * ll.Add(new DebugCurve(100, 1, color, c.BoundaryCurve)); * } * * LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(ll); */ //*************debug code end }
/// <summary> /// Changes an edge's label and updates the display /// </summary> /// <param name="e">The edge whose label has to be changed</param> /// <param name="newLabel">The new label</param> internal void RelabelEdge(Edge e, string newLabel) { if (e.Label == null) { e.Label = new Label(newLabel); } else { e.Label.Text = newLabel; } gViewer.SetEdgeLabel(e, e.Label); e.Label.GeometryLabel.InnerPoints = new List <Point>(); var ep = new EdgeLabelPlacement(gViewer.Graph.GeometryGraph); ep.Run(); gViewer.Graph.GeometryGraph.UpdateBoundingBox(); gViewer.Invalidate(); }
void SetLabels() { var edgeLabeller = new EdgeLabelPlacement(originalGraph); edgeLabeller.Run(); }
static void LabelParentEdgesAndMaybeRerouteThemNicely(GeometryGraph graph, List<Edge> inParentEdges, List<Edge> outParentEdges, EdgeRoutingSettings edgeRoutingSettings) { if (AllowedToRoute(inParentEdges, outParentEdges, edgeRoutingSettings)) { var shapeGroupRouter = new SplineRouter(graph, edgeRoutingSettings.Padding, edgeRoutingSettings.PolylinePadding, edgeRoutingSettings.RoutingToParentConeAngle, inParentEdges, outParentEdges); shapeGroupRouter.Run(); } var labeledEdges = outParentEdges.Concat(inParentEdges).Where(e => e.Labels.Any()); if (labeledEdges.Any()) { var elb = new EdgeLabelPlacement(graph.Nodes, labeledEdges); //consider adding more nodes here: some sibling clusters maybe elb.Run(); } /*//*************debug code start var parentEdges = inParentEdges.Concat(outParentEdges); var ll = new List<DebugCurve>(); var marked = new Microsoft.Msagl.Core.DataStructures.Set<Node>(); foreach (var e in parentEdges) { marked.Insert(e.Source); marked.Insert(e.Target); ll.Add(new DebugCurve(100, 1, "blue", e.Curve)); } foreach (var c in graph.RootCluster.AllClustersDepthFirst()) { var color = marked.Contains(c) ? "red" : "green"; ll.Add(new DebugCurve(100, 1, color, c.BoundaryCurve)); } foreach (var c in graph.Nodes) { var color = marked.Contains(c) ? "red" : "green"; ll.Add(new DebugCurve(100, 1, color, c.BoundaryCurve)); } LayoutAlgorithmSettings.ShowDebugCurvesEnumeration(ll); */ //*************debug code end }
/// <summary> /// </summary> /// <param name="geometryGraph"></param> /// <param name="layoutSettings"></param> /// <param name="edgesToRoute"></param> public static void RouteAndLabelEdges(GeometryGraph geometryGraph, LayoutAlgorithmSettings layoutSettings, IEnumerable<Edge> edgesToRoute) { //todo: what about parent edges!!!! var filteredEdgesToRoute = edgesToRoute.Where(e => ! e.UnderCollapsedCluster()).ToArray(); var ers = layoutSettings.EdgeRoutingSettings; if (ers.EdgeRoutingMode == EdgeRoutingMode.Rectilinear || ers.EdgeRoutingMode == EdgeRoutingMode.RectilinearToCenter) { RectilinearInteractiveEditor.CreatePortsAndRouteEdges( layoutSettings.NodeSeparation/3, layoutSettings.NodeSeparation/3, geometryGraph.Nodes, edgesToRoute, ers.EdgeRoutingMode, true, ers.UseObstacleRectangles, ers.BendPenalty); } else if (ers.EdgeRoutingMode == EdgeRoutingMode.Spline || ers.EdgeRoutingMode==EdgeRoutingMode.SugiyamaSplines) { new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, null) { ContinueOnOverlaps = true, KeepOriginalSpline = ers.KeepOriginalSpline }.Run(); } else if (ers.EdgeRoutingMode == EdgeRoutingMode.SplineBundling) { var edgeBundlingSettings = ers.BundlingSettings ?? new BundlingSettings(); var bundleRouter = new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, edgeBundlingSettings) { KeepOriginalSpline = ers.KeepOriginalSpline }; bundleRouter.Run(); if (bundleRouter.OverlapsDetected) { new SplineRouter(geometryGraph, filteredEdgesToRoute, ers.Padding, ers.PolylinePadding, ers.ConeAngle, null) { ContinueOnOverlaps = true, KeepOriginalSpline = ers.KeepOriginalSpline }.Run(); } } else if (ers.EdgeRoutingMode == EdgeRoutingMode.StraightLine) { var router = new StraightLineEdges(filteredEdgesToRoute, ers.Padding); router.Run(); } var elb = new EdgeLabelPlacement(geometryGraph.Nodes, filteredEdgesToRoute); elb.Run(); geometryGraph.UpdateBoundingBox(); }
///<summary> ///</summary> public static void RouteEdgesRectilinearly(IViewer viewer) { var geomGraph = viewer.Graph.GeometryGraph; var settings = viewer.Graph.LayoutAlgorithmSettings; RectilinearInteractiveEditor.CreatePortsAndRouteEdges(settings.NodeSeparation / 3, 1, geomGraph.Nodes, geomGraph.Edges, settings.EdgeRoutingSettings.EdgeRoutingMode, true, settings.EdgeRoutingSettings.UseObstacleRectangles, settings.EdgeRoutingSettings.BendPenalty); var labelPlacer = new EdgeLabelPlacement(geomGraph); labelPlacer.Run(); }
void DragObjectsForRectilinearCase(Point delta) { foreach (GeomNode node in objectsToDrag.Where(n => n is GeomNode)) node.Center += delta; RectilinearInteractiveEditor.CreatePortsAndRouteEdges(LayoutSettings.NodeSeparation/3, 1, graph.Nodes, graph.Edges, LayoutSettings.EdgeRoutingSettings.EdgeRoutingMode, true, LayoutSettings.EdgeRoutingSettings .UseObstacleRectangles, LayoutSettings.EdgeRoutingSettings.BendPenalty); var labelPlacer = new EdgeLabelPlacement(graph); labelPlacer.Run(); foreach (GeomEdge e in Graph.Edges) UpdateGraphBoundingBoxWithCheck(e); foreach (GeomNode n in Graph.Nodes) UpdateGraphBoundingBoxWithCheck(n); }
internal static void PlaceLabels(GeometryGraph component, CancelToken cancelToken) { List<Label> labelList = component.Edges.SelectMany(e => e.Labels).ToList(); var labelPlacer = new EdgeLabelPlacement(component, labelList); labelPlacer.Run(cancelToken); }
void DragEdgesAsStraighLines(Point delta) { foreach (GeomEdge edge in edgesDraggedWithSource) DragEdgeAsStraightLine(delta, edge); foreach (GeomEdge edge in edgesDraggedWithTarget) DragEdgeAsStraightLine(delta, edge); var ep = new EdgeLabelPlacement(graph.Nodes, edgesDraggedWithSource.Union(edgesDraggedWithTarget)); ep.Run(); }
/// <summary> /// Changes an edge's label and updates the display /// </summary> /// <param name="e">The edge whose label has to be changed</param> /// <param name="newLabel">The new label</param> internal void RelabelEdge(Edge e, string newLabel) { if (e.Label == null) e.Label = new Label(newLabel); else e.Label.Text = newLabel; gViewer.SetEdgeLabel(e, e.Label); e.Label.GeometryLabel.InnerPoints = new List<Point>(); var ep = new EdgeLabelPlacement(gViewer.Graph.GeometryGraph); ep.Run(); gViewer.Graph.GeometryGraph.UpdateBoundingBox(); gViewer.Invalidate(); }
private void Label_box_LostFocus(object sender, RoutedEventArgs e) { var editingObj = _graphViewer.LayoutEditor.EditingObject; if (editingObj == null) { return; } var obj = editingObj.DrawingObject as DrawingObject2; if (obj == null) { return; } if (obj.Label == null) { if (label_box.Text == "") { return; } } else if (obj.Label.Text == label_box.Text) { return; } var node = obj as Node; if (node != null) { _graphViewer.updateVNodeLabelText(editingObj as VNode, label_box.Text); //var sz = Common.MeasureLabel(label); //node.GeometryNode.BoundaryCurve = NodeBoundaryCurves.GetNodeBoundaryCurve(node,sz.Width,sz.Height ); //(editingObj as VNode).Invalidate(); } else { var edge = obj as Edge; if (edge == null) { return; } var vedge = editingObj as VEdge; var label = edge.Label; if (label == null) { label = new DrawingLabel(label_box.Text); edge.Label = label; label.Owner = edge; //var sz = Common.MeasureLabel(label); //edge.GeometryEdge.Label = new Microsoft.Msagl.Core.Layout.Label(sz.Width, sz.Height, edge.GeometryEdge); var llabel = new LLabel(); edge.GeometryEdge.Label = llabel; llabel.GeometryParent = edge.GeometryEdge; label.GeometryLabel = llabel; //edge.GeometryEdge.Label.UserData = edge.Label; //var fe = _graphViewer.CreateDefaultFrameworkElementForDrawingObject(edge); //var vlabel = new VLabel(edge, fe); //fe.Tag = vlabel; //(editingObj as VEdge).VLabel = vlabel; _graphViewer.SetVEdgeLabel(edge, vedge, _graphViewer.ZIndexOfEdge(edge)); _graphViewer.LayoutEditor.AttachLayoutChangeEvent(vedge.VLabel); } else { label.Text = label_box.Text; var textBlock = _graphViewer.drawingObjectsToFrameworkElements[edge] as TextBlock; textBlock.Text = label.Text; //textBlock.InvalidateMeasure(); textBlock.Width = Double.NaN; textBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); textBlock.Width = textBlock.DesiredSize.Width; //textBlock.Height = textBlock.DesiredSize.Height; //label.GeometryLabel.Width } //var vedge = _graphViewer.GetIViewerObject(edge) as VEdge; //_graphViewer.SetVEdgeLabel(edge, vedge, _graphViewer.ZIndexOfEdge(edge)); _graphViewer.AssignLabelWidthHeight(edge.GeometryEdge, edge); //_graphViewer.LayoutEditor.AttachLayoutChangeEvent(vedge.VLabel); //var labelCol = new List<LLabel>(); //labelCol.Add(label.GeometryLabel); //EdgeLabelPlacement lp = new EdgeLabelPlacement(_graphViewer.Graph.GeometryGraph,labelCol);//,label.GeometryLabel) //var lp=new EdgeLabelPlacement(_graphViewer.Graph.GeometryGraph, new List<LLabel> { label.GeometryLabel}); var lp = new EdgeLabelPlacement(_graphViewer.Graph.GeometryGraph, new [] { label.GeometryLabel }); lp.Run(); vedge.Invalidate(); //edge.LabelText = label_box.Text; //var vedge = _graphViewer.GetIViewerObject(edge) as VEdge; //_graphViewer.SetVEdgeLabel(edge, vedge, _graphViewer.ZIndexOfEdge(edge)); //vedge.Invalidate(); } //if (label.Text == label_box.Text) // return; //label.Text = label_box.Text; //obj.Label = label; }