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