Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/08/14 03:27:24 (10 years ago)
Author:
swagner
Message:

#2205: Worked on optimization networks

File:
1 edited

Legend:

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

    r11421 r11423  
    3434    }
    3535
    36     [Storable]
    37     private INode node;
    38     public INode Node {
    39       get { return node; }
     36    private INode parent;
     37    public INode Parent {
     38      get { return parent; }
    4039      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;
     40        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.");
     46          DeregisterParentEvents();
     47          parent = value;
     48          RegisterParentEvents();
     49          OnToStringChanged();
     50        }
    4651      }
    4752    }
     
    4954    [StorableConstructor]
    5055    protected Port(bool deserializing) : base(deserializing) { }
    51     protected Port(Port original, Cloner cloner)
    52       : base(original, cloner) {
    53       node = (INode)cloner.GetClone(original.node);  // NOTE: original node is NOT automatically cloned
    54     }
     56    protected Port(Port original, Cloner cloner) : base(original, cloner) { }
    5557    protected Port() : base("Port") { }
    5658    protected Port(string name) : base(name) { }
    5759    protected Port(string name, string description) : base(name, description) { }
     60
     61    public override string ToString() {
     62      if (parent != null) {
     63        return string.Concat(parent.ToString(), " -> ", base.ToString());
     64      }
     65      return base.ToString();
     66    }
     67
     68    #region Parent Events
     69    protected virtual void RegisterParentEvents() {
     70      if (parent != null) {
     71        parent.ToStringChanged += Parent_ToStringChanged;
     72      }
     73    }
     74    protected virtual void DeregisterParentEvents() {
     75      if (parent != null) {
     76        parent.ToStringChanged -= Parent_ToStringChanged;
     77      }
     78    }
     79    void Parent_ToStringChanged(object sender, EventArgs e) {
     80      OnToStringChanged();
     81    }
     82    #endregion
    5883  }
    5984}
Note: See TracChangeset for help on using the changeset viewer.