Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13135


Ignore:
Timestamp:
11/11/15 13:53:10 (9 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • refactored network visualization
Location:
branches/OptimizationNetworks
Files:
7 added
7 deleted
18 edited

Legend:

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

    r13077 r13135  
    2424using System.Drawing.Drawing2D;
    2525using System.Windows.Forms;
     26using HeuristicLab.Common;
    2627using HeuristicLab.Common.Resources;
    2728using HeuristicLab.Core.Networks;
     
    3637
    3738    public override Image Image { get { return VSImageLibrary.RadialChart; } }
    38     public override string ToolTip { get { return "Add Nodes"; } }
     39    public override string Text { get { return "Add &Nodes"; } }
     40    public override string ToolTipText { get { return "Add Nodes"; } }
    3941
    4042    public AddNodesChartMode(ChartControl control) : base(control) { }
    4143
    4244    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
    43       base.HandleOnMouseMove(sender, e);
     45      try {
     46        if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    4447
    45       if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    46 
    47       try {
    48         chartControl.PictureBox.Refresh();
     48        chartControl.RefreshPicture();
    4949
    5050        var size = new Size(200, 100);
    51         using (var graphics = chartControl.PictureBox.CreateGraphics())
     51
     52        using (var graphics = chartControl.CreatePictureGraphics())
    5253        using (var pen = new Pen(Color.Gray) { DashStyle = DashStyle.Dash }) {
    5354          graphics.DrawRectangle(pen,
     
    5758            size.Height);
    5859        }
     60
    5961      } finally {
    60         chartControl.PictureBox.Update();
     62        chartControl.UpdatePicture();
     63        base.HandleOnMouseMove(sender, e);
    6164      }
    6265    }
    6366
    64     public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    65       base.HandleOnMouseUp(sender, e);
     67    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
     68      try {
     69        switch (e.Button) {
     70          case MouseButtons.Left:
     71            var network = chartControl.Tag as IUserDefinedNetwork;
     72            if (network == null) return;
    6673
    67       switch (e.Button) {
    68         case MouseButtons.Left:
    69           var network = chartControl.Tag as IUserDefinedNetwork;
    70           if (network == null) return;
     74            var node = CreateNode(network);
     75            if (node == null) return;
    7176
    72           var node = CreateNode(network);
    73           var visualizableNode = node as IVisualizableNode;
    74           if (visualizableNode == null) return;
     77            var center = chartControl.Chart.TransformPixelToWorld(e.Location);
     78            var size = chartControl.Chart.TransformPixelToWorld(new Size(100, 50));
     79            var lowerLeft = center - new Offset(size);
     80            var upperRight = center + new Offset(size);
     81            node.VisualProperties = new NodeVisualProperties(new Point2D<double>(lowerLeft.X, lowerLeft.Y),
     82                                                             new Point2D<double>(upperRight.X, upperRight.Y));
     83            network.Nodes.Add(node);
     84            break;
     85        }
     86      } finally {
     87        base.HandleOnMouseDown(sender, e);
     88      }
     89    }
    7590
    76           var center = chartControl.Chart.TransformPixelToWorld(e.Location);
    77           var size = chartControl.Chart.TransformPixelToWorld(new Size(200, 100));
    78 
    79           visualizableNode.VisualProperties.X = center.X;
    80           visualizableNode.VisualProperties.Y = center.Y;
    81           visualizableNode.VisualProperties.Width = size.Width;
    82           visualizableNode.VisualProperties.Height = size.Height;
    83 
    84           network.Nodes.Add(node);
    85           break;
    86       }
     91    public override void HandleOnMouseLeave(object sender, EventArgs e) {
     92      chartControl.RefreshPicture();
     93      base.HandleOnMouseLeave(sender, e);
    8794    }
    8895
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/AddPortsChartMode.cs

    r13077 r13135  
    3636
    3737    public override Image Image { get { return VSImageLibrary.Interface; } }
    38     public override string ToolTip { get { return "Add Ports"; } }
     38    public override string Text { get { return "Add Por&ts"; } }
     39    public override string ToolTipText { get { return "Add Ports"; } }
    3940
    4041    public AddPortsChartMode(ChartControl control) : base(control) { }
    4142
    4243    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
    43       base.HandleOnMouseMove(sender, e);
     44      try {
     45        if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    4446
    45       if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    46 
    47       try {
    48         chartControl.PictureBox.Refresh();
     47        chartControl.RefreshPicture();
    4948
    5049        var nodeRectangles = chartControl.Chart.GetAllPrimitives(e.Location).OfType<NodeRectangle>();
     
    5655        var ur = chartControl.Chart.TransformWorldToPixel(nodeRectangle.UpperRight);
    5756
    58         using (var graphics = chartControl.PictureBox.CreateGraphics())
    59         using (var pen = new Pen(Color.Green) { Width = 2f }) {
     57        var node = nodeRectangle.NetworkItem;
     58        bool nodeValid = node is IAlgorithmNode || node is IUserDefinedNode;
     59
     60        using (var graphics = chartControl.CreatePictureGraphics())
     61        using (var pen = new Pen(nodeValid ? Color.Green : Color.Red) { Width = 2f }) {
    6062          graphics.DrawRectangle(pen,
    6163            ll.X,
     
    6567        }
    6668      } finally {
    67         chartControl.PictureBox.Update();
     69        chartControl.UpdatePicture();
     70        base.HandleOnMouseMove(sender, e);
    6871      }
    6972    }
    7073
    71     public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    72       base.HandleOnMouseUp(sender, e);
     74    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
     75      try {
     76        switch (e.Button) {
     77          case MouseButtons.Left:
     78            if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    7379
    74       switch (e.Button) {
    75         case MouseButtons.Left:
    76           var network = chartControl.Tag as IUserDefinedNetwork;
    77           if (network == null) return;
     80            var nodeRectangles = chartControl.Chart.GetAllPrimitives(e.Location).OfType<NodeRectangle>();
     81            var nodeRectangle = nodeRectangles.FirstOrDefault();
     82            if (nodeRectangle == null) return;
    7883
    79           var nodeRectangles = chartControl.Chart.GetAllPrimitives(e.Location).OfType<NodeRectangle>();
    80           var nodeRectangle = nodeRectangles.FirstOrDefault();
    81           if (nodeRectangle == null) return;
     84            var node = nodeRectangle.NetworkItem;
     85            bool nodeValid = node is IAlgorithmNode || node is IUserDefinedNode;
     86            if (!nodeValid) return;
    8287
    83           var node = nodeRectangle.NetworkItem;
    84           var port = CreatePort(node);
     88            var port = CreatePort(node);
     89            if (port == null) return;
    8590
    86           var algNode = node as IAlgorithmNode;
    87           if (algNode != null) {
    88             algNode.Ports.Add(port);
    89             return;
    90           }
     91            var algNode = node as IAlgorithmNode;
     92            if (algNode != null) {
     93              algNode.Ports.Add(port);
     94              return;
     95            }
    9196
    92           var userDefNode = node as IUserDefinedNode;
    93           if (userDefNode != null) {
     97            var userDefNode = (IUserDefinedNode)node;
    9498            userDefNode.Ports.Add(port);
    95             return;
    96           }
    97           break;
     99            break;
     100        }
     101      } finally {
     102        base.HandleOnMouseDown(sender, e);
    98103      }
    99104    }
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/ConnectPortsChartMode.cs

    r13077 r13135  
    3535
    3636    public override Image Image { get { return VSImageLibrary.OrgChart; } }
    37     public override string ToolTip { get { return "Connect Ports"; } }
     37    public override string Text { get { return "&Connect Ports"; } }
     38    public override string ToolTipText { get { return "Connect Ports"; } }
    3839
    3940    public ConnectPortsChartMode(ChartControl control) : base(control) { }
    4041
    41     public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
    42       base.HandleOnMouseDown(sender, e);
     42    public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
     43      try {
     44        if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    4345
    44       if (!(chartControl.Tag is IUserDefinedNetwork)) return;
     46        chartControl.RefreshPicture();
    4547
    46       switch (e.Button) {
    47         case MouseButtons.Left:
    48           var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
    49           var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>();
    50           var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortRectangle));
    51           startPortRectangle = portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation));
    52           break;
     48        var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
     49        var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>();
     50        var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive));
     51        var currentPortRectangle = (PortRectangle)portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation));
     52
     53        // TODO: highlight allowed port connections only
     54
     55        using (var graphics = chartControl.CreatePictureGraphics()) {
     56          Point startLocation = Point.Empty;
     57          if (startPortRectangle != null) {
     58            DrawCircleAroundPortRectangle(graphics, startPortRectangle, startPortRectangle.NetworkItem is IConnectablePort);
     59            startLocation = chartControl.Chart.TransformWorldToPixel(startPortRectangle.Point);
     60          }
     61
     62          Point endLocation = e.Location;
     63          if (currentPortRectangle != null && (startPortRectangle != null || e.Button == MouseButtons.None)) {
     64            DrawCircleAroundPortRectangle(graphics, currentPortRectangle, currentPortRectangle.NetworkItem is IConnectablePort);
     65            endLocation = chartControl.Chart.TransformWorldToPixel(currentPortRectangle.Point);
     66          }
     67
     68          bool connectionValid = startPortRectangle != null && startPortRectangle.NetworkItem is IConnectablePort;
     69          connectionValid &= currentPortRectangle == null || currentPortRectangle.NetworkItem is IConnectablePort;
     70
     71          if (startPortRectangle != null)
     72            DrawLineBetweenLocations(graphics, startLocation, endLocation, connectionValid);
     73        }
     74      } finally {
     75        chartControl.UpdatePicture();
     76        base.HandleOnMouseMove(sender, e);
    5377      }
    5478    }
    5579
    56     public override void HandleOnMouseMove(object sender, MouseEventArgs e) {
    57       base.HandleOnMouseMove(sender, e);
     80    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
     81      try {
     82        var network = chartControl.Tag as IUserDefinedNetwork;
     83        if (network == null) return;
    5884
    59       if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    60 
    61       try {
    62         chartControl.PictureBox.Refresh();
    63 
    64         var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
    65         var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>();
    66         var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortRectangle)).ToList();
    67         var currentPortRectangle = portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation));
    68 
    69         // TODO: highlight allowed port connections only
    70 
    71         Point startLocation = Point.Empty;
    72         if (startPortRectangle != null) {
    73           DrawCircleAroundPortRectangle(startPortRectangle);
    74           startLocation = chartControl.Chart.TransformWorldToPixel(startPortRectangle.Point);
     85        switch (e.Button) {
     86          case MouseButtons.Left:
     87            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
     88            var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>();
     89            var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive));
     90            startPortRectangle = (PortRectangle)portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation));
     91            break;
    7592        }
    76 
    77         Point endLocation = e.Location;
    78         if (currentPortRectangle != null) {
    79           DrawCircleAroundPortRectangle(currentPortRectangle);
    80           endLocation = chartControl.Chart.TransformWorldToPixel(currentPortRectangle.Point);
    81         }
    82 
    83         if (startPortRectangle != null)
    84           DrawLineBetweenLocations(startLocation, endLocation);
    8593      } finally {
    86         chartControl.PictureBox.Update();
     94        base.HandleOnMouseDown(sender, e);
    8795      }
    8896    }
    8997
    9098    public override void HandleOnMouseUp(object sender, MouseEventArgs e) {
    91       base.HandleOnMouseUp(sender, e);
     99      try {
     100        var network = chartControl.Tag as IUserDefinedNetwork;
     101        if (network == null) return;
    92102
    93       if (!(chartControl.Tag is IUserDefinedNetwork)) return;
     103        switch (e.Button) {
     104          case MouseButtons.Left:
     105            var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
     106            var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>();
     107            var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive));
     108            endPortRectangle = (PortRectangle)portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation));
    94109
    95       switch (e.Button) {
    96         case MouseButtons.Left:
    97           var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
    98           var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>();
    99           var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortRectangle)).ToList();
    100           endPortRectangle = portRectangles.FirstOrDefault(x => x.ContainsPoint(worldLocation));
     110            if (startPortRectangle == endPortRectangle || startPortRectangle == null || endPortRectangle == null) {
     111              startPortRectangle = null;
     112              endPortRectangle = null;
     113              return;
     114            }
    101115
    102           if (startPortRectangle == endPortRectangle && startPortRectangle == null || endPortRectangle == null) {
     116            var startPort = (IConnectablePort)startPortRectangle.NetworkItem;
     117            var endPort = (IConnectablePort)endPortRectangle.NetworkItem;
     118
     119            // TODO: check if port connection is allowed
     120
     121            startPort.ConnectedPort = endPort;
     122
    103123            startPortRectangle = null;
    104124            endPortRectangle = null;
    105             return;
    106           }
    107 
    108           var startPort = (IConnectablePort)startPortRectangle.NetworkItem;
    109           var endPort = (IConnectablePort)endPortRectangle.NetworkItem;
    110 
    111           // TODO: check if port connection is allowed
    112 
    113           startPort.ConnectedPort = endPort;
    114 
    115           startPortRectangle = null;
    116           endPortRectangle = null;
    117           break;
     125            break;
     126        }
     127      } finally {
     128        base.HandleOnMouseUp(sender, e);
    118129      }
    119130    }
    120131
    121     protected virtual void DrawCircleAroundPortRectangle(PortRectangle portRectangle) {
     132    #region Helpers
     133    protected virtual void DrawCircleAroundPortRectangle(Graphics graphics, PortRectangle portRectangle, bool valid) {
    122134      var centerP = chartControl.Chart.TransformWorldToPixel(portRectangle.Point);
    123135      int a = (int)Math.Round(portRectangle.Size.Width / 2.0 * Math.Sqrt(2));
    124136      int b = (int)Math.Round(portRectangle.Size.Height / 2.0 * Math.Sqrt(2));
    125137
    126       using (var graphics = chartControl.PictureBox.CreateGraphics())
    127       using (var pen = new Pen(Color.Green) { Width = 2f }) {
     138      using (var pen = new Pen(valid ? Color.Green : Color.Red) { Width = 2f }) {
    128139        graphics.DrawEllipse(pen,
    129140          centerP.X - a,
     
    134145    }
    135146
    136     protected virtual void DrawLineBetweenLocations(Point startLocation, Point endLocation) {
    137       using (var graphics = chartControl.PictureBox.CreateGraphics())
    138       using (var pen = new Pen(Color.Green) { DashStyle = DashStyle.Dash, Width = 2f })
     147    protected virtual void DrawLineBetweenLocations(Graphics graphics, Point startLocation, Point endLocation, bool valid) {
     148      using (var pen = new Pen(valid ? Color.Green : Color.Red) { DashStyle = DashStyle.Dash, Width = 2f })
    139149        graphics.DrawLine(pen, startLocation.X, startLocation.Y, endLocation.X, endLocation.Y);
    140150    }
     151    #endregion
    141152  }
    142153}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/HeuristicLab.Networks.Views.NetworkVisualization.Views-3.3.csproj

    r13077 r13135  
    120120    <Compile Include="ChartModes\AddNodesChartMode.cs" />
    121121    <Compile Include="ChartModes\AddPortsChartMode.cs" />
    122     <Compile Include="ChartModes\NetworkSelectChartMode.cs" />
     122    <Compile Include="ChartModes\SelectChartMode.cs" />
    123123    <Compile Include="ChartModes\ConnectPortsChartMode.cs" />
    124124    <Compile Include="NetworkVisualizationView.cs">
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.cs

    r13077 r13135  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Linq;
    2324using HeuristicLab.Collections;
     
    2829using HeuristicLab.Networks.Views.NetworkVisualization.Views.ChartModes;
    2930using HeuristicLab.Visualization;
     31using HeuristicLab.Visualization.ChartModes;
    3032
    3133namespace HeuristicLab.Networks.Views.NetworkVisualization.Views {
     
    3436  [Content(typeof(INetwork), false)]
    3537  public partial class NetworkVisualizationView : NetworkItemView {
     38    private Dictionary<string, IPrimitive> primitiveDict = new Dictionary<string, IPrimitive>();
     39
    3640    public new INetwork Content {
    3741      get { return (INetwork)base.Content; }
     
    4246      InitializeComponent();
    4347
    44       var initialMode = new NetworkSelectChartMode(chartControl);
     48      var initialMode = new SelectChartMode(chartControl);
    4549      chartControl.AddChartModes(
    4650        initialMode,
    47         new MoveChartMode(chartControl),
     51        new PanChartMode(chartControl),
     52        new RulerChartMode(chartControl),
    4853        new ZoomInChartMode(chartControl),
    4954        new ZoomOutChartMode(chartControl),
     
    8186    }
    8287
    83     private void UpdateContent() {
    84       if (Content == null) return;
    85 
    86       chartControl.Chart.Group.Clear();
    87       DrawNodes(Content.Nodes);
    88       ConnectNodes(Content.Nodes);
    89     }
    90 
    91     private void DrawNodes(IKeyedItemCollection<string, INode> nodes) {
    92       var chart = chartControl.Chart;
    93 
    94       foreach (var node in nodes.OfType<IVisualizableNode>()) {
    95         var nodeShape = new NodeRectangle(chart, node);
    96         chart.Group.Add(nodeShape);
    97       }
    98     }
    99 
    100     private void ConnectNodes(IKeyedItemCollection<string, INode> nodes) {
    101       var chart = chartControl.Chart;
    102       var nodeRectangles = chart.Group.Primitives.OfType<NodeRectangle>();
    103       var node2NodeShape = nodeRectangles.ToDictionary(k => k.NetworkItem.Name, v => v);
    104 
    105       foreach (var node in nodes) {
    106         var nodeShape = node2NodeShape[node.Name];
    107         foreach (var port in node.Ports.OfType<IConnectablePort>()) {
    108           var connectedPort = port.ConnectedPort as IConnectablePort;
    109           if (connectedPort == null) continue;
    110 
    111           var connectedNode = connectedPort.Parent;
    112           if (connectedNode == null) continue;
    113 
    114           var connectedShape = node2NodeShape[connectedNode.Name];
    115           var leftPortRectangle = nodeShape.GetPortRectangle(port);
    116           var rightPortRectangle = connectedShape.GetPortRectangle(connectedPort);
    117 
    118           var connectionShape = new ConnectionLine(chart, leftPortRectangle, rightPortRectangle);
    119 
    120           chart.Group.Add(connectionShape);
    121         }
    122       }
    123     }
    124 
    12588    #region Event Handlers
    12689    #region Nodes Event Handlers
     
    149112    #endregion
    150113    #endregion
     114
     115    #region Helpers
     116    private void UpdateContent() {
     117      if (Content == null) return;
     118
     119      chartControl.SuspendRendering();
     120      try {
     121        chartControl.Chart.Group.Clear();
     122        DrawNodes(Content.Nodes);
     123        ConnectNodes(Content.Nodes);
     124      } finally {
     125        chartControl.ResumeRendering();
     126      }
     127    }
     128
     129    private void DrawNodes(IKeyedItemCollection<string, INode> nodes) {
     130      foreach (var node in nodes) {
     131        var defaultPrimitive = PrimitiveAttribute.CreateDefaultPrimitive(node.GetType(), chartControl.Chart, node);
     132        if (defaultPrimitive == null) continue;
     133        chartControl.Chart.Group.Add(defaultPrimitive);
     134        primitiveDict[node.Name] = defaultPrimitive;
     135      }
     136    }
     137
     138    private void ConnectNodes(IKeyedItemCollection<string, INode> nodes) {
     139      var chart = chartControl.Chart;
     140      foreach (var node in nodes) {
     141        var nodeRectangle = primitiveDict[node.Name] as NodeRectangle;
     142        if (nodeRectangle == null) continue;
     143
     144        foreach (var port in node.Ports.OfType<IConnectablePort>()) {
     145          var connectedPort = port.ConnectedPort as IConnectablePort;
     146          if (connectedPort == null) continue;
     147
     148          var connectedNode = connectedPort.Parent;
     149          if (connectedNode == null) continue;
     150
     151          var connectedRectangle = primitiveDict[connectedNode.Name] as NodeRectangle;
     152          if (connectedRectangle == null) continue;
     153
     154          var leftPortRectangle = (PortRectangle)nodeRectangle.GetPortPrimitive(port);
     155          var rightPortRectangle = (PortRectangle)connectedRectangle.GetPortPrimitive(connectedPort);
     156
     157          var connectionShape = new ConnectionLine(chart, leftPortRectangle, rightPortRectangle);
     158
     159          chart.Group.Add(connectionShape);
     160        }
     161      }
     162    }
     163    #endregion
    151164  }
    152165}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/HeuristicLab.Networks.Views.NetworkVisualization-3.3.csproj

    r13077 r13135  
    8686      <Private>False</Private>
    8787    </Reference>
     88    <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     89      <Private>False</Private>
     90    </Reference>
    8891    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    8992      <SpecificVersion>False</SpecificVersion>
     
    98101    <Reference Include="System.Core" />
    99102    <Reference Include="System.Drawing" />
    100     <Reference Include="System.Windows.Forms" />
    101     <Reference Include="System.Xml.Linq" />
    102     <Reference Include="System.Data.DataSetExtensions" />
    103     <Reference Include="System.Data" />
    104     <Reference Include="System.Net.Http" />
    105     <Reference Include="System.Xml" />
    106103  </ItemGroup>
    107104  <ItemGroup>
    108105    <Compile Include="Interfaces\INetworkItemPrimitive.cs" />
     106    <Compile Include="INodeVisualProperties.cs" />
     107    <Compile Include="IPortVisualProperties.cs" />
     108    <Compile Include="NodeVisualProperties.cs" />
     109    <Compile Include="Orientation.cs" />
     110    <Compile Include="PortVisualProperties.cs" />
    109111    <Compile Include="Primitives\ConnectionLine.cs" />
    110112    <Compile Include="Plugin.cs" />
     
    123125    </ProjectReference>
    124126  </ItemGroup>
     127  <ItemGroup />
    125128  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    126129  <PropertyGroup>
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/ConnectionLine.cs

    r13077 r13135  
    5959    protected virtual void RegisterPortRectangleEvents(PortRectangle portRectangle) {
    6060      portRectangle.RedrawRequired += PortRectangle_RedrawRequired;
    61       portRectangle.NetworkItemChanged += PortRectangleNetworkItemChanged;
    62       if (portRectangle.NetworkItem != null) {
    63         var port = portRectangle.NetworkItem;
    64         port.NameChanged += Port_NameChanged;
    65       }
    6661    }
    6762
    6863    protected virtual void DeregisterPortRectangleEvents(PortRectangle portRectangle) {
    6964      portRectangle.RedrawRequired -= PortRectangle_RedrawRequired;
    70       portRectangle.NetworkItemChanged -= PortRectangleNetworkItemChanged;
    71       if (portRectangle.NetworkItem != null) {
    72         var port = portRectangle.NetworkItem;
    73         port.NameChanged -= Port_NameChanged;
    74       }
    7565    }
    7666
     
    10595      }
    10696    }
    107 
    10897    #endregion
    10998
     
    111100    public event EventHandler StartPortRectangleChanged;
    112101    protected virtual void OnStartPortRectangleChanged() {
    113       UpdateToolTip();
    114102      var handler = StartPortRectangleChanged;
    115103      if (handler != null) handler(this, EventArgs.Empty);
     
    118106    public event EventHandler EndPortRectangleChanged;
    119107    protected virtual void OnEndPortRectangleChanged() {
    120       UpdateToolTip();
    121108      var handler = EndPortRectangleChanged;
    122109      if (handler != null) handler(this, EventArgs.Empty);
     
    128115      SetPosition(startPortRectangle.Point, endPortRectangle.Point);
    129116    }
    130 
    131     private void PortRectangleNetworkItemChanged(object sender, EventArgs e) {
    132       UpdateToolTip();
    133     }
    134 
    135     private void Port_NameChanged(object sender, EventArgs e) {
    136       UpdateToolTip();
    137     }
    138     #endregion
    139 
    140     #region Helpers
    141     private void UpdateToolTip() {
    142       string startText = "null", endText = "null";
    143 
    144       if (startPortRectangle != null) {
    145         var startPort = startPortRectangle.NetworkItem;
    146         if (startPort != null) {
    147           startText = startPort.Name;
    148           var startNode = startPort.Parent;
    149           startText = (startNode != null ? startNode.Name : "null") + "." + startText;
    150         }
    151       }
    152 
    153       if (endPortRectangle != null) {
    154         var endPort = endPortRectangle.NetworkItem;
    155         if (endPort != null) {
    156           endText = endPort.Name;
    157           var endNode = endPort.Parent;
    158           endText = (endNode != null ? endNode.Name : "null") + "." + endText;
    159         }
    160       }
    161 
    162       ToolTipText = string.Format("[{0}] --> [{1}]", startText, endText);
    163     }
    164117    #endregion
    165118  }
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/NodeRectangle.cs

    r13077 r13135  
    2323using System.Collections.Generic;
    2424using System.Drawing;
    25 using System.Linq;
     25using HeuristicLab.Common;
    2626using HeuristicLab.Core.Networks;
    2727using HeuristicLab.Visualization;
    2828
    2929namespace HeuristicLab.Networks.Views.NetworkVisualization {
    30   public class NodeRectangle : Visualization.Rectangle, INetworkItemPrimitive<IVisualizableNode> {
    31     private readonly Dictionary<IPort, PortRectangle> port2PortRectangle = new Dictionary<IPort, PortRectangle>();
    32 
    33     protected IGroup portRectangles;
     30  [Primitive(typeof(INode), true)]
     31  public class NodeRectangle : Visualization.Rectangle, INetworkItemPrimitive<INode> {
     32    protected readonly Dictionary<IPort, IPrimitive> port2primitive = new Dictionary<IPort, IPrimitive>();
     33    protected readonly IGroup portRectangles;
    3434
    3535    protected bool IgnoreVisualPropertiesChanges { get; set; }
    3636
    37     protected IVisualizableNode networkItem;
    38     public IVisualizableNode NetworkItem {
     37    protected INode networkItem;
     38    public INode NetworkItem {
    3939      get { return networkItem; }
    4040      set {
     
    4343        networkItem = value;
    4444        if (networkItem != null) RegisterNetworkItemEvents();
    45         UpdateToolTip();
    4645        LoadVisualProperties();
    4746        OnNetworkItemChanged();
     
    4948    }
    5049
    51     public NodeRectangle(IChart chart, IVisualizableNode node)
    52       : base(chart, Point.Empty, Point.Empty) {
     50    public NodeRectangle(IChart chart, INode node)
     51      : base(chart, PointD.Empty, PointD.Empty) {
    5352      NetworkItem = node;
    5453
    5554      portRectangles = new Group(chart);
    5655      foreach (var port in node.Ports) {
    57         var portRectangle = new PortRectangle(this, port);
    58         port2PortRectangle.Add(port, portRectangle);
    59         portRectangles.Add(portRectangle);
     56        var portPrimitive = PrimitiveAttribute.CreateDefaultPrimitive(port.GetType(), chart, port, node); // TODO: port.Parent != node
     57        port2primitive.Add(port, portPrimitive);
     58        portRectangles.Add(portPrimitive);
    6059      }
    61       UpdatePortRectangles();
    6260      portRectangles.RedrawRequired += (sender, args) => OnRedrawRequired();
    6361    }
    6462
    6563    protected virtual void RegisterNetworkItemEvents() {
    66       networkItem.NameChanged += NetworkItemNameChanged;
     64      networkItem.NameChanged += NetworkItem_NameChanged;
    6765      if (networkItem.VisualProperties != null) {
    6866        networkItem.VisualProperties.Changed += VisualProperties_Changed;
     
    7573
    7674    protected virtual void DeregisterNetworkItemEvents() {
    77       networkItem.NameChanged -= NetworkItemNameChanged;
     75      networkItem.NameChanged -= NetworkItem_NameChanged;
    7876      if (networkItem.VisualProperties != null) {
    7977        networkItem.VisualProperties.Changed -= VisualProperties_Changed;
     
    8785    #region Overrides
    8886    public override void SetPosition(PointD lowerLeft, PointD upperRight) {
    89       SuppressEvents = true;
    90       try {
    91         base.SetPosition(lowerLeft, upperRight);
    92         SaveVisualProperties();
    93         UpdatePortRectangles();
    94       } finally {
    95         SuppressEvents = false;
    96         OnRedrawRequired();
    97       }
     87      base.SetPosition(lowerLeft, upperRight);
     88      SaveVisualProperties();
    9889    }
    9990
     
    10394      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
    10495
    105       using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) {
    106         graphics.DrawString(ToolTipText, font, Brushes.Black, p.X + 5, p.Y + 5);
     96      if (networkItem != null) {
     97        using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) {
     98          graphics.DrawString(networkItem.Name, font, Brushes.Black, p.X + 5, p.Y + 5);
     99        }
    107100      }
    108101
     
    111104    #endregion
    112105
    113     public PortRectangle GetPortRectangle(IPort name) {
    114       PortRectangle portRectangle;
    115       port2PortRectangle.TryGetValue(name, out portRectangle);
    116       return portRectangle;
     106    public IPrimitive GetPortPrimitive(IPort name) {
     107      IPrimitive portPrimitive;
     108      port2primitive.TryGetValue(name, out portPrimitive);
     109      return portPrimitive;
    117110    }
    118111
     
    126119
    127120    #region Event Handlers
    128     private void NetworkItemNameChanged(object sender, EventArgs e) {
    129       UpdateToolTip();
    130     }
    131 
    132121    private void VisualProperties_Changed(object sender, EventArgs e) {
    133122      if (IgnoreVisualPropertiesChanges) return;
     123
    134124      LoadVisualProperties();
    135125    }
    136126
     127    private void NetworkItem_NameChanged(object sender, EventArgs e) { OnRedrawRequired(); }
     128
    137129    private void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
    138130      foreach (var port in e.Items) {
    139         var portRectangle = new PortRectangle(this, port);
    140         port2PortRectangle.Add(port, portRectangle);
     131        var portRectangle = PrimitiveAttribute.CreateDefaultPrimitive(port.GetType(), Chart, port, networkItem);
     132        port2primitive.Add(port, portRectangle);
    141133        portRectangles.Add(portRectangle);
    142134      }
    143135
    144       SuppressEvents = true;
    145       try {
    146         UpdatePortRectangles();
    147       } finally {
    148         SuppressEvents = false;
    149         OnRedrawRequired();
    150       }
     136      OnRedrawRequired();
    151137    }
    152138
    153139    private void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
    154140      foreach (var port in e.Items) {
    155         var portRectangle = port2PortRectangle[port];
    156         port2PortRectangle.Remove(port);
     141        var portRectangle = port2primitive[port];
     142        port2primitive.Remove(port);
    157143        portRectangles.Remove(portRectangle);
    158144      }
    159145
    160       UpdatePortRectangles();
    161146      OnRedrawRequired();
    162147    }
     
    164149
    165150    #region Helpers
    166     private void UpdateToolTip() {
    167       ToolTipText = networkItem.Name;
     151    private INodeVisualProperties CreateDefaultVisualProperties() {
     152      var offset = Chart.UpperRight - Chart.LowerLeft;
     153      var center = new PointD(Chart.LowerLeft.X + offset.DX * 0.5, Chart.LowerLeft.Y + offset.DY * 0.5);
     154      var size = Chart.TransformPixelToWorld(new Size(200, 100));
     155      var lowerLeft = center - new Offset(size.Width * 0.5, size.Height * 0.5);
     156      var upperRight = center + new Offset(size.Width * 0.5, size.Height * 0.5);
     157      return new NodeVisualProperties(new Point2D<double>(lowerLeft.X, lowerLeft.Y), new Point2D<double>(upperRight.X, upperRight.Y));
    168158    }
    169159
    170160    private void LoadVisualProperties() {
    171       var offset = Chart.UpperRight - Chart.LowerLeft;
    172       var center = new PointD(Chart.LowerLeft.X + offset.DX * 0.5, Chart.LowerLeft.Y + offset.DY * 0.5);
    173       var size = Chart.TransformPixelToWorld(new Size(200, 100));
     161      if (networkItem.VisualProperties == null)
     162        networkItem.VisualProperties = CreateDefaultVisualProperties();
    174163
    175       bool vpAvailable = networkItem != null && networkItem.VisualProperties != null;
    176       bool useDefaultLocation = !vpAvailable || double.IsNaN(networkItem.VisualProperties.X);
    177       bool useDefaultSize = !vpAvailable || double.IsNaN(networkItem.VisualProperties.Width);
    178 
    179       if (!useDefaultLocation) {
    180         center.X = networkItem.VisualProperties.X;
    181         center.Y = networkItem.VisualProperties.Y;
    182       }
    183 
    184       if (!useDefaultSize) {
    185         size.Width = networkItem.VisualProperties.Width;
    186         size.Height = networkItem.VisualProperties.Height;
    187       }
    188 
    189       var ll = new PointD(center.X - size.Width * 0.5, center.Y - size.Height * 0.5);
    190       var ur = ll + new Offset(size.Width, size.Height);
    191 
    192       SetPosition(ll, ur);
     164      var vp = (INodeVisualProperties)networkItem.VisualProperties;
     165      SetPosition(new PointD(vp.LowerLeft.X, vp.LowerLeft.Y), new PointD(vp.UpperRight.X, vp.UpperRight.Y));
    193166    }
    194167
     
    196169      if (networkItem == null) return;
    197170
    198       var visualProperties = networkItem.VisualProperties;
    199       var centerW = new PointD(LowerLeft.X + Size.Width * 0.5, UpperRight.Y - Size.Height * 0.5);
     171      var vp = (INodeVisualProperties)networkItem.VisualProperties;
    200172
    201173      IgnoreVisualPropertiesChanges = true;
    202174      try {
    203         visualProperties.X = centerW.X;
    204         visualProperties.Y = centerW.Y;
    205         visualProperties.Width = Size.Width;
    206         visualProperties.Height = Size.Height;
     175        vp.LowerLeft = new Point2D<double>(LowerLeft.X, LowerLeft.Y);
     176        vp.UpperRight = new Point2D<double>(UpperRight.X, UpperRight.Y);
    207177      } finally { IgnoreVisualPropertiesChanges = false; }
    208 
    209       OnRedrawRequired();
    210     }
    211 
    212     private void UpdatePortRectangles() {
    213       if (portRectangles == null) return;
    214 
    215       var rectangles = portRectangles.OfType<PortRectangle>().ToArray();
    216       double space = Size.Width / (rectangles.Length + 1);
    217       for (int i = 0; i < rectangles.Length; i++) {
    218         double dx = Math.Round(space * (i + 1));
    219         var point = LowerLeft + new Offset(dx, 0);
    220         rectangles[i].SetPosition(point);
    221       }
    222178    }
    223179    #endregion
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/PortRectangle.cs

    r13077 r13135  
    2222using System;
    2323using System.Drawing;
     24using System.Drawing.Drawing2D;
    2425using System.Linq;
     26using HeuristicLab.Common;
    2527using HeuristicLab.Core.Networks;
    2628using HeuristicLab.Visualization;
    2729
    2830namespace HeuristicLab.Networks.Views.NetworkVisualization {
     31  [Primitive(typeof(IPort), true)]
    2932  public class PortRectangle : FixedSizeRectangle, INetworkItemPrimitive<IPort> {
    3033    private const int size = 10;
     34
     35    protected readonly INodeVisualProperties nodeVisualProperties;
     36
     37    protected bool IgnoreVisualPropertiesChanges { get; set; }
    3138
    3239    public override Size Size {
     
    4552        networkItem = value;
    4653        if (networkItem != null) RegisterNetworkItemEvents();
     54        LoadVisualProperties();
    4755        OnNetworkItemChanged();
    4856      }
    4957    }
    5058
    51     public PortRectangle(NodeRectangle nodeRectangle, IPort port)
    52       : base(nodeRectangle.Chart, PointD.Empty, Size.Empty, Pens.Black, Brushes.Red) {
     59    public PortRectangle(IChart chart, IPort port, INode node)
     60      : base(chart, PointD.Empty, Size.Empty, Pens.Black, Brushes.Red) {
     61      nodeVisualProperties = (INodeVisualProperties)node.VisualProperties;
     62      nodeVisualProperties.Changed += NodeVisualProperties_Changed;
    5363      NetworkItem = port;
    5464    }
    5565
    5666    protected virtual void RegisterNetworkItemEvents() {
    57       networkItem.NameChanged += NetworkItemNameChanged;
     67      networkItem.NameChanged += NetworkItem_NameChanged;
     68      if (networkItem.VisualProperties != null) {
     69        networkItem.VisualProperties.Changed += VisualProperties_Changed;
     70      }
    5871      var connectablePort = networkItem as IConnectablePort;
    5972      if (connectablePort != null) {
     
    6376
    6477    protected virtual void DeregisterNetworkItemEvents() {
    65       networkItem.NameChanged -= NetworkItemNameChanged;
     78      networkItem.NameChanged -= NetworkItem_NameChanged;
     79      if (networkItem.VisualProperties != null) {
     80        networkItem.VisualProperties.Changed -= VisualProperties_Changed;
     81      }
    6682      var connectablePort = networkItem as IConnectablePort;
    6783      if (connectablePort != null) {
     
    7086    }
    7187
     88    #region Overrides
     89    public override void SetPosition(PointD point) {
     90      base.SetPosition(point);
     91      SaveVisualProperties();
     92    }
     93
     94    public override void Draw(Graphics graphics) {
     95      base.Draw(graphics);
     96
     97      var p = Chart.TransformWorldToPixel(Point);
     98
     99      if (networkItem != null && networkItem.VisualProperties != null) {
     100        using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) {
     101          var textSize = graphics.MeasureString(networkItem.Name, font);
     102          var vp = (IPortVisualProperties)networkItem.VisualProperties;
     103          switch (vp.Orientation) {
     104            case Orientation.North: p = new Point((int)(p.X - textSize.Width / 2), (int)(p.Y - Size.Height - textSize.Height)); break;
     105            case Orientation.East: p = new Point(p.X + Size.Width, (int)(p.Y - textSize.Height / 2)); break;
     106            case Orientation.South: p = new Point((int)(p.X - textSize.Width / 2), p.Y + Size.Height); break;
     107            case Orientation.West: p = new Point((int)(p.X - Size.Width - textSize.Width), (int)(p.Y - textSize.Height / 2)); break;
     108          }
     109
     110          graphics.DrawString(networkItem.Name, font, Brushes.Black, p);
     111        }
     112      }
     113    }
     114
     115    public override void PostDraw(Graphics graphics) {
     116      base.PostDraw(graphics);
     117
     118      if (Selected) {
     119        var p = Chart.TransformWorldToPixel(Point);
     120        using (var pen = new Pen(Color.LightGray, 3) { DashStyle = DashStyle.Dash })
     121          graphics.DrawRectangle(pen, p.X - Size.Width / 2, p.Y - Size.Height / 2, Size.Width, Size.Height);
     122      }
     123    }
     124
     125    #endregion
     126
    72127    #region Events
     128
    73129    public event EventHandler NetworkItemChanged;
     130
    74131    protected virtual void OnNetworkItemChanged() {
    75       UpdateToolTip();
    76132      var handler = NetworkItemChanged;
    77133      if (handler != null) handler(this, EventArgs.Empty);
    78134    }
    79135
    80     public event EventHandler NodeRectangleChanged;
    81     protected virtual void OnNodeRectangleChanged() {
    82       var handler = NodeRectangleChanged;
    83       if (handler != null) handler(this, EventArgs.Empty);
    84     }
    85136    #endregion
    86137
    87138    #region Event Handlers
    88     private void NetworkItemNameChanged(object sender, EventArgs e) {
    89       UpdateToolTip();
     139
     140    private void NodeVisualProperties_Changed(object sender, EventArgs e) {
     141      if (IgnoreVisualPropertiesChanges) return;
     142
     143      LoadVisualProperties();
     144    }
     145
     146    private void VisualProperties_Changed(object sender, EventArgs e) {
     147      if (IgnoreVisualPropertiesChanges) return;
     148
     149      LoadVisualProperties();
     150    }
     151
     152    private void NetworkItem_NameChanged(object sender, EventArgs e) {
     153      OnRedrawRequired();
    90154    }
    91155
    92156    private void Port_ConnectedPortChanged(object sender, EventArgs e) {
    93       var connectablePort = (IConnectablePort)networkItem;
    94 
    95157      var connectionLines = Chart.Group.GetAllPrimitives(Point).OfType<ConnectionLine>();
    96158      var outgoingLines = connectionLines.Where(x => x.StartPortRectangle == this);
    97 
    98       foreach (var l in outgoingLines)
    99         Chart.Group.Remove(l);
    100 
     159      foreach (var l in outgoingLines) Chart.Group.Remove(l);
     160
     161      var connectablePort = (IConnectablePort)networkItem;
    101162      var connectedPort = connectablePort.ConnectedPort as IConnectablePort;
    102163      if (connectedPort == null) return;
    103 
    104       var connectedNode = connectedPort.Parent;
    105       if (connectedNode == null) return;
    106164
    107165      var nodeRectangles = Chart.Group.Primitives.OfType<NodeRectangle>();
    108166      PortRectangle endPortRectangle = null;
    109167      foreach (var nodeRectangle in nodeRectangles) {
    110         endPortRectangle = nodeRectangle.GetPortRectangle(connectedPort);
     168        endPortRectangle = (PortRectangle)nodeRectangle.GetPortPrimitive(connectedPort);
    111169        if (endPortRectangle != null) break;
    112170      }
     
    116174      var connectionShape = new ConnectionLine(Chart, this, endPortRectangle);
    117175      Chart.Group.Add(connectionShape);
    118 
    119     }
     176    }
     177
    120178    #endregion
    121179
    122180    #region Helpers
    123     private void UpdateToolTip() {
    124       ToolTipText = networkItem.Name;
    125     }
     181
     182    private IPortVisualProperties CreateDefaultVisualProperties() {
     183      return new PortVisualProperties(Orientation.South, 0.5);
     184    }
     185
     186    private void LoadVisualProperties() {
     187      if (networkItem.VisualProperties == null)
     188        networkItem.VisualProperties = CreateDefaultVisualProperties();
     189
     190      var vp = (IPortVisualProperties)networkItem.VisualProperties;
     191      var p = PointD.Empty;
     192      double nodeWidth = nodeVisualProperties.UpperRight.X - nodeVisualProperties.LowerLeft.X;
     193      double nodeHeight = nodeVisualProperties.UpperRight.Y - nodeVisualProperties.LowerLeft.Y;
     194
     195      switch (vp.Orientation) {
     196        case Orientation.North:
     197          p.X = nodeVisualProperties.LowerLeft.X + vp.Offset * nodeWidth;
     198          p.Y = nodeVisualProperties.UpperRight.Y;
     199          break;
     200        case Orientation.East:
     201          p.X = nodeVisualProperties.UpperRight.X;
     202          p.Y = nodeVisualProperties.UpperRight.Y - vp.Offset * nodeHeight;
     203          break;
     204        case Orientation.South:
     205          p.X = nodeVisualProperties.UpperRight.X - vp.Offset * nodeWidth;
     206          p.Y = nodeVisualProperties.LowerLeft.Y;
     207          break;
     208        case Orientation.West:
     209          p.X = nodeVisualProperties.LowerLeft.X;
     210          p.Y = nodeVisualProperties.LowerLeft.Y + vp.Offset * nodeHeight;
     211          break;
     212      }
     213
     214      SetPosition(p);
     215    }
     216
     217    private void SaveVisualProperties() {
     218      if (networkItem == null) return;
     219
     220      var vp = (IPortVisualProperties)networkItem.VisualProperties;
     221
     222      IgnoreVisualPropertiesChanges = true;
     223      try {
     224        var lowerLeft = nodeVisualProperties.LowerLeft;
     225        var upperRight = nodeVisualProperties.UpperRight;
     226
     227        if (lowerLeft.X <= Point.X && Point.X <= upperRight.X) {
     228          // check N/S
     229          if (Point.Y.IsAlmost(upperRight.Y)) {
     230            vp.Orientation = Orientation.North;
     231            vp.Offset = (Point.X - lowerLeft.X) / (upperRight.X - lowerLeft.X);
     232          } else if (Point.Y.IsAlmost(lowerLeft.Y)) {
     233            vp.Orientation = Orientation.South;
     234            vp.Offset = (upperRight.X - Point.X) / (upperRight.X - lowerLeft.X);
     235          }
     236        }
     237        if (lowerLeft.Y <= Point.Y && Point.Y <= upperRight.Y) {
     238          // check E/W
     239          if (Point.X.IsAlmost(upperRight.X)) {
     240            vp.Orientation = Orientation.East;
     241            vp.Offset = (upperRight.Y - Point.Y) / (upperRight.Y - lowerLeft.Y);
     242          } else if (Point.X.IsAlmost(lowerLeft.X)) {
     243            vp.Orientation = Orientation.West;
     244            vp.Offset = (Point.Y - lowerLeft.Y) / (upperRight.Y - lowerLeft.Y);
     245          }
     246        }
     247      } finally {
     248        IgnoreVisualPropertiesChanges = false;
     249      }
     250    }
     251
    126252    #endregion
    127253  }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/INetworkItem.cs

    r13077 r13135  
    2323
    2424namespace HeuristicLab.Core.Networks {
    25   public interface INetworkItem : INamedItem {
     25  public interface INetworkItem : INamedItem, IVisualizable {
    2626    INetworkItem Parent { get; }
    2727    IEnumerable<INetworkItem> Children { get; }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/IVisualProperties.cs

    r13077 r13135  
    2121
    2222using System;
     23using HeuristicLab.Common;
    2324
    2425namespace HeuristicLab.Core.Networks {
    25   public interface IVisualProperties {
     26  public interface IVisualProperties : IDeepCloneable {
    2627    event EventHandler Changed;
    2728  }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/NetworkItem.cs

    r13077 r13135  
    4747    }
    4848
     49    [Storable]
     50    public IVisualProperties VisualProperties { get; set; }
     51
    4952    [StorableConstructor]
    5053    protected NetworkItem(bool deserializing) : base(deserializing) { }
    51     protected NetworkItem(NetworkItem original, Cloner cloner) : base(original, cloner) { }
     54    protected NetworkItem(NetworkItem original, Cloner cloner) : base(original, cloner) {
     55      VisualProperties = cloner.Clone(original.VisualProperties);
     56    }
    5257    protected NetworkItem() : base("NetworkItem") { }
    5358    protected NetworkItem(string name) : base(name) { }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/Node.cs

    r13077 r13135  
    2929  [Item("Node", "Abstract base class for nodes of a network.")]
    3030  [StorableClass]
    31   public abstract class Node : NetworkItem, IVisualizableNode {
     31  public abstract class Node : NetworkItem, INode {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.RadialChart; }
     
    5555        if (readOnlyPorts == null) readOnlyPorts = ports.AsReadOnly();
    5656        return readOnlyPorts;
    57       }
    58     }
    59 
    60     public string VisualName { get { return Name; } }
    61 
    62     [Storable]
    63     private INodeVisualProperties visualProperties;
    64     public INodeVisualProperties VisualProperties {
    65       get {
    66         if (visualProperties == null)
    67           visualProperties = new NodeVisualProperties();
    68         return visualProperties;
    6957      }
    7058    }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/Port.cs

    r13077 r13135  
    2727  [Item("Port", "Abstract base class for ports of network nodes.")]
    2828  [StorableClass]
    29   public abstract class Port : NetworkItem, IVisualizablePort {
     29  public abstract class Port : NetworkItem, IPort {
    3030    public static new Image StaticItemImage {
    3131      get { return HeuristicLab.Common.Resources.VSImageLibrary.Interface; }
     
    4040    }
    4141
    42     [Storable]
    43     private IPortVisualProperties visualProperties;
    44     public IPortVisualProperties VisualProperties {
    45       get {
    46         if (visualProperties == null)
    47           visualProperties = new PortVisualProperties();
    48         return visualProperties;
    49       }
    50     }
    51 
    5242    [StorableConstructor]
    5343    protected Port(bool deserializing) : base(deserializing) { }
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Core/VisualProperties.cs

    r13077 r13135  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using HeuristicLab.Common;
    324using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    526namespace HeuristicLab.Core.Networks {
    627  [StorableClass]
    7   public class VisualProperties : DeepCloneable, IVisualProperties {
     28  public abstract class VisualProperties : DeepCloneable, IVisualProperties {
    829    #region Constructors & Cloning
    930    [StorableConstructor]
    1031    protected VisualProperties(bool deserializing) : base() { }
    11     protected VisualProperties(VisualProperties original, Cloner cloner)
    12       : base(original, cloner) { }
     32    protected VisualProperties(VisualProperties original, Cloner cloner) : base(original, cloner) { }
    1333
    14     public VisualProperties() { }
    15 
    16     public override IDeepCloneable Clone(Cloner cloner) {
    17       return new VisualProperties(this, cloner);
    18     }
     34    protected VisualProperties() { }
    1935    #endregion
    2036
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/HeuristicLab.Networks-3.3.csproj

    r13077 r13135  
    203203    </Compile>
    204204    <Compile Include="ConfigurationPort.cs" />
    205     <Compile Include="Core\INodeVisualProperties.cs" />
    206     <Compile Include="Core\IPortVisualProperties.cs" />
    207     <Compile Include="Core\IVisualizableNode.cs" />
    208     <Compile Include="Core\IVisualizablePort.cs" />
     205    <Compile Include="Core\IVisualizable.cs" />
    209206    <Compile Include="Core\IVisualProperties.cs" />
    210     <Compile Include="Core\NodeVisualProperties.cs" />
    211     <Compile Include="Core\PortVisualProperties.cs" />
    212207    <Compile Include="Core\VisualProperties.cs" />
    213208    <Compile Include="ExecutionPort.cs" />
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNetworkItem.cs

    r13077 r13135  
    9898      get { return CompiledNetworkItem.Children; }
    9999    }
     100
     101    [Storable]
     102    public IVisualProperties VisualProperties { get; set; }
    100103    #endregion
    101104
     
    169172      variableStore = cloner.Clone(original.variableStore);
    170173      CompiledNetworkItem = cloner.Clone(original.compiledNetworkItem);
     174      VisualProperties = cloner.Clone(original.VisualProperties);
    171175    }
    172176    protected ProgrammableNetworkItem()
     
    358362        get { return Enumerable.Empty<INetworkItem>(); }
    359363      }
     364
     365      // TODO: no visual properties needed here
     366      public IVisualProperties VisualProperties {
     367        get { return Context.VisualProperties; }
     368        set { Context.VisualProperties = value; }
     369      }
    360370      #endregion
    361371
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/Programmable/ProgrammableNode.cs

    r13077 r13135  
    3232  [Item("ProgrammableNode", "Abstract base class for programmable nodes of a network.")]
    3333  [StorableClass]
    34   public abstract class ProgrammableNode : ProgrammableNetworkItem, IProgrammableNode, IVisualizableNode {
     34  public abstract class ProgrammableNode : ProgrammableNetworkItem, IProgrammableNode {
    3535    public static new Image StaticItemImage {
    3636      get { return HeuristicLab.Common.Resources.VSImageLibrary.RadialChart; }
     
    5858      }
    5959    }
    60 
    61     public string VisualName { get { return Name; } }
    62 
    63     [Storable]
    64     private INodeVisualProperties visualProperties;
    65     public INodeVisualProperties VisualProperties {
    66       get {
    67         if (visualProperties == null)
    68           visualProperties = new NodeVisualProperties();
    69         return visualProperties;
    70       }
    71     }
    7260    #endregion
    7361
     
    127115      IKeyedItemCollection<string, IPort> INode.Ports {
    128116        get { return Ports; }
    129       }
    130 
    131       public string VisualName { get { return Context.VisualName; } }
    132 
    133       public INodeVisualProperties VisualProperties {
    134         get { return Context.VisualProperties; }
    135117      }
    136118      #endregion
Note: See TracChangeset for help on using the changeset viewer.