Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3386


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

completly refactored the graph visualization (ticket #867)

Location:
trunk/sources
Files:
6 added
2 edited
11 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core/3.3/OperatorGraph.cs

    r3317 r3386  
    9090    protected OperatorGraph(bool deserializing) : base(deserializing) { }
    9191
     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    }
    92100    [StorableHook(HookType.AfterDeserialization)]
    93101    private void Initialize() {
    94102      RegisterOperatorsEvents();
     103      OnOperatorGraphDeserializationFinished();
    95104    }
    96105
  • 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";
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/IShapeInfo.cs

    r3374 r3386  
    2828using Netron.Diagramming.Core;
    2929using HeuristicLab.Collections;
     30using HeuristicLab.Common;
    3031
    3132namespace HeuristicLab.Operators.Views.GraphVisualization {
     
    3536
    3637    IShape CreateShape();
     38    IEnumerable<string> Connectors { get; }
    3739    void UpdateShape(IShape shape);
     40    void UpdateShapeInfo(IShape shape);
    3841
    3942    event EventHandler Changed;
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/ShapeInfo.cs

    r3374 r3386  
    2929using HeuristicLab.Collections;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Common;
    3132
    3233namespace HeuristicLab.Operators.Views.GraphVisualization {
    3334  [StorableClass]
    34   internal abstract class ShapeInfo : DeepCloneable, IShapeInfo {
     35  public abstract class ShapeInfo : DeepCloneable, IShapeInfo {
    3536    private ShapeInfo() {
    3637    }
     
    6061    }
    6162
     63    public abstract IEnumerable<string> Connectors { get; }
     64
    6265    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)
    6569        this.Changed(this, EventArgs.Empty);
    6670    }
     
    7781    }
    7882
     83    public virtual void UpdateShapeInfo(IShape shape) {
     84      this.Location = shape.Location;
     85    }
     86
    7987    public override IDeepCloneable Clone(Cloner cloner) {
    80       ShapeInfo clone = (ShapeInfo) base.Clone(cloner);
     88      ShapeInfo clone = (ShapeInfo)base.Clone(cloner);
    8189      clone.shapeType = this.shapeType;
    8290      clone.location = this.location;
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/HeuristicLab.Operators.Views.GraphVisualization-3.3.csproj

    r3384 r3386  
    8686  <ItemGroup>
    8787    <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>
    9488    <Compile Include="Properties\AssemblyInfo.cs" />
    9589  </ItemGroup>
     
    9892    <None Include="HeuristicLabOperatorsViewsGraphVisualizationPlugin.cs.frame" />
    9993    <None Include="Properties\AssemblyInfo.frame" />
    100     <Compile Include="GraphVisualizationInfoView.cs">
     94    <Compile Include="General\GraphVisualizationInfo.cs" />
     95    <Compile Include="General\GraphVisualizationInfoView.cs">
    10196      <SubType>UserControl</SubType>
    10297    </Compile>
    103     <Compile Include="GraphVisualizationInfoView.Designer.cs">
     98    <Compile Include="General\GraphVisualizationInfoView.Designer.cs">
    10499      <DependentUpon>GraphVisualizationInfoView.cs</DependentUpon>
    105100    </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" />
    109115    <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">
    113119      <SubType>Code</SubType>
    114120    </Compile>
    115     <Compile Include="Model\ShapeInfoFactory.cs" />
     121    <Compile Include="OperatorGraphVisualization\OperatorShapeInfoFactory.cs" />
    116122  </ItemGroup>
    117123  <ItemGroup>
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphView.cs

    r3374 r3386  
    6666      bool createdVisualizationInfo = false;
    6767      if (this.VisualizationInfo == null) {
    68         this.VisualizationInfo = new GraphVisualizationInfo(this.Content);
     68        this.VisualizationInfo = new OperatorGraphVisualizationInfo(this.Content);
    6969        createdVisualizationInfo = true;
    7070      }
     
    108108    }
    109109
    110     private GraphVisualizationInfo VisualizationInfo {
    111       get { return Content.VisualizationInfo as GraphVisualizationInfo; }
     110    private OperatorGraphVisualizationInfo VisualizationInfo {
     111      get { return Content.VisualizationInfo as OperatorGraphVisualizationInfo; }
    112112      set { this.Content.VisualizationInfo = value; }
    113113    }
     
    228228      if (e.Effect != DragDropEffects.None) {
    229229        IOperator op = e.Data.GetData("Value") as IOperator;
    230         IOperatorShapeInfo shapeInfo = Factory.CreateOperatorShapeInfo(op);
     230        IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op);
    231231        Point mouse = new Point(MousePosition.X, MousePosition.Y);
    232232        Point screen = this.graphVisualizationInfoView.PointToScreen(new Point(0, 0));
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphVisualizationInfo.cs

    r3374 r3386  
    2929using HeuristicLab.Collections;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Common;
    3132
    3233namespace HeuristicLab.Operators.Views.GraphVisualization {
    3334  [StorableClass]
    34   public sealed class GraphVisualizationInfo : DeepCloneable {
     35  public sealed class OperatorGraphVisualizationInfo : GraphVisualizationInfo {
     36    [Storable]
    3537    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             } else
    63               this.RegisterParameterEvents(param);
    64           }
    65         }
    66       }
    67     }
    68 
    6938    private BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>> operatorParameterCollectionMapping;
    7039    private Dictionary<IParameter, IOperator> parameterOperatorMapping;
    7140
    72     private GraphVisualizationInfo() {
     41    private OperatorGraphVisualizationInfo()
     42      : base() {
    7343      this.operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>();
    7444      this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IObservableKeyedCollection<string, IParameter>>();
    7545      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)
    8256      : this() {
    83       this.OperatorGraph = operatorGraph;
     57      this.operatorGraph = operatorGraph;
     58      this.RegisterOperatorGraphEvents();
    8459
    8560      foreach (IOperator op in operatorGraph.Operators)
    86         if (!this.operatorShapeInfoMapping.ContainsFirst(op))
     61        if (!this.operatorShapeInfoMapping.ContainsFirst(op))  //could be added by referencing parameters
    8762          this.AddOperator(op);
    8863
     
    9065    }
    9166
     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
    92107    public override IDeepCloneable Clone(Cloner cloner) {
    93       GraphVisualizationInfo clone = new GraphVisualizationInfo();
    94       cloner.RegisterClonedObject(this, clone);
     108      OperatorGraphVisualizationInfo clone = (OperatorGraphVisualizationInfo)base.Clone(cloner);
    95109      clone.operatorGraph = (OperatorGraph)cloner.Clone(this.operatorGraph);
     110      clone.RegisterOperatorGraphEvents();
    96111      clone.oldInitialShape = (IOperatorShapeInfo)cloner.Clone(this.oldInitialShape);
    97112      clone.oldInitialShapeColor = this.oldInitialShapeColor;
     
    105120        clone.operatorParameterCollectionMapping.Add(op, pair.Key.Parameters);
    106121        clone.operatorShapeInfoMapping.Add(op, shapeInfo);
    107         clone.shapeInfos.Add(shapeInfo);
    108122      }
    109123
     
    112126          clone.parameterOperatorMapping.Add(param, oper);
    113127          IValueParameter<IOperator> opParam = param as IValueParameter<IOperator>;
    114           if (opParam != null) {
     128          if (opParam != null)
    115129            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
    121131            clone.RegisterParameterEvents(param);
    122132        }
    123133      }
    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      }
    125143      return clone;
    126144    }
    127145
    128     public event EventHandler InitialShapeChanged;
     146    internal IOperator GetOperatorForShapeInfo(IOperatorShapeInfo shapeInfo) {
     147      return this.operatorShapeInfoMapping.GetBySecond(shapeInfo);
     148    }
     149
    129150    private void operatorGraph_InitialOperatorChanged(object sender, EventArgs e) {
    130151      this.UpdateInitialShape();
     
    143164
    144165      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;
    152170    private Color oldInitialShapeColor;
    153     public IOperatorShapeInfo InitialShape {
     171    public override IShapeInfo InitialShape {
    154172      get {
    155173        IOperator op = this.operatorGraph.InitialOperator;
     
    161179        if (value == null)
    162180          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]
    169189    private OperatorGraph operatorGraph;
    170     [Storable]
    171190    public OperatorGraph OperatorGraph {
    172191      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);
    202206    }
    203207
     
    215219    }
    216220
    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;
    218231      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];
    241233      param.Value = null;
    242234    }
     
    247239      if (!this.operatorShapeInfoMapping.ContainsFirst(op)) {
    248240        this.RegisterOperatorEvents(op);
    249         IOperatorShapeInfo shapeInfo = Factory.CreateOperatorShapeInfo(op);
     241        IOperatorShapeInfo shapeInfo = OperatorShapeInfoFactory.CreateOperatorShapeInfo(op);
    250242        this.operatorParameterCollectionMapping.Add(op, op.Parameters);
    251243        this.operatorShapeInfoMapping.Add(op, shapeInfo);
     
    255247      }
    256248    }
    257 
    258249    private void RemoveOperator(IOperator op) {
    259250      this.DeregisterOperatorEvents(op);
     
    333324      if (opParam != null) {
    334325        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);
    337328
    338329        if (opParam.Value != null) {
    339330          if (!this.operatorShapeInfoMapping.ContainsFirst(opParam.Value))
    340331            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));
    342334        }
    343335      } else
     
    350342        this.DeregisterOperatorParameterEvents(opParam);
    351343        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);
    353346        shapeInfo.RemoveConnector(param.Name);
    354347      } else
     
    360353    private void opParam_ValueChanged(object sender, EventArgs e) {
    361354      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));
    374365      }
    375366    }
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs

    r3374 r3386  
    2929using System.Windows.Forms;
    3030using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Common;
    3132
    3233namespace HeuristicLab.Operators.Views.GraphVisualization {
    3334  [StorableClass]
    3435  internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
    35     [Storable]
    36     private List<string> connectorNames;
    3736    [Storable]
    3837    private List<string> labels;
     
    5756
    5857    public void AddConnector(string connectorName) {
    59       if (!this.connectorNames.Contains(connectorName) && connectorName != "Successor") {
     58      if (!this.connectorNames.Contains(connectorName)) {
    6059        this.connectorNames.Add(connectorName);
    6160        this.OnChanged();
     
    7372      this.labels = new List<string>(labels);
    7473      this.OnChanged();
     74    }
     75
     76    [Storable]
     77    private List<string> connectorNames;
     78    public override IEnumerable<string> Connectors {
     79      get { return this.connectorNames; }
    7580    }
    7681
     
    163168    public override void UpdateShape(IShape shape) {
    164169      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]) {
    187184          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;
    195211    }
    196212
    197213    public override IDeepCloneable Clone(Cloner cloner) {
    198       OperatorShapeInfo clone = (OperatorShapeInfo) base.Clone(cloner);
     214      OperatorShapeInfo clone = (OperatorShapeInfo)base.Clone(cloner);
    199215      clone.collapsed = this.collapsed;
    200216      clone.color = this.color;
     
    202218      clone.lineWidth = this.lineWidth;
    203219      clone.title = this.title;
    204       clone.icon = (Bitmap) this.icon.Clone();
     220      clone.icon = (Bitmap)this.icon.Clone();
    205221
    206222      clone.connectorNames = new List<string>(this.connectorNames);
  • trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfoFactory.cs

    r3374 r3386  
    3030
    3131namespace 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";
    4034    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);
    4236      IEnumerable<string> paramaterNameValues = op.Parameters.Where(p => !(p is IValueParameter<IOperator>)).Select(p => p.ToString());
    4337
    44       OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames,paramaterNameValues);
     38      OperatorShapeInfo operatorShapeInfo = new OperatorShapeInfo(operatorParameterNames, paramaterNameValues);
     39      operatorShapeInfo.AddConnector(PredecessorConnector);
    4540      operatorShapeInfo.Collapsed = true;
    4641      operatorShapeInfo.Title = op.Name;
     
    5247      return operatorShapeInfo;
    5348    }
    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     }
    6549  }
    6650}
Note: See TracChangeset for help on using the changeset viewer.