1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Collections;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Persistence;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Operators.Views.GraphVisualization {
|
---|
30 | [StorableType("10aec1bc-e1c2-4f7c-920d-82acd7492ad0")]
|
---|
31 | public class GraphVisualizationInfo : DeepCloneable, IGraphVisualizationInfo {
|
---|
32 | [StorableConstructor]
|
---|
33 | protected GraphVisualizationInfo(StorableConstructorFlag 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() {
|
---|
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);
|
---|
84 | this.connectionInfos.RemoveWhere(c => c.From == shapeInfo);
|
---|
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 | }
|
---|