1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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 |
|
---|
22 | using System;
|
---|
23 | using System.Linq;
|
---|
24 | using HeuristicLab.Collections;
|
---|
25 | using HeuristicLab.Core.Views;
|
---|
26 | using HeuristicLab.DataPreprocessing.Filter;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.DataPreprocessing.Views {
|
---|
30 | [View("CheckedFilterCollection View")]
|
---|
31 | [Content(typeof(FilterContent), true)]
|
---|
32 | public partial class FilterView : ItemView {
|
---|
33 | public new FilterContent Content {
|
---|
34 | get { return (FilterContent)base.Content; }
|
---|
35 | set { base.Content = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public FilterView() {
|
---|
39 | InitializeComponent();
|
---|
40 | tbTotal.Text = "0";
|
---|
41 | tbRemaining.Text = "0";
|
---|
42 | tbPercentage.Text = "0%";
|
---|
43 | }
|
---|
44 |
|
---|
45 | protected override void OnContentChanged() {
|
---|
46 | base.OnContentChanged();
|
---|
47 | if (Content != null) {
|
---|
48 | checkedFilterView.Content = Content.Filters;
|
---|
49 | rBtnAnd.Checked = Content.IsAndCombination;
|
---|
50 | rBtnOr.Checked = !Content.IsAndCombination;
|
---|
51 | UpdateFilter();
|
---|
52 | } else {
|
---|
53 | checkedFilterView.Content = null;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | protected override void RegisterContentEvents() {
|
---|
57 | base.RegisterContentEvents();
|
---|
58 | Content.Filters.ItemsAdded += Content_ItemsAdded;
|
---|
59 | Content.Filters.ItemsRemoved += Content_ItemsRemoved;
|
---|
60 | Content.Filters.CheckedItemsChanged += Content_CheckedItemsChanged;
|
---|
61 | }
|
---|
62 | protected override void DeregisterContentEvents() {
|
---|
63 | Content.Filters.ItemsAdded -= Content_ItemsAdded;
|
---|
64 | Content.Filters.ItemsRemoved -= Content_ItemsRemoved;
|
---|
65 | Content.Filters.CheckedItemsChanged -= Content_CheckedItemsChanged;
|
---|
66 | base.DeregisterContentEvents();
|
---|
67 | }
|
---|
68 |
|
---|
69 | private void UpdateFilter() {
|
---|
70 | bool activeFilters = Content.ActiveFilters.Any();
|
---|
71 | applyFilterButton.Enabled = activeFilters;
|
---|
72 |
|
---|
73 | Content.PreprocessingData.ResetFilter();
|
---|
74 |
|
---|
75 | int numTotal = Content.PreprocessingData.Rows;
|
---|
76 | int numRemaining = numTotal;
|
---|
77 |
|
---|
78 | if (activeFilters) {
|
---|
79 | var remainingRows = Content.GetRemainingRows();
|
---|
80 | numRemaining = remainingRows.Count(x => x);
|
---|
81 |
|
---|
82 | if (numRemaining < numTotal) {
|
---|
83 | Content.PreprocessingData.SetFilter(remainingRows);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | tbRemaining.Text = numRemaining.ToString();
|
---|
88 | double ratio = numTotal > 0 ? numRemaining / (double)numTotal : 0.0;
|
---|
89 | tbPercentage.Text = ratio.ToString("P4");
|
---|
90 | tbTotal.Text = numTotal.ToString();
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | #region Content Events
|
---|
95 | //whenever a new filter is added the preprocessing data is set to the filter
|
---|
96 | private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
|
---|
97 | if (Content != null) {
|
---|
98 | foreach (IFilter filter in e.Items) {
|
---|
99 | filter.ConstrainedValue = Content.PreprocessingData;
|
---|
100 | }
|
---|
101 | }
|
---|
102 | }
|
---|
103 | private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) {
|
---|
104 | if (Content != null) {
|
---|
105 | UpdateFilter();
|
---|
106 | }
|
---|
107 | }
|
---|
108 | private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) {
|
---|
109 | if (Content != null) {
|
---|
110 | foreach (IFilter filter in e.Items) {
|
---|
111 | filter.Active = checkedFilterView.Content.ItemChecked(filter);
|
---|
112 | }
|
---|
113 | UpdateFilter();
|
---|
114 | }
|
---|
115 | }
|
---|
116 | #endregion
|
---|
117 |
|
---|
118 | #region Controls Events
|
---|
119 | private void rBtnAnd_CheckedChanged(object sender, EventArgs e) {
|
---|
120 | if (Content != null) {
|
---|
121 | Content.IsAndCombination = rBtnAnd.Checked;
|
---|
122 | UpdateFilter();
|
---|
123 | }
|
---|
124 | }
|
---|
125 | private void applyFilterButton_Click(object sender, EventArgs e) {
|
---|
126 | if (Content != null) {
|
---|
127 | //apply filters
|
---|
128 | Content.PreprocessingData.PersistFilter();
|
---|
129 | Content.PreprocessingData.ResetFilter();
|
---|
130 | //deactivate checked filters
|
---|
131 | foreach (var filter in Content.Filters.CheckedItems.ToList()) {
|
---|
132 | checkedFilterView.Content.SetItemCheckedState(filter, false);
|
---|
133 | filter.Active = false;
|
---|
134 | }
|
---|
135 | UpdateFilter();
|
---|
136 | }
|
---|
137 | }
|
---|
138 | #endregion
|
---|
139 | }
|
---|
140 | }
|
---|