Changeset 13833


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

#2205: worked on optimization networks

  • added layout algorithm prototype
  • fixed bug in LoadVisualProperties methods
Location:
branches/OptimizationNetworks
Files:
1 added
6 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  }
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/HeuristicLab.Networks.Views.NetworkVisualization-3.3.csproj

    r13799 r13833  
    113113    <Compile Include="INodeVisualProperties.cs" />
    114114    <Compile Include="IPortVisualProperties.cs" />
     115    <Compile Include="Layout.cs" />
    115116    <Compile Include="NodeVisualProperties.cs" />
    116117    <Compile Include="Orientation.cs" />
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/AlgorithmNodeRectangle.cs

    r13799 r13833  
    3030    protected readonly Brush ActiveBrush = new SolidBrush(Color.FromArgb(255, 100, 200, 100));
    3131
     32    public new IAlgorithmNode NetworkItem {
     33      get { return (IAlgorithmNode)base.NetworkItem; }
     34      set { base.NetworkItem = value; }
     35    }
     36
    3237    public AlgorithmNodeRectangle(IChart chart, IAlgorithmNode node)
    3338      : base(chart, node) {
    3439      Brush = InactiveBrush;
    35       node.Algorithm.Started += (sender, args) => Brush = ActiveBrush;
    36       node.Algorithm.Stopped += (sender, args) => Brush = InactiveBrush;
    37       node.StartedAlgorithmsChanged += (sender, args) => Brush = ((IAlgorithmNode)sender).StartedAlgorithms.Any() ? ActiveBrush : InactiveBrush;
    3840    }
     41
     42    protected override void RegisterNetworkItemEvents() {
     43      base.RegisterNetworkItemEvents();
     44      NetworkItem.StartedAlgorithmsChanged += NetworkItem_StartedAlgorithmsChanged;
     45      if (NetworkItem.Algorithm != null) {
     46        NetworkItem.Algorithm.Started += Algorithm_Started; ;
     47        NetworkItem.Algorithm.Stopped += Algorithm_Stopped; ;
     48      }
     49    }
     50
     51    protected override void DeregisterNetworkItemEvents() {
     52      if (NetworkItem.Algorithm != null) {
     53        NetworkItem.Algorithm.Stopped -= Algorithm_Stopped; ;
     54        NetworkItem.Algorithm.Started -= Algorithm_Started; ;
     55      }
     56      NetworkItem.StartedAlgorithmsChanged -= NetworkItem_StartedAlgorithmsChanged;
     57      base.DeregisterNetworkItemEvents();
     58    }
     59
     60    private void NetworkItem_StartedAlgorithmsChanged(object sender, System.EventArgs e) {
     61      Brush = ((IAlgorithmNode)sender).StartedAlgorithms.Any() ? ActiveBrush : InactiveBrush;
     62    }
     63    private void Algorithm_Started(object sender, System.EventArgs e) { Brush = ActiveBrush; }
     64    private void Algorithm_Stopped(object sender, System.EventArgs e) { Brush = InactiveBrush; }
    3965  }
    4066}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/MessagePortRectangle.cs

    r13799 r13833  
    3939    public MessagePortRectangle(IChart chart, IMessagePort port, INode node)
    4040      : base(chart, port, node) {
    41       IdleBrush = new SolidBrush(VisualProperties.BrushColor);
    42       port.MessageSent += (sender, args) => Highlight(MessageSentBrush);
    43       port.MessageReceived += (sender, args) => Highlight(MessageReceivedBrush);
     41      IdleBrush = Brush;
     42    }
     43
     44    protected override void RegisterNetworkItemEvents() {
     45      base.RegisterNetworkItemEvents();
     46      NetworkItem.MessageSent += NetworkItem_MessageSent;
     47      NetworkItem.MessageReceived += Port_MessageReceived;
     48    }
     49
     50    protected override void DeregisterNetworkItemEvents() {
     51      NetworkItem.MessageReceived -= Port_MessageReceived;
     52      NetworkItem.MessageSent -= NetworkItem_MessageSent;
     53      base.DeregisterNetworkItemEvents();
     54    }
     55
     56    private void Port_MessageReceived(object sender, Common.EventArgs<IMessage, System.Threading.CancellationToken> e) {
     57      Highlight(MessageReceivedBrush);
     58    }
     59
     60
     61    private void NetworkItem_MessageSent(object sender, Common.EventArgs<IMessage, System.Threading.CancellationToken> e) {
     62      Highlight(MessageSentBrush);
    4463    }
    4564
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/NodeRectangle.cs

    r13799 r13833  
    255255    #region Helpers
    256256    private void LoadVisualProperties() {
    257       if (VisualProperties == null)
    258         VisualProperties = new NodeVisualProperties();
    259 
    260       var vp = VisualProperties;
     257      INodeVisualProperties vp = new NodeVisualProperties();
     258
     259      if (networkItem != null)
     260        if (VisualProperties == null) VisualProperties = vp;
     261        else vp = VisualProperties;
     262
    261263      IgnoreVisualPropertiesChanges = true;
    262264      try {
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/PortRectangle.cs

    r13799 r13833  
    205205    #region Helpers
    206206    private void LoadVisualProperties() {
    207       if (VisualProperties == null)
    208         VisualProperties = new PortVisualProperties();
    209 
    210       var vp = VisualProperties;
     207      IPortVisualProperties vp = new PortVisualProperties();
     208
     209      if (networkItem != null)
     210        if (VisualProperties == null) VisualProperties = vp;
     211        else vp = VisualProperties;
     212
    211213      IgnoreVisualPropertiesChanges = true;
    212214      try {
Note: See TracChangeset for help on using the changeset viewer.