#region License Information
/* HeuristicLab
* Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using HeuristicLab.Collections;
using HeuristicLab.Common;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Operators.Views.GraphVisualization {
[StorableType("BCD0386A-465C-4A16-8A05-04370A403F6D")]
public class GraphVisualizationInfo : DeepCloneable, IGraphVisualizationInfo {
[StorableConstructor]
protected GraphVisualizationInfo(bool deserializing) : base() { }
protected GraphVisualizationInfo(GraphVisualizationInfo original, Cloner cloner)
: base(original, cloner) {
shapeInfos = new ObservableSet(original.shapeInfos.Select(x => cloner.Clone(x)));
connectionInfos = new ObservableSet(original.connectionInfos.Select(x => cloner.Clone(x)));
initialShape = cloner.Clone(original.initialShape);
}
public override IDeepCloneable Clone(Cloner cloner) {
return new GraphVisualizationInfo(this, cloner);
}
public GraphVisualizationInfo()
: base() {
this.shapeInfos = new ObservableSet();
this.connectionInfos = new ObservableSet();
}
#region IGraphVisualizationInfo Members
[Storable]
private IShapeInfo initialShape;
public virtual IShapeInfo InitialShape {
get { return this.initialShape; }
set {
if (this.initialShape != value) {
this.initialShape = value;
this.OnInitialShapeChanged();
}
}
}
[Storable]
protected ObservableSet shapeInfos;
public INotifyObservableCollectionItemsChanged ObserveableShapeInfos {
get { return shapeInfos; }
}
public IEnumerable ShapeInfos {
get { return shapeInfos; }
}
[Storable]
protected ObservableSet connectionInfos;
public INotifyObservableCollectionItemsChanged ObservableConnectionInfos {
get { return connectionInfos; }
}
public IEnumerable ConnectionInfos {
get { return connectionInfos; }
}
public virtual void AddShapeInfo(IShapeInfo shapeInfo) {
this.shapeInfos.Add(shapeInfo);
}
public virtual void RemoveShapeInfo(IShapeInfo shapeInfo) {
this.shapeInfos.Remove(shapeInfo);
this.connectionInfos.RemoveWhere(c => c.From == shapeInfo);
this.connectionInfos.RemoveWhere(c => c.To == shapeInfo);
}
public virtual void AddConnectionInfo(IConnectionInfo connectionInfo) {
this.connectionInfos.Add(connectionInfo);
}
public virtual void RemoveConnectionInfo(IConnectionInfo connectionInfo) {
this.connectionInfos.Remove(connectionInfo);
}
public IEnumerable GetConnectionInfos(IShapeInfo shapeInfo) {
return this.ConnectionInfos.Where(c => c.From == shapeInfo || c.To == shapeInfo);
}
public IEnumerable GetConnectionInfos(IShapeInfo shapeInfo, string connector) {
return this.ConnectionInfos.Where(c => (c.From == shapeInfo && c.ConnectorFrom == connector) ||
(c.To == shapeInfo && c.ConnectorTo == connector));
}
public event EventHandler InitialShapeChanged;
protected virtual void OnInitialShapeChanged() {
EventHandler handler = this.InitialShapeChanged;
if (handler != null)
this.InitialShapeChanged(this, EventArgs.Empty);
}
#endregion
}
}