Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShapeInfo.cs @ 2935

Last change on this file since 2935 was 2935, checked in by mkommend, 15 years ago

added visual indication for operator breakpoints (ticket #867)

File size: 5.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.Linq;
25using System.Text;
26using HeuristicLab.Core;
27using System.Drawing;
28using Netron.Diagramming.Core;
29using System.Windows.Forms;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Operators.Views.GraphVisualization {
33  internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
34    [Storable]
35    private List<string> connectorNames;
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) && connectorName != "Successor") {
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 bool collapsed;
78    public bool Collapsed {
79      get { return this.collapsed; }
80      set {
81        if (this.collapsed != value) {
82          this.collapsed = value;
83          this.OnChanged();
84        }
85      }
86    }
87
88    [Storable]
89    private string title;
90    public string Title {
91      get { return this.title; }
92      set {
93        if (this.title != value) {
94          this.title = value;
95          this.OnChanged();
96        }
97      }
98    }
99
100    [Storable]
101    private Color color;
102    public Color Color {
103      get { return this.color; }
104      set {
105        if (this.color != value) {
106          this.color = value;
107          this.OnChanged();
108        }
109      }
110    }
111
112    [Storable]
113    private Color lineColor;
114    public Color LineColor {
115      get { return this.lineColor; }
116      set {
117        if (this.lineColor != value) {
118          this.lineColor = value;
119          this.OnChanged();
120        }
121      }
122    }
123
124    [Storable]
125    private float lineWidth;
126    public float LineWidth {
127      get { return this.lineWidth; }
128      set {
129        if (this.lineWidth != value) {
130          this.lineWidth = value;
131          this.OnChanged();
132        }
133      }
134    }
135
136    [Storable]
137    private Bitmap icon;
138    public Bitmap Icon {
139      get { return this.icon; }
140      set {
141        if (this.icon != value) {
142          this.icon = value;
143          this.OnChanged();
144        }
145      }
146    }
147
148    public override IShape CreateShape() {
149      OperatorShape shape = (OperatorShape)base.CreateShape();
150      shape.Title = this.Title;
151      shape.Color = this.Color;
152      shape.LineColor = this.LineColor;
153      shape.LineWidth = this.LineWidth;
154      shape.Icon = this.Icon;
155      shape.Collapsed = this.Collapsed;
156      foreach (string connectorName in this.connectorNames)
157        shape.AddConnector(connectorName);
158
159      shape.UpdateLabels(this.labels);
160      return shape;
161    }
162
163    public override void UpdateShape(IShape shape) {
164      base.UpdateShape(shape);
165      OperatorShape operatorShape = shape as OperatorShape;
166      if (operatorShape != null) {
167        operatorShape.Title = this.Title;
168        operatorShape.Color = this.Color;
169        operatorShape.LineColor = this.LineColor;
170        operatorShape.LineWidth = this.LineWidth;
171        operatorShape.Collapsed = this.Collapsed;
172
173        int i = 0;
174        int j = 0;
175        //remove old connectors and skip correct connectors
176        List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
177        while (i < this.connectorNames.Count && j < oldConnectorNames.Count) {
178          if (this.connectorNames[i] != oldConnectorNames[j]) {
179            operatorShape.RemoveConnector(oldConnectorNames[j]);
180          } else
181            i++;
182          j++;
183        }
184        //remove remaining old connectors
185        for (; j < oldConnectorNames.Count; j++)
186          operatorShape.RemoveConnector(oldConnectorNames[j]);
187
188        //add new connectors
189        for (; i < this.connectorNames.Count; i++)
190          operatorShape.AddConnector(this.connectorNames[i]);
191
192        operatorShape.UpdateLabels(this.labels);
193      }
194    }
195  }
196}
Note: See TracBrowser for help on using the repository browser.