Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/26/16 15:05:28 (9 years ago)
Author:
jkarder
Message:

#2205: worked on optimization networks

  • improved network visualization
Location:
branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/HeuristicLab.Networks.Views.NetworkVisualization-3.3.csproj

    r13135 r13799  
    7575    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    7676      <SpecificVersion>False</SpecificVersion>
     77      <Private>False</Private>
    7778    </Reference>
    7879    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    7980      <SpecificVersion>False</SpecificVersion>
    8081      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    81       <Private>True</Private>
     82      <Private>False</Private>
    8283    </Reference>
    8384    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    8485      <SpecificVersion>False</SpecificVersion>
    8586      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
     87      <Private>False</Private>
     88    </Reference>
     89    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     90      <SpecificVersion>False</SpecificVersion>
     91      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    8692      <Private>False</Private>
    8793    </Reference>
     
    101107    <Reference Include="System.Core" />
    102108    <Reference Include="System.Drawing" />
     109    <Reference Include="System.Windows.Forms" />
    103110  </ItemGroup>
    104111  <ItemGroup>
     
    109116    <Compile Include="Orientation.cs" />
    110117    <Compile Include="PortVisualProperties.cs" />
     118    <Compile Include="Primitives\AlgorithmNodeRectangle.cs" />
    111119    <Compile Include="Primitives\ConnectionLine.cs" />
    112120    <Compile Include="Plugin.cs" />
     121    <Compile Include="Primitives\MessagePortRectangle.cs" />
    113122    <Compile Include="Primitives\NodeRectangle.cs" />
    114123    <Compile Include="Primitives\PortRectangle.cs" />
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/INodeVisualProperties.cs

    r13135 r13799  
    2020#endregion
    2121
     22using System.Drawing;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core.Networks;
     
    2728    Point2D<double> LowerLeft { get; set; }
    2829    Point2D<double> UpperRight { get; set; }
     30    Color BrushColor { get; set; }
     31    Color PenColor { get; set; }
    2932  }
    3033}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/IPortVisualProperties.cs

    r13135 r13799  
    2020#endregion
    2121
     22using System.Drawing;
    2223using HeuristicLab.Core.Networks;
    2324
     
    2627    Orientation Orientation { get; set; }
    2728    double Offset { get; set; }
     29    Color BrushColor { get; set; }
     30    Color PenColor { get; set; }
    2831  }
    2932}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/NodeVisualProperties.cs

    r13135 r13799  
    2020#endregion
    2121
     22using System.Drawing;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core.Networks;
     
    4950    }
    5051
     52    [Storable]
     53    private Color brushColor;
     54    public Color BrushColor {
     55      get { return brushColor; }
     56      set {
     57        if (brushColor == value) return;
     58        brushColor = value;
     59        OnChanged();
     60      }
     61    }
     62
     63    [Storable]
     64    private Color penColor;
     65    public Color PenColor {
     66      get { return penColor; }
     67      set {
     68        if (penColor == value) return;
     69        penColor = value;
     70        OnChanged();
     71      }
     72    }
     73
    5174    #region Constructors & Cloning
    5275    [StorableConstructor]
     
    5679      lowerLeft = original.lowerLeft;
    5780      upperRight = original.upperRight;
     81      brushColor = original.brushColor;
     82      penColor = original.penColor;
    5883    }
    5984
    60     public NodeVisualProperties(Point2D<double> lowerLeft, Point2D<double> upperRight) {
    61       this.lowerLeft = lowerLeft;
    62       this.upperRight = upperRight;
     85    public NodeVisualProperties() {
     86      lowerLeft = new Point2D<double>(0.0, 0.0);
     87      upperRight = new Point2D<double>(200.0, 100.0);
     88      brushColor = Color.FromArgb(255, 120, 200, 240);
     89      penColor = Color.Black;
    6390    }
    6491
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/PortVisualProperties.cs

    r13135 r13799  
    2020#endregion
    2121
     22using System.Drawing;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core.Networks;
     
    4950    }
    5051
     52    [Storable]
     53    private Color brushColor;
     54    public Color BrushColor {
     55      get { return brushColor; }
     56      set {
     57        if (brushColor == value) return;
     58        brushColor = value;
     59        OnChanged();
     60      }
     61    }
     62
     63    [Storable]
     64    private Color penColor;
     65    public Color PenColor {
     66      get { return penColor; }
     67      set {
     68        if (penColor == value) return;
     69        penColor = value;
     70        OnChanged();
     71      }
     72    }
     73
    5174    #region Constructors & Cloning
    5275    [StorableConstructor]
     
    5679      orientation = original.orientation;
    5780      offset = original.offset;
     81      brushColor = original.brushColor;
     82      penColor = original.penColor;
    5883    }
    5984
    60     public PortVisualProperties(Orientation orientation, double offset) {
    61       this.orientation = orientation;
    62       this.offset = offset;
     85    public PortVisualProperties() {
     86      orientation = Orientation.South;
     87      offset = 0.5;
     88      brushColor = Color.RosyBrown;
     89      penColor = Color.Black;
    6390    }
    6491
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/ConnectionLine.cs

    r13135 r13799  
    8181      double bx = -2.5 * ax - ay, by = -2.5 * ay + ax;
    8282      double cx = -2.5 * ax + ay, cy = -2.5 * ay - ax;
    83       double mul = 4 * Chart.WorldToPixelRatio.Width;
     83      double mul = 5 * Chart.WorldToPixelRatio.Width;
    8484      bx *= mul; by *= mul;
    8585      cx *= mul; cy *= mul;
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/NodeRectangle.cs

    r13135 r13799  
    2323using System.Collections.Generic;
    2424using System.Drawing;
     25using System.Drawing.Drawing2D;
     26using System.Windows.Forms;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core.Networks;
     
    3335    protected readonly IGroup portRectangles;
    3436
     37    protected INodeVisualProperties VisualProperties {
     38      get { return (INodeVisualProperties)networkItem.VisualProperties; }
     39      set {
     40        if (networkItem.VisualProperties == value) return;
     41        networkItem.VisualProperties = value;
     42      }
     43    }
    3544    protected bool IgnoreVisualPropertiesChanges { get; set; }
    3645
     
    4857    }
    4958
     59    public override Brush Brush {
     60      get { return base.Brush; }
     61      set {
     62        if (base.Brush == value) return;
     63        base.Brush = value;
     64        SaveVisualProperties();
     65      }
     66    }
     67
     68    public override Pen Pen {
     69      get { return base.Pen; }
     70      set {
     71        if (base.Pen == value) return;
     72        base.Pen = value;
     73        SaveVisualProperties();
     74      }
     75    }
     76
    5077    public NodeRectangle(IChart chart, INode node)
    5178      : base(chart, PointD.Empty, PointD.Empty) {
     79      bool adjustSize = node.VisualProperties == null;
    5280      NetworkItem = node;
    5381
     
    5987      }
    6088      portRectangles.RedrawRequired += (sender, args) => OnRedrawRequired();
     89
     90      if (adjustSize) AdjustSize();
    6191    }
    6292
    6393    protected virtual void RegisterNetworkItemEvents() {
     94      if (VisualProperties != null) {
     95        VisualProperties.Changed += VisualProperties_Changed;
     96      }
    6497      networkItem.NameChanged += NetworkItem_NameChanged;
    65       if (networkItem.VisualProperties != null) {
    66         networkItem.VisualProperties.Changed += VisualProperties_Changed;
    67       }
    6898      if (networkItem.Ports != null) {
    6999        networkItem.Ports.ItemsAdded += Ports_ItemsAdded;
     
    73103
    74104    protected virtual void DeregisterNetworkItemEvents() {
     105      if (VisualProperties != null) {
     106        VisualProperties.Changed -= VisualProperties_Changed;
     107      }
    75108      networkItem.NameChanged -= NetworkItem_NameChanged;
    76       if (networkItem.VisualProperties != null) {
    77         networkItem.VisualProperties.Changed -= VisualProperties_Changed;
    78       }
    79109      if (networkItem.Ports != null) {
    80110        networkItem.Ports.ItemsAdded -= Ports_ItemsAdded;
     
    90120
    91121    public override void Draw(Graphics graphics) {
    92       base.Draw(graphics);
     122      int cornerRadius = (int)Math.Round(6 * Chart.WorldToPixelRatio.Width);
     123      var point = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
     124      var size = Chart.TransformWorldToPixel(Size);
     125      var bounds = new System.Drawing.Rectangle(point.X, point.Y, size.Width, size.Height);
     126      var arc = new System.Drawing.Rectangle(point, new Size(cornerRadius * 2, cornerRadius * 2));
     127
     128      using (var path = new GraphicsPath()) {
     129        path.AddArc(arc, 180f, 90f);
     130        arc.X = bounds.Right - cornerRadius * 2;
     131        path.AddArc(arc, 270f, 90);
     132        arc.Y = bounds.Bottom - cornerRadius * 2;
     133        path.AddArc(arc, 0f, 90f);
     134        arc.X = bounds.Left;
     135        path.AddArc(arc, 90f, 90f);
     136        path.CloseFigure();
     137
     138        graphics.FillPath(Brush, path);
     139        graphics.DrawPath(Pen, path);
     140      }
    93141
    94142      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
    95143
    96144      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);
     145        using (var headerFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width), FontStyle.Bold))
     146        using (var contentFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) {
     147          int margin = 4, x, y, lastY;
     148
     149          x = p.X + (int)Math.Round(margin * Chart.WorldToPixelRatio.Width);
     150          y = p.Y + (int)Math.Round(margin * Chart.WorldToPixelRatio.Height);
     151
     152          var imageSize = networkItem.ItemImage.Size;
     153          float imageWidth = (float)Math.Round(imageSize.Width * Chart.WorldToPixelRatio.Width);
     154          float imageHeight = (float)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height);
     155          graphics.DrawImage(networkItem.ItemImage, x, y, imageWidth, imageHeight);
     156          lastY = y;
     157
     158          var textSize = graphics.MeasureString(networkItem.Name, headerFont);
     159          x += (int)Math.Round((imageSize.Width + margin) * Chart.WorldToPixelRatio.Width);
     160          y += (int)Math.Round((imageSize.Height - textSize.Height * Chart.PixelToWorldRatio.Height) / 2 * Chart.WorldToPixelRatio.Height);
     161          graphics.DrawString(networkItem.Name, headerFont, Brushes.Black, x, y);
     162          y = lastY + (int)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height);
     163
     164          x = p.X;
     165          y += (int)Math.Round(margin * Chart.WorldToPixelRatio.Height);
     166          graphics.DrawLine(Pen, x, y, x + size.Width, y);
     167
     168          foreach (var port in networkItem.Ports) {
     169            x = p.X + (int)Math.Round(margin * Chart.WorldToPixelRatio.Width);
     170            y += (int)Math.Round(margin * Chart.WorldToPixelRatio.Height);
     171
     172            imageSize = port.ItemImage.Size;
     173            imageWidth = (float)Math.Round(imageSize.Width * Chart.WorldToPixelRatio.Width);
     174            imageHeight = (float)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height);
     175            graphics.DrawImage(port.ItemImage, x, y, imageWidth, imageHeight);
     176            lastY = y;
     177
     178            textSize = graphics.MeasureString(port.Name, contentFont);
     179            x += (int)Math.Round((imageSize.Width + margin) * Chart.WorldToPixelRatio.Width);
     180            y += (int)Math.Round((imageSize.Height - textSize.Height * Chart.PixelToWorldRatio.Height) / 2 * Chart.WorldToPixelRatio.Height);
     181            graphics.DrawString(port.Name, contentFont, Brushes.Black, x, y);
     182            y = lastY + (int)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height);
     183
     184            var parameterizedPort = port as IParameterizedPort;
     185            if (parameterizedPort != null) {
     186              foreach (var param in parameterizedPort.Parameters) {
     187                x = p.X + (int)Math.Round(4 * margin * Chart.WorldToPixelRatio.Width);
     188                y += (int)Math.Round(margin * Chart.WorldToPixelRatio.Height);
     189
     190                imageSize = param.ItemImage.Size;
     191                imageWidth = (float)Math.Round(imageSize.Width * Chart.WorldToPixelRatio.Width);
     192                imageHeight = (float)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height);
     193                graphics.DrawImage(param.ItemImage, x, y, imageWidth, imageHeight);
     194                lastY = y;
     195
     196                textSize = graphics.MeasureString(param.Name, contentFont);
     197                x += (int)Math.Round((imageSize.Width + margin) * Chart.WorldToPixelRatio.Width);
     198                y += (int)Math.Round((imageSize.Height - textSize.Height * Chart.PixelToWorldRatio.Height) / 2 * Chart.WorldToPixelRatio.Height);
     199                graphics.DrawString(param.Name, contentFont, Brushes.Black, x, y);
     200                y = lastY + (int)Math.Round(imageSize.Height * Chart.WorldToPixelRatio.Height);
     201              }
     202            }
     203          }
    99204        }
    100205      }
     
    128233
    129234    private void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
     235      AdjustSize();
     236
    130237      foreach (var port in e.Items) {
    131238        var portRectangle = PrimitiveAttribute.CreateDefaultPrimitive(port.GetType(), Chart, port, networkItem);
     
    133240        portRectangles.Add(portRectangle);
    134241      }
    135 
    136       OnRedrawRequired();
    137242    }
    138243
    139244    private void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
     245      AdjustSize();
     246
    140247      foreach (var port in e.Items) {
    141248        var portRectangle = port2primitive[port];
     
    143250        portRectangles.Remove(portRectangle);
    144251      }
    145 
    146       OnRedrawRequired();
    147252    }
    148253    #endregion
    149254
    150255    #region Helpers
    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));
    158     }
    159 
    160256    private void LoadVisualProperties() {
    161       if (networkItem.VisualProperties == null)
    162         networkItem.VisualProperties = CreateDefaultVisualProperties();
    163 
    164       var vp = (INodeVisualProperties)networkItem.VisualProperties;
    165       SetPosition(new PointD(vp.LowerLeft.X, vp.LowerLeft.Y), new PointD(vp.UpperRight.X, vp.UpperRight.Y));
     257      if (VisualProperties == null)
     258        VisualProperties = new NodeVisualProperties();
     259
     260      var vp = VisualProperties;
     261      IgnoreVisualPropertiesChanges = true;
     262      try {
     263        SetPosition(new PointD(vp.LowerLeft.X, vp.LowerLeft.Y), new PointD(vp.UpperRight.X, vp.UpperRight.Y));
     264        Brush = new SolidBrush(vp.BrushColor);
     265        Pen = new Pen(vp.PenColor);
     266      } finally { IgnoreVisualPropertiesChanges = false; }
    166267    }
    167268
    168269    private void SaveVisualProperties() {
    169       if (networkItem == null) return;
    170 
    171       var vp = (INodeVisualProperties)networkItem.VisualProperties;
    172 
     270      if (networkItem == null || IgnoreVisualPropertiesChanges) return;
     271
     272      var vp = VisualProperties;
    173273      IgnoreVisualPropertiesChanges = true;
    174274      try {
    175275        vp.LowerLeft = new Point2D<double>(LowerLeft.X, LowerLeft.Y);
    176276        vp.UpperRight = new Point2D<double>(UpperRight.X, UpperRight.Y);
     277        vp.BrushColor = ((SolidBrush)Brush).Color;
     278        vp.PenColor = Pen.Color;
    177279      } finally { IgnoreVisualPropertiesChanges = false; }
     280    }
     281
     282    private void AdjustSize() {
     283      if (networkItem == null) return;
     284
     285      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y + Size.Height));
     286      int margin = 4, x = p.X, y = p.Y;
     287      using (var headerFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25), FontStyle.Bold))
     288      using (var contentFont = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25))) {
     289        x += 2 * margin; y += 2 * margin;
     290        int headerWidth = networkItem.ItemImage.Width + margin + TextRenderer.MeasureText(networkItem.Name, headerFont).Width;
     291        y += networkItem.ItemImage.Height + margin;
     292        int maxPortWidth = 0, maxPortParamWidth = 0;
     293        foreach (var port in networkItem.Ports) {
     294          int portWidth = port.ItemImage.Width + margin + TextRenderer.MeasureText(port.Name, contentFont).Width;
     295          if (portWidth > maxPortWidth) maxPortWidth = portWidth;
     296          y += margin + port.ItemImage.Height;
     297          var parameterizedPort = port as IParameterizedPort;
     298          if (parameterizedPort != null) {
     299            foreach (var param in parameterizedPort.Parameters) {
     300              int portParamWidth = param.ItemImage.Width + 3 * margin + TextRenderer.MeasureText(param.Name, contentFont).Width;
     301              if (portParamWidth > maxPortParamWidth) maxPortParamWidth = portParamWidth;
     302              y += margin + param.ItemImage.Height;
     303            }
     304          }
     305        }
     306
     307        x += Math.Max(headerWidth, Math.Max(maxPortWidth, maxPortParamWidth));
     308        var ll = Chart.TransformPixelToWorld(new Point(p.X, y));
     309        var ur = Chart.TransformPixelToWorld(new Point(x, p.Y));
     310        SetPosition(ll, ur);
     311      }
    178312    }
    179313    #endregion
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization/3.3/Primitives/PortRectangle.cs

    r13135 r13799  
    3535    protected readonly INodeVisualProperties nodeVisualProperties;
    3636
     37    protected IPortVisualProperties VisualProperties {
     38      get { return (IPortVisualProperties)networkItem.VisualProperties; }
     39      set {
     40        if (networkItem.VisualProperties == value) return;
     41        networkItem.VisualProperties = value;
     42      }
     43    }
    3744    protected bool IgnoreVisualPropertiesChanges { get; set; }
    3845
     
    5764    }
    5865
     66    public override Brush Brush {
     67      get { return base.Brush; }
     68      set {
     69        if (base.Brush == value) return;
     70        base.Brush = value;
     71        SaveVisualProperties();
     72      }
     73    }
     74
     75    public override Pen Pen {
     76      get { return base.Pen; }
     77      set {
     78        if (base.Pen == value) return;
     79        base.Pen = value;
     80        SaveVisualProperties();
     81      }
     82    }
     83
    5984    public PortRectangle(IChart chart, IPort port, INode node)
    60       : base(chart, PointD.Empty, Size.Empty, Pens.Black, Brushes.Red) {
     85      : base(chart, PointD.Empty, Size.Empty) {
    6186      nodeVisualProperties = (INodeVisualProperties)node.VisualProperties;
    6287      nodeVisualProperties.Changed += NodeVisualProperties_Changed;
     
    6590
    6691    protected virtual void RegisterNetworkItemEvents() {
     92      if (VisualProperties != null) {
     93        VisualProperties.Changed += VisualProperties_Changed;
     94      }
    6795      networkItem.NameChanged += NetworkItem_NameChanged;
    68       if (networkItem.VisualProperties != null) {
    69         networkItem.VisualProperties.Changed += VisualProperties_Changed;
    70       }
    7196      var connectablePort = networkItem as IConnectablePort;
    7297      if (connectablePort != null) {
     
    76101
    77102    protected virtual void DeregisterNetworkItemEvents() {
     103      if (VisualProperties != null) {
     104        VisualProperties.Changed -= VisualProperties_Changed;
     105      }
    78106      networkItem.NameChanged -= NetworkItem_NameChanged;
    79       if (networkItem.VisualProperties != null) {
    80         networkItem.VisualProperties.Changed -= VisualProperties_Changed;
    81       }
    82107      var connectablePort = networkItem as IConnectablePort;
    83108      if (connectablePort != null) {
     
    97122      var p = Chart.TransformWorldToPixel(Point);
    98123
    99       if (networkItem != null && networkItem.VisualProperties != null) {
     124      if (networkItem != null && VisualProperties != null) {
    100125        using (var font = new Font(FontFamily.GenericSansSerif, (float)Math.Round(8.25 * Chart.WorldToPixelRatio.Width))) {
    101126          var textSize = graphics.MeasureString(networkItem.Name, font);
    102           var vp = (IPortVisualProperties)networkItem.VisualProperties;
     127          var vp = VisualProperties;
    103128          switch (vp.Orientation) {
    104129            case Orientation.North: p = new Point((int)(p.X - textSize.Width / 2), (int)(p.Y - Size.Height - textSize.Height)); break;
     
    179204
    180205    #region Helpers
    181 
    182     private IPortVisualProperties CreateDefaultVisualProperties() {
    183       return new PortVisualProperties(Orientation.South, 0.5);
    184     }
    185 
    186206    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);
     207      if (VisualProperties == null)
     208        VisualProperties = new PortVisualProperties();
     209
     210      var vp = VisualProperties;
     211      IgnoreVisualPropertiesChanges = true;
     212      try {
     213        var p = PointD.Empty;
     214        double nodeWidth = nodeVisualProperties.UpperRight.X - nodeVisualProperties.LowerLeft.X;
     215        double nodeHeight = nodeVisualProperties.UpperRight.Y - nodeVisualProperties.LowerLeft.Y;
     216
     217        switch (vp.Orientation) {
     218          case Orientation.North:
     219            p.X = nodeVisualProperties.LowerLeft.X + vp.Offset * nodeWidth;
     220            p.Y = nodeVisualProperties.UpperRight.Y;
     221            break;
     222          case Orientation.East:
     223            p.X = nodeVisualProperties.UpperRight.X;
     224            p.Y = nodeVisualProperties.UpperRight.Y - vp.Offset * nodeHeight;
     225            break;
     226          case Orientation.South:
     227            p.X = nodeVisualProperties.UpperRight.X - vp.Offset * nodeWidth;
     228            p.Y = nodeVisualProperties.LowerLeft.Y;
     229            break;
     230          case Orientation.West:
     231            p.X = nodeVisualProperties.LowerLeft.X;
     232            p.Y = nodeVisualProperties.LowerLeft.Y + vp.Offset * nodeHeight;
     233            break;
     234        }
     235
     236        SetPosition(p);
     237        Brush = new SolidBrush(vp.BrushColor);
     238        Pen = new Pen(vp.PenColor);
     239      } finally { IgnoreVisualPropertiesChanges = false; }
    215240    }
    216241
    217242    private void SaveVisualProperties() {
    218       if (networkItem == null) return;
    219 
    220       var vp = (IPortVisualProperties)networkItem.VisualProperties;
    221 
     243      if (networkItem == null || IgnoreVisualPropertiesChanges) return;
     244
     245      var vp = VisualProperties;
    222246      IgnoreVisualPropertiesChanges = true;
    223247      try {
     
    245269          }
    246270        }
    247       } finally {
    248         IgnoreVisualPropertiesChanges = false;
    249       }
     271
     272        vp.BrushColor = ((SolidBrush)Brush).Color;
     273        vp.PenColor = Pen.Color;
     274      } finally { IgnoreVisualPropertiesChanges = false; }
    250275    }
    251276
Note: See TracChangeset for help on using the changeset viewer.