Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11248 for trunk/sources


Ignore:
Timestamp:
07/31/14 00:08:24 (10 years ago)
Author:
bburlacu
Message:

#2223: Added item attributes and firing of events in the DirectedGraph.

Location:
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Arc.cs

    r11241 r11248  
    2525
    2626namespace HeuristicLab.Core {
    27   /// <summary>
    28   /// An arc that can have a weight, a label, and a data object for holding additional info
    29   /// </summary>
     27  [Item("Arc", "A graph arc connecting two graph vertices, that can have a weight, label, and data object for holding additional info")]
    3028  [StorableClass]
    3129  public class Arc : Item, IArc {
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs

    r11241 r11248  
    7171    private void AfterDeserialization() {
    7272      foreach (var vertex in vertices) {
    73         vertex.ArcAdded += OnArcAdded;
    74         vertex.ArcRemoved += OnArcRemoved;
     73        vertex.ArcAdded += OnVertexArcAdded;
     74        vertex.ArcRemoved += OnVertexArcRemoved;
    7575      }
    7676
     
    9191      vertices.Add(vertex);
    9292      // register event handlers
    93       vertex.ArcAdded += OnArcAdded;
    94       vertex.ArcRemoved += OnArcRemoved;
     93      vertex.ArcAdded += OnVertexArcAdded;
     94      vertex.ArcRemoved += OnVertexArcRemoved;
     95      OnVertedAdded(this, EventArgs.Empty);
    9596    }
    9697
     
    102103        RemoveArc(arc);
    103104      // deregister event handlers
    104       vertex.ArcAdded -= OnArcAdded;
    105       vertex.ArcRemoved -= OnArcRemoved;
     105      vertex.ArcAdded -= OnVertexArcAdded;
     106      vertex.ArcRemoved -= OnVertexArcRemoved;
     107      OnVertexRemoved(this, EventArgs.Empty); // do not pass the removed vertex in the event as we don't need it anymore
    106108    }
    107109
     
    118120      target.AddArc(arc);
    119121      arcs.Add(arc);
     122      OnArcAdded(this, EventArgs.Empty);
    120123    }
    121124
     
    126129      source.RemoveArc(arc);
    127130      target.RemoveArc(arc);
     131      OnArcRemoved(this, EventArgs.Empty);
    128132    }
    129133
    130     public event EventHandler ArcAdded;
    131     protected virtual void OnArcAdded(object sender, EventArgs<IArc> args) {
     134    protected virtual void OnVertexArcAdded(object sender, EventArgs<IArc> args) {
    132135      var arc = args.Value;
    133       // the ArcAdded event is fired by a vertex when an arc from or towards another vertex is added to his list of connections
     136      // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections
    134137      // because the arc is added in both directions by both the source and the target, this event will get fired twice
    135138      // here, we only want to add the arc once, so if its already contained, we return without complaining
     
    138141    }
    139142
    140 
    141     public event EventHandler ArcRemoved;
    142     protected virtual void OnArcRemoved(object sender, EventArgs<IArc> args) {
     143    protected virtual void OnVertexArcRemoved(object sender, EventArgs<IArc> args) {
    143144      var arc = args.Value;
    144145      if (!arcs.Contains(arc)) return; // the same rationale as above
     
    148149    // events
    149150    public event EventHandler VertexAdded;
     151    protected virtual void OnVertedAdded(object sender, EventArgs args) {
     152      var added = VertexAdded;
     153      if (added != null)
     154        added(sender, args);
     155    }
     156
    150157    public event EventHandler VertexRemoved;
     158    protected virtual void OnVertexRemoved(object sender, EventArgs args) {
     159      var removed = VertexRemoved;
     160      if (removed != null)
     161        removed(sender, args);
     162    }
     163
     164    public event EventHandler ArcAdded;
     165    protected virtual void OnArcAdded(object sender, EventArgs args) {
     166      var added = ArcAdded;
     167      if (added != null)
     168        added(sender, args);
     169    }
     170
     171    public event EventHandler ArcRemoved;
     172    protected virtual void OnArcRemoved(object sender, EventArgs args) {
     173      var removed = ArcRemoved;
     174      if (removed != null)
     175        removed(sender, args);
     176    }
    151177  }
    152178}
  • trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Vertex.cs

    r11241 r11248  
    2727
    2828namespace HeuristicLab.Core {
     29  [Item("Vertex", "An object representing a vertex in the graph. It can have a text label, a weight, and an additional data object.")]
    2930  [StorableClass]
    3031  public class Vertex : Item, IVertex {
Note: See TracChangeset for help on using the changeset viewer.