Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/10 18:50:00 (14 years ago)
Author:
mkommend
Message:

Refactored Operators.* (ticket #922).

Location:
branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/BidirectionalLookup.cs

    r4068 r4673  
    3131    [Storable]
    3232    private Dictionary<TSecond, TFirst> secondToFirst;
     33
     34    [StorableConstructor]
     35    protected BidirectionalLookup(bool deserializing) : base() { }
    3336
    3437    public BidirectionalLookup() {
  • branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/ConnectionInfo.cs

    r4068 r4673  
    2828  [StorableClass]
    2929  public class ConnectionInfo : DeepCloneable, IConnectionInfo {
    30     private ConnectionInfo() {
     30    [StorableConstructor]
     31    private ConnectionInfo(bool deserializing) : base() { }
     32    private ConnectionInfo(ConnectionInfo original, Cloner cloner)
     33      : base(original, cloner) {
     34      from = cloner.Clone(original.from);
     35      connectorFrom = original.ConnectorFrom;
     36      to = cloner.Clone(original.To);
     37      connectorTo = original.ConnectorTo;
     38    }
     39    public override IDeepCloneable Clone(Cloner cloner) {
     40      return new ConnectionInfo(this, cloner);
    3141    }
    3242    public ConnectionInfo(IShapeInfo from, string connectorFrom, IShapeInfo to, string connectorTo)
    33       : this() {
     43      : base() {
    3444      if (from == to)
    3545        throw new ArgumentException("Could not create connections between the same shape info.");
     
    7080    protected virtual void OnChanged() {
    7181      EventHandler handler = this.Changed;
    72       if (handler != null)
    73         this.Changed(this, EventArgs.Empty);
    74     }
    75 
    76     public override IDeepCloneable Clone(Cloner cloner) {
    77       ConnectionInfo clone = (ConnectionInfo)base.Clone(cloner);
    78       clone.from = (IShapeInfo)cloner.Clone(this.from);
    79       clone.connectorFrom = this.ConnectorFrom;
    80       clone.to = (IShapeInfo)cloner.Clone(this.To);
    81       clone.connectorTo = this.ConnectorTo;
    82       return clone;
     82      if (handler != null) this.Changed(this, EventArgs.Empty);
    8383    }
    8484  }
  • branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/GraphVisualizationInfo.cs

    r4068 r4673  
    3030  [StorableClass]
    3131  public class GraphVisualizationInfo : DeepCloneable, IGraphVisualizationInfo {
    32     public GraphVisualizationInfo() {
     32    [StorableConstructor]
     33    protected GraphVisualizationInfo(bool deserializing) : base() { }
     34    protected GraphVisualizationInfo(GraphVisualizationInfo original, Cloner cloner)
     35      : base(original, cloner) {
     36      shapeInfos = new ObservableSet<IShapeInfo>(original.shapeInfos.Select(x => cloner.Clone(x)));
     37      connectionInfos = new ObservableSet<IConnectionInfo>(original.connectionInfos.Select(x => cloner.Clone(x)));
     38      initialShape = cloner.Clone(original.initialShape);
     39    }
     40    public override IDeepCloneable Clone(Cloner cloner) {
     41      return new GraphVisualizationInfo(this, cloner);
     42    }
     43    public GraphVisualizationInfo()
     44      : base() {
    3345      this.shapeInfos = new ObservableSet<IShapeInfo>();
    3446      this.connectionInfos = new ObservableSet<IConnectionInfo>();
     
    96108    }
    97109    #endregion
    98 
    99     public override IDeepCloneable Clone(Cloner cloner) {
    100       GraphVisualizationInfo clone = (GraphVisualizationInfo)base.Clone(cloner);
    101       clone.shapeInfos = new ObservableSet<IShapeInfo>(this.shapeInfos.Select(x => (IShapeInfo)cloner.Clone(x)));
    102       clone.connectionInfos = new ObservableSet<IConnectionInfo>(this.connectionInfos.Select(x => (IConnectionInfo)cloner.Clone(x)));
    103       if (this.initialShape != null)
    104         clone.initialShape = (IShapeInfo)this.initialShape.Clone(cloner);
    105       return clone;
    106     }
    107110  }
    108111}
  • branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/General/ShapeInfo.cs

    r4068 r4673  
    3030  [StorableClass]
    3131  public abstract class ShapeInfo : DeepCloneable, IShapeInfo {
    32     private ShapeInfo() {
     32    [StorableConstructor]
     33    protected ShapeInfo(bool deserializing) : base() { }
     34    protected ShapeInfo(ShapeInfo original, Cloner cloner)
     35      : base(original, cloner) {
     36      shapeType = original.shapeType;
     37      location = original.location;
    3338    }
    3439
     
    6267    protected virtual void OnChanged() {
    6368      EventHandler handler = this.Changed;
    64       if (handler != null)
    65         this.Changed(this, EventArgs.Empty);
     69      if (handler != null) this.Changed(this, EventArgs.Empty);
    6670    }
    6771
     
    8084      this.Location = shape.Location;
    8185    }
    82 
    83     public override IDeepCloneable Clone(Cloner cloner) {
    84       ShapeInfo clone = (ShapeInfo)base.Clone(cloner);
    85       clone.shapeType = this.shapeType;
    86       clone.location = this.location;
    87       return clone;
    88     }
    8986  }
    9087}
  • branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorGraphVisualizationInfo.cs

    r4068 r4673  
    4646    [StorableConstructor]
    4747    private OperatorGraphVisualizationInfo(bool deserializing)
    48       : base() {
     48      : base(deserializing) {
    4949      this.operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IKeyedItemCollection<string, IParameter>>();
    5050      this.parameterOperatorMapping = new Dictionary<IParameter, IOperator>();
     51    }
     52    private OperatorGraphVisualizationInfo(OperatorGraphVisualizationInfo original, Cloner cloner)
     53      : base(original, cloner) {
     54      operatorShapeInfoMapping = new BidirectionalLookup<IOperator, IOperatorShapeInfo>();
     55      operatorParameterCollectionMapping = new BidirectionalLookup<IOperator, IKeyedItemCollection<string, IParameter>>();
     56      parameterOperatorMapping = new Dictionary<IParameter, IOperator>();
     57
     58      operatorGraph = cloner.Clone(original.operatorGraph);
     59      RegisterOperatorGraphEvents();
     60      oldInitialShape = cloner.Clone(original.oldInitialShape);
     61      oldInitialShapeColor = original.oldInitialShapeColor;
     62
     63      foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in original.operatorShapeInfoMapping.FirstEnumerable) {
     64        IOperator op = cloner.Clone(pair.Key);
     65        IOperatorShapeInfo shapeInfo = cloner.Clone(pair.Value);
     66        RegisterOperatorEvents(op);
     67        operatorParameterCollectionMapping.Add(op, pair.Key.Parameters);
     68        operatorShapeInfoMapping.Add(op, shapeInfo);
     69      }
     70
     71      foreach (IOperator oper in operatorShapeInfoMapping.FirstValues) {
     72        foreach (IParameter param in oper.Parameters) {
     73          parameterOperatorMapping.Add(param, oper);
     74          IValueParameter opParam = param as IValueParameter;
     75          if (opParam != null && typeof(IOperator).IsAssignableFrom(param.DataType))
     76            RegisterOperatorParameterEvents(opParam);
     77          else
     78            RegisterParameterEvents(param);
     79        }
     80      }
     81      if (original.operatorGraph.InitialOperator != null) {
     82        IOperatorShapeInfo newInitialShapeInfo = original.operatorShapeInfoMapping.GetByFirst(original.operatorGraph.InitialOperator);
     83        if (newInitialShapeInfo != null) {
     84          oldInitialShapeColor = newInitialShapeInfo.Color;
     85          newInitialShapeInfo.Color = Color.LightGreen;
     86        }
     87        oldInitialShape = InitialShape;
     88        OnInitialShapeChanged();
     89      }
     90    }
     91    public override IDeepCloneable Clone(Cloner cloner) {
     92      return new OperatorGraphVisualizationInfo(this, cloner);
    5193    }
    5294
     
    64106
    65107    [StorableHook(HookType.AfterDeserialization)]
    66     private void DeserializationHook() {
     108    private void AfterDeserialization() {
    67109      this.operatorGraph.DeserializationFinished += new EventHandler(operatorGraph_DeserializationFinished);
    68110
     
    101143      }
    102144      this.operatorGraph.DeserializationFinished -= new EventHandler(operatorGraph_DeserializationFinished);
    103     }
    104 
    105     public override IDeepCloneable Clone(Cloner cloner) {
    106       OperatorGraphVisualizationInfo clone = (OperatorGraphVisualizationInfo)base.Clone(cloner);
    107       clone.operatorGraph = (OperatorGraph)cloner.Clone(this.operatorGraph);
    108       clone.RegisterOperatorGraphEvents();
    109       clone.oldInitialShape = (IOperatorShapeInfo)cloner.Clone(this.oldInitialShape);
    110       clone.oldInitialShapeColor = this.oldInitialShapeColor;
    111 
    112       IOperator op;
    113       IOperatorShapeInfo shapeInfo;
    114       foreach (KeyValuePair<IOperator, IOperatorShapeInfo> pair in this.operatorShapeInfoMapping.FirstEnumerable) {
    115         op = (IOperator)cloner.Clone(pair.Key);
    116         shapeInfo = (IOperatorShapeInfo)cloner.Clone(pair.Value);
    117         clone.RegisterOperatorEvents(op);
    118         clone.operatorParameterCollectionMapping.Add(op, pair.Key.Parameters);
    119         clone.operatorShapeInfoMapping.Add(op, shapeInfo);
    120       }
    121 
    122       foreach (IOperator oper in clone.operatorShapeInfoMapping.FirstValues) {
    123         foreach (IParameter param in oper.Parameters) {
    124           clone.parameterOperatorMapping.Add(param, oper);
    125           IValueParameter opParam = param as IValueParameter;
    126           if (opParam != null && typeof(IOperator).IsAssignableFrom(param.DataType))
    127             clone.RegisterOperatorParameterEvents(opParam);
    128           else
    129             clone.RegisterParameterEvents(param);
    130         }
    131       }
    132       if (this.operatorGraph.InitialOperator != null) {
    133         IOperatorShapeInfo newInitialShapeInfo = this.operatorShapeInfoMapping.GetByFirst(this.operatorGraph.InitialOperator);
    134         if (newInitialShapeInfo != null) {
    135           oldInitialShapeColor = newInitialShapeInfo.Color;
    136           newInitialShapeInfo.Color = Color.LightGreen;
    137         }
    138         oldInitialShape = this.InitialShape;
    139         this.OnInitialShapeChanged();
    140       }
    141       return clone;
    142145    }
    143146
  • branches/CloningRefactoring/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs

    r4068 r4673  
    3232    [Storable]
    3333    private List<string> labels;
     34
     35    [StorableConstructor]
     36    protected OperatorShapeInfo(bool deserializing) : base(deserializing) { }
     37    protected OperatorShapeInfo(OperatorShapeInfo original, Cloner cloner)
     38      : base(original, cloner) {
     39      collapsed = original.collapsed;
     40      color = original.color;
     41      lineColor = original.lineColor;
     42      lineWidth = original.lineWidth;
     43      title = original.title;
     44      icon = (Bitmap)original.icon.Clone();
     45
     46      connectorNames = new List<string>(original.connectorNames);
     47      labels = new List<string>(original.labels);
     48    }
     49    public override IDeepCloneable Clone(Cloner cloner) {
     50      return new OperatorShapeInfo(this, cloner);
     51    }
    3452
    3553    public OperatorShapeInfo()
     
    216234      //TODO update Connector and labels;
    217235    }
    218 
    219     public override IDeepCloneable Clone(Cloner cloner) {
    220       OperatorShapeInfo clone = (OperatorShapeInfo)base.Clone(cloner);
    221       clone.collapsed = this.collapsed;
    222       clone.color = this.color;
    223       clone.lineColor = this.lineColor;
    224       clone.lineWidth = this.lineWidth;
    225       clone.title = this.title;
    226       clone.icon = (Bitmap)this.icon.Clone();
    227 
    228       clone.connectorNames = new List<string>(this.connectorNames);
    229       clone.labels = new List<string>(this.labels);
    230 
    231       return clone;
    232     }
    233236  }
    234237}
Note: See TracChangeset for help on using the changeset viewer.