/// <summary> /// Applies given criterion action to rows satisfying given criterion /// </summary> public void ApplyFilterAction(AbstractLocalizationCriterion crit, LocalizationCriterionAction2 act) { if (crit == null) { throw new ArgumentNullException("crit"); } List <DataGridViewRow> toBeDeletedRows = new List <DataGridViewRow>(); // list of rows to be deleted foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in Rows) { bool oldCheckValue = (bool)row.Cells[CheckBoxColumnName].Value; bool newCheckValue = oldCheckValue; var evalResult = crit.Eval(row.DataSourceItem); // criterion evaluation result if (evalResult == true) // row satisfies the criterion { if (act == LocalizationCriterionAction2.CHECK || act == LocalizationCriterionAction2.CHECK_REMOVE) // check the row { row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = true; newCheckValue = true; } else if (act == LocalizationCriterionAction2.UNCHECK) { row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = false; // uncheck the row newCheckValue = false; } else if (act == LocalizationCriterionAction2.REMOVE) { row.Cells[CheckBoxColumnName].Tag = row.Cells[CheckBoxColumnName].Value = false; toBeDeletedRows.Add(row); // add row to the list of rows to be deleted newCheckValue = false; } } else if (!oldCheckValue && evalResult == false && act == LocalizationCriterionAction2.CHECK_REMOVE) { toBeDeletedRows.Add(row); newCheckValue = false; } ChangeRowCheckState(row, oldCheckValue, newCheckValue); // change row check state } foreach (DataGridViewKeyValueRow <CodeStringResultItem> row in toBeDeletedRows) { ConflictResolver.TryAdd(row.Key, null, row); // remove the row from conflict resolver row.Cells[KeyColumnName].Tag = null; row.ErrorText = null; Rows.Remove(row); removedRows.Add(row); // add to the list of remebered rows } UpdateCheckHeader(); }
/// <summary> /// Adds given criterion to the GUI and local copy of criteria /// </summary> private void AddCriterionOption(AbstractLocalizationCriterion crit) { if (crit == null) { throw new ArgumentNullException("crit"); } try { ComboBox box = null; Label label = null; box = new ComboBox(); box.DropDownStyle = ComboBoxStyle.DropDownList; box.Tag = crit.Name; box.Items.Add(LocalizationCriterionAction.FORCE_ENABLE.ToHumanForm()); box.Items.Add(LocalizationCriterionAction.FORCE_DISABLE.ToHumanForm()); box.Items.Add(LocalizationCriterionAction.VALUE.ToHumanForm() + " " + crit.Weight); box.Items.Add(LocalizationCriterionAction.IGNORE.ToHumanForm()); box.Items.Add(LocalizationCriterionAction2.CHECK.ToHumanForm()); box.Items.Add(LocalizationCriterionAction2.CHECK_REMOVE.ToHumanForm()); box.Items.Add(LocalizationCriterionAction2.UNCHECK.ToHumanForm()); box.Items.Add(LocalizationCriterionAction2.REMOVE.ToHumanForm()); box.Width = 130; box.DropDownWidth = 200; box.Name = crit.Name + "box"; box.SelectedIndex = (int)crit.Action; box.SelectedIndexChanged += new EventHandler(Box_SelectedIndexChanged); label = new Label(); label.Name = crit.Name + "label"; label.Text = crit.Description; label.Dock = DockStyle.Fill; label.AutoEllipsis = true; label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; filterPanel.Controls.Add(label); filterPanel.Controls.Add(box); if (crit is LocalizationCustomCriterion) { filterCustomCriteriaNames.Add(label.Name); filterCustomCriteriaNames.Add(box.Name); } // add deep copy of the criterion to the local copy of criteria filterCriteriaCopy.Add(crit.Name, crit.DeepCopy()); } catch (Exception ex) { VLOutputWindow.VisualLocalizerPane.WriteException(ex); VisualLocalizer.Library.Components.MessageBox.ShowException(ex); } }
/// <summary> /// Calculates localization probability from given criteria /// </summary> public int GetLocalizationProbability(Dictionary <string, AbstractLocalizationCriterion> criteria) { bool disableRequest = false; float sum = 0; foreach (var pair in criteria) { AbstractLocalizationCriterion crit = pair.Value; bool?result = crit.Eval(this); if (result.HasValue && result.Value) { switch (crit.Action) { case LocalizationCriterionAction.FORCE_ENABLE: return(AbstractLocalizationCriterion.MAX_LOC_PROBABILITY); case LocalizationCriterionAction.FORCE_DISABLE: disableRequest = true; break; case LocalizationCriterionAction.VALUE: sum += crit.Weight; break; case LocalizationCriterionAction.IGNORE: break; } } } if (disableRequest) { return(0); } double half = AbstractLocalizationCriterion.MAX_LOC_PROBABILITY / 2.0; int x = (int)(half + Math.Atan(sum / half) * AbstractLocalizationCriterion.MAX_LOC_PROBABILITY / Math.PI); if (x >= 0 && x <= AbstractLocalizationCriterion.MAX_LOC_PROBABILITY) { return(x); } else { return(x < 0 ? 0 : AbstractLocalizationCriterion.MAX_LOC_PROBABILITY); } }