Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs @ 14467

Last change on this file since 14467 was 14185, checked in by swagner, 8 years ago

#2526: Updated year of copyrights in license headers

File size: 4.3 KB
RevLine 
[13502]1#region License Information
2/* HeuristicLab
[14185]3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[13502]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;
[10589]23using System.Collections.Generic;
24using System.Linq;
[10712]25using HeuristicLab.Collections;
[10589]26using HeuristicLab.Core.Views;
[10712]27using HeuristicLab.DataPreprocessing.Filter;
[10589]28using HeuristicLab.MainForm;
29
[10712]30namespace HeuristicLab.DataPreprocessing.Views {
[10589]31  [View("CheckedFilterCollection View")]
[10712]32  [Content(typeof(FilterContent), true)]
33  public partial class FilterView : ItemView {
[10589]34
[10712]35    public FilterView() {
[10589]36      InitializeComponent();
[10637]37      tbTotal.Text = "0";
[11044]38      tbRemaining.Text = "0";
[10637]39      tbPercentage.Text = "0%";
[10589]40    }
41
[13502]42    private void InitData() {
43      checkedFilterView.Content = Content.Filters;
44      checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
45      checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
46      checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
[10877]47    }
48
[10712]49    public new FilterContent Content {
[10589]50      get { return (FilterContent)base.Content; }
[10813]51      set { base.Content = value; }
[10589]52    }
53
[13502]54    protected override void OnContentChanged() {
[10813]55      base.OnContentChanged();
[13502]56      if (Content != null) {
[10877]57        InitData();
[10813]58        UpdateFilterInfo();
59      }
60    }
61
[10712]62    private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
[13502]63      if (Content != null) {
64        foreach (IFilter filter in e.Items) {
[10877]65          filter.Active = checkedFilterView.Content.ItemChecked(filter);
66        }
67        UpdateFilterInfo();
[10637]68      }
[10693]69    }
70
[10712]71    private void UpdateFilterInfo() {
[13502]72      List<IFilter> filters = Content.Filters.ToList();
73      int activeFilters = filters.Count(c => c.Active);
74      applyFilterButton.Enabled = (activeFilters > 0);
75      rBtnAnd.Enabled = (activeFilters > 0);
76      rBtnOr.Enabled = (activeFilters > 0);
77      Content.FilterLogic.Reset();
78      bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
[10877]79
[13502]80      int filteredCnt = result.Count(c => !c);
[10877]81
[13502]82      tbRemaining.Text = filteredCnt.ToString();
83      double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / (double)result.Length;
84      tbPercentage.Text = String.Format("{0:0.0000}%", percentage);
85      tbTotal.Text = result.Length.ToString();
[10589]86    }
87
[10712]88    private void applyFilterButton_Click(object sender, EventArgs e) {
[13502]89      if (Content != null) {
[10877]90        List<IFilter> filters = Content.Filters.ToList();
[10933]91        //apply filters
[10877]92        Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
[10933]93        //deactivate checked filters
94        filters = checkedFilterView.Content.CheckedItems.ToList();
[13502]95        foreach (IFilter filter in filters) {
[10933]96          checkedFilterView.Content.SetItemCheckedState(filter, false);
97          filter.Active = false;
98        }
99        UpdateFilterInfo();
[10877]100      }
[10589]101    }
102
[10637]103    //whenever a new filter is added the preprocessing data is set to the filter
[10712]104    private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
[13502]105      if (Content != null) {
106        foreach (IFilter filter in e.Items) {
[10877]107          filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
108        }
[10637]109      }
110    }
111
[10712]112    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
[13502]113      if (Content != null) {
[10877]114        UpdateFilterInfo();
115      }
[10693]116    }
117
[13502]118    private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
119      if (Content != null) {
[10877]120        UpdateFilterInfo();
[11002]121        Content.IsAndCombination = rBtnAnd.Checked;
[10877]122      }
[10785]123    }
124
[10589]125  }
126}
Note: See TracBrowser for help on using the repository browser.