Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/17/10 23:50:05 (14 years ago)
Author:
mkommend
Message:

completly refactored the graph visualization (ticket #867)

Location:
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General
Files:
1 added
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/GraphVisualizationInfoView.cs

    r3374 r3386  
    3737using System.Diagnostics;
    3838using System.Threading;
     39using System.Drawing.Drawing2D;
    3940
    4041namespace HeuristicLab.Operators.Views.GraphVisualization {
    4142  [View("GraphVisualizationInfo View")]
    42   [Content(typeof(GraphVisualizationInfo), false)]
     43  [Content(typeof(IGraphVisualizationInfo), true)]
    4344  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
    4949    public GraphVisualizationInfoView() {
    5050      InitializeComponent();
    51       this.causedUpdateOfShapeInfo = false;
    52       this.shapeInfoShapeMapping = new BidirectionalLookup<IOperatorShapeInfo, IShape>();
    53       this.shapeInfoConnectionsMapping = new BidirectionalLookup<IOperatorShapeInfo, INotifyObservableDictionaryItemsChanged<string, IOperatorShapeInfo>>();
    54       this.connectionConnectorsMapping = 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)
    5858      : this() {
    5959      this.Content = content;
     
    6464    }
    6565
    66     public new GraphVisualizationInfo Content {
    67       get { return (GraphVisualizationInfo)base.Content; }
     66    public new IGraphVisualizationInfo Content {
     67      get { return (IGraphVisualizationInfo)base.Content; }
    6868      set { base.Content = value; }
    6969    }
     
    7878      this.SetEnabledStateOfControls();
    7979    }
    80 
    8180    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();
    8382      HeuristicLab.Netron.Controller controller = this.Controller as HeuristicLab.Netron.Controller;
    8483      if (Content == null && deleteTool != null && controller != null)
    85         controller.RemoveTool(deleteTool); 
     84        controller.RemoveTool(deleteTool);
    8685      else {
    8786        if (ReadOnly && deleteTool != null && controller != null)
     
    9392
    9493    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)
    9698        this.RemoveShapeInfo(shapeInfo);
    97 
    9899      this.shapeInfoShapeMapping.Clear();
    99       this.shapeInfoConnectionsMapping.Clear();
    100       this.connectionConnectorsMapping.Clear();
    101100
    102101      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);
    110106        this.UpdateLayoutRoot();
    111107      }
    112108      this.SetEnabledStateOfControls();
    113109    }
    114 
    115110    private void UpdateLayoutRoot() {
    116       IOperatorShapeInfo shapeInfo = this.Content.InitialShape;
     111      IShapeInfo shapeInfo = this.Content.InitialShape;
    117112      if (shapeInfo != null)
    118113        this.graphVisualization.Controller.Model.LayoutRoot = this.shapeInfoShapeMapping.GetByFirst(shapeInfo);
     
    120115        this.graphVisualization.Controller.Model.LayoutRoot = null;
    121116    }
    122 
    123117    private void VisualizationInfo_InitialShapeChanged(object sender, EventArgs e) {
    124118      this.UpdateLayoutRoot();
     
    128122      base.RegisterContentEvents();
    129123      this.Content.InitialShapeChanged += new EventHandler(VisualizationInfo_InitialShapeChanged);
    130       this.Content.ObserveableShapeInfos.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IOperatorShapeInfo>(ShapeInfos_ItemsAdded);
    131       this.Content.ObserveableShapeInfos.ItemsRemoved += 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.ObservableConnections.ItemsRemoved += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsRemoved);
    136       this.Content.ObservableConnections.ItemsReplaced += new CollectionItemsChangedEventHandler<KeyValuePair<KeyValuePair<IOperatorShapeInfo, string>, IOperatorShapeInfo>>(Connections_ItemsReplaced);
    137       this.Content.ObservableConnections.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);
    138132    }
    139133
     
    141135      base.DeregisterContentEvents();
    142136      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)
    155150        this.RemoveShapeInfo(shapeInfo);
    156       foreach (IOperatorShapeInfo shapeInfo in e.Items)
     151      foreach (IShapeInfo shapeInfo in e.Items)
    157152        this.AddShapeInfo(shapeInfo);
    158153    }
    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)
    162156        this.AddShapeInfo(shapeInfo);
    163157    }
    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)
    167160        this.RemoveShapeInfo(shapeInfo);
    168161    }
    169162
    170     private void AddShapeInfo(IOperatorShapeInfo shapeInfo) {
     163    private void AddShapeInfo(IShapeInfo shapeInfo) {
    171164      this.RegisterShapeInfoEvents(shapeInfo);
    172 
    173165      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);
    177167      this.shapeInfoShapeMapping.Add(shapeInfo, shape);
    178168
     
    180170      this.graphVisualization.Invalidate();
    181171    }
    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        }
    203182    }
    204183
     
    206185      shapeInfo.Changed += new EventHandler(shapeInfo_Changed);
    207186    }
    208 
    209187    private void DeregisterShapeInfoEvents(IShapeInfo shapeInfo) {
    210188      shapeInfo.Changed -= new EventHandler(shapeInfo_Changed);
    211189    }
    212190
    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);
    256232        this.graphVisualization.Controller.Model.AddConnection(connection);
    257233        this.graphVisualization.Invalidate();
     
    259235    }
    260236
    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    }
    282244    private void RemoveConnection(IConnection connection) {
    283       if (connection == null)
    284         return;
    285 
    286245      if (connection.From.AttachedTo != null)
    287246        connection.From.DetachFromParent();
    288247      if (connection.To.AttachedTo != null)
    289248        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)) {
    294250        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);
    309280    }
    310281
     
    321292
    322293    private void shape_OnEntityChange(object sender, EntityEventArgs e) {
    323       if (this.causedUpdateOfShapeInfo)
    324         return;
    325 
    326       this.causedUpdateOfShapeInfo = true;
    327294      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);
    335299      this.graphVisualization.Invalidate();
    336       this.causedUpdateOfShapeInfo = false;
    337     }
     300    }
     301
    338302
    339303    private void graphVisualization_OnEntityAdded(object sender, EntityEventArgs e) {
    340304      IConnection connection = e.Entity as IConnection;
    341       if (connection != null && !this.connectionConnectorsMapping.ContainsFirst(connection)) {
     305      if (connection != null && !this.connectionInfoConnectionMapping.ContainsSecond(connection)) {
    342306        IConnector connectorFrom = connection.From.AttachedTo;
    343307        IConnector connectorTo = connection.To.AttachedTo;
    344308        this.RemoveConnection(connection); //is added again by the model events
    345309
    346         if (connectorFrom != null && connectorTo != null && connectorFrom.Name != "Predecessor") {
     310        if (connectorFrom != null && connectorTo != null) {
    347311          IShape shapeFrom = (IShape)connectorFrom.Parent;
    348312          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));
    355320        }
    356321      }
     
    360325      IShape shape = e.Entity as IShape;
    361326      if (shape != null && this.shapeInfoShapeMapping.ContainsSecond(shape)) {
    362         IOperatorShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape);
     327        IShapeInfo shapeInfo = this.shapeInfoShapeMapping.GetBySecond(shape);
    363328        this.Content.RemoveShapeInfo(shapeInfo);
    364329      }
    365330
    366331      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() {
    377340      if (this.shapeInfoShapeMapping.Count > 0
    378         && this.connectionConnectorsMapping.Count > 0
     341        && this.connectionInfoConnectionMapping.Count > 0
    379342        && this.Content.InitialShape != null) { //otherwise the layout does not work
    380343        string layoutName = "Standard TreeLayout";
Note: See TracChangeset for help on using the changeset viewer.