Changeset 13132


Ignore:
Timestamp:
11/10/15 14:32:39 (3 years ago)
Author:
jkarder
Message:

#1265: worked on visualization

  • added Selected to ChartMode
  • added PrimitiveAttribute
Location:
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartControl.cs

    r13122 r13132  
    388388      };
    389389
    390       rb.CheckedChanged += (sender, args) => { if (rb.Checked) Mode = chartMode; };
     390      rb.CheckedChanged += (sender, args) => { if (rb.Checked) chartMode.Select(); };
    391391
    392392      return rb;
     
    400400      };
    401401
    402       mi.CheckedChanged += (sender, args) => { if (mi.Checked) Mode = chartMode; };
     402      mi.CheckedChanged += (sender, args) => { if (mi.Checked) chartMode.Select(); };
    403403
    404404      return mi;
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartMode.cs

    r13122 r13132  
    4141    }
    4242
     43    private bool selected;
     44    public bool Selected {
     45      get { return selected; }
     46      set {
     47        if (selected == value) return;
     48        selected = value;
     49        if (selected) {
     50          chartControl.Mode = this;
     51          OnSelected();
     52        } else {
     53          if (chartControl.Mode == this)
     54            chartControl.Mode = null;
     55          OnDeselected();
     56        }
     57        OnSelectedChanged();
     58      }
     59    }
     60
    4361    protected ChartMode(ChartControl control) {
    4462      chartControl = control;
     63      chartControl.ModeChanged += (sender, args) => Selected = chartControl.Mode == this;
    4564    }
    4665
    47     public void Select() { chartControl.Mode = this; }
    48     public void Deselect() { chartControl.Mode = null; }
     66    public void Select() { Selected = true; }
     67    public void Deselect() { Selected = false; }
     68
     69    protected virtual void OnSelected() { }
     70    protected virtual void OnDeselected() { }
    4971
    5072    public virtual void HandleOnKeyDown(object sender, KeyEventArgs e) {
     
    7597    public virtual void HandleOnMouseLeave(object sender, EventArgs e) { }
    7698    public virtual void HandleOnClick(object sender, EventArgs e) { }
     99
     100    public event EventHandler SelectedChanged;
     101    protected virtual void OnSelectedChanged() {
     102      var handler = SelectedChanged;
     103      if (handler != null) handler(this, EventArgs.Empty);
     104    }
    77105  }
    78106}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/RulerChartMode.cs

    r13115 r13132  
    8585    }
    8686
     87    #region Helpers
    8788    protected virtual void DrawCross(Graphics graphics, Point point) {
    8889      using (var pen = new Pen(Color.Red)) {
     
    112113      graphics.DrawRectangle(Pens.Red, location.X, location.Y, width, height);
    113114      graphics.DrawString(text, SystemFonts.DefaultFont, Brushes.Black, location.X, location.Y + 2);
    114 
    115115    }
     116    #endregion
    116117  }
    117118}
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/ChartModes/SelectChartMode.cs

    r13122 r13132  
    3333    public SelectChartMode(ChartControl control) : base(control) { }
    3434
     35    protected override void OnDeselected() {
     36      try {
     37        chartControl.SuspendRendering();
     38        foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
     39          p.Selected = false;
     40      } finally {
     41        chartControl.ResumeRendering();
     42        base.OnDeselected();
     43      }
     44    }
     45
    3546    public override void HandleOnKeyDown(object sender, KeyEventArgs e) {
    3647      try {
     
    3950            try {
    4051              chartControl.SuspendRendering();
    41               foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives)
    42                 chartControl.Chart.Group.Remove(primitive);
     52              foreach (var p in chartControl.Chart.Group.SelectedPrimitives)
     53                chartControl.Chart.Group.Remove(p);
    4354            } finally { chartControl.ResumeRendering(); }
    44 
    4555            break;
    4656        }
     
    5767              chartControl.SuspendRendering();
    5868              var worldLocation = chartControl.Chart.TransformPixelToWorld(e.Location);
    59               foreach (var sp in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
    60                 sp.Selected = false;
    61               var p = chartControl.Chart.GetPrimitive(e.Location);
    62               if (p != null) p.Selected = true;
     69              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(x => !x.ContainsPoint(worldLocation)))
     70                p.Selected = false;
     71              var sp = chartControl.Chart.GetPrimitive(e.Location);
     72              if (sp != null) sp.Selected = true;
    6373            } finally { chartControl.ResumeRendering(); }
    6474            break;
     
    8090            try {
    8191              chartControl.SuspendRendering();
    82               foreach (var primitive in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
    83                 primitive.Move(previousWorldLocation, offset);
     92              foreach (var p in chartControl.Chart.Group.SelectedPrimitives.Where(p => p.ContainsPoint(previousWorldLocation)))
     93                p.Move(previousWorldLocation, offset);
    8494            } finally { chartControl.ResumeRendering(); }
    8595            break;
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/HeuristicLab.Visualization-3.3.csproj

    r13112 r13132  
    132132    <Compile Include="ChartModes\PanChartMode.cs" />
    133133    <Compile Include="ChartModes\RulerChartMode.cs" />
     134    <Compile Include="PrimitiveAttribute.cs" />
    134135    <Compile Include="Primitives\Grid.cs" />
    135136    <Compile Include="Properties\Resources.Designer.cs">
Note: See TracChangeset for help on using the changeset viewer.