- Timestamp:
- 04/17/10 23:50:05 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General
- Files:
-
- 5 added
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.