Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4555 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 4.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Collections;
26using HeuristicLab.Common;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Operators.Views.GraphVisualization {
30  [StorableClass]
31  public class GraphVisualizationInfo : DeepCloneable, IGraphVisualizationInfo {
32    public GraphVisualizationInfo() {
33      this.shapeInfos = new ObservableSet<IShapeInfo>();
34      this.connectionInfos = new ObservableSet<IConnectionInfo>();
35    }
36    #region IGraphVisualizationInfo Members
37    [Storable]
38    private IShapeInfo initialShape;
39    public virtual IShapeInfo InitialShape {
40      get { return this.initialShape; }
41      set {
42        if (this.initialShape != value) {
43          this.initialShape = value;
44          this.OnInitialShapeChanged();
45        }
46      }
47    }
48
49    [Storable]
50    protected ObservableSet<IShapeInfo> shapeInfos;
51    public INotifyObservableCollectionItemsChanged<IShapeInfo> ObserveableShapeInfos {
52      get { return shapeInfos; }
53    }
54    public IEnumerable<IShapeInfo> ShapeInfos {
55      get { return shapeInfos; }
56    }
57
58    [Storable]
59    protected ObservableSet<IConnectionInfo> connectionInfos;
60    public INotifyObservableCollectionItemsChanged<IConnectionInfo> ObservableConnectionInfos {
61      get { return connectionInfos; }
62    }
63    public IEnumerable<IConnectionInfo> ConnectionInfos {
64      get { return connectionInfos; }
65    }
66
67    public virtual void AddShapeInfo(IShapeInfo shapeInfo) {
68      this.shapeInfos.Add(shapeInfo);
69    }
70    public virtual void RemoveShapeInfo(IShapeInfo shapeInfo) {
71      this.shapeInfos.Remove(shapeInfo);
72      this.connectionInfos.RemoveWhere(c => c.From == shapeInfo);
73      this.connectionInfos.RemoveWhere(c => c.To == shapeInfo);
74    }
75
76    public virtual void AddConnectionInfo(IConnectionInfo connectionInfo) {
77      this.connectionInfos.Add(connectionInfo);
78    }
79    public virtual void RemoveConnectionInfo(IConnectionInfo connectionInfo) {
80      this.connectionInfos.Remove(connectionInfo);
81    }
82
83    public IEnumerable<IConnectionInfo> GetConnectionInfos(IShapeInfo shapeInfo) {
84      return this.ConnectionInfos.Where(c => c.From == shapeInfo || c.To == shapeInfo);
85    }
86    public IEnumerable<IConnectionInfo> GetConnectionInfos(IShapeInfo shapeInfo, string connector) {
87      return this.ConnectionInfos.Where(c => (c.From == shapeInfo && c.ConnectorFrom == connector) ||
88        (c.To == shapeInfo && c.ConnectorTo == connector));
89    }
90
91    public event EventHandler InitialShapeChanged;
92    protected virtual void OnInitialShapeChanged() {
93      EventHandler handler = this.InitialShapeChanged;
94      if (handler != null)
95        this.InitialShapeChanged(this, EventArgs.Empty);
96    }
97    #endregion
98
99    public override IDeepCloneable Clone(Cloner cloner) {
100      GraphVisualizationInfo clone = (GraphVisualizationInfo)base.Clone(cloner);
101      clone.shapeInfos = new ObservableSet<IShapeInfo>(this.shapeInfos.Select(x => (IShapeInfo)cloner.Clone(x)));
102      clone.connectionInfos = new ObservableSet<IConnectionInfo>(this.connectionInfos.Select(x => (IConnectionInfo)cloner.Clone(x)));
103      if (this.initialShape != null)
104        clone.initialShape = (IShapeInfo)this.initialShape.Clone(cloner);
105      return clone;
106    }
107  }
108}
Note: See TracBrowser for help on using the repository browser.