Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3353 was 3353, checked in by mkommend, 14 years ago

corrected image changes in operator graph visualization (ticket #867)

File size: 6.2 KB
RevLine 
[2853]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;
[2861]29using System.Windows.Forms;
[2934]30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[2853]31
32namespace HeuristicLab.Operators.Views.GraphVisualization {
[3017]33  [StorableClass]
[2934]34  internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
35    [Storable]
36    private List<string> connectorNames;
37    [Storable]
38    private List<string> labels;
[2853]39
40    public OperatorShapeInfo()
41      : base(typeof(OperatorShape)) {
[2861]42      this.connectorNames = new List<string>();
[2934]43      this.labels = new List<string>();
[2853]44    }
45
46    public OperatorShapeInfo(IEnumerable<string> connectorNames)
47      : this() {
48      foreach (string connectorName in connectorNames)
49        this.connectorNames.Add(connectorName);
50    }
51
[2934]52    public OperatorShapeInfo(IEnumerable<string> connectorNames, IEnumerable<string> labels)
53      : this(connectorNames) {
54      foreach (string label in labels)
55        this.labels.Add(label);
56    }
57
58    public void AddConnector(string connectorName) {
[2861]59      if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") {
60        this.connectorNames.Add(connectorName);
[2853]61        this.OnChanged();
[2861]62      }
[2853]63    }
64
[2934]65    public void RemoveConnector(string connectorName) {
[2861]66      if (this.connectorNames.Contains(connectorName)) {
67        this.connectorNames.Remove(connectorName);
[2853]68        this.OnChanged();
[2861]69      }
[2853]70    }
71
[2934]72    public void UpdateLabels(IEnumerable<string> labels) {
73      this.labels = new List<string>(labels);
74      this.OnChanged();
75    }
76
77    [Storable]
78    private bool collapsed;
79    public bool Collapsed {
80      get { return this.collapsed; }
81      set {
82        if (this.collapsed != value) {
83          this.collapsed = value;
84          this.OnChanged();
85        }
86      }
87    }
88
89    [Storable]
[2853]90    private string title;
91    public string Title {
92      get { return this.title; }
93      set {
94        if (this.title != value) {
95          this.title = value;
96          this.OnChanged();
97        }
98      }
99    }
100
[2934]101    [Storable]
102    private Color color;
103    public Color Color {
104      get { return this.color; }
[2853]105      set {
[2934]106        if (this.color != value) {
107          this.color = value;
[2853]108          this.OnChanged();
109        }
110      }
111    }
112
[2934]113    [Storable]
[2935]114    private Color lineColor;
115    public Color LineColor {
116      get { return this.lineColor; }
117      set {
118        if (this.lineColor != value) {
119          this.lineColor = value;
120          this.OnChanged();
121        }
122      }
123    }
124
125    [Storable]
126    private float lineWidth;
127    public float LineWidth {
128      get { return this.lineWidth; }
129      set {
130        if (this.lineWidth != value) {
131          this.lineWidth = value;
132          this.OnChanged();
133        }
134      }
135    }
136
[2934]137    private Bitmap icon;
138    public Bitmap Icon {
139      get { return this.icon; }
[2853]140      set {
[2934]141        if (this.icon != value) {
142          this.icon = value;
[2853]143          this.OnChanged();
144        }
145      }
146    }
147
148    public override IShape CreateShape() {
149      OperatorShape shape = (OperatorShape)base.CreateShape();
150      shape.Title = this.Title;
[2934]151      shape.Color = this.Color;
[2935]152      shape.LineColor = this.LineColor;
153      shape.LineWidth = this.LineWidth;
[2934]154      shape.Icon = this.Icon;
155      shape.Collapsed = this.Collapsed;
[2853]156      foreach (string connectorName in this.connectorNames)
157        shape.AddConnector(connectorName);
[2934]158
159      shape.UpdateLabels(this.labels);
[2853]160      return shape;
161    }
[2861]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;
[2934]168        operatorShape.Color = this.Color;
[2935]169        operatorShape.LineColor = this.LineColor;
170        operatorShape.LineWidth = this.LineWidth;
[3353]171        operatorShape.Icon = this.Icon;
[2934]172        operatorShape.Collapsed = this.Collapsed;
[2861]173
174        int i = 0;
175        int j = 0;
176        //remove old connectors and skip correct connectors
177        List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
178        while (i < this.connectorNames.Count && j < oldConnectorNames.Count) {
179          if (this.connectorNames[i] != oldConnectorNames[j]) {
180            operatorShape.RemoveConnector(oldConnectorNames[j]);
181          } else
182            i++;
183          j++;
184        }
[2934]185        //remove remaining old connectors
[2868]186        for (; j < oldConnectorNames.Count; j++)
[2861]187          operatorShape.RemoveConnector(oldConnectorNames[j]);
188
189        //add new connectors
190        for (; i < this.connectorNames.Count; i++)
191          operatorShape.AddConnector(this.connectorNames[i]);
[2934]192
193        operatorShape.UpdateLabels(this.labels);
[2861]194      }
195    }
[2968]196
197    public override IDeepCloneable Clone(Cloner cloner) {
198      OperatorShapeInfo clone = (OperatorShapeInfo) base.Clone(cloner);
199      clone.collapsed = this.collapsed;
200      clone.color = this.color;
201      clone.lineColor = this.lineColor;
202      clone.lineWidth = this.lineWidth;
203      clone.title = this.title;
204      clone.icon = (Bitmap) this.icon.Clone();
205
[2970]206      clone.connectorNames = new List<string>(this.connectorNames);
207      clone.labels = new List<string>(this.labels);
[2968]208
209      return clone;
210    }
[2853]211  }
212}
Note: See TracBrowser for help on using the repository browser.