/// <summary> /// CONSTRUCTOR /// </summary> private FrmEditPeakFilterCondition(Form owner, Core core, PeakFilter.Condition defaults, bool readOnly) : this() { this._core = core; this._readOnly = readOnly; this.ctlTitleBar1.Text = readOnly ? "View Condition" : "Edit Condition"; // Setup boxes this._cbPeaks = DataSet.ForPeaks(core).CreateConditionBox(this._txtIsInSet, this._btnIsInSet); this._cbFlags = DataSet.ForUserFlags(core).CreateConditionBox(this._txtIsFlaggedWith, this._btnIsFlaggedWith); this._cbClusters = DataSet.ForClusters(core).CreateConditionBox(this._txtIsInCluster, this._btnIsInCluster); this._lsoFlags = EnumComboBox.Create(this._lstFlagComparator, Filter.ESetOperator.Any); this._lsoPats = EnumComboBox.Create(this._lstClusterComparator, Filter.ELimitedSetOperator.Any); this._lsoPeaks = EnumComboBox.Create(this._lstPeakComparator, Filter.EElementOperator.Is); this._lsoFilter = EnumComboBox.Create(this._lstFilterOp, Filter.EElementOperator.Is); this._lsoStats = EnumComboBox.Create(this._lstStatisticComparator, Filter.EStatOperator.LessThan); this._lstIsStatistic.Items.AddRange(IVisualisableExtensions.WhereEnabled(core.Statistics).ToArray()); this._ecbFilter = DataSet.ForPeakFilter(core).CreateComboBox(this._lstFilter, null, EditableComboBox.EFlags.IncludeAll); this._isInitialised = true; if (defaults == null) { this.checkBox1.Checked = false; this._radAnd.Checked = true; this._txtComp_TextChanged(null, null); } else { // Not this.checkBox1.Checked = defaults.Negate; this._radAnd.Checked = defaults.CombiningOperator == Filter.ELogicOperator.And; this._radOr.Checked = defaults.CombiningOperator == Filter.ELogicOperator.Or; if (defaults is PeakFilter.ConditionCluster) { PeakFilter.ConditionCluster def = (PeakFilter.ConditionCluster)defaults; List <Cluster> strong; if (!def.Clusters.TryGetStrong(out strong)) { this.ShowWeakFailureMessage("clusters"); } this._chkIsInCluster.Checked = true; this._lsoPats.SelectedItem = def.ClustersOp; this._cbClusters.SelectedItems = strong; } else if (defaults is PeakFilter.ConditionPeak) { PeakFilter.ConditionPeak def = (PeakFilter.ConditionPeak)defaults; List <Peak> strong; if (!def.Peaks.TryGetStrong(out strong)) { this.ShowWeakFailureMessage("peaks"); } this._chkIsInSet.Checked = true; this._lsoPeaks.SelectedItem = def.PeaksOp; this._cbPeaks.SelectedItems = strong; } else if (defaults is PeakFilter.ConditionFlags) { PeakFilter.ConditionFlags def = (PeakFilter.ConditionFlags)defaults; List <UserFlag> strong; if (!def.Flags.TryGetStrong(out strong)) { this.ShowWeakFailureMessage("peaks"); } this._chkIsFlaggedWith.Checked = true; this._lsoFlags.SelectedItem = def.FlagsOp; this._cbFlags.SelectedItems = strong; } else if (defaults is PeakFilter.ConditionStatistic) { PeakFilter.ConditionStatistic def = (PeakFilter.ConditionStatistic)defaults; ConfigurationStatistic strong; if (!def.Statistic.TryGetTarget(out strong)) { this.ShowWeakFailureMessage("statistics"); } ConfigurationStatistic stat = def.Statistic.GetTarget(); if (stat == null) { FrmMsgBox.ShowError(this, "The statistic specified when this condition was created has since been removed. Please select a different statistic."); } this._chkIsStatistic.Checked = true; this._lsoStats.SelectedItem = def.StatisticOp; this._lstIsStatistic.SelectedItem = stat; this._txtStatisticValue.Text = def.StatisticValue.ToString(); } else if (defaults is PeakFilter.ConditionFilter) { PeakFilter.ConditionFilter def = (PeakFilter.ConditionFilter)defaults; this._radFilter.Checked = true; this._lsoFilter.SelectedItem = def.FilterOp ? Filter.EElementOperator.Is : Filter.EElementOperator.IsNot; this._ecbFilter.SelectedItem = def.Filter; } else { throw new SwitchException(defaults.GetType()); } } if (readOnly) { UiControls.MakeReadOnly(this); } }
private void _btnMarkAsOutlier_Click(object sender, EventArgs e) { object item = this._chart.SelectedItem.DataPoint.Tag; ObservationInfo observationInfo = item as ObservationInfo; Peak peak = item as Peak; bool safeToReplace = false; if (peak != null) { List <PeakFilter.Condition> filters = new List <PeakFilter.Condition>(this._peakFilter.Conditions.Cast <PeakFilter.Condition>()); bool needsNewFilter = true; foreach (PeakFilter.Condition filter in filters) { PeakFilter.ConditionPeak klalkq = filter as PeakFilter.ConditionPeak; if (klalkq != null && klalkq.CombiningOperator == Filter.ELogicOperator.And && klalkq.Negate == false && klalkq.PeaksOp == Filter.EElementOperator.IsNot) { needsNewFilter = false; List <Peak> strong; if (!klalkq.Peaks.TryGetStrong(out strong)) { FrmMsgBox.ShowError(this, "Couldn't modify current filter because it contains expired data."); return; } filters.Remove(klalkq); filters.Add(new PeakFilter.ConditionPeak(Filter.ELogicOperator.And, false, strong.ConcatSingle(peak), Filter.EElementOperator.IsNot)); safeToReplace = filters.Count == 1; break; } } if (needsNewFilter) { filters.Add(new PeakFilter.ConditionPeak(Filter.ELogicOperator.And, false, new[] { peak }, Filter.EElementOperator.IsNot)); } PeakFilter newFilter = new PeakFilter(null, null, filters); if (safeToReplace) { this._core.SetPeakFilters(this._core.PeakFilters.ReplaceSingle(this._peakFilter, newFilter).ToArray()); } else { this._core.SetPeakFilters(this._core.PeakFilters.ConcatSingle(newFilter).ToArray()); } this._peakFilter = newFilter; this.UpdateScores(); return; } if (observationInfo == null) { bool needsNewFilter2 = true; List <ObsFilter.Condition> filters2 = new List <ObsFilter.Condition>(this._obsFilter.Conditions.Cast <ObsFilter.Condition>()); foreach (ObsFilter.ConditionObservation fikaklq in filters2) { ObsFilter.ConditionObservation qkklqq = fikaklq as ObsFilter.ConditionObservation; if (qkklqq != null && qkklqq.CombiningOperator == Filter.ELogicOperator.And && qkklqq.Negate == false && qkklqq.Operator == Filter.EElementOperator.IsNot) { needsNewFilter2 = false; filters2.Remove(qkklqq); filters2.Add(new ObsFilter.ConditionObservation(Filter.ELogicOperator.And, false, Filter.EElementOperator.IsNot, qkklqq.Possibilities.ConcatSingle(observationInfo))); safeToReplace = filters2.Count == 1; break; } } if (needsNewFilter2) { filters2.Add(new ObsFilter.ConditionObservation(Filter.ELogicOperator.And, false, Filter.EElementOperator.IsNot, new[] { observationInfo })); } ObsFilter obsFilter = new ObsFilter(null, null, filters2); if (safeToReplace) { this._core.SetObsFilters(this._core.ObsFilters.ReplaceSingle(this._obsFilter, obsFilter).ToArray()); } else { this._core.SetObsFilters(this._core.ObsFilters.ConcatSingle(obsFilter).ToArray()); } this._obsFilter = obsFilter; this.UpdateScores(); } }