Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis Refactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs @ 5551

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

Updated year of copyrights (#1406)

File size: 7.5 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.Collections.Generic;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using Netron.Diagramming.Core;
28
29namespace HeuristicLab.Operators.Views.GraphVisualization {
30  [StorableClass]
31  internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
32    [Storable]
33    private List<string> labels;
34
35    [StorableConstructor]
36    protected OperatorShapeInfo(bool deserializing) : base(deserializing) { }
37    protected OperatorShapeInfo(OperatorShapeInfo original, Cloner cloner)
38      : base(original, cloner) {
39      collapsed = original.collapsed;
40      color = original.color;
41      lineColor = original.lineColor;
42      lineWidth = original.lineWidth;
43      title = original.title;
44      if (original.icon != null) icon = (Bitmap)original.icon.Clone();
45
46      connectorNames = new List<string>(original.connectorNames);
47      labels = new List<string>(original.labels);
48    }
49    public override IDeepCloneable Clone(Cloner cloner) {
50      return new OperatorShapeInfo(this, cloner);
51    }
52
53    public OperatorShapeInfo()
54      : base(typeof(OperatorShape)) {
55      this.connectorNames = new List<string>();
56      this.labels = new List<string>();
57    }
58
59    public OperatorShapeInfo(IEnumerable<string> connectorNames)
60      : this() {
61      foreach (string connectorName in connectorNames)
62        this.connectorNames.Add(connectorName);
63    }
64
65    public OperatorShapeInfo(IEnumerable<string> connectorNames, IEnumerable<string> labels)
66      : this(connectorNames) {
67      foreach (string label in labels)
68        this.labels.Add(label);
69    }
70
71    public void AddConnector(string connectorName) {
72      if (!this.connectorNames.Contains(connectorName)) {
73        this.connectorNames.Add(connectorName);
74        this.OnChanged();
75      }
76    }
77
78    public void RemoveConnector(string connectorName) {
79      if (this.connectorNames.Contains(connectorName)) {
80        this.connectorNames.Remove(connectorName);
81        this.OnChanged();
82      }
83    }
84
85    public void UpdateLabels(IEnumerable<string> labels) {
86      this.labels = new List<string>(labels);
87      this.OnChanged();
88    }
89
90    [Storable]
91    private List<string> connectorNames;
92    public override IEnumerable<string> Connectors {
93      get { return this.connectorNames; }
94    }
95
96    [Storable]
97    private bool collapsed;
98    public bool Collapsed {
99      get { return this.collapsed; }
100      set {
101        if (this.collapsed != value) {
102          this.collapsed = value;
103          this.OnChanged();
104        }
105      }
106    }
107
108    [Storable]
109    private string title;
110    public string Title {
111      get { return this.title; }
112      set {
113        if (this.title != value) {
114          this.title = value;
115          this.OnChanged();
116        }
117      }
118    }
119
120    [Storable]
121    private Color color;
122    public Color Color {
123      get { return this.color; }
124      set {
125        if (this.color != value) {
126          this.color = value;
127          this.OnChanged();
128        }
129      }
130    }
131
132    [Storable]
133    private Color lineColor;
134    public Color LineColor {
135      get { return this.lineColor; }
136      set {
137        if (this.lineColor != value) {
138          this.lineColor = value;
139          this.OnChanged();
140        }
141      }
142    }
143
144    [Storable]
145    private float lineWidth;
146    public float LineWidth {
147      get { return this.lineWidth; }
148      set {
149        if (this.lineWidth != value) {
150          this.lineWidth = value;
151          this.OnChanged();
152        }
153      }
154    }
155
156    private Bitmap icon;
157    public Bitmap Icon {
158      get { return this.icon; }
159      set {
160        if (this.icon != value) {
161          this.icon = value;
162          this.OnChanged();
163        }
164      }
165    }
166
167    public override IShape CreateShape() {
168      OperatorShape shape = (OperatorShape)base.CreateShape();
169      shape.Title = this.Title;
170      shape.Color = this.Color;
171      shape.LineColor = this.LineColor;
172      shape.LineWidth = this.LineWidth;
173      shape.Icon = this.Icon;
174      shape.Collapsed = this.Collapsed;
175      foreach (string connectorName in this.connectorNames)
176        if (connectorName != OperatorShapeInfoFactory.SuccessorConnector && connectorName != OperatorShapeInfoFactory.PredecessorConnector)
177          shape.AddConnector(connectorName);
178
179      shape.UpdateLabels(this.labels);
180      return shape;
181    }
182
183    public override void UpdateShape(IShape shape) {
184      base.UpdateShape(shape);
185      OperatorShape operatorShape = (OperatorShape)shape;
186      operatorShape.Title = this.Title;
187      operatorShape.Color = this.Color;
188      operatorShape.LineColor = this.LineColor;
189      operatorShape.LineWidth = this.LineWidth;
190      operatorShape.Icon = this.Icon;
191      operatorShape.Collapsed = this.Collapsed;
192
193      int i = 0;
194      int j = 0;
195      //remove old connectors and skip correct connectors
196      List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
197      while (i < this.connectorNames.Count && j < oldConnectorNames.Count) {
198        if (connectorNames[i] == OperatorShapeInfoFactory.SuccessorConnector ||
199          connectorNames[i] == OperatorShapeInfoFactory.PredecessorConnector)
200          i++;
201        else if (oldConnectorNames[j] == OperatorShapeInfoFactory.SuccessorConnector ||
202          oldConnectorNames[j] == OperatorShapeInfoFactory.PredecessorConnector)
203          j++;
204        else if (this.connectorNames[i] != oldConnectorNames[j]) {
205          operatorShape.RemoveConnector(oldConnectorNames[j]);
206          j++;
207        } else {
208          i++;
209          j++;
210        }
211      }
212      //remove remaining old connectors
213      for (; j < oldConnectorNames.Count; j++)
214        operatorShape.RemoveConnector(oldConnectorNames[j]);
215
216      //add new connectors except successor and connector
217      for (; i < this.connectorNames.Count; i++)
218        if (this.connectorNames[i] != OperatorShapeInfoFactory.SuccessorConnector && this.connectorNames[i] != OperatorShapeInfoFactory.PredecessorConnector)
219          operatorShape.AddConnector(this.connectorNames[i]);
220
221      operatorShape.UpdateLabels(this.labels);
222    }
223
224    public override void UpdateShapeInfo(IShape shape) {
225      base.UpdateShapeInfo(shape);
226      OperatorShape operatorShape = (OperatorShape)shape;
227      this.Title = operatorShape.Title;
228      this.Color = operatorShape.Color;
229      this.LineColor = operatorShape.LineColor;
230      this.LineWidth = operatorShape.LineWidth;
231      this.Icon = operatorShape.Icon;
232      this.Collapsed = operatorShape.Collapsed;
233
234      //TODO update Connector and labels;
235    }
236  }
237}
Note: See TracBrowser for help on using the repository browser.