private void addConvolutionFilter_Click(object sender, EventArgs e) { //Check if filter is selected for edit ConvFilter cf = null; List <string> selectedFields = new List <string>(); selectedFields.AddRange(filterCheckedListBox.CheckedItems.OfType <string>()); if (selectedFields.Count > 0) { cf = filters.GetConvFilter(selectedFields.First()); } using (var convForm = new AddConvDialog(cf)) { var result = convForm.ShowDialog(); if (result == DialogResult.OK) { filters.addEditFilter(new ConvFilter(convForm.name, convForm.kernel, convForm.offset, convForm.columns, convForm.rows, convForm.kernelAnchorRow, convForm.kernelAnchorCol)); filterCheckedListBox.Items.Add(convForm.name); filterCheckedListBox.Items.Clear(); filterCheckedListBox.Items.AddRange(filters.getFilterNames()); } } }
public AddConvDialog(ConvFilter editFilter) { InitializeComponent(); this.editFilter = editFilter; if (editFilter != null) { fromExisting(editFilter); } }
public void addEditFilter(ConvFilter newConvFilter) { Filter existingFilter = filters.FindLast(item => item.Name == newConvFilter.Name); if (existingFilter != null && existingFilter.GetType() == newConvFilter.GetType()) { filters.Remove(existingFilter); } filters.Add(newConvFilter); }
private void fromExisting(ConvFilter editFilter) { tableLayoutPanel1.Controls.Clear(); for (int i = 0; i < editFilter.Columns; i++) { for (int j = 0; j < editFilter.Rows; j++) { TextBox textBox = new TextBox(); textBox.Text = editFilter.Kernel[i, j].ToString(); tableLayoutPanel1.Controls.Add(textBox, i, j); } } offsetTextBox.Text = editFilter.Offset.ToString(); rowsTextBox.Text = editFilter.Rows.ToString(); columnsTextBox.Text = editFilter.Columns.ToString(); anchorColTextBox.Text = editFilter.KernelAnchorCol.ToString(); anchorRowTextBox.Text = editFilter.KernelAnchorRow.ToString(); nameTextBox.Text = editFilter.Name; columns = editFilter.Columns; rows = editFilter.Rows; }
public ConvFilter GetConvFilter(string filterName) { ConvFilter filter = (ConvFilter)filters.FindLast(item => item.Name == filterName && item.GetType() == typeof(ConvFilter)); return(filter); }