Changeset 11248 for trunk/sources/HeuristicLab.Core/3.3/Collections
- Timestamp:
- 07/31/14 00:08:24 (10 years ago)
- 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 25 25 26 26 namespace 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")] 30 28 [StorableClass] 31 29 public class Arc : Item, IArc { -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/DirectedGraph.cs
r11241 r11248 71 71 private void AfterDeserialization() { 72 72 foreach (var vertex in vertices) { 73 vertex.ArcAdded += On ArcAdded;74 vertex.ArcRemoved += On ArcRemoved;73 vertex.ArcAdded += OnVertexArcAdded; 74 vertex.ArcRemoved += OnVertexArcRemoved; 75 75 } 76 76 … … 91 91 vertices.Add(vertex); 92 92 // register event handlers 93 vertex.ArcAdded += OnArcAdded; 94 vertex.ArcRemoved += OnArcRemoved; 93 vertex.ArcAdded += OnVertexArcAdded; 94 vertex.ArcRemoved += OnVertexArcRemoved; 95 OnVertedAdded(this, EventArgs.Empty); 95 96 } 96 97 … … 102 103 RemoveArc(arc); 103 104 // 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 106 108 } 107 109 … … 118 120 target.AddArc(arc); 119 121 arcs.Add(arc); 122 OnArcAdded(this, EventArgs.Empty); 120 123 } 121 124 … … 126 129 source.RemoveArc(arc); 127 130 target.RemoveArc(arc); 131 OnArcRemoved(this, EventArgs.Empty); 128 132 } 129 133 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) { 132 135 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 connections136 // the ArcAdded event is fired by a vertex when an arc from/to another vertex is added to its list of connections 134 137 // because the arc is added in both directions by both the source and the target, this event will get fired twice 135 138 // here, we only want to add the arc once, so if its already contained, we return without complaining … … 138 141 } 139 142 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) { 143 144 var arc = args.Value; 144 145 if (!arcs.Contains(arc)) return; // the same rationale as above … … 148 149 // events 149 150 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 150 157 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 } 151 177 } 152 178 } -
trunk/sources/HeuristicLab.Core/3.3/Collections/DirectedGraph/Vertex.cs
r11241 r11248 27 27 28 28 namespace 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.")] 29 30 [StorableClass] 30 31 public class Vertex : Item, IVertex {
Note: See TracChangeset
for help on using the changeset viewer.