Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs @ 3514

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