[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Text;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using System.Drawing;
|
---|
| 28 | using Netron.Diagramming.Core;
|
---|
[2861] | 29 | using System.Windows.Forms;
|
---|
[2934] | 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2853] | 31 |
|
---|
| 32 | namespace HeuristicLab.Operators.Views.GraphVisualization {
|
---|
[2995] | 33 | [StorableClass(StorableClassType.MarkedOnly)]
|
---|
[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;
|
---|
[2934] | 171 | operatorShape.Collapsed = this.Collapsed;
|
---|
[2861] | 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 | }
|
---|
[2934] | 184 | //remove remaining old connectors
|
---|
[2868] | 185 | for (; j < oldConnectorNames.Count; j++)
|
---|
[2861] | 186 | operatorShape.RemoveConnector(oldConnectorNames[j]);
|
---|
| 187 |
|
---|
| 188 | //add new connectors
|
---|
| 189 | for (; i < this.connectorNames.Count; i++)
|
---|
| 190 | operatorShape.AddConnector(this.connectorNames[i]);
|
---|
[2934] | 191 |
|
---|
| 192 | operatorShape.UpdateLabels(this.labels);
|
---|
[2861] | 193 | }
|
---|
| 194 | }
|
---|
[2968] | 195 |
|
---|
| 196 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 197 | OperatorShapeInfo clone = (OperatorShapeInfo) base.Clone(cloner);
|
---|
| 198 | clone.collapsed = this.collapsed;
|
---|
| 199 | clone.color = this.color;
|
---|
| 200 | clone.lineColor = this.lineColor;
|
---|
| 201 | clone.lineWidth = this.lineWidth;
|
---|
| 202 | clone.title = this.title;
|
---|
| 203 | clone.icon = (Bitmap) this.icon.Clone();
|
---|
| 204 |
|
---|
[2970] | 205 | clone.connectorNames = new List<string>(this.connectorNames);
|
---|
| 206 | clone.labels = new List<string>(this.labels);
|
---|
[2968] | 207 |
|
---|
| 208 | return clone;
|
---|
| 209 | }
|
---|
[2853] | 210 | }
|
---|
| 211 | }
|
---|