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