Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.0/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/GraphVisualizationInfo.cs @ 7749

Last change on this file since 7749 was 3742, checked in by gkronber, 14 years ago

Fixed GPL license headers and deleted files which are not referenced by projects. #893

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 System.Text;
26using HeuristicLab.Core;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.Collections;
29using HeuristicLab.Common;
30
31namespace HeuristicLab.Operators.Views.GraphVisualization {
32  [StorableClass]
33  public class GraphVisualizationInfo : DeepCloneable, IGraphVisualizationInfo {
34    public GraphVisualizationInfo() {
35      this.shapeInfos = new ObservableSet<IShapeInfo>();
36      this.connectionInfos = new ObservableSet<IConnectionInfo>();
37    }
38    #region IGraphVisualizationInfo Members
39    [Storable]
40    private IShapeInfo initialShape;
41    public virtual IShapeInfo InitialShape {
42      get { return this.initialShape; }
43      set {
44        if (this.initialShape != value) {
45          this.initialShape = value;
46          this.OnInitialShapeChanged();
47        }
48      }
49    }
50
51    [Storable]
52    protected ObservableSet<IShapeInfo> shapeInfos;
53    public INotifyObservableCollectionItemsChanged<IShapeInfo> ObserveableShapeInfos {
54      get { return shapeInfos; }
55    }
56    public IEnumerable<IShapeInfo> ShapeInfos {
57      get { return shapeInfos; }
58    }
59
60    [Storable]
61    protected ObservableSet<IConnectionInfo> connectionInfos;
62    public INotifyObservableCollectionItemsChanged<IConnectionInfo> ObservableConnectionInfos {
63      get { return connectionInfos; }
64    }
65    public IEnumerable<IConnectionInfo> ConnectionInfos {
66      get { return connectionInfos; }
67    }
68
69    public virtual void AddShapeInfo(IShapeInfo shapeInfo) {
70      this.shapeInfos.Add(shapeInfo);
71    }
72    public virtual void RemoveShapeInfo(IShapeInfo shapeInfo) {
73      this.shapeInfos.Remove(shapeInfo);
74      this.connectionInfos.RemoveWhere(c => c.From == shapeInfo);
75      this.connectionInfos.RemoveWhere(c => c.To == shapeInfo);
76    }
77
78    public virtual void AddConnectionInfo(IConnectionInfo connectionInfo) {
79      this.connectionInfos.Add(connectionInfo);
80    }
81    public virtual void RemoveConnectionInfo(IConnectionInfo connectionInfo) {
82      this.connectionInfos.Remove(connectionInfo);
83    }
84
85    public IEnumerable<IConnectionInfo> GetConnectionInfos(IShapeInfo shapeInfo) {
86      return this.ConnectionInfos.Where(c => c.From == shapeInfo || c.To == shapeInfo);
87    }
88    public IEnumerable<IConnectionInfo> GetConnectionInfos(IShapeInfo shapeInfo, string connector) {
89      return this.ConnectionInfos.Where(c => (c.From == shapeInfo && c.ConnectorFrom == connector) ||
90        (c.To == shapeInfo && c.ConnectorTo == connector));
91    }
92
93    public event EventHandler InitialShapeChanged;
94    protected virtual void OnInitialShapeChanged() {
95      EventHandler handler = this.InitialShapeChanged;
96      if (handler != null)
97        this.InitialShapeChanged(this, EventArgs.Empty);
98    }
99    #endregion
100
101    public override IDeepCloneable Clone(Cloner cloner) {
102      GraphVisualizationInfo clone = (GraphVisualizationInfo)base.Clone(cloner);
103      clone.shapeInfos = new ObservableSet<IShapeInfo>(this.shapeInfos.Select(x => (IShapeInfo)cloner.Clone(x)));
104      clone.connectionInfos = new ObservableSet<IConnectionInfo>(this.connectionInfos.Select(x => (IConnectionInfo)cloner.Clone(x)));
105      if (this.initialShape != null)
106        clone.initialShape = (IShapeInfo)this.initialShape.Clone(cloner);
107      return clone;
108    }
109  }
110}
Note: See TracBrowser for help on using the repository browser.