[10589] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Windows.Forms;
|
---|
[10712] | 5 | using HeuristicLab.Collections;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
[10589] | 7 | using HeuristicLab.Core.Views;
|
---|
[10712] | 8 | using HeuristicLab.Data;
|
---|
| 9 | using HeuristicLab.DataPreprocessing.Filter;
|
---|
[10589] | 10 | using HeuristicLab.MainForm;
|
---|
| 11 |
|
---|
[10712] | 12 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
[10589] | 13 | [View("CheckedFilterCollection View")]
|
---|
[10712] | 14 | [Content(typeof(FilterContent), true)]
|
---|
| 15 | public partial class FilterView : ItemView {
|
---|
[10589] | 16 |
|
---|
[10712] | 17 | public FilterView() {
|
---|
[10589] | 18 | InitializeComponent();
|
---|
[10637] | 19 | tbTotal.Text = "0";
|
---|
| 20 | tbFiltered.Text = "0";
|
---|
| 21 | tbPercentage.Text = "0%";
|
---|
[10785] | 22 | checkedFilterView.Content = new CheckedItemCollection<IFilter>();
|
---|
| 23 | checkedFilterView.Content.ItemsAdded += Content_ItemsAdded;
|
---|
| 24 | checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved;
|
---|
| 25 | checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged;
|
---|
[10589] | 26 | }
|
---|
| 27 |
|
---|
[10712] | 28 | public new FilterContent Content {
|
---|
[10589] | 29 | get { return (FilterContent)base.Content; }
|
---|
[10813] | 30 | set { base.Content = value; }
|
---|
[10589] | 31 | }
|
---|
| 32 |
|
---|
[10813] | 33 | protected override void OnContentChanged()
|
---|
| 34 | {
|
---|
| 35 | base.OnContentChanged();
|
---|
| 36 | if (Content != null)
|
---|
| 37 | {
|
---|
| 38 | ImportFiltersFromContent();
|
---|
| 39 | UpdateFilterInfo();
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[10712] | 43 | private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
|
---|
[10713] | 44 |
|
---|
| 45 | foreach (IFilter filter in e.Items)
|
---|
| 46 | {
|
---|
[10813] | 47 | filter.Active = checkedFilterView.Content.ItemChecked(filter);
|
---|
[10637] | 48 | }
|
---|
[10693] | 49 | UpdateFilterInfo();
|
---|
[10813] | 50 | ExportFiltersToContent();
|
---|
[10693] | 51 | Refresh();
|
---|
| 52 | ResumeRepaint(true);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[10712] | 55 | private void UpdateFilterInfo() {
|
---|
[10785] | 56 | List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
|
---|
[10696] | 57 |
|
---|
| 58 | int activeFilters = filters.Count(c => c.Active);
|
---|
| 59 |
|
---|
| 60 | applyFilterButton.Enabled = (activeFilters > 0);
|
---|
[10785] | 61 | rBtnAnd.Enabled = (activeFilters > 0);
|
---|
| 62 | rBtnOr.Enabled = (activeFilters > 0);
|
---|
| 63 | btnReset.Enabled = (activeFilters > 0);
|
---|
[10849] | 64 | Content.FilterLogic.Reset();
|
---|
[10785] | 65 | bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked);
|
---|
[10713] | 66 |
|
---|
[10785] | 67 | int filteredCnt = result.Count(c => c);
|
---|
[10713] | 68 |
|
---|
[10693] | 69 | tbFiltered.Text = filteredCnt.ToString();
|
---|
[10813] | 70 | double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / result.Length;
|
---|
[10693] | 71 | tbPercentage.Text = percentage.ToString() + "%";
|
---|
| 72 | tbTotal.Text = result.Length.ToString();
|
---|
[10589] | 73 | }
|
---|
| 74 |
|
---|
[10712] | 75 | private void applyFilterButton_Click(object sender, EventArgs e) {
|
---|
[10785] | 76 | List<IFilter> filters = checkedFilterView.ItemCollection.ToList<IFilter>();
|
---|
| 77 | Content.FilterLogic.Apply(filters, rBtnAnd.Checked);
|
---|
[10589] | 78 | }
|
---|
| 79 |
|
---|
[10637] | 80 | //whenever a new filter is added the preprocessing data is set to the filter
|
---|
[10712] | 81 | private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
|
---|
| 82 | foreach (IFilter filter in e.Items) {
|
---|
[10637] | 83 | filter.ConstrainedValue = Content.FilterLogic.PreprocessingData;
|
---|
| 84 | }
|
---|
[10693] | 85 | UpdateFilterInfo();
|
---|
[10813] | 86 | ExportFiltersToContent();
|
---|
[10637] | 87 | }
|
---|
| 88 |
|
---|
[10712] | 89 | private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
|
---|
[10693] | 90 | UpdateFilterInfo();
|
---|
[10813] | 91 | ExportFiltersToContent();
|
---|
[10693] | 92 | }
|
---|
| 93 |
|
---|
[10785] | 94 | private void rBtnAnd_CheckedChanged(object sender, EventArgs e)
|
---|
| 95 | {
|
---|
| 96 | UpdateFilterInfo();
|
---|
[10813] | 97 | ExportFiltersToContent();
|
---|
[10842] | 98 | Content.isAndCombination = rBtnAnd.Checked;
|
---|
[10785] | 99 | }
|
---|
| 100 |
|
---|
| 101 | private void btnReset_Click(object sender, EventArgs e)
|
---|
| 102 | {
|
---|
| 103 | Content.FilterLogic.Reset();
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[10813] | 106 | private void ImportFiltersFromContent()
|
---|
| 107 | {
|
---|
| 108 | checkedFilterView.ItemCollection.AddRange(Content.Filters);
|
---|
| 109 |
|
---|
| 110 | foreach (IFilter filter in checkedFilterView.ItemCollection) {
|
---|
| 111 | if (filter.Active)
|
---|
| 112 | {
|
---|
| 113 | checkedFilterView.Content.SetItemCheckedState(filter, true);
|
---|
| 114 | }
|
---|
| 115 | else
|
---|
| 116 | {
|
---|
| 117 | checkedFilterView.Content.SetItemCheckedState(filter, false);
|
---|
| 118 | }
|
---|
[10842] | 119 | rBtnAnd.Checked = Content.isAndCombination;
|
---|
| 120 | rBtnOr.Checked = !Content.isAndCombination;
|
---|
[10813] | 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | private void ExportFiltersToContent()
|
---|
| 125 | {
|
---|
| 126 | Content.Filters = checkedFilterView.ItemCollection.ToList<IFilter>();
|
---|
| 127 | }
|
---|
[10589] | 128 | }
|
---|
| 129 | }
|
---|