Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13839


Ignore:
Timestamp:
05/09/16 13:55:42 (9 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • added layout calculation for ports
File:
1 edited

Legend:

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

    r13833 r13839  
    2424using System.Linq;
    2525using HeuristicLab.Collections;
    26 using HeuristicLab.Core;
    2726using HeuristicLab.Core.Networks;
    2827using HeuristicLab.Core.Networks.Views;
     
    6463    protected override void OnContentChanged() {
    6564      base.OnContentChanged();
    66       UpdateContent();
    67       if (Content != null)
    68         LayoutNodes(Content.Nodes);
     65      bool doLayout = Content != null && Content.Nodes.Any(x => x.VisualProperties == null);
     66      UpdateContent();
     67      if (doLayout) {
     68        LayoutNodes();
     69        LayoutPorts();
     70      }
    6971      chartControl.Tag = Content;
    7072    }
     
    138140        primitiveDict.Clear();
    139141        chartControl.Chart.Group.Clear();
    140         DrawNodes(Content.Nodes);
    141         ConnectNodes(Content.Nodes);
     142        DrawNodes();
     143        ConnectNodes();
    142144      } finally {
    143145        chartControl.ResumeRendering();
     
    145147    }
    146148
    147     private void DrawNodes(IKeyedItemCollection<string, INode> nodes) {
    148       foreach (var node in nodes) {
     149    private void DrawNodes() {
     150      foreach (var node in Content.Nodes) {
    149151        var defaultPrimitive = PrimitiveAttribute.CreateDefaultPrimitive(node.GetType(), chartControl.Chart, node);
    150152        if (defaultPrimitive == null) continue;
     
    154156    }
    155157
    156     private void ConnectNodes(IKeyedItemCollection<string, INode> nodes) {
    157       var chart = chartControl.Chart;
    158       foreach (var node in nodes) {
     158    private void ConnectNodes() {
     159      foreach (var node in Content.Nodes) {
    159160        var nodeRectangle = primitiveDict[node.Name] as NodeRectangle;
    160161        if (nodeRectangle == null) continue;
     
    173174          var rightPortRectangle = (PortRectangle)connectedRectangle.GetPortPrimitive(connectedPort);
    174175
    175           var connectionShape = new ConnectionLine(chart, leftPortRectangle, rightPortRectangle);
    176 
    177           chart.Group.Add(connectionShape);
    178         }
    179       }
    180     }
    181 
    182     private void LayoutNodes(IKeyedItemCollection<string, INode> nodes) {
     176          var connectionShape = new ConnectionLine(chartControl.Chart, leftPortRectangle, rightPortRectangle);
     177
     178          chartControl.Chart.Group.Add(connectionShape);
     179        }
     180      }
     181    }
     182
     183    private void LayoutNodes() {
    183184      var layout = new Layout();
    184185      var layoutNodes = new Dictionary<string, Layout.LayoutNode>();
    185186
    186       foreach (var node in nodes) {
     187      foreach (var node in Content.Nodes) {
    187188        var nodeRectangle = primitiveDict[node.Name] as NodeRectangle;
    188189        if (nodeRectangle == null) continue;
     
    227228      }
    228229    }
     230
     231    private void LayoutPorts() {
     232      foreach (var node in Content.Nodes) {
     233        var nodeRectangle = primitiveDict[node.Name] as NodeRectangle;
     234        if (nodeRectangle == null) continue;
     235
     236        foreach (var port in node.Ports.OfType<IConnectablePort>()) {
     237          var connectedPort = port.ConnectedPort as IConnectablePort;
     238          if (connectedPort == null) continue;
     239
     240          var connectedNode = connectedPort.Parent;
     241          if (connectedNode == null) continue;
     242
     243          var connectedRectangle = primitiveDict[connectedNode.Name] as NodeRectangle;
     244          if (connectedRectangle == null) continue;
     245
     246          var leftCenter = nodeRectangle.Center();
     247          var rightCenter = connectedRectangle.Center();
     248          var line = new Line(null, rightCenter, leftCenter);
     249
     250          var leftIntersection = nodeRectangle.ComputeIntersect(line).Single();
     251          var rightIntersection = connectedRectangle.ComputeIntersect(line).Single();
     252
     253          var leftPortRectangle = (PortRectangle)nodeRectangle.GetPortPrimitive(port);
     254          leftPortRectangle.SetPosition(leftIntersection);
     255          var rightPortRectangle = (PortRectangle)connectedRectangle.GetPortPrimitive(connectedPort);
     256          rightPortRectangle.SetPosition(rightIntersection);
     257        }
     258      }
     259    }
    229260    #endregion
    230261  }
Note: See TracChangeset for help on using the changeset viewer.