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