Changeset 2868 for trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphView.cs
- Timestamp:
- 02/25/10 17:28:31 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphView.cs
r2862 r2868 42 42 private BidirectionalLookup<IShapeInfo, IShape> shapeInfoShapeMapping; 43 43 private BidirectionalLookup<IShapeInfo, INotifyObservableDictionaryItemsChanged<string, IShapeInfo>> shapeInfoConnectionsMapping; 44 private Dictionary<IConnector, IShape> connectorShapeMapping;45 44 private BidirectionalLookup<IConnection, KeyValuePair<IConnector, IConnector>> connectionConnectorsMapping; 46 45 … … 53 52 this.shapeInfoConnectionsMapping = new BidirectionalLookup<IShapeInfo, INotifyObservableDictionaryItemsChanged<string, IShapeInfo>>(); 54 53 this.connectionConnectorsMapping = new BidirectionalLookup<IConnection, KeyValuePair<IConnector, IConnector>>(); 55 this.connectorShapeMapping = new Dictionary<IConnector, IShape>();56 54 } 57 55 … … 83 81 this.shapeInfoShapeMapping.Clear(); 84 82 this.shapeInfoConnectionsMapping.Clear(); 85 this.connectorShapeMapping.Clear();86 83 this.connectionConnectorsMapping.Clear(); 87 84 … … 89 86 if (!this.shapeInfoShapeMapping.ContainsFirst(shapeInfo)) 90 87 this.AddShapeInfo(shapeInfo); 88 89 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> connection in this.VisualizationInfo.Connections) 90 this.AddConnection(connection.Key.Key, connection.Key.Value, connection.Value); 91 91 92 92 this.UpdateLayoutRoot(); … … 111 111 this.VisualizationInfo.ObserveableShapeInfos.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsRemoved); 112 112 this.VisualizationInfo.ObserveableShapeInfos.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_CollectionReset); 113 114 this.VisualizationInfo.ObservableConnections.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_ItemsAdded); 115 this.VisualizationInfo.ObservableConnections.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_ItemsRemoved); 116 this.VisualizationInfo.ObservableConnections.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_ItemsReplaced); 117 this.VisualizationInfo.ObservableConnections.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_CollectionReset); 113 118 } 114 119 … … 119 124 this.VisualizationInfo.ObserveableShapeInfos.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsRemoved); 120 125 this.VisualizationInfo.ObserveableShapeInfos.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_CollectionReset); 126 127 this.VisualizationInfo.ObservableConnections.ItemsAdded -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_ItemsAdded); 128 this.VisualizationInfo.ObservableConnections.ItemsRemoved -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_ItemsRemoved); 129 this.VisualizationInfo.ObservableConnections.ItemsReplaced -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_ItemsReplaced); 130 this.VisualizationInfo.ObservableConnections.CollectionReset -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>>(Connections_CollectionReset); 121 131 } 122 132 … … 144 154 shape.OnEntityChange += new EventHandler<EntityEventArgs>(shape_OnEntityChange); 145 155 this.shapeInfoShapeMapping.Add(shapeInfo, shape); 146 this.shapeInfoConnectionsMapping.Add(shapeInfo, shapeInfo.ObservableConnections);147 148 foreach (IConnector connector in shape.Connectors)149 this.connectorShapeMapping.Add(connector, shape);150 156 151 157 this.graphVisualization.Controller.Model.AddShape(shape); 152 153 foreach (KeyValuePair<string, IShapeInfo> pair in shapeInfo.Connections) {154 if (!this.shapeInfoShapeMapping.ContainsFirst(pair.Value))155 this.AddShapeInfo(pair.Value);156 this.AddConnection(shapeInfo, pair.Key, pair.Value);157 }158 158 } 159 159 … … 180 180 private void RegisterShapeInfoEvents(IShapeInfo shapeInfo) { 181 181 shapeInfo.Changed += new ChangedEventHandler(shapeInfo_Changed); 182 shapeInfo.ObservableConnections.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsAdded);183 shapeInfo.ObservableConnections.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsRemoved);184 shapeInfo.ObservableConnections.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsReplaced);185 shapeInfo.ObservableConnections.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_CollectionReset);186 182 } 187 183 188 184 private void DeregisterShapeInfoEvents(IShapeInfo shapeInfo) { 189 185 shapeInfo.Changed -= new ChangedEventHandler(shapeInfo_Changed); 190 shapeInfo.ObservableConnections.ItemsAdded -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsAdded); 191 shapeInfo.ObservableConnections.ItemsRemoved -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsRemoved); 192 shapeInfo.ObservableConnections.ItemsReplaced -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_ItemsReplaced); 193 shapeInfo.ObservableConnections.CollectionReset -= new CollectionItemsChangedEventHandler<KeyValuePair<string, IShapeInfo>>(Connections_CollectionReset); 194 } 195 196 private void Connections_CollectionReset(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) { 197 IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender); 186 } 187 188 private void Connections_CollectionReset(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>> e) { 198 189 IConnection connection; 199 foreach (KeyValuePair< string, IShapeInfo> pair in e.Items) {200 connection = this.GetConnection( shapeInfo, pair.Key);190 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> pair in e.Items) { 191 connection = this.GetConnection(pair.Key.Key, pair.Key.Value); 201 192 this.RemoveConnection(connection); 202 193 } 203 foreach (KeyValuePair<string, IShapeInfo> pair in e.Items) 204 this.AddConnection(shapeInfo, pair.Key, pair.Value); 205 } 206 207 private void Connections_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) { 208 IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender); 194 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> pair in e.Items) 195 this.AddConnection(pair.Key.Key, pair.Key.Value, pair.Value); 196 } 197 198 private void Connections_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>> e) { 209 199 IConnection connection; 210 foreach (KeyValuePair< string, IShapeInfo> pair in e.Items) {211 connection = this.GetConnection( shapeInfo, pair.Key);200 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> pair in e.Items) { 201 connection = this.GetConnection(pair.Key.Key, pair.Key.Value); 212 202 this.RemoveConnection(connection); 213 203 } 214 foreach (KeyValuePair<string, IShapeInfo> pair in e.Items) 215 this.AddConnection(shapeInfo, pair.Key, pair.Value); 216 } 217 218 private void Connections_ItemsAdded(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) { 219 IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender); 220 foreach (KeyValuePair<string, IShapeInfo> pair in e.Items) 221 this.AddConnection(shapeInfo, pair.Key, pair.Value); 222 } 223 224 private void Connections_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<string, IShapeInfo>> e) { 225 IShapeInfo shapeInfo = this.shapeInfoConnectionsMapping.GetBySecond((INotifyObservableDictionaryItemsChanged<string, IShapeInfo>)sender); 204 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> pair in e.Items) 205 this.AddConnection(pair.Key.Key, pair.Key.Value, pair.Value); 206 } 207 208 private void Connections_ItemsAdded(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>> e) { 209 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> pair in e.Items) 210 this.AddConnection(pair.Key.Key, pair.Key.Value, pair.Value); 211 } 212 213 private void Connections_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo>> e) { 226 214 IConnection connection; 227 foreach (KeyValuePair< string, IShapeInfo> pair in e.Items) {228 connection = this.GetConnection( shapeInfo, pair.Key);215 foreach (KeyValuePair<KeyValuePair<IShapeInfo, string>, IShapeInfo> pair in e.Items) { 216 connection = this.GetConnection(pair.Key.Key, pair.Key.Value); 229 217 this.RemoveConnection(connection); 230 218 } … … 237 225 IConnector connectorFrom = shapeFrom.Connectors.Where(c => c.Name == connectorName).First(); 238 226 IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").FirstOrDefault(); 239 240 IConnection connection = Factory.CreateConnection(connectorFrom, connectorTo); 241 this.connectionConnectorsMapping.Add(connection, new KeyValuePair<IConnector, IConnector>(connectorFrom, connectorTo)); 242 this.graphVisualization.Controller.Model.AddConnection(connection); 243 this.graphVisualization.Invalidate(); 227 KeyValuePair<IConnector, IConnector> connectorPair = new KeyValuePair<IConnector, IConnector>(connectorFrom, connectorTo); 228 if (!this.connectionConnectorsMapping.ContainsSecond(connectorPair)) { 229 IConnection connection = Factory.CreateConnection(connectorFrom, connectorTo); 230 this.connectionConnectorsMapping.Add(connection, connectorPair); 231 this.graphVisualization.Controller.Model.AddConnection(connection); 232 this.graphVisualization.Invalidate(); 233 } 244 234 } 245 235 … … 258 248 IConnection connection = this.GetConnection(shapeInfoFrom, connectorName); 259 249 IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom); 260 IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").First OrDefault();250 IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").First(); 261 251 262 252 connection.To.DetachFromParent(); … … 307 297 IConnection connection = e.Entity as IConnection; 308 298 if (connection != null && !this.connectionConnectorsMapping.ContainsFirst(connection)) { 309 if (connection.From.AttachedTo == null || connection.To.AttachedTo == null) 310 this.RemoveConnection(connection); 299 IConnector connectorFrom = connection.From.AttachedTo; 300 IConnector connectorTo = connection.To.AttachedTo; 301 this.RemoveConnection(connection); //is added again by the model events 302 303 if (connectorFrom != null && connectorTo != null) { 304 IShape shapeFrom = (IShape)connectorFrom.Parent; 305 IShape shapeTo = (IShape)connectorTo.Parent; 306 IShapeInfo shapeInfoFrom = this.shapeInfoShapeMapping.GetBySecond(shapeFrom); 307 IShapeInfo shapeInfoTo = this.shapeInfoShapeMapping.GetBySecond(shapeTo); 308 string connectorName = connectorFrom.Name; 309 310 this.VisualizationInfo.AddConnection(shapeInfoFrom, connectorName, shapeInfoTo); 311 } 311 312 } 312 313 } … … 321 322 IConnection connection = e.Entity as IConnection; 322 323 if (connection != null && this.connectionConnectorsMapping.ContainsFirst(connection)) { 323 IShape parentShape = this.connectorShapeMapping[connection.From.AttachedTo];324 IShape parentShape = (IShape)connection.From.AttachedTo.Parent; 324 325 IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(parentShape); 325 string parameterName = connection.From.AttachedTo.Name;326 327 shapeInfo.RemoveConnection(parameterName);326 string connectorName = connection.From.AttachedTo.Name; 327 328 this.VisualizationInfo.RemoveConnection(shapeInfo, connectorName); 328 329 } 329 330 }
Note: See TracChangeset
for help on using the changeset viewer.