Free cookie consent management tool by TermsFeed Policy Generator

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

completly refactored the graph visualization (ticket #867)

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

Legend:

Unmodified
Added
Removed
  • 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.