locked
Forcing straight edges RRS feed

  • Question

  • Is there any way I can, post or pre layout, disable edge curves and make them all straight lines?

    I'm talking about a programmatic process equivalent to manually removing all polyline corners

    Here's what I'm currently doing:
    foreach (var edge in Msagl_Viewer.Graph.Edges)
     edge.Attr.EdgeCurve = new Curve
     {
     Segments =
     {
     new LineSegment(edge.SourceNode.BoundingBox.Center,
     edge.TargetNode.BoundingBox.Center)
     }
    };
    
    
    Msagl_Viewer.NeedToCalculateLayout = false;
    Msagl_Viewer.Graph = Msagl_Viewer.Graph;
    Msagl_Viewer.NeedToCalculateLayout = true;

     

    It works, but as soon as I move a node that was attached to a curved edge, the polyline corners suddenly reappear and the edge gets curved again. I just want the polyline corners gone for good (or not there to begin with).

    Help would be appreciated, Thanks !

    Thursday, December 23, 2010 11:40 PM

Answers

  • That did the trick ! Invalidate() wasn't enough for me, though - I had to reassign the graph for the update to take place immediately.

    For posterity, the entire function is:

            public static void StraightenEdges(GViewer msaglViewer)
            {
                foreach (var ed in msaglViewer.Graph.GeometryGraph.Edges)
                    ed.CreateSimpleEdgeCurve();

                msaglViewer.NeedToCalculateLayout = false;
                msaglViewer.Graph = msaglViewer.Graph;
                msaglViewer.NeedToCalculateLayout = true;
            }

    Again, Thank you very much

     

    Friday, January 14, 2011 12:59 PM

All replies

  • I suppose you have the source of GeometryGraphEditor.cs as it is a part of the distribution. Please change the function GetClosenessToLine to always return 1. The edges should be created as straight lines after that.
    Thanks,
    Lev

     


    Lev Nachmanson
    Monday, December 27, 2010 7:47 PM
  • Hi Lev, thank you for your suggestion.

    I have a couple of issues with it (forgive me if they are due to my initial request not being clear)

    1. When the graph is first drawn, the edges are still curved. Only when I move a node, do its incident edges straighten (which means I'd have to move a vertex cover in order to straighten all edges). If I run my above code all the the edges straighten, but then assigning a new graph to the viewer I get a null reference exception at Microsoft.Msagl.GraphViewerGdi.Tessellator.TessellateCurve(DEdge dedge, Double radiusForUnderlyingPolylineCorners) where the edge.Attr.EdgeCurve is null.
    2. The polyline corners aren't actually removed, rather they are ignored. This is a problem because I do want to be able to add polyline corners manually , which will curve the edges.

    So in short, my goal is to delete all the automatically generated polyline corners (or not generate them in the first place), while maintaining the ability to manually add polyline corners (and have them affect the layout, of course).

    Thank you again for your help!

    Thursday, December 30, 2010 1:30 PM
  • The following code works for me, tested in WindowsApplicationSample

    gViewer.Graph = graph;

     

    //making edges straight

     

    foreach(var ed in graph.GeometryGraph.Edges) ed.CreateSimpleEdgeCurve();

    gViewer.Invalidate();

    Thanks,

    Lev


    Lev Nachmanson
    Wednesday, January 5, 2011 12:31 AM
  • That did the trick ! Invalidate() wasn't enough for me, though - I had to reassign the graph for the update to take place immediately.

    For posterity, the entire function is:

            public static void StraightenEdges(GViewer msaglViewer)
            {
                foreach (var ed in msaglViewer.Graph.GeometryGraph.Edges)
                    ed.CreateSimpleEdgeCurve();

                msaglViewer.NeedToCalculateLayout = false;
                msaglViewer.Graph = msaglViewer.Graph;
                msaglViewer.NeedToCalculateLayout = true;
            }

    Again, Thank you very much

     

    Friday, January 14, 2011 12:59 PM