Problem with routing points while adding links

Hello,

I’ve encountered problem with drawing links with specified routing points. Below are defined 3 functions:

    public void LoadXml(Diagram diagram)
    {
        var root = XElement.Load("file.xml");
        _routineDiagram = diagram;
        diagram.LayoutCompleted += LoadLinkRoutes;
        _routineDiagram.PartManager.UpdatesRouteDataPoints = false;
        Model.Load<NodeModel, LinkModel>(root, "Node", "Link");
    }

    public void LoadDb(Diagram diagram)
    {
        //local variables - holds items readed from file
        var nodes = new List<NodeModel>();
        var links = new List<LinkModel>();

        /*loading nodes and links from database to above structures*/
        //...

        _routineDiagram = diagram;
        diagram.LayoutCompleted += LoadLinkRoutes;
        _routineDiagram.PartManager.UpdatesRouteDataPoints = false;

        //add readed nodes to nodes source
        foreach (var node in nodes)
        {
            Nodes.Add(node);
        }

        //add readed nodes to links source
        foreach (var link in links)
        {
            Links.Add(link);
        }
    }

    private void LoadLinkRoutes(object sender, DiagramEventArgs e)
    {
        _routineDiagram.LayoutCompleted -= LoadLinkRoutes;

        foreach (var link in _routineDiagram.Links)
        {
            var linkModel = link.Data as LinkModel;
            if (linkModel != null)
            {
                link.Route.Points = linkModel.Points?.ToList();
            }
        }
        _routineDiagram.PartManager.UpdatesRouteDataPoints = true;
    }

LoadXml method works fine (example copied from goXam “Logic Circuit” demo), but when I want to add links manually (LoadDB method) routing points are being reset to default. Below picture shows both results.

Could You explain me what I’m doing wrong?
Thanks in advance.

What are the types for “Nodes” and for “Links”, and where are they defined?

Is your LoadLinkRoutes method actually called after the (initial) layout has completed? I’m wondering if you need to conduct your changes to “Nodes” and to “Links” in a transaction.

Did you debug the value of linkModel.Points?.ToList() to make sure it was returning the correct sequence of Points?

Thank you for quick response.

  1. Link and nodes are ObservableCollections:

     public ObservableCollection<LinkModel> Links { get; } = new ObservableCollection<LinkModel>();
     public ObservableCollection<NodeModel> Nodes { get; } = new ObservableCollection<NodeModel>();
    

And model classes:

public class GoXamRoutingDiagramModel : GraphLinksModel<NodeModel, string, string, LinkModel>
{
}

public class NodeModel : GraphLinksModelNodeData<string>
{
    //...
}

public class LinkModel : GraphLinksModelLinkData<string, string>
{
    //...
}
  1. I attached my custom PartManager to diagram override method OnModelChange. Below is the list of operations:

    LoadXML:

    1. StartedTransaction: Load
    2. ChangedNodesSource: …
    3. ChangedLinksSource: …
    4. CommitedTransaction: Load
    5. StartedTransaction: Layout
    6. CommitedTransaction: Layout
    7. LoadLinkRoutes(…)

    LoadDB:

    1. AddedNode: …
    2. AddedNode: …
    3. AddedLink: …
    4. AddedLink: …

On LoadDB LoadLinkRoutes is never called. If I call this method manually - nothing changes.

  1. Yes, i checked if linkModel.Points returns correct collection of points - it does.

Here is whole prototype application with above code: https://drive.google.com/open?id=0B8JGhAhN4Sq5YURYS0dmeHcxRk0

Are you making all these changes in a transaction?

Indeed, closing add link operations in transaction solved the problem. Seems to works the same as LoadXml function. Many thanks for your help. I made:

        Model.StartTransaction("xxx");
        foreach (var node in nodes)
            Nodes.Add(node);
        foreach (var link in links)
            Links.Add(link);
        Model.CommitTransaction("xxx");

and moved assignation of routing points to PartManager:

public class CustomPartManager : PartManager
{
    public override void OnModelChanged(ModelChangedEventArgs e)
    {
        base.OnModelChanged(e);

        if (e.Change == ModelChange.StartedTransaction && ((string)e.Data).Equals("xxx"))
        {
            UpdatesRouteDataPoints = false;
            Diagram.LayoutCompleted += OnLayoutCompleted;
        }
    }

    private void OnLayoutCompleted(object sender, DiagramEventArgs e)
    {
        Diagram.LayoutCompleted -= OnLayoutCompleted;

        foreach (var link in Diagram.Links)
        {
            var linkModel = link.Data as LinkModel;
            if (linkModel != null)
            {
                link.Route.Points = linkModel.Points?.ToList();
            }
        }
        UpdatesRouteDataPoints = true;
    }
}

But I’ve encounteder another problem that seems to be even in LoadXML method. When I put node on negative position (X=-30, Y=-30) and link it to another node, after loading links from XML all of them are reset to default routing. For a fraction of second everything seems to be OK, view is being moved to show left upper corner and then suddenly links are rerouted to default. Could you tell what me what is wrong?

So you have a Binding on Node.Location? And had you updated the linkModel.Points for each connected Link to properly connect with the moved node?

I’m surprised that using negative coordinates would make any difference. What about if X=-30 and Y=10, or X=10 and Y=-30?

Sorry, I wasn’t clear at this point. I’m loading XML file with nodes (some of them are on “minus” coordinates (eg. X=10, Y-30)) and links with specified routing points. Something like that:

`



















`

As it can be seen, Node 2 has location (-52, -202) and there are links with specified routing points. After loading this file on empty diagram, problem occures.

Image can say more than thousand words - so please take a look at those movies:

OK: https://drive.google.com/open?id=0B8JGhAhN4Sq5Y1Q1NjVVOUpPYjA
FAIL: https://drive.google.com/open?id=0B8JGhAhN4Sq5OGZkbzJQc2x3VEE

I’m sorry, but there’s no way for me to know what the difference is between those two cases.

Typically the problem is caused by the size or position of the Node changing, causing connected Links to be re-routed.