Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11421 for branches


Ignore:
Timestamp:
10/07/14 08:32:58 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks
Files:
4 added
17 edited

Legend:

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

    r11412 r11421  
    4949  </ItemGroup>
    5050  <ItemGroup>
     51    <Compile Include="PortView.cs">
     52      <SubType>UserControl</SubType>
     53    </Compile>
     54    <Compile Include="PortView.Designer.cs">
     55      <DependentUpon>PortView.cs</DependentUpon>
     56    </Compile>
    5157    <Compile Include="VariablesNodeView.cs">
    5258      <SubType>UserControl</SubType>
     
    6773      <DependentUpon>InputPortView.cs</DependentUpon>
    6874    </Compile>
    69     <Compile Include="PortView.cs">
     75    <Compile Include="ValuePortView.cs">
    7076      <SubType>UserControl</SubType>
    7177    </Compile>
    72     <Compile Include="PortView.Designer.cs">
    73       <DependentUpon>PortView.cs</DependentUpon>
     78    <Compile Include="ValuePortView.Designer.cs">
     79      <DependentUpon>ValuePortView.cs</DependentUpon>
    7480    </Compile>
    7581    <Compile Include="NodeView.cs">
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/InputPortView.cs

    r11412 r11421  
    2929  [Content(typeof(IInputPort<>), false)]
    3030  [Content(typeof(IInputPort), false)]
    31   public partial class InputPortView : PortView {
     31  public partial class InputPortView : ValuePortView {
    3232    public new IInputPort Content {
    3333      get { return (IInputPort)base.Content; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/PortView.Designer.cs

    r11412 r11421  
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.valueGroupBox = new System.Windows.Forms.GroupBox();
    48       this.valuePanel = new System.Windows.Forms.Panel();
    49       this.valueViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    5047      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    51       this.valueGroupBox.SuspendLayout();
    52       this.valuePanel.SuspendLayout();
    5348      this.SuspendLayout();
    5449      //
     
    6459      this.infoLabel.Location = new System.Drawing.Point(626, 3);
    6560      //
    66       // valueGroupBox
    67       //
    68       this.valueGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    69             | System.Windows.Forms.AnchorStyles.Left)
    70             | System.Windows.Forms.AnchorStyles.Right)));
    71       this.valueGroupBox.Controls.Add(this.valuePanel);
    72       this.valueGroupBox.Location = new System.Drawing.Point(0, 26);
    73       this.valueGroupBox.Name = "valueGroupBox";
    74       this.valueGroupBox.Size = new System.Drawing.Size(645, 491);
    75       this.valueGroupBox.TabIndex = 3;
    76       this.valueGroupBox.TabStop = false;
    77       this.valueGroupBox.Text = "Value";
    78       //
    79       // valuePanel
    80       //
    81       this.valuePanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    82             | System.Windows.Forms.AnchorStyles.Left)
    83             | System.Windows.Forms.AnchorStyles.Right)));
    84       this.valuePanel.Controls.Add(this.valueViewHost);
    85       this.valuePanel.Location = new System.Drawing.Point(6, 19);
    86       this.valuePanel.Name = "valuePanel";
    87       this.valuePanel.Size = new System.Drawing.Size(633, 466);
    88       this.valuePanel.TabIndex = 0;
    89       //
    90       // valueViewHost
    91       //
    92       this.valueViewHost.Caption = "View";
    93       this.valueViewHost.Content = null;
    94       this.valueViewHost.Dock = System.Windows.Forms.DockStyle.Fill;
    95       this.valueViewHost.Enabled = false;
    96       this.valueViewHost.Location = new System.Drawing.Point(0, 0);
    97       this.valueViewHost.Name = "valueViewHost";
    98       this.valueViewHost.ReadOnly = false;
    99       this.valueViewHost.Size = new System.Drawing.Size(633, 466);
    100       this.valueViewHost.TabIndex = 0;
    101       this.valueViewHost.ViewsLabelVisible = true;
    102       this.valueViewHost.ViewType = null;
    103       //
    10461      // PortView
    10562      //
    10663      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    107       this.Controls.Add(this.valueGroupBox);
    10864      this.Name = "PortView";
    10965      this.Size = new System.Drawing.Size(645, 517);
     
    11167      this.Controls.SetChildIndex(this.nameTextBox, 0);
    11268      this.Controls.SetChildIndex(this.infoLabel, 0);
    113       this.Controls.SetChildIndex(this.valueGroupBox, 0);
    11469      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    115       this.valueGroupBox.ResumeLayout(false);
    116       this.valuePanel.ResumeLayout(false);
    11770      this.ResumeLayout(false);
    11871      this.PerformLayout();
     
    12275    #endregion
    12376
    124     protected System.Windows.Forms.GroupBox valueGroupBox;
    125     protected System.Windows.Forms.Panel valuePanel;
    126     protected MainForm.WindowsForms.ViewHost valueViewHost;
    127 
    128 
    129 
    13077
    13178  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/PortView.cs

    r11412 r11421  
    2828namespace HeuristicLab.Optimization.Networks.Views {
    2929  [View("Port View")]
    30   [Content(typeof(Port<>), true)]
    31   [Content(typeof(IPort<>), false)]
     30  [Content(typeof(Port), true)]
    3231  [Content(typeof(IPort), false)]
    3332  public partial class PortView : NamedItemView {
     
    4039      InitializeComponent();
    4140    }
    42 
    43     protected override void DeregisterContentEvents() {
    44       Content.ValueChanged -= Content_ValueChanged;
    45       base.DeregisterContentEvents();
    46     }
    47 
    48     protected override void RegisterContentEvents() {
    49       base.RegisterContentEvents();
    50       Content.ValueChanged += Content_ValueChanged;
    51     }
    52 
    53     protected override void OnContentChanged() {
    54       base.OnContentChanged();
    55       if (Content == null) {
    56         valueViewHost.Content = null;
    57       } else {
    58         valueViewHost.ViewType = null;
    59         valueViewHost.Content = Content.Value as IContent;
    60       }
    61     }
    62 
    63     protected override void SetEnabledStateOfControls() {
    64       base.SetEnabledStateOfControls();
    65       valueGroupBox.Enabled = (Content as IContent) != null;
    66     }
    67     protected virtual void Content_ValueChanged(object sender, System.EventArgs e) {
    68       if (InvokeRequired)
    69         Invoke(new EventHandler(Content_ValueChanged), sender, e);
    70       else {
    71         valueViewHost.ViewType = null;
    72         valueViewHost.Content = Content.Value as IContent;
    73 
    74       }
    75     }
    7641  }
    7742}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj

    r11412 r11421  
    4848  </ItemGroup>
    4949  <ItemGroup>
     50    <Compile Include="IPort.cs" />
    5051    <Compile Include="IVariablesNode.cs" />
     52    <Compile Include="Port.cs" />
    5153    <Compile Include="VariablesNode.cs" />
    5254    <Compile Include="EventArgs.cs" />
     
    6163    <Compile Include="INetwork.cs" />
    6264    <Compile Include="IInputPort.cs" />
    63     <Compile Include="IPort.cs" />
     65    <Compile Include="IValuePort.cs" />
    6466    <Compile Include="INode.cs" />
    6567    <Compile Include="Network.cs" />
     
    6769    <Compile Include="NodeCollection.cs" />
    6870    <Compile Include="PortCollection.cs" />
    69     <Compile Include="Port.cs" />
     71    <Compile Include="ValuePort.cs" />
    7072    <Compile Include="Plugin.cs" />
    7173    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputOutputPort.cs

    r11412 r11421  
    2424
    2525namespace HeuristicLab.Optimization.Networks {
    26   public interface IInputOutputPort : IPort {
     26  public interface IInputOutputPort : IValuePort {
    2727    IOutputInputPort OutputInputPort { get; }
    2828
     
    3030  }
    3131
    32   public interface IInputOutputPort<TIn, TOut> : IInputOutputPort, IPort<TIn>
     32  public interface IInputOutputPort<TIn, TOut> : IInputOutputPort, IValuePort<TIn>
    3333    where TIn : class, IItem
    3434    where TOut : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputPort.cs

    r11412 r11421  
    2424
    2525namespace HeuristicLab.Optimization.Networks {
    26   public interface IInputPort : IPort {
     26  public interface IInputPort : IValuePort {
    2727    IOutputPort OutputPort { get; set; }
    2828
     
    3030  }
    3131
    32   public interface IInputPort<T> : IInputPort, IPort<T> where T : class, IItem {
     32  public interface IInputPort<T> : IInputPort, IValuePort<T> where T : class, IItem {
    3333    new IOutputPort<T> OutputPort { get; set; }
    3434  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputInputPort.cs

    r11406 r11421  
    2424
    2525namespace HeuristicLab.Optimization.Networks {
    26   public interface IOutputInputPort : IPort {
     26  public interface IOutputInputPort : IValuePort {
    2727    object SendValue(object value);
    2828  }
    2929
    30   public interface IOutputInputPort<TOut, TIn> : IOutputInputPort, IPort<TOut>
     30  public interface IOutputInputPort<TOut, TIn> : IOutputInputPort, IValuePort<TOut>
    3131    where TOut : class, IItem
    3232    where TIn : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputPort.cs

    r11401 r11421  
    2323
    2424namespace HeuristicLab.Optimization.Networks {
    25   public interface IOutputPort : IPort {
     25  public interface IOutputPort : IValuePort {
    2626    new object Value { get; set; }
    2727  }
    2828
    29   public interface IOutputPort<T> : IOutputPort, IPort<T> where T : class, IItem {
     29  public interface IOutputPort<T> : IOutputPort, IValuePort<T> where T : class, IItem {
    3030    new T Value { get; set; }
    3131  }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IPort.cs

    r11409 r11421  
    2121
    2222using HeuristicLab.Core;
    23 using System;
    2423
    2524namespace HeuristicLab.Optimization.Networks {
    2625  public interface IPort : INamedItem {
    27     //DISCUSS: Should there be a reference to the node of this port?
    28 
    29     object Value { get; }
    30 
    31     event EventHandler ValueChanged;
    32   }
    33 
    34   public interface IPort<T> : IPort where T : class, IItem {
    35     new T Value { get; }
     26    INode Node { get; set; }
    3627  }
    3728}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs

    r11412 r11421  
    2828  [Item("InputOutputPort", "A synchronous input/output port of an optimization network node.")]
    2929  [StorableClass]
    30   public class InputOutputPort<TIn, TOut> : Port<TIn>, IInputOutputPort<TIn, TOut>
     30  public class InputOutputPort<TIn, TOut> : ValuePort<TIn>, IInputOutputPort<TIn, TOut>
    3131    where TIn : class, IItem
    3232    where TOut : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs

    r11412 r11421  
    2929  [Item("InputPort", "An asynchronous input port of an optimization network node.")]
    3030  [StorableClass]
    31   public class InputPort<T> : Port<T>, IInputPort<T> where T : class, IItem {
     31  public class InputPort<T> : ValuePort<T>, IInputPort<T> where T : class, IItem {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Node.cs

    r11401 r11421  
    5656    public Node()
    5757      : base("Node") {
    58       ports = new PortCollection();
     58      ports = new PortCollection(this);
    5959      readOnlyPorts = null;
    6060    }
    6161    public Node(string name)
    6262      : base(name) {
    63       ports = new PortCollection();
     63      ports = new PortCollection(this);
    6464      readOnlyPorts = null;
    6565    }
    6666    public Node(string name, string description)
    6767      : base(name, description) {
    68       ports = new PortCollection();
     68      ports = new PortCollection(this);
    6969      readOnlyPorts = null;
    7070    }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputInputPort.cs

    r11406 r11421  
    2828  [Item("OutputInputPort", "A synchronous output/input port of an optimization network node.")]
    2929  [StorableClass]
    30   public class OutputInputPort<TOut, TIn> : Port<TOut>, IOutputInputPort<TOut, TIn>
     30  public class OutputInputPort<TOut, TIn> : ValuePort<TOut>, IOutputInputPort<TOut, TIn>
    3131    where TOut : class, IItem
    3232    where TIn : class, IItem {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputPort.cs

    r11409 r11421  
    2929  [Item("OutputPort", "An asynchronous output port of an optimization network node.")]
    3030  [StorableClass]
    31   public class OutputPort<T> : Port<T>, IOutputPort<T> where T : class, IItem {
     31  public class OutputPort<T> : ValuePort<T>, IOutputPort<T> where T : class, IItem {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs

    r11406 r11421  
    2929  [Item("Port", "Abstract base class for ports of an optimization network node.")]
    3030  [StorableClass]
    31   public abstract class Port<T> : NamedItem, IPort<T> where T : class, IItem {
     31  public abstract class Port : NamedItem, IPort {
    3232    public static new Image StaticItemImage {
    3333      get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; }
     
    3535
    3636    [Storable]
    37     protected T value;
    38     public virtual T Value {
    39       get { return value; }
    40       protected set {
    41         DeregisterValueEvents();
    42         this.value = value;
    43         RegisterValueEvents();
    44         OnValueChanged();
     37    private INode node;
     38    public INode Node {
     39      get { return node; }
     40      set {
     41        if ((value != null) && !value.Ports.Contains(this))
     42          throw new InvalidOperationException("Port is not contained in port collection of node.");
     43        if ((value == null) && node.Ports.Contains(this))
     44          throw new InvalidOperationException("Port is still contained in port collection of node.");
     45        node = value;
    4546      }
    46     }
    47     object IPort.Value {
    48       get { return Value; }
    4947    }
    5048
    5149    [StorableConstructor]
    5250    protected Port(bool deserializing) : base(deserializing) { }
    53     protected Port(Port<T> original, Cloner cloner)
     51    protected Port(Port original, Cloner cloner)
    5452      : base(original, cloner) {
    55       value = cloner.Clone(original.value);
    56       RegisterValueEvents();
     53      node = (INode)cloner.GetClone(original.node);  // NOTE: original node is NOT automatically cloned
    5754    }
    5855    protected Port() : base("Port") { }
    5956    protected Port(string name) : base(name) { }
    6057    protected Port(string name, string description) : base(name, description) { }
    61 
    62     [StorableHook(HookType.AfterDeserialization)]
    63     private void AfterDeserialization() {
    64       RegisterValueEvents();
    65     }
    66 
    67     public override string ToString() {
    68       return Name + ": " + (Value != null ? Value.ToString() : "null");
    69     }
    70 
    71     public event EventHandler ValueChanged;
    72     protected virtual void OnValueChanged() {
    73       var handler = ValueChanged;
    74       if (handler != null) handler(this, EventArgs.Empty);
    75       OnToStringChanged();
    76     }
    77 
    78     protected virtual void RegisterValueEvents() {
    79       if (value != null) {
    80         value.ToStringChanged += new EventHandler(Value_ToStringChanged);
    81       }
    82     }
    83     protected virtual void DeregisterValueEvents() {
    84       if (value != null) {
    85         value.ToStringChanged -= new EventHandler(Value_ToStringChanged);
    86       }
    87     }
    88     private void Value_ToStringChanged(object sender, EventArgs e) {
    89       OnToStringChanged();
    90     }
    9158  }
    9259}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/PortCollection.cs

    r11401 r11421  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
    2524using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     25using System;
     26using System.Collections.Generic;
    2627
    2728namespace HeuristicLab.Optimization.Networks {
    2829  [StorableClass]
    29   [Item("PortCollection", "Represents a collection of ports.")]
     30  [Item("PortCollection", "Represents a collection of ports in an optimization network node.")]
    3031  public class PortCollection : NamedItemCollection<IPort> {
     32    [Storable]
     33    private INode node;
     34    public INode Node {
     35      get { return node; }
     36    }
     37
    3138    [StorableConstructor]
    3239    protected PortCollection(bool deserializing) : base(deserializing) { }
    33     protected PortCollection(PortCollection original, Cloner cloner) : base(original, cloner) { }
    34     public PortCollection() : base() { }
    35     public PortCollection(int capacity) : base(capacity) { }
    36     public PortCollection(IEnumerable<IPort> collection) : base(collection) { }
     40    protected PortCollection(PortCollection original, Cloner cloner)
     41      : base(original, cloner) {
     42      if (!cloner.ClonedObjectRegistered(original.node))
     43        // NOTE: cannot clone port collection alone if referenced node is not cloned
     44        throw new InvalidOperationException("Node of port collection is not cloned.");
     45      node = cloner.Clone(original.node);
     46    }
     47    public PortCollection(INode node)
     48      : base() {
     49      this.node = node;
     50    }
     51    public PortCollection(INode node, int capacity)
     52      : base(capacity) {
     53      this.node = node;
     54    }
     55    public PortCollection(INode node, IEnumerable<IPort> collection)
     56      : base(collection) {
     57      this.node = node;
     58    }
    3759
    3860    public override IDeepCloneable Clone(Cloner cloner) { return new PortCollection(this, cloner); }
     61
     62    protected override void OnItemsAdded(IEnumerable<IPort> items) {
     63      foreach (var p in items)
     64        p.Node = node;
     65      base.OnItemsAdded(items);
     66    }
     67    protected override void OnItemsRemoved(IEnumerable<IPort> items) {
     68      foreach (var p in items)
     69        p.Node = null;
     70      base.OnItemsRemoved(items);
     71    }
     72    protected override void OnItemsReplaced(IEnumerable<IPort> items, IEnumerable<IPort> oldItems) {
     73      foreach (var p in oldItems)
     74        p.Node = null;
     75      foreach (var p in items)
     76        p.Node = node;
     77      base.OnItemsReplaced(items, oldItems);
     78    }
     79    protected override void OnCollectionReset(IEnumerable<IPort> items, IEnumerable<IPort> oldItems) {
     80      foreach (var p in oldItems)
     81        p.Node = null;
     82      foreach (var p in items)
     83        p.Node = node;
     84      base.OnCollectionReset(items, oldItems);
     85    }
    3986  }
    4087}
Note: See TracChangeset for help on using the changeset viewer.