Changeset 15973 for branches/2522_RefactorPluginInfrastructure/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs
- Timestamp:
- 06/28/18 11:13:37 (6 years ago)
- Location:
- branches/2522_RefactorPluginInfrastructure
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2522_RefactorPluginInfrastructure
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.DataPreprocessing.Views
- Property svn:mergeinfo changed
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.DataPreprocessing.Views/3.4
- Property svn:ignore
-
old new 1 1 ComparisonFilterView.resx 2 2 FilterView.resx 3 *.user
-
- Property svn:ignore
-
branches/2522_RefactorPluginInfrastructure/HeuristicLab.DataPreprocessing.Views/3.4/FilterView.cs
r11044 r15973 1 using System; 2 using System.Collections.Generic; 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; 3 23 using System.Linq; 4 using System.Windows.Forms;5 24 using HeuristicLab.Collections; 6 using HeuristicLab.Core;7 25 using HeuristicLab.Core.Views; 8 using HeuristicLab.Data;9 26 using HeuristicLab.DataPreprocessing.Filter; 10 27 using HeuristicLab.MainForm; … … 14 31 [Content(typeof(FilterContent), true)] 15 32 public partial class FilterView : ItemView { 33 public new FilterContent Content { 34 get { return (FilterContent)base.Content; } 35 set { base.Content = value; } 36 } 16 37 17 38 public FilterView() { … … 22 43 } 23 44 24 private void InitData() 25 { 45 protected override void OnContentChanged() { 46 base.OnContentChanged(); 47 if (Content != null) { 26 48 checkedFilterView.Content = Content.Filters; 27 checkedFilterView.Content.ItemsAdded += Content_ItemsAdded; 28 checkedFilterView.Content.ItemsRemoved += Content_ItemsRemoved; 29 checkedFilterView.Content.CheckedItemsChanged += Content_CheckedItemsChanged; 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(); 30 67 } 31 68 32 public new FilterContent Content { 33 get { return (FilterContent)base.Content; } 34 set { base.Content = value; } 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(); 35 91 } 36 92 37 protected override void OnContentChanged() 38 { 39 base.OnContentChanged(); 40 if (Content != null) 41 { 42 InitData(); 43 UpdateFilterInfo(); 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 } 44 101 } 45 102 } 46 103 private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) { 104 if (Content != null) { 105 UpdateFilter(); 106 } 107 } 47 108 private void Content_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) { 48 if (Content != null) 49 { 50 foreach (IFilter filter in e.Items) 51 { 109 if (Content != null) { 110 foreach (IFilter filter in e.Items) { 52 111 filter.Active = checkedFilterView.Content.ItemChecked(filter); 53 112 } 54 UpdateFilter Info();113 UpdateFilter(); 55 114 } 56 115 } 116 #endregion 57 117 58 private void UpdateFilterInfo() { 59 List<IFilter> filters = Content.Filters.ToList(); 60 int activeFilters = filters.Count(c => c.Active); 61 applyFilterButton.Enabled = (activeFilters > 0); 62 rBtnAnd.Enabled = (activeFilters > 0); 63 rBtnOr.Enabled = (activeFilters > 0); 64 Content.FilterLogic.Reset(); 65 bool[] result = Content.FilterLogic.Preview(filters, rBtnAnd.Checked); 66 67 int filteredCnt = result.Count(c => !c); 68 69 tbRemaining.Text = filteredCnt.ToString(); 70 double percentage = result.Length == 0 ? 0.0 : filteredCnt * 100 / (double)result.Length; 71 tbPercentage.Text = String.Format("{0:0.0000}%", percentage); 72 tbTotal.Text = result.Length.ToString(); 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 } 73 124 } 74 75 125 private void applyFilterButton_Click(object sender, EventArgs e) { 76 if (Content != null) 77 { 78 List<IFilter> filters = Content.Filters.ToList(); 126 if (Content != null) { 79 127 //apply filters 80 Content.FilterLogic.Apply(filters, rBtnAnd.Checked); 128 Content.PreprocessingData.PersistFilter(); 129 Content.PreprocessingData.ResetFilter(); 81 130 //deactivate checked filters 82 filters = checkedFilterView.Content.CheckedItems.ToList(); 83 foreach (IFilter filter in filters) 84 { 131 foreach (var filter in Content.Filters.CheckedItems.ToList()) { 85 132 checkedFilterView.Content.SetItemCheckedState(filter, false); 86 133 filter.Active = false; 87 134 } 88 UpdateFilter Info();135 UpdateFilter(); 89 136 } 90 137 } 91 92 //whenever a new filter is added the preprocessing data is set to the filter 93 private void Content_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IFilter> e) { 94 if (Content != null) 95 { 96 foreach (IFilter filter in e.Items) 97 { 98 filter.ConstrainedValue = Content.FilterLogic.PreprocessingData; 99 } 100 } 101 } 102 103 private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IFilter> e) { 104 if (Content != null) 105 { 106 UpdateFilterInfo(); 107 } 108 } 109 110 private void rBtnAnd_CheckedChanged(object sender, EventArgs e) 111 { 112 if (Content != null) 113 { 114 UpdateFilterInfo(); 115 Content.IsAndCombination = rBtnAnd.Checked; 116 } 117 } 118 138 #endregion 119 139 } 120 140 }
Note: See TracChangeset
for help on using the changeset viewer.