Free cookie consent management tool by TermsFeed Policy Generator

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

#2205: worked on optimization networks

  • improved network visualization
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.