microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.34k stars 301 forks source link

[Help wanted] How to properly add new Edge to GViewer programmatically #321

Open MVoloshin opened 1 year ago

MVoloshin commented 1 year ago

Hello! Please, tell me how to create and add new Egde to GViewer programmatically? I can't get this working without some hacks at the moment(

new_edge = gcnew Edge(ivn1->Node, ivn2->Node, ConnectionToGraph::Connected, gv->LayoutEditor->EdgeAttr->Clone());
            new_edge->SourcePort = gcnew FloatingPort(new_edge->SourceNode->GeometryNode->BoundaryCurve, new_edge->SourceNode->GeometryNode->Center); // exception SourcePort is null in RouteEdge() without this
            new_edge->TargetPort = gcnew FloatingPort(new_edge->TargetNode->GeometryNode->BoundaryCurve, new_edge->TargetNode->GeometryNode->Center); // exception TargetPort is null in RouteEdge() without this
            IViewerEdge^ ive = gv->RouteEdge(new_edge);
            gv->AddEdge(ive, false); // fails without RouteEdge()
            gv->LayoutEditor->AttachLayoutChangeEvent(ive); // edge line is not moved together with nodes without this (why?)
            setLabelForEdge(ive, weight);