Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9283 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

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