Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4555 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 2.7 KB
Line 
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
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    private ShapeInfo() {
33    }
34
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
41    [Storable]
42    private Type shapeType;
43    public Type ShapeType {
44      get { return this.shapeType; }
45    }
46
47    [Storable]
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
59    public abstract IEnumerable<string> Connectors { get; }
60
61    public event EventHandler Changed;
62    protected virtual void OnChanged() {
63      EventHandler handler = this.Changed;
64      if (handler != null)
65        this.Changed(this, EventArgs.Empty);
66    }
67
68    public virtual IShape CreateShape() {
69      IShape shape = (IShape)Activator.CreateInstance(this.shapeType);
70      shape.Tag = this;
71      shape.Location = this.Location;
72      return shape;
73    }
74
75    public virtual void UpdateShape(IShape shape) {
76      shape.Location = this.Location;
77    }
78
79    public virtual void UpdateShapeInfo(IShape shape) {
80      this.Location = shape.Location;
81    }
82
83    public override IDeepCloneable Clone(Cloner cloner) {
84      ShapeInfo clone = (ShapeInfo)base.Clone(cloner);
85      clone.shapeType = this.shapeType;
86      clone.location = this.location;
87      return clone;
88    }
89  }
90}
Note: See TracBrowser for help on using the repository browser.