Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs @ 14996

Last change on this file since 14996 was 14996, checked in by pfleck, 7 years ago

#2709

  • Fixed initial selection of the grouping text box (empty string instead of null to select the first entry).
  • General code fixes (removed unnessecary bank lines and code, class member order, ...)
File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Collections;
26using HeuristicLab.Core.Views;
27using HeuristicLab.DataPreprocessing.Filter;
28using HeuristicLab.MainForm;
29
30namespace HeuristicLab.DataPreprocessing.Views {
31  [View("CheckedFilterCollection View")]
32  [Content(typeof(FilterContent), true)]
33  public partial class FilterView : ItemView {
34    public new FilterContent Content {
35      get { return (FilterContent)base.Content; }
36      set { base.Content = value; }
37    }
38
39    public FilterView() {
40      InitializeComponent();
41      tbTotal.Text = "0";
42      tbRemaining.Text = "0";
43      tbPercentage.Text = "0%";
44    }
45
46    private void InitData() {
47      checkedFilterView.Content = Content.Filters;
48      checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
49      checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
50      checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
51    }
52
53    protected override void OnContentChanged() {
54      base.OnContentChanged();
55      if (Content != null) {
56        InitData();
57        UpdateFilterInfo();
58      }
59    }
60
61    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
62      if (Content != null) {
63        foreach (IFilter filter in e.Items) {
64          filter.Active = checkedFilterView.Content.ItemChecked(filter);
65        }
66        UpdateFilterInfo();
67      }
68    }
69
70    private void UpdateFilterInfo() {
71      List<IFilter> filters = Content.Filters.ToList();
72      int activeFilters = filters.Count(c => c.Active);
73      applyFilterButton.Enabled = (activeFilters > 0);
74      rBtnAnd.Enabled = (activeFilters > 0);
75      rBtnOr.Enabled = (activeFilters > 0);
76      Content.FilterLogic.Reset();
77      bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
78
79      int filteredCnt = result.Count(c => !c);
80
81      tbRemaining.Text = filteredCnt.ToString();
82      double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / (double)result.Length;
83      tbPercentage.Text = String.Format("{0:0.0000}%", percentage);
84      tbTotal.Text = result.Length.ToString();
85    }
86
87    private void applyFilterButton_Click(object sender, EventArgs e) {
88      if (Content != null) {
89        List<IFilter> filters = Content.Filters.ToList();
90        //apply filters
91        Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
92        //deactivate checked filters
93        filters = checkedFilterView.Content.CheckedItems.ToList();
94        foreach (IFilter filter in filters) {
95          checkedFilterView.Content.SetItemCheckedState(filter, false);
96          filter.Active = false;
97        }
98        UpdateFilterInfo();
99      }
100    }
101
102    //whenever a new filter is added the preprocessing data is set to the filter
103    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
104      if (Content != null) {
105        foreach (IFilter filter in e.Items) {
106          filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
107        }
108      }
109    }
110
111    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
112      if (Content != null) {
113        UpdateFilterInfo();
114      }
115    }
116
117    private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
118      if (Content != null) {
119        UpdateFilterInfo();
120        Content.IsAndCombination = rBtnAnd.Checked;
121      }
122    }
123  }
124}
Note: See TracBrowser for help on using the repository browser.