[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 {
|
---|
[2934] | 32 | private ShapeInfo() {
|
---|
[2968] | 33 | }
|
---|
[2934] | 34 |
|
---|
[2853] | 35 | protected ShapeInfo(Type shapeType) {
|
---|
| 36 | if (!typeof(IShape).IsAssignableFrom(shapeType))
|
---|
| 37 | throw new ArgumentException("The passed shape type " + shapeType + " must be derived from IShape.");
|
---|
| 38 | this.shapeType = shapeType;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[2934] | 41 | [Storable]
|
---|
[2853] | 42 | private Type shapeType;
|
---|
| 43 | public Type ShapeType {
|
---|
| 44 | get { return this.shapeType; }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[2934] | 47 | [Storable]
|
---|
[2853] | 48 | private Point location;
|
---|
| 49 | public Point Location {
|
---|
| 50 | get { return this.location; }
|
---|
| 51 | set {
|
---|
| 52 | if (this.location != value) {
|
---|
| 53 | this.location = value;
|
---|
| 54 | this.OnChanged();
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[3386] | 59 | public abstract IEnumerable<string> Connectors { get; }
|
---|
| 60 |
|
---|
[2968] | 61 | public event EventHandler Changed;
|
---|
[3386] | 62 | protected virtual void OnChanged() {
|
---|
| 63 | EventHandler handler = this.Changed;
|
---|
| 64 | if (handler != null)
|
---|
[2934] | 65 | this.Changed(this, EventArgs.Empty);
|
---|
[2853] | 66 | }
|
---|
| 67 |
|
---|
| 68 | public virtual IShape CreateShape() {
|
---|
| 69 | IShape shape = (IShape)Activator.CreateInstance(this.shapeType);
|
---|
[2893] | 70 | shape.Tag = this;
|
---|
[2853] | 71 | shape.Location = this.Location;
|
---|
| 72 | return shape;
|
---|
| 73 | }
|
---|
[2861] | 74 |
|
---|
| 75 | public virtual void UpdateShape(IShape shape) {
|
---|
| 76 | shape.Location = this.Location;
|
---|
| 77 | }
|
---|
[2968] | 78 |
|
---|
[3386] | 79 | public virtual void UpdateShapeInfo(IShape shape) {
|
---|
| 80 | this.Location = shape.Location;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
[2968] | 83 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[3386] | 84 | ShapeInfo clone = (ShapeInfo)base.Clone(cloner);
|
---|
[2968] | 85 | clone.shapeType = this.shapeType;
|
---|
| 86 | clone.location = this.location;
|
---|
| 87 | return clone;
|
---|
| 88 | }
|
---|
[2853] | 89 | }
|
---|
| 90 | }
|
---|