Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/ViewportConstraints/ConstraintCollection.cs @ 13788

Last change on this file since 13788 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.9 KB
Line 
1using System.Linq;
2using System.Windows;
3using Microsoft.Research.DynamicDataDisplay;
4using Microsoft.Research.DynamicDataDisplay.Common;
5using Microsoft.Research.DynamicDataDisplay.Common.Auxiliary;
6using System;
7using System.Collections.Specialized;
8
9namespace Microsoft.Research.DynamicDataDisplay.ViewportConstraints
10{
11  /// <summary>
12  /// Represents a collection of <see cref="ViewportConstraint"/>s.
13  /// <remarks>
14  /// ViewportConstraint that is being added should not be null.
15  /// </remarks>
16  /// </summary>
17  public sealed class ConstraintCollection : D3Collection<ViewportConstraint>
18  {
19    private readonly Viewport2D viewport;
20    internal ConstraintCollection(Viewport2D viewport)
21    {
22      if (viewport == null)
23        throw new ArgumentNullException("viewport");
24
25      this.viewport = viewport;
26    }
27
28    protected override void OnItemAdding(ViewportConstraint item)
29    {
30      if (item == null)
31        throw new ArgumentNullException("item");
32    }
33
34    protected override void OnItemAdded(ViewportConstraint item)
35    {
36      item.Changed += OnItemChanged;
37      ISupportAttachToViewport attachable = item as ISupportAttachToViewport;
38      if (attachable != null)
39      {
40        attachable.Attach(viewport);
41      }
42    }
43
44    private void OnItemChanged(object sender, EventArgs e)
45    {
46      OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
47    }
48
49    protected override void OnItemRemoving(ViewportConstraint item)
50    {
51      ISupportAttachToViewport attachable = item as ISupportAttachToViewport;
52      if (attachable != null)
53      {
54        attachable.Detach(viewport);
55      }
56      item.Changed -= OnItemChanged;
57    }
58
59    internal DataRect Apply(DataRect oldVisible, DataRect newVisible, Viewport2D viewport)
60    {
61      DataRect res = newVisible;
62      foreach (var constraint in this)
63      {
64        res = constraint.Apply(oldVisible, res, viewport);
65      }
66      return res;
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.