Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13799 for branches


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

#2205: worked on optimization networks

  • improved network visualization
Location:
branches/OptimizationNetworks
Files:
2 added
14 edited

Legend:

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

    r13135 r13799  
    7979            var lowerLeft = center - new Offset(size);
    8080            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));
     81            node.VisualProperties = new NodeVisualProperties {
     82              LowerLeft = new Point2D<double>(lowerLeft.X, lowerLeft.Y),
     83              UpperRight = new Point2D<double>(upperRight.X, upperRight.Y)
     84            };
    8385            network.Nodes.Add(node);
    8486            break;
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/ChartModes/SelectChartMode.cs

    r13135 r13799  
    4949    }
    5050
    51     public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
    52       try {
    53         if (!(chartControl.Tag is IUserDefinedNetwork)) return;
    54 
    55         switch (e.KeyCode) {
    56           case Keys.Delete:
    57             chartControl.SuspendRendering();
    58 
    59             var connectionLines = chartControl.Chart.Group.Primitives.OfType<ConnectionLine>().ToList();
    60             var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>().ToList();
    61             var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)).OfType<PortRectangle>().ToList();
    62 
    63             var deletedNodes = new HashSet<INode>();
    64             var deletedPorts = new HashSet<IMessagePort>();
    65 
    66             foreach (var nodeRectangle in nodeRectangles) {
    67               if (nodeRectangle.Selected) {
    68                 var node = nodeRectangle.NetworkItem;
    69                 if (node == null) continue;
    70                 deletedNodes.Add(node);
    71                 foreach (var port in node.Ports.OfType<IMessagePort>())
    72                   deletedPorts.Add(port);
    73               }
    74             }
    75 
    76             foreach (var portRectangle in portRectangles) {
    77               if (portRectangle.Selected) {
    78                 var port = portRectangle.NetworkItem as IMessagePort;
    79                 if (port == null) continue;
    80                 port.Parent.Ports.Remove(port);
    81                 deletedPorts.Add(port);
    82               }
    83             }
    84 
    85             selectedPortRectangle = null;
    86 
    87             foreach (var connectionLine in connectionLines) {
    88               var startPortRectangle = connectionLine.StartPortRectangle;
    89               var endPortRectangle = connectionLine.EndPortRectangle;
    90               if (startPortRectangle == null || endPortRectangle == null) continue;
    91 
    92               var startPort = startPortRectangle.NetworkItem as IMessagePort;
    93               var endPort = endPortRectangle.NetworkItem as IMessagePort;
    94               if (startPort == null || endPort == null) continue;
    95 
    96               if (connectionLine.Selected || deletedPorts.Contains(startPort) || deletedPorts.Contains(endPort))
    97                 startPort.ConnectedPort = null;
    98             }
    99 
    100             foreach (var node in deletedNodes)
    101               node.Parent.Nodes.Remove(node);
    102             break;
    103         }
    104       } finally {
    105         chartControl.ResumeRendering();
    106       }
    107     }
    108 
    10951    public override void HandleOnMouseDown(object sender, MouseEventArgs e) {
    11052      try {
     
    12971                  selectedPortRectangle = portRectangle;
    13072                  constrainingNodeRectangle = nodeRectangle;
     73                  break;
    13174                }
    13275              }
     
    13477
    13578            if (selectedPortRectangle != null)
    136               foreach (var sp in chartControl.Chart.Group.SelectedPrimitives)
     79              foreach (var sp in chartControl.Chart.Group.SelectedPrimitives) {
    13780                sp.Selected = false;
    138             else
    139               base.HandleOnMouseDown(sender, e);
     81                OnSelectedPrimitivesChanged();
     82              } else base.HandleOnMouseDown(sender, e);
    14083            break;
    14184        }
     
    196139      }
    197140    }
     141
     142    protected override void DeleteSelectedPrimitives() {
     143      if (!(chartControl.Tag is IUserDefinedNetwork)) return;
     144
     145      try {
     146        chartControl.SuspendRendering();
     147
     148        var connectionLines = chartControl.Chart.Group.Primitives.OfType<ConnectionLine>().ToList();
     149        var nodeRectangles = chartControl.Chart.Group.Primitives.OfType<NodeRectangle>().ToList();
     150        var portRectangles = nodeRectangles.SelectMany(x => x.NetworkItem.Ports.Select(x.GetPortPrimitive)).OfType<PortRectangle>().ToList();
     151
     152        var deletedNodes = new HashSet<INode>();
     153        var deletedPorts = new HashSet<IMessagePort>();
     154
     155        foreach (var nodeRectangle in nodeRectangles) {
     156          if (nodeRectangle.Selected) {
     157            var node = nodeRectangle.NetworkItem;
     158            if (node == null) continue;
     159            deletedNodes.Add(node);
     160            foreach (var port in node.Ports.OfType<IMessagePort>())
     161              deletedPorts.Add(port);
     162          }
     163        }
     164
     165        foreach (var portRectangle in portRectangles) {
     166          if (portRectangle.Selected) {
     167            var port = portRectangle.NetworkItem as IMessagePort;
     168            if (port == null) continue;
     169            port.Parent.Ports.Remove(port);
     170            deletedPorts.Add(port);
     171          }
     172        }
     173
     174        selectedPortRectangle = null;
     175
     176        foreach (var connectionLine in connectionLines) {
     177          var startPortRectangle = connectionLine.StartPortRectangle;
     178          var endPortRectangle = connectionLine.EndPortRectangle;
     179          if (startPortRectangle == null || endPortRectangle == null) continue;
     180
     181          var startPort = startPortRectangle.NetworkItem as IMessagePort;
     182          var endPort = endPortRectangle.NetworkItem as IMessagePort;
     183          if (startPort == null || endPort == null) continue;
     184
     185          if (connectionLine.Selected || deletedPorts.Contains(startPort) || deletedPorts.Contains(endPort))
     186            startPort.ConnectedPort = null;
     187        }
     188
     189        foreach (var node in deletedNodes)
     190          node.Parent.Nodes.Remove(node);
     191      } finally { chartControl.ResumeRendering(); }
     192    }
    198193  }
    199194}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.Designer.cs

    r13077 r13799  
    2525    private void InitializeComponent() {
    2626      this.chartControl = new HeuristicLab.Visualization.ChartControl();
     27      this.splitContainer = new System.Windows.Forms.SplitContainer();
     28      this.detailsToggleButton = new System.Windows.Forms.Button();
     29      this.detailsGroupBox = new System.Windows.Forms.GroupBox();
     30      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    2731      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
     32      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     33      this.splitContainer.Panel1.SuspendLayout();
     34      this.splitContainer.Panel2.SuspendLayout();
     35      this.splitContainer.SuspendLayout();
     36      this.detailsGroupBox.SuspendLayout();
    2837      this.SuspendLayout();
    2938      //
     
    3948            | System.Windows.Forms.AnchorStyles.Right)));
    4049      this.chartControl.BackColor = System.Drawing.SystemColors.Control;
    41       this.chartControl.Location = new System.Drawing.Point(3, 26);
     50      this.chartControl.Location = new System.Drawing.Point(3, 3);
     51      this.chartControl.Mode = null;
    4252      this.chartControl.Name = "chartControl";
    4353      this.chartControl.ScaleOnResize = true;
    44       this.chartControl.Size = new System.Drawing.Size(639, 488);
     54      this.chartControl.ShowToolBar = true;
     55      this.chartControl.Size = new System.Drawing.Size(408, 482);
     56      this.chartControl.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    4557      this.chartControl.TabIndex = 3;
     58      //
     59      // splitContainer
     60      //
     61      this.splitContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     62            | System.Windows.Forms.AnchorStyles.Left)
     63            | System.Windows.Forms.AnchorStyles.Right)));
     64      this.splitContainer.Location = new System.Drawing.Point(3, 26);
     65      this.splitContainer.Name = "splitContainer";
     66      //
     67      // splitContainer.Panel1
     68      //
     69      this.splitContainer.Panel1.Controls.Add(this.detailsToggleButton);
     70      this.splitContainer.Panel1.Controls.Add(this.chartControl);
     71      //
     72      // splitContainer.Panel2
     73      //
     74      this.splitContainer.Panel2.Controls.Add(this.detailsGroupBox);
     75      this.splitContainer.Size = new System.Drawing.Size(639, 488);
     76      this.splitContainer.SplitterDistance = 439;
     77      this.splitContainer.TabIndex = 4;
     78      //
     79      // detailsToggleButton
     80      //
     81      this.detailsToggleButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     82            | System.Windows.Forms.AnchorStyles.Right)));
     83      this.detailsToggleButton.Location = new System.Drawing.Point(417, 3);
     84      this.detailsToggleButton.Name = "detailsToggleButton";
     85      this.detailsToggleButton.Size = new System.Drawing.Size(19, 482);
     86      this.detailsToggleButton.TabIndex = 4;
     87      this.detailsToggleButton.Text = ">";
     88      this.detailsToggleButton.UseVisualStyleBackColor = true;
     89      this.detailsToggleButton.Click += new System.EventHandler(this.detailsToggleButton_Click);
     90      //
     91      // detailsGroupBox
     92      //
     93      this.detailsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     94            | System.Windows.Forms.AnchorStyles.Left)
     95            | System.Windows.Forms.AnchorStyles.Right)));
     96      this.detailsGroupBox.Controls.Add(this.viewHost);
     97      this.detailsGroupBox.Location = new System.Drawing.Point(3, 3);
     98      this.detailsGroupBox.Name = "detailsGroupBox";
     99      this.detailsGroupBox.Size = new System.Drawing.Size(190, 482);
     100      this.detailsGroupBox.TabIndex = 1;
     101      this.detailsGroupBox.TabStop = false;
     102      this.detailsGroupBox.Text = "Details";
     103      //
     104      // viewHost
     105      //
     106      this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     107            | System.Windows.Forms.AnchorStyles.Left)
     108            | System.Windows.Forms.AnchorStyles.Right)));
     109      this.viewHost.Caption = "View";
     110      this.viewHost.Content = null;
     111      this.viewHost.Enabled = false;
     112      this.viewHost.Location = new System.Drawing.Point(6, 19);
     113      this.viewHost.Name = "viewHost";
     114      this.viewHost.ReadOnly = false;
     115      this.viewHost.Size = new System.Drawing.Size(178, 457);
     116      this.viewHost.TabIndex = 0;
     117      this.viewHost.ViewsLabelVisible = true;
     118      this.viewHost.ViewType = null;
    46119      //
    47120      // NetworkVisualizationView
     
    49122      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    50123      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    51       this.Controls.Add(this.chartControl);
     124      this.Controls.Add(this.splitContainer);
    52125      this.Name = "NetworkVisualizationView";
    53126      this.Controls.SetChildIndex(this.nameLabel, 0);
    54127      this.Controls.SetChildIndex(this.nameTextBox, 0);
    55128      this.Controls.SetChildIndex(this.infoLabel, 0);
    56       this.Controls.SetChildIndex(this.chartControl, 0);
     129      this.Controls.SetChildIndex(this.splitContainer, 0);
    57130      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
     131      this.splitContainer.Panel1.ResumeLayout(false);
     132      this.splitContainer.Panel2.ResumeLayout(false);
     133      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit();
     134      this.splitContainer.ResumeLayout(false);
     135      this.detailsGroupBox.ResumeLayout(false);
    58136      this.ResumeLayout(false);
    59137      this.PerformLayout();
     
    64142
    65143    private Visualization.ChartControl chartControl;
     144    private System.Windows.Forms.SplitContainer splitContainer;
     145    private System.Windows.Forms.Button detailsToggleButton;
     146    private System.Windows.Forms.GroupBox detailsGroupBox;
     147    private MainForm.WindowsForms.ViewHost viewHost;
    66148  }
    67149}
  • branches/OptimizationNetworks/HeuristicLab.Networks.Views.NetworkVisualization.Views/3.3/NetworkVisualizationView.cs

    r13135 r13799  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    4647      InitializeComponent();
    4748
    48       var initialMode = new SelectChartMode(chartControl);
     49      var selectMode = new SelectChartMode(chartControl);
     50      selectMode.SelectedPrimitivesChanged += SelectMode_SelectedPrimitivesChanged;
    4951      chartControl.AddChartModes(
    50         initialMode,
     52        selectMode,
    5153        new PanChartMode(chartControl),
    5254        new RulerChartMode(chartControl),
     
    5759        new ConnectPortsChartMode(chartControl)
    5860      );
    59       chartControl.Mode = initialMode;
     61      chartControl.Mode = selectMode;
    6062    }
    6163
     
    8789
    8890    #region Event Handlers
     91    private void SelectMode_SelectedPrimitivesChanged(object sender, EventArgs e) {
     92      var selectedPrimitives = chartControl.Chart.Group.SelectedPrimitives;
     93      var nodePrimitive = selectedPrimitives.OfType<NodeRectangle>().SingleOrDefault();
     94      viewHost.Content = nodePrimitive != null ? nodePrimitive.NetworkItem : null;
     95    }
     96
    8997    #region Nodes Event Handlers
    9098    private void Nodes_ItemsAdded(object sender, CollectionItemsChangedEventArgs<INode> e) {
     
    111119    private void Ports_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IPort> e) { }
    112120    #endregion
     121
     122    private void detailsToggleButton_Click(object sender, EventArgs e) {
     123      splitContainer.Panel2Collapsed = !splitContainer.Panel2Collapsed;
     124      detailsToggleButton.Text = splitContainer.Panel2Collapsed ? "<" : ">";
     125    }
    113126    #endregion
    114127
  • 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
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/AlgorithmNode.cs

    r13459 r13799  
    5959    }
    6060
     61    [Storable]
     62    private IItemCollection<IAlgorithm> startedAlgorithms;
     63    public IItemCollection<IAlgorithm> StartedAlgorithms {
     64      get { return startedAlgorithms; }
     65    }
     66
    6167    [StorableConstructor]
    6268    protected AlgorithmNode(bool deserializing) : base(deserializing) { }
     
    6571      algorithm = cloner.Clone(original.algorithm);
    6672      runs = cloner.Clone(original.runs);
     73      startedAlgorithms = cloner.Clone(original.startedAlgorithms);
     74      RegisterStartedAlgorithmsEvents();
    6775    }
    6876    public AlgorithmNode()
    6977      : base("AlgorithmNode") {
    7078      runs = new RunCollection();
    71     }
     79      startedAlgorithms = new ItemCollection<IAlgorithm>();
     80      RegisterStartedAlgorithmsEvents();
     81    }
     82
    7283    public AlgorithmNode(string name)
    7384      : base(name) {
    7485      runs = new RunCollection();
     86      startedAlgorithms = new ItemCollection<IAlgorithm>();
     87      RegisterStartedAlgorithmsEvents();
    7588    }
    7689    public AlgorithmNode(string name, string description)
    7790      : base(name, description) {
    7891      runs = new RunCollection();
     92      startedAlgorithms = new ItemCollection<IAlgorithm>();
     93      RegisterStartedAlgorithmsEvents();
    7994    }
    8095
    8196    public override IDeepCloneable Clone(Cloner cloner) {
    8297      return new AlgorithmNode(this, cloner);
     98    }
     99
     100    [StorableHook(HookType.AfterDeserialization)]
     101    private void AfterDeserialization() {
     102      RegisterStartedAlgorithmsEvents();
     103    }
     104
     105    protected virtual void RegisterStartedAlgorithmsEvents() {
     106      startedAlgorithms.ItemsAdded += StartedAlgorithms_ItemsChanged;
     107      startedAlgorithms.ItemsRemoved += StartedAlgorithms_ItemsChanged;
     108    }
     109
     110    private void StartedAlgorithms_ItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IAlgorithm> e) {
     111      OnStartedAlgorithmsChanged();
    83112    }
    84113
     
    146175        algorithm.Prepare(true);
    147176        algorithm.ExceptionOccurred += (sender, args) => { exception = args.Value; };
    148         algorithm.Started += (sender, args) => { started.Set(); };
    149         algorithm.Stopped += (sender, args) => { stopped.Set(); };
     177        algorithm.Started += (sender, args) => { started.Set(); startedAlgorithms.Add((IAlgorithm)sender); };
     178        algorithm.Stopped += (sender, args) => { stopped.Set(); startedAlgorithms.Remove((IAlgorithm)sender); };
    150179        algorithm.Start();
    151180        stopped.WaitOne();
     
    175204    }
    176205
     206    public event EventHandler StartedAlgorithmsChanged;
     207    protected virtual void OnStartedAlgorithmsChanged() {
     208      var handler = StartedAlgorithmsChanged;
     209      if (handler != null) handler(this, EventArgs.Empty);
     210    }
     211
    177212    #region Ports Events
    178213    protected override void RegisterPortsEvents() {
  • branches/OptimizationNetworks/HeuristicLab.Networks/3.3/IAlgorithmNode.cs

    r11577 r13799  
    2020#endregion
    2121
     22using System;
     23using HeuristicLab.Core;
    2224using HeuristicLab.Core.Networks;
    2325using HeuristicLab.Optimization;
    24 using System;
    2526
    2627namespace HeuristicLab.Networks {
     
    2930    IAlgorithm Algorithm { get; set; }
    3031    RunCollection Runs { get; }
     32    IItemCollection<IAlgorithm> StartedAlgorithms { get; }
    3133
    3234    event EventHandler AlgorithmChanged;
     35    event EventHandler StartedAlgorithmsChanged;
    3336  }
    3437}
Note: See TracChangeset for help on using the changeset viewer.