Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/GraphVisualizationInfo.cs @ 3580

Last change on this file since 3580 was 3431, checked in by swagner, 15 years ago

Removed property ReadOnlyView (#969)

File size: 3.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Collections;
8using HeuristicLab.Common;
9
10namespace HeuristicLab.Operators.Views.GraphVisualization {
11  [StorableClass]
12  public class GraphVisualizationInfo : DeepCloneable, IGraphVisualizationInfo {
13    public GraphVisualizationInfo() {
14      this.shapeInfos = new ObservableSet<IShapeInfo>();
15      this.connectionInfos = new ObservableSet<IConnectionInfo>();
16    }
17    #region IGraphVisualizationInfo Members
18    [Storable]
19    private IShapeInfo initialShape;
20    public virtual IShapeInfo InitialShape {
21      get { return this.initialShape; }
22      set {
23        if (this.initialShape != value) {
24          this.initialShape = value;
25          this.OnInitialShapeChanged();
26        }
27      }
28    }
29
30    [Storable]
31    protected ObservableSet<IShapeInfo> shapeInfos;
32    public INotifyObservableCollectionItemsChanged<IShapeInfo> ObserveableShapeInfos {
33      get { return shapeInfos; }
34    }
35    public IEnumerable<IShapeInfo> ShapeInfos {
36      get { return shapeInfos; }
37    }
38
39    [Storable]
40    protected ObservableSet<IConnectionInfo> connectionInfos;
41    public INotifyObservableCollectionItemsChanged<IConnectionInfo> ObservableConnectionInfos {
42      get { return connectionInfos; }
43    }
44    public IEnumerable<IConnectionInfo> ConnectionInfos {
45      get { return connectionInfos; }
46    }
47
48    public virtual void AddShapeInfo(IShapeInfo shapeInfo) {
49      this.shapeInfos.Add(shapeInfo);
50    }
51    public virtual void RemoveShapeInfo(IShapeInfo shapeInfo) {
52      this.shapeInfos.Remove(shapeInfo);
53      this.connectionInfos.RemoveWhere(c => c.From == shapeInfo);
54      this.connectionInfos.RemoveWhere(c => c.To == shapeInfo);
55    }
56
57    public virtual void AddConnectionInfo(IConnectionInfo connectionInfo) {
58      this.connectionInfos.Add(connectionInfo);
59    }
60    public virtual void RemoveConnectionInfo(IConnectionInfo connectionInfo) {
61      this.connectionInfos.Remove(connectionInfo);
62    }
63
64    public IEnumerable<IConnectionInfo> GetConnectionInfos(IShapeInfo shapeInfo) {
65      return this.ConnectionInfos.Where(c => c.From == shapeInfo || c.To == shapeInfo);
66    }
67    public IEnumerable<IConnectionInfo> GetConnectionInfos(IShapeInfo shapeInfo, string connector) {
68      return this.ConnectionInfos.Where(c => (c.From == shapeInfo && c.ConnectorFrom == connector) ||
69        (c.To == shapeInfo && c.ConnectorTo == connector));
70    }
71
72    public event EventHandler InitialShapeChanged;
73    protected virtual void OnInitialShapeChanged() {
74      EventHandler handler = this.InitialShapeChanged;
75      if (handler != null)
76        this.InitialShapeChanged(this, EventArgs.Empty);
77    }
78    #endregion
79
80    public override IDeepCloneable Clone(Cloner cloner) {
81      GraphVisualizationInfo clone = (GraphVisualizationInfo)base.Clone(cloner);
82      clone.shapeInfos = new ObservableSet<IShapeInfo>(this.shapeInfos.Select(x => (IShapeInfo)cloner.Clone(x)));
83      clone.connectionInfos = new ObservableSet<IConnectionInfo>(this.connectionInfos.Select(x => (IConnectionInfo)cloner.Clone(x)));
84      if (this.initialShape != null)
85        clone.initialShape = (IShapeInfo)this.initialShape.Clone(cloner);
86      return clone;
87    }
88  }
89}
Note: See TracBrowser for help on using the repository browser.