Changeset 2861 for trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorGraphVisualizationInfo.cs
- Timestamp:
- 02/24/10 17:58:03 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorGraphVisualizationInfo.cs
r2853 r2861 30 30 31 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 32 public sealed class OperatorGraphVisualizationInfo : Item{32 public sealed class OperatorGraphVisualizationInfo : DeepCloneable { 33 33 private BidirectionalLookup<IOperator, IShapeInfo> shapeInfoMapping; 34 35 public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph) { 34 private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping; 35 private Dictionary<IValueParameter<IOperator>, IOperator> parameterOperatorMapping; 36 37 private OperatorGraphVisualizationInfo() { 38 this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>(); 39 this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>(); 40 this.parameterOperatorMapping = new Dictionary<IValueParameter<IOperator>, IOperator>(); 41 42 this.shapeInfos = new ObservableSet<IShapeInfo>(); 43 } 44 45 public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph) 46 : this() { 36 47 this.operatorGraph = operatorGraph; 37 this.shapeInfoMapping = new BidirectionalLookup<IOperator, IShapeInfo>(); 38 this.shapeInfos = new ObservableSet<IShapeInfo>(); 39 48 this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged); 40 49 foreach (IOperator op in operatorGraph.Operators) 41 50 this.AddOperator(op); 42 this.initialOperator = operatorGraph.InitialOperator;43 51 44 52 operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded); … … 47 55 } 48 56 57 public event EventHandler InitialShapeChanged; 58 private void operatorGraph_InitialOperatorChanged(object sender, EventArgs e) { 59 if (this.InitialShapeChanged != null) 60 this.InitialShapeChanged(this, new EventArgs()); 61 } 62 63 public IShapeInfo InitialShape { 64 get { 65 IOperator op = this.operatorGraph.InitialOperator; 66 if (op == null) 67 return null; 68 return this.shapeInfoMapping.GetByFirst(op); 69 } 70 } 71 49 72 private OperatorGraph operatorGraph; 50 73 public OperatorGraph OperatorGraph { … … 56 79 get { return this.shapeInfos; } 57 80 } 58 59 81 public IEnumerable<IShapeInfo> ShapeInfos { 60 82 get { return this.shapeInfos; } 61 83 } 62 84 63 private IOperator initialOperator;64 public IOperator InitialOperator {65 get { return this.initialOperator; }66 set {67 if (this.initialOperator != value) {68 if (!this.shapeInfoMapping.ContainsFirst(value))69 throw new ArgumentException("Could not set initial operator in graph visualization information, because the operator " +70 value.ToString() + " is not contained in the operator set.");71 this.initialOperator = value;72 this.OnChanged();73 }74 }75 }76 77 85 internal void AddShapeInfo(IOperator op, IShapeInfo shapeInfo) { 78 86 this.RegisterOperatorEvents(op); 87 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 79 88 this.shapeInfoMapping.Add(op, shapeInfo); 80 89 this.shapeInfos.Add(shapeInfo); … … 90 99 #region operator events 91 100 private void AddOperator(IOperator op) { 92 if (!shapeInfoMapping.ContainsFirst(op)) { 93 this.RegisterOperatorEvents(op); 94 95 IShapeInfo shapeInfo = ShapeInfoFactory.CreateShapeInfo(op); 96 this.shapeInfoMapping.Add(op, shapeInfo); 97 this.shapeInfos.Add(shapeInfo); 98 } 101 if (shapeInfoMapping.ContainsFirst(op)) 102 return; 103 104 this.RegisterOperatorEvents(op); 105 IShapeInfo shapeInfo = Factory.CreateShapeInfo(op); 106 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 107 this.shapeInfoMapping.Add(op, shapeInfo); 108 foreach (IParameter param in op.Parameters) 109 this.AddParameter(op, param); 110 111 this.shapeInfos.Add(shapeInfo); 99 112 } 100 113 101 114 private void RemoveOperator(IOperator op) { 102 115 this.DeregisterOperatorEvents(op); 116 foreach (IParameter param in op.Parameters) 117 this.RemoveParameter(op, param); 103 118 104 119 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 120 this.operatorParameterCollectionMapping.RemoveByFirst(op); 105 121 this.shapeInfoMapping.RemoveByFirst(op); 106 122 this.shapeInfos.Remove(shapeInfo); … … 139 155 140 156 #region parameter events 141 private void AddParameter(I Parameter param) {157 private void AddParameter(IOperator op, IParameter param) { 142 158 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 143 159 if (opParam != null) { 144 RegisterOperatorParameterEvents(opParam); 145 //TODO add connector 146 } 147 } 148 private void RemoveParameter(IParameter param) { 160 this.RegisterOperatorParameterEvents(opParam); 161 this.parameterOperatorMapping.Add(opParam, op); 162 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 163 shapeInfo.AddConnector(param.Name); 164 165 if (opParam.Value != null) { 166 if (!this.shapeInfoMapping.ContainsFirst(opParam.Value)) 167 this.AddOperator(opParam.Value); 168 shapeInfo.AddConnection(param.Name, this.shapeInfoMapping.GetByFirst(opParam.Value)); 169 } 170 } 171 } 172 private void RemoveParameter(IOperator op, IParameter param) { 149 173 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 150 174 if (opParam != null) { 151 DeregisterOperatorParameterEvents(opParam); 152 //TODO remove connector 175 this.DeregisterOperatorParameterEvents(opParam); 176 this.parameterOperatorMapping.Remove(opParam); 177 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 178 shapeInfo.RemoveConnector(param.Name); 153 179 } 154 180 } … … 156 182 private void opParam_ValueChanged(object sender, EventArgs e) { 157 183 IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender; 158 //TODO update connections 184 if (opParam != null) { 185 IOperator op = this.parameterOperatorMapping[opParam]; 186 IShapeInfo shapeInfo = this.shapeInfoMapping.GetByFirst(op); 187 188 if (opParam.Value == null) 189 shapeInfo.RemoveConnection(opParam.Name); 190 else 191 shapeInfo.ChangeConnection(opParam.Name, this.shapeInfoMapping.GetByFirst(opParam.Value)); 192 } 159 193 } 160 194 161 195 private void Parameters_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 162 foreach (IParameter param in e.Items) 163 AddParameter(param); 196 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 197 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 198 foreach (IParameter param in e.Items) 199 AddParameter(op, param); 164 200 } 165 201 private void Parameters_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 166 foreach (IParameter param in e.Items) 167 RemoveParameter(param); 202 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 203 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 204 foreach (IParameter param in e.Items) 205 RemoveParameter(op, param); 168 206 } 169 207 private void Parameters_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 208 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 209 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 170 210 foreach (IParameter param in e.OldItems) 171 RemoveParameter( param);172 foreach (IParameter param in e.Items) 173 AddParameter( param);211 RemoveParameter(op, param); 212 foreach (IParameter param in e.Items) 213 AddParameter(op, param); 174 214 } 175 215 private void Parameters_CollectionReset(object sender, CollectionItemsChangedEventArgs<IParameter> e) { 216 IObservableKeyedCollection<string, IParameter> parameterCollection = sender as IObservableKeyedCollection<string, IParameter>; 217 IOperator op = this.operatorParameterCollectionMapping.GetBySecond(parameterCollection); 176 218 foreach (IParameter param in e.OldItems) 177 RemoveParameter(param); 178 foreach (IParameter param in e.Items) 179 AddParameter(param); 180 } 219 RemoveParameter(op, param); 220 foreach (IParameter param in e.Items) 221 AddParameter(op, param); 222 } 223 181 224 182 225 private void RegisterOperatorParameterEvents(IValueParameter<IOperator> opParam) { … … 187 230 } 188 231 #endregion 189 190 191 192 193 194 195 196 197 private static IConnection CreateConnection(IShape from, IShape to) {198 IConnector parentConnector = from.Connectors.Where(c => c.Name == "Bottom connector").First();199 IConnector operatorConnector = to.Connectors.Where(c => c.Name == "Top connector").First();200 201 IConnection connection = new Connection(parentConnector.Point, operatorConnector.Point);202 203 parentConnector.AttachConnector(connection.From);204 operatorConnector.AttachConnector(connection.To);205 206 return connection;207 }208 232 } 209 233 }
Note: See TracChangeset
for help on using the changeset viewer.