[2853] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Drawing;
|
---|
[4068] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2853] | 27 | using Netron.Diagramming.Core;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Operators.Views.GraphVisualization {
|
---|
[3017] | 30 | [StorableClass]
|
---|
[3386] | 31 | public abstract class ShapeInfo : DeepCloneable, IShapeInfo {
|
---|
[4722] | 32 | [StorableConstructor]
|
---|
| 33 | protected ShapeInfo(bool deserializing) : base() { }
|
---|
| 34 | protected ShapeInfo(ShapeInfo original, Cloner cloner)
|
---|
| 35 | : base(original, cloner) {
|
---|
| 36 | shapeType = original.shapeType;
|
---|
| 37 | location = original.location;
|
---|
[2968] | 38 | }
|
---|
[2934] | 39 |
|
---|
[2853] | 40 | protected ShapeInfo(Type shapeType) {
|
---|
| 41 | if (!typeof(IShape).IsAssignableFrom(shapeType))
|
---|
| 42 | throw new ArgumentException("The passed shape type " + shapeType + " must be derived from IShape.");
|
---|
| 43 | this.shapeType = shapeType;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[2934] | 46 | [Storable]
|
---|
[2853] | 47 | private Type shapeType;
|
---|
| 48 | public Type ShapeType {
|
---|
| 49 | get { return this.shapeType; }
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[2934] | 52 | [Storable]
|
---|
[2853] | 53 | private Point location;
|
---|
| 54 | public Point Location {
|
---|
| 55 | get { return this.location; }
|
---|
| 56 | set {
|
---|
| 57 | if (this.location != value) {
|
---|
| 58 | this.location = value;
|
---|
| 59 | this.OnChanged();
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[3386] | 64 | public abstract IEnumerable<string> Connectors { get; }
|
---|
| 65 |
|
---|
[2968] | 66 | public event EventHandler Changed;
|
---|
[3386] | 67 | protected virtual void OnChanged() {
|
---|
| 68 | EventHandler handler = this.Changed;
|
---|
[4722] | 69 | if (handler != null) this.Changed(this, EventArgs.Empty);
|
---|
[2853] | 70 | }
|
---|
| 71 |
|
---|
| 72 | public virtual IShape CreateShape() {
|
---|
| 73 | IShape shape = (IShape)Activator.CreateInstance(this.shapeType);
|
---|
[2893] | 74 | shape.Tag = this;
|
---|
[2853] | 75 | shape.Location = this.Location;
|
---|
| 76 | return shape;
|
---|
| 77 | }
|
---|
[2861] | 78 |
|
---|
| 79 | public virtual void UpdateShape(IShape shape) {
|
---|
| 80 | shape.Location = this.Location;
|
---|
| 81 | }
|
---|
[2968] | 82 |
|
---|
[3386] | 83 | public virtual void UpdateShapeInfo(IShape shape) {
|
---|
| 84 | this.Location = shape.Location;
|
---|
| 85 | }
|
---|
[2853] | 86 | }
|
---|
| 87 | }
|
---|