source: trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/ShapeInfo.cs @ 5445

Last change on this file since 5445 was 5445, checked in by swagner, 9 years ago

Updated year of copyrights (#1406)

File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using HeuristicLab.Common;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using Netron.Diagramming.Core;
28
29namespace HeuristicLab.Operators.Views.GraphVisualization {
30  [StorableClass]
31  public abstract class ShapeInfo : DeepCloneable, IShapeInfo {
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;
38    }
39
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
46    [Storable]
47    private Type shapeType;
48    public Type ShapeType {
49      get { return this.shapeType; }
50    }
51
52    [Storable]
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
64    public abstract IEnumerable<string> Connectors { get; }
65
66    public event EventHandler Changed;
67    protected virtual void OnChanged() {
68      EventHandler handler = this.Changed;
69      if (handler != null) this.Changed(this, EventArgs.Empty);
70    }
71
72    public virtual IShape CreateShape() {
73      IShape shape = (IShape)Activator.CreateInstance(this.shapeType);
74      shape.Tag = this;
75      shape.Location = this.Location;
76      return shape;
77    }
78
79    public virtual void UpdateShape(IShape shape) {
80      shape.Location = this.Location;
81    }
82
83    public virtual void UpdateShapeInfo(IShape shape) {
84      this.Location = shape.Location;
85    }
86  }
87}
Note: See TracBrowser for help on using the repository browser.