Ignore:
Timestamp:
05/04/16 15:15:10 (4 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • added layout algorithm prototype
  • fixed bug in LoadVisualProperties methods
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.cs

    r13799 r13833  
    6565      base.OnContentChanged();
    6666      UpdateContent();
     67      if (Content != null)
     68        LayoutNodes(Content.Nodes);
    6769      chartControl.Tag = Content;
    6870    }
     
    132134      chartControl.SuspendRendering();
    133135      try {
     136        foreach (var r in primitiveDict.Values.OfType<NodeRectangle>())
     137          r.NetworkItem = null;
     138        primitiveDict.Clear();
    134139        chartControl.Chart.Group.Clear();
    135140        DrawNodes(Content.Nodes);
     
    174179      }
    175180    }
     181
     182    private void LayoutNodes(IKeyedItemCollection<string, INode> nodes) {
     183      var layout = new Layout();
     184      var layoutNodes = new Dictionary<string, Layout.LayoutNode>();
     185
     186      foreach (var node in nodes) {
     187        var nodeRectangle = primitiveDict[node.Name] as NodeRectangle;
     188        if (nodeRectangle == null) continue;
     189
     190        var nodeSize = chartControl.Chart.TransformWorldToPixel(nodeRectangle.Size);
     191        Layout.LayoutNode layoutNode;
     192        if (!layoutNodes.TryGetValue(node.Name, out layoutNode)) {
     193          layoutNodes.Add(node.Name, layoutNode = new Layout.LayoutNode(nodeSize));
     194          layout.AddNode(layoutNode);
     195        }
     196
     197        foreach (var port in node.Ports.OfType<IConnectablePort>()) {
     198          var connectedPort = port.ConnectedPort as IConnectablePort;
     199          if (connectedPort == null) continue;
     200
     201          var connectedNode = connectedPort.Parent;
     202          if (connectedNode == null) continue;
     203
     204          var connectedRectangle = primitiveDict[connectedNode.Name] as NodeRectangle;
     205          if (connectedRectangle == null) continue;
     206
     207          nodeSize = chartControl.Chart.TransformWorldToPixel(connectedRectangle.Size);
     208          if (!layoutNodes.ContainsKey(connectedNode.Name)) {
     209            layoutNodes.Add(connectedNode.Name, new Layout.LayoutNode(nodeSize));
     210            layout.AddNode(layoutNodes[connectedNode.Name]);
     211          }
     212
     213          layoutNode.AddNode(layoutNodes[connectedNode.Name]);
     214        }
     215      }
     216
     217      var bounds = chartControl.GetPictureBounds();
     218      bounds.Offset((int)chartControl.Chart.LowerLeft.X, -(int)chartControl.Chart.UpperRight.Y);
     219
     220      layout.Arrange(bounds);
     221
     222      foreach (var entry in layoutNodes) {
     223        var nodeRectangle = primitiveDict[entry.Key] as NodeRectangle;
     224        if (nodeRectangle == null) continue;
     225        var rectangleNode = entry.Value;
     226        nodeRectangle.Move(rectangleNode.Location - nodeRectangle.Center());
     227      }
     228    }
    176229    #endregion
    177230  }
Note: See TracChangeset for help on using the changeset viewer.