[2853] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17097] | 3 | * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2853] | 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;
|
---|
[4068] | 24 | using System.Drawing;
|
---|
[2853] | 25 | using System.Linq;
|
---|
[4068] | 26 | using HeuristicLab.Collections;
|
---|
| 27 | using HeuristicLab.Common;
|
---|
[2853] | 28 | using HeuristicLab.Core;
|
---|
[17097] | 29 | using HEAL.Attic;
|
---|
[2853] | 30 |
|
---|
| 31 | namespace HeuristicLab.Operators.Views.GraphVisualization {
|
---|
[17097] | 32 | [StorableType("24376FA2-D635-4E10-85CC-FFE57C0788F9")]
|
---|
[3386] | 33 | public sealed class OperatorGraphVisualizationInfo : GraphVisualizationInfo {
|
---|
| 34 | [Storable]
|
---|
[2934] | 35 | private BidirectionalLookup<IOperator, IOperatorShapeInfo> operatorShapeInfoMapping;
|
---|
[3393] | 36 | private BidirectionalLookup<IOperator, IKeyedItemCollection<string, IParameter>> operatorParameterCollectionMapping;
|
---|
[2934] | 37 | private Dictionary<IParameter, IOperator> parameterOperatorMapping;
|
---|
[2853] | 38 |
|
---|
[3386] | 39 | private OperatorGraphVisualizationInfo()
|
---|
| 40 | : base() {
|
---|
[2934] | 41 | this.operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>();
|
---|
[3393] | 42 | this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IKeyedItemCollection<string, IParameter>>();
|
---|
[2934] | 43 | this.parameterOperatorMapping = new Dictionary<IParameter, IOperator>();
|
---|
[3386] | 44 | }
|
---|
[2861] | 45 |
|
---|
[3386] | 46 | [StorableConstructor]
|
---|
[17097] | 47 | private OperatorGraphVisualizationInfo(StorableConstructorFlag _) : base(_) {
|
---|
[3393] | 48 | this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IKeyedItemCollection<string, IParameter>>();
|
---|
[3386] | 49 | this.parameterOperatorMapping = new Dictionary<IParameter, IOperator>();
|
---|
[2861] | 50 | }
|
---|
[4722] | 51 | private OperatorGraphVisualizationInfo(OperatorGraphVisualizationInfo original, Cloner cloner)
|
---|
| 52 | : base(original, cloner) {
|
---|
| 53 | operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>();
|
---|
| 54 | operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IKeyedItemCollection<string, IParameter>>();
|
---|
| 55 | parameterOperatorMapping = new Dictionary<IParameter, IOperator>();
|
---|
[2853] | 56 |
|
---|
[4722] | 57 | operatorGraph = cloner.Clone(original.operatorGraph);
|
---|
| 58 | RegisterOperatorGraphEvents();
|
---|
| 59 | oldInitialShape = cloner.Clone(original.oldInitialShape);
|
---|
| 60 | oldInitialShapeColor = original.oldInitialShapeColor;
|
---|
| 61 |
|
---|
| 62 | foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in original.operatorShapeInfoMapping.FirstEnumerable) {
|
---|
| 63 | IOperator op = cloner.Clone(pair.Key);
|
---|
| 64 | IOperatorShapeInfo shapeInfo = cloner.Clone(pair.Value);
|
---|
| 65 | RegisterOperatorEvents(op);
|
---|
[6572] | 66 | operatorParameterCollectionMapping.Add(op, op.Parameters);
|
---|
[4722] | 67 | operatorShapeInfoMapping.Add(op, shapeInfo);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | foreach (IOperator oper in operatorShapeInfoMapping.FirstValues) {
|
---|
| 71 | foreach (IParameter param in oper.Parameters) {
|
---|
| 72 | parameterOperatorMapping.Add(param, oper);
|
---|
| 73 | IValueParameter opParam = param as IValueParameter;
|
---|
| 74 | if (opParam != null && typeof(IOperator).IsAssignableFrom(param.DataType))
|
---|
| 75 | RegisterOperatorParameterEvents(opParam);
|
---|
| 76 | else
|
---|
| 77 | RegisterParameterEvents(param);
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 82 | return new OperatorGraphVisualizationInfo(this, cloner);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[3386] | 85 | public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph)
|
---|
[2861] | 86 | : this() {
|
---|
[3386] | 87 | this.operatorGraph = operatorGraph;
|
---|
| 88 | this.RegisterOperatorGraphEvents();
|
---|
[2875] | 89 |
|
---|
[2853] | 90 | foreach (IOperator op in operatorGraph.Operators)
|
---|
[3386] | 91 | if (!this.operatorShapeInfoMapping.ContainsFirst(op)) //could be added by referencing parameters
|
---|
[2868] | 92 | this.AddOperator(op);
|
---|
[2853] | 93 |
|
---|
[2875] | 94 | this.UpdateInitialShape();
|
---|
[2853] | 95 | }
|
---|
| 96 |
|
---|
[3386] | 97 | [StorableHook(HookType.AfterDeserialization)]
|
---|
[4722] | 98 | private void AfterDeserialization() {
|
---|
[3386] | 99 | this.operatorGraph.DeserializationFinished += new EventHandler(operatorGraph_DeserializationFinished);
|
---|
[5008] | 100 | if (oldInitialShapeColor.IsEmpty) oldInitialShapeColor = Color.LightBlue;
|
---|
[3386] | 101 |
|
---|
| 102 | IOperator op;
|
---|
| 103 | IOperatorShapeInfo shapeInfo;
|
---|
| 104 | foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in this.operatorShapeInfoMapping.FirstEnumerable) {
|
---|
| 105 | op = pair.Key;
|
---|
| 106 | shapeInfo = pair.Value;
|
---|
| 107 | shapeInfo.Icon = new Bitmap(op.ItemImage);
|
---|
| 108 | this.RegisterOperatorEvents(op);
|
---|
| 109 | this.operatorParameterCollectionMapping.Add(op, op.Parameters);
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | foreach (IOperator oper in this.operatorShapeInfoMapping.FirstValues) {
|
---|
| 113 | foreach (IParameter param in oper.Parameters) {
|
---|
[3422] | 114 | IValueParameter opParam = param as IValueParameter;
|
---|
[3386] | 115 | this.parameterOperatorMapping.Add(param, oper);
|
---|
[3422] | 116 | if (opParam != null && typeof(IOperator).IsAssignableFrom(param.DataType))
|
---|
[3386] | 117 | this.RegisterOperatorParameterEvents(opParam);
|
---|
| 118 | else
|
---|
| 119 | this.RegisterParameterEvents(param);
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
[7226] | 122 |
|
---|
| 123 | foreach (IOperatorShapeInfo shapeInfo2 in this.operatorShapeInfoMapping.SecondValues)
|
---|
| 124 | if (string.IsNullOrEmpty(shapeInfo2.TypeName)) shapeInfo2.TypeName = this.operatorShapeInfoMapping.GetBySecond(shapeInfo2).GetType().GetPrettyName();
|
---|
[3386] | 125 | }
|
---|
| 126 |
|
---|
| 127 | private void operatorGraph_DeserializationFinished(object sender, EventArgs e) {
|
---|
| 128 | this.RegisterOperatorGraphEvents();
|
---|
| 129 | this.operatorGraph.DeserializationFinished -= new EventHandler(operatorGraph_DeserializationFinished);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[6036] | 132 | public IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) {
|
---|
[3386] | 133 | return this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
[2861] | 136 | private void operatorGraph_InitialOperatorChanged(object sender, EventArgs e) {
|
---|
[2875] | 137 | this.UpdateInitialShape();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | private void UpdateInitialShape() {
|
---|
[2934] | 141 | IOperatorShapeInfo old = this.oldInitialShape as OperatorShapeInfo;
|
---|
[2875] | 142 | if (old != null)
|
---|
[2934] | 143 | old.Color = oldInitialShapeColor;
|
---|
[2875] | 144 |
|
---|
| 145 | OperatorShapeInfo newInitialShapeInfo = this.InitialShape as OperatorShapeInfo;
|
---|
| 146 | if (newInitialShapeInfo != null) {
|
---|
[2934] | 147 | oldInitialShapeColor = newInitialShapeInfo.Color;
|
---|
| 148 | newInitialShapeInfo.Color = Color.LightGreen;
|
---|
[2875] | 149 | }
|
---|
| 150 |
|
---|
| 151 | oldInitialShape = this.InitialShape;
|
---|
[3386] | 152 | this.OnInitialShapeChanged();
|
---|
[2861] | 153 | }
|
---|
| 154 |
|
---|
[3386] | 155 | private IShapeInfo oldInitialShape;
|
---|
[5008] | 156 | [Storable]
|
---|
[2875] | 157 | private Color oldInitialShapeColor;
|
---|
[3386] | 158 | public override IShapeInfo InitialShape {
|
---|
[2861] | 159 | get {
|
---|
| 160 | IOperator op = this.operatorGraph.InitialOperator;
|
---|
[5008] | 161 | if (op == null) return null;
|
---|
[2934] | 162 | return this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
[2861] | 163 | }
|
---|
[2893] | 164 | set {
|
---|
| 165 | if (value == null)
|
---|
| 166 | this.OperatorGraph.InitialOperator = null;
|
---|
[3386] | 167 | else {
|
---|
[5008] | 168 | this.oldInitialShape = InitialShape;
|
---|
[3386] | 169 | IOperatorShapeInfo shapeInfo = (IOperatorShapeInfo)value;
|
---|
| 170 | this.OperatorGraph.InitialOperator = this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
|
---|
| 171 | }
|
---|
[2893] | 172 | }
|
---|
[2861] | 173 | }
|
---|
| 174 |
|
---|
[3386] | 175 | [Storable]
|
---|
[2942] | 176 | private OperatorGraph operatorGraph;
|
---|
[2853] | 177 | public OperatorGraph OperatorGraph {
|
---|
| 178 | get { return this.operatorGraph; }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[3386] | 181 | private void RegisterOperatorGraphEvents() {
|
---|
| 182 | this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged);
|
---|
| 183 | this.operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded);
|
---|
| 184 | this.operatorGraph.Operators.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsRemoved);
|
---|
| 185 | this.operatorGraph.Operators.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_CollectionReset);
|
---|
[2853] | 186 | }
|
---|
| 187 |
|
---|
[3386] | 188 | private void DeregisterOperatorGraphEvents() {
|
---|
| 189 | this.operatorGraph.InitialOperatorChanged -= new EventHandler(operatorGraph_InitialOperatorChanged);
|
---|
| 190 | this.operatorGraph.Operators.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded);
|
---|
| 191 | this.operatorGraph.Operators.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsRemoved);
|
---|
| 192 | this.operatorGraph.Operators.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_CollectionReset);
|
---|
[2868] | 193 | }
|
---|
| 194 |
|
---|
| 195 | #region methods to manipulate operatorgraph by the shape info
|
---|
[6036] | 196 | public void AddShapeInfo(IOperator op, IOperatorShapeInfo shapeInfo) {
|
---|
[2853] | 197 | this.RegisterOperatorEvents(op);
|
---|
[2861] | 198 | this.operatorParameterCollectionMapping.Add(op, op.Parameters);
|
---|
[2934] | 199 | this.operatorShapeInfoMapping.Add(op, shapeInfo);
|
---|
[2853] | 200 | this.shapeInfos.Add(shapeInfo);
|
---|
| 201 |
|
---|
[2868] | 202 | foreach (IParameter param in op.Parameters)
|
---|
| 203 | this.AddParameter(op, param);
|
---|
| 204 |
|
---|
[2942] | 205 | this.operatorGraph.Operators.Add(op);
|
---|
[2853] | 206 | }
|
---|
| 207 |
|
---|
[3386] | 208 | public override void RemoveShapeInfo(IShapeInfo shapeInfo) {
|
---|
| 209 | IOperatorShapeInfo opShapeInfo = (IOperatorShapeInfo)shapeInfo;
|
---|
| 210 | if (this.operatorShapeInfoMapping.ContainsSecond(opShapeInfo)) {
|
---|
| 211 | IOperator op = this.operatorShapeInfoMapping.GetBySecond(opShapeInfo);
|
---|
| 212 | this.operatorGraph.Operators.Remove(op);
|
---|
| 213 | }
|
---|
[2853] | 214 | }
|
---|
| 215 |
|
---|
[3386] | 216 | public override void RemoveConnectionInfo(IConnectionInfo connectionInfo) {
|
---|
| 217 | IOperatorShapeInfo shapeInfo = (IOperatorShapeInfo)connectionInfo.From;
|
---|
| 218 | IOperator op = this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
|
---|
[3422] | 219 | IValueParameter param = (IValueParameter)op.Parameters[connectionInfo.ConnectorFrom];
|
---|
[2868] | 220 | param.Value = null;
|
---|
| 221 | }
|
---|
[3422] | 222 |
|
---|
| 223 | public override void AddConnectionInfo(IConnectionInfo connectionInfo) {
|
---|
| 224 | IOperatorShapeInfo shapeInfo = (IOperatorShapeInfo)connectionInfo.From;
|
---|
| 225 | IOperator op = this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
|
---|
| 226 | IOperatorShapeInfo shapeInfoTo = (IOperatorShapeInfo)connectionInfo.To;
|
---|
| 227 | IOperator opTo = this.operatorShapeInfoMapping.GetBySecond(shapeInfoTo);
|
---|
[3514] | 228 | IValueParameter param = (IValueParameter)op.Parameters.Where(p => p.Name == connectionInfo.ConnectorFrom).SingleOrDefault();
|
---|
| 229 | if (param != null)
|
---|
| 230 | param.Value = opTo;
|
---|
[3422] | 231 | }
|
---|
[2868] | 232 | #endregion
|
---|
| 233 |
|
---|
[2853] | 234 | #region operator events
|
---|
| 235 | private void AddOperator(IOperator op) {
|
---|
[2934] | 236 | if (!this.operatorShapeInfoMapping.ContainsFirst(op)) {
|
---|
[2868] | 237 | this.RegisterOperatorEvents(op);
|
---|
[3386] | 238 | IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op);
|
---|
[2868] | 239 | this.operatorParameterCollectionMapping.Add(op, op.Parameters);
|
---|
[2934] | 240 | this.operatorShapeInfoMapping.Add(op, shapeInfo);
|
---|
[2942] | 241 | this.shapeInfos.Add(shapeInfo);
|
---|
[2868] | 242 | foreach (IParameter param in op.Parameters)
|
---|
| 243 | this.AddParameter(op, param);
|
---|
| 244 | }
|
---|
[2853] | 245 | }
|
---|
| 246 | private void RemoveOperator(IOperator op) {
|
---|
| 247 | this.DeregisterOperatorEvents(op);
|
---|
[2861] | 248 | foreach (IParameter param in op.Parameters)
|
---|
| 249 | this.RemoveParameter(op, param);
|
---|
[2853] | 250 |
|
---|
[2934] | 251 | IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
[2861] | 252 | this.operatorParameterCollectionMapping.RemoveByFirst(op);
|
---|
[2934] | 253 | this.operatorShapeInfoMapping.RemoveByFirst(op);
|
---|
[2853] | 254 | this.shapeInfos.Remove(shapeInfo);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
[2935] | 257 | private void OperatorBreakpointChanged(object sender, EventArgs e) {
|
---|
| 258 | IOperator op = (IOperator)sender;
|
---|
| 259 | IOperatorShapeInfo operatorShapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
| 260 | if (op.Breakpoint) {
|
---|
| 261 | operatorShapeInfo.LineColor = Color.Red;
|
---|
| 262 | operatorShapeInfo.LineWidth = 2;
|
---|
| 263 | } else {
|
---|
| 264 | operatorShapeInfo.LineColor = Color.Black;
|
---|
| 265 | operatorShapeInfo.LineWidth = 1;
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 |
|
---|
[3344] | 269 | private void OperatorItemImageChanged(object sender, EventArgs e) {
|
---|
| 270 | IOperator op = (IOperator)sender;
|
---|
| 271 | IOperatorShapeInfo operatorShapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
| 272 | operatorShapeInfo.Icon = new Bitmap(op.ItemImage);
|
---|
| 273 | }
|
---|
| 274 |
|
---|
[2896] | 275 | private void OperatorNameChanged(object sender, EventArgs e) {
|
---|
| 276 | IOperator op = (IOperator)sender;
|
---|
[2934] | 277 | IOperatorShapeInfo operatorShapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
| 278 | operatorShapeInfo.Title = op.Name;
|
---|
[2896] | 279 | }
|
---|
| 280 |
|
---|
[2853] | 281 | private void Operators_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IOperator> e) {
|
---|
| 282 | foreach (IOperator op in e.Items)
|
---|
| 283 | this.AddOperator(op);
|
---|
| 284 | }
|
---|
| 285 | private void Operators_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IOperator> e) {
|
---|
| 286 | foreach (IOperator op in e.Items)
|
---|
| 287 | this.RemoveOperator(op);
|
---|
| 288 | }
|
---|
| 289 | private void Operators_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IOperator> e) {
|
---|
| 290 | foreach (IOperator op in e.OldItems)
|
---|
| 291 | this.RemoveOperator(op);
|
---|
| 292 | foreach (IOperator op in e.Items)
|
---|
| 293 | this.AddOperator(op);
|
---|
| 294 | }
|
---|
| 295 |
|
---|
| 296 | private void RegisterOperatorEvents(IOperator op) {
|
---|
| 297 | op.Parameters.ItemsAdded += new CollectionItemsChangedEventHandler<IParameter>(Parameters_ItemsAdded);
|
---|
| 298 | op.Parameters.ItemsRemoved += new CollectionItemsChangedEventHandler<IParameter>(Parameters_ItemsRemoved);
|
---|
| 299 | op.Parameters.ItemsReplaced += new CollectionItemsChangedEventHandler<IParameter>(Parameters_ItemsReplaced);
|
---|
| 300 | op.Parameters.CollectionReset += new CollectionItemsChangedEventHandler<IParameter>(Parameters_CollectionReset);
|
---|
[2896] | 301 | op.NameChanged += new EventHandler(OperatorNameChanged);
|
---|
[3344] | 302 | op.ItemImageChanged += new EventHandler(OperatorItemImageChanged);
|
---|
[2935] | 303 | op.BreakpointChanged += new EventHandler(OperatorBreakpointChanged);
|
---|
[2853] | 304 | }
|
---|
[2896] | 305 |
|
---|
[2853] | 306 | private void DeregisterOperatorEvents(IOperator op) {
|
---|
| 307 | op.Parameters.ItemsAdded -= new CollectionItemsChangedEventHandler<IParameter>(Parameters_ItemsAdded);
|
---|
| 308 | op.Parameters.ItemsRemoved -= new CollectionItemsChangedEventHandler<IParameter>(Parameters_ItemsRemoved);
|
---|
| 309 | op.Parameters.ItemsReplaced -= new CollectionItemsChangedEventHandler<IParameter>(Parameters_ItemsReplaced);
|
---|
| 310 | op.Parameters.CollectionReset -= new CollectionItemsChangedEventHandler<IParameter>(Parameters_CollectionReset);
|
---|
[2896] | 311 | op.NameChanged -= new EventHandler(OperatorNameChanged);
|
---|
[3344] | 312 | op.ItemImageChanged -= new EventHandler(OperatorItemImageChanged);
|
---|
[2935] | 313 | op.BreakpointChanged -= new EventHandler(OperatorBreakpointChanged);
|
---|
[2853] | 314 | }
|
---|
| 315 | #endregion
|
---|
| 316 |
|
---|
| 317 | #region parameter events
|
---|
[2861] | 318 | private void AddParameter(IOperator op, IParameter param) {
|
---|
[2934] | 319 | this.parameterOperatorMapping.Add(param, op);
|
---|
[3422] | 320 | IValueParameter opParam = param as IValueParameter;
|
---|
| 321 | if (opParam != null && typeof(IOperator).IsAssignableFrom(param.DataType)) {
|
---|
[2861] | 322 | this.RegisterOperatorParameterEvents(opParam);
|
---|
[3386] | 323 | IOperatorShapeInfo shapeInfoFrom = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
| 324 | shapeInfoFrom.AddConnector(param.Name);
|
---|
[2861] | 325 |
|
---|
| 326 | if (opParam.Value != null) {
|
---|
[3422] | 327 | if (!this.operatorShapeInfoMapping.ContainsFirst((IOperator)opParam.Value))
|
---|
| 328 | this.AddOperator((IOperator)opParam.Value);
|
---|
| 329 | IOperatorShapeInfo shapeInfoTo = this.operatorShapeInfoMapping.GetByFirst((IOperator)opParam.Value);
|
---|
[3386] | 330 | this.connectionInfos.Add(new ConnectionInfo(shapeInfoFrom, param.Name, shapeInfoTo, OperatorShapeInfoFactory.PredecessorConnector));
|
---|
[2861] | 331 | }
|
---|
[2934] | 332 | } else
|
---|
| 333 | this.RegisterParameterEvents(param);
|
---|
[2853] | 334 | }
|
---|
[2868] | 335 |
|
---|
[2861] | 336 | private void RemoveParameter(IOperator op, IParameter param) {
|
---|
[3422] | 337 | IValueParameter opParam = param as IValueParameter;
|
---|
| 338 | if (opParam != null && typeof(IOperator).IsAssignableFrom(param.DataType)) {
|
---|
[2861] | 339 | this.DeregisterOperatorParameterEvents(opParam);
|
---|
[2934] | 340 | IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
[3386] | 341 | this.connectionInfos.RemoveWhere(c => c.From == shapeInfo && c.ConnectorFrom == param.Name);
|
---|
| 342 | this.connectionInfos.RemoveWhere(c => c.To == shapeInfo && c.ConnectorTo == param.Name);
|
---|
[2934] | 343 | shapeInfo.RemoveConnector(param.Name);
|
---|
| 344 | } else
|
---|
| 345 | this.DeregisterParameterEvents(param);
|
---|
[2868] | 346 |
|
---|
[2934] | 347 | this.parameterOperatorMapping.Remove(param);
|
---|
[2853] | 348 | }
|
---|
| 349 |
|
---|
| 350 | private void opParam_ValueChanged(object sender, EventArgs e) {
|
---|
[3422] | 351 | IValueParameter opParam = (IValueParameter)sender;
|
---|
[3729] | 352 | if (this.parameterOperatorMapping.ContainsKey(opParam)) {
|
---|
| 353 | IOperator op = this.parameterOperatorMapping[opParam];
|
---|
| 354 | IOperatorShapeInfo shapeInfoFrom = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
| 355 | KeyValuePair<IOperatorShapeInfo, string> connectionFrom = new KeyValuePair<IOperatorShapeInfo, string>(shapeInfoFrom, opParam.Name);
|
---|
[2861] | 356 |
|
---|
[3729] | 357 | this.connectionInfos.RemoveWhere(c => c.From == shapeInfoFrom && c.ConnectorFrom == opParam.Name);
|
---|
| 358 | if (opParam.Value != null) {
|
---|
| 359 | if (!this.operatorShapeInfoMapping.ContainsFirst((IOperator)opParam.Value))
|
---|
| 360 | this.AddOperator((IOperator)opParam.Value);
|
---|
| 361 | IOperatorShapeInfo shapeInfoTo = this.operatorShapeInfoMapping.GetByFirst((IOperator)opParam.Value);
|
---|
| 362 | base.AddConnectionInfo(new ConnectionInfo(shapeInfoFrom, opParam.Name, shapeInfoTo, OperatorShapeInfoFactory.PredecessorConnector));
|
---|
| 363 | }
|
---|
[2861] | 364 | }
|
---|
[2853] | 365 | }
|
---|
| 366 |
|
---|
| 367 | private void Parameters_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
[3393] | 368 | IKeyedItemCollection<string, IParameter> parameterCollection = sender as IKeyedItemCollection<string, IParameter>;
|
---|
[2861] | 369 | IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
|
---|
[2853] | 370 | foreach (IParameter param in e.Items)
|
---|
[2861] | 371 | AddParameter(op, param);
|
---|
[2934] | 372 | this.UpdateParameterLabels(op);
|
---|
[2853] | 373 | }
|
---|
| 374 | private void Parameters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
[3393] | 375 | IKeyedItemCollection<string, IParameter> parameterCollection = sender as IKeyedItemCollection<string, IParameter>;
|
---|
[2861] | 376 | IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
|
---|
[2853] | 377 | foreach (IParameter param in e.Items)
|
---|
[2861] | 378 | RemoveParameter(op, param);
|
---|
[2934] | 379 | this.UpdateParameterLabels(op);
|
---|
[2853] | 380 | }
|
---|
| 381 | private void Parameters_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
[3393] | 382 | IKeyedItemCollection<string, IParameter> parameterCollection = sender as IKeyedItemCollection<string, IParameter>;
|
---|
[2861] | 383 | IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
|
---|
[2853] | 384 | foreach (IParameter param in e.OldItems)
|
---|
[2861] | 385 | RemoveParameter(op, param);
|
---|
[2853] | 386 | foreach (IParameter param in e.Items)
|
---|
[2861] | 387 | AddParameter(op, param);
|
---|
[2934] | 388 | this.UpdateParameterLabels(op);
|
---|
[2853] | 389 | }
|
---|
| 390 | private void Parameters_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) {
|
---|
[3393] | 391 | IKeyedItemCollection<string, IParameter> parameterCollection = sender as IKeyedItemCollection<string, IParameter>;
|
---|
[2861] | 392 | IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection);
|
---|
[2853] | 393 | foreach (IParameter param in e.OldItems)
|
---|
[2861] | 394 | RemoveParameter(op, param);
|
---|
[2853] | 395 | foreach (IParameter param in e.Items)
|
---|
[2861] | 396 | AddParameter(op, param);
|
---|
[2934] | 397 | this.UpdateParameterLabels(op);
|
---|
[2853] | 398 | }
|
---|
| 399 |
|
---|
[3422] | 400 | private void RegisterOperatorParameterEvents(IValueParameter opParam) {
|
---|
[2853] | 401 | opParam.ValueChanged += new EventHandler(opParam_ValueChanged);
|
---|
| 402 | }
|
---|
[3422] | 403 | private void DeregisterOperatorParameterEvents(IValueParameter opParam) {
|
---|
[2853] | 404 | opParam.ValueChanged -= new EventHandler(opParam_ValueChanged);
|
---|
| 405 | }
|
---|
[2934] | 406 | private void RegisterParameterEvents(IParameter param) {
|
---|
| 407 | param.ToStringChanged += new EventHandler(param_ToStringChanged);
|
---|
| 408 | param.NameChanged += new EventHandler(param_NameChanged);
|
---|
| 409 | }
|
---|
| 410 | private void DeregisterParameterEvents(IParameter param) {
|
---|
| 411 | param.ToStringChanged -= new EventHandler(param_ToStringChanged);
|
---|
| 412 | param.NameChanged -= new EventHandler(param_NameChanged);
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | private void param_NameChanged(object sender, EventArgs e) {
|
---|
| 416 | IParameter param = (IParameter)sender;
|
---|
| 417 | IOperator op = this.parameterOperatorMapping[param];
|
---|
| 418 | this.UpdateParameterLabels(op);
|
---|
| 419 | }
|
---|
| 420 | private void param_ToStringChanged(object sender, EventArgs e) {
|
---|
| 421 | IParameter param = (IParameter)sender;
|
---|
| 422 | IOperator op = this.parameterOperatorMapping[param];
|
---|
| 423 | this.UpdateParameterLabels(op);
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | private void UpdateParameterLabels(IOperator op) {
|
---|
[3422] | 427 | IEnumerable<IParameter> parameters = op.Parameters.Where(p => !(p is IValueParameter && typeof(IOperator).IsAssignableFrom(p.DataType)));
|
---|
[2934] | 428 | IOperatorShapeInfo operatorShapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);
|
---|
| 429 | if (parameters.Count() > 0)
|
---|
| 430 | operatorShapeInfo.UpdateLabels(parameters.Select(p => p.ToString()));
|
---|
| 431 | else
|
---|
| 432 | operatorShapeInfo.UpdateLabels(new List<string>());
|
---|
| 433 | }
|
---|
[2853] | 434 | #endregion
|
---|
| 435 | }
|
---|
[2893] | 436 | } |
---|