Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11431


Ignore:
Timestamp:
10/09/14 03:10:16 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

Location:
branches/OptimizationNetworks
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/InputPortView.cs

    r11423 r11431  
    3939    }
    4040
     41    private void UpdateOutputPortTextBoxText() {
     42      if ((Content == null) || (Content.OutputPort == null)) {
     43        outputPortTextBox.Text = string.Empty;
     44      } else {
     45        outputPortTextBox.Text = Content.OutputPort.Path + "." + Content.OutputPort.ToString();
     46      }
     47    }
     48
    4149    protected override void DeregisterContentEvents() {
    4250      Content.OutputPortChanged -= Content_OutputPortChanged;
    4351      base.DeregisterContentEvents();
    4452    }
    45 
    4653    protected override void RegisterContentEvents() {
    4754      base.RegisterContentEvents();
     
    5158    protected override void OnContentChanged() {
    5259      base.OnContentChanged();
    53       outputPortTextBox.Text = ((Content == null) || (Content.OutputPort == null)) ? string.Empty : Content.OutputPort.ToString();
     60      UpdateOutputPortTextBoxText();
    5461    }
    5562
     
    5865      outputPortTextBox.Enabled = Content != null && !ReadOnly;
    5966    }
     67
    6068    protected virtual void Content_OutputPortChanged(object sender, EventArgs e) {
    6169      if (InvokeRequired)
    6270        Invoke(new EventHandler(Content_OutputPortChanged), sender, e);
    6371      else {
    64         outputPortTextBox.Text = Content.OutputPort == null ? string.Empty : Content.OutputPort.ToString();
     72        UpdateOutputPortTextBoxText();
    6573      }
    6674    }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/NodeCollectionView.cs

    r11409 r11431  
    4747      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    4848        try {
    49           return (INode)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     49          var n = (INode)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     50          n.Name = GetUniqueName(n.Name);
     51          return n;
    5052        }
    5153        catch (Exception ex) {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks.Views/3.3/PortCollectionView.cs

    r11409 r11431  
    4747      if (typeSelectorDialog.ShowDialog(this) == DialogResult.OK) {
    4848        try {
    49           return (IPort)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     49          var p = (IPort)typeSelectorDialog.TypeSelector.CreateInstanceOfSelectedType();
     50          p.Name = GetUniqueName(p.Name);
     51          return p;
    5052        }
    5153        catch (Exception ex) {
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IPort.cs

    r11423 r11431  
    2121
    2222using HeuristicLab.Core;
     23using System;
    2324
    2425namespace HeuristicLab.Optimization.Networks {
    2526  public interface IPort : INamedItem {
    2627    INode Parent { get; set; }
     28    string Path { get; }
     29
     30    event EventHandler PathChanged;
    2731  }
    2832}
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs

    r11421 r11431  
    9292    }
    9393    protected void OutputInputPort_ValueSent(object sender, OutputInputPortEventArgs<TIn, TOut> e) {
    94       var value = (TIn)e.Value.Clone();
     94      var value = e.Value;
     95      if (value != null)
     96        value = (TIn)value.Clone();
    9597      Value = value;
    9698      e.Result = OnValueReceived(value);
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs

    r11423 r11431  
    8888      if (outputPort != null) {
    8989        outputPort.ValueChanged += OutputPort_ValueChanged;
    90         outputPort.ToStringChanged += OutputPort_ToStringChanged;
     90        outputPort.PathChanged += OutputPort_PathChanged;
    9191      }
    9292    }
     
    9494      if (outputPort != null) {
    9595        outputPort.ValueChanged -= OutputPort_ValueChanged;
    96         outputPort.ToStringChanged -= OutputPort_ToStringChanged;
     96        outputPort.PathChanged -= OutputPort_PathChanged;
    9797      }
    9898    }
    9999    protected void OutputPort_ValueChanged(object sender, EventArgs e) {
    100       Value = (T)OutputPort.Value.Clone();
     100      var value = OutputPort.Value;
     101      if (value != null)
     102        value = (T)value.Clone();
     103      Value = value;
    101104      //DISCUSS: clone value?
    102105      //DISCUSS: switch threads to decouple value propagation and to make communication asynchronous -> should be done in Node?
    103106    }
    104     protected void OutputPort_ToStringChanged(object sender, EventArgs e) {
     107    protected void OutputPort_PathChanged(object sender, EventArgs e) {
    105108      OnOutputPortChanged();
    106109    }
  • branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs

    r11423 r11431  
    3838      get { return parent; }
    3939      set {
     40        // NOTE: never call setter directly as the Parent property is set by the node which contains the port
    4041        if (value != parent) {
    41           // NOTE: never call setter directly as the Parent property is set by the node which contains the port
    42           if ((value != null) && !value.Ports.Contains(this))
    43             throw new InvalidOperationException("Port is not contained in port collection of node.");
    44           if ((value == null) && parent.Ports.Contains(this))
    45             throw new InvalidOperationException("Port is still contained in port collection of node.");
    4642          DeregisterParentEvents();
    4743          parent = value;
    4844          RegisterParentEvents();
    49           OnToStringChanged();
     45          OnPathChanged();
    5046        }
     47      }
     48    }
     49    public string Path {
     50      get {
     51        return parent != null ? parent.Name : string.Empty;
    5152      }
    5253    }
     
    5960    protected Port(string name, string description) : base(name, description) { }
    6061
    61     public override string ToString() {
    62       if (parent != null) {
    63         return string.Concat(parent.ToString(), " -> ", base.ToString());
    64       }
    65       return base.ToString();
     62    public event EventHandler PathChanged;
     63    protected virtual void OnPathChanged() {
     64      var handler = PathChanged;
     65      if (handler != null) handler(this, EventArgs.Empty);
    6666    }
    6767
     
    6969    protected virtual void RegisterParentEvents() {
    7070      if (parent != null) {
    71         parent.ToStringChanged += Parent_ToStringChanged;
     71        parent.NameChanged += Parent_NameChanged;
    7272      }
    7373    }
    7474    protected virtual void DeregisterParentEvents() {
    7575      if (parent != null) {
    76         parent.ToStringChanged -= Parent_ToStringChanged;
     76        parent.NameChanged -= Parent_NameChanged;
    7777      }
    7878    }
    79     void Parent_ToStringChanged(object sender, EventArgs e) {
    80       OnToStringChanged();
     79    void Parent_NameChanged(object sender, EventArgs e) {
     80      OnPathChanged();
    8181    }
    8282    #endregion
Note: See TracChangeset for help on using the changeset viewer.