microsoft / automatic-graph-layout

A set of tools for graph layout and viewing
Other
1.36k stars 308 forks source link

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

Open MVoloshin opened 2 years ago

MVoloshin commented 2 years 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);