Changeset 3386
- Timestamp:
- 04/17/10 23:50:05 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 added
- 2 edited
- 11 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs
r3317 r3386 90 90 protected OperatorGraph(bool deserializing) : base(deserializing) { } 91 91 92 //mkommend: IMPROTANT DO NOT REMOVE THIS PRIVATE EVENT 93 //needed to register OperatorGraph events in GraphVisualizationInfo 94 public event EventHandler DeserializationFinished; 95 private void OnOperatorGraphDeserializationFinished() { 96 EventHandler handler = DeserializationFinished; 97 if(handler != null) 98 handler(this,EventArgs.Empty); 99 } 92 100 [StorableHook(HookType.AfterDeserialization)] 93 101 private void Initialize() { 94 102 RegisterOperatorsEvents(); 103 OnOperatorGraphDeserializationFinished(); 95 104 } 96 105 -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/GraphVisualizationInfoView.cs
r3374 r3386 37 37 using System.Diagnostics; 38 38 using System.Threading; 39 using System.Drawing.Drawing2D; 39 40 40 41 namespace HeuristicLab.Operators.Views.GraphVisualization { 41 42 [View("GraphVisualizationInfo View")] 42 [Content(typeof( GraphVisualizationInfo), false)]43 [Content(typeof(IGraphVisualizationInfo), true)] 43 44 public partial class GraphVisualizationInfoView : ContentView { 44 private BidirectionalLookup<IOperatorShapeInfo, IShape> shapeInfoShapeMapping; 45 private BidirectionalLookup<IOperatorShapeInfo, INotifyObservableDictionaryItemsChanged<string, IOperatorShapeInfo>> shapeInfoConnectionsMapping; 46 private BidirectionalLookup<IConnection, KeyValuePair<IConnector, IConnector>> connectionConnectorsMapping; 47 48 private bool causedUpdateOfShapeInfo; 45 private BidirectionalLookup<IShapeInfo, IShape> shapeInfoShapeMapping; 46 private BidirectionalLookup<IConnectionInfo, IConnection> connectionInfoConnectionMapping; 47 private LinePenStyle connectionPenStyle; 48 49 49 public GraphVisualizationInfoView() { 50 50 InitializeComponent(); 51 this. causedUpdateOfShapeInfo = false;52 this. shapeInfoShapeMapping = new BidirectionalLookup<IOperatorShapeInfo, IShape>();53 this. shapeInfoConnectionsMapping = new BidirectionalLookup<IOperatorShapeInfo, INotifyObservableDictionaryItemsChanged<string, IOperatorShapeInfo>>();54 this.connection ConnectorsMapping = new BidirectionalLookup<IConnection, KeyValuePair<IConnector, IConnector>>();55 } 56 57 public GraphVisualizationInfoView( GraphVisualizationInfo content)51 this.shapeInfoShapeMapping = new BidirectionalLookup<IShapeInfo, IShape>(); 52 this.connectionInfoConnectionMapping = new BidirectionalLookup<IConnectionInfo, IConnection>(); 53 this.connectionPenStyle = new LinePenStyle(); 54 this.connectionPenStyle.EndCap = LineCap.ArrowAnchor; 55 } 56 57 public GraphVisualizationInfoView(IGraphVisualizationInfo content) 58 58 : this() { 59 59 this.Content = content; … … 64 64 } 65 65 66 public new GraphVisualizationInfo Content {67 get { return ( GraphVisualizationInfo)base.Content; }66 public new IGraphVisualizationInfo Content { 67 get { return (IGraphVisualizationInfo)base.Content; } 68 68 set { base.Content = value; } 69 69 } … … 78 78 this.SetEnabledStateOfControls(); 79 79 } 80 81 80 private void SetEnabledStateOfControls() { 82 DeleteTool deleteTool = (DeleteTool) this.Controller.Tools.Where(t => t.Name == ControllerBase.DeleteToolName).FirstOrDefault();81 DeleteTool deleteTool = (DeleteTool)this.Controller.Tools.Where(t => t.Name == ControllerBase.DeleteToolName).FirstOrDefault(); 83 82 HeuristicLab.Netron.Controller controller = this.Controller as HeuristicLab.Netron.Controller; 84 83 if (Content == null && deleteTool != null && controller != null) 85 controller.RemoveTool(deleteTool); 84 controller.RemoveTool(deleteTool); 86 85 else { 87 86 if (ReadOnly && deleteTool != null && controller != null) … … 93 92 94 93 private void UpdateContent() { 95 foreach (IOperatorShapeInfo shapeInfo in this.shapeInfoShapeMapping.FirstValues) 94 foreach (IConnectionInfo connectionInfo in this.connectionInfoConnectionMapping.FirstValues) 95 this.RemoveConnectionInfo(connectionInfo); 96 this.connectionInfoConnectionMapping.Clear(); 97 foreach (IShapeInfo shapeInfo in this.shapeInfoShapeMapping.FirstValues) 96 98 this.RemoveShapeInfo(shapeInfo); 97 98 99 this.shapeInfoShapeMapping.Clear(); 99 this.shapeInfoConnectionsMapping.Clear();100 this.connectionConnectorsMapping.Clear();101 100 102 101 if (Content != null) { 103 foreach (IOperatorShapeInfo shapeInfo in this.Content.OperatorShapeInfos) 104 if (!this.shapeInfoShapeMapping.ContainsFirst(shapeInfo)) 105 this.AddShapeInfo(shapeInfo); 106 107 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> connection in this.Content.Connections) 108 this.AddConnection(connection.Key.Key, connection.Key.Value, connection.Value); 109 102 foreach (IShapeInfo shapeInfo in this.Content.ShapeInfos) 103 this.AddShapeInfo(shapeInfo); 104 foreach (IConnectionInfo connectionInfo in this.Content.ConnectionInfos) 105 this.AddConnectionInfo(connectionInfo); 110 106 this.UpdateLayoutRoot(); 111 107 } 112 108 this.SetEnabledStateOfControls(); 113 109 } 114 115 110 private void UpdateLayoutRoot() { 116 I OperatorShapeInfo shapeInfo = this.Content.InitialShape;111 IShapeInfo shapeInfo = this.Content.InitialShape; 117 112 if (shapeInfo != null) 118 113 this.graphVisualization.Controller.Model.LayoutRoot = this.shapeInfoShapeMapping.GetByFirst(shapeInfo); … … 120 115 this.graphVisualization.Controller.Model.LayoutRoot = null; 121 116 } 122 123 117 private void VisualizationInfo_InitialShapeChanged(object sender, EventArgs e) { 124 118 this.UpdateLayoutRoot(); … … 128 122 base.RegisterContentEvents(); 129 123 this.Content.InitialShapeChanged += new EventHandler(VisualizationInfo_InitialShapeChanged); 130 this.Content.ObserveableShapeInfos.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_ItemsAdded); 131 this.Content.ObserveableShapeInfos.Items Removed += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_ItemsRemoved);132 this.Content.ObserveableShapeInfos. CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_CollectionReset);133 134 this.Content.ObservableConnections.ItemsAdded += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsAdded); 135 this.Content.ObservableConnection s.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsRemoved);136 this.Content.ObservableConnection s.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsReplaced);137 this.Content.ObservableConnection s.CollectionReset += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_CollectionReset);124 125 this.Content.ObserveableShapeInfos.ItemsAdded += new CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsAdded); 126 this.Content.ObserveableShapeInfos.ItemsRemoved += new CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsRemoved); 127 this.Content.ObserveableShapeInfos.CollectionReset += new CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_CollectionReset); 128 129 this.Content.ObservableConnectionInfos.ItemsAdded += new CollectionItemsChangedEventHandler<IConnectionInfo>(ConnectionInfos_ItemsAdded); 130 this.Content.ObservableConnectionInfos.ItemsRemoved += new CollectionItemsChangedEventHandler<IConnectionInfo>(ConnectionInfos_ItemsRemoved); 131 this.Content.ObservableConnectionInfos.CollectionReset += new CollectionItemsChangedEventHandler<IConnectionInfo>(ConnectionInfos_CollectionReset); 138 132 } 139 133 … … 141 135 base.DeregisterContentEvents(); 142 136 this.Content.InitialShapeChanged -= new EventHandler(VisualizationInfo_InitialShapeChanged); 143 this.Content.ObserveableShapeInfos.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_ItemsAdded); 144 this.Content.ObserveableShapeInfos.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_ItemsRemoved); 145 this.Content.ObserveableShapeInfos.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_CollectionReset); 146 147 this.Content.ObservableConnections.ItemsAdded -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsAdded); 148 this.Content.ObservableConnections.ItemsRemoved -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsRemoved); 149 this.Content.ObservableConnections.ItemsReplaced -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsReplaced); 150 this.Content.ObservableConnections.CollectionReset -= new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_CollectionReset); 151 } 152 153 private void ShapeInfos_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IOperatorShapeInfo> e) { 154 foreach (IOperatorShapeInfo shapeInfo in e.OldItems) 137 138 this.Content.ObserveableShapeInfos.ItemsAdded -= new CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsAdded); 139 this.Content.ObserveableShapeInfos.ItemsRemoved -= new CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_ItemsRemoved); 140 this.Content.ObserveableShapeInfos.CollectionReset -= new CollectionItemsChangedEventHandler<IShapeInfo>(ShapeInfos_CollectionReset); 141 142 this.Content.ObservableConnectionInfos.ItemsAdded -= new CollectionItemsChangedEventHandler<IConnectionInfo>(ConnectionInfos_ItemsAdded); 143 this.Content.ObservableConnectionInfos.ItemsRemoved -= new CollectionItemsChangedEventHandler<IConnectionInfo>(ConnectionInfos_ItemsRemoved); 144 this.Content.ObservableConnectionInfos.CollectionReset -= new CollectionItemsChangedEventHandler<IConnectionInfo>(ConnectionInfos_CollectionReset); 145 } 146 147 #region ShapeInfos 148 private void ShapeInfos_CollectionReset(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IShapeInfo> e) { 149 foreach (IShapeInfo shapeInfo in e.OldItems) 155 150 this.RemoveShapeInfo(shapeInfo); 156 foreach (I OperatorShapeInfo shapeInfo in e.Items)151 foreach (IShapeInfo shapeInfo in e.Items) 157 152 this.AddShapeInfo(shapeInfo); 158 153 } 159 160 private void ShapeInfos_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IOperatorShapeInfo> e) { 161 foreach (IOperatorShapeInfo shapeInfo in e.Items) 154 private void ShapeInfos_ItemsAdded(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IShapeInfo> e) { 155 foreach (IShapeInfo shapeInfo in e.Items) 162 156 this.AddShapeInfo(shapeInfo); 163 157 } 164 165 private void ShapeInfos_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IOperatorShapeInfo> e) { 166 foreach (IOperatorShapeInfo shapeInfo in e.Items) 158 private void ShapeInfos_ItemsRemoved(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<IShapeInfo> e) { 159 foreach (IShapeInfo shapeInfo in e.Items) 167 160 this.RemoveShapeInfo(shapeInfo); 168 161 } 169 162 170 private void AddShapeInfo(I OperatorShapeInfo shapeInfo) {163 private void AddShapeInfo(IShapeInfo shapeInfo) { 171 164 this.RegisterShapeInfoEvents(shapeInfo); 172 173 165 IShape shape = shapeInfo.CreateShape(); 174 shape.OnEntityChange += new EventHandler<EntityEventArgs>(shape_OnEntityChange); 175 shape.OnMouseEnter += new EventHandler<EntityMouseEventArgs>(shape_OnMouseEnter); 176 shape.OnMouseLeave += new EventHandler<EntityMouseEventArgs>(shape_OnMouseLeave); 166 this.RegisterShapeEvents(shape); 177 167 this.shapeInfoShapeMapping.Add(shapeInfo, shape); 178 168 … … 180 170 this.graphVisualization.Invalidate(); 181 171 } 182 183 private void RemoveShapeInfo(IOperatorShapeInfo shapeInfo) { 184 this.DeregisterShapeInfoEvents(shapeInfo); 185 IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfo); 186 shape.OnEntityChange -= new EventHandler<EntityEventArgs>(shape_OnEntityChange); 187 shape.OnMouseEnter -= new EventHandler<EntityMouseEventArgs>(shape_OnMouseEnter); 188 shape.OnMouseLeave -= new EventHandler<EntityMouseEventArgs>(shape_OnMouseLeave); 189 190 IConnection connection; 191 foreach (IConnector connector in shape.Connectors) { 192 connection = this.GetConnection(shapeInfo, connector.Name); 193 this.RemoveConnection(connection); 194 } 195 196 this.shapeInfoShapeMapping.RemoveByFirst(shapeInfo); 197 this.shapeInfoConnectionsMapping.RemoveByFirst(shapeInfo); 198 199 if (this.graphVisualization.Controller.Model.Shapes.Contains(shape)) { 200 this.graphVisualization.Controller.Model.RemoveShape(shape); 201 } 202 this.graphVisualization.Invalidate(); 172 private void RemoveShapeInfo(IShapeInfo shapeInfo) { 173 this.DeregisterShapeInfoEvents(shapeInfo); 174 IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfo); 175 this.DeregisterShapeEvents(shape); 176 this.shapeInfoShapeMapping.RemoveByFirst(shapeInfo); 177 178 if (this.graphVisualization.Controller.Model.Shapes.Contains(shape)) { 179 this.graphVisualization.Controller.Model.RemoveShape(shape); 180 this.graphVisualization.Invalidate(); 181 } 203 182 } 204 183 … … 206 185 shapeInfo.Changed += new EventHandler(shapeInfo_Changed); 207 186 } 208 209 187 private void DeregisterShapeInfoEvents(IShapeInfo shapeInfo) { 210 188 shapeInfo.Changed -= new EventHandler(shapeInfo_Changed); 211 189 } 212 190 213 private void Connections_CollectionReset(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> e) { 214 IConnection connection; 215 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> pair in e.Items) { 216 connection = this.GetConnection(pair.Key.Key, pair.Key.Value); 217 this.RemoveConnection(connection); 218 } 219 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> pair in e.Items) 220 this.AddConnection(pair.Key.Key, pair.Key.Value, pair.Value); 221 } 222 223 private void Connections_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> e) { 224 IConnection connection; 225 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> pair in e.Items) { 226 connection = this.GetConnection(pair.Key.Key, pair.Key.Value); 227 this.RemoveConnection(connection); 228 } 229 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> pair in e.Items) 230 this.AddConnection(pair.Key.Key, pair.Key.Value, pair.Value); 231 } 232 233 private void Connections_ItemsAdded(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> e) { 234 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> pair in e.Items) 235 this.AddConnection(pair.Key.Key, pair.Key.Value, pair.Value); 236 } 237 238 private void Connections_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> e) { 239 IConnection connection; 240 foreach (KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> pair in e.Items) { 241 connection = this.GetConnection(pair.Key.Key, pair.Key.Value); 242 this.RemoveConnection(connection); 243 } 244 } 245 246 private void AddConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName, IOperatorShapeInfo shapeInfoTo) { 247 IShape shapeFrom = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom); 248 IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(shapeInfoTo); 249 250 IConnector connectorFrom = shapeFrom.Connectors.Where(c => c.Name == connectorName).First(); 251 IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").FirstOrDefault(); 252 KeyValuePair<IConnector, IConnector> connectorPair = new KeyValuePair<IConnector, IConnector>(connectorFrom, connectorTo); 253 if (!this.connectionConnectorsMapping.ContainsSecond(connectorPair)) { 254 IConnection connection = Factory.CreateConnection(connectorFrom, connectorTo); 255 this.connectionConnectorsMapping.Add(connection, connectorPair); 191 private void shapeInfo_Changed(object sender, EventArgs e) { 192 IShapeInfo shapeInfo = (IShapeInfo)sender; 193 IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfo); 194 this.DeregisterShapeEvents(shape); 195 shapeInfo.UpdateShape(shape); 196 shape.Invalidate(); 197 this.RegisterShapeEvents(shape); 198 } 199 #endregion 200 201 #region ConnectionInfos 202 private void ConnectionInfos_CollectionReset(object sender, CollectionItemsChangedEventArgs<IConnectionInfo> e) { 203 foreach (IConnectionInfo connectionInfo in e.Items) 204 this.RemoveConnectionInfo(connectionInfo); 205 foreach (IConnectionInfo connectionInfo in e.Items) 206 this.AddConnectionInfo(connectionInfo); 207 } 208 private void ConnectionInfos_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IConnectionInfo> e) { 209 foreach (IConnectionInfo connectionInfo in e.Items) 210 this.AddConnectionInfo(connectionInfo); 211 } 212 private void ConnectionInfos_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IConnectionInfo> e) { 213 foreach (IConnectionInfo connectionInfo in e.Items) 214 this.RemoveConnectionInfo(connectionInfo); 215 } 216 217 private void AddConnectionInfo(IConnectionInfo connectionInfo) { 218 this.RegisterConnectionInfoEvents(connectionInfo); 219 IShape shapeFrom = this.shapeInfoShapeMapping.GetByFirst(connectionInfo.From); 220 IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(connectionInfo.To); 221 222 IConnector connectorFrom = shapeFrom.Connectors.Where(c => c.Name == connectionInfo.ConnectorFrom).FirstOrDefault(); 223 IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == connectionInfo.ConnectorTo).FirstOrDefault(); 224 if (connectorFrom != null && connectorTo != null) { 225 Connection connection = new Connection(connectorFrom.Point, connectorTo.Point); 226 connection.From.AllowMove = false; 227 connection.To.AllowMove = false; 228 connectorFrom.AttachConnector(connection.From); 229 connectorTo.AttachConnector(connection.To); 230 connection.PenStyle = this.connectionPenStyle; 231 this.connectionInfoConnectionMapping.Add(connectionInfo, connection); 256 232 this.graphVisualization.Controller.Model.AddConnection(connection); 257 233 this.graphVisualization.Invalidate(); … … 259 235 } 260 236 261 private IConnection GetConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName) { 262 IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom); 263 IConnector connector = shape.Connectors.Where(c => c.Name == connectorName).First(); 264 265 if (!this.connectionConnectorsMapping.SecondValues.Any(p => p.Key == connector)) 266 return null; 267 268 KeyValuePair<IConnector, IConnector> connectorPair = this.connectionConnectorsMapping.SecondValues.Where(p => p.Key == connector).FirstOrDefault(); 269 return this.connectionConnectorsMapping.GetBySecond(connectorPair); 270 } 271 272 private void ChangeConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName, IOperatorShapeInfo shapeInfoTo) { 273 IConnection connection = this.GetConnection(shapeInfoFrom, connectorName); 274 IShape shapeTo = this.shapeInfoShapeMapping.GetByFirst(shapeInfoFrom); 275 IConnector connectorTo = shapeTo.Connectors.Where(c => c.Name == "Predecessor").First(); 276 277 connection.To.DetachFromParent(); 278 connection.To.AttachTo(connectorTo); 279 this.graphVisualization.Invalidate(); 280 } 281 237 private void RemoveConnectionInfo(IConnectionInfo connectionInfo) { 238 DeregisterConnectionInfoEvents(connectionInfo); 239 IConnection connection = this.connectionInfoConnectionMapping.GetByFirst(connectionInfo); 240 this.connectionInfoConnectionMapping.RemoveByFirst(connectionInfo); 241 this.RemoveConnection(connection); 242 243 } 282 244 private void RemoveConnection(IConnection connection) { 283 if (connection == null)284 return;285 286 245 if (connection.From.AttachedTo != null) 287 246 connection.From.DetachFromParent(); 288 247 if (connection.To.AttachedTo != null) 289 248 connection.To.DetachFromParent(); 290 291 if (this.connectionConnectorsMapping.ContainsFirst(connection)) 292 this.connectionConnectorsMapping.RemoveByFirst(connection); 293 if (this.graphVisualization.Controller.Model.Connections.Contains(connection)) 249 if (this.Controller.Model.Connections.Contains(connection)) { 294 250 this.graphVisualization.Controller.Model.Remove(connection); 295 this.graphVisualization.Invalidate(); 296 } 297 298 299 private void shapeInfo_Changed(object sender, EventArgs e) { 300 if (this.causedUpdateOfShapeInfo) 301 return; 302 303 this.causedUpdateOfShapeInfo = true; 304 IOperatorShapeInfo shapeInfo = (IOperatorShapeInfo)sender; 305 IShape shape = this.shapeInfoShapeMapping.GetByFirst(shapeInfo); 306 shapeInfo.UpdateShape(shape); 307 shape.Invalidate(); 308 this.causedUpdateOfShapeInfo = false; 251 this.graphVisualization.Invalidate(); 252 } 253 } 254 255 private void RegisterConnectionInfoEvents(IConnectionInfo connectionInfo) { 256 connectionInfo.Changed += new EventHandler(connectionInfo_Changed); 257 } 258 private void DeregisterConnectionInfoEvents(IConnectionInfo connectionInfo) { 259 connectionInfo.Changed -= new EventHandler(connectionInfo_Changed); 260 } 261 private void connectionInfo_Changed(object sender, EventArgs e) { 262 IConnectionInfo connectionInfo = (IConnectionInfo)sender; 263 IConnection connection = this.connectionInfoConnectionMapping.GetByFirst(connectionInfo); 264 this.RemoveConnectionInfo(connectionInfo); 265 this.AddConnectionInfo(connectionInfo); 266 } 267 #endregion 268 269 #region netron events - shapes, graphvisualization 270 private void RegisterShapeEvents(IShape shape) { 271 shape.OnEntityChange += new EventHandler<EntityEventArgs>(shape_OnEntityChange); 272 shape.OnMouseEnter += new EventHandler<EntityMouseEventArgs>(shape_OnMouseEnter); 273 shape.OnMouseLeave += new EventHandler<EntityMouseEventArgs>(shape_OnMouseLeave); 274 } 275 276 private void DeregisterShapeEvents(IShape shape) { 277 shape.OnEntityChange -= new EventHandler<EntityEventArgs>(shape_OnEntityChange); 278 shape.OnMouseEnter -= new EventHandler<EntityMouseEventArgs>(shape_OnMouseEnter); 279 shape.OnMouseLeave -= new EventHandler<EntityMouseEventArgs>(shape_OnMouseLeave); 309 280 } 310 281 … … 321 292 322 293 private void shape_OnEntityChange(object sender, EntityEventArgs e) { 323 if (this.causedUpdateOfShapeInfo)324 return;325 326 this.causedUpdateOfShapeInfo = true;327 294 IShape shape = e.Entity as IShape; 328 IOperatorShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape); 329 shapeInfo.Location = shape.Location; 330 331 OperatorShape operatorShape = shape as OperatorShape; 332 if (operatorShape != null) 333 shapeInfo.Collapsed = operatorShape.Collapsed; 334 295 IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape); 296 this.DeregisterShapeInfoEvents(shapeInfo); 297 shapeInfo.UpdateShapeInfo(shape); 298 this.RegisterShapeInfoEvents(shapeInfo); 335 299 this.graphVisualization.Invalidate(); 336 this.causedUpdateOfShapeInfo = false;337 } 300 } 301 338 302 339 303 private void graphVisualization_OnEntityAdded(object sender, EntityEventArgs e) { 340 304 IConnection connection = e.Entity as IConnection; 341 if (connection != null && !this.connection ConnectorsMapping.ContainsFirst(connection)) {305 if (connection != null && !this.connectionInfoConnectionMapping.ContainsSecond(connection)) { 342 306 IConnector connectorFrom = connection.From.AttachedTo; 343 307 IConnector connectorTo = connection.To.AttachedTo; 344 308 this.RemoveConnection(connection); //is added again by the model events 345 309 346 if (connectorFrom != null && connectorTo != null && connectorFrom.Name != "Predecessor") {310 if (connectorFrom != null && connectorTo != null) { 347 311 IShape shapeFrom = (IShape)connectorFrom.Parent; 348 312 IShape shapeTo = (IShape)connectorTo.Parent; 349 IOperatorShapeInfo shapeInfoFrom = this.shapeInfoShapeMapping.GetBySecond(shapeFrom); 350 IOperatorShapeInfo shapeInfoTo = this.shapeInfoShapeMapping.GetBySecond(shapeTo); 351 string connectorName = connectorFrom.Name; 352 353 if (shapeFrom != shapeTo) //avoid self references 354 this.Content.AddConnection(shapeInfoFrom, connectorName, shapeInfoTo); 313 IShapeInfo shapeInfoFrom = this.shapeInfoShapeMapping.GetBySecond(shapeFrom); 314 IShapeInfo shapeInfoTo = this.shapeInfoShapeMapping.GetBySecond(shapeTo); 315 string connectorFromName = connectorFrom.Name; 316 string connectorToName = connectorTo.Name; 317 318 if (shapeInfoFrom != shapeInfoTo) //avoid self references 319 this.Content.AddConnectionInfo(new ConnectionInfo(shapeInfoFrom, connectorFromName, shapeInfoTo, connectorToName)); 355 320 } 356 321 } … … 360 325 IShape shape = e.Entity as IShape; 361 326 if (shape != null && this.shapeInfoShapeMapping.ContainsSecond(shape)) { 362 I OperatorShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape);327 IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape); 363 328 this.Content.RemoveShapeInfo(shapeInfo); 364 329 } 365 330 366 331 IConnection connection = e.Entity as IConnection; 367 if (connection != null && this.connectionConnectorsMapping.ContainsFirst(connection)) { 368 IShape parentShape = (IShape)connection.From.AttachedTo.Parent; 369 IOperatorShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(parentShape); 370 string connectorName = connection.From.AttachedTo.Name; 371 372 this.Content.RemoveConnection(shapeInfo, connectorName); 373 } 374 } 375 376 internal void RelayoutGraph() { 332 if (connection != null && this.connectionInfoConnectionMapping.ContainsSecond(connection)) { 333 IConnectionInfo connectionInfo = connectionInfoConnectionMapping.GetBySecond(connection); 334 this.Content.RemoveConnectionInfo(connectionInfo); 335 } 336 } 337 #endregion 338 339 public void RelayoutGraph() { 377 340 if (this.shapeInfoShapeMapping.Count > 0 378 && this.connection ConnectorsMapping.Count > 0341 && this.connectionInfoConnectionMapping.Count > 0 379 342 && this.Content.InitialShape != null) { //otherwise the layout does not work 380 343 string layoutName = "Standard TreeLayout"; -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/IShapeInfo.cs
r3374 r3386 28 28 using Netron.Diagramming.Core; 29 29 using HeuristicLab.Collections; 30 using HeuristicLab.Common; 30 31 31 32 namespace HeuristicLab.Operators.Views.GraphVisualization { … … 35 36 36 37 IShape CreateShape(); 38 IEnumerable<string> Connectors { get; } 37 39 void UpdateShape(IShape shape); 40 void UpdateShapeInfo(IShape shape); 38 41 39 42 event EventHandler Changed; -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/ShapeInfo.cs
r3374 r3386 29 29 using HeuristicLab.Collections; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Common; 31 32 32 33 namespace HeuristicLab.Operators.Views.GraphVisualization { 33 34 [StorableClass] 34 internalabstract class ShapeInfo : DeepCloneable, IShapeInfo {35 public abstract class ShapeInfo : DeepCloneable, IShapeInfo { 35 36 private ShapeInfo() { 36 37 } … … 60 61 } 61 62 63 public abstract IEnumerable<string> Connectors { get; } 64 62 65 public event EventHandler Changed; 63 protected void OnChanged() { 64 if (this.Changed != null) 66 protected virtual void OnChanged() { 67 EventHandler handler = this.Changed; 68 if (handler != null) 65 69 this.Changed(this, EventArgs.Empty); 66 70 } … … 77 81 } 78 82 83 public virtual void UpdateShapeInfo(IShape shape) { 84 this.Location = shape.Location; 85 } 86 79 87 public override IDeepCloneable Clone(Cloner cloner) { 80 ShapeInfo clone = (ShapeInfo) 88 ShapeInfo clone = (ShapeInfo)base.Clone(cloner); 81 89 clone.shapeType = this.shapeType; 82 90 clone.location = this.location; -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/HeuristicLab.Operators.Views.GraphVisualization-3.3.csproj
r3384 r3386 86 86 <ItemGroup> 87 87 <Compile Include="HeuristicLabOperatorsViewsGraphVisualizationPlugin.cs" /> 88 <Compile Include="OperatorGraphView.cs">89 <SubType>UserControl</SubType>90 </Compile>91 <Compile Include="OperatorGraphView.Designer.cs">92 <DependentUpon>OperatorGraphView.cs</DependentUpon>93 </Compile>94 88 <Compile Include="Properties\AssemblyInfo.cs" /> 95 89 </ItemGroup> … … 98 92 <None Include="HeuristicLabOperatorsViewsGraphVisualizationPlugin.cs.frame" /> 99 93 <None Include="Properties\AssemblyInfo.frame" /> 100 <Compile Include="GraphVisualizationInfoView.cs"> 94 <Compile Include="General\GraphVisualizationInfo.cs" /> 95 <Compile Include="General\GraphVisualizationInfoView.cs"> 101 96 <SubType>UserControl</SubType> 102 97 </Compile> 103 <Compile Include="G raphVisualizationInfoView.Designer.cs">98 <Compile Include="General\GraphVisualizationInfoView.Designer.cs"> 104 99 <DependentUpon>GraphVisualizationInfoView.cs</DependentUpon> 105 100 </Compile> 106 <Compile Include="Model\IOperatorShapeInfo.cs" /> 107 <Compile Include="Model\OperatorShapeInfo.cs" /> 108 <Compile Include="Model\GraphVisualizationInfo.cs" /> 101 <Compile Include="General\ConnectionInfo.cs" /> 102 <Compile Include="General\IConnectionInfo.cs" /> 103 <Compile Include="General\IGraphVisualizationInfo.cs" /> 104 <Compile Include="OperatorGraphVisualization\IOperatorShapeInfo.cs" /> 105 <Compile Include="OperatorGraphVisualization\OperatorGraphView.cs"> 106 <SubType>UserControl</SubType> 107 </Compile> 108 <Compile Include="OperatorGraphVisualization\OperatorGraphView.Designer.cs"> 109 <DependentUpon>OperatorGraphView.cs</DependentUpon> 110 </Compile> 111 <Compile Include="OperatorGraphVisualization\OperatorGraphVisualizationInfo.cs"> 112 <SubType>Code</SubType> 113 </Compile> 114 <Compile Include="OperatorGraphVisualization\OperatorShapeInfo.cs" /> 109 115 <Compile Include="BidirectionalLookup.cs" /> 110 <Compile Include=" Model\IShapeInfo.cs" />111 <Compile Include=" Model\OperatorShape.cs" />112 <Compile Include=" Model\ShapeInfo.cs">116 <Compile Include="General\IShapeInfo.cs" /> 117 <Compile Include="OperatorGraphVisualization\OperatorShape.cs" /> 118 <Compile Include="General\ShapeInfo.cs"> 113 119 <SubType>Code</SubType> 114 120 </Compile> 115 <Compile Include=" Model\ShapeInfoFactory.cs" />121 <Compile Include="OperatorGraphVisualization\OperatorShapeInfoFactory.cs" /> 116 122 </ItemGroup> 117 123 <ItemGroup> -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphView.cs
r3374 r3386 66 66 bool createdVisualizationInfo = false; 67 67 if (this.VisualizationInfo == null) { 68 this.VisualizationInfo = new GraphVisualizationInfo(this.Content);68 this.VisualizationInfo = new OperatorGraphVisualizationInfo(this.Content); 69 69 createdVisualizationInfo = true; 70 70 } … … 108 108 } 109 109 110 private GraphVisualizationInfo VisualizationInfo {111 get { return Content.VisualizationInfo as GraphVisualizationInfo; }110 private OperatorGraphVisualizationInfo VisualizationInfo { 111 get { return Content.VisualizationInfo as OperatorGraphVisualizationInfo; } 112 112 set { this.Content.VisualizationInfo = value; } 113 113 } … … 228 228 if (e.Effect != DragDropEffects.None) { 229 229 IOperator op = e.Data.GetData("Value") as IOperator; 230 IOperatorShapeInfo shapeInfo = Factory.CreateOperatorShapeInfo(op);230 IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op); 231 231 Point mouse = new Point(MousePosition.X, MousePosition.Y); 232 232 Point screen = this.graphVisualizationInfoView.PointToScreen(new Point(0, 0)); -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphVisualizationInfo.cs
r3374 r3386 29 29 using HeuristicLab.Collections; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Common; 31 32 32 33 namespace HeuristicLab.Operators.Views.GraphVisualization { 33 34 [StorableClass] 34 public sealed class GraphVisualizationInfo : DeepCloneable { 35 public sealed class OperatorGraphVisualizationInfo : GraphVisualizationInfo { 36 [Storable] 35 37 private BidirectionalLookup<IOperator, IOperatorShapeInfo> operatorShapeInfoMapping; 36 [Storable]37 private BidirectionalLookup<IOperator, IOperatorShapeInfo> OperatorShapeInfoMappingStore {38 get { return this.operatorShapeInfoMapping; }39 set {40 IOperator op;41 IOperatorShapeInfo shapeInfo;42 foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in value.FirstEnumerable) {43 op = pair.Key;44 shapeInfo = pair.Value;45 shapeInfo.Icon = new Bitmap(op.ItemImage);46 this.RegisterOperatorEvents(op);47 this.operatorParameterCollectionMapping.Add(op, pair.Key.Parameters);48 this.operatorShapeInfoMapping.Add(op, shapeInfo);49 this.shapeInfos.Add(shapeInfo);50 }51 52 foreach (IOperator oper in value.FirstValues) {53 foreach (IParameter param in oper.Parameters) {54 this.parameterOperatorMapping.Add(param, oper);55 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;56 if (opParam != null) {57 this.RegisterOperatorParameterEvents(opParam);58 shapeInfo = this.operatorShapeInfoMapping.GetByFirst(oper);59 if (opParam.Value != null) {60 this.connections.Add(new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, param.Name), this.operatorShapeInfoMapping.GetByFirst(opParam.Value));61 }62 } else63 this.RegisterParameterEvents(param);64 }65 }66 }67 }68 69 38 private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping; 70 39 private Dictionary<IParameter, IOperator> parameterOperatorMapping; 71 40 72 private GraphVisualizationInfo() { 41 private OperatorGraphVisualizationInfo() 42 : base() { 73 43 this.operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>(); 74 44 this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>(); 75 45 this.parameterOperatorMapping = new Dictionary<IParameter, IOperator>(); 76 77 this.shapeInfos = new ObservableSet<IOperatorShapeInfo>(); 78 this.connections = new ObservableDictionary<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>(); 79 } 80 81 public GraphVisualizationInfo(OperatorGraph operatorGraph) 46 } 47 48 [StorableConstructor] 49 private OperatorGraphVisualizationInfo(bool deserializing) 50 : base() { 51 this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>(); 52 this.parameterOperatorMapping = new Dictionary<IParameter, IOperator>(); 53 } 54 55 public OperatorGraphVisualizationInfo(OperatorGraph operatorGraph) 82 56 : this() { 83 this.OperatorGraph = operatorGraph; 57 this.operatorGraph = operatorGraph; 58 this.RegisterOperatorGraphEvents(); 84 59 85 60 foreach (IOperator op in operatorGraph.Operators) 86 if (!this.operatorShapeInfoMapping.ContainsFirst(op)) 61 if (!this.operatorShapeInfoMapping.ContainsFirst(op)) //could be added by referencing parameters 87 62 this.AddOperator(op); 88 63 … … 90 65 } 91 66 67 [StorableHook(HookType.AfterDeserialization)] 68 private void DeserializationHook() { 69 this.operatorGraph.DeserializationFinished += new EventHandler(operatorGraph_DeserializationFinished); 70 71 IOperator op; 72 IOperatorShapeInfo shapeInfo; 73 foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in this.operatorShapeInfoMapping.FirstEnumerable) { 74 op = pair.Key; 75 shapeInfo = pair.Value; 76 shapeInfo.Icon = new Bitmap(op.ItemImage); 77 this.RegisterOperatorEvents(op); 78 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 79 } 80 81 foreach (IOperator oper in this.operatorShapeInfoMapping.FirstValues) { 82 foreach (IParameter param in oper.Parameters) { 83 this.parameterOperatorMapping.Add(param, oper); 84 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 85 if (opParam != null) 86 this.RegisterOperatorParameterEvents(opParam); 87 else 88 this.RegisterParameterEvents(param); 89 } 90 } 91 } 92 93 private void operatorGraph_DeserializationFinished(object sender, EventArgs e) { 94 this.RegisterOperatorGraphEvents(); 95 if (this.operatorGraph.InitialOperator != null) { 96 IOperatorShapeInfo newInitialShapeInfo = this.operatorShapeInfoMapping.GetByFirst(this.operatorGraph.InitialOperator); 97 if (newInitialShapeInfo != null) { 98 oldInitialShapeColor = newInitialShapeInfo.Color; 99 newInitialShapeInfo.Color = Color.LightGreen; 100 } 101 oldInitialShape = this.InitialShape; 102 this.OnInitialShapeChanged(); 103 } 104 this.operatorGraph.DeserializationFinished -= new EventHandler(operatorGraph_DeserializationFinished); 105 } 106 92 107 public override IDeepCloneable Clone(Cloner cloner) { 93 GraphVisualizationInfo clone = new GraphVisualizationInfo(); 94 cloner.RegisterClonedObject(this, clone); 108 OperatorGraphVisualizationInfo clone = (OperatorGraphVisualizationInfo)base.Clone(cloner); 95 109 clone.operatorGraph = (OperatorGraph)cloner.Clone(this.operatorGraph); 110 clone.RegisterOperatorGraphEvents(); 96 111 clone.oldInitialShape = (IOperatorShapeInfo)cloner.Clone(this.oldInitialShape); 97 112 clone.oldInitialShapeColor = this.oldInitialShapeColor; … … 105 120 clone.operatorParameterCollectionMapping.Add(op, pair.Key.Parameters); 106 121 clone.operatorShapeInfoMapping.Add(op, shapeInfo); 107 clone.shapeInfos.Add(shapeInfo);108 122 } 109 123 … … 112 126 clone.parameterOperatorMapping.Add(param, oper); 113 127 IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>; 114 if (opParam != null) {128 if (opParam != null) 115 129 clone.RegisterOperatorParameterEvents(opParam); 116 shapeInfo = clone.operatorShapeInfoMapping.GetByFirst(oper); 117 if (opParam.Value != null) { 118 clone.connections.Add(new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, param.Name), clone.operatorShapeInfoMapping.GetByFirst(opParam.Value)); 119 } 120 } else 130 else 121 131 clone.RegisterParameterEvents(param); 122 132 } 123 133 } 124 134 if (this.operatorGraph.InitialOperator != null) { 135 IOperatorShapeInfo newInitialShapeInfo = this.operatorShapeInfoMapping.GetByFirst(this.operatorGraph.InitialOperator); 136 if (newInitialShapeInfo != null) { 137 oldInitialShapeColor = newInitialShapeInfo.Color; 138 newInitialShapeInfo.Color = Color.LightGreen; 139 } 140 oldInitialShape = this.InitialShape; 141 this.OnInitialShapeChanged(); 142 } 125 143 return clone; 126 144 } 127 145 128 public event EventHandler InitialShapeChanged; 146 internal IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) { 147 return this.operatorShapeInfoMapping.GetBySecond(shapeInfo); 148 } 149 129 150 private void operatorGraph_InitialOperatorChanged(object sender, EventArgs e) { 130 151 this.UpdateInitialShape(); … … 143 164 144 165 oldInitialShape = this.InitialShape; 145 if (this.InitialShapeChanged != null) 146 this.InitialShapeChanged(this, new EventArgs()); 147 } 148 149 [Storable] 150 private IOperatorShapeInfo oldInitialShape; 151 [Storable] 166 this.OnInitialShapeChanged(); 167 } 168 169 private IShapeInfo oldInitialShape; 152 170 private Color oldInitialShapeColor; 153 public IOperatorShapeInfo InitialShape {171 public override IShapeInfo InitialShape { 154 172 get { 155 173 IOperator op = this.operatorGraph.InitialOperator; … … 161 179 if (value == null) 162 180 this.OperatorGraph.InitialOperator = null; 163 else 164 this.OperatorGraph.InitialOperator = this.operatorShapeInfoMapping.GetBySecond(value); 165 } 166 } 167 168 181 else { 182 IOperatorShapeInfo shapeInfo = (IOperatorShapeInfo)value; 183 this.OperatorGraph.InitialOperator = this.operatorShapeInfoMapping.GetBySecond(shapeInfo); 184 } 185 } 186 } 187 188 [Storable] 169 189 private OperatorGraph operatorGraph; 170 [Storable]171 190 public OperatorGraph OperatorGraph { 172 191 get { return this.operatorGraph; } 173 private set { 174 if (this.operatorGraph != null || value == null) 175 throw new InvalidOperationException("Could not set OperatorGraph"); 176 177 this.operatorGraph = value; 178 this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged); 179 this.operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded); 180 this.operatorGraph.Operators.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsRemoved); 181 this.operatorGraph.Operators.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_CollectionReset); 182 } 183 } 184 185 private ObservableSet<IOperatorShapeInfo> shapeInfos; 186 public INotifyObservableCollectionItemsChanged<IOperatorShapeInfo> ObserveableShapeInfos { 187 get { return this.shapeInfos; } 188 } 189 public IEnumerable<IOperatorShapeInfo> OperatorShapeInfos { 190 get { return this.shapeInfos; } 191 } 192 public IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) { 193 return this.operatorShapeInfoMapping.GetBySecond(shapeInfo); 194 } 195 196 private ObservableDictionary<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> connections; 197 public INotifyObservableDictionaryItemsChanged<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo> ObservableConnections { 198 get { return this.connections; } 199 } 200 public IEnumerable<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>> Connections { 201 get { return this.connections; } 192 } 193 194 private void RegisterOperatorGraphEvents() { 195 this.operatorGraph.InitialOperatorChanged += new EventHandler(operatorGraph_InitialOperatorChanged); 196 this.operatorGraph.Operators.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded); 197 this.operatorGraph.Operators.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsRemoved); 198 this.operatorGraph.Operators.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_CollectionReset); 199 } 200 201 private void DeregisterOperatorGraphEvents() { 202 this.operatorGraph.InitialOperatorChanged -= new EventHandler(operatorGraph_InitialOperatorChanged); 203 this.operatorGraph.Operators.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsAdded); 204 this.operatorGraph.Operators.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_ItemsRemoved); 205 this.operatorGraph.Operators.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperator>(Operators_CollectionReset); 202 206 } 203 207 … … 215 219 } 216 220 217 internal void RemoveShapeInfo(IOperatorShapeInfo shapeInfo) { 221 public override void RemoveShapeInfo(IShapeInfo shapeInfo) { 222 IOperatorShapeInfo opShapeInfo = (IOperatorShapeInfo)shapeInfo; 223 if (this.operatorShapeInfoMapping.ContainsSecond(opShapeInfo)) { 224 IOperator op = this.operatorShapeInfoMapping.GetBySecond(opShapeInfo); 225 this.operatorGraph.Operators.Remove(op); 226 } 227 } 228 229 public override void RemoveConnectionInfo(IConnectionInfo connectionInfo) { 230 IOperatorShapeInfo shapeInfo = (IOperatorShapeInfo)connectionInfo.From; 218 231 IOperator op = this.operatorShapeInfoMapping.GetBySecond(shapeInfo); 219 this.operatorGraph.Operators.Remove(op); 220 } 221 222 internal void AddConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName, IOperatorShapeInfo shapeInfoTo) { 223 IOperator opFrom = this.operatorShapeInfoMapping.GetBySecond(shapeInfoFrom); 224 IOperator opTo = this.operatorShapeInfoMapping.GetBySecond(shapeInfoTo); 225 226 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 227 param.Value = opTo; 228 } 229 230 internal void ChangeConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName, IOperatorShapeInfo shapeInfoTo) { 231 IOperator opFrom = this.operatorShapeInfoMapping.GetBySecond(shapeInfoFrom); 232 IOperator opTo = this.operatorShapeInfoMapping.GetBySecond(shapeInfoTo); 233 234 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 235 param.Value = opTo; 236 } 237 238 internal void RemoveConnection(IOperatorShapeInfo shapeInfoFrom, string connectorName) { 239 IOperator opFrom = this.operatorShapeInfoMapping.GetBySecond(shapeInfoFrom); 240 IValueParameter<IOperator> param = (IValueParameter<IOperator>)opFrom.Parameters[connectorName]; 232 IValueParameter<IOperator> param = (IValueParameter<IOperator>)op.Parameters[connectionInfo.ConnectorFrom]; 241 233 param.Value = null; 242 234 } … … 247 239 if (!this.operatorShapeInfoMapping.ContainsFirst(op)) { 248 240 this.RegisterOperatorEvents(op); 249 IOperatorShapeInfo shapeInfo = Factory.CreateOperatorShapeInfo(op);241 IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op); 250 242 this.operatorParameterCollectionMapping.Add(op, op.Parameters); 251 243 this.operatorShapeInfoMapping.Add(op, shapeInfo); … … 255 247 } 256 248 } 257 258 249 private void RemoveOperator(IOperator op) { 259 250 this.DeregisterOperatorEvents(op); … … 333 324 if (opParam != null) { 334 325 this.RegisterOperatorParameterEvents(opParam); 335 IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op);336 shapeInfo .AddConnector(param.Name);326 IOperatorShapeInfo shapeInfoFrom = this.operatorShapeInfoMapping.GetByFirst(op); 327 shapeInfoFrom.AddConnector(param.Name); 337 328 338 329 if (opParam.Value != null) { 339 330 if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value)) 340 331 this.AddOperator(opParam.Value); 341 this.connections.Add(new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, param.Name), this.operatorShapeInfoMapping.GetByFirst(opParam.Value)); 332 IOperatorShapeInfo shapeInfoTo = this.operatorShapeInfoMapping.GetByFirst(opParam.Value); 333 this.connectionInfos.Add(new ConnectionInfo(shapeInfoFrom, param.Name, shapeInfoTo, OperatorShapeInfoFactory.PredecessorConnector)); 342 334 } 343 335 } else … … 350 342 this.DeregisterOperatorParameterEvents(opParam); 351 343 IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op); 352 this.connections.Remove(new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, param.Name)); 344 this.connectionInfos.RemoveWhere(c => c.From == shapeInfo && c.ConnectorFrom == param.Name); 345 this.connectionInfos.RemoveWhere(c => c.To == shapeInfo && c.ConnectorTo == param.Name); 353 346 shapeInfo.RemoveConnector(param.Name); 354 347 } else … … 360 353 private void opParam_ValueChanged(object sender, EventArgs e) { 361 354 IValueParameter<IOperator> opParam = (IValueParameter<IOperator>)sender; 362 if (opParam != null) { 363 IOperator op = this.parameterOperatorMapping[opParam]; 364 IOperatorShapeInfo shapeInfo = this.operatorShapeInfoMapping.GetByFirst(op); 365 KeyValuePair<IOperatorShapeInfo, string> connectionFrom = new KeyValuePair<IOperatorShapeInfo, string>(shapeInfo, opParam.Name); 366 367 if (opParam.Value == null) 368 this.connections.Remove(connectionFrom); 369 else { 370 if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value)) 371 this.AddOperator(opParam.Value); 372 this.connections[connectionFrom] = this.operatorShapeInfoMapping.GetByFirst(opParam.Value); 373 } 355 IOperator op = this.parameterOperatorMapping[opParam]; 356 IOperatorShapeInfo shapeInfoFrom = this.operatorShapeInfoMapping.GetByFirst(op); 357 KeyValuePair<IOperatorShapeInfo, string> connectionFrom = new KeyValuePair<IOperatorShapeInfo, string>(shapeInfoFrom, opParam.Name); 358 359 this.connectionInfos.RemoveWhere(c => c.From == shapeInfoFrom && c.ConnectorFrom == opParam.Name); 360 if (opParam.Value != null) { 361 if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value)) 362 this.AddOperator(opParam.Value); 363 IShapeInfo shapeInfoTo = this.operatorShapeInfoMapping.GetByFirst(opParam.Value); 364 this.AddConnectionInfo(new ConnectionInfo(shapeInfoFrom, opParam.Name, shapeInfoTo, OperatorShapeInfoFactory.PredecessorConnector)); 374 365 } 375 366 } -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs
r3374 r3386 29 29 using System.Windows.Forms; 30 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using HeuristicLab.Common; 31 32 32 33 namespace HeuristicLab.Operators.Views.GraphVisualization { 33 34 [StorableClass] 34 35 internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo { 35 [Storable]36 private List<string> connectorNames;37 36 [Storable] 38 37 private List<string> labels; … … 57 56 58 57 public void AddConnector(string connectorName) { 59 if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") {58 if (!this.connectorNames.Contains(connectorName)) { 60 59 this.connectorNames.Add(connectorName); 61 60 this.OnChanged(); … … 73 72 this.labels = new List<string>(labels); 74 73 this.OnChanged(); 74 } 75 76 [Storable] 77 private List<string> connectorNames; 78 public override IEnumerable<string> Connectors { 79 get { return this.connectorNames; } 75 80 } 76 81 … … 163 168 public override void UpdateShape(IShape shape) { 164 169 base.UpdateShape(shape); 165 OperatorShape operatorShape = shape as OperatorShape; 166 if (operatorShape != null) { 167 operatorShape.Title = this.Title; 168 operatorShape.Color = this.Color; 169 operatorShape.LineColor = this.LineColor; 170 operatorShape.LineWidth = this.LineWidth; 171 operatorShape.Icon = this.Icon; 172 operatorShape.Collapsed = this.Collapsed; 173 174 int i = 0; 175 int j = 0; 176 //remove old connectors and skip correct connectors 177 List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList(); 178 while (i < this.connectorNames.Count && j < oldConnectorNames.Count) { 179 if (this.connectorNames[i] != oldConnectorNames[j]) { 180 operatorShape.RemoveConnector(oldConnectorNames[j]); 181 } else 182 i++; 183 j++; 184 } 185 //remove remaining old connectors 186 for (; j < oldConnectorNames.Count; j++) 170 OperatorShape operatorShape = (OperatorShape)shape; 171 operatorShape.Title = this.Title; 172 operatorShape.Color = this.Color; 173 operatorShape.LineColor = this.LineColor; 174 operatorShape.LineWidth = this.LineWidth; 175 operatorShape.Icon = this.Icon; 176 operatorShape.Collapsed = this.Collapsed; 177 178 int i = 0; 179 int j = 0; 180 //remove old connectors and skip correct connectors 181 List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList(); 182 while (i < this.connectorNames.Count && j < oldConnectorNames.Count) { 183 if (this.connectorNames[i] != oldConnectorNames[j]) { 187 184 operatorShape.RemoveConnector(oldConnectorNames[j]); 188 189 //add new connectors 190 for (; i < this.connectorNames.Count; i++) 191 operatorShape.AddConnector(this.connectorNames[i]); 192 193 operatorShape.UpdateLabels(this.labels); 194 } 185 } else 186 i++; 187 j++; 188 } 189 //remove remaining old connectors 190 for (; j < oldConnectorNames.Count; j++) 191 operatorShape.RemoveConnector(oldConnectorNames[j]); 192 193 //add new connectors 194 for (; i < this.connectorNames.Count; i++) 195 operatorShape.AddConnector(this.connectorNames[i]); 196 197 operatorShape.UpdateLabels(this.labels); 198 } 199 200 public override void UpdateShapeInfo(IShape shape) { 201 base.UpdateShapeInfo(shape); 202 OperatorShape operatorShape = (OperatorShape)shape; 203 this.Title = operatorShape.Title; 204 this.Color = operatorShape.Color; 205 this.LineColor = operatorShape.LineColor; 206 this.LineWidth = operatorShape.LineWidth; 207 this.Icon = operatorShape.Icon; 208 this.Collapsed = operatorShape.Collapsed; 209 210 //TODO update Connector and labels; 195 211 } 196 212 197 213 public override IDeepCloneable Clone(Cloner cloner) { 198 OperatorShapeInfo clone = (OperatorShapeInfo) 214 OperatorShapeInfo clone = (OperatorShapeInfo)base.Clone(cloner); 199 215 clone.collapsed = this.collapsed; 200 216 clone.color = this.color; … … 202 218 clone.lineWidth = this.lineWidth; 203 219 clone.title = this.title; 204 clone.icon = (Bitmap) 220 clone.icon = (Bitmap)this.icon.Clone(); 205 221 206 222 clone.connectorNames = new List<string>(this.connectorNames); -
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfoFactory.cs
r3374 r3386 30 30 31 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 32 public static class Factory { 33 private static LinePenStyle connectionPenStyle; 34 35 static Factory() { 36 connectionPenStyle = new LinePenStyle(); 37 connectionPenStyle.EndCap = LineCap.ArrowAnchor; 38 } 39 32 internal static class OperatorShapeInfoFactory { 33 public const string PredecessorConnector = "Predecessor"; 40 34 public static IOperatorShapeInfo CreateOperatorShapeInfo(IOperator op) { 41 IEnumerable<string> operatorParameterNames = op.Parameters.Where(p => p is IValueParameter<IOperator> && p.Name != "Successor").Select(p => p.Name);35 IEnumerable<string> operatorParameterNames = op.Parameters.Where(p => p is IValueParameter<IOperator>).Select(p => p.Name); 42 36 IEnumerable<string> paramaterNameValues = op.Parameters.Where(p => !(p is IValueParameter<IOperator>)).Select(p => p.ToString()); 43 37 44 OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames,paramaterNameValues); 38 OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames, paramaterNameValues); 39 operatorShapeInfo.AddConnector(PredecessorConnector); 45 40 operatorShapeInfo.Collapsed = true; 46 41 operatorShapeInfo.Title = op.Name; … … 52 47 return operatorShapeInfo; 53 48 } 54 55 public static IConnection CreateConnection(IConnector from, IConnector to) {56 Connection connection = new Connection(from.Point, to.Point);57 connection.From.AllowMove = false;58 connection.To.AllowMove = false;59 from.AttachConnector(connection.From);60 61 to.AttachConnector(connection.To);62 connection.PenStyle = connectionPenStyle;63 return connection;64 }65 49 } 66 50 }
Note: See TracChangeset
for help on using the changeset viewer.